diff --git a/src/Compiler/TypedTree/CompilerGlobalState.fs b/src/Compiler/TypedTree/CompilerGlobalState.fs index 7047fc3cf35..bde704da3fb 100644 --- a/src/Compiler/TypedTree/CompilerGlobalState.fs +++ b/src/Compiler/TypedTree/CompilerGlobalState.fs @@ -71,3 +71,7 @@ let newUnique() = System.Threading.Interlocked.Increment &uniqueCount //++GLOBAL MUTABLE STATE (concurrency-safe) let mutable private stampCount = 0L let newStamp() = System.Threading.Interlocked.Increment &stampCount + +let resetUniqueAndStamp() = + System.Threading.Interlocked.Exchange(&uniqueCount, 0) |> ignore + System.Threading.Interlocked.Exchange(&stampCount, 0) |> ignore \ No newline at end of file diff --git a/src/Compiler/TypedTree/CompilerGlobalState.fsi b/src/Compiler/TypedTree/CompilerGlobalState.fsi index 6f0dba79ddf..ee68bd25d90 100644 --- a/src/Compiler/TypedTree/CompilerGlobalState.fsi +++ b/src/Compiler/TypedTree/CompilerGlobalState.fsi @@ -50,3 +50,6 @@ val newUnique: (unit -> int64) /// Unique name generator for stamps attached to to val_specs, tycon_specs etc. /// Concurrency-safe val newStamp: (unit -> int64) + +/// used for test only, to make newUnique and newStamp robust between compilation calls +val internal resetUniqueAndStamp: (unit -> unit) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/OptimizationTests.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/OptimizationTests.fs new file mode 100644 index 00000000000..9a747e4ef78 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/OptimizationTests.fs @@ -0,0 +1,30 @@ +module FSharp.Compiler.ComponentTests.EmittedIL.Optimization.OptimizationTests +open Xunit +open FSharp.Test +open FSharp.Test.Compiler +let [] folder = __SOURCE_DIRECTORY__ + "/samples" +[] +let ``baselines`` compilation = + compilation + |> asFsx + |> verifyBaselines + |> compileAndRun + |> shouldSucceed diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/array_of_function_no_alloc.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/array_of_function_no_alloc.fsx new file mode 100644 index 00000000000..dedf5181b18 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/array_of_function_no_alloc.fsx @@ -0,0 +1,20 @@ +// +// { "optimization": { "reported_in": "#3660", "reported_by": "@varon", "last_know_version_not_optimizing": "8", "first_known_version_optimizing": null } } +// +let exampleFunc v = v + 2 + +let runAll(fArr:(int -> int) array) x = + let mutable n = 0 + for i = 0 to fArr.Length - 1 do + n <- n + fArr.[i] x + n + + +let runAllNoAlloc(fArr:(int -> int) array) x = + let mutable n = 0 + for i = 0 to fArr.Length - 1 do + let z = fArr.[i] + n <- n + z x + n + +System.Console.WriteLine() \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/array_of_function_no_alloc.fsx.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/array_of_function_no_alloc.fsx.il.net472.bsl new file mode 100644 index 00000000000..39dffd1b737 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/array_of_function_no_alloc.fsx.il.net472.bsl @@ -0,0 +1,210 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Array_of_function_no_alloc + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested assembly beforefieldinit runAll@9 + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3[],int32,class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> + { + .field static assembly initonly class Array_of_function_no_alloc/runAll@9 @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3[],int32,class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>::.ctor() + IL_0006: ret + } + + .method public strict virtual instance class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + Invoke(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2[] source, + int32 index) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: ldelem class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + IL_0007: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Array_of_function_no_alloc/runAll@9::.ctor() + IL_0005: stsfld class Array_of_function_no_alloc/runAll@9 Array_of_function_no_alloc/runAll@9::@_instance + IL_000a: ret + } + + } + + .method public static int32 exampleFunc(int32 v) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldc.i4.2 + IL_0002: add + IL_0003: ret + } + + .method public static int32 runAll(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2[] fArr, + int32 x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 7 + .locals init (int32 V_0, + int32 V_1) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: ldc.i4.0 + IL_0003: stloc.1 + IL_0004: br.s IL_001a + + IL_0006: ldloc.0 + IL_0007: ldsfld class Array_of_function_no_alloc/runAll@9 Array_of_function_no_alloc/runAll@9::@_instance + IL_000c: ldarg.0 + IL_000d: ldloc.1 + IL_000e: ldarg.1 + IL_000f: call !!1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2[],int32>::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>>, + !0, + !1, + !!0) + IL_0014: add + IL_0015: stloc.0 + IL_0016: ldloc.1 + IL_0017: ldc.i4.1 + IL_0018: add + IL_0019: stloc.1 + IL_001a: ldloc.1 + IL_001b: ldarg.0 + IL_001c: ldlen + IL_001d: conv.i4 + IL_001e: blt.s IL_0006 + + IL_0020: ldloc.0 + IL_0021: ret + } + + .method public static int32 runAllNoAlloc(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2[] fArr, + int32 x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 5 + .locals init (int32 V_0, + int32 V_1, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 V_2) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: ldc.i4.0 + IL_0003: stloc.1 + IL_0004: br.s IL_001c + + IL_0006: ldarg.0 + IL_0007: ldloc.1 + IL_0008: ldelem class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + IL_000d: stloc.2 + IL_000e: ldloc.0 + IL_000f: ldloc.2 + IL_0010: ldarg.1 + IL_0011: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0016: add + IL_0017: stloc.0 + IL_0018: ldloc.1 + IL_0019: ldc.i4.1 + IL_001a: add + IL_001b: stloc.1 + IL_001c: ldloc.1 + IL_001d: ldarg.0 + IL_001e: ldlen + IL_001f: conv.i4 + IL_0020: blt.s IL_0006 + + IL_0022: ldloc.0 + IL_0023: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Array_of_function_no_alloc$fsx::init@ + IL_0006: ldsfld int32 ''.$Array_of_function_no_alloc$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Array_of_function_no_alloc$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Array_of_function_no_alloc::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/array_of_function_no_alloc.fsx.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/array_of_function_no_alloc.fsx.il.netcore.bsl new file mode 100644 index 00000000000..474229111ca --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/array_of_function_no_alloc.fsx.il.netcore.bsl @@ -0,0 +1,211 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern runtime { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Array_of_function_no_alloc + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested assembly beforefieldinit runAll@9 + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3[],int32,class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> + { + .field static assembly initonly class Array_of_function_no_alloc/runAll@9 @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3[],int32,class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>::.ctor() + IL_0006: ret + } + + .method public strict virtual instance class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + Invoke(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2[] source, + int32 index) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: ldelem class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + IL_0007: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Array_of_function_no_alloc/runAll@9::.ctor() + IL_0005: stsfld class Array_of_function_no_alloc/runAll@9 Array_of_function_no_alloc/runAll@9::@_instance + IL_000a: ret + } + + } + + .method public static int32 exampleFunc(int32 v) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldc.i4.2 + IL_0002: add + IL_0003: ret + } + + .method public static int32 runAll(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2[] fArr, + int32 x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 7 + .locals init (int32 V_0, + int32 V_1) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: ldc.i4.0 + IL_0003: stloc.1 + IL_0004: br.s IL_001a + + IL_0006: ldloc.0 + IL_0007: ldsfld class Array_of_function_no_alloc/runAll@9 Array_of_function_no_alloc/runAll@9::@_instance + IL_000c: ldarg.0 + IL_000d: ldloc.1 + IL_000e: ldarg.1 + IL_000f: call !!1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2[],int32>::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>>, + !0, + !1, + !!0) + IL_0014: add + IL_0015: stloc.0 + IL_0016: ldloc.1 + IL_0017: ldc.i4.1 + IL_0018: add + IL_0019: stloc.1 + IL_001a: ldloc.1 + IL_001b: ldarg.0 + IL_001c: ldlen + IL_001d: conv.i4 + IL_001e: blt.s IL_0006 + + IL_0020: ldloc.0 + IL_0021: ret + } + + .method public static int32 runAllNoAlloc(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2[] fArr, + int32 x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 5 + .locals init (int32 V_0, + int32 V_1, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 V_2) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: ldc.i4.0 + IL_0003: stloc.1 + IL_0004: br.s IL_001c + + IL_0006: ldarg.0 + IL_0007: ldloc.1 + IL_0008: ldelem class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + IL_000d: stloc.2 + IL_000e: ldloc.0 + IL_000f: ldloc.2 + IL_0010: ldarg.1 + IL_0011: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0016: add + IL_0017: stloc.0 + IL_0018: ldloc.1 + IL_0019: ldc.i4.1 + IL_001a: add + IL_001b: stloc.1 + IL_001c: ldloc.1 + IL_001d: ldarg.0 + IL_001e: ldlen + IL_001f: conv.i4 + IL_0020: blt.s IL_0006 + + IL_0022: ldloc.0 + IL_0023: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Array_of_function_no_alloc$fsx::init@ + IL_0006: ldsfld int32 ''.$Array_of_function_no_alloc$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Array_of_function_no_alloc$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Array_of_function_no_alloc::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx new file mode 100644 index 00000000000..7b9b14f8cba --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx @@ -0,0 +1,16 @@ +// +// { "optimization": { "reported_in": "#15872", "reported_by": "@kerams", "last_know_version_not_optimizing": "8", "first_known_version_optimizing": null } } +// +let inline map mapping result = + match result with + | Error e -> Error e + | Ok x -> Ok (mapping x) + +let ff x = map (fun y -> y.ToString ()) x + +let ffs x = map id x + +System.Console.WriteLine(ff (Ok "")) +System.Console.WriteLine(ffs (Ok "")) +System.Console.WriteLine(ff (Error "")) +System.Console.WriteLine(ffs (Error "")) \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx.il.net472.debug.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx.il.net472.debug.bsl new file mode 100644 index 00000000000..a1656131408 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx.il.net472.debug.bsl @@ -0,0 +1,192 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Du_for_same_expression + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 mapping, + valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 result) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 4 + .locals init (!!c V_0, + !!a V_1) + IL_0000: ldarga.s result + IL_0002: call instance int32 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_Tag() + IL_0007: ldc.i4.0 + IL_0008: bne.un.s IL_000c + + IL_000a: br.s IL_001b + + IL_000c: ldarga.s result + IL_000e: call instance !1 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ErrorValue() + IL_0013: stloc.0 + IL_0014: ldloc.0 + IL_0015: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_001a: ret + + IL_001b: ldarga.s result + IL_001d: call instance !0 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ResultValue() + IL_0022: stloc.1 + IL_0023: ldarg.0 + IL_0024: ldloc.1 + IL_0025: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_002a: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_002f: ret + } + + .method public static valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 ff(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 x) cil managed + { + + .maxstack 3 + .locals init (!!a V_0, + !!a V_1) + IL_0000: ldarga.s x + IL_0002: call instance int32 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_Tag() + IL_0007: ldc.i4.0 + IL_0008: bne.un.s IL_000c + + IL_000a: br.s IL_0019 + + IL_000c: ldarga.s x + IL_000e: call instance !1 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ErrorValue() + IL_0013: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_0018: ret + + IL_0019: ldarga.s x + IL_001b: call instance !0 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ResultValue() + IL_0020: stloc.0 + IL_0021: ldloc.0 + IL_0022: stloc.1 + IL_0023: ldloca.s V_1 + IL_0025: constrained. !!a + IL_002b: callvirt instance string [runtime]System.Object::ToString() + IL_0030: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_0035: ret + } + + .method public static valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 ffs(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 x) cil managed + { + + .maxstack 3 + .locals init (!!a V_0) + IL_0000: ldarga.s x + IL_0002: call instance int32 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_Tag() + IL_0007: ldc.i4.0 + IL_0008: bne.un.s IL_000c + + IL_000a: br.s IL_0019 + + IL_000c: ldarga.s x + IL_000e: call instance !1 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ErrorValue() + IL_0013: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_0018: ret + + IL_0019: ldarga.s x + IL_001b: call instance !0 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ResultValue() + IL_0020: stloc.0 + IL_0021: ldloc.0 + IL_0022: call !!0 [FSharp.Core]Microsoft.FSharp.Core.Operators::Identity(!!0) + IL_0027: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_002c: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Du_for_same_expression$fsx::init@ + IL_0006: ldsfld int32 ''.$Du_for_same_expression$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 3 + IL_0000: ldstr "" + IL_0005: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_000a: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ff(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_000f: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_0014: call void [runtime]System.Console::WriteLine(object) + IL_0019: ldstr "" + IL_001e: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_0023: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ffs(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_0028: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_002d: call void [runtime]System.Console::WriteLine(object) + IL_0032: ldstr "" + IL_0037: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_003c: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ff(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_0041: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_0046: call void [runtime]System.Console::WriteLine(object) + IL_004b: ldstr "" + IL_0050: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_0055: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ffs(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_005a: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_005f: call void [runtime]System.Console::WriteLine(object) + IL_0064: ret + } + +} + +.class private abstract auto ansi sealed ''.$Du_for_same_expression$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Du_for_same_expression::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx.il.net472.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx.il.net472.release.bsl new file mode 100644 index 00000000000..c944b4946c9 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx.il.net472.release.bsl @@ -0,0 +1,188 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Du_for_same_expression + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 mapping, + valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 result) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 4 + .locals init (!!c V_0, + !!a V_1) + IL_0000: ldarga.s result + IL_0002: call instance int32 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_Tag() + IL_0007: ldc.i4.0 + IL_0008: bne.un.s IL_000c + + IL_000a: br.s IL_001b + + IL_000c: ldarga.s result + IL_000e: call instance !1 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ErrorValue() + IL_0013: stloc.0 + IL_0014: ldloc.0 + IL_0015: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_001a: ret + + IL_001b: ldarga.s result + IL_001d: call instance !0 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ResultValue() + IL_0022: stloc.1 + IL_0023: ldarg.0 + IL_0024: ldloc.1 + IL_0025: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_002a: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_002f: ret + } + + .method public static valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 ff(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 x) cil managed + { + + .maxstack 3 + .locals init (!!a V_0, + !!a V_1) + IL_0000: ldarga.s x + IL_0002: call instance int32 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_Tag() + IL_0007: ldc.i4.0 + IL_0008: bne.un.s IL_000c + + IL_000a: br.s IL_0019 + + IL_000c: ldarga.s x + IL_000e: call instance !1 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ErrorValue() + IL_0013: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_0018: ret + + IL_0019: ldarga.s x + IL_001b: call instance !0 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ResultValue() + IL_0020: stloc.0 + IL_0021: ldloc.0 + IL_0022: stloc.1 + IL_0023: ldloca.s V_1 + IL_0025: constrained. !!a + IL_002b: callvirt instance string [runtime]System.Object::ToString() + IL_0030: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_0035: ret + } + + .method public static valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 ffs(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 x) cil managed + { + + .maxstack 8 + IL_0000: ldarga.s x + IL_0002: call instance int32 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_Tag() + IL_0007: ldc.i4.0 + IL_0008: bne.un.s IL_000c + + IL_000a: br.s IL_0019 + + IL_000c: ldarga.s x + IL_000e: call instance !1 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ErrorValue() + IL_0013: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_0018: ret + + IL_0019: ldarga.s x + IL_001b: call instance !0 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ResultValue() + IL_0020: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_0025: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Du_for_same_expression$fsx::init@ + IL_0006: ldsfld int32 ''.$Du_for_same_expression$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 3 + IL_0000: ldstr "" + IL_0005: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_000a: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ff(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_000f: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_0014: call void [runtime]System.Console::WriteLine(object) + IL_0019: ldstr "" + IL_001e: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_0023: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ffs(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_0028: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_002d: call void [runtime]System.Console::WriteLine(object) + IL_0032: ldstr "" + IL_0037: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_003c: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ff(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_0041: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_0046: call void [runtime]System.Console::WriteLine(object) + IL_004b: ldstr "" + IL_0050: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_0055: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ffs(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_005a: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_005f: call void [runtime]System.Console::WriteLine(object) + IL_0064: ret + } + +} + +.class private abstract auto ansi sealed ''.$Du_for_same_expression$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Du_for_same_expression::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx.il.netcore.debug.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx.il.netcore.debug.bsl new file mode 100644 index 00000000000..cb3a48ce126 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx.il.netcore.debug.bsl @@ -0,0 +1,193 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern runtime { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Du_for_same_expression + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 mapping, + valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 result) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 4 + .locals init (!!c V_0, + !!a V_1) + IL_0000: ldarga.s result + IL_0002: call instance int32 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_Tag() + IL_0007: ldc.i4.0 + IL_0008: bne.un.s IL_000c + + IL_000a: br.s IL_001b + + IL_000c: ldarga.s result + IL_000e: call instance !1 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ErrorValue() + IL_0013: stloc.0 + IL_0014: ldloc.0 + IL_0015: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_001a: ret + + IL_001b: ldarga.s result + IL_001d: call instance !0 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ResultValue() + IL_0022: stloc.1 + IL_0023: ldarg.0 + IL_0024: ldloc.1 + IL_0025: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_002a: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_002f: ret + } + + .method public static valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 ff(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 x) cil managed + { + + .maxstack 3 + .locals init (!!a V_0, + !!a V_1) + IL_0000: ldarga.s x + IL_0002: call instance int32 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_Tag() + IL_0007: ldc.i4.0 + IL_0008: bne.un.s IL_000c + + IL_000a: br.s IL_0019 + + IL_000c: ldarga.s x + IL_000e: call instance !1 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ErrorValue() + IL_0013: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_0018: ret + + IL_0019: ldarga.s x + IL_001b: call instance !0 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ResultValue() + IL_0020: stloc.0 + IL_0021: ldloc.0 + IL_0022: stloc.1 + IL_0023: ldloca.s V_1 + IL_0025: constrained. !!a + IL_002b: callvirt instance string [runtime]System.Object::ToString() + IL_0030: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_0035: ret + } + + .method public static valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 ffs(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 x) cil managed + { + + .maxstack 3 + .locals init (!!a V_0) + IL_0000: ldarga.s x + IL_0002: call instance int32 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_Tag() + IL_0007: ldc.i4.0 + IL_0008: bne.un.s IL_000c + + IL_000a: br.s IL_0019 + + IL_000c: ldarga.s x + IL_000e: call instance !1 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ErrorValue() + IL_0013: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_0018: ret + + IL_0019: ldarga.s x + IL_001b: call instance !0 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ResultValue() + IL_0020: stloc.0 + IL_0021: ldloc.0 + IL_0022: call !!0 [FSharp.Core]Microsoft.FSharp.Core.Operators::Identity(!!0) + IL_0027: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_002c: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Du_for_same_expression$fsx::init@ + IL_0006: ldsfld int32 ''.$Du_for_same_expression$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 3 + IL_0000: ldstr "" + IL_0005: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_000a: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ff(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_000f: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_0014: call void [runtime]System.Console::WriteLine(object) + IL_0019: ldstr "" + IL_001e: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_0023: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ffs(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_0028: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_002d: call void [runtime]System.Console::WriteLine(object) + IL_0032: ldstr "" + IL_0037: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_003c: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ff(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_0041: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_0046: call void [runtime]System.Console::WriteLine(object) + IL_004b: ldstr "" + IL_0050: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_0055: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ffs(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_005a: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_005f: call void [runtime]System.Console::WriteLine(object) + IL_0064: ret + } + +} + +.class private abstract auto ansi sealed ''.$Du_for_same_expression$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Du_for_same_expression::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx.il.netcore.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx.il.netcore.release.bsl new file mode 100644 index 00000000000..2ae246db384 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/du_for_same_expression.fsx.il.netcore.release.bsl @@ -0,0 +1,189 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern runtime { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Du_for_same_expression + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 mapping, + valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 result) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 4 + .locals init (!!c V_0, + !!a V_1) + IL_0000: ldarga.s result + IL_0002: call instance int32 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_Tag() + IL_0007: ldc.i4.0 + IL_0008: bne.un.s IL_000c + + IL_000a: br.s IL_001b + + IL_000c: ldarga.s result + IL_000e: call instance !1 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ErrorValue() + IL_0013: stloc.0 + IL_0014: ldloc.0 + IL_0015: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_001a: ret + + IL_001b: ldarga.s result + IL_001d: call instance !0 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ResultValue() + IL_0022: stloc.1 + IL_0023: ldarg.0 + IL_0024: ldloc.1 + IL_0025: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_002a: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_002f: ret + } + + .method public static valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 ff(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 x) cil managed + { + + .maxstack 3 + .locals init (!!a V_0, + !!a V_1) + IL_0000: ldarga.s x + IL_0002: call instance int32 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_Tag() + IL_0007: ldc.i4.0 + IL_0008: bne.un.s IL_000c + + IL_000a: br.s IL_0019 + + IL_000c: ldarga.s x + IL_000e: call instance !1 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ErrorValue() + IL_0013: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_0018: ret + + IL_0019: ldarga.s x + IL_001b: call instance !0 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ResultValue() + IL_0020: stloc.0 + IL_0021: ldloc.0 + IL_0022: stloc.1 + IL_0023: ldloca.s V_1 + IL_0025: constrained. !!a + IL_002b: callvirt instance string [runtime]System.Object::ToString() + IL_0030: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_0035: ret + } + + .method public static valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 ffs(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 x) cil managed + { + + .maxstack 8 + IL_0000: ldarga.s x + IL_0002: call instance int32 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_Tag() + IL_0007: ldc.i4.0 + IL_0008: bne.un.s IL_000c + + IL_000a: br.s IL_0019 + + IL_000c: ldarga.s x + IL_000e: call instance !1 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ErrorValue() + IL_0013: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_0018: ret + + IL_0019: ldarga.s x + IL_001b: call instance !0 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::get_ResultValue() + IL_0020: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_0025: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Du_for_same_expression$fsx::init@ + IL_0006: ldsfld int32 ''.$Du_for_same_expression$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 3 + IL_0000: ldstr "" + IL_0005: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_000a: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ff(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_000f: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_0014: call void [runtime]System.Console::WriteLine(object) + IL_0019: ldstr "" + IL_001e: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewOk(!0) + IL_0023: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ffs(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_0028: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_002d: call void [runtime]System.Console::WriteLine(object) + IL_0032: ldstr "" + IL_0037: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_003c: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ff(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_0041: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_0046: call void [runtime]System.Console::WriteLine(object) + IL_004b: ldstr "" + IL_0050: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2::NewError(!1) + IL_0055: call valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 Du_for_same_expression::ffs(valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2) + IL_005a: box valuetype [FSharp.Core]Microsoft.FSharp.Core.FSharpResult`2 + IL_005f: call void [runtime]System.Console::WriteLine(object) + IL_0064: ret + } + +} + +.class private abstract auto ansi sealed ''.$Du_for_same_expression$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Du_for_same_expression::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_custom_step.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_custom_step.fsx new file mode 100644 index 00000000000..bd9d176ddea --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_custom_step.fsx @@ -0,0 +1,13 @@ +// +// { "optimization": { "reported_in": "#9548", "reported_by": "@teo-tsirpanis" +// , "last_know_version_not_optimizing": "8", "first_known_version_optimizing": 9 +// , "fixed_in" :"#16650", "fixed_by": "@brianrourkeboll"} +// } +// + +open System + +let g() = + for x in 0 .. 2 .. 15 do + Console.WriteLine x +g() \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_custom_step.fsx.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_custom_step.fsx.il.net472.bsl new file mode 100644 index 00000000000..5cef9f96c1e --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_custom_step.fsx.il.net472.bsl @@ -0,0 +1,131 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed For_loop_custom_step + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static void g() cil managed + { + + .maxstack 5 + .locals init (class [runtime]System.Collections.Generic.IEnumerable`1 V_0, + class [runtime]System.Collections.Generic.IEnumerator`1 V_1, + class [runtime]System.IDisposable V_2) + IL_0000: ldc.i4.0 + IL_0001: ldc.i4.2 + IL_0002: ldc.i4.s 15 + IL_0004: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, + int32, + int32) + IL_0009: stloc.0 + IL_000a: ldloc.0 + IL_000b: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0010: stloc.1 + .try + { + IL_0011: br.s IL_001e + + IL_0013: ldloc.1 + IL_0014: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0019: call void [runtime]System.Console::WriteLine(int32) + IL_001e: ldloc.1 + IL_001f: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0024: brtrue.s IL_0013 + + IL_0026: leave.s IL_003a + + } + finally + { + IL_0028: ldloc.1 + IL_0029: isinst [runtime]System.IDisposable + IL_002e: stloc.2 + IL_002f: ldloc.2 + IL_0030: brfalse.s IL_0039 + + IL_0032: ldloc.2 + IL_0033: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0038: endfinally + IL_0039: endfinally + } + IL_003a: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$For_loop_custom_step$fsx::init@ + IL_0006: ldsfld int32 ''.$For_loop_custom_step$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void For_loop_custom_step::g() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$For_loop_custom_step$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void For_loop_custom_step::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_custom_step.fsx.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_custom_step.fsx.il.netcore.bsl new file mode 100644 index 00000000000..3f1c43f9852 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_custom_step.fsx.il.netcore.bsl @@ -0,0 +1,132 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern runtime { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed For_loop_custom_step + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static void g() cil managed + { + + .maxstack 5 + .locals init (class [runtime]System.Collections.Generic.IEnumerable`1 V_0, + class [runtime]System.Collections.Generic.IEnumerator`1 V_1, + class [runtime]System.IDisposable V_2) + IL_0000: ldc.i4.0 + IL_0001: ldc.i4.2 + IL_0002: ldc.i4.s 15 + IL_0004: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, + int32, + int32) + IL_0009: stloc.0 + IL_000a: ldloc.0 + IL_000b: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0010: stloc.1 + .try + { + IL_0011: br.s IL_001e + + IL_0013: ldloc.1 + IL_0014: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0019: call void [runtime]System.Console::WriteLine(int32) + IL_001e: ldloc.1 + IL_001f: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0024: brtrue.s IL_0013 + + IL_0026: leave.s IL_003a + + } + finally + { + IL_0028: ldloc.1 + IL_0029: isinst [runtime]System.IDisposable + IL_002e: stloc.2 + IL_002f: ldloc.2 + IL_0030: brfalse.s IL_0039 + + IL_0032: ldloc.2 + IL_0033: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0038: endfinally + IL_0039: endfinally + } + IL_003a: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$For_loop_custom_step$fsx::init@ + IL_0006: ldsfld int32 ''.$For_loop_custom_step$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void For_loop_custom_step::g() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$For_loop_custom_step$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void For_loop_custom_step::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx new file mode 100644 index 00000000000..a97f88ce83e --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx @@ -0,0 +1,4 @@ +// +// { "optimization": { "reported_in": "#9548", "reported_by": "@cartermp", "last_know_version_not_optimizing": "8", "first_known_version_optimizing": null } } +// +for x in 0L..100L do printfn "hello" \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx.il.net472.debug.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx.il.net472.debug.bsl new file mode 100644 index 00000000000..013cc35284e --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx.il.net472.debug.bsl @@ -0,0 +1,161 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed For_loop_non_int + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .field static assembly class [runtime]System.Collections.Generic.IEnumerable`1 inputSequence@4 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .field static assembly class [runtime]System.Collections.Generic.IEnumerator`1 enumerator@4 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method assembly specialname static class [runtime]System.Collections.Generic.IEnumerable`1 get_inputSequence@4() cil managed + { + + .maxstack 8 + IL_0000: ldsfld class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::inputSequence@4 + IL_0005: ret + } + + .method assembly specialname static class [runtime]System.Collections.Generic.IEnumerator`1 get_enumerator@4() cil managed + { + + .maxstack 8 + IL_0000: ldsfld class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::enumerator@4 + IL_0005: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$For_loop_non_int$fsx::init@ + IL_0006: ldsfld int32 ''.$For_loop_non_int$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 5 + .locals init (int64 V_0, + class [runtime]System.IDisposable V_1) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: ldc.i4.1 + IL_0003: conv.i8 + IL_0004: ldc.i4.s 100 + IL_0006: conv.i8 + IL_0007: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt64(int64, + int64, + int64) + IL_000c: stsfld class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::inputSequence@4 + IL_0011: call class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::get_inputSequence@4() + IL_0016: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_001b: stsfld class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::enumerator@4 + .try + { + IL_0020: br.s IL_003d + + IL_0022: call class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + IL_0027: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_002c: stloc.0 + IL_002d: ldstr "hello" + IL_0032: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5::.ctor(string) + IL_0037: call !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4) + IL_003c: pop + IL_003d: call class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + IL_0042: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0047: brtrue.s IL_0022 + + IL_0049: leave.s IL_0061 + + } + finally + { + IL_004b: call class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + IL_0050: isinst [runtime]System.IDisposable + IL_0055: stloc.1 + IL_0056: ldloc.1 + IL_0057: brfalse.s IL_0060 + + IL_0059: ldloc.1 + IL_005a: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_005f: endfinally + IL_0060: endfinally + } + IL_0061: ret + } + + .property class [runtime]System.Collections.Generic.IEnumerable`1 + inputSequence@4() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 ) + .get class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::get_inputSequence@4() + } + .property class [runtime]System.Collections.Generic.IEnumerator`1 + enumerator@4() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 ) + .get class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + } +} + +.class private abstract auto ansi sealed ''.$For_loop_non_int$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void For_loop_non_int::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx.il.net472.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx.il.net472.release.bsl new file mode 100644 index 00000000000..be756f243a8 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx.il.net472.release.bsl @@ -0,0 +1,171 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern netstandard +{ + .publickeytoken = (CC 7B 13 FF CD 2D DD 51 ) + .ver 2:0:0:0 +} +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed For_loop_non_int + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .field static assembly class [runtime]System.Collections.Generic.IEnumerable`1 inputSequence@4 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .field static assembly class [runtime]System.Collections.Generic.IEnumerator`1 enumerator@4 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method assembly specialname static class [runtime]System.Collections.Generic.IEnumerable`1 get_inputSequence@4() cil managed + { + + .maxstack 8 + IL_0000: ldsfld class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::inputSequence@4 + IL_0005: ret + } + + .method assembly specialname static class [runtime]System.Collections.Generic.IEnumerator`1 get_enumerator@4() cil managed + { + + .maxstack 8 + IL_0000: ldsfld class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::enumerator@4 + IL_0005: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$For_loop_non_int$fsx::init@ + IL_0006: ldsfld int32 ''.$For_loop_non_int$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 5 + .locals init (int64 V_0, + class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4 V_1, + class [runtime]System.IDisposable V_2) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: ldc.i4.1 + IL_0003: conv.i8 + IL_0004: ldc.i4.s 100 + IL_0006: conv.i8 + IL_0007: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt64(int64, + int64, + int64) + IL_000c: stsfld class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::inputSequence@4 + IL_0011: call class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::get_inputSequence@4() + IL_0016: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_001b: stsfld class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::enumerator@4 + .try + { + IL_0020: br.s IL_0044 + + IL_0022: call class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + IL_0027: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_002c: stloc.0 + IL_002d: ldstr "hello" + IL_0032: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5::.ctor(string) + IL_0037: stloc.1 + IL_0038: call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out() + IL_003d: ldloc.1 + IL_003e: call !!0 [FSharp.Core]Microsoft.FSharp.Core.PrintfModule::PrintFormatLineToTextWriter(class [runtime]System.IO.TextWriter, + class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4) + IL_0043: pop + IL_0044: call class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + IL_0049: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_004e: brtrue.s IL_0022 + + IL_0050: leave.s IL_0068 + + } + finally + { + IL_0052: call class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + IL_0057: isinst [runtime]System.IDisposable + IL_005c: stloc.2 + IL_005d: ldloc.2 + IL_005e: brfalse.s IL_0067 + + IL_0060: ldloc.2 + IL_0061: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0066: endfinally + IL_0067: endfinally + } + IL_0068: ret + } + + .property class [runtime]System.Collections.Generic.IEnumerable`1 + inputSequence@4() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 ) + .get class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::get_inputSequence@4() + } + .property class [runtime]System.Collections.Generic.IEnumerator`1 + enumerator@4() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 ) + .get class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + } +} + +.class private abstract auto ansi sealed ''.$For_loop_non_int$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void For_loop_non_int::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx.il.netcore.debug.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx.il.netcore.debug.bsl new file mode 100644 index 00000000000..1c8f81f7893 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx.il.netcore.debug.bsl @@ -0,0 +1,161 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed For_loop_non_int + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .field static assembly class [runtime]System.Collections.Generic.IEnumerable`1 inputSequence@4 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .field static assembly class [runtime]System.Collections.Generic.IEnumerator`1 enumerator@4 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method assembly specialname static class [runtime]System.Collections.Generic.IEnumerable`1 get_inputSequence@4() cil managed + { + + .maxstack 8 + IL_0000: ldsfld class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::inputSequence@4 + IL_0005: ret + } + + .method assembly specialname static class [runtime]System.Collections.Generic.IEnumerator`1 get_enumerator@4() cil managed + { + + .maxstack 8 + IL_0000: ldsfld class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::enumerator@4 + IL_0005: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$For_loop_non_int$fsx::init@ + IL_0006: ldsfld int32 ''.$For_loop_non_int$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 5 + .locals init (int64 V_0, + class [runtime]System.IDisposable V_1) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: ldc.i4.1 + IL_0003: conv.i8 + IL_0004: ldc.i4.s 100 + IL_0006: conv.i8 + IL_0007: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt64(int64, + int64, + int64) + IL_000c: stsfld class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::inputSequence@4 + IL_0011: call class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::get_inputSequence@4() + IL_0016: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_001b: stsfld class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::enumerator@4 + .try + { + IL_0020: br.s IL_003d + + IL_0022: call class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + IL_0027: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_002c: stloc.0 + IL_002d: ldstr "hello" + IL_0032: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5::.ctor(string) + IL_0037: call !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4) + IL_003c: pop + IL_003d: call class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + IL_0042: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0047: brtrue.s IL_0022 + + IL_0049: leave.s IL_0061 + + } + finally + { + IL_004b: call class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + IL_0050: isinst [runtime]System.IDisposable + IL_0055: stloc.1 + IL_0056: ldloc.1 + IL_0057: brfalse.s IL_0060 + + IL_0059: ldloc.1 + IL_005a: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_005f: endfinally + IL_0060: endfinally + } + IL_0061: ret + } + + .property class [runtime]System.Collections.Generic.IEnumerable`1 + inputSequence@4() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 ) + .get class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::get_inputSequence@4() + } + .property class [runtime]System.Collections.Generic.IEnumerator`1 + enumerator@4() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 ) + .get class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + } +} + +.class private abstract auto ansi sealed ''.$For_loop_non_int$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void For_loop_non_int::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx.il.netcore.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx.il.netcore.release.bsl new file mode 100644 index 00000000000..4e86c17fd04 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/for_loop_non_int.fsx.il.netcore.release.bsl @@ -0,0 +1,171 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern netstandard +{ + .publickeytoken = (CC 7B 13 FF CD 2D DD 51 ) + .ver 2:1:0:0 +} +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed For_loop_non_int + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .field static assembly class [runtime]System.Collections.Generic.IEnumerable`1 inputSequence@4 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .field static assembly class [runtime]System.Collections.Generic.IEnumerator`1 enumerator@4 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method assembly specialname static class [runtime]System.Collections.Generic.IEnumerable`1 get_inputSequence@4() cil managed + { + + .maxstack 8 + IL_0000: ldsfld class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::inputSequence@4 + IL_0005: ret + } + + .method assembly specialname static class [runtime]System.Collections.Generic.IEnumerator`1 get_enumerator@4() cil managed + { + + .maxstack 8 + IL_0000: ldsfld class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::enumerator@4 + IL_0005: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$For_loop_non_int$fsx::init@ + IL_0006: ldsfld int32 ''.$For_loop_non_int$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 5 + .locals init (int64 V_0, + class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4 V_1, + class [runtime]System.IDisposable V_2) + IL_0000: ldc.i4.0 + IL_0001: conv.i8 + IL_0002: ldc.i4.1 + IL_0003: conv.i8 + IL_0004: ldc.i4.s 100 + IL_0006: conv.i8 + IL_0007: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt64(int64, + int64, + int64) + IL_000c: stsfld class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::inputSequence@4 + IL_0011: call class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::get_inputSequence@4() + IL_0016: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_001b: stsfld class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::enumerator@4 + .try + { + IL_0020: br.s IL_0044 + + IL_0022: call class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + IL_0027: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_002c: stloc.0 + IL_002d: ldstr "hello" + IL_0032: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5::.ctor(string) + IL_0037: stloc.1 + IL_0038: call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out() + IL_003d: ldloc.1 + IL_003e: call !!0 [FSharp.Core]Microsoft.FSharp.Core.PrintfModule::PrintFormatLineToTextWriter(class [runtime]System.IO.TextWriter, + class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4) + IL_0043: pop + IL_0044: call class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + IL_0049: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_004e: brtrue.s IL_0022 + + IL_0050: leave.s IL_0068 + + } + finally + { + IL_0052: call class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + IL_0057: isinst [runtime]System.IDisposable + IL_005c: stloc.2 + IL_005d: ldloc.2 + IL_005e: brfalse.s IL_0067 + + IL_0060: ldloc.2 + IL_0061: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0066: endfinally + IL_0067: endfinally + } + IL_0068: ret + } + + .property class [runtime]System.Collections.Generic.IEnumerable`1 + inputSequence@4() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 ) + .get class [runtime]System.Collections.Generic.IEnumerable`1 For_loop_non_int::get_inputSequence@4() + } + .property class [runtime]System.Collections.Generic.IEnumerator`1 + enumerator@4() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 ) + .get class [runtime]System.Collections.Generic.IEnumerator`1 For_loop_non_int::get_enumerator@4() + } +} + +.class private abstract auto ansi sealed ''.$For_loop_non_int$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void For_loop_non_int::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/if_then_else_bool_expression.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/if_then_else_bool_expression.fsx new file mode 100644 index 00000000000..14ef1aed364 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/if_then_else_bool_expression.fsx @@ -0,0 +1,13 @@ +// +// { "optimization": { "reported_in": "#16302", "reported_by": "@thorium", "last_know_version_not_optimizing": "8", "first_known_version_optimizing": null } } +// +let foo a b = + if a then false + elif b then false + else true + +let bar a b = + not(a || b) + +System.Console.WriteLine(foo true false) +System.Console.WriteLine(bar true false) \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/if_then_else_bool_expression.fsx.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/if_then_else_bool_expression.fsx.il.net472.bsl new file mode 100644 index 00000000000..ee9de97e33f --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/if_then_else_bool_expression.fsx.il.net472.bsl @@ -0,0 +1,133 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed If_then_else_bool_expression + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static bool foo(bool a, + bool b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: brfalse.s IL_0005 + + IL_0003: ldc.i4.0 + IL_0004: ret + + IL_0005: ldarg.1 + IL_0006: brfalse.s IL_000a + + IL_0008: ldc.i4.0 + IL_0009: ret + + IL_000a: ldc.i4.1 + IL_000b: ret + } + + .method public static bool bar(bool a, + bool b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: brtrue.s IL_0008 + + IL_0003: ldarg.1 + IL_0004: ldc.i4.0 + IL_0005: ceq + IL_0007: ret + + IL_0008: ldc.i4.0 + IL_0009: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$If_then_else_bool_expression$fsx::init@ + IL_0006: ldsfld int32 ''.$If_then_else_bool_expression$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldc.i4.0 + IL_0002: call bool If_then_else_bool_expression::foo(bool, + bool) + IL_0007: call void [runtime]System.Console::WriteLine(bool) + IL_000c: ldc.i4.1 + IL_000d: ldc.i4.0 + IL_000e: call bool If_then_else_bool_expression::bar(bool, + bool) + IL_0013: call void [runtime]System.Console::WriteLine(bool) + IL_0018: ret + } + +} + +.class private abstract auto ansi sealed ''.$If_then_else_bool_expression$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void If_then_else_bool_expression::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/if_then_else_bool_expression.fsx.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/if_then_else_bool_expression.fsx.il.netcore.bsl new file mode 100644 index 00000000000..0a45b2f2763 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/if_then_else_bool_expression.fsx.il.netcore.bsl @@ -0,0 +1,134 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern runtime { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed If_then_else_bool_expression + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static bool foo(bool a, + bool b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: brfalse.s IL_0005 + + IL_0003: ldc.i4.0 + IL_0004: ret + + IL_0005: ldarg.1 + IL_0006: brfalse.s IL_000a + + IL_0008: ldc.i4.0 + IL_0009: ret + + IL_000a: ldc.i4.1 + IL_000b: ret + } + + .method public static bool bar(bool a, + bool b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: brtrue.s IL_0008 + + IL_0003: ldarg.1 + IL_0004: ldc.i4.0 + IL_0005: ceq + IL_0007: ret + + IL_0008: ldc.i4.0 + IL_0009: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$If_then_else_bool_expression$fsx::init@ + IL_0006: ldsfld int32 ''.$If_then_else_bool_expression$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldc.i4.0 + IL_0002: call bool If_then_else_bool_expression::foo(bool, + bool) + IL_0007: call void [runtime]System.Console::WriteLine(bool) + IL_000c: ldc.i4.1 + IL_000d: ldc.i4.0 + IL_000e: call bool If_then_else_bool_expression::bar(bool, + bool) + IL_0013: call void [runtime]System.Console::WriteLine(bool) + IL_0018: ret + } + +} + +.class private abstract auto ansi sealed ''.$If_then_else_bool_expression$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void If_then_else_bool_expression::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/inplace_array_update.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/inplace_array_update.fsx new file mode 100644 index 00000000000..0d510934254 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/inplace_array_update.fsx @@ -0,0 +1,32 @@ +// +// { "optimization": { "reported_in": "#6499", "reported_by": "@atlemann,@cartermp", "last_know_version_not_optimizing": "8", "first_known_version_optimizing": null } } +// +module Foo = + + let bar (f : 'a -> 'a -> 'a) (a:'a array) (b:'a array) = + Array.map2 f a b + + let barInPlace (f : 'a -> 'a -> 'a) (a:'a array) (b:'a array) = + for i in 0..b.Length - 1 do + b.[i] <- f a.[i] b.[i] + + let inline barInPlaceInline (f : 'a -> 'a -> 'a) (a:'a array) (b:'a array) = + for i in 0..b.Length - 1 do + b.[i] <- f a.[i] b.[i] + + let barInPlaceOptClosure (f : 'a -> 'a -> 'a) (a:'a array) (b:'a array) = + let func = OptimizedClosures.FSharpFunc<'a, 'a, 'a>.Adapt(f) + for i in 0..b.Length - 1 do + b.[i] <- func.Invoke(a.[i], b.[i]) + + let inline barInPlaceOptClosureInline (f : 'a -> 'a -> 'a) (a:'a array) (b:'a array) = + let func = OptimizedClosures.FSharpFunc<'a, 'a, 'a>.Adapt(f) + for i in 0..b.Length - 1 do + b.[i] <- func.Invoke(a.[i], b.[i]) + + let barFunInside (a:single array) (b:single array) = + let f = (fun a b -> a * 0.7f + b * 0.3f) + for i in 0..b.Length - 1 do + b.[i] <- f a.[i] b.[i] + +System.Console.WriteLine() \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/inplace_array_update.fsx.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/inplace_array_update.fsx.il.net472.bsl new file mode 100644 index 00000000000..5b3fea2cc3f --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/inplace_array_update.fsx.il.net472.bsl @@ -0,0 +1,314 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Inplace_array_update + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto ansi sealed nested public Foo + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static !!a[] bar(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f, + !!a[] a, + !!a[] b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: tail. + IL_0005: call !!2[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map2(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0[], + !!1[]) + IL_000a: ret + } + + .method public static void barInPlace(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f, + !!a[] a, + !!a[] b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_0023 + + IL_0004: ldarg.2 + IL_0005: ldloc.0 + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: ldloc.0 + IL_0009: ldelem !!a + IL_000e: ldarg.2 + IL_000f: ldloc.0 + IL_0010: ldelem !!a + IL_0015: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_001a: stelem !!a + IL_001f: ldloc.0 + IL_0020: ldc.i4.1 + IL_0021: add + IL_0022: stloc.0 + IL_0023: ldloc.0 + IL_0024: ldarg.2 + IL_0025: ldlen + IL_0026: conv.i4 + IL_0027: blt.s IL_0004 + + IL_0029: ret + } + + .method public static void barInPlaceInline(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f, + !!a[] a, + !!a[] b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_0023 + + IL_0004: ldarg.2 + IL_0005: ldloc.0 + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: ldloc.0 + IL_0009: ldelem !!a + IL_000e: ldarg.2 + IL_000f: ldloc.0 + IL_0010: ldelem !!a + IL_0015: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_001a: stelem !!a + IL_001f: ldloc.0 + IL_0020: ldc.i4.1 + IL_0021: add + IL_0022: stloc.0 + IL_0023: ldloc.0 + IL_0024: ldarg.2 + IL_0025: ldlen + IL_0026: conv.i4 + IL_0027: blt.s IL_0004 + + IL_0029: ret + } + + .method public static void barInPlaceOptClosure(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f, + !!a[] a, + !!a[] b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: call class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Adapt(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: stloc.1 + IL_0009: br.s IL_002a + + IL_000b: ldarg.2 + IL_000c: ldloc.1 + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: ldloc.1 + IL_0010: ldelem !!a + IL_0015: ldarg.2 + IL_0016: ldloc.1 + IL_0017: ldelem !!a + IL_001c: callvirt instance !2 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Invoke(!0, + !1) + IL_0021: stelem !!a + IL_0026: ldloc.1 + IL_0027: ldc.i4.1 + IL_0028: add + IL_0029: stloc.1 + IL_002a: ldloc.1 + IL_002b: ldarg.2 + IL_002c: ldlen + IL_002d: conv.i4 + IL_002e: blt.s IL_000b + + IL_0030: ret + } + + .method public static void barInPlaceOptClosureInline(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f, + !!a[] a, + !!a[] b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: call class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Adapt(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: stloc.1 + IL_0009: br.s IL_002a + + IL_000b: ldarg.2 + IL_000c: ldloc.1 + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: ldloc.1 + IL_0010: ldelem !!a + IL_0015: ldarg.2 + IL_0016: ldloc.1 + IL_0017: ldelem !!a + IL_001c: callvirt instance !2 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Invoke(!0, + !1) + IL_0021: stelem !!a + IL_0026: ldloc.1 + IL_0027: ldc.i4.1 + IL_0028: add + IL_0029: stloc.1 + IL_002a: ldloc.1 + IL_002b: ldarg.2 + IL_002c: ldlen + IL_002d: conv.i4 + IL_002e: blt.s IL_000b + + IL_0030: ret + } + + .method public static void barFunInside(float32[] a, + float32[] b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 7 + .locals init (int32 V_0, + float32 V_1, + float32 V_2) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_002e + + IL_0004: ldarg.1 + IL_0005: ldloc.0 + IL_0006: ldarg.0 + IL_0007: ldloc.0 + IL_0008: ldelem [runtime]System.Single + IL_000d: stloc.1 + IL_000e: ldarg.1 + IL_000f: ldloc.0 + IL_0010: ldelem [runtime]System.Single + IL_0015: stloc.2 + IL_0016: ldloc.1 + IL_0017: ldc.r4 0.69999999 + IL_001c: mul + IL_001d: ldloc.2 + IL_001e: ldc.r4 0.30000001 + IL_0023: mul + IL_0024: add + IL_0025: stelem [runtime]System.Single + IL_002a: ldloc.0 + IL_002b: ldc.i4.1 + IL_002c: add + IL_002d: stloc.0 + IL_002e: ldloc.0 + IL_002f: ldarg.1 + IL_0030: ldlen + IL_0031: conv.i4 + IL_0032: blt.s IL_0004 + + IL_0034: ret + } + + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Inplace_array_update$fsx::init@ + IL_0006: ldsfld int32 ''.$Inplace_array_update$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Inplace_array_update$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Inplace_array_update::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/inplace_array_update.fsx.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/inplace_array_update.fsx.il.netcore.bsl new file mode 100644 index 00000000000..8b377601531 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/inplace_array_update.fsx.il.netcore.bsl @@ -0,0 +1,315 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern runtime { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Inplace_array_update + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto ansi sealed nested public Foo + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static !!a[] bar(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f, + !!a[] a, + !!a[] b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: ldarg.2 + IL_0003: tail. + IL_0005: call !!2[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map2(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0[], + !!1[]) + IL_000a: ret + } + + .method public static void barInPlace(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f, + !!a[] a, + !!a[] b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_0023 + + IL_0004: ldarg.2 + IL_0005: ldloc.0 + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: ldloc.0 + IL_0009: ldelem !!a + IL_000e: ldarg.2 + IL_000f: ldloc.0 + IL_0010: ldelem !!a + IL_0015: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_001a: stelem !!a + IL_001f: ldloc.0 + IL_0020: ldc.i4.1 + IL_0021: add + IL_0022: stloc.0 + IL_0023: ldloc.0 + IL_0024: ldarg.2 + IL_0025: ldlen + IL_0026: conv.i4 + IL_0027: blt.s IL_0004 + + IL_0029: ret + } + + .method public static void barInPlaceInline(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f, + !!a[] a, + !!a[] b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_0023 + + IL_0004: ldarg.2 + IL_0005: ldloc.0 + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: ldloc.0 + IL_0009: ldelem !!a + IL_000e: ldarg.2 + IL_000f: ldloc.0 + IL_0010: ldelem !!a + IL_0015: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_001a: stelem !!a + IL_001f: ldloc.0 + IL_0020: ldc.i4.1 + IL_0021: add + IL_0022: stloc.0 + IL_0023: ldloc.0 + IL_0024: ldarg.2 + IL_0025: ldlen + IL_0026: conv.i4 + IL_0027: blt.s IL_0004 + + IL_0029: ret + } + + .method public static void barInPlaceOptClosure(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f, + !!a[] a, + !!a[] b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: call class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Adapt(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: stloc.1 + IL_0009: br.s IL_002a + + IL_000b: ldarg.2 + IL_000c: ldloc.1 + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: ldloc.1 + IL_0010: ldelem !!a + IL_0015: ldarg.2 + IL_0016: ldloc.1 + IL_0017: ldelem !!a + IL_001c: callvirt instance !2 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Invoke(!0, + !1) + IL_0021: stelem !!a + IL_0026: ldloc.1 + IL_0027: ldc.i4.1 + IL_0028: add + IL_0029: stloc.1 + IL_002a: ldloc.1 + IL_002b: ldarg.2 + IL_002c: ldlen + IL_002d: conv.i4 + IL_002e: blt.s IL_000b + + IL_0030: ret + } + + .method public static void barInPlaceOptClosureInline(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f, + !!a[] a, + !!a[] b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 V_0, + int32 V_1) + IL_0000: ldarg.0 + IL_0001: call class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Adapt(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: stloc.1 + IL_0009: br.s IL_002a + + IL_000b: ldarg.2 + IL_000c: ldloc.1 + IL_000d: ldloc.0 + IL_000e: ldarg.1 + IL_000f: ldloc.1 + IL_0010: ldelem !!a + IL_0015: ldarg.2 + IL_0016: ldloc.1 + IL_0017: ldelem !!a + IL_001c: callvirt instance !2 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Invoke(!0, + !1) + IL_0021: stelem !!a + IL_0026: ldloc.1 + IL_0027: ldc.i4.1 + IL_0028: add + IL_0029: stloc.1 + IL_002a: ldloc.1 + IL_002b: ldarg.2 + IL_002c: ldlen + IL_002d: conv.i4 + IL_002e: blt.s IL_000b + + IL_0030: ret + } + + .method public static void barFunInside(float32[] a, + float32[] b) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 7 + .locals init (int32 V_0, + float32 V_1, + float32 V_2) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_002e + + IL_0004: ldarg.1 + IL_0005: ldloc.0 + IL_0006: ldarg.0 + IL_0007: ldloc.0 + IL_0008: ldelem [runtime]System.Single + IL_000d: stloc.1 + IL_000e: ldarg.1 + IL_000f: ldloc.0 + IL_0010: ldelem [runtime]System.Single + IL_0015: stloc.2 + IL_0016: ldloc.1 + IL_0017: ldc.r4 0.69999999 + IL_001c: mul + IL_001d: ldloc.2 + IL_001e: ldc.r4 0.30000001 + IL_0023: mul + IL_0024: add + IL_0025: stelem [runtime]System.Single + IL_002a: ldloc.0 + IL_002b: ldc.i4.1 + IL_002c: add + IL_002d: stloc.0 + IL_002e: ldloc.0 + IL_002f: ldarg.1 + IL_0030: ldlen + IL_0031: conv.i4 + IL_0032: blt.s IL_0004 + + IL_0034: ret + } + + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Inplace_array_update$fsx::init@ + IL_0006: ldsfld int32 ''.$Inplace_array_update$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Inplace_array_update$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Inplace_array_update::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/lambda_inlining.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/lambda_inlining.fsx new file mode 100644 index 00000000000..9889aefa075 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/lambda_inlining.fsx @@ -0,0 +1,37 @@ +// +// { "optimization": { "reported_in": "#12416", "reported_by": "@mrange", "last_know_version_not_optimizing": "8", "first_known_version_optimizing": null } } +// +type 'T PushStream = ('T -> bool) -> bool + +let inline ofArray (vs : _ array) : _ PushStream = fun ([] r) -> + let mutable i = 0 + while i < vs.Length && r vs.[i] do + i <- i + 1 + i = vs.Length + +let inline fold ([] f) z ([] ps : _ PushStream) = + let mutable s = z + let _ = ps (fun v -> s <- f s v; true) + s + +let values = [|0..10000|] + +let thisIsInlined1 () = fold (+) 0 (ofArray values) +let thisIsInlined2 () = + let vs = [|0..10000|] + fold (+) 0 (ofArray vs) + +let thisIsNotInlined1 () = fold (+) 0 (ofArray [|0..10000|]) + +type Test() = + let _values = [|0..10000|] + static let _svalues = [|0..10000|] + + let array vs = fold (+) 0 (ofArray vs) + + member x.thisIsInlined2 () = fold (+) 0 (ofArray values) + member x.thisIsInlined3 () = array _values + + member x.thisIsNotInlined2 () = fold (+) 0 (ofArray _values) + member x.thisIsNotInlined3 () = fold (+) 0 (ofArray _svalues) + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/lambda_inlining.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/lambda_inlining.fsx.il.bsl new file mode 100644 index 00000000000..b4314541564 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/lambda_inlining.fsx.il.bsl @@ -0,0 +1,890 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Lambda_inlining + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested assembly beforefieldinit fold@14 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 s + .method assembly specialname rtspecialname + instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 s) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> class Lambda_inlining/fold@14::f + IL_000d: ldarg.0 + IL_000e: ldarg.2 + IL_000f: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 class Lambda_inlining/fold@14::s + IL_0014: ret + } + + .method public strict virtual instance bool Invoke(!b v) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 class Lambda_inlining/fold@14::s + IL_0006: ldarg.0 + IL_0007: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> class Lambda_inlining/fold@14::f + IL_000c: ldarg.0 + IL_000d: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 class Lambda_inlining/fold@14::s + IL_0012: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::get_contents() + IL_0017: ldarg.1 + IL_0018: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_001d: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::set_contents(!0) + IL_0022: ldc.i4.1 + IL_0023: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit thisIsNotInlined1@24 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool> + { + .field public int32[] vs + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method assembly specialname rtspecialname instance void .ctor(int32[] vs) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool>::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32[] Lambda_inlining/thisIsNotInlined1@24::vs + IL_000d: ret + } + + .method public strict virtual instance bool Invoke(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 r) cil managed + { + + .maxstack 7 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_0008 + + IL_0004: ldloc.0 + IL_0005: ldc.i4.1 + IL_0006: add + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldarg.0 + IL_000a: ldfld int32[] Lambda_inlining/thisIsNotInlined1@24::vs + IL_000f: ldlen + IL_0010: conv.i4 + IL_0011: bge.s IL_0027 + + IL_0013: ldarg.1 + IL_0014: ldarg.0 + IL_0015: ldfld int32[] Lambda_inlining/thisIsNotInlined1@24::vs + IL_001a: ldloc.0 + IL_001b: ldelem [runtime]System.Int32 + IL_0020: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0025: br.s IL_0028 + + IL_0027: ldc.i4.0 + IL_0028: brtrue.s IL_0004 + + IL_002a: ldloc.0 + IL_002b: ldarg.0 + IL_002c: ldfld int32[] Lambda_inlining/thisIsNotInlined1@24::vs + IL_0031: ldlen + IL_0032: conv.i4 + IL_0033: ceq + IL_0035: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit 'thisIsNotInlined1@24-1' + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 s + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method assembly specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 s) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Lambda_inlining/'thisIsNotInlined1@24-1'::s + IL_000d: ret + } + + .method public strict virtual instance bool Invoke(int32 v) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Lambda_inlining/'thisIsNotInlined1@24-1'::s + IL_0006: ldarg.0 + IL_0007: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Lambda_inlining/'thisIsNotInlined1@24-1'::s + IL_000c: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::get_contents() + IL_0011: ldarg.1 + IL_0012: add + IL_0013: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::set_contents(!0) + IL_0018: ldc.i4.1 + IL_0019: ret + } + + } + + .class auto ansi serializable nested public Test + 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 ansi serializable sealed nested assembly beforefieldinit thisIsNotInlined2@35 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool> + { + .field public int32[] vs + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method assembly specialname rtspecialname instance void .ctor(int32[] vs) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool>::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32[] Lambda_inlining/Test/thisIsNotInlined2@35::vs + IL_000d: ret + } + + .method public strict virtual instance bool Invoke(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 r) cil managed + { + + .maxstack 7 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_0008 + + IL_0004: ldloc.0 + IL_0005: ldc.i4.1 + IL_0006: add + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldarg.0 + IL_000a: ldfld int32[] Lambda_inlining/Test/thisIsNotInlined2@35::vs + IL_000f: ldlen + IL_0010: conv.i4 + IL_0011: bge.s IL_0027 + + IL_0013: ldarg.1 + IL_0014: ldarg.0 + IL_0015: ldfld int32[] Lambda_inlining/Test/thisIsNotInlined2@35::vs + IL_001a: ldloc.0 + IL_001b: ldelem [runtime]System.Int32 + IL_0020: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0025: br.s IL_0028 + + IL_0027: ldc.i4.0 + IL_0028: brtrue.s IL_0004 + + IL_002a: ldloc.0 + IL_002b: ldarg.0 + IL_002c: ldfld int32[] Lambda_inlining/Test/thisIsNotInlined2@35::vs + IL_0031: ldlen + IL_0032: conv.i4 + IL_0033: ceq + IL_0035: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit 'thisIsNotInlined2@35-1' + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 s + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method assembly specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 s) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Lambda_inlining/Test/'thisIsNotInlined2@35-1'::s + IL_000d: ret + } + + .method public strict virtual instance bool Invoke(int32 v) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Lambda_inlining/Test/'thisIsNotInlined2@35-1'::s + IL_0006: ldarg.0 + IL_0007: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Lambda_inlining/Test/'thisIsNotInlined2@35-1'::s + IL_000c: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::get_contents() + IL_0011: ldarg.1 + IL_0012: add + IL_0013: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::set_contents(!0) + IL_0018: ldc.i4.1 + IL_0019: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit thisIsNotInlined3@36 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool> + { + .field public int32[] vs + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method assembly specialname rtspecialname instance void .ctor(int32[] vs) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool>::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld int32[] Lambda_inlining/Test/thisIsNotInlined3@36::vs + IL_000d: ret + } + + .method public strict virtual instance bool Invoke(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 r) cil managed + { + + .maxstack 7 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_0008 + + IL_0004: ldloc.0 + IL_0005: ldc.i4.1 + IL_0006: add + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldarg.0 + IL_000a: ldfld int32[] Lambda_inlining/Test/thisIsNotInlined3@36::vs + IL_000f: ldlen + IL_0010: conv.i4 + IL_0011: bge.s IL_0027 + + IL_0013: ldarg.1 + IL_0014: ldarg.0 + IL_0015: ldfld int32[] Lambda_inlining/Test/thisIsNotInlined3@36::vs + IL_001a: ldloc.0 + IL_001b: ldelem [runtime]System.Int32 + IL_0020: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0025: br.s IL_0028 + + IL_0027: ldc.i4.0 + IL_0028: brtrue.s IL_0004 + + IL_002a: ldloc.0 + IL_002b: ldarg.0 + IL_002c: ldfld int32[] Lambda_inlining/Test/thisIsNotInlined3@36::vs + IL_0031: ldlen + IL_0032: conv.i4 + IL_0033: ceq + IL_0035: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit 'thisIsNotInlined3@36-1' + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 s + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method assembly specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 s) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::.ctor() + IL_0006: ldarg.0 + IL_0007: ldarg.1 + IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Lambda_inlining/Test/'thisIsNotInlined3@36-1'::s + IL_000d: ret + } + + .method public strict virtual instance bool Invoke(int32 v) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Lambda_inlining/Test/'thisIsNotInlined3@36-1'::s + IL_0006: ldarg.0 + IL_0007: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Lambda_inlining/Test/'thisIsNotInlined3@36-1'::s + IL_000c: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::get_contents() + IL_0011: ldarg.1 + IL_0012: add + IL_0013: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::set_contents(!0) + IL_0018: ldc.i4.1 + IL_0019: ret + } + + } + + .field assembly int32[] _values + .field static assembly int32[] _svalues + .field static assembly int32 init@26 + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldc.i4.0 + IL_000a: ldc.i4.1 + IL_000b: ldc.i4 0x2710 + IL_0010: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, + int32, + int32) + IL_0015: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_001a: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToArray(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_001f: stfld int32[] Lambda_inlining/Test::_values + IL_0024: ret + } + + .method public hidebysig instance int32 thisIsInlined2() cil managed + { + + .maxstack 4 + .locals init (int32 V_0, + int32 V_1, + int32 V_2) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: ldc.i4.0 + IL_0003: stloc.1 + IL_0004: br.s IL_000a + + IL_0006: ldloc.1 + IL_0007: ldc.i4.1 + IL_0008: add + IL_0009: stloc.1 + IL_000a: ldloc.1 + IL_000b: call int32[] Lambda_inlining::get_values() + IL_0010: ldlen + IL_0011: conv.i4 + IL_0012: bge.s IL_0027 + + IL_0014: call int32[] Lambda_inlining::get_values() + IL_0019: ldloc.1 + IL_001a: ldelem [runtime]System.Int32 + IL_001f: stloc.2 + IL_0020: ldloc.0 + IL_0021: ldloc.2 + IL_0022: add + IL_0023: stloc.0 + IL_0024: ldc.i4.1 + IL_0025: br.s IL_0028 + + IL_0027: ldc.i4.0 + IL_0028: brtrue.s IL_0006 + + IL_002a: ldloc.1 + IL_002b: call int32[] Lambda_inlining::get_values() + IL_0030: ldlen + IL_0031: conv.i4 + IL_0032: ceq + IL_0034: pop + IL_0035: ldloc.0 + IL_0036: ret + } + + .method public hidebysig instance int32 thisIsInlined3() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.0 + IL_0002: ldfld int32[] Lambda_inlining/Test::_values + IL_0007: callvirt instance int32 Lambda_inlining/Test::'array'(int32[]) + IL_000c: ret + } + + .method public hidebysig instance int32 thisIsNotInlined2() cil managed + { + + .maxstack 4 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool> V_0, + int32[] V_1, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 V_2) + IL_0000: ldarg.0 + IL_0001: ldfld int32[] Lambda_inlining/Test::_values + IL_0006: stloc.1 + IL_0007: ldloc.1 + IL_0008: newobj instance void Lambda_inlining/Test/thisIsNotInlined2@35::.ctor(int32[]) + IL_000d: stloc.0 + IL_000e: ldc.i4.0 + IL_000f: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::.ctor(!0) + IL_0014: stloc.2 + IL_0015: ldloc.0 + IL_0016: ldloc.2 + IL_0017: newobj instance void Lambda_inlining/Test/'thisIsNotInlined2@35-1'::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1) + IL_001c: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool>::Invoke(!0) + IL_0021: pop + IL_0022: ldloc.2 + IL_0023: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::get_contents() + IL_0028: ret + } + + .method public hidebysig instance int32 thisIsNotInlined3() cil managed + { + + .maxstack 4 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool> V_0, + int32[] V_1, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 V_2) + IL_0000: volatile. + IL_0002: ldsfld int32 Lambda_inlining/Test::init@26 + IL_0007: ldc.i4.2 + IL_0008: bge.s IL_0011 + + IL_000a: call void [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/IntrinsicFunctions::FailStaticInit() + IL_000f: br.s IL_0011 + + IL_0011: ldsfld int32[] Lambda_inlining/Test::_svalues + IL_0016: stloc.1 + IL_0017: ldloc.1 + IL_0018: newobj instance void Lambda_inlining/Test/thisIsNotInlined3@36::.ctor(int32[]) + IL_001d: stloc.0 + IL_001e: ldc.i4.0 + IL_001f: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::.ctor(!0) + IL_0024: stloc.2 + IL_0025: ldloc.0 + IL_0026: ldloc.2 + IL_0027: newobj instance void Lambda_inlining/Test/'thisIsNotInlined3@36-1'::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1) + IL_002c: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool>::Invoke(!0) + IL_0031: pop + IL_0032: ldloc.2 + IL_0033: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::get_contents() + IL_0038: ret + } + + .method assembly hidebysig instance int32 'array'(int32[] vs) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 4 + .locals init (int32 V_0, + int32 V_1, + int32 V_2) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: ldc.i4.0 + IL_0003: stloc.1 + IL_0004: br.s IL_000a + + IL_0006: ldloc.1 + IL_0007: ldc.i4.1 + IL_0008: add + IL_0009: stloc.1 + IL_000a: ldloc.1 + IL_000b: ldarg.1 + IL_000c: ldlen + IL_000d: conv.i4 + IL_000e: bge.s IL_001f + + IL_0010: ldarg.1 + IL_0011: ldloc.1 + IL_0012: ldelem [runtime]System.Int32 + IL_0017: stloc.2 + IL_0018: ldloc.0 + IL_0019: ldloc.2 + IL_001a: add + IL_001b: stloc.0 + IL_001c: ldc.i4.1 + IL_001d: br.s IL_0020 + + IL_001f: ldc.i4.0 + IL_0020: brtrue.s IL_0006 + + IL_0022: ldloc.1 + IL_0023: ldarg.1 + IL_0024: ldlen + IL_0025: conv.i4 + IL_0026: ceq + IL_0028: pop + IL_0029: ldloc.0 + IL_002a: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Lambda_inlining$fsx::init@ + IL_0006: ldsfld int32 ''.$Lambda_inlining$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldc.i4.1 + IL_0002: ldc.i4 0x2710 + IL_0007: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, + int32, + int32) + IL_000c: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0011: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToArray(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0016: stsfld int32[] Lambda_inlining/Test::_svalues + IL_001b: ldc.i4.2 + IL_001c: volatile. + IL_001e: stsfld int32 Lambda_inlining/Test::init@26 + IL_0023: ret + } + + } + + .field static assembly int32[] values@17 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method public static bool ofArray(!!a[] vs, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 r) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + .param [2] + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.InlineIfLambdaAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 5 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: br.s IL_0008 + + IL_0004: ldloc.0 + IL_0005: ldc.i4.1 + IL_0006: add + IL_0007: stloc.0 + IL_0008: ldloc.0 + IL_0009: ldarg.0 + IL_000a: ldlen + IL_000b: conv.i4 + IL_000c: bge.s IL_001d + + IL_000e: ldarg.1 + IL_000f: ldarg.0 + IL_0010: ldloc.0 + IL_0011: ldelem !!a + IL_0016: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001b: br.s IL_001e + + IL_001d: ldc.i4.0 + IL_001e: brtrue.s IL_0004 + + IL_0020: ldloc.0 + IL_0021: ldarg.0 + IL_0022: ldlen + IL_0023: conv.i4 + IL_0024: ceq + IL_0026: ret + } + + .method public static !!a fold(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> f, + !!a z, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool> ps) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .param [1] + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.InlineIfLambdaAttribute::.ctor() = ( 01 00 00 00 ) + .param [3] + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.InlineIfLambdaAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 V_0) + IL_0000: ldarg.1 + IL_0001: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::.ctor(!0) + IL_0006: stloc.0 + IL_0007: ldarg.2 + IL_0008: ldarg.0 + IL_0009: ldloc.0 + IL_000a: newobj instance void class Lambda_inlining/fold@14::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1) + IL_000f: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool>::Invoke(!0) + IL_0014: pop + IL_0015: ldloc.0 + IL_0016: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::get_contents() + IL_001b: ret + } + + .method public specialname static int32[] get_values() cil managed + { + + .maxstack 8 + IL_0000: ldsfld int32[] Lambda_inlining::values@17 + IL_0005: ret + } + + .method public static int32 thisIsInlined1() cil managed + { + + .maxstack 4 + .locals init (int32 V_0, + int32 V_1, + int32 V_2) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: ldc.i4.0 + IL_0003: stloc.1 + IL_0004: br.s IL_000a + + IL_0006: ldloc.1 + IL_0007: ldc.i4.1 + IL_0008: add + IL_0009: stloc.1 + IL_000a: ldloc.1 + IL_000b: call int32[] Lambda_inlining::get_values() + IL_0010: ldlen + IL_0011: conv.i4 + IL_0012: bge.s IL_0027 + + IL_0014: call int32[] Lambda_inlining::get_values() + IL_0019: ldloc.1 + IL_001a: ldelem [runtime]System.Int32 + IL_001f: stloc.2 + IL_0020: ldloc.0 + IL_0021: ldloc.2 + IL_0022: add + IL_0023: stloc.0 + IL_0024: ldc.i4.1 + IL_0025: br.s IL_0028 + + IL_0027: ldc.i4.0 + IL_0028: brtrue.s IL_0006 + + IL_002a: ldloc.1 + IL_002b: call int32[] Lambda_inlining::get_values() + IL_0030: ldlen + IL_0031: conv.i4 + IL_0032: ceq + IL_0034: pop + IL_0035: ldloc.0 + IL_0036: ret + } + + .method public static int32 thisIsInlined2() cil managed + { + + .maxstack 5 + .locals init (int32[] V_0, + int32 V_1, + int32 V_2, + int32 V_3) + IL_0000: ldc.i4.0 + IL_0001: ldc.i4.1 + IL_0002: ldc.i4 0x2710 + IL_0007: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, + int32, + int32) + IL_000c: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0011: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToArray(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0016: stloc.0 + IL_0017: ldc.i4.0 + IL_0018: stloc.1 + IL_0019: ldc.i4.0 + IL_001a: stloc.2 + IL_001b: br.s IL_0021 + + IL_001d: ldloc.2 + IL_001e: ldc.i4.1 + IL_001f: add + IL_0020: stloc.2 + IL_0021: ldloc.2 + IL_0022: ldloc.0 + IL_0023: ldlen + IL_0024: conv.i4 + IL_0025: bge.s IL_0036 + + IL_0027: ldloc.0 + IL_0028: ldloc.2 + IL_0029: ldelem [runtime]System.Int32 + IL_002e: stloc.3 + IL_002f: ldloc.1 + IL_0030: ldloc.3 + IL_0031: add + IL_0032: stloc.1 + IL_0033: ldc.i4.1 + IL_0034: br.s IL_0037 + + IL_0036: ldc.i4.0 + IL_0037: brtrue.s IL_001d + + IL_0039: ldloc.2 + IL_003a: ldloc.0 + IL_003b: ldlen + IL_003c: conv.i4 + IL_003d: ceq + IL_003f: pop + IL_0040: ldloc.1 + IL_0041: ret + } + + .method public static int32 thisIsNotInlined1() cil managed + { + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool> V_0, + int32[] V_1, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 V_2) + IL_0000: ldc.i4.0 + IL_0001: ldc.i4.1 + IL_0002: ldc.i4 0x2710 + IL_0007: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, + int32, + int32) + IL_000c: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0011: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToArray(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0016: stloc.1 + IL_0017: ldloc.1 + IL_0018: newobj instance void Lambda_inlining/thisIsNotInlined1@24::.ctor(int32[]) + IL_001d: stloc.0 + IL_001e: ldc.i4.0 + IL_001f: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::.ctor(!0) + IL_0024: stloc.2 + IL_0025: ldloc.0 + IL_0026: ldloc.2 + IL_0027: newobj instance void Lambda_inlining/'thisIsNotInlined1@24-1'::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1) + IL_002c: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,bool>::Invoke(!0) + IL_0031: pop + IL_0032: ldloc.2 + IL_0033: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::get_contents() + IL_0038: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Lambda_inlining$fsx::init@ + IL_0006: ldsfld int32 ''.$Lambda_inlining$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldc.i4.1 + IL_0002: ldc.i4 0x2710 + IL_0007: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, + int32, + int32) + IL_000c: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0011: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToArray(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0016: stsfld int32[] Lambda_inlining::values@17 + IL_001b: call void Lambda_inlining/Test::staticInitialization@() + IL_0020: ret + } + + .property int32[] values() + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 ) + .get int32[] Lambda_inlining::get_values() + } +} + +.class private abstract auto ansi sealed ''.$Lambda_inlining$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Lambda_inlining::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/option_elision_non_constant_result.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/option_elision_non_constant_result.fsx new file mode 100644 index 00000000000..34398d16cce --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/option_elision_non_constant_result.fsx @@ -0,0 +1,24 @@ +// +// { "optimization": { "reported_in": "#8983", "reported_by": "@NinoFloris", "last_know_version_not_optimizing": "8", "first_known_version_optimizing": null } } +// + +let inline mapOption mapper option = + match option with + | Some x -> Some(mapper x) + | None -> None + +let almostErasedOption() = + let y () = 3 + + match Some(y()) |> mapOption (fun x -> x + 2) with + | Some x -> 5 + | None -> 4 + +let unnecessaryOption() = + let y () = 3 + + match Some(y()) |> mapOption (fun x -> x + 2) with + | Some x -> x + | None -> 4 + +System.Console.WriteLine() \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/option_elision_non_constant_result.fsx.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/option_elision_non_constant_result.fsx.il.net472.bsl new file mode 100644 index 00000000000..067bc74986d --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/option_elision_non_constant_result.fsx.il.net472.bsl @@ -0,0 +1,151 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Option_elision_non_constant_result + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 + mapOption(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 mapper, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 option) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 4 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 V_0, + !!a V_1) + IL_0000: ldarg.1 + IL_0001: brtrue.s IL_0005 + + IL_0003: br.s IL_001b + + IL_0005: ldarg.1 + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1::get_Value() + IL_000d: stloc.1 + IL_000e: ldarg.0 + IL_000f: ldloc.1 + IL_0010: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0015: call class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1::Some(!0) + IL_001a: ret + + IL_001b: ldnull + IL_001c: ret + } + + .method public static int32 almostErasedOption() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.5 + IL_0001: call class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1::Some(!0) + IL_0006: brtrue.s IL_000a + + IL_0008: br.s IL_000c + + IL_000a: ldc.i4.5 + IL_000b: ret + + IL_000c: ldc.i4.4 + IL_000d: ret + } + + .method public static int32 unnecessaryOption() cil managed + { + + .maxstack 3 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 V_0) + IL_0000: ldc.i4.5 + IL_0001: call class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1::Some(!0) + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: brtrue.s IL_000c + + IL_000a: br.s IL_0013 + + IL_000c: ldloc.0 + IL_000d: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1::get_Value() + IL_0012: ret + + IL_0013: ldc.i4.4 + IL_0014: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Option_elision_non_constant_result$fsx::init@ + IL_0006: ldsfld int32 ''.$Option_elision_non_constant_result$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Option_elision_non_constant_result$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Option_elision_non_constant_result::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/option_elision_non_constant_result.fsx.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/option_elision_non_constant_result.fsx.il.netcore.bsl new file mode 100644 index 00000000000..065129fff9a --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/option_elision_non_constant_result.fsx.il.netcore.bsl @@ -0,0 +1,152 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern runtime { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Option_elision_non_constant_result + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 + mapOption(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 mapper, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 option) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 4 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 V_0, + !!a V_1) + IL_0000: ldarg.1 + IL_0001: brtrue.s IL_0005 + + IL_0003: br.s IL_001b + + IL_0005: ldarg.1 + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1::get_Value() + IL_000d: stloc.1 + IL_000e: ldarg.0 + IL_000f: ldloc.1 + IL_0010: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0015: call class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1::Some(!0) + IL_001a: ret + + IL_001b: ldnull + IL_001c: ret + } + + .method public static int32 almostErasedOption() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.5 + IL_0001: call class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1::Some(!0) + IL_0006: brtrue.s IL_000a + + IL_0008: br.s IL_000c + + IL_000a: ldc.i4.5 + IL_000b: ret + + IL_000c: ldc.i4.4 + IL_000d: ret + } + + .method public static int32 unnecessaryOption() cil managed + { + + .maxstack 3 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 V_0) + IL_0000: ldc.i4.5 + IL_0001: call class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1::Some(!0) + IL_0006: stloc.0 + IL_0007: ldloc.0 + IL_0008: brtrue.s IL_000c + + IL_000a: br.s IL_0013 + + IL_000c: ldloc.0 + IL_000d: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpOption`1::get_Value() + IL_0012: ret + + IL_0013: ldc.i4.4 + IL_0014: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Option_elision_non_constant_result$fsx::init@ + IL_0006: ldsfld int32 ''.$Option_elision_non_constant_result$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Option_elision_non_constant_result$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Option_elision_non_constant_result::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/spurious_tail.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/spurious_tail.fsx new file mode 100644 index 00000000000..5fcf9685e08 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/spurious_tail.fsx @@ -0,0 +1,30 @@ +// +// { "optimization": { "reported_in": "#6329", "reported_by": "@NinoFloris", "last_know_version_not_optimizing": "8", "first_known_version_optimizing": null } } +// +open System.Runtime.CompilerServices + +type LoggerLevel = A = 0 | B = 1 + +type Logger() = + let messages = System.Collections.Generic.List(10000); + + [] + let nop () = () + member this.Log(level : LoggerLevel, msg : string) = + messages.Add(msg) + nop() + + member this.Log(level : LoggerLevel, obj : 'a) = + messages.Add(obj.ToString()) + nop() + +type TailLogger() = + let messages = System.Collections.Generic.List(10000); + + member this.Log(level : LoggerLevel, msg : string) = + messages.Add(msg) + + member this.Log(level : LoggerLevel, obj : 'a) = + messages.Add(obj.ToString()) + +System.Console.WriteLine() \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/spurious_tail.fsx.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/spurious_tail.fsx.il.net472.bsl new file mode 100644 index 00000000000..aec55758862 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/spurious_tail.fsx.il.net472.bsl @@ -0,0 +1,213 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Spurious_tail + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested public LoggerLevel + extends [runtime]System.Enum + { + .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 ) + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype Spurious_tail/LoggerLevel A = int32(0x00000000) + .field public static literal valuetype Spurious_tail/LoggerLevel B = int32(0x00000001) + } + + .class auto ansi serializable nested public Logger + 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 ) + .field assembly class [runtime]System.Collections.Generic.List`1 messages + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldc.i4 0x2710 + IL_000e: newobj instance void class [runtime]System.Collections.Generic.List`1::.ctor(int32) + IL_0013: stfld class [runtime]System.Collections.Generic.List`1 Spurious_tail/Logger::messages + IL_0018: ret + } + + .method public hidebysig instance void + Log(valuetype Spurious_tail/LoggerLevel level, + string msg) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [runtime]System.Collections.Generic.List`1 Spurious_tail/Logger::messages + IL_0006: ldarg.2 + IL_0007: callvirt instance void class [runtime]System.Collections.Generic.List`1::Add(!0) + IL_000c: ldarg.0 + IL_000d: callvirt instance void Spurious_tail/Logger::'nop'() + IL_0012: ret + } + + .method public hidebysig instance void + Log(valuetype Spurious_tail/LoggerLevel level, + !!a obj) cil managed + { + + .maxstack 4 + .locals init (!!a V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class [runtime]System.Collections.Generic.List`1 Spurious_tail/Logger::messages + IL_0006: ldarg.2 + IL_0007: stloc.0 + IL_0008: ldloca.s V_0 + IL_000a: constrained. !!a + IL_0010: callvirt instance string [runtime]System.Object::ToString() + IL_0015: callvirt instance void class [runtime]System.Collections.Generic.List`1::Add(!0) + IL_001a: ldarg.0 + IL_001b: callvirt instance void Spurious_tail/Logger::'nop'() + IL_0020: ret + } + + .method assembly hidebysig instance void 'nop'() cil managed aggressiveinlining + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class auto ansi serializable nested public TailLogger + 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 ) + .field assembly class [runtime]System.Collections.Generic.List`1 messages + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldc.i4 0x2710 + IL_000e: newobj instance void class [runtime]System.Collections.Generic.List`1::.ctor(int32) + IL_0013: stfld class [runtime]System.Collections.Generic.List`1 Spurious_tail/TailLogger::messages + IL_0018: ret + } + + .method public hidebysig instance void + Log(valuetype Spurious_tail/LoggerLevel level, + string msg) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [runtime]System.Collections.Generic.List`1 Spurious_tail/TailLogger::messages + IL_0006: ldarg.2 + IL_0007: tail. + IL_0009: callvirt instance void class [runtime]System.Collections.Generic.List`1::Add(!0) + IL_000e: ret + } + + .method public hidebysig instance void + Log(valuetype Spurious_tail/LoggerLevel level, + !!a obj) cil managed + { + + .maxstack 4 + .locals init (!!a V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class [runtime]System.Collections.Generic.List`1 Spurious_tail/TailLogger::messages + IL_0006: ldarg.2 + IL_0007: stloc.0 + IL_0008: ldloca.s V_0 + IL_000a: constrained. !!a + IL_0010: callvirt instance string [runtime]System.Object::ToString() + IL_0015: tail. + IL_0017: callvirt instance void class [runtime]System.Collections.Generic.List`1::Add(!0) + IL_001c: ret + } + + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Spurious_tail$fsx::init@ + IL_0006: ldsfld int32 ''.$Spurious_tail$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Spurious_tail$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Spurious_tail::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/spurious_tail.fsx.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/spurious_tail.fsx.il.netcore.bsl new file mode 100644 index 00000000000..da47285c762 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/spurious_tail.fsx.il.netcore.bsl @@ -0,0 +1,219 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern runtime { } +.assembly extern System.Collections +{ + .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) + .ver 8:0:0:0 +} +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Spurious_tail + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested public LoggerLevel + extends [runtime]System.Enum + { + .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 ) + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype Spurious_tail/LoggerLevel A = int32(0x00000000) + .field public static literal valuetype Spurious_tail/LoggerLevel B = int32(0x00000001) + } + + .class auto ansi serializable nested public Logger + 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 ) + .field assembly class [System.Collections]System.Collections.Generic.List`1 messages + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldc.i4 0x2710 + IL_000e: newobj instance void class [System.Collections]System.Collections.Generic.List`1::.ctor(int32) + IL_0013: stfld class [System.Collections]System.Collections.Generic.List`1 Spurious_tail/Logger::messages + IL_0018: ret + } + + .method public hidebysig instance void + Log(valuetype Spurious_tail/LoggerLevel level, + string msg) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [System.Collections]System.Collections.Generic.List`1 Spurious_tail/Logger::messages + IL_0006: ldarg.2 + IL_0007: callvirt instance void class [System.Collections]System.Collections.Generic.List`1::Add(!0) + IL_000c: ldarg.0 + IL_000d: callvirt instance void Spurious_tail/Logger::'nop'() + IL_0012: ret + } + + .method public hidebysig instance void + Log(valuetype Spurious_tail/LoggerLevel level, + !!a obj) cil managed + { + + .maxstack 4 + .locals init (!!a V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class [System.Collections]System.Collections.Generic.List`1 Spurious_tail/Logger::messages + IL_0006: ldarg.2 + IL_0007: stloc.0 + IL_0008: ldloca.s V_0 + IL_000a: constrained. !!a + IL_0010: callvirt instance string [runtime]System.Object::ToString() + IL_0015: callvirt instance void class [System.Collections]System.Collections.Generic.List`1::Add(!0) + IL_001a: ldarg.0 + IL_001b: callvirt instance void Spurious_tail/Logger::'nop'() + IL_0020: ret + } + + .method assembly hidebysig instance void 'nop'() cil managed aggressiveinlining + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class auto ansi serializable nested public TailLogger + 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 ) + .field assembly class [System.Collections]System.Collections.Generic.List`1 messages + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldc.i4 0x2710 + IL_000e: newobj instance void class [System.Collections]System.Collections.Generic.List`1::.ctor(int32) + IL_0013: stfld class [System.Collections]System.Collections.Generic.List`1 Spurious_tail/TailLogger::messages + IL_0018: ret + } + + .method public hidebysig instance void + Log(valuetype Spurious_tail/LoggerLevel level, + string msg) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [System.Collections]System.Collections.Generic.List`1 Spurious_tail/TailLogger::messages + IL_0006: ldarg.2 + IL_0007: tail. + IL_0009: callvirt instance void class [System.Collections]System.Collections.Generic.List`1::Add(!0) + IL_000e: ret + } + + .method public hidebysig instance void + Log(valuetype Spurious_tail/LoggerLevel level, + !!a obj) cil managed + { + + .maxstack 4 + .locals init (!!a V_0) + IL_0000: ldarg.0 + IL_0001: ldfld class [System.Collections]System.Collections.Generic.List`1 Spurious_tail/TailLogger::messages + IL_0006: ldarg.2 + IL_0007: stloc.0 + IL_0008: ldloca.s V_0 + IL_000a: constrained. !!a + IL_0010: callvirt instance string [runtime]System.Object::ToString() + IL_0015: tail. + IL_0017: callvirt instance void class [System.Collections]System.Collections.Generic.List`1::Add(!0) + IL_001c: ret + } + + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Spurious_tail$fsx::init@ + IL_0006: ldsfld int32 ''.$Spurious_tail$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Spurious_tail$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Spurious_tail::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/static_init_field.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/static_init_field.fsx new file mode 100644 index 00000000000..c80f4c62e07 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/static_init_field.fsx @@ -0,0 +1,14 @@ +// +// { "optimization": { "reported_in": "#6454", "reported_by": "@auduchinok", "last_know_version_not_optimizing": "8", "first_known_version_optimizing": null } } +// +// [] +type S<'T>(x: 'T[]) = + static let empty = S<'T>(null) + static member Empty = empty + +[] +type S2<'T>(x: 'T[]) = + static let empty = S2<'T>.M() + static member M() = empty + +System.Console.WriteLine() \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/static_init_field.fsx.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/static_init_field.fsx.il.net472.bsl new file mode 100644 index 00000000000..2da714dba4d --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/static_init_field.fsx.il.net472.bsl @@ -0,0 +1,364 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Static_init_field + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public beforefieldinit S`1 + 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 ) + .field static assembly class Static_init_field/S`1 empty + .field static assembly int32 init@5 + .method public specialname rtspecialname instance void .ctor(!T[] x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: newobj instance void class Static_init_field/S`1::.ctor(!0[]) + IL_0006: stsfld class Static_init_field/S`1 class Static_init_field/S`1::empty + IL_000b: ldc.i4.1 + IL_000c: volatile. + IL_000e: stsfld int32 class Static_init_field/S`1::init@5 + IL_0013: ret + } + + .method public specialname static class Static_init_field/S`1 get_Empty() cil managed + { + + .maxstack 8 + IL_0000: volatile. + IL_0002: ldsfld int32 class Static_init_field/S`1::init@5 + IL_0007: ldc.i4.1 + IL_0008: bge.s IL_0011 + + IL_000a: call void [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/IntrinsicFunctions::FailStaticInit() + IL_000f: br.s IL_0011 + + IL_0011: ldsfld class Static_init_field/S`1 class Static_init_field/S`1::empty + IL_0016: ret + } + + .property class Static_init_field/S`1 + Empty() + { + .get class Static_init_field/S`1 Static_init_field/S`1::get_Empty() + } + } + + .class sequential ansi serializable sealed nested public beforefieldinit S2`1 + extends [runtime]System.ValueType + implements class [runtime]System.IEquatable`1>, + [runtime]System.Collections.IStructuralEquatable, + class [runtime]System.IComparable`1>, + [runtime]System.IComparable, + [runtime]System.Collections.IStructuralComparable + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.StructAttribute::.ctor() = ( 01 00 00 00 ) + .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 ) + .field static assembly object empty + .field static assembly int32 'init@10-1' + .field assembly !T[] x + .method public hidebysig virtual final instance int32 CompareTo(valuetype Static_init_field/S2`1 obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: call class [runtime]System.Collections.IComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericComparer() + IL_0005: ldarg.0 + IL_0006: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_000b: ldarga.s obj + IL_000d: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0012: tail. + IL_0014: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonWithComparerIntrinsic(class [runtime]System.Collections.IComparer, + !!0, + !!0) + IL_0019: ret + } + + .method public hidebysig virtual final instance int32 CompareTo(object obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 5 + .locals init (valuetype Static_init_field/S2`1 V_0) + IL_0000: ldarg.1 + IL_0001: unbox.any valuetype Static_init_field/S2`1 + IL_0006: stloc.0 + IL_0007: call class [runtime]System.Collections.IComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericComparer() + IL_000c: ldarg.0 + IL_000d: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0012: ldloca.s V_0 + IL_0014: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0019: tail. + IL_001b: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonWithComparerIntrinsic(class [runtime]System.Collections.IComparer, + !!0, + !!0) + IL_0020: ret + } + + .method public hidebysig virtual final + instance int32 CompareTo(object obj, + class [runtime]System.Collections.IComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 5 + .locals init (valuetype Static_init_field/S2`1 V_0) + IL_0000: ldarg.1 + IL_0001: unbox.any valuetype Static_init_field/S2`1 + IL_0006: stloc.0 + IL_0007: ldarg.2 + IL_0008: ldarg.0 + IL_0009: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_000e: ldloca.s V_0 + IL_0010: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0015: tail. + IL_0017: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonWithComparerIntrinsic(class [runtime]System.Collections.IComparer, + !!0, + !!0) + IL_001c: ret + } + + .method public hidebysig virtual final instance int32 GetHashCode(class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 7 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: ldc.i4 0x9e3779b9 + IL_0007: ldarg.1 + IL_0008: ldarg.0 + IL_0009: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_000e: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericHashWithComparerIntrinsic(class [runtime]System.Collections.IEqualityComparer, + !!0) + IL_0013: ldloc.0 + IL_0014: ldc.i4.6 + IL_0015: shl + IL_0016: ldloc.0 + IL_0017: ldc.i4.2 + IL_0018: shr + IL_0019: add + IL_001a: add + IL_001b: add + IL_001c: stloc.0 + IL_001d: ldloc.0 + IL_001e: ret + } + + .method public hidebysig virtual final instance int32 GetHashCode() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call class [runtime]System.Collections.IEqualityComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericEqualityComparer() + IL_0006: call instance int32 valuetype Static_init_field/S2`1::GetHashCode(class [runtime]System.Collections.IEqualityComparer) + IL_000b: ret + } + + .method public hidebysig virtual final + instance bool Equals(object obj, + class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 5 + .locals init (valuetype Static_init_field/S2`1 V_0) + IL_0000: ldarg.1 + IL_0001: isinst valuetype Static_init_field/S2`1 + IL_0006: brfalse.s IL_0025 + + IL_0008: ldarg.1 + IL_0009: unbox.any valuetype Static_init_field/S2`1 + IL_000e: stloc.0 + IL_000f: ldarg.2 + IL_0010: ldarg.0 + IL_0011: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0016: ldloca.s V_0 + IL_0018: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_001d: tail. + IL_001f: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityWithComparerIntrinsic(class [runtime]System.Collections.IEqualityComparer, + !!0, + !!0) + IL_0024: ret + + IL_0025: ldc.i4.0 + IL_0026: ret + } + + .method public specialname rtspecialname instance void .ctor(!T[] x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld !0[] valuetype Static_init_field/S2`1::x + IL_0007: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call object valuetype Static_init_field/S2`1::M() + IL_0005: stsfld object valuetype Static_init_field/S2`1::empty + IL_000a: ldc.i4.1 + IL_000b: volatile. + IL_000d: stsfld int32 valuetype Static_init_field/S2`1::'init@10-1' + IL_0012: ret + } + + .method public static object M() cil managed + { + + .maxstack 8 + IL_0000: volatile. + IL_0002: ldsfld int32 valuetype Static_init_field/S2`1::'init@10-1' + IL_0007: ldc.i4.1 + IL_0008: bge.s IL_0011 + + IL_000a: call void [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/IntrinsicFunctions::FailStaticInit() + IL_000f: br.s IL_0011 + + IL_0011: ldsfld object valuetype Static_init_field/S2`1::empty + IL_0016: ret + } + + .method public hidebysig virtual final instance bool Equals(valuetype Static_init_field/S2`1 obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0006: ldarga.s obj + IL_0008: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_000d: tail. + IL_000f: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityERIntrinsic(!!0, + !!0) + IL_0014: ret + } + + .method public hidebysig virtual final instance bool Equals(object obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 4 + .locals init (valuetype Static_init_field/S2`1 V_0, + valuetype Static_init_field/S2`1 V_1) + IL_0000: ldarg.1 + IL_0001: isinst valuetype Static_init_field/S2`1 + IL_0006: brfalse.s IL_0026 + + IL_0008: ldarg.1 + IL_0009: unbox.any valuetype Static_init_field/S2`1 + IL_000e: stloc.0 + IL_000f: ldloc.0 + IL_0010: stloc.1 + IL_0011: ldarg.0 + IL_0012: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0017: ldloca.s V_1 + IL_0019: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_001e: tail. + IL_0020: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityERIntrinsic(!!0, + !!0) + IL_0025: ret + + IL_0026: ldc.i4.0 + IL_0027: ret + } + + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Static_init_field$fsx::init@ + IL_0006: ldsfld int32 ''.$Static_init_field$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Static_init_field$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Static_init_field::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/static_init_field.fsx.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/static_init_field.fsx.il.netcore.bsl new file mode 100644 index 00000000000..d322c8b88b9 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/static_init_field.fsx.il.netcore.bsl @@ -0,0 +1,365 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern runtime { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Static_init_field + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public beforefieldinit S`1 + 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 ) + .field static assembly class Static_init_field/S`1 empty + .field static assembly int32 init@5 + .method public specialname rtspecialname instance void .ctor(!T[] x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: newobj instance void class Static_init_field/S`1::.ctor(!0[]) + IL_0006: stsfld class Static_init_field/S`1 class Static_init_field/S`1::empty + IL_000b: ldc.i4.1 + IL_000c: volatile. + IL_000e: stsfld int32 class Static_init_field/S`1::init@5 + IL_0013: ret + } + + .method public specialname static class Static_init_field/S`1 get_Empty() cil managed + { + + .maxstack 8 + IL_0000: volatile. + IL_0002: ldsfld int32 class Static_init_field/S`1::init@5 + IL_0007: ldc.i4.1 + IL_0008: bge.s IL_0011 + + IL_000a: call void [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/IntrinsicFunctions::FailStaticInit() + IL_000f: br.s IL_0011 + + IL_0011: ldsfld class Static_init_field/S`1 class Static_init_field/S`1::empty + IL_0016: ret + } + + .property class Static_init_field/S`1 + Empty() + { + .get class Static_init_field/S`1 Static_init_field/S`1::get_Empty() + } + } + + .class sequential ansi serializable sealed nested public beforefieldinit S2`1 + extends [runtime]System.ValueType + implements class [runtime]System.IEquatable`1>, + [runtime]System.Collections.IStructuralEquatable, + class [runtime]System.IComparable`1>, + [runtime]System.IComparable, + [runtime]System.Collections.IStructuralComparable + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.StructAttribute::.ctor() = ( 01 00 00 00 ) + .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 ) + .field static assembly object empty + .field static assembly int32 'init@10-1' + .field assembly !T[] x + .method public hidebysig virtual final instance int32 CompareTo(valuetype Static_init_field/S2`1 obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: call class [runtime]System.Collections.IComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericComparer() + IL_0005: ldarg.0 + IL_0006: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_000b: ldarga.s obj + IL_000d: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0012: tail. + IL_0014: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonWithComparerIntrinsic(class [runtime]System.Collections.IComparer, + !!0, + !!0) + IL_0019: ret + } + + .method public hidebysig virtual final instance int32 CompareTo(object obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 5 + .locals init (valuetype Static_init_field/S2`1 V_0) + IL_0000: ldarg.1 + IL_0001: unbox.any valuetype Static_init_field/S2`1 + IL_0006: stloc.0 + IL_0007: call class [runtime]System.Collections.IComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericComparer() + IL_000c: ldarg.0 + IL_000d: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0012: ldloca.s V_0 + IL_0014: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0019: tail. + IL_001b: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonWithComparerIntrinsic(class [runtime]System.Collections.IComparer, + !!0, + !!0) + IL_0020: ret + } + + .method public hidebysig virtual final + instance int32 CompareTo(object obj, + class [runtime]System.Collections.IComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 5 + .locals init (valuetype Static_init_field/S2`1 V_0) + IL_0000: ldarg.1 + IL_0001: unbox.any valuetype Static_init_field/S2`1 + IL_0006: stloc.0 + IL_0007: ldarg.2 + IL_0008: ldarg.0 + IL_0009: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_000e: ldloca.s V_0 + IL_0010: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0015: tail. + IL_0017: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonWithComparerIntrinsic(class [runtime]System.Collections.IComparer, + !!0, + !!0) + IL_001c: ret + } + + .method public hidebysig virtual final instance int32 GetHashCode(class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 7 + .locals init (int32 V_0) + IL_0000: ldc.i4.0 + IL_0001: stloc.0 + IL_0002: ldc.i4 0x9e3779b9 + IL_0007: ldarg.1 + IL_0008: ldarg.0 + IL_0009: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_000e: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericHashWithComparerIntrinsic(class [runtime]System.Collections.IEqualityComparer, + !!0) + IL_0013: ldloc.0 + IL_0014: ldc.i4.6 + IL_0015: shl + IL_0016: ldloc.0 + IL_0017: ldc.i4.2 + IL_0018: shr + IL_0019: add + IL_001a: add + IL_001b: add + IL_001c: stloc.0 + IL_001d: ldloc.0 + IL_001e: ret + } + + .method public hidebysig virtual final instance int32 GetHashCode() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call class [runtime]System.Collections.IEqualityComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericEqualityComparer() + IL_0006: call instance int32 valuetype Static_init_field/S2`1::GetHashCode(class [runtime]System.Collections.IEqualityComparer) + IL_000b: ret + } + + .method public hidebysig virtual final + instance bool Equals(object obj, + class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 5 + .locals init (valuetype Static_init_field/S2`1 V_0) + IL_0000: ldarg.1 + IL_0001: isinst valuetype Static_init_field/S2`1 + IL_0006: brfalse.s IL_0025 + + IL_0008: ldarg.1 + IL_0009: unbox.any valuetype Static_init_field/S2`1 + IL_000e: stloc.0 + IL_000f: ldarg.2 + IL_0010: ldarg.0 + IL_0011: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0016: ldloca.s V_0 + IL_0018: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_001d: tail. + IL_001f: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityWithComparerIntrinsic(class [runtime]System.Collections.IEqualityComparer, + !!0, + !!0) + IL_0024: ret + + IL_0025: ldc.i4.0 + IL_0026: ret + } + + .method public specialname rtspecialname instance void .ctor(!T[] x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld !0[] valuetype Static_init_field/S2`1::x + IL_0007: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call object valuetype Static_init_field/S2`1::M() + IL_0005: stsfld object valuetype Static_init_field/S2`1::empty + IL_000a: ldc.i4.1 + IL_000b: volatile. + IL_000d: stsfld int32 valuetype Static_init_field/S2`1::'init@10-1' + IL_0012: ret + } + + .method public static object M() cil managed + { + + .maxstack 8 + IL_0000: volatile. + IL_0002: ldsfld int32 valuetype Static_init_field/S2`1::'init@10-1' + IL_0007: ldc.i4.1 + IL_0008: bge.s IL_0011 + + IL_000a: call void [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/IntrinsicFunctions::FailStaticInit() + IL_000f: br.s IL_0011 + + IL_0011: ldsfld object valuetype Static_init_field/S2`1::empty + IL_0016: ret + } + + .method public hidebysig virtual final instance bool Equals(valuetype Static_init_field/S2`1 obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0006: ldarga.s obj + IL_0008: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_000d: tail. + IL_000f: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityERIntrinsic(!!0, + !!0) + IL_0014: ret + } + + .method public hidebysig virtual final instance bool Equals(object obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 4 + .locals init (valuetype Static_init_field/S2`1 V_0, + valuetype Static_init_field/S2`1 V_1) + IL_0000: ldarg.1 + IL_0001: isinst valuetype Static_init_field/S2`1 + IL_0006: brfalse.s IL_0026 + + IL_0008: ldarg.1 + IL_0009: unbox.any valuetype Static_init_field/S2`1 + IL_000e: stloc.0 + IL_000f: ldloc.0 + IL_0010: stloc.1 + IL_0011: ldarg.0 + IL_0012: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_0017: ldloca.s V_1 + IL_0019: ldfld !0[] valuetype Static_init_field/S2`1::x + IL_001e: tail. + IL_0020: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityERIntrinsic(!!0, + !!0) + IL_0025: ret + + IL_0026: ldc.i4.0 + IL_0027: ret + } + + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Static_init_field$fsx::init@ + IL_0006: ldsfld int32 ''.$Static_init_field$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Static_init_field$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Static_init_field::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/tailcall_last_expression_parens.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/tailcall_last_expression_parens.fsx new file mode 100644 index 00000000000..3617e01fb7c --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/tailcall_last_expression_parens.fsx @@ -0,0 +1,36 @@ +// +// { "optimization": { "reported_in": "#6984", "reported_by": "@teo-tsirpanis", "last_know_version_not_optimizing": "8", "first_known_version_optimizing": null } } +// +let factorialOk1 x = + let rec impl x acc = + if x = 0UL then + acc + else + impl (x - 1UL) (x * acc) + impl x 1UL + +let factorialOk2 x = + let rec impl x acc = + if x = 0UL then + acc + else + impl <|| (x - 1UL, x * acc) + impl x 1UL + +let factorialNotOk1 x = + let rec impl x acc = + if x = 0UL then + acc + else + impl (x - 1UL) <| x * acc + impl x 1UL + +let factorialNotOk2 x = + let rec impl x acc = + if x = 0UL then + acc + else + (impl (x-1UL)) (x * acc) + impl x 1UL + +System.Console.WriteLine() \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/tailcall_last_expression_parens.fsx.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/tailcall_last_expression_parens.fsx.il.net472.bsl new file mode 100644 index 00000000000..62dae440bc5 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/tailcall_last_expression_parens.fsx.il.net472.bsl @@ -0,0 +1,360 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Tailcall_last_expression_parens + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested assembly beforefieldinit impl@6 + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 + { + .field static assembly initonly class Tailcall_last_expression_parens/impl@6 @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::.ctor() + IL_0006: ret + } + + .method public strict virtual instance uint64 + Invoke(uint64 x, + uint64 acc) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: brtrue.s IL_0005 + + IL_0003: ldarg.2 + IL_0004: ret + + IL_0005: ldarg.1 + IL_0006: ldc.i4.1 + IL_0007: conv.i8 + IL_0008: sub + IL_0009: ldarg.1 + IL_000a: ldarg.2 + IL_000b: mul + IL_000c: starg.s acc + IL_000e: starg.s x + IL_0010: br.s IL_0000 + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Tailcall_last_expression_parens/impl@6::.ctor() + IL_0005: stsfld class Tailcall_last_expression_parens/impl@6 Tailcall_last_expression_parens/impl@6::@_instance + IL_000a: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit 'impl@14-1' + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 + { + .field static assembly initonly class Tailcall_last_expression_parens/'impl@14-1' @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::.ctor() + IL_0006: ret + } + + .method public strict virtual instance uint64 + Invoke(uint64 x, + uint64 acc) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: brtrue.s IL_0005 + + IL_0003: ldarg.2 + IL_0004: ret + + IL_0005: ldarg.1 + IL_0006: ldc.i4.1 + IL_0007: conv.i8 + IL_0008: sub + IL_0009: ldarg.1 + IL_000a: ldarg.2 + IL_000b: mul + IL_000c: starg.s acc + IL_000e: starg.s x + IL_0010: br.s IL_0000 + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Tailcall_last_expression_parens/'impl@14-1'::.ctor() + IL_0005: stsfld class Tailcall_last_expression_parens/'impl@14-1' Tailcall_last_expression_parens/'impl@14-1'::@_instance + IL_000a: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit 'impl@22-2' + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 + { + .field static assembly initonly class Tailcall_last_expression_parens/'impl@22-2' @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::.ctor() + IL_0006: ret + } + + .method public strict virtual instance uint64 + Invoke(uint64 x, + uint64 acc) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: brtrue.s IL_0005 + + IL_0003: ldarg.2 + IL_0004: ret + + IL_0005: ldarg.0 + IL_0006: ldarg.1 + IL_0007: ldc.i4.1 + IL_0008: conv.i8 + IL_0009: sub + IL_000a: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>::Invoke(!0) + IL_000f: ldarg.1 + IL_0010: ldarg.2 + IL_0011: mul + IL_0012: tail. + IL_0014: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0019: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Tailcall_last_expression_parens/'impl@22-2'::.ctor() + IL_0005: stsfld class Tailcall_last_expression_parens/'impl@22-2' Tailcall_last_expression_parens/'impl@22-2'::@_instance + IL_000a: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit 'impl@30-3' + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 + { + .field static assembly initonly class Tailcall_last_expression_parens/'impl@30-3' @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::.ctor() + IL_0006: ret + } + + .method public strict virtual instance uint64 + Invoke(uint64 x, + uint64 acc) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: brtrue.s IL_0005 + + IL_0003: ldarg.2 + IL_0004: ret + + IL_0005: ldarg.0 + IL_0006: ldarg.1 + IL_0007: ldc.i4.1 + IL_0008: conv.i8 + IL_0009: sub + IL_000a: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>::Invoke(!0) + IL_000f: ldarg.1 + IL_0010: ldarg.2 + IL_0011: mul + IL_0012: tail. + IL_0014: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0019: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Tailcall_last_expression_parens/'impl@30-3'::.ctor() + IL_0005: stsfld class Tailcall_last_expression_parens/'impl@30-3' Tailcall_last_expression_parens/'impl@30-3'::@_instance + IL_000a: ret + } + + } + + .method public static uint64 factorialOk1(uint64 x) cil managed + { + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> V_0) + IL_0000: ldsfld class Tailcall_last_expression_parens/impl@6 Tailcall_last_expression_parens/impl@6::@_instance + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: ldc.i4.1 + IL_0009: conv.i8 + IL_000a: tail. + IL_000c: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_0011: ret + } + + .method public static uint64 factorialOk2(uint64 x) cil managed + { + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> V_0) + IL_0000: ldsfld class Tailcall_last_expression_parens/'impl@14-1' Tailcall_last_expression_parens/'impl@14-1'::@_instance + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: ldc.i4.1 + IL_0009: conv.i8 + IL_000a: tail. + IL_000c: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_0011: ret + } + + .method public static uint64 factorialNotOk1(uint64 x) cil managed + { + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> V_0) + IL_0000: ldsfld class Tailcall_last_expression_parens/'impl@22-2' Tailcall_last_expression_parens/'impl@22-2'::@_instance + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: ldc.i4.1 + IL_0009: conv.i8 + IL_000a: tail. + IL_000c: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_0011: ret + } + + .method public static uint64 factorialNotOk2(uint64 x) cil managed + { + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> V_0) + IL_0000: ldsfld class Tailcall_last_expression_parens/'impl@30-3' Tailcall_last_expression_parens/'impl@30-3'::@_instance + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: ldc.i4.1 + IL_0009: conv.i8 + IL_000a: tail. + IL_000c: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_0011: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Tailcall_last_expression_parens$fsx::init@ + IL_0006: ldsfld int32 ''.$Tailcall_last_expression_parens$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Tailcall_last_expression_parens$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Tailcall_last_expression_parens::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/tailcall_last_expression_parens.fsx.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/tailcall_last_expression_parens.fsx.il.netcore.bsl new file mode 100644 index 00000000000..8044a1868b5 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/tailcall_last_expression_parens.fsx.il.netcore.bsl @@ -0,0 +1,361 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern runtime { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Tailcall_last_expression_parens + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested assembly beforefieldinit impl@6 + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 + { + .field static assembly initonly class Tailcall_last_expression_parens/impl@6 @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::.ctor() + IL_0006: ret + } + + .method public strict virtual instance uint64 + Invoke(uint64 x, + uint64 acc) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: brtrue.s IL_0005 + + IL_0003: ldarg.2 + IL_0004: ret + + IL_0005: ldarg.1 + IL_0006: ldc.i4.1 + IL_0007: conv.i8 + IL_0008: sub + IL_0009: ldarg.1 + IL_000a: ldarg.2 + IL_000b: mul + IL_000c: starg.s acc + IL_000e: starg.s x + IL_0010: br.s IL_0000 + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Tailcall_last_expression_parens/impl@6::.ctor() + IL_0005: stsfld class Tailcall_last_expression_parens/impl@6 Tailcall_last_expression_parens/impl@6::@_instance + IL_000a: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit 'impl@14-1' + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 + { + .field static assembly initonly class Tailcall_last_expression_parens/'impl@14-1' @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::.ctor() + IL_0006: ret + } + + .method public strict virtual instance uint64 + Invoke(uint64 x, + uint64 acc) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: brtrue.s IL_0005 + + IL_0003: ldarg.2 + IL_0004: ret + + IL_0005: ldarg.1 + IL_0006: ldc.i4.1 + IL_0007: conv.i8 + IL_0008: sub + IL_0009: ldarg.1 + IL_000a: ldarg.2 + IL_000b: mul + IL_000c: starg.s acc + IL_000e: starg.s x + IL_0010: br.s IL_0000 + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Tailcall_last_expression_parens/'impl@14-1'::.ctor() + IL_0005: stsfld class Tailcall_last_expression_parens/'impl@14-1' Tailcall_last_expression_parens/'impl@14-1'::@_instance + IL_000a: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit 'impl@22-2' + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 + { + .field static assembly initonly class Tailcall_last_expression_parens/'impl@22-2' @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::.ctor() + IL_0006: ret + } + + .method public strict virtual instance uint64 + Invoke(uint64 x, + uint64 acc) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: brtrue.s IL_0005 + + IL_0003: ldarg.2 + IL_0004: ret + + IL_0005: ldarg.0 + IL_0006: ldarg.1 + IL_0007: ldc.i4.1 + IL_0008: conv.i8 + IL_0009: sub + IL_000a: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>::Invoke(!0) + IL_000f: ldarg.1 + IL_0010: ldarg.2 + IL_0011: mul + IL_0012: tail. + IL_0014: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0019: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Tailcall_last_expression_parens/'impl@22-2'::.ctor() + IL_0005: stsfld class Tailcall_last_expression_parens/'impl@22-2' Tailcall_last_expression_parens/'impl@22-2'::@_instance + IL_000a: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit 'impl@30-3' + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 + { + .field static assembly initonly class Tailcall_last_expression_parens/'impl@30-3' @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::.ctor() + IL_0006: ret + } + + .method public strict virtual instance uint64 + Invoke(uint64 x, + uint64 acc) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: brtrue.s IL_0005 + + IL_0003: ldarg.2 + IL_0004: ret + + IL_0005: ldarg.0 + IL_0006: ldarg.1 + IL_0007: ldc.i4.1 + IL_0008: conv.i8 + IL_0009: sub + IL_000a: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>::Invoke(!0) + IL_000f: ldarg.1 + IL_0010: ldarg.2 + IL_0011: mul + IL_0012: tail. + IL_0014: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0019: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Tailcall_last_expression_parens/'impl@30-3'::.ctor() + IL_0005: stsfld class Tailcall_last_expression_parens/'impl@30-3' Tailcall_last_expression_parens/'impl@30-3'::@_instance + IL_000a: ret + } + + } + + .method public static uint64 factorialOk1(uint64 x) cil managed + { + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> V_0) + IL_0000: ldsfld class Tailcall_last_expression_parens/impl@6 Tailcall_last_expression_parens/impl@6::@_instance + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: ldc.i4.1 + IL_0009: conv.i8 + IL_000a: tail. + IL_000c: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_0011: ret + } + + .method public static uint64 factorialOk2(uint64 x) cil managed + { + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> V_0) + IL_0000: ldsfld class Tailcall_last_expression_parens/'impl@14-1' Tailcall_last_expression_parens/'impl@14-1'::@_instance + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: ldc.i4.1 + IL_0009: conv.i8 + IL_000a: tail. + IL_000c: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_0011: ret + } + + .method public static uint64 factorialNotOk1(uint64 x) cil managed + { + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> V_0) + IL_0000: ldsfld class Tailcall_last_expression_parens/'impl@22-2' Tailcall_last_expression_parens/'impl@22-2'::@_instance + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: ldc.i4.1 + IL_0009: conv.i8 + IL_000a: tail. + IL_000c: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_0011: ret + } + + .method public static uint64 factorialNotOk2(uint64 x) cil managed + { + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> V_0) + IL_0000: ldsfld class Tailcall_last_expression_parens/'impl@30-3' Tailcall_last_expression_parens/'impl@30-3'::@_instance + IL_0005: stloc.0 + IL_0006: ldloc.0 + IL_0007: ldarg.0 + IL_0008: ldc.i4.1 + IL_0009: conv.i8 + IL_000a: tail. + IL_000c: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_0011: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Tailcall_last_expression_parens$fsx::init@ + IL_0006: ldsfld int32 ''.$Tailcall_last_expression_parens$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Tailcall_last_expression_parens$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Tailcall_last_expression_parens::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/typedefof.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/typedefof.fsx new file mode 100644 index 00000000000..14be757b9dd --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/typedefof.fsx @@ -0,0 +1,11 @@ +// +// { "optimization": { "reported_in": "#5019", "reported_by": "@rspeele,@ForNever", "last_know_version_not_optimizing": "8", "first_known_version_optimizing": null } } +// +open System.Collections.Generic +type C() = + member this.M() = + let x = typedefof> + () + + +System.Console.WriteLine() \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/typedefof.fsx.il.net472.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/typedefof.fsx.il.net472.bsl new file mode 100644 index 00000000000..1dc2c80435a --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/typedefof.fsx.il.net472.bsl @@ -0,0 +1,128 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern netstandard +{ + .publickeytoken = (CC 7B 13 FF CD 2D DD 51 ) + .ver 2:0:0:0 +} +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Typedefof + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + 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 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance void M() cil managed + { + + .maxstack 3 + .locals init (class [runtime]System.Type V_0, + class [runtime]System.Type V_1) + IL_0000: ldtoken class [runtime]System.Collections.Generic.List`1 + IL_0005: call class [netstandard]System.Type [netstandard]System.Type::GetTypeFromHandle(valuetype [netstandard]System.RuntimeTypeHandle) + IL_000a: stloc.1 + IL_000b: ldloc.1 + IL_000c: callvirt instance bool [netstandard]System.Type::get_IsGenericType() + IL_0011: brfalse.s IL_001b + + IL_0013: ldloc.1 + IL_0014: callvirt instance class [netstandard]System.Type [netstandard]System.Type::GetGenericTypeDefinition() + IL_0019: br.s IL_001c + + IL_001b: ldloc.1 + IL_001c: stloc.0 + IL_001d: ret + } + + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Typedefof$fsx::init@ + IL_0006: ldsfld int32 ''.$Typedefof$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Typedefof$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Typedefof::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/typedefof.fsx.il.netcore.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/typedefof.fsx.il.netcore.bsl new file mode 100644 index 00000000000..330c6ce43be --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/typedefof.fsx.il.netcore.bsl @@ -0,0 +1,134 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern runtime { } +.assembly extern System.Collections +{ + .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) + .ver 8:0:0:0 +} +.assembly extern netstandard +{ + .publickeytoken = (CC 7B 13 FF CD 2D DD 51 ) + .ver 2:1:0:0 +} +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Typedefof + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + 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 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance void M() cil managed + { + + .maxstack 3 + .locals init (class [runtime]System.Type V_0, + class [runtime]System.Type V_1) + IL_0000: ldtoken class [System.Collections]System.Collections.Generic.List`1 + IL_0005: call class [netstandard]System.Type [netstandard]System.Type::GetTypeFromHandle(valuetype [netstandard]System.RuntimeTypeHandle) + IL_000a: stloc.1 + IL_000b: ldloc.1 + IL_000c: callvirt instance bool [netstandard]System.Type::get_IsGenericType() + IL_0011: brfalse.s IL_001b + + IL_0013: ldloc.1 + IL_0014: callvirt instance class [netstandard]System.Type [netstandard]System.Type::GetGenericTypeDefinition() + IL_0019: br.s IL_001c + + IL_001b: ldloc.1 + IL_001c: stloc.0 + IL_001d: ret + } + + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Typedefof$fsx::init@ + IL_0006: ldsfld int32 ''.$Typedefof$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call void [runtime]System.Console::WriteLine() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed ''.$Typedefof$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Typedefof::staticInitialization@() + IL_0005: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx new file mode 100644 index 00000000000..185cd97fb80 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx @@ -0,0 +1,35 @@ +// +// { "optimization": { "reported_in": "#5291", "reported_by": "@jack-pappas", "last_know_version_not_optimizing": "8", "first_known_version_optimizing": null } } +// + +open System.Collections.Generic +open OptimizedClosures + +[] +let foldStrong (folder : 'State -> 'T -> 'State) state (enumerator : ('TEnumerator :> IEnumerator<'T>)) : 'State = + let folder = FSharpFunc<_,_,_>.Adapt folder + + let mutable enumerator' = enumerator + let mutable state = state + while enumerator'.MoveNext () do + state <- folder.Invoke (state, enumerator.Current) + state + +[] +let inline fold< ^State, ^T, ^TSeq, ^TEnumerator + when ^TSeq: (member GetEnumerator: unit -> ^TEnumerator) + and ^TEnumerator :> IEnumerator< ^T > > + (folder : ^State -> ^T -> ^State) state (source : ^TSeq) : 'State = + // This 'use' binding causes unnecessary boxing of 'enumerator'. + use enumerator = (^TSeq : (member GetEnumerator: unit -> ^TEnumerator) (source)) + foldStrong folder state enumerator + + +let testFoldOnListT () = + let items = ResizeArray ([| 1; 1; 2; 3; 5; 8 |]) + + ("", items) + ||> fold (fun state x -> + state + string x) + +System.Console.WriteLine(testFoldOnListT()) \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx.il.net472.debug.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx.il.net472.debug.bsl new file mode 100644 index 00000000000..b435eb5a868 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx.il.net472.debug.bsl @@ -0,0 +1,346 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern netstandard +{ + .publickeytoken = (CC 7B 13 FF CD 2D DD 51 ) + .ver 2:0:0:0 +} +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Use_binding_on_struct_enumerator + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested assembly beforefieldinit testFoldOnListT@32 + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 + { + .field static assembly initonly class Use_binding_on_struct_enumerator/testFoldOnListT@32 @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::.ctor() + IL_0006: ret + } + + .method public strict virtual instance string + Invoke(string state, + int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: box [runtime]System.Int32 + IL_0007: unbox.any [runtime]System.IFormattable + IL_000c: ldnull + IL_000d: call class [netstandard]System.Globalization.CultureInfo [netstandard]System.Globalization.CultureInfo::get_InvariantCulture() + IL_0012: callvirt instance string [netstandard]System.IFormattable::ToString(string, + class [netstandard]System.IFormatProvider) + IL_0017: call string [runtime]System.String::Concat(string, + string) + IL_001c: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Use_binding_on_struct_enumerator/testFoldOnListT@32::.ctor() + IL_0005: stsfld class Use_binding_on_struct_enumerator/testFoldOnListT@32 Use_binding_on_struct_enumerator/testFoldOnListT@32::@_instance + IL_000a: ret + } + + } + + .field static assembly valuetype ''/T3339_24Bytes@ field3340@ at I_00003943 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method public static !!State FoldStrong) TEnumerator>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> folder, + !!State state, + !!TEnumerator enumerator) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 0A 66 6F 6C 64 53 74 72 6F 6E 67 00 00 ) + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 V_0, + !!TEnumerator V_1, + !!State V_2, + !!TEnumerator V_3) + IL_0000: ldarg.0 + IL_0001: call class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Adapt(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: stloc.0 + IL_0007: ldarg.2 + IL_0008: stloc.1 + IL_0009: ldarg.1 + IL_000a: stloc.2 + IL_000b: br.s IL_0024 + + IL_000d: ldloc.0 + IL_000e: ldloc.2 + IL_000f: ldarg.2 + IL_0010: stloc.3 + IL_0011: ldloca.s V_3 + IL_0013: constrained. !!TEnumerator + IL_0019: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_001e: callvirt instance !2 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Invoke(!0, + !1) + IL_0023: stloc.2 + IL_0024: ldloca.s V_1 + IL_0026: constrained. !!TEnumerator + IL_002c: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0031: brtrue.s IL_000d + + IL_0033: ldloc.2 + IL_0034: ret + } + + .method public static !!State Fold) TEnumerator>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> folder, + !!State state, + !!TSeq source) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 04 66 6F 6C 64 00 00 ) + + .maxstack 5 + .locals init (!!TEnumerator V_0, + !!State V_1, + class [runtime]System.IDisposable V_2) + IL_0000: ldc.i4.0 + IL_0001: brfalse.s IL_000b + + IL_0003: ldnull + IL_0004: unbox.any !!TEnumerator + IL_0009: br.s IL_0016 + + IL_000b: ldstr "Dynamic invocation of GetEnumerator is not supported" + IL_0010: newobj instance void [runtime]System.NotSupportedException::.ctor(string) + IL_0015: throw + + IL_0016: stloc.0 + .try + { + IL_0017: ldarg.0 + IL_0018: ldarg.1 + IL_0019: ldloc.0 + IL_001a: call !!0 Use_binding_on_struct_enumerator::FoldStrong(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0, + !!2) + IL_001f: stloc.1 + IL_0020: leave.s IL_0039 + + } + finally + { + IL_0022: ldloc.0 + IL_0023: box !!TEnumerator + IL_0028: isinst [runtime]System.IDisposable + IL_002d: stloc.2 + IL_002e: ldloc.2 + IL_002f: brfalse.s IL_0038 + + IL_0031: ldloc.2 + IL_0032: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0037: endfinally + IL_0038: endfinally + } + IL_0039: ldloc.1 + IL_003a: ret + } + + .method public static !!State Fold$W) TEnumerator>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 getEnumerator, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> folder, + !!State state, + !!TSeq source) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 04 66 6F 6C 64 00 00 ) + + .maxstack 5 + .locals init (!!TEnumerator V_0, + !!State V_1, + class [runtime]System.IDisposable V_2) + IL_0000: ldarg.0 + IL_0001: ldarg.3 + IL_0002: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0007: stloc.0 + .try + { + IL_0008: ldarg.1 + IL_0009: ldarg.2 + IL_000a: ldloc.0 + IL_000b: call !!0 Use_binding_on_struct_enumerator::FoldStrong(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0, + !!2) + IL_0010: stloc.1 + IL_0011: leave.s IL_002a + + } + finally + { + IL_0013: ldloc.0 + IL_0014: box !!TEnumerator + IL_0019: isinst [runtime]System.IDisposable + IL_001e: stloc.2 + IL_001f: ldloc.2 + IL_0020: brfalse.s IL_0029 + + IL_0022: ldloc.2 + IL_0023: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0028: endfinally + IL_0029: endfinally + } + IL_002a: ldloc.1 + IL_002b: ret + } + + .method public static string testFoldOnListT() cil managed + { + + .maxstack 5 + .locals init (class [runtime]System.Collections.Generic.List`1 V_0, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> V_1, + valuetype [runtime]System.Collections.Generic.List`1/Enumerator V_2, + string V_3, + class [runtime]System.IDisposable V_4) + IL_0000: ldc.i4.6 + IL_0001: newarr [runtime]System.Int32 + IL_0006: dup + IL_0007: ldtoken field valuetype ''/T3339_24Bytes@ Use_binding_on_struct_enumerator::field3340@ + IL_000c: call void [runtime]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [runtime]System.Array, + valuetype [runtime]System.RuntimeFieldHandle) + IL_0011: newobj instance void class [runtime]System.Collections.Generic.List`1::.ctor(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0016: stloc.0 + IL_0017: ldsfld class Use_binding_on_struct_enumerator/testFoldOnListT@32 Use_binding_on_struct_enumerator/testFoldOnListT@32::@_instance + IL_001c: stloc.1 + IL_001d: ldloc.0 + IL_001e: callvirt instance valuetype [runtime]System.Collections.Generic.List`1/Enumerator class [runtime]System.Collections.Generic.List`1::GetEnumerator() + IL_0023: stloc.2 + .try + { + IL_0024: ldloc.1 + IL_0025: ldstr "" + IL_002a: ldloc.2 + IL_002b: call !!0 Use_binding_on_struct_enumerator::FoldStrong>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0, + !!2) + IL_0030: stloc.3 + IL_0031: leave.s IL_004d + + } + finally + { + IL_0033: ldloc.2 + IL_0034: box valuetype [runtime]System.Collections.Generic.List`1/Enumerator + IL_0039: isinst [runtime]System.IDisposable + IL_003e: stloc.s V_4 + IL_0040: ldloc.s V_4 + IL_0042: brfalse.s IL_004c + + IL_0044: ldloc.s V_4 + IL_0046: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004b: endfinally + IL_004c: endfinally + } + IL_004d: ldloc.3 + IL_004e: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Use_binding_on_struct_enumerator$fsx::init@ + IL_0006: ldsfld int32 ''.$Use_binding_on_struct_enumerator$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call string Use_binding_on_struct_enumerator::testFoldOnListT() + IL_0005: call void [runtime]System.Console::WriteLine(string) + IL_000a: ret + } + +} + +.class private abstract auto ansi sealed ''.$Use_binding_on_struct_enumerator$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Use_binding_on_struct_enumerator::staticInitialization@() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed beforefieldinit '' + extends [runtime]System.Object +{ + .class explicit ansi sealed nested assembly beforefieldinit T3339_24Bytes@ + extends [runtime]System.ValueType + { + .pack 0 + .size 24 + } + +} + + + + +.data cil I_00003943 = bytearray ( + 01 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 + 05 00 00 00 08 00 00 00) + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx.il.net472.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx.il.net472.release.bsl new file mode 100644 index 00000000000..923c0ee025c --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx.il.net472.release.bsl @@ -0,0 +1,346 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern netstandard +{ + .publickeytoken = (CC 7B 13 FF CD 2D DD 51 ) + .ver 2:0:0:0 +} +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Use_binding_on_struct_enumerator + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested assembly beforefieldinit testFoldOnListT@32 + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 + { + .field static assembly initonly class Use_binding_on_struct_enumerator/testFoldOnListT@32 @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::.ctor() + IL_0006: ret + } + + .method public strict virtual instance string + Invoke(string state, + int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: box [runtime]System.Int32 + IL_0007: unbox.any [runtime]System.IFormattable + IL_000c: ldnull + IL_000d: call class [netstandard]System.Globalization.CultureInfo [netstandard]System.Globalization.CultureInfo::get_InvariantCulture() + IL_0012: callvirt instance string [netstandard]System.IFormattable::ToString(string, + class [netstandard]System.IFormatProvider) + IL_0017: call string [runtime]System.String::Concat(string, + string) + IL_001c: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Use_binding_on_struct_enumerator/testFoldOnListT@32::.ctor() + IL_0005: stsfld class Use_binding_on_struct_enumerator/testFoldOnListT@32 Use_binding_on_struct_enumerator/testFoldOnListT@32::@_instance + IL_000a: ret + } + + } + + .field static assembly valuetype ''/T3534_24Bytes@ field3535@ at I_00003945 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method public static !!State FoldStrong) TEnumerator>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> folder, + !!State state, + !!TEnumerator enumerator) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 0A 66 6F 6C 64 53 74 72 6F 6E 67 00 00 ) + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 V_0, + !!TEnumerator V_1, + !!State V_2, + !!TEnumerator V_3) + IL_0000: ldarg.0 + IL_0001: call class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Adapt(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: stloc.0 + IL_0007: ldarg.2 + IL_0008: stloc.1 + IL_0009: ldarg.1 + IL_000a: stloc.2 + IL_000b: br.s IL_0024 + + IL_000d: ldloc.0 + IL_000e: ldloc.2 + IL_000f: ldarg.2 + IL_0010: stloc.3 + IL_0011: ldloca.s V_3 + IL_0013: constrained. !!TEnumerator + IL_0019: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_001e: callvirt instance !2 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Invoke(!0, + !1) + IL_0023: stloc.2 + IL_0024: ldloca.s V_1 + IL_0026: constrained. !!TEnumerator + IL_002c: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0031: brtrue.s IL_000d + + IL_0033: ldloc.2 + IL_0034: ret + } + + .method public static !!State Fold) TEnumerator>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> folder, + !!State state, + !!TSeq source) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 04 66 6F 6C 64 00 00 ) + + .maxstack 5 + .locals init (!!TEnumerator V_0, + !!State V_1, + class [runtime]System.IDisposable V_2) + IL_0000: ldc.i4.0 + IL_0001: brfalse.s IL_000b + + IL_0003: ldnull + IL_0004: unbox.any !!TEnumerator + IL_0009: br.s IL_0016 + + IL_000b: ldstr "Dynamic invocation of GetEnumerator is not supported" + IL_0010: newobj instance void [runtime]System.NotSupportedException::.ctor(string) + IL_0015: throw + + IL_0016: stloc.0 + .try + { + IL_0017: ldarg.0 + IL_0018: ldarg.1 + IL_0019: ldloc.0 + IL_001a: call !!0 Use_binding_on_struct_enumerator::FoldStrong(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0, + !!2) + IL_001f: stloc.1 + IL_0020: leave.s IL_0039 + + } + finally + { + IL_0022: ldloc.0 + IL_0023: box !!TEnumerator + IL_0028: isinst [runtime]System.IDisposable + IL_002d: stloc.2 + IL_002e: ldloc.2 + IL_002f: brfalse.s IL_0038 + + IL_0031: ldloc.2 + IL_0032: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0037: endfinally + IL_0038: endfinally + } + IL_0039: ldloc.1 + IL_003a: ret + } + + .method public static !!State Fold$W) TEnumerator>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 getEnumerator, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> folder, + !!State state, + !!TSeq source) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 04 66 6F 6C 64 00 00 ) + + .maxstack 5 + .locals init (!!TEnumerator V_0, + !!State V_1, + class [runtime]System.IDisposable V_2) + IL_0000: ldarg.0 + IL_0001: ldarg.3 + IL_0002: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0007: stloc.0 + .try + { + IL_0008: ldarg.1 + IL_0009: ldarg.2 + IL_000a: ldloc.0 + IL_000b: call !!0 Use_binding_on_struct_enumerator::FoldStrong(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0, + !!2) + IL_0010: stloc.1 + IL_0011: leave.s IL_002a + + } + finally + { + IL_0013: ldloc.0 + IL_0014: box !!TEnumerator + IL_0019: isinst [runtime]System.IDisposable + IL_001e: stloc.2 + IL_001f: ldloc.2 + IL_0020: brfalse.s IL_0029 + + IL_0022: ldloc.2 + IL_0023: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0028: endfinally + IL_0029: endfinally + } + IL_002a: ldloc.1 + IL_002b: ret + } + + .method public static string testFoldOnListT() cil managed + { + + .maxstack 5 + .locals init (class [runtime]System.Collections.Generic.List`1 V_0, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> V_1, + valuetype [runtime]System.Collections.Generic.List`1/Enumerator V_2, + string V_3, + class [runtime]System.IDisposable V_4) + IL_0000: ldc.i4.6 + IL_0001: newarr [runtime]System.Int32 + IL_0006: dup + IL_0007: ldtoken field valuetype ''/T3534_24Bytes@ Use_binding_on_struct_enumerator::field3535@ + IL_000c: call void [runtime]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [runtime]System.Array, + valuetype [runtime]System.RuntimeFieldHandle) + IL_0011: newobj instance void class [runtime]System.Collections.Generic.List`1::.ctor(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0016: stloc.0 + IL_0017: ldsfld class Use_binding_on_struct_enumerator/testFoldOnListT@32 Use_binding_on_struct_enumerator/testFoldOnListT@32::@_instance + IL_001c: stloc.1 + IL_001d: ldloc.0 + IL_001e: callvirt instance valuetype [runtime]System.Collections.Generic.List`1/Enumerator class [runtime]System.Collections.Generic.List`1::GetEnumerator() + IL_0023: stloc.2 + .try + { + IL_0024: ldloc.1 + IL_0025: ldstr "" + IL_002a: ldloc.2 + IL_002b: call !!0 Use_binding_on_struct_enumerator::FoldStrong>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0, + !!2) + IL_0030: stloc.3 + IL_0031: leave.s IL_004d + + } + finally + { + IL_0033: ldloc.2 + IL_0034: box valuetype [runtime]System.Collections.Generic.List`1/Enumerator + IL_0039: isinst [runtime]System.IDisposable + IL_003e: stloc.s V_4 + IL_0040: ldloc.s V_4 + IL_0042: brfalse.s IL_004c + + IL_0044: ldloc.s V_4 + IL_0046: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004b: endfinally + IL_004c: endfinally + } + IL_004d: ldloc.3 + IL_004e: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Use_binding_on_struct_enumerator$fsx::init@ + IL_0006: ldsfld int32 ''.$Use_binding_on_struct_enumerator$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call string Use_binding_on_struct_enumerator::testFoldOnListT() + IL_0005: call void [runtime]System.Console::WriteLine(string) + IL_000a: ret + } + +} + +.class private abstract auto ansi sealed ''.$Use_binding_on_struct_enumerator$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Use_binding_on_struct_enumerator::staticInitialization@() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed beforefieldinit '' + extends [runtime]System.Object +{ + .class explicit ansi sealed nested assembly beforefieldinit T3534_24Bytes@ + extends [runtime]System.ValueType + { + .pack 0 + .size 24 + } + +} + + + + +.data cil I_00003945 = bytearray ( + 01 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 + 05 00 00 00 08 00 00 00) + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx.il.netcore.debug.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx.il.netcore.debug.bsl new file mode 100644 index 00000000000..66bb0434fd9 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx.il.netcore.debug.bsl @@ -0,0 +1,352 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern System.Collections +{ + .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) + .ver 8:0:0:0 +} +.assembly extern runtime { } +.assembly extern netstandard +{ + .publickeytoken = (CC 7B 13 FF CD 2D DD 51 ) + .ver 2:1:0:0 +} +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Use_binding_on_struct_enumerator + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested assembly beforefieldinit testFoldOnListT@32 + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 + { + .field static assembly initonly class Use_binding_on_struct_enumerator/testFoldOnListT@32 @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::.ctor() + IL_0006: ret + } + + .method public strict virtual instance string + Invoke(string state, + int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: box [runtime]System.Int32 + IL_0007: unbox.any [runtime]System.IFormattable + IL_000c: ldnull + IL_000d: call class [netstandard]System.Globalization.CultureInfo [netstandard]System.Globalization.CultureInfo::get_InvariantCulture() + IL_0012: callvirt instance string [netstandard]System.IFormattable::ToString(string, + class [netstandard]System.IFormatProvider) + IL_0017: call string [runtime]System.String::Concat(string, + string) + IL_001c: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Use_binding_on_struct_enumerator/testFoldOnListT@32::.ctor() + IL_0005: stsfld class Use_binding_on_struct_enumerator/testFoldOnListT@32 Use_binding_on_struct_enumerator/testFoldOnListT@32::@_instance + IL_000a: ret + } + + } + + .field static assembly valuetype ''/T3352_24Bytes@ field3353@ at I_0000398B + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method public static !!State FoldStrong) TEnumerator>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> folder, + !!State state, + !!TEnumerator enumerator) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 0A 66 6F 6C 64 53 74 72 6F 6E 67 00 00 ) + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 V_0, + !!TEnumerator V_1, + !!State V_2, + !!TEnumerator V_3) + IL_0000: ldarg.0 + IL_0001: call class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Adapt(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: stloc.0 + IL_0007: ldarg.2 + IL_0008: stloc.1 + IL_0009: ldarg.1 + IL_000a: stloc.2 + IL_000b: br.s IL_0024 + + IL_000d: ldloc.0 + IL_000e: ldloc.2 + IL_000f: ldarg.2 + IL_0010: stloc.3 + IL_0011: ldloca.s V_3 + IL_0013: constrained. !!TEnumerator + IL_0019: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_001e: callvirt instance !2 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Invoke(!0, + !1) + IL_0023: stloc.2 + IL_0024: ldloca.s V_1 + IL_0026: constrained. !!TEnumerator + IL_002c: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0031: brtrue.s IL_000d + + IL_0033: ldloc.2 + IL_0034: ret + } + + .method public static !!State Fold) TEnumerator>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> folder, + !!State state, + !!TSeq source) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 04 66 6F 6C 64 00 00 ) + + .maxstack 5 + .locals init (!!TEnumerator V_0, + !!State V_1, + class [runtime]System.IDisposable V_2) + IL_0000: ldc.i4.0 + IL_0001: brfalse.s IL_000b + + IL_0003: ldnull + IL_0004: unbox.any !!TEnumerator + IL_0009: br.s IL_0016 + + IL_000b: ldstr "Dynamic invocation of GetEnumerator is not supported" + IL_0010: newobj instance void [runtime]System.NotSupportedException::.ctor(string) + IL_0015: throw + + IL_0016: stloc.0 + .try + { + IL_0017: ldarg.0 + IL_0018: ldarg.1 + IL_0019: ldloc.0 + IL_001a: call !!0 Use_binding_on_struct_enumerator::FoldStrong(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0, + !!2) + IL_001f: stloc.1 + IL_0020: leave.s IL_0039 + + } + finally + { + IL_0022: ldloc.0 + IL_0023: box !!TEnumerator + IL_0028: isinst [runtime]System.IDisposable + IL_002d: stloc.2 + IL_002e: ldloc.2 + IL_002f: brfalse.s IL_0038 + + IL_0031: ldloc.2 + IL_0032: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0037: endfinally + IL_0038: endfinally + } + IL_0039: ldloc.1 + IL_003a: ret + } + + .method public static !!State Fold$W) TEnumerator>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 getEnumerator, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> folder, + !!State state, + !!TSeq source) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 04 66 6F 6C 64 00 00 ) + + .maxstack 5 + .locals init (!!TEnumerator V_0, + !!State V_1, + class [runtime]System.IDisposable V_2) + IL_0000: ldarg.0 + IL_0001: ldarg.3 + IL_0002: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0007: stloc.0 + .try + { + IL_0008: ldarg.1 + IL_0009: ldarg.2 + IL_000a: ldloc.0 + IL_000b: call !!0 Use_binding_on_struct_enumerator::FoldStrong(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0, + !!2) + IL_0010: stloc.1 + IL_0011: leave.s IL_002a + + } + finally + { + IL_0013: ldloc.0 + IL_0014: box !!TEnumerator + IL_0019: isinst [runtime]System.IDisposable + IL_001e: stloc.2 + IL_001f: ldloc.2 + IL_0020: brfalse.s IL_0029 + + IL_0022: ldloc.2 + IL_0023: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0028: endfinally + IL_0029: endfinally + } + IL_002a: ldloc.1 + IL_002b: ret + } + + .method public static string testFoldOnListT() cil managed + { + + .maxstack 5 + .locals init (class [System.Collections]System.Collections.Generic.List`1 V_0, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> V_1, + valuetype [System.Collections]System.Collections.Generic.List`1/Enumerator V_2, + string V_3, + class [runtime]System.IDisposable V_4) + IL_0000: ldc.i4.6 + IL_0001: newarr [runtime]System.Int32 + IL_0006: dup + IL_0007: ldtoken field valuetype ''/T3352_24Bytes@ Use_binding_on_struct_enumerator::field3353@ + IL_000c: call void [runtime]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [runtime]System.Array, + valuetype [runtime]System.RuntimeFieldHandle) + IL_0011: newobj instance void class [System.Collections]System.Collections.Generic.List`1::.ctor(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0016: stloc.0 + IL_0017: ldsfld class Use_binding_on_struct_enumerator/testFoldOnListT@32 Use_binding_on_struct_enumerator/testFoldOnListT@32::@_instance + IL_001c: stloc.1 + IL_001d: ldloc.0 + IL_001e: callvirt instance valuetype [System.Collections]System.Collections.Generic.List`1/Enumerator class [System.Collections]System.Collections.Generic.List`1::GetEnumerator() + IL_0023: stloc.2 + .try + { + IL_0024: ldloc.1 + IL_0025: ldstr "" + IL_002a: ldloc.2 + IL_002b: call !!0 Use_binding_on_struct_enumerator::FoldStrong>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0, + !!2) + IL_0030: stloc.3 + IL_0031: leave.s IL_004d + + } + finally + { + IL_0033: ldloc.2 + IL_0034: box valuetype [System.Collections]System.Collections.Generic.List`1/Enumerator + IL_0039: isinst [runtime]System.IDisposable + IL_003e: stloc.s V_4 + IL_0040: ldloc.s V_4 + IL_0042: brfalse.s IL_004c + + IL_0044: ldloc.s V_4 + IL_0046: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004b: endfinally + IL_004c: endfinally + } + IL_004d: ldloc.3 + IL_004e: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Use_binding_on_struct_enumerator$fsx::init@ + IL_0006: ldsfld int32 ''.$Use_binding_on_struct_enumerator$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call string Use_binding_on_struct_enumerator::testFoldOnListT() + IL_0005: call void [runtime]System.Console::WriteLine(string) + IL_000a: ret + } + +} + +.class private abstract auto ansi sealed ''.$Use_binding_on_struct_enumerator$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Use_binding_on_struct_enumerator::staticInitialization@() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed beforefieldinit '' + extends [runtime]System.Object +{ + .class explicit ansi sealed nested assembly beforefieldinit T3352_24Bytes@ + extends [runtime]System.ValueType + { + .pack 0 + .size 24 + } + +} + + + + +.data cil I_0000398B = bytearray ( + 01 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 + 05 00 00 00 08 00 00 00) + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx.il.netcore.release.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx.il.netcore.release.bsl new file mode 100644 index 00000000000..42931bf4692 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Optimization/samples/use_binding_on_struct_enumerator.fsx.il.netcore.release.bsl @@ -0,0 +1,352 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly extern System.Collections +{ + .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) + .ver 8:0:0:0 +} +.assembly extern runtime { } +.assembly extern netstandard +{ + .publickeytoken = (CC 7B 13 FF CD 2D DD 51 ) + .ver 2:1:0:0 +} +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.mresource public FSharpSignatureData.assembly +{ + + +} +.mresource public FSharpOptimizationData.assembly +{ + + +} +.module assembly.dll + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed Use_binding_on_struct_enumerator + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested assembly beforefieldinit testFoldOnListT@32 + extends class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 + { + .field static assembly initonly class Use_binding_on_struct_enumerator/testFoldOnListT@32 @_instance + .method assembly specialname rtspecialname instance void .ctor() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::.ctor() + IL_0006: ret + } + + .method public strict virtual instance string + Invoke(string state, + int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: box [runtime]System.Int32 + IL_0007: unbox.any [runtime]System.IFormattable + IL_000c: ldnull + IL_000d: call class [netstandard]System.Globalization.CultureInfo [netstandard]System.Globalization.CultureInfo::get_InvariantCulture() + IL_0012: callvirt instance string [netstandard]System.IFormattable::ToString(string, + class [netstandard]System.IFormatProvider) + IL_0017: call string [runtime]System.String::Concat(string, + string) + IL_001c: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Use_binding_on_struct_enumerator/testFoldOnListT@32::.ctor() + IL_0005: stsfld class Use_binding_on_struct_enumerator/testFoldOnListT@32 Use_binding_on_struct_enumerator/testFoldOnListT@32::@_instance + IL_000a: ret + } + + } + + .field static assembly valuetype ''/T3547_24Bytes@ field3548@ at I_0000398D + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method public static !!State FoldStrong) TEnumerator>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> folder, + !!State state, + !!TEnumerator enumerator) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 0A 66 6F 6C 64 53 74 72 6F 6E 67 00 00 ) + + .maxstack 5 + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 V_0, + !!TEnumerator V_1, + !!State V_2, + !!TEnumerator V_3) + IL_0000: ldarg.0 + IL_0001: call class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Adapt(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: stloc.0 + IL_0007: ldarg.2 + IL_0008: stloc.1 + IL_0009: ldarg.1 + IL_000a: stloc.2 + IL_000b: br.s IL_0024 + + IL_000d: ldloc.0 + IL_000e: ldloc.2 + IL_000f: ldarg.2 + IL_0010: stloc.3 + IL_0011: ldloca.s V_3 + IL_0013: constrained. !!TEnumerator + IL_0019: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_001e: callvirt instance !2 class [FSharp.Core]Microsoft.FSharp.Core.OptimizedClosures/FSharpFunc`3::Invoke(!0, + !1) + IL_0023: stloc.2 + IL_0024: ldloca.s V_1 + IL_0026: constrained. !!TEnumerator + IL_002c: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0031: brtrue.s IL_000d + + IL_0033: ldloc.2 + IL_0034: ret + } + + .method public static !!State Fold) TEnumerator>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> folder, + !!State state, + !!TSeq source) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 04 66 6F 6C 64 00 00 ) + + .maxstack 5 + .locals init (!!TEnumerator V_0, + !!State V_1, + class [runtime]System.IDisposable V_2) + IL_0000: ldc.i4.0 + IL_0001: brfalse.s IL_000b + + IL_0003: ldnull + IL_0004: unbox.any !!TEnumerator + IL_0009: br.s IL_0016 + + IL_000b: ldstr "Dynamic invocation of GetEnumerator is not supported" + IL_0010: newobj instance void [runtime]System.NotSupportedException::.ctor(string) + IL_0015: throw + + IL_0016: stloc.0 + .try + { + IL_0017: ldarg.0 + IL_0018: ldarg.1 + IL_0019: ldloc.0 + IL_001a: call !!0 Use_binding_on_struct_enumerator::FoldStrong(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0, + !!2) + IL_001f: stloc.1 + IL_0020: leave.s IL_0039 + + } + finally + { + IL_0022: ldloc.0 + IL_0023: box !!TEnumerator + IL_0028: isinst [runtime]System.IDisposable + IL_002d: stloc.2 + IL_002e: ldloc.2 + IL_002f: brfalse.s IL_0038 + + IL_0031: ldloc.2 + IL_0032: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0037: endfinally + IL_0038: endfinally + } + IL_0039: ldloc.1 + IL_003a: ret + } + + .method public static !!State Fold$W) TEnumerator>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 getEnumerator, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> folder, + !!State state, + !!TSeq source) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationSourceNameAttribute::.ctor(string) = ( 01 00 04 66 6F 6C 64 00 00 ) + + .maxstack 5 + .locals init (!!TEnumerator V_0, + !!State V_1, + class [runtime]System.IDisposable V_2) + IL_0000: ldarg.0 + IL_0001: ldarg.3 + IL_0002: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0007: stloc.0 + .try + { + IL_0008: ldarg.1 + IL_0009: ldarg.2 + IL_000a: ldloc.0 + IL_000b: call !!0 Use_binding_on_struct_enumerator::FoldStrong(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0, + !!2) + IL_0010: stloc.1 + IL_0011: leave.s IL_002a + + } + finally + { + IL_0013: ldloc.0 + IL_0014: box !!TEnumerator + IL_0019: isinst [runtime]System.IDisposable + IL_001e: stloc.2 + IL_001f: ldloc.2 + IL_0020: brfalse.s IL_0029 + + IL_0022: ldloc.2 + IL_0023: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0028: endfinally + IL_0029: endfinally + } + IL_002a: ldloc.1 + IL_002b: ret + } + + .method public static string testFoldOnListT() cil managed + { + + .maxstack 5 + .locals init (class [System.Collections]System.Collections.Generic.List`1 V_0, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> V_1, + valuetype [System.Collections]System.Collections.Generic.List`1/Enumerator V_2, + string V_3, + class [runtime]System.IDisposable V_4) + IL_0000: ldc.i4.6 + IL_0001: newarr [runtime]System.Int32 + IL_0006: dup + IL_0007: ldtoken field valuetype ''/T3547_24Bytes@ Use_binding_on_struct_enumerator::field3548@ + IL_000c: call void [runtime]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [runtime]System.Array, + valuetype [runtime]System.RuntimeFieldHandle) + IL_0011: newobj instance void class [System.Collections]System.Collections.Generic.List`1::.ctor(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0016: stloc.0 + IL_0017: ldsfld class Use_binding_on_struct_enumerator/testFoldOnListT@32 Use_binding_on_struct_enumerator/testFoldOnListT@32::@_instance + IL_001c: stloc.1 + IL_001d: ldloc.0 + IL_001e: callvirt instance valuetype [System.Collections]System.Collections.Generic.List`1/Enumerator class [System.Collections]System.Collections.Generic.List`1::GetEnumerator() + IL_0023: stloc.2 + .try + { + IL_0024: ldloc.1 + IL_0025: ldstr "" + IL_002a: ldloc.2 + IL_002b: call !!0 Use_binding_on_struct_enumerator::FoldStrong>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !!0, + !!2) + IL_0030: stloc.3 + IL_0031: leave.s IL_004d + + } + finally + { + IL_0033: ldloc.2 + IL_0034: box valuetype [System.Collections]System.Collections.Generic.List`1/Enumerator + IL_0039: isinst [runtime]System.IDisposable + IL_003e: stloc.s V_4 + IL_0040: ldloc.s V_4 + IL_0042: brfalse.s IL_004c + + IL_0044: ldloc.s V_4 + IL_0046: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004b: endfinally + IL_004c: endfinally + } + IL_004d: ldloc.3 + IL_004e: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: stsfld int32 ''.$Use_binding_on_struct_enumerator$fsx::init@ + IL_0006: ldsfld int32 ''.$Use_binding_on_struct_enumerator$fsx::init@ + IL_000b: pop + IL_000c: ret + } + + .method assembly specialname static void staticInitialization@() cil managed + { + + .maxstack 8 + IL_0000: call string Use_binding_on_struct_enumerator::testFoldOnListT() + IL_0005: call void [runtime]System.Console::WriteLine(string) + IL_000a: ret + } + +} + +.class private abstract auto ansi sealed ''.$Use_binding_on_struct_enumerator$fsx + extends [runtime]System.Object +{ + .field static assembly int32 init@ + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 8 + IL_0000: call void Use_binding_on_struct_enumerator::staticInitialization@() + IL_0005: ret + } + +} + +.class private abstract auto ansi sealed beforefieldinit '' + extends [runtime]System.Object +{ + .class explicit ansi sealed nested assembly beforefieldinit T3547_24Bytes@ + extends [runtime]System.ValueType + { + .pack 0 + .size 24 + } + +} + + + + +.data cil I_0000398D = bytearray ( + 01 00 00 00 01 00 00 00 02 00 00 00 03 00 00 00 + 05 00 00 00 08 00 00 00) + + diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 4f04946a466..08a1506f0fa 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -175,9 +175,11 @@ - + + + diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index 1cbf3a3aade..2c6864bc014 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -1099,10 +1099,28 @@ module rec Compiler = let convenienceBaselineInstructions baseline expected actual = + + let getLines (text: string) = + [| + let reader = new StringReader(text) + let mutable line = reader.ReadLine() + while not(isNull line) do + line + line <- reader.ReadLine() + |] + let expectedLines = getLines expected |> Array.indexed + let actualLines = getLines actual |> Array.indexed + let firstDiff = + Seq.zip expectedLines actualLines + |> Seq.skipWhile (fun (a,b) -> a = b) + |> Seq.tryHead + |> function | None -> "" + | Some((line, expected), (_,actual)) -> $"diff at line {line+1}:\nexpected:\n{expected}\nactual:\n{actual}\n" $"""to update baseline: $ cp {baseline.FilePath} {baseline.BslSource} to compare baseline: $ code --diff {baseline.FilePath} {baseline.BslSource} +{firstDiff} Expected: {expected} Actual: @@ -1148,6 +1166,7 @@ Actual: ).Replace("\r\n","\n") if errorsExpectedBaseLine <> errorsActual then + fs.CreateOutputDirectory() createBaselineErrors bsl.FSBaseline errorsActual updateBaseLineIfEnvironmentSaysSo bsl.FSBaseline diff --git a/tests/FSharp.Test.Utilities/CompilerAssert.fs b/tests/FSharp.Test.Utilities/CompilerAssert.fs index a97b214acde..0156c2a5c5f 100644 --- a/tests/FSharp.Test.Utilities/CompilerAssert.fs +++ b/tests/FSharp.Test.Utilities/CompilerAssert.fs @@ -315,8 +315,11 @@ module rec CompilerAssertHelpers = // lookup the last static constructor // of the assembly types, which should match // the equivalent of a .fsx entry point - let moduleInitType = asm.GetTypes() |> Array.last - moduleInitType.GetConstructors(BindingFlags.Static ||| BindingFlags.NonPublic).[0] :> MethodBase + let startupcodeType = asm.GetTypes() |> Array.tryFindBack (fun m -> m.Name.StartsWith "$" && m.Name.EndsWith "$fsx") + match startupcodeType with + | None -> failwith $"unable to find startup code in script {asm.Location}" + | Some moduleInitType -> + moduleInitType.GetConstructors(BindingFlags.Static ||| BindingFlags.NonPublic).[0] :> MethodBase else entryPoint let args = mkDefaultArgs entryPoint @@ -407,6 +410,7 @@ module rec CompilerAssertHelpers = // Generate a response file, purely for diagnostic reasons. File.WriteAllLines(Path.ChangeExtension(outputFilePath, ".rsp"), args) + FSharp.Compiler.CompilerGlobalState.resetUniqueAndStamp() let errors, rc = checker.Compile args |> Async.RunImmediate errors, rc, outputFilePath