Skip to content

Commit

Permalink
apply formatting (fix build) (#13209)
Browse files Browse the repository at this point in the history
* preformat

* apply formatting
  • Loading branch information
dsyme authored May 31, 2022
1 parent 36af364 commit 5b1a3ae
Show file tree
Hide file tree
Showing 16 changed files with 484 additions and 162 deletions.
4 changes: 4 additions & 0 deletions src/FSharp.Core/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# FSharp.Core uses more "conservative" settings - more lines etc.

[*.fs]
max_line_length=120
fsharp_max_function_binding_width=1
fsharp_max_if_then_else_short_width=40
44 changes: 24 additions & 20 deletions src/FSharp.Core/QueryExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,33 @@ open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.DerivedPatterns
open Microsoft.FSharp.Reflection
open Microsoft.FSharp.Linq.RuntimeHelpers
open System.Collections
open System.Collections.Concurrent
open System.Collections.Generic
open System.Linq
open System.Linq.Expressions
open System.Reflection

// ----------------------------------------------------------------------------

/// A type used to reconstruct a grouping after applying a mutable->immutable mapping transformation
/// on a result of a query.
type Grouping<'K, 'T>(key: 'K, values: seq<'T>) =
interface System.Linq.IGrouping<'K, 'T> with
interface IGrouping<'K, 'T> with
member _.Key = key

interface System.Collections.IEnumerable with
interface IEnumerable with
member _.GetEnumerator() =
values.GetEnumerator() :> System.Collections.IEnumerator
values.GetEnumerator() :> IEnumerator

interface System.Collections.Generic.IEnumerable<'T> with
interface Generic.IEnumerable<'T> with
member _.GetEnumerator() =
values.GetEnumerator()

module internal Adapters =

let memoize f =
let d =
new System.Collections.Concurrent.ConcurrentDictionary<Type, 'b>(HashIdentity.Structural)
let d = new ConcurrentDictionary<Type, 'b>(HashIdentity.Structural)

fun x -> d.GetOrAdd(x, (fun r -> f r))

Expand All @@ -46,13 +48,13 @@ module internal Adapters =

let MemberInitializationHelperMeth =
methodhandleof (fun x -> LeafExpressionConverter.MemberInitializationHelper x)
|> System.Reflection.MethodInfo.GetMethodFromHandle
:?> System.Reflection.MethodInfo
|> MethodInfo.GetMethodFromHandle
:?> MethodInfo

let NewAnonymousObjectHelperMeth =
methodhandleof (fun x -> LeafExpressionConverter.NewAnonymousObjectHelper x)
|> System.Reflection.MethodInfo.GetMethodFromHandle
:?> System.Reflection.MethodInfo
|> MethodInfo.GetMethodFromHandle
:?> MethodInfo

// The following patterns are used to recognize object construction
// using the 'new O(Prop1 = <e>, Prop2 = <e>)' syntax
Expand All @@ -73,7 +75,8 @@ module internal Adapters =
let rec propSetList acc x =
match x with
// detect " v.X <- y"
| ((Patterns.PropertySet (Some (Patterns.Var var), _, _, _)) as p) :: xs when var = varArg -> propSetList (p :: acc) xs
| ((Patterns.PropertySet (Some (Patterns.Var var), _, _, _)) as p) :: xs when var = varArg ->
propSetList (p :: acc) xs
// skip unit values
| (Patterns.Value (v, _)) :: xs when v = null -> propSetList acc xs
// detect "v"
Expand Down Expand Up @@ -190,8 +193,7 @@ module internal Adapters =
let fields =
Microsoft.FSharp.Reflection.FSharpType.GetRecordFields(
typ,
System.Reflection.BindingFlags.Public
||| System.Reflection.BindingFlags.NonPublic
BindingFlags.Public ||| BindingFlags.NonPublic
)

match fields |> Array.tryFindIndex (fun p -> p = propInfo) with
Expand Down Expand Up @@ -223,18 +225,19 @@ module internal Adapters =

match convs with
| x1 :: x2 :: x3 :: x4 :: x5 :: x6 :: x7 :: x8 :: tail ->
RewriteTupleType ty (List.map2 ConvImmutableTypeToMutableType [ x1; x2; x3; x4; x5; x6; x7; TupleConv(x8 :: tail) ])
let els = [ x1; x2; x3; x4; x5; x6; x7; TupleConv(x8 :: tail) ]
RewriteTupleType ty (List.map2 ConvImmutableTypeToMutableType els)
| _ -> RewriteTupleType ty (List.map2 ConvImmutableTypeToMutableType convs)
| RecordConv (_, convs) ->
assert (isPartiallyImmutableRecord ty)
let types = [| for f in FSharpType.GetRecordFields ty -> f.PropertyType |]
ConvImmutableTypeToMutableType (TupleConv convs) (FSharpType.MakeTupleType types)
| GroupingConv (_keyTy, _elemTy, conv) ->
assert ty.IsGenericType
assert (ty.GetGenericTypeDefinition() = typedefof<System.Linq.IGrouping<_, _>>)
assert (ty.GetGenericTypeDefinition() = typedefof<IGrouping<_, _>>)
let keyt1 = ty.GetGenericArguments().[0]
let valt1 = ty.GetGenericArguments().[1]
typedefof<System.Linq.IGrouping<_, _>>.MakeGenericType [| keyt1; ConvImmutableTypeToMutableType conv valt1 |]
typedefof<IGrouping<_, _>>.MakeGenericType [| keyt1; ConvImmutableTypeToMutableType conv valt1 |]
| SeqConv conv ->
assert ty.IsGenericType
let isIQ = ty.GetGenericTypeDefinition() = typedefof<IQueryable<_>>
Expand All @@ -256,14 +259,14 @@ module internal Adapters =
let mhandle =
(methodhandleof (fun x -> LeafExpressionConverter.NewAnonymousObjectHelper x))

let minfo =
(System.Reflection.MethodInfo.GetMethodFromHandle mhandle) :?> System.Reflection.MethodInfo
let minfo = (MethodInfo.GetMethodFromHandle mhandle) :?> MethodInfo

let gmd = minfo.GetGenericMethodDefinition()

(fun tm ->
match tm with
| Patterns.Call (_obj, minfo2, _args) -> minfo2.IsGenericMethod && (gmd = minfo2.GetGenericMethodDefinition())
| Patterns.Call (_obj, minfo2, _args) ->
minfo2.IsGenericMethod && (gmd = minfo2.GetGenericMethodDefinition())
| _ -> false)

/// Cleanup the use of property-set object constructions in leaf expressions that form parts of F# queries.
Expand Down Expand Up @@ -305,7 +308,8 @@ module internal Adapters =
// rewrite bottom-up
let e =
match e with
| ExprShape.ShapeCombination (comb, args) -> ExprShape.RebuildShapeCombination(comb, List.map SimplifyConsumingExpr args)
| ExprShape.ShapeCombination (comb, args) ->
ExprShape.RebuildShapeCombination(comb, List.map SimplifyConsumingExpr args)
| ExprShape.ShapeLambda (v, body) -> Expr.Lambda(v, SimplifyConsumingExpr body)
| ExprShape.ShapeVar _ -> e

Expand Down
30 changes: 25 additions & 5 deletions src/FSharp.Core/array.fs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ module Array =

// Wrap a StructBox around all keys in case the key type is itself a type using null as a representation
let countByRefType (projection: 'T -> 'Key) (array: 'T[]) =
countByImpl RuntimeHelpers.StructBox<'Key>.Comparer (fun t -> RuntimeHelpers.StructBox(projection t)) (fun sb -> sb.Value) array
countByImpl
RuntimeHelpers.StructBox<'Key>.Comparer
(fun t -> RuntimeHelpers.StructBox(projection t))
(fun sb -> sb.Value)
array

[<CompiledName("CountBy")>]
let countBy (projection: 'T -> 'Key) (array: 'T[]) =
Expand Down Expand Up @@ -570,7 +574,11 @@ module Array =

// Wrap a StructBox around all keys in case the key type is itself a type using null as a representation
let groupByRefType (keyf: 'T -> 'Key) (array: 'T[]) =
groupByImpl RuntimeHelpers.StructBox<'Key>.Comparer (fun t -> RuntimeHelpers.StructBox(keyf t)) (fun sb -> sb.Value) array
groupByImpl
RuntimeHelpers.StructBox<'Key>.Comparer
(fun t -> RuntimeHelpers.StructBox(keyf t))
(fun sb -> sb.Value)
array

[<CompiledName("GroupBy")>]
let groupBy (projection: 'T -> 'Key) (array: 'T[]) =
Expand Down Expand Up @@ -822,7 +830,12 @@ module Array =

count

let private createMask<'a> (f: 'a -> bool) (src: array<'a>) (maskArrayOut: byref<array<uint32>>) (leftoverMaskOut: byref<uint32>) =
let private createMask<'a>
(f: 'a -> bool)
(src: array<'a>)
(maskArrayOut: byref<array<uint32>>)
(leftoverMaskOut: byref<uint32>)
=
let maskArrayLength = src.Length / 0x20

// null when there are less than 32 items in src array.
Expand Down Expand Up @@ -1208,7 +1221,10 @@ module Array =

if len % chunkSize <> 0 then
res.[chunkCount - 1] <-
Microsoft.FSharp.Primitives.Basics.Array.subUnchecked ((chunkCount - 1) * chunkSize) (len % chunkSize) array
Microsoft.FSharp.Primitives.Basics.Array.subUnchecked
((chunkCount - 1) * chunkSize)
(len % chunkSize)
array

res

Expand Down Expand Up @@ -1776,7 +1792,11 @@ module Array =

for j in 1 .. len - 1 do
if lenInner <> array.[j].Length then
invalidArgDifferentArrayLength "array.[0]" lenInner (String.Format("array.[{0}]", j)) array.[j].Length
invalidArgDifferentArrayLength
"array.[0]"
lenInner
(String.Format("array.[{0}]", j))
array.[j].Length

let result: 'T[][] =
Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked lenInner
Expand Down
69 changes: 53 additions & 16 deletions src/FSharp.Core/async.fs
Original file line number Diff line number Diff line change
Expand Up @@ -870,13 +870,15 @@ module AsyncPrimitives =
/// - Create Thread and call Start() with exception protection. We don't expect this
/// to fail but protect nevertheless.
let CreateSwitchToNewThreadAsync () =
MakeAsyncWithCancelCheck(fun ctxt -> ctxt.ProtectCode(fun () -> ctxt.trampolineHolder.StartThreadWithTrampoline ctxt.cont))
MakeAsyncWithCancelCheck(fun ctxt ->
ctxt.ProtectCode(fun () -> ctxt.trampolineHolder.StartThreadWithTrampoline ctxt.cont))

/// - Initial cancellation check
/// - Call ThreadPool.QueueUserWorkItem with exception protection. We don't expect this
/// to fail but protect nevertheless.
let CreateSwitchToThreadPoolAsync () =
MakeAsyncWithCancelCheck(fun ctxt -> ctxt.ProtectCode(fun () -> ctxt.trampolineHolder.QueueWorkItemWithTrampoline ctxt.cont))
MakeAsyncWithCancelCheck(fun ctxt ->
ctxt.ProtectCode(fun () -> ctxt.trampolineHolder.QueueWorkItemWithTrampoline ctxt.cont))

/// Post back to the sync context regardless of which continuation is taken
/// - Call syncCtxt.Post with exception protection
Expand Down Expand Up @@ -917,7 +919,8 @@ module AsyncPrimitives =
// This logic was added in F# 2.0 though is incorrect from the perspective of
// how SynchronizationContext is meant to work. However the logic works for
// mainline scenarios (WinForms/WPF) and for compatibility reasons we won't change it.
| _ when Object.Equals(syncCtxt, currentSyncCtxt) && thread.Equals Thread.CurrentThread -> executeImmediately ()
| _ when Object.Equals(syncCtxt, currentSyncCtxt) && thread.Equals Thread.CurrentThread ->
executeImmediately ()
| _ -> trampolineHolder.PostOrQueueWithTrampoline syncCtxt action

member _.PostOrQueueWithTrampoline res =
Expand Down Expand Up @@ -1074,7 +1077,7 @@ module AsyncPrimitives =
(typeof<FuncDelegate<'T>>)
.GetMethod("Invoke", BindingFlags.Public ||| BindingFlags.NonPublic ||| BindingFlags.Instance)

System.Delegate.CreateDelegate(typeof<'Delegate>, obj, invokeMeth) :?> 'Delegate
Delegate.CreateDelegate(typeof<'Delegate>, obj, invokeMeth) :?> 'Delegate

[<DebuggerHidden>]
let QueueAsync cancellationToken cont econt ccont computation =
Expand Down Expand Up @@ -1429,7 +1432,9 @@ type Async =
static member CancelCheck() =
unitAsync

static member FromContinuations(callback: ('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit) : Async<'T> =
static member FromContinuations
(callback: ('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit)
: Async<'T> =
MakeAsyncWithCancelCheck(fun ctxt ->
let mutable underCurrentThreadStack = true
let mutable contToTailCall = None
Expand All @@ -1451,7 +1456,11 @@ type Async =
ctxt.trampolineHolder.ExecuteWithTrampoline(fun () -> cont x) |> unfake

try
callback (once ctxt.cont, (fun exn -> once ctxt.econt (ExceptionDispatchInfo.RestoreOrCapture exn)), once ctxt.ccont)
callback (
once ctxt.cont,
(fun exn -> once ctxt.econt (ExceptionDispatchInfo.RestoreOrCapture exn)),
once ctxt.ccont
)
with exn ->
if not (latch.Enter()) then
invalidOp (SR.GetString(SR.controlContinuationInvokedMultipleTimes))
Expand Down Expand Up @@ -1518,7 +1527,12 @@ type Async =
static member Parallel(computations: seq<Async<'T>>, ?maxDegreeOfParallelism: int) =
match maxDegreeOfParallelism with
| Some x when x < 1 ->
raise (System.ArgumentException(String.Format(SR.GetString(SR.maxDegreeOfParallelismNotPositive), x), "maxDegreeOfParallelism"))
raise (
System.ArgumentException(
String.Format(SR.GetString(SR.maxDegreeOfParallelismNotPositive), x),
"maxDegreeOfParallelism"
)
)
| _ -> ()

MakeAsyncWithCancelCheck(fun ctxt ->
Expand Down Expand Up @@ -1547,8 +1561,10 @@ type Async =

match firstExn with
| None -> ctxt.trampolineHolder.ExecuteWithTrampoline(fun () -> ctxt.cont results)
| Some (Choice1Of2 exn) -> ctxt.trampolineHolder.ExecuteWithTrampoline(fun () -> ctxt.econt exn)
| Some (Choice2Of2 cexn) -> ctxt.trampolineHolder.ExecuteWithTrampoline(fun () -> ctxt.ccont cexn)
| Some (Choice1Of2 exn) ->
ctxt.trampolineHolder.ExecuteWithTrampoline(fun () -> ctxt.econt exn)
| Some (Choice2Of2 cexn) ->
ctxt.trampolineHolder.ExecuteWithTrampoline(fun () -> ctxt.ccont cexn)
else
fake ()

Expand Down Expand Up @@ -1724,7 +1740,12 @@ type Async =
let cancellationToken =
defaultArg cancellationToken defaultCancellationTokenSource.Token

AsyncPrimitives.StartWithContinuations cancellationToken computation continuation exceptionContinuation cancellationContinuation
AsyncPrimitives.StartWithContinuations
cancellationToken
computation
continuation
exceptionContinuation
cancellationContinuation

static member StartWithContinuations
(
Expand Down Expand Up @@ -1781,7 +1802,8 @@ type Async =
DisposeCancellationRegistration &registration
DisposeTimer &timer

ctxt.trampolineHolder.ExecuteWithTrampoline(fun () -> ctxt.ccont (OperationCanceledException(ctxt.token)))
ctxt.trampolineHolder.ExecuteWithTrampoline(fun () ->
ctxt.ccont (OperationCanceledException(ctxt.token)))
|> unfake)
)
|> Some
Expand Down Expand Up @@ -1847,7 +1869,8 @@ type Async =
UnregisterWaitHandle &rwh

// Call the cancellation continuation
ctxt.trampolineHolder.ExecuteWithTrampoline(fun () -> ctxt.ccont (OperationCanceledException(ctxt.token)))
ctxt.trampolineHolder.ExecuteWithTrampoline(fun () ->
ctxt.ccont (OperationCanceledException(ctxt.token)))
|> unfake)
)
|> Some
Expand Down Expand Up @@ -1929,7 +1952,11 @@ type Async =
let res = resultCell.GrabResult()
return res.Commit()
else
let! ok = Async.AwaitWaitHandle(resultCell.GetWaitHandle(), ?millisecondsTimeout = millisecondsTimeout)
let! ok =
Async.AwaitWaitHandle(
resultCell.GetWaitHandle(),
?millisecondsTimeout = millisecondsTimeout
)

if ok then
let res = resultCell.GrabResult()
Expand Down Expand Up @@ -2009,10 +2036,18 @@ type Async =
Async.FromBeginEnd((fun (iar, state) -> beginAction (arg, iar, state)), endAction, ?cancelAction = cancelAction)

static member FromBeginEnd(arg1, arg2, beginAction, endAction, ?cancelAction) : Async<'T> =
Async.FromBeginEnd((fun (iar, state) -> beginAction (arg1, arg2, iar, state)), endAction, ?cancelAction = cancelAction)
Async.FromBeginEnd(
(fun (iar, state) -> beginAction (arg1, arg2, iar, state)),
endAction,
?cancelAction = cancelAction
)

static member FromBeginEnd(arg1, arg2, arg3, beginAction, endAction, ?cancelAction) : Async<'T> =
Async.FromBeginEnd((fun (iar, state) -> beginAction (arg1, arg2, arg3, iar, state)), endAction, ?cancelAction = cancelAction)
Async.FromBeginEnd(
(fun (iar, state) -> beginAction (arg1, arg2, arg3, iar, state)),
endAction,
?cancelAction = cancelAction
)

static member AsBeginEnd<'Arg, 'T>
(computation: ('Arg -> Async<'T>))
Expand Down Expand Up @@ -2267,7 +2302,9 @@ module WebExtensions =
)
|> CreateTryWithFilterAsync(fun exn ->
match exn with
| :? System.Net.WebException as webExn when webExn.Status = System.Net.WebExceptionStatus.RequestCanceled && canceled ->
| :? System.Net.WebException as webExn when
webExn.Status = System.Net.WebExceptionStatus.RequestCanceled && canceled
->

Some(CreateAsyncResultAsync(AsyncResult.Canceled(OperationCanceledException webExn.Message)))
| _ -> None)
Expand Down
3 changes: 2 additions & 1 deletion src/FSharp.Core/collections.fs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ module ComparisonIdentity =
let inline Structural<'T when 'T: comparison> : IComparer<'T> =
LanguagePrimitives.FastGenericComparer<'T>

let inline NonStructural<'T when 'T: (static member (<): 'T * 'T -> bool) and 'T: (static member (>): 'T * 'T -> bool)> : IComparer<'T> =
let inline NonStructural<'T
when 'T: (static member (<): 'T * 'T -> bool) and 'T: (static member (>): 'T * 'T -> bool)> : IComparer<'T> =
{ new IComparer<'T> with
member _.Compare(x, y) =
NonStructuralComparison.compare x y
Expand Down
Loading

0 comments on commit 5b1a3ae

Please sign in to comment.