Skip to content

Commit

Permalink
fantomas
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom committed Nov 20, 2024
1 parent ef80877 commit 1be4e74
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
25 changes: 20 additions & 5 deletions src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ let ComputeTypeAccess (tref: ILTypeRef) hidden (accessibility: Accessibility) re

/// Indicates how type parameters are mapped to IL type variables
[<NoEquality; NoComparison>]
type TypeReprEnv(reprs: Map<Stamp, (uint16 * Typar)>, count: int, templateReplacement: (TyconRef * ILTypeRef * Typars * TyparInstantiation) option) =
type TypeReprEnv
(reprs: Map<Stamp, (uint16 * Typar)>, count: int, templateReplacement: (TyconRef * ILTypeRef * Typars * TyparInstantiation) option) =

static let empty = TypeReprEnv(count = 0, reprs = Map.empty, templateReplacement = None)

Expand All @@ -536,7 +537,7 @@ type TypeReprEnv(reprs: Map<Stamp, (uint16 * Typar)>, count: int, templateReplac
/// Lookup a type parameter
member _.Item(tp: Typar, m: range) =
try
reprs[tp.Stamp] |>fst
reprs[tp.Stamp] |> fst
with :? KeyNotFoundException ->
errorR (InternalError("Undefined or unsolved type variable: " + showL (typarL tp), m))
// Random value for post-hoc diagnostic analysis on generated tree *
Expand Down Expand Up @@ -574,7 +575,12 @@ type TypeReprEnv(reprs: Map<Stamp, (uint16 * Typar)>, count: int, templateReplac
member eenv.ForTyconRef(tcref: TyconRef) = eenv.ForTycon tcref.Deref

/// Get a list of the Typars in this environment
member eenv.AsUserProvidedTypars() = reprs |> Map.toList |> List.map(fun (_, (_, tp)) -> tp) |> List.filter(fun tp -> not tp.IsCompilerGenerated) |> Zset.ofList typarOrder
member eenv.AsUserProvidedTypars() =
reprs
|> Map.toList
|> List.map (fun (_, (_, tp)) -> tp)
|> List.filter (fun tp -> not tp.IsCompilerGenerated)
|> Zset.ofList typarOrder

//--------------------------------------------------------------------------
// Generate type references
Expand Down Expand Up @@ -6922,9 +6928,13 @@ and GetIlxClosureFreeVars cenv m (thisVars: ValRef list) boxity eenv takenNames
g.CompilerGlobalState.Value.StableNameGenerator.GetUniqueCompilerGeneratedName(basenameSafeForUseAsTypename, expr.Range, uniq)

let ilCloTypeRef = NestedTypeRefForCompLoc eenv.cloc cloName

let initialFreeTyvars =
match g.realsig with
| true -> { emptyFreeTyvars with FreeTypars = eenv.tyenv.AsUserProvidedTypars() }
| true ->
{ emptyFreeTyvars with
FreeTypars = eenv.tyenv.AsUserProvidedTypars()
}
| false -> emptyFreeTyvars

ilCloTypeRef, initialFreeTyvars
Expand All @@ -6938,7 +6948,12 @@ and GetIlxClosureFreeVars cenv m (thisVars: ValRef list) boxity eenv takenNames
| None -> opts
| Some(tcref, _, typars, _) -> opts.WithTemplateReplacement(tyconRefEq g tcref, typars)

accFreeInExpr opts expr { emptyFreeVars with FreeTyvars = initialFreeTyvars }
accFreeInExpr
opts
expr
{ emptyFreeVars with
FreeTyvars = initialFreeTyvars
}

// Partition the free variables when some can be accessed from places besides the immediate environment
// Also filter out the current value being bound, if any, as it is available from the "this"
Expand Down
56 changes: 28 additions & 28 deletions tests/fsharp/Compiler/CodeGen/EmittedIL/TaskGeneratedCode.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ type Generic1InGeneric1<'T>() =
extends [runtime]System.Object
{
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 )
.class auto autochar sealed nested assembly beforefieldinit specialname clo@7<A>
.class auto autochar sealed nested assembly beforefieldinit specialname clo@7<T,A>
extends [runtime]System.ValueType
implements [runtime]System.Runtime.CompilerServices.IAsyncStateMachine,
class [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.IResumableStateMachine`1<valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!A>>
Expand Down Expand Up @@ -1132,7 +1132,7 @@ type Generic1InGeneric1<'T>() =
class [runtime]System.Exception V_9,
class [runtime]System.Exception V_10)
IL_0000: ldarg.0
IL_0001: ldfld int32 valuetype Test/Generic1InGeneric1`1/clo@7<!A>::ResumptionPoint
IL_0001: ldfld int32 valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::ResumptionPoint
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: ldc.i4.1
Expand Down Expand Up @@ -1161,16 +1161,16 @@ type Generic1InGeneric1<'T>() =
IL_002c: nop
IL_002d: ldarg.0
IL_002e: ldfld class [runtime]System.Threading.Tasks.Task`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::computation
IL_002e: ldfld class [runtime]System.Threading.Tasks.Task`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::computation
IL_0033: stloc.3
IL_0034: ldarg.0
IL_0035: ldloc.3
IL_0036: callvirt instance valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1<!0> class [netstandard]System.Threading.Tasks.Task`1<!A>::GetAwaiter()
IL_003b: stfld valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::awaiter
IL_003b: stfld valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::awaiter
IL_0040: ldc.i4.1
IL_0041: stloc.s V_4
IL_0043: ldarg.0
IL_0044: ldflda valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::awaiter
IL_0044: ldflda valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::awaiter
IL_0049: call instance bool valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1<!A>::get_IsCompleted()
IL_004e: brfalse.s IL_0052
Expand All @@ -1185,7 +1185,7 @@ type Generic1InGeneric1<'T>() =
IL_0059: ldarg.0
IL_005a: ldc.i4.1
IL_005b: stfld int32 valuetype Test/Generic1InGeneric1`1/clo@7<!A>::ResumptionPoint
IL_005b: stfld int32 valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::ResumptionPoint
IL_0060: ldc.i4.0
IL_0061: nop
IL_0062: stloc.s V_5
Expand All @@ -1199,27 +1199,27 @@ type Generic1InGeneric1<'T>() =
IL_006e: brfalse.s IL_0092
IL_0070: ldarg.0
IL_0071: ldflda valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::awaiter
IL_0071: ldflda valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::awaiter
IL_0076: call instance !0 valuetype [netstandard]System.Runtime.CompilerServices.TaskAwaiter`1<!A>::GetResult()
IL_007b: stloc.s V_6
IL_007d: ldloc.s V_6
IL_007f: stloc.s V_7
IL_0081: ldarg.0
IL_0082: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::Data
IL_0082: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::Data
IL_0087: ldloc.s V_7
IL_0089: stfld !0 valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!A>::Result
IL_008e: ldc.i4.1
IL_008f: nop
IL_0090: br.s IL_00ab
IL_0092: ldarg.0
IL_0093: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::Data
IL_0093: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::Data
IL_0098: ldflda valuetype [runtime]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!0> valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!A>::MethodBuilder
IL_009d: ldarg.0
IL_009e: ldflda valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::awaiter
IL_009e: ldflda valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::awaiter
IL_00a3: ldarg.0
IL_00a4: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!A>::AwaitUnsafeOnCompleted<valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!0>,valuetype Test/Generic1InGeneric1`1/clo@7<!0>>(!!0&,
!!1&)
IL_00a4: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!A>::AwaitUnsafeOnCompleted<valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!1>,valuetype Test/Generic1InGeneric1`1/clo@7<!0,!1>>(!!0&,
!!1&)
IL_00a9: ldc.i4.0
IL_00aa: nop
IL_00ab: brfalse.s IL_00c1
Expand All @@ -1228,7 +1228,7 @@ type Generic1InGeneric1<'T>() =
IL_00ae: ldloca.s V_8
IL_00b0: initobj valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!A>
IL_00b6: ldloc.s V_8
IL_00b8: stfld valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::awaiter
IL_00b8: stfld valuetype [runtime]System.Runtime.CompilerServices.TaskAwaiter`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::awaiter
IL_00bd: ldc.i4.1
IL_00be: nop
IL_00bf: br.s IL_00c3
Expand All @@ -1240,10 +1240,10 @@ type Generic1InGeneric1<'T>() =
IL_00c5: brfalse.s IL_00e4
IL_00c7: ldarg.0
IL_00c8: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::Data
IL_00c8: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::Data
IL_00cd: ldflda valuetype [runtime]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!0> valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!A>::MethodBuilder
IL_00d2: ldarg.0
IL_00d3: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::Data
IL_00d3: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::Data
IL_00d8: ldfld !0 valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!A>::Result
IL_00dd: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!A>::SetResult(!0)
IL_00e2: leave.s IL_00f2
Expand All @@ -1268,7 +1268,7 @@ type Generic1InGeneric1<'T>() =
IL_00f9: ret
IL_00fa: ldarg.0
IL_00fb: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::Data
IL_00fb: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::Data
IL_0100: ldflda valuetype [runtime]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!0> valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!A>::MethodBuilder
IL_0105: ldloc.s V_10
IL_0107: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!A>::SetException(class [netstandard]System.Exception)
Expand All @@ -1281,7 +1281,7 @@ type Generic1InGeneric1<'T>() =
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::Data
IL_0001: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::Data
IL_0006: ldflda valuetype [runtime]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!0> valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!A>::MethodBuilder
IL_000b: ldarg.1
IL_000c: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!A>::SetStateMachine(class [netstandard]System.Runtime.CompilerServices.IAsyncStateMachine)
Expand All @@ -1294,7 +1294,7 @@ type Generic1InGeneric1<'T>() =
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld int32 valuetype Test/Generic1InGeneric1`1/clo@7<!A>::ResumptionPoint
IL_0001: ldfld int32 valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::ResumptionPoint
IL_0006: ret
}
Expand All @@ -1304,7 +1304,7 @@ type Generic1InGeneric1<'T>() =
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldfld valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::Data
IL_0001: ldfld valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::Data
IL_0006: ret
}
Expand All @@ -1315,7 +1315,7 @@ type Generic1InGeneric1<'T>() =
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!A>::Data
IL_0002: stfld valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!A>::Data
IL_0007: ret
}
Expand Down Expand Up @@ -1348,26 +1348,26 @@ type Generic1InGeneric1<'T>() =
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
.maxstack 4
.locals init (valuetype Test/Generic1InGeneric1`1/clo@7<!!A> V_0,
valuetype Test/Generic1InGeneric1`1/clo@7<!!A>& V_1)
.locals init (valuetype Test/Generic1InGeneric1`1/clo@7<!T,!!A> V_0,
valuetype Test/Generic1InGeneric1`1/clo@7<!T,!!A>& V_1)
IL_0000: ldloca.s V_0
IL_0002: initobj valuetype Test/Generic1InGeneric1`1/clo@7<!!A>
IL_0002: initobj valuetype Test/Generic1InGeneric1`1/clo@7<!T,!!A>
IL_0008: ldloca.s V_0
IL_000a: stloc.1
IL_000b: ldloc.1
IL_000c: ldarg.1
IL_000d: stfld class [runtime]System.Threading.Tasks.Task`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!!A>::computation
IL_000d: stfld class [runtime]System.Threading.Tasks.Task`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!!A>::computation
IL_0012: ldloc.1
IL_0013: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!!A>::Data
IL_0013: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!!A>::Data
IL_0018: call valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!0> valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!!A>::Create()
IL_001d: stfld valuetype [runtime]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!0> valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!!A>::MethodBuilder
IL_0022: ldloc.1
IL_0023: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!!A>::Data
IL_0023: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!!A>::Data
IL_0028: ldflda valuetype [runtime]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!0> valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!!A>::MethodBuilder
IL_002d: ldloc.1
IL_002e: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!!0>::Start<valuetype Test/Generic1InGeneric1`1/clo@7<!!0>>(!!0&)
IL_002e: call instance void valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!!0>::Start<valuetype Test/Generic1InGeneric1`1/clo@7<!0,!!0>>(!!0&)
IL_0033: ldloc.1
IL_0034: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!0> valuetype Test/Generic1InGeneric1`1/clo@7<!!A>::Data
IL_0034: ldflda valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!1> valuetype Test/Generic1InGeneric1`1/clo@7<!T,!!A>::Data
IL_0039: ldflda valuetype [runtime]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!0> valuetype [FSharp.Core]Microsoft.FSharp.Control.TaskStateMachineData`1<!!A>::MethodBuilder
IL_003e: call instance class [netstandard]System.Threading.Tasks.Task`1<!0> valuetype [netstandard]System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1<!!A>::get_Task()
IL_0043: ret
Expand Down

0 comments on commit 1be4e74

Please sign in to comment.