From cc670d05228afc310d23842db72bcba4dd14fcbb Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Tue, 23 Jan 2024 14:49:33 -0500 Subject: [PATCH 01/25] Better lowering of `[lo..hi]` & `[|lo..hi|]` --- .../Optimize/LowerComputedCollections.fs | 62 ++ src/Compiler/TypedTree/TcGlobals.fs | 6 + src/Compiler/TypedTree/TypedTreeOps.fs | 4 + src/Compiler/TypedTree/TypedTreeOps.fsi | 4 + tests/FSharp.Test.Utilities/ILChecker.fs | 12 +- .../ComputedCollectionLoweringTests.fs | 648 ++++++++++++++++++ tests/fsharp/FSharpSuite.Tests.fsproj | 3 +- 7 files changed, 737 insertions(+), 2 deletions(-) create mode 100644 tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index f2f3e4f6245..4afbbb82591 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -252,15 +252,77 @@ let (|SeqToArray|_|) g expr = | ValApp g g.seq_to_array_vref (_, [seqExpr], m) -> Some (seqExpr, m) | _ -> None +[] +let (|ConstInt32Range|_|) g expr = + match expr with + | ValApp g g.range_int32_op_vref ([], [Expr.Const (value = Const.Int32 start); Expr.Const (value = Const.Int32 1); Expr.Const (value = Const.Int32 finish)], _), _ -> ValueSome (start, finish) + | _ -> ValueNone + +[] +let (|Int32Range|_|) g expr = + match expr with + | ValApp g g.range_int32_op_vref ([], [start; Expr.Const (value = Const.Int32 1); finish], _), _ -> ValueSome (start, finish) + | _ -> ValueNone + let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = // If ListCollector is in FSharp.Core then this optimization kicks in if g.ListCollector_tcr.CanDeref then + let constListSizeThreshold = 100 + let constArraySizeThreshold = int System.UInt16.MaxValue match overallExpr with + // [5..1] → [] + | SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when + start > finish + -> + Some (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m)) + + // [1..5] → [1; 2; 3; 4; 5] ≡ 1 :: 2 :: 3 :: 4 :: 5 :: [] + | SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), _) when + finish - start + 1 < constListSizeThreshold + -> + let rec conses acc n = + if n < start then acc + else conses (mkCons g g.int32_ty (Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)) acc) (n - 1) + + Some (conses (mkNil g Text.Range.range0 g.int32_ty) finish) + + // [start..finish] → List.init (finish - start + 1) ((+) start) + | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> + let diff = mkAsmExpr ([AbstractIL.IL.AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) + let range = mkAsmExpr ([AbstractIL.IL.AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) + let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty + let body = mkAsmExpr ([AbstractIL.IL.AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) + let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) + let init = mkCallListInit g m g.int32_ty range initializer + Some init + | SeqToList g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ListCollector_ty overallElemTy LowerComputedListOrArraySeqExpr tcVal g amap m collectorTy overallSeqExpr + // [|5..1|] → [||] + | SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when + start > finish + -> + Some (mkArray (g.int32_ty, [], m)) + + // [|1..5|] → [|1; 2; 3; 4; 5|] + | SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when + finish - start + 1 < constArraySizeThreshold + -> + Some (mkArray (g.int32_ty, [for n in start..finish -> Expr.Const(Const.Int32 n, Text.Range.range0, g.int32_ty)], m)) + + // [|start..finish|] → Array.init (finish - start + 1) ((+) start) + | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> + let diff = mkAsmExpr ([AbstractIL.IL.AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) + let range = mkAsmExpr ([AbstractIL.IL.AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) + let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty + let body = mkAsmExpr ([AbstractIL.IL.AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) + let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) + let init = mkCallArrayInit g m g.int32_ty range initializer + Some init + | SeqToArray g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ArrayCollector_ty overallElemTy LowerComputedListOrArraySeqExpr tcVal g amap m collectorTy overallSeqExpr diff --git a/src/Compiler/TypedTree/TcGlobals.fs b/src/Compiler/TypedTree/TcGlobals.fs index 3830dd008e5..bf6661ddce6 100644 --- a/src/Compiler/TypedTree/TcGlobals.fs +++ b/src/Compiler/TypedTree/TcGlobals.fs @@ -811,6 +811,7 @@ type TcGlobals( let v_range_int32_op_info = makeIntrinsicValRef(fslib_MFOperatorIntrinsics_nleref, "RangeInt32" , None , None , [], ([[v_int_ty];[v_int_ty];[v_int_ty]], mkSeqTy v_int_ty)) let v_array_length_info = makeIntrinsicValRef(fslib_MFArrayModule_nleref, "length" , None , Some "Length" , [vara], ([[mkArrayType 1 varaTy]], v_int_ty)) + let v_array_init_info = makeIntrinsicValRef(fslib_MFArrayModule_nleref, "init" , None , Some "Initialize", [vara], ([[v_int32_ty]; [v_int32_ty --> varaTy]], mkArrayType 1 varaTy)) let v_array_get_info = makeIntrinsicValRef(fslib_MFIntrinsicFunctions_nleref, "GetArray" , None , None , [vara], ([[mkArrayType 1 varaTy]; [v_int_ty]], varaTy)) let v_array2D_get_info = makeIntrinsicValRef(fslib_MFIntrinsicFunctions_nleref, "GetArray2D" , None , None , [vara], ([[mkArrayType 2 varaTy];[v_int_ty]; [v_int_ty]], varaTy)) let v_array3D_get_info = makeIntrinsicValRef(fslib_MFIntrinsicFunctions_nleref, "GetArray3D" , None , None , [vara], ([[mkArrayType 3 varaTy];[v_int_ty]; [v_int_ty]; [v_int_ty]], varaTy)) @@ -820,6 +821,8 @@ type TcGlobals( let v_array3D_set_info = makeIntrinsicValRef(fslib_MFIntrinsicFunctions_nleref, "SetArray3D" , None , None , [vara], ([[mkArrayType 3 varaTy];[v_int_ty]; [v_int_ty]; [v_int_ty]; [varaTy]], v_unit_ty)) let v_array4D_set_info = makeIntrinsicValRef(fslib_MFIntrinsicFunctions_nleref, "SetArray4D" , None , None , [vara], ([[mkArrayType 4 varaTy];[v_int_ty]; [v_int_ty]; [v_int_ty]; [v_int_ty]; [varaTy]], v_unit_ty)) + let v_list_init_info = makeIntrinsicValRef(fslib_MFListModule_nleref, "init" , None , Some "Initialize", [vara], ([[v_int32_ty]; [v_int32_ty --> varaTy]], mkListTy varaTy)) + let v_option_toNullable_info = makeIntrinsicValRef(fslib_MFOptionModule_nleref, "toNullable" , None , Some "ToNullable" , [vara], ([[mkOptionTy varaTy]], mkNullableTy varaTy)) let v_option_defaultValue_info = makeIntrinsicValRef(fslib_MFOptionModule_nleref, "defaultValue" , None , Some "DefaultValue" , [vara], ([[varaTy]; [mkOptionTy varaTy]], varaTy)) @@ -1751,6 +1754,7 @@ type TcGlobals( member _.seq_to_array_info = v_seq_to_array_info member _.array_length_info = v_array_length_info + member _.array_init_info = v_array_init_info member _.array_get_info = v_array_get_info member _.array2D_get_info = v_array2D_get_info member _.array3D_get_info = v_array3D_get_info @@ -1760,6 +1764,8 @@ type TcGlobals( member _.array3D_set_info = v_array3D_set_info member _.array4D_set_info = v_array4D_set_info + member _.list_init_info = v_list_init_info + member val option_toNullable_info = v_option_toNullable_info member val option_defaultValue_info = v_option_defaultValue_info diff --git a/src/Compiler/TypedTree/TypedTreeOps.fs b/src/Compiler/TypedTree/TypedTreeOps.fs index 8616a7e43fa..e789d4c5140 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.fs @@ -7736,6 +7736,8 @@ let mkCallToEnumOperator (g: TcGlobals) m ty e1 = mkApps g (typedExprForIntrinsi let mkCallArrayLength (g: TcGlobals) m ty e1 = mkApps g (typedExprForIntrinsic g m g.array_length_info, [[ty]], [e1], m) +let mkCallArrayInit (g: TcGlobals) m ty e1 e2 = mkApps g (typedExprForIntrinsic g m g.array_init_info, [[ty]], [e1; e2], m) + let mkCallArrayGet (g: TcGlobals) m ty e1 idx1 = mkApps g (typedExprForIntrinsic g m g.array_get_info, [[ty]], [ e1 ; idx1 ], m) let mkCallArray2DGet (g: TcGlobals) m ty e1 idx1 idx2 = mkApps g (typedExprForIntrinsic g m g.array2D_get_info, [[ty]], [ e1 ; idx1; idx2 ], m) @@ -7752,6 +7754,8 @@ let mkCallArray3DSet (g: TcGlobals) m ty e1 idx1 idx2 idx3 v = mkApps g (typedEx let mkCallArray4DSet (g: TcGlobals) m ty e1 idx1 idx2 idx3 idx4 v = mkApps g (typedExprForIntrinsic g m g.array4D_set_info, [[ty]], [ e1 ; idx1; idx2; idx3; idx4; v ], m) +let mkCallListInit (g: TcGlobals) m ty e1 e2 = mkApps g (typedExprForIntrinsic g m g.list_init_info, [[ty]], [e1; e2], m) + let mkCallHash (g: TcGlobals) m ty e1 = mkApps g (typedExprForIntrinsic g m g.hash_info, [[ty]], [ e1 ], m) let mkCallBox (g: TcGlobals) m ty e1 = mkApps g (typedExprForIntrinsic g m g.box_info, [[ty]], [ e1 ], m) diff --git a/src/Compiler/TypedTree/TypedTreeOps.fsi b/src/Compiler/TypedTree/TypedTreeOps.fsi index 2345ac5eb40..fd74ebf4b17 100755 --- a/src/Compiler/TypedTree/TypedTreeOps.fsi +++ b/src/Compiler/TypedTree/TypedTreeOps.fsi @@ -2015,6 +2015,8 @@ val mkCallCreateEvent: TcGlobals -> range -> TType -> TType -> Expr -> Expr -> E val mkCallArrayLength: TcGlobals -> range -> TType -> Expr -> Expr +val mkCallArrayInit: TcGlobals -> range -> TType -> Expr -> Expr -> Expr + val mkCallArrayGet: TcGlobals -> range -> TType -> Expr -> Expr -> Expr val mkCallArray2DGet: TcGlobals -> range -> TType -> Expr -> Expr -> Expr -> Expr @@ -2031,6 +2033,8 @@ val mkCallArray3DSet: TcGlobals -> range -> TType -> Expr -> Expr -> Expr -> Exp val mkCallArray4DSet: TcGlobals -> range -> TType -> Expr -> Expr -> Expr -> Expr -> Expr -> Expr -> Expr +val mkCallListInit: TcGlobals -> range -> TType -> Expr -> Expr -> Expr + val mkCallHash: TcGlobals -> range -> TType -> Expr -> Expr val mkCallBox: TcGlobals -> range -> TType -> Expr -> Expr diff --git a/tests/FSharp.Test.Utilities/ILChecker.fs b/tests/FSharp.Test.Utilities/ILChecker.fs index 8164f876a52..e1c98765798 100644 --- a/tests/FSharp.Test.Utilities/ILChecker.fs +++ b/tests/FSharp.Test.Utilities/ILChecker.fs @@ -129,9 +129,19 @@ module ILChecker = errorMsgOpt <- Some(msg + "\nExpected:\n" + ilCode + "\n") else for i = 0 to expectedLines.Length - 1 do + let ignorePrivateImplDeets (s: string) = + // .field static assembly valuetype ''/T3169_40Bytes@ field3170@ at I_000028A7 + let s = match s.IndexOf "PrivateImplementationDetails" with -1 -> s | i -> s[..i] + // .class explicit ansi sealed nested assembly beforefieldinit T3169_40Bytes@ + let s = match s.IndexOf ".class explicit ansi sealed nested assembly beforefieldinit" with -1 -> s | i -> s[..i] + // .data cil I_000028A7 = bytearray ( + let s = match s.IndexOf ".data cil" with -1 -> s | i -> s[..i] + s + let expected = expectedLines[i].Trim() let actual = actualLines[i].Trim() - if expected <> actual then + + if ignorePrivateImplDeets expected <> ignorePrivateImplDeets actual then errors.Add $"\n==\nName: '%s{actualLines[0]}'\n\nExpected:\t %s{expected}\nActual:\t\t %s{actual}\n==" if errors.Count > 0 then diff --git a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs new file mode 100644 index 00000000000..54c6ec08b1e --- /dev/null +++ b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs @@ -0,0 +1,648 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.UnitTests + +open NUnit.Framework +open FSharp.Test + +[] +module ComputedCollectionLoweringTests = + module Array = + [] + let ``Lone RangeInt32 with const args when start > finish lowers to empty array``() = + CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], + """ + module Test + + let test () = [|10..1|] + """, + (fun verifier -> verifier.VerifyIL [ + """ + .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 Test + 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 int32[] test() cil managed + { + + .maxstack 8 + IL_0000: call !!0[] [runtime]System.Array::Empty() + IL_0005: ret + } + + } + + .class private abstract auto ansi sealed ''.$Test + extends [runtime]System.Object + { + } + """ + ])) + + [] + let ``Lone RangeInt32 with const args lowers to blob``() = + CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], + """ + module Test + + let test () = [|1..10|] + """, + (fun verifier -> verifier.VerifyIL [ + """ + .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 Test + 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 valuetype ''/T3169_40Bytes@ field3170@ at I_000028A7 + .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .method public static int32[] test() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.s 10 + IL_0002: newarr [runtime]System.Int32 + IL_0007: dup + IL_0008: ldtoken field valuetype ''/T3169_40Bytes@ Test::field3170@ + IL_000d: call void [runtime]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [runtime]System.Array, + valuetype [runtime]System.RuntimeFieldHandle) + IL_0012: ret + } + + } + + .class private abstract auto ansi sealed ''.$Test + extends [runtime]System.Object + { + } + + .class private abstract auto ansi sealed beforefieldinit '' + extends [runtime]System.Object + { + .class explicit ansi sealed nested assembly beforefieldinit T3169_40Bytes@ + extends [runtime]System.ValueType + { + .pack 0 + .size 40 + } + + } + + + + + .data cil I_000028A7 = bytearray ( + 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 + 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 + 09 00 00 00 0A 00 00 00) + """ + ])) + + [] + let ``Lone RangeInt32 with dynamic args lowers to call to init``() = + CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], + """ + module Test + + let test start finish = [|start..finish|] + """, + (fun verifier -> verifier.VerifyIL [ + """ + .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 Test + 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 test@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public int32 start + .method assembly specialname rtspecialname + instance void .ctor(int32 start) 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 int32 Test/test@1::start + IL_000d: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 Test/test@1::start + IL_0006: ldarg.1 + IL_0007: add + IL_0008: ret + } + + } + + .method public static int32[] test(int32 start, + int32 finish) 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.1 + IL_0001: ldarg.0 + IL_0002: sub + IL_0003: ldc.i4.1 + IL_0004: add + IL_0005: ldarg.0 + IL_0006: newobj instance void Test/test@1::.ctor(int32) + IL_000b: tail. + IL_000d: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0012: ret + } + + } + + .class private abstract auto ansi sealed ''.$Test + extends [runtime]System.Object + { + } + """ + ])) + + module List = + [] + let ``Lone RangeInt32 with const args when start > finish lowers to empty list``() = + CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], + """ + module Test + + let test () = [10..1] + """, + (fun verifier -> verifier.VerifyIL [ + """ + .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 Test + 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.Collections.FSharpList`1 + test() cil managed + { + + .maxstack 8 + IL_0000: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_0005: ret + } + + } + + .class private abstract auto ansi sealed ''.$Test + extends [runtime]System.Object + { + } + """ + ])) + + [] + let ``Lone small RangeInt32 with const args lowers to conses``() = + CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], + """ + module Test + + let test () = [1..10] + """, + (fun verifier -> verifier.VerifyIL [ + """ + .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 Test + 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.Collections.FSharpList`1 + test() cil managed + { + + .maxstack 13 + IL_0000: ldc.i4.1 + IL_0001: ldc.i4.2 + IL_0002: ldc.i4.3 + IL_0003: ldc.i4.4 + IL_0004: ldc.i4.5 + IL_0005: ldc.i4.6 + IL_0006: ldc.i4.7 + IL_0007: ldc.i4.8 + IL_0008: ldc.i4.s 9 + IL_000a: ldc.i4.s 10 + IL_000c: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_0011: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_0016: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_001b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_0020: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_0025: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_002a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_002f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_0034: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_0039: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_003e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_0043: ret + } + + } + + .class private abstract auto ansi sealed ''.$Test + extends [runtime]System.Object + { + } + """ + ])) + + [] + let ``Lone bigger RangeInt32 with const args lowers to call to init``() = + CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], + """ + module Test + + let test () = [1..10_000] + """, + (fun verifier -> verifier.VerifyIL [ + """ + .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 Test + 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 test@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class Test/test@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Test/test@1::.ctor() + IL_0005: stsfld class Test/test@1 Test/test@1::@_instance + IL_000a: ret + } + + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + test() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4 0x2710 + IL_0005: ldc.i4.1 + IL_0006: sub + IL_0007: ldc.i4.1 + IL_0008: add + IL_0009: ldsfld class Test/test@1 Test/test@1::@_instance + IL_000e: tail. + IL_0010: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0015: ret + } + + } + + .class private abstract auto ansi sealed ''.$Test + extends [runtime]System.Object + { + } + """ + ])) + + [] + let ``Lone RangeInt32 with dynamic args lowers to call to init``() = + CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], + """ + module Test + + let test start finish = [start..finish] + """, + (fun verifier -> verifier.VerifyIL [ + """ + .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 Test + 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 test@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public int32 start + .method assembly specialname rtspecialname + instance void .ctor(int32 start) 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 int32 Test/test@1::start + IL_000d: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 Test/test@1::start + IL_0006: ldarg.1 + IL_0007: add + IL_0008: ret + } + + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + test(int32 start, + int32 finish) 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.1 + IL_0001: ldarg.0 + IL_0002: sub + IL_0003: ldc.i4.1 + IL_0004: add + IL_0005: ldarg.0 + IL_0006: newobj instance void Test/test@1::.ctor(int32) + IL_000b: tail. + IL_000d: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0012: ret + } + + } + + .class private abstract auto ansi sealed ''.$Test + extends [runtime]System.Object + { + } + """ + ])) + diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index b6d69d8ae1a..c22183118b1 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -72,6 +72,7 @@ + @@ -109,7 +110,7 @@ false - + From 4c3da4a19bf756484e841bdddaa11b921c1ebbfb Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Tue, 23 Jan 2024 15:42:57 -0500 Subject: [PATCH 02/25] Not much point to that --- src/Compiler/Optimize/LowerComputedCollections.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 4afbbb82591..cbe31f17e1f 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -279,7 +279,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = // [1..5] → [1; 2; 3; 4; 5] ≡ 1 :: 2 :: 3 :: 4 :: 5 :: [] | SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), _) when - finish - start + 1 < constListSizeThreshold + finish - start < constListSizeThreshold -> let rec conses acc n = if n < start then acc @@ -309,7 +309,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = // [|1..5|] → [|1; 2; 3; 4; 5|] | SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when - finish - start + 1 < constArraySizeThreshold + finish - start < constArraySizeThreshold -> Some (mkArray (g.int32_ty, [for n in start..finish -> Expr.Const(Const.Int32 n, Text.Range.range0, g.int32_ty)], m)) From 09f4023e0a1ddcc9d65fd0c7445d7ad21afc045c Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Wed, 24 Jan 2024 14:21:17 -0500 Subject: [PATCH 03/25] Fix path casing in fsproj --- tests/fsharp/FSharpSuite.Tests.fsproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fsharp/FSharpSuite.Tests.fsproj b/tests/fsharp/FSharpSuite.Tests.fsproj index c22183118b1..c7cd7c6e1f5 100644 --- a/tests/fsharp/FSharpSuite.Tests.fsproj +++ b/tests/fsharp/FSharpSuite.Tests.fsproj @@ -72,7 +72,7 @@ - + From dcc970d71148d0ced5273e588253ce800fe92834 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Wed, 24 Jan 2024 14:21:47 -0500 Subject: [PATCH 04/25] Add comments --- src/Compiler/Optimize/LowerComputedCollections.fs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index cbe31f17e1f..4aecc80d18f 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -252,12 +252,14 @@ let (|SeqToArray|_|) g expr = | ValApp g g.seq_to_array_vref (_, [seqExpr], m) -> Some (seqExpr, m) | _ -> None +/// 1..10 [] let (|ConstInt32Range|_|) g expr = match expr with | ValApp g g.range_int32_op_vref ([], [Expr.Const (value = Const.Int32 start); Expr.Const (value = Const.Int32 1); Expr.Const (value = Const.Int32 finish)], _), _ -> ValueSome (start, finish) | _ -> ValueNone +/// start..finish [] let (|Int32Range|_|) g expr = match expr with @@ -281,6 +283,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = | SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), _) when finish - start < constListSizeThreshold -> + // … :: … :: … let rec conses acc n = if n < start then acc else conses (mkCons g g.int32_ty (Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)) acc) (n - 1) From 720a241da43326a0ab03aab75994cf37b3df84f9 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Wed, 24 Jan 2024 14:22:45 -0500 Subject: [PATCH 05/25] Use smaller, byte-based const arr threshold --- src/Compiler/Optimize/LowerComputedCollections.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 4aecc80d18f..089d8988ebd 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -270,7 +270,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = // If ListCollector is in FSharp.Core then this optimization kicks in if g.ListCollector_tcr.CanDeref then let constListSizeThreshold = 100 - let constArraySizeThreshold = int System.UInt16.MaxValue + let constArrayBytesThreshold = 1024 match overallExpr with // [5..1] → [] @@ -312,7 +312,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = // [|1..5|] → [|1; 2; 3; 4; 5|] | SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when - finish - start < constArraySizeThreshold + (finish - start) * sizeof < constArrayBytesThreshold -> Some (mkArray (g.int32_ty, [for n in start..finish -> Expr.Const(Const.Int32 n, Text.Range.range0, g.int32_ty)], m)) From 0a23a5e0c545fa8307374adae96306f7869eccac Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Wed, 24 Jan 2024 14:23:05 -0500 Subject: [PATCH 06/25] Dynamically return empty if start > finish --- .../Optimize/LowerComputedCollections.fs | 38 ++-- .../ComputedCollectionLoweringTests.fs | 204 +++++++++++++++--- 2 files changed, 197 insertions(+), 45 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 089d8988ebd..acdcd5ff54b 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -2,7 +2,7 @@ module internal FSharp.Compiler.LowerComputedCollectionExpressions -open Internal.Utilities.Library +open FSharp.Compiler.AbstractIL.IL open FSharp.Compiler.AccessibilityLogic open FSharp.Compiler.DiagnosticsLogger open FSharp.Compiler.InfoReader @@ -290,15 +290,20 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = Some (conses (mkNil g Text.Range.range0 g.int32_ty) finish) - // [start..finish] → List.init (finish - start + 1) ((+) start) + // [start..finish] → if start <= finish then List.init (finish - start + 1) ((+) start) else [] | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> - let diff = mkAsmExpr ([AbstractIL.IL.AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) - let range = mkAsmExpr ([AbstractIL.IL.AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) + let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) + let range = mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty - let body = mkAsmExpr ([AbstractIL.IL.AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) + let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) - let init = mkCallListInit g m g.int32_ty range initializer - Some init + let init = mkAsmExpr ([I_ret], [], [mkCallListInit g m g.int32_ty range initializer], [], Text.Range.range0) + + let emptyLabel = generateCodeLabel () + let empty = mkLabelled Text.Range.range0 emptyLabel (mkNil g Text.Range.range0 g.int32_ty) + let breakToEmptyIfStartGtFinish = mkAsmExpr ([I_brcmp (BI_bgt, emptyLabel)], [], [start; finish], [g.int32_ty], Text.Range.range0) + + Some (mkAsmExpr ([], [], [breakToEmptyIfStartGtFinish; init; empty], [], Text.Range.range0)) | SeqToList g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ListCollector_ty overallElemTy @@ -314,17 +319,22 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = | SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when (finish - start) * sizeof < constArrayBytesThreshold -> - Some (mkArray (g.int32_ty, [for n in start..finish -> Expr.Const(Const.Int32 n, Text.Range.range0, g.int32_ty)], m)) + Some (mkArray (g.int32_ty, [for n in start..finish -> Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)], m)) - // [|start..finish|] → Array.init (finish - start + 1) ((+) start) + // [|start..finish|] → if start <= finish then Array.init (finish - start + 1) ((+) start) else [||] | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> - let diff = mkAsmExpr ([AbstractIL.IL.AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) - let range = mkAsmExpr ([AbstractIL.IL.AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) + let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) + let range = mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty - let body = mkAsmExpr ([AbstractIL.IL.AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) + let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) - let init = mkCallArrayInit g m g.int32_ty range initializer - Some init + let init = mkAsmExpr ([I_ret], [], [mkCallArrayInit g m g.int32_ty range initializer], [], Text.Range.range0) + + let emptyLabel = generateCodeLabel () + let empty = mkLabelled Text.Range.range0 emptyLabel (mkArray (g.int32_ty, [], m)) + let breakToEmptyIfStartGtFinish = mkAsmExpr ([I_brcmp (BI_bgt, emptyLabel)], [], [start; finish], [g.int32_ty], Text.Range.range0) + + Some (mkAsmExpr ([], [], [breakToEmptyIfStartGtFinish; init; empty], [], Text.Range.range0)) | SeqToArray g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ArrayCollector_ty overallElemTy diff --git a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs index 54c6ec08b1e..78d8fdd09c3 100644 --- a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs +++ b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs @@ -9,7 +9,7 @@ open FSharp.Test module ComputedCollectionLoweringTests = module Array = [] - let ``Lone RangeInt32 with const args when start > finish lowers to empty array``() = + let ``Lone RangeInt32 with const args when start > finish lowers to empty array`` () = CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], """ module Test @@ -72,7 +72,7 @@ module ComputedCollectionLoweringTests = ])) [] - let ``Lone RangeInt32 with const args lowers to blob``() = + let ``Lone RangeInt32 with const args ≤ 1024 bytes lowers to blob`` () = CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], """ module Test @@ -162,7 +162,125 @@ module ComputedCollectionLoweringTests = ])) [] - let ``Lone RangeInt32 with dynamic args lowers to call to init``() = + let ``Lone RangeInt32 with const args > 1024 bytes lowers to call to init`` () = + CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], + """ + module Test + + let test () = [|1..257|] + """, + (fun verifier -> verifier.VerifyIL [ + """ + .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 Test + 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 test@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class Test/test@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Test/test@1::.ctor() + IL_0005: stsfld class Test/test@1 Test/test@1::@_instance + IL_000a: ret + } + + } + + .method public static int32[] test() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldc.i4 0x101 + IL_0006: bgt.s IL_001d + + IL_0008: ldc.i4 0x101 + IL_000d: ldc.i4.1 + IL_000e: sub + IL_000f: ldc.i4.1 + IL_0010: add + IL_0011: ldsfld class Test/test@1 Test/test@1::@_instance + IL_0016: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_001b: ret + + IL_001c: ldnull + IL_001d: call !!0[] [runtime]System.Array::Empty() + IL_0022: ldnull + IL_0023: ret + } + + } + + .class private abstract auto ansi sealed ''.$Test + extends [runtime]System.Object + { + } + """ + ])) + + [] + let ``Lone RangeInt32 with dynamic args lowers to call to init`` () = CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], """ module Test @@ -246,17 +364,25 @@ module ComputedCollectionLoweringTests = .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.1 - IL_0001: ldarg.0 - IL_0002: sub - IL_0003: ldc.i4.1 - IL_0004: add + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: bgt.s IL_0016 + + IL_0004: ldarg.1 IL_0005: ldarg.0 - IL_0006: newobj instance void Test/test@1::.ctor(int32) - IL_000b: tail. - IL_000d: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0006: sub + IL_0007: ldc.i4.1 + IL_0008: add + IL_0009: ldarg.0 + IL_000a: newobj instance void Test/test@1::.ctor(int32) + IL_000f: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0012: ret + IL_0014: ret + + IL_0015: ldnull + IL_0016: call !!0[] [runtime]System.Array::Empty() + IL_001b: ldnull + IL_001c: ret } } @@ -270,7 +396,7 @@ module ComputedCollectionLoweringTests = module List = [] - let ``Lone RangeInt32 with const args when start > finish lowers to empty list``() = + let ``Lone RangeInt32 with const args when start > finish lowers to empty list`` () = CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], """ module Test @@ -334,7 +460,7 @@ module ComputedCollectionLoweringTests = ])) [] - let ``Lone small RangeInt32 with const args lowers to conses``() = + let ``Lone small RangeInt32 with const args ≤ 100 lowers to conses`` () = CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], """ module Test @@ -428,12 +554,12 @@ module ComputedCollectionLoweringTests = ])) [] - let ``Lone bigger RangeInt32 with const args lowers to call to init``() = + let ``Lone RangeInt32 with const args > 100 lowers to call to init`` () = CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], """ module Test - let test () = [1..10_000] + let test () = [1..101] """, (fun verifier -> verifier.VerifyIL [ """ @@ -517,16 +643,24 @@ module ComputedCollectionLoweringTests = { .maxstack 8 - IL_0000: ldc.i4 0x2710 - IL_0005: ldc.i4.1 - IL_0006: sub + IL_0000: ldc.i4.1 + IL_0001: ldc.i4.s 101 + IL_0003: bgt.s IL_0017 + + IL_0005: ldc.i4.s 101 IL_0007: ldc.i4.1 - IL_0008: add - IL_0009: ldsfld class Test/test@1 Test/test@1::@_instance - IL_000e: tail. + IL_0008: sub + IL_0009: ldc.i4.1 + IL_000a: add + IL_000b: ldsfld class Test/test@1 Test/test@1::@_instance IL_0010: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) IL_0015: ret + + IL_0016: ldnull + IL_0017: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_001c: ldnull + IL_001d: ret } } @@ -624,17 +758,25 @@ module ComputedCollectionLoweringTests = .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.1 - IL_0001: ldarg.0 - IL_0002: sub - IL_0003: ldc.i4.1 - IL_0004: add + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: bgt.s IL_0016 + + IL_0004: ldarg.1 IL_0005: ldarg.0 - IL_0006: newobj instance void Test/test@1::.ctor(int32) - IL_000b: tail. - IL_000d: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_0006: sub + IL_0007: ldc.i4.1 + IL_0008: add + IL_0009: ldarg.0 + IL_000a: newobj instance void Test/test@1::.ctor(int32) + IL_000f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0012: ret + IL_0014: ret + + IL_0015: ldnull + IL_0016: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_001b: ldnull + IL_001c: ret } } From dd40c16d42138f4027cbc624d51fb1dfe5e442fa Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Wed, 24 Jan 2024 14:36:44 -0500 Subject: [PATCH 07/25] Better place to put the range, probably --- src/Compiler/Optimize/LowerComputedCollections.fs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 1b5ed8cc804..9e62cf7f0f1 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -300,13 +300,13 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) - let init = mkAsmExpr ([I_ret], [], [mkCallListInit g m g.int32_ty range initializer], [], Text.Range.range0) + let init = mkAsmExpr ([I_ret], [], [mkCallListInit g Text.Range.range0 g.int32_ty range initializer], [], Text.Range.range0) let emptyLabel = generateCodeLabel () let empty = mkLabelled Text.Range.range0 emptyLabel (mkNil g Text.Range.range0 g.int32_ty) let breakToEmptyIfStartGtFinish = mkAsmExpr ([I_brcmp (BI_bgt, emptyLabel)], [], [start; finish], [g.int32_ty], Text.Range.range0) - Some (mkAsmExpr ([], [], [breakToEmptyIfStartGtFinish; init; empty], [], Text.Range.range0)) + Some (mkAsmExpr ([], [], [breakToEmptyIfStartGtFinish; init; empty], [], m)) | SeqToList g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ListCollector_ty overallElemTy @@ -331,13 +331,13 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) - let init = mkAsmExpr ([I_ret], [], [mkCallArrayInit g m g.int32_ty range initializer], [], Text.Range.range0) + let init = mkAsmExpr ([I_ret], [], [mkCallArrayInit g Text.Range.range0 g.int32_ty range initializer], [], Text.Range.range0) let emptyLabel = generateCodeLabel () - let empty = mkLabelled Text.Range.range0 emptyLabel (mkArray (g.int32_ty, [], m)) + let empty = mkLabelled Text.Range.range0 emptyLabel (mkArray (g.int32_ty, [], Text.Range.range0)) let breakToEmptyIfStartGtFinish = mkAsmExpr ([I_brcmp (BI_bgt, emptyLabel)], [], [start; finish], [g.int32_ty], Text.Range.range0) - Some (mkAsmExpr ([], [], [breakToEmptyIfStartGtFinish; init; empty], [], Text.Range.range0)) + Some (mkAsmExpr ([], [], [breakToEmptyIfStartGtFinish; init; empty], [], m)) | SeqToArray g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ArrayCollector_ty overallElemTy From 0136a96c76f4c6b13043c719ad8b5fefde654317 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Thu, 25 Jan 2024 14:17:00 -0500 Subject: [PATCH 08/25] Properly handle branching --- src/Compiler/CodeGen/IlxGen.fs | 8 +++-- .../Optimize/LowerComputedCollections.fs | 27 ++++++++++------ .../Optimize/LowerComputedCollections.fsi | 7 +++- .../ComputedCollectionLoweringTests.fs | 32 +++++++------------ 4 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index e301813edae..9f4a8b0b9d7 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -2867,8 +2867,12 @@ and GenExprPreSteps (cenv: cenv) (cgbuf: CodeGenBuffer) eenv expr sequel = None match lowering with - | Some altExpr -> - GenExpr cenv cgbuf eenv altExpr sequel + | Some(LowerComputedCollectionExpressions.ComputedCollectionExprLowering.Expr initExpr) -> + GenExpr cenv cgbuf eenv initExpr sequel + true + | Some(LowerComputedCollectionExpressions.ComputedCollectionExprLowering.Either(branch1, branch2)) -> + GenExpr cenv cgbuf eenv branch1 (sequelIgnoreEndScopes sequel) + GenExpr cenv cgbuf eenv branch2 sequel true | None -> diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 9e62cf7f0f1..ed28282b768 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -269,6 +269,11 @@ let (|Int32Range|_|) g expr = | ValApp g g.range_int32_op_vref ([], [start; Expr.Const (value = Const.Int32 1); finish], _), _ -> ValueSome (start, finish) | _ -> ValueNone +[] +type ComputedCollectionExprLowering = + | Expr of initExpr: Expr + | Either of branch1: Expr * branch2: Expr + let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = // If ListCollector is in FSharp.Core then this optimization kicks in if g.ListCollector_tcr.CanDeref then @@ -280,7 +285,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = | SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when start > finish -> - Some (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m)) + Some (ComputedCollectionExprLowering.Expr (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m))) // [1..5] → [1; 2; 3; 4; 5] ≡ 1 :: 2 :: 3 :: 4 :: 5 :: [] | SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), _) when @@ -291,7 +296,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = if n < start then acc else conses (mkCons g g.int32_ty (Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)) acc) (n - 1) - Some (conses (mkNil g Text.Range.range0 g.int32_ty) finish) + Some (ComputedCollectionExprLowering.Expr (conses (mkNil g Text.Range.range0 g.int32_ty) finish)) // [start..finish] → if start <= finish then List.init (finish - start + 1) ((+) start) else [] | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> @@ -300,29 +305,30 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) - let init = mkAsmExpr ([I_ret], [], [mkCallListInit g Text.Range.range0 g.int32_ty range initializer], [], Text.Range.range0) + let init = mkCallListInit g Text.Range.range0 g.int32_ty range initializer let emptyLabel = generateCodeLabel () let empty = mkLabelled Text.Range.range0 emptyLabel (mkNil g Text.Range.range0 g.int32_ty) - let breakToEmptyIfStartGtFinish = mkAsmExpr ([I_brcmp (BI_bgt, emptyLabel)], [], [start; finish], [g.int32_ty], Text.Range.range0) + let breakToEmptyIfStartGtFinish = mkAsmExpr ([I_brcmp (BI_bgt, emptyLabel)], [], [start; finish], [mkListTy g g.int32_ty], Text.Range.range0) - Some (mkAsmExpr ([], [], [breakToEmptyIfStartGtFinish; init; empty], [], m)) + Some (ComputedCollectionExprLowering.Either (mkAsmExpr ([], [], [breakToEmptyIfStartGtFinish; init], [mkListTy g g.int32_ty], m), empty)) | SeqToList g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ListCollector_ty overallElemTy LowerComputedListOrArraySeqExpr tcVal g amap m collectorTy overallSeqExpr + |> Option.map ComputedCollectionExprLowering.Expr // [|5..1|] → [||] | SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when start > finish -> - Some (mkArray (g.int32_ty, [], m)) + Some (ComputedCollectionExprLowering.Expr (mkArray (g.int32_ty, [], m))) // [|1..5|] → [|1; 2; 3; 4; 5|] | SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when (finish - start) * sizeof < constArrayBytesThreshold -> - Some (mkArray (g.int32_ty, [for n in start..finish -> Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)], m)) + Some (ComputedCollectionExprLowering.Expr (mkArray (g.int32_ty, [for n in start..finish -> Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)], m))) // [|start..finish|] → if start <= finish then Array.init (finish - start + 1) ((+) start) else [||] | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> @@ -331,17 +337,18 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) - let init = mkAsmExpr ([I_ret], [], [mkCallArrayInit g Text.Range.range0 g.int32_ty range initializer], [], Text.Range.range0) + let init = mkCallArrayInit g Text.Range.range0 g.int32_ty range initializer let emptyLabel = generateCodeLabel () let empty = mkLabelled Text.Range.range0 emptyLabel (mkArray (g.int32_ty, [], Text.Range.range0)) - let breakToEmptyIfStartGtFinish = mkAsmExpr ([I_brcmp (BI_bgt, emptyLabel)], [], [start; finish], [g.int32_ty], Text.Range.range0) + let breakToEmptyIfStartGtFinish = mkAsmExpr ([I_brcmp (BI_bgt, emptyLabel)], [], [start; finish], [mkArrayType g g.int32_ty], Text.Range.range0) - Some (mkAsmExpr ([], [], [breakToEmptyIfStartGtFinish; init; empty], [], m)) + Some (ComputedCollectionExprLowering.Either (mkAsmExpr ([], [], [breakToEmptyIfStartGtFinish; init], [mkArrayType g g.int32_ty], m), empty)) | SeqToArray g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ArrayCollector_ty overallElemTy LowerComputedListOrArraySeqExpr tcVal g amap m collectorTy overallSeqExpr + |> Option.map ComputedCollectionExprLowering.Expr | _ -> None else diff --git a/src/Compiler/Optimize/LowerComputedCollections.fsi b/src/Compiler/Optimize/LowerComputedCollections.fsi index a1656361776..393e007a7df 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fsi +++ b/src/Compiler/Optimize/LowerComputedCollections.fsi @@ -6,5 +6,10 @@ open FSharp.Compiler.Import open FSharp.Compiler.TcGlobals open FSharp.Compiler.TypedTree +[] +type ComputedCollectionExprLowering = + | Expr of initExpr: Expr + | Either of branch1: Expr * branch2: Expr + val LowerComputedListOrArrayExpr: - tcVal: ConstraintSolver.TcValF -> g: TcGlobals -> amap: ImportMap -> Expr -> Expr option + tcVal: ConstraintSolver.TcValF -> g: TcGlobals -> amap: ImportMap -> Expr -> ComputedCollectionExprLowering option diff --git a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs index 78d8fdd09c3..aefc9151a1e 100644 --- a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs +++ b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs @@ -252,7 +252,7 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldc.i4.1 IL_0001: ldc.i4 0x101 - IL_0006: bgt.s IL_001d + IL_0006: bgt.s IL_001c IL_0008: ldc.i4 0x101 IL_000d: ldc.i4.1 @@ -264,10 +264,8 @@ module ComputedCollectionLoweringTests = class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) IL_001b: ret - IL_001c: ldnull - IL_001d: call !!0[] [runtime]System.Array::Empty() - IL_0022: ldnull - IL_0023: ret + IL_001c: call !!0[] [runtime]System.Array::Empty() + IL_0021: ret } } @@ -366,7 +364,7 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldarg.0 IL_0001: ldarg.1 - IL_0002: bgt.s IL_0016 + IL_0002: bgt.s IL_0015 IL_0004: ldarg.1 IL_0005: ldarg.0 @@ -379,10 +377,8 @@ module ComputedCollectionLoweringTests = class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) IL_0014: ret - IL_0015: ldnull - IL_0016: call !!0[] [runtime]System.Array::Empty() - IL_001b: ldnull - IL_001c: ret + IL_0015: call !!0[] [runtime]System.Array::Empty() + IL_001a: ret } } @@ -645,7 +641,7 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldc.i4.1 IL_0001: ldc.i4.s 101 - IL_0003: bgt.s IL_0017 + IL_0003: bgt.s IL_0016 IL_0005: ldc.i4.s 101 IL_0007: ldc.i4.1 @@ -657,10 +653,8 @@ module ComputedCollectionLoweringTests = class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) IL_0015: ret - IL_0016: ldnull - IL_0017: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_001c: ldnull - IL_001d: ret + IL_0016: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_001b: ret } } @@ -760,7 +754,7 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldarg.0 IL_0001: ldarg.1 - IL_0002: bgt.s IL_0016 + IL_0002: bgt.s IL_0015 IL_0004: ldarg.1 IL_0005: ldarg.0 @@ -773,10 +767,8 @@ module ComputedCollectionLoweringTests = class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) IL_0014: ret - IL_0015: ldnull - IL_0016: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_001b: ldnull - IL_001c: ret + IL_0015: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_001a: ret } } From 283ad75dd412ea73ba0e4739f53df08f2418b3c0 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 26 Jan 2024 09:59:50 -0500 Subject: [PATCH 09/25] Go branchless * Use branchless `max` in call to `Array.init`/`List.init`. Getting the sequel to be appended to each branch correctly in all cases looked like a nontrivial undertaking. * Lower the size thresholds for const ranges (temporarily?). --- src/Compiler/CodeGen/IlxGen.fs | 6 +- .../Optimize/LowerComputedCollections.fs | 47 +++-- .../Optimize/LowerComputedCollections.fsi | 7 +- .../ComputedCollectionLoweringTests.fs | 161 +++++++++++------- 4 files changed, 120 insertions(+), 101 deletions(-) diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index 9f4a8b0b9d7..1047dfa4433 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -2867,13 +2867,9 @@ and GenExprPreSteps (cenv: cenv) (cgbuf: CodeGenBuffer) eenv expr sequel = None match lowering with - | Some(LowerComputedCollectionExpressions.ComputedCollectionExprLowering.Expr initExpr) -> + | Some initExpr -> GenExpr cenv cgbuf eenv initExpr sequel true - | Some(LowerComputedCollectionExpressions.ComputedCollectionExprLowering.Either(branch1, branch2)) -> - GenExpr cenv cgbuf eenv branch1 (sequelIgnoreEndScopes sequel) - GenExpr cenv cgbuf eenv branch2 sequel - true | None -> let lowering = diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index ed28282b768..bb3d7b766a8 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -269,23 +269,18 @@ let (|Int32Range|_|) g expr = | ValApp g g.range_int32_op_vref ([], [start; Expr.Const (value = Const.Int32 1); finish], _), _ -> ValueSome (start, finish) | _ -> ValueNone -[] -type ComputedCollectionExprLowering = - | Expr of initExpr: Expr - | Either of branch1: Expr * branch2: Expr - let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = // If ListCollector is in FSharp.Core then this optimization kicks in if g.ListCollector_tcr.CanDeref then - let constListSizeThreshold = 100 - let constArrayBytesThreshold = 1024 + let constListSizeThreshold = 10 + let constArrayBytesThreshold = 40 match overallExpr with // [5..1] → [] | SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when start > finish -> - Some (ComputedCollectionExprLowering.Expr (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m))) + Some (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m)) // [1..5] → [1; 2; 3; 4; 5] ≡ 1 :: 2 :: 3 :: 4 :: 5 :: [] | SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), _) when @@ -296,59 +291,57 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = if n < start then acc else conses (mkCons g g.int32_ty (Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)) acc) (n - 1) - Some (ComputedCollectionExprLowering.Expr (conses (mkNil g Text.Range.range0 g.int32_ty) finish)) + Some (conses (mkNil g Text.Range.range0 g.int32_ty) finish) // [start..finish] → if start <= finish then List.init (finish - start + 1) ((+) start) else [] | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) let range = mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) + let zero = mkZero g Text.Range.range0 + let negRangeLtZero = mkAsmExpr ([AI_neg], [], [mkAsmExpr ([AI_clt], [], [range; zero], [g.int32_ty], Text.Range.range0)], [g.int32_ty], Text.Range.range0) + let anded = mkAsmExpr ([AI_and], [], [range; negRangeLtZero], [g.int32_ty], Text.Range.range0) + // range ^ (range & -(range < 0)) + // https://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax + let range = mkAsmExpr ([AI_xor], [], [range; anded], [g.int32_ty], Text.Range.range0) let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) - let init = mkCallListInit g Text.Range.range0 g.int32_ty range initializer - - let emptyLabel = generateCodeLabel () - let empty = mkLabelled Text.Range.range0 emptyLabel (mkNil g Text.Range.range0 g.int32_ty) - let breakToEmptyIfStartGtFinish = mkAsmExpr ([I_brcmp (BI_bgt, emptyLabel)], [], [start; finish], [mkListTy g g.int32_ty], Text.Range.range0) - - Some (ComputedCollectionExprLowering.Either (mkAsmExpr ([], [], [breakToEmptyIfStartGtFinish; init], [mkListTy g g.int32_ty], m), empty)) + Some (mkCallListInit g m g.int32_ty range initializer) | SeqToList g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ListCollector_ty overallElemTy LowerComputedListOrArraySeqExpr tcVal g amap m collectorTy overallSeqExpr - |> Option.map ComputedCollectionExprLowering.Expr // [|5..1|] → [||] | SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when start > finish -> - Some (ComputedCollectionExprLowering.Expr (mkArray (g.int32_ty, [], m))) + Some (mkArray (g.int32_ty, [], m)) // [|1..5|] → [|1; 2; 3; 4; 5|] | SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when (finish - start) * sizeof < constArrayBytesThreshold -> - Some (ComputedCollectionExprLowering.Expr (mkArray (g.int32_ty, [for n in start..finish -> Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)], m))) + Some (mkArray (g.int32_ty, [for n in start..finish -> Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)], m)) // [|start..finish|] → if start <= finish then Array.init (finish - start + 1) ((+) start) else [||] | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) let range = mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) + let zero = mkZero g Text.Range.range0 + let negRangeLtZero = mkAsmExpr ([AI_neg], [], [mkAsmExpr ([AI_clt], [], [range; zero], [g.int32_ty], Text.Range.range0)], [g.int32_ty], Text.Range.range0) + let anded = mkAsmExpr ([AI_and], [], [range; negRangeLtZero], [g.int32_ty], Text.Range.range0) + // range ^ (range & -(range < 0)) + // https://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax + let range = mkAsmExpr ([AI_xor], [], [range; anded], [g.int32_ty], Text.Range.range0) let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) - let init = mkCallArrayInit g Text.Range.range0 g.int32_ty range initializer - - let emptyLabel = generateCodeLabel () - let empty = mkLabelled Text.Range.range0 emptyLabel (mkArray (g.int32_ty, [], Text.Range.range0)) - let breakToEmptyIfStartGtFinish = mkAsmExpr ([I_brcmp (BI_bgt, emptyLabel)], [], [start; finish], [mkArrayType g g.int32_ty], Text.Range.range0) - - Some (ComputedCollectionExprLowering.Either (mkAsmExpr ([], [], [breakToEmptyIfStartGtFinish; init], [mkArrayType g g.int32_ty], m), empty)) + Some (mkCallArrayInit g m g.int32_ty range initializer) | SeqToArray g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ArrayCollector_ty overallElemTy LowerComputedListOrArraySeqExpr tcVal g amap m collectorTy overallSeqExpr - |> Option.map ComputedCollectionExprLowering.Expr | _ -> None else diff --git a/src/Compiler/Optimize/LowerComputedCollections.fsi b/src/Compiler/Optimize/LowerComputedCollections.fsi index 393e007a7df..a1656361776 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fsi +++ b/src/Compiler/Optimize/LowerComputedCollections.fsi @@ -6,10 +6,5 @@ open FSharp.Compiler.Import open FSharp.Compiler.TcGlobals open FSharp.Compiler.TypedTree -[] -type ComputedCollectionExprLowering = - | Expr of initExpr: Expr - | Either of branch1: Expr * branch2: Expr - val LowerComputedListOrArrayExpr: - tcVal: ConstraintSolver.TcValF -> g: TcGlobals -> amap: ImportMap -> Expr -> ComputedCollectionExprLowering option + tcVal: ConstraintSolver.TcValF -> g: TcGlobals -> amap: ImportMap -> Expr -> Expr option diff --git a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs index aefc9151a1e..b56803f1be7 100644 --- a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs +++ b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs @@ -250,22 +250,31 @@ module ComputedCollectionLoweringTests = { .maxstack 8 - IL_0000: ldc.i4.1 - IL_0001: ldc.i4 0x101 - IL_0006: bgt.s IL_001c - - IL_0008: ldc.i4 0x101 - IL_000d: ldc.i4.1 - IL_000e: sub - IL_000f: ldc.i4.1 - IL_0010: add - IL_0011: ldsfld class Test/test@1 Test/test@1::@_instance - IL_0016: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0000: ldc.i4 0x101 + IL_0005: ldc.i4.1 + IL_0006: sub + IL_0007: ldc.i4.1 + IL_0008: add + IL_0009: ldc.i4 0x101 + IL_000e: ldc.i4.1 + IL_000f: sub + IL_0010: ldc.i4.1 + IL_0011: add + IL_0012: ldc.i4 0x101 + IL_0017: ldc.i4.1 + IL_0018: sub + IL_0019: ldc.i4.1 + IL_001a: add + IL_001b: ldc.i4.0 + IL_001c: clt + IL_001e: neg + IL_001f: and + IL_0020: xor + IL_0021: ldsfld class Test/test@1 Test/test@1::@_instance + IL_0026: tail. + IL_0028: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_001b: ret - - IL_001c: call !!0[] [runtime]System.Array::Empty() - IL_0021: ret + IL_002d: ret } } @@ -362,23 +371,32 @@ module ComputedCollectionLoweringTests = .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: ldarg.1 - IL_0002: bgt.s IL_0015 - - IL_0004: ldarg.1 - IL_0005: ldarg.0 - IL_0006: sub - IL_0007: ldc.i4.1 - IL_0008: add - IL_0009: ldarg.0 - IL_000a: newobj instance void Test/test@1::.ctor(int32) - IL_000f: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0000: ldarg.1 + IL_0001: ldarg.0 + IL_0002: sub + IL_0003: ldc.i4.1 + IL_0004: add + IL_0005: ldarg.1 + IL_0006: ldarg.0 + IL_0007: sub + IL_0008: ldc.i4.1 + IL_0009: add + IL_000a: ldarg.1 + IL_000b: ldarg.0 + IL_000c: sub + IL_000d: ldc.i4.1 + IL_000e: add + IL_000f: ldc.i4.0 + IL_0010: clt + IL_0012: neg + IL_0013: and + IL_0014: xor + IL_0015: ldarg.0 + IL_0016: newobj instance void Test/test@1::.ctor(int32) + IL_001b: tail. + IL_001d: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0014: ret - - IL_0015: call !!0[] [runtime]System.Array::Empty() - IL_001a: ret + IL_0022: ret } } @@ -639,22 +657,31 @@ module ComputedCollectionLoweringTests = { .maxstack 8 - IL_0000: ldc.i4.1 - IL_0001: ldc.i4.s 101 - IL_0003: bgt.s IL_0016 - - IL_0005: ldc.i4.s 101 - IL_0007: ldc.i4.1 - IL_0008: sub - IL_0009: ldc.i4.1 - IL_000a: add - IL_000b: ldsfld class Test/test@1 Test/test@1::@_instance - IL_0010: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_0000: ldc.i4.s 101 + IL_0002: ldc.i4.1 + IL_0003: sub + IL_0004: ldc.i4.1 + IL_0005: add + IL_0006: ldc.i4.s 101 + IL_0008: ldc.i4.1 + IL_0009: sub + IL_000a: ldc.i4.1 + IL_000b: add + IL_000c: ldc.i4.s 101 + IL_000e: ldc.i4.1 + IL_000f: sub + IL_0010: ldc.i4.1 + IL_0011: add + IL_0012: ldc.i4.0 + IL_0013: clt + IL_0015: neg + IL_0016: and + IL_0017: xor + IL_0018: ldsfld class Test/test@1 Test/test@1::@_instance + IL_001d: tail. + IL_001f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0015: ret - - IL_0016: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_001b: ret + IL_0024: ret } } @@ -752,23 +779,32 @@ module ComputedCollectionLoweringTests = .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: ldarg.1 - IL_0002: bgt.s IL_0015 - - IL_0004: ldarg.1 - IL_0005: ldarg.0 - IL_0006: sub - IL_0007: ldc.i4.1 - IL_0008: add - IL_0009: ldarg.0 - IL_000a: newobj instance void Test/test@1::.ctor(int32) - IL_000f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_0000: ldarg.1 + IL_0001: ldarg.0 + IL_0002: sub + IL_0003: ldc.i4.1 + IL_0004: add + IL_0005: ldarg.1 + IL_0006: ldarg.0 + IL_0007: sub + IL_0008: ldc.i4.1 + IL_0009: add + IL_000a: ldarg.1 + IL_000b: ldarg.0 + IL_000c: sub + IL_000d: ldc.i4.1 + IL_000e: add + IL_000f: ldc.i4.0 + IL_0010: clt + IL_0012: neg + IL_0013: and + IL_0014: xor + IL_0015: ldarg.0 + IL_0016: newobj instance void Test/test@1::.ctor(int32) + IL_001b: tail. + IL_001d: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0014: ret - - IL_0015: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_001a: ret + IL_0022: ret } } @@ -779,4 +815,3 @@ module ComputedCollectionLoweringTests = } """ ])) - From a972f2c54ecfe4c2216afa330474dd9d47a4fa83 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 26 Jan 2024 10:27:56 -0500 Subject: [PATCH 10/25] Update release notes --- docs/release-notes/.FSharp.Compiler.Service/8.0.300.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md index 35128d40ad0..8fb65067702 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.300.md @@ -19,3 +19,4 @@ * Reduce allocations in compiler checking via `ValueOption` usage ([PR #16323](https://github.com/dotnet/fsharp/pull/16323), [PR #16567](https://github.com/dotnet/fsharp/pull/16567)) * Reverted [#16348](https://github.com/dotnet/fsharp/pull/16348) `ThreadStatic` `CancellationToken` changes to improve test stability and prevent potential unwanted cancellations. ([PR #16536](https://github.com/dotnet/fsharp/pull/16536)) * Refactored parenthesization API. ([PR #16461])(https://github.com/dotnet/fsharp/pull/16461)) +* Improved lowering of `[start..finish]` and `[|start..finish|]`. ([PR #16577](https://github.com/dotnet/fsharp/pull/16577)) From 5d2e907db1d476d4aa8047b5ac074724c401188f Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 26 Jan 2024 10:35:32 -0500 Subject: [PATCH 11/25] Will it be green? --- .../Optimize/LowerComputedCollections.fs | 32 +-- .../ComputedCollectionLoweringTests.fs | 195 ++++++++++++------ 2 files changed, 147 insertions(+), 80 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index bb3d7b766a8..bf854f162b5 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -272,8 +272,8 @@ let (|Int32Range|_|) g expr = let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = // If ListCollector is in FSharp.Core then this optimization kicks in if g.ListCollector_tcr.CanDeref then - let constListSizeThreshold = 10 - let constArrayBytesThreshold = 40 + //let constListSizeThreshold = 10 + //let constArrayBytesThreshold = 40 match overallExpr with // [5..1] → [] @@ -282,16 +282,16 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = -> Some (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m)) - // [1..5] → [1; 2; 3; 4; 5] ≡ 1 :: 2 :: 3 :: 4 :: 5 :: [] - | SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), _) when - finish - start < constListSizeThreshold - -> - // … :: … :: … - let rec conses acc n = - if n < start then acc - else conses (mkCons g g.int32_ty (Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)) acc) (n - 1) + //// [1..5] → [1; 2; 3; 4; 5] ≡ 1 :: 2 :: 3 :: 4 :: 5 :: [] + //| SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), _) when + // finish - start < constListSizeThreshold + // -> + // // … :: … :: … + // let rec conses acc n = + // if n < start then acc + // else conses (mkCons g g.int32_ty (Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)) acc) (n - 1) - Some (conses (mkNil g Text.Range.range0 g.int32_ty) finish) + // Some (conses (mkNil g Text.Range.range0 g.int32_ty) finish) // [start..finish] → if start <= finish then List.init (finish - start + 1) ((+) start) else [] | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> @@ -318,11 +318,11 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = -> Some (mkArray (g.int32_ty, [], m)) - // [|1..5|] → [|1; 2; 3; 4; 5|] - | SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when - (finish - start) * sizeof < constArrayBytesThreshold - -> - Some (mkArray (g.int32_ty, [for n in start..finish -> Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)], m)) + //// [|1..5|] → [|1; 2; 3; 4; 5|] + //| SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when + // (finish - start) * sizeof < constArrayBytesThreshold + // -> + // Some (mkArray (g.int32_ty, [for n in start..finish -> Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)], m)) // [|start..finish|] → if start <= finish then Array.init (finish - start + 1) ((+) start) else [||] | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> diff --git a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs index b56803f1be7..57b808f4ea2 100644 --- a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs +++ b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs @@ -72,7 +72,7 @@ module ComputedCollectionLoweringTests = ])) [] - let ``Lone RangeInt32 with const args ≤ 1024 bytes lowers to blob`` () = + let ``Lone RangeInt32 with const args ≤ 1024 bytes lowers to call to init`` () = CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], """ module Test @@ -117,19 +117,74 @@ module ComputedCollectionLoweringTests = 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 valuetype ''/T3169_40Bytes@ field3170@ at I_000028A7 - .custom instance void [runtime]System.Diagnostics.DebuggerBrowsableAttribute::.ctor(valuetype [runtime]System.Diagnostics.DebuggerBrowsableState) = ( 01 00 00 00 00 00 00 00 ) + .class auto ansi serializable sealed nested assembly beforefieldinit test@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class Test/test@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Test/test@1::.ctor() + IL_0005: stsfld class Test/test@1 Test/test@1::@_instance + IL_000a: ret + } + + } + .method public static int32[] test() cil managed { .maxstack 8 IL_0000: ldc.i4.s 10 - IL_0002: newarr [runtime]System.Int32 - IL_0007: dup - IL_0008: ldtoken field valuetype ''/T3169_40Bytes@ Test::field3170@ - IL_000d: call void [runtime]System.Runtime.CompilerServices.RuntimeHelpers::InitializeArray(class [runtime]System.Array, - valuetype [runtime]System.RuntimeFieldHandle) - IL_0012: ret + IL_0002: ldc.i4.1 + IL_0003: sub + IL_0004: ldc.i4.1 + IL_0005: add + IL_0006: ldc.i4.s 10 + IL_0008: ldc.i4.1 + IL_0009: sub + IL_000a: ldc.i4.1 + IL_000b: add + IL_000c: ldc.i4.s 10 + IL_000e: ldc.i4.1 + IL_000f: sub + IL_0010: ldc.i4.1 + IL_0011: add + IL_0012: ldc.i4.0 + IL_0013: clt + IL_0015: neg + IL_0016: and + IL_0017: xor + IL_0018: ldsfld class Test/test@1 Test/test@1::@_instance + IL_001d: tail. + IL_001f: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0024: ret } } @@ -137,27 +192,7 @@ module ComputedCollectionLoweringTests = .class private abstract auto ansi sealed ''.$Test extends [runtime]System.Object { - } - - .class private abstract auto ansi sealed beforefieldinit '' - extends [runtime]System.Object - { - .class explicit ansi sealed nested assembly beforefieldinit T3169_40Bytes@ - extends [runtime]System.ValueType - { - .pack 0 - .size 40 - } - - } - - - - - .data cil I_000028A7 = bytearray ( - 01 00 00 00 02 00 00 00 03 00 00 00 04 00 00 00 - 05 00 00 00 06 00 00 00 07 00 00 00 08 00 00 00 - 09 00 00 00 0A 00 00 00) + } """ ])) @@ -474,7 +509,7 @@ module ComputedCollectionLoweringTests = ])) [] - let ``Lone small RangeInt32 with const args ≤ 100 lowers to conses`` () = + let ``Lone small RangeInt32 with const args ≤ 100 lowers to call to init`` () = CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], """ module Test @@ -519,43 +554,75 @@ module ComputedCollectionLoweringTests = 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 test@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class Test/test@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Test/test@1::.ctor() + IL_0005: stsfld class Test/test@1 Test/test@1::@_instance + IL_000a: ret + } + + } + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 test() cil managed { - .maxstack 13 - IL_0000: ldc.i4.1 - IL_0001: ldc.i4.2 - IL_0002: ldc.i4.3 - IL_0003: ldc.i4.4 - IL_0004: ldc.i4.5 - IL_0005: ldc.i4.6 - IL_0006: ldc.i4.7 - IL_0007: ldc.i4.8 - IL_0008: ldc.i4.s 9 - IL_000a: ldc.i4.s 10 - IL_000c: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_0011: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0016: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_001b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0020: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0025: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_002a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_002f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0034: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0039: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_003e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0043: ret + .maxstack 8 + IL_0000: ldc.i4.s 10 + IL_0002: ldc.i4.1 + IL_0003: sub + IL_0004: ldc.i4.1 + IL_0005: add + IL_0006: ldc.i4.s 10 + IL_0008: ldc.i4.1 + IL_0009: sub + IL_000a: ldc.i4.1 + IL_000b: add + IL_000c: ldc.i4.s 10 + IL_000e: ldc.i4.1 + IL_000f: sub + IL_0010: ldc.i4.1 + IL_0011: add + IL_0012: ldc.i4.0 + IL_0013: clt + IL_0015: neg + IL_0016: and + IL_0017: xor + IL_0018: ldsfld class Test/test@1 Test/test@1::@_instance + IL_001d: tail. + IL_001f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0024: ret } } From f21305a1c5517d48d9bcc0518432918488096fd7 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 26 Jan 2024 13:45:26 -0500 Subject: [PATCH 12/25] Remove optimizations for const ranges --- .../Optimize/LowerComputedCollections.fs | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index bf854f162b5..70573f35f16 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -272,9 +272,6 @@ let (|Int32Range|_|) g expr = let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = // If ListCollector is in FSharp.Core then this optimization kicks in if g.ListCollector_tcr.CanDeref then - //let constListSizeThreshold = 10 - //let constArrayBytesThreshold = 40 - match overallExpr with // [5..1] → [] | SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when @@ -282,18 +279,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = -> Some (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m)) - //// [1..5] → [1; 2; 3; 4; 5] ≡ 1 :: 2 :: 3 :: 4 :: 5 :: [] - //| SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), _) when - // finish - start < constListSizeThreshold - // -> - // // … :: … :: … - // let rec conses acc n = - // if n < start then acc - // else conses (mkCons g g.int32_ty (Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)) acc) (n - 1) - - // Some (conses (mkNil g Text.Range.range0 g.int32_ty) finish) - - // [start..finish] → if start <= finish then List.init (finish - start + 1) ((+) start) else [] + // [start..finish] → let range = finish - start + 1 in List.init (max range 0) ((+) start) | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) let range = mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) @@ -318,13 +304,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = -> Some (mkArray (g.int32_ty, [], m)) - //// [|1..5|] → [|1; 2; 3; 4; 5|] - //| SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when - // (finish - start) * sizeof < constArrayBytesThreshold - // -> - // Some (mkArray (g.int32_ty, [for n in start..finish -> Expr.Const (Const.Int32 n, Text.Range.range0, g.int32_ty)], m)) - - // [|start..finish|] → if start <= finish then Array.init (finish - start + 1) ((+) start) else [||] + // [|start..finish|] → let range = finish - start + 1 in Array.init (max range 0) ((+) start) | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) let range = mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) From 49e738cbd15ebcfd44e9cd5844194612a304e0f2 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 26 Jan 2024 13:53:12 -0500 Subject: [PATCH 13/25] Update comments --- src/Compiler/Optimize/LowerComputedCollections.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 70573f35f16..2b9f25f69c5 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -279,7 +279,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = -> Some (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m)) - // [start..finish] → let range = finish - start + 1 in List.init (max range 0) ((+) start) + // [start..finish] → List.init (max (finish - start + 1) 0) ((+) start) | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) let range = mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) @@ -304,7 +304,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = -> Some (mkArray (g.int32_ty, [], m)) - // [|start..finish|] → let range = finish - start + 1 in Array.init (max range 0) ((+) start) + // [|start..finish|] → Array.init (max (finish - start + 1) 0) ((+) start) | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) let range = mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) From 38ccefe5b5862ef7e09cd2a40f49d51288b49521 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 26 Jan 2024 17:16:06 -0500 Subject: [PATCH 14/25] Revert that --- src/Compiler/CodeGen/IlxGen.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index 1047dfa4433..e301813edae 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -2867,8 +2867,8 @@ and GenExprPreSteps (cenv: cenv) (cgbuf: CodeGenBuffer) eenv expr sequel = None match lowering with - | Some initExpr -> - GenExpr cenv cgbuf eenv initExpr sequel + | Some altExpr -> + GenExpr cenv cgbuf eenv altExpr sequel true | None -> From 3a6758979e86aa99f3cc4b9267d745f1c94ee41f Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Fri, 26 Jan 2024 17:16:35 -0500 Subject: [PATCH 15/25] Closer --- .../Optimize/LowerComputedCollections.fs | 40 +- .../ComputationExpr07.fs.il.bsl | 120 +++-- .../GenericComparison/Compare09.fsx.il.bsl | 190 ++++++-- .../GenericComparison/Equals08.fsx.il.bsl | 190 ++++++-- .../GenericComparison/Hash11.fsx.il.bsl | 116 ++++- .../ListExpressionStepping02.fs.il.bsl | 275 ++++++++--- .../Misc/CodeGenRenamings01.fs.il.bsl | 455 ++++++++++-------- .../EmittedIL/Misc/ForLoop01.fs.il.bsl | 115 +++-- .../ComputedCollectionLoweringTests.fs | 200 +++----- 9 files changed, 1127 insertions(+), 574 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 2b9f25f69c5..2f8eed54c33 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -279,20 +279,24 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = -> Some (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m)) - // [start..finish] → List.init (max (finish - start + 1) 0) ((+) start) + // [start..finish] → if finish < start then [] else List.init (finish - start + 1) ((+) start) | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) let range = mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) - let zero = mkZero g Text.Range.range0 - let negRangeLtZero = mkAsmExpr ([AI_neg], [], [mkAsmExpr ([AI_clt], [], [range; zero], [g.int32_ty], Text.Range.range0)], [g.int32_ty], Text.Range.range0) - let anded = mkAsmExpr ([AI_and], [], [range; negRangeLtZero], [g.int32_ty], Text.Range.range0) - // range ^ (range & -(range < 0)) - // https://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax - let range = mkAsmExpr ([AI_xor], [], [range; anded], [g.int32_ty], Text.Range.range0) let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) - Some (mkCallListInit g m g.int32_ty range initializer) + + let expr = + mkCond + DebugPointAtBinding.NoneAtInvisible + m + (mkListTy g g.int32_ty) + (mkILAsmClt g Text.Range.range0 finish start) + (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], Text.Range.range0)) + (mkCallListInit g Text.Range.range0 g.int32_ty range initializer) + + Some expr | SeqToList g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ListCollector_ty overallElemTy @@ -304,20 +308,24 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = -> Some (mkArray (g.int32_ty, [], m)) - // [|start..finish|] → Array.init (max (finish - start + 1) 0) ((+) start) + // [|start..finish|] → if finish < start then [||] else Array.init (finish - start + 1) ((+) start) | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) let range = mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) - let zero = mkZero g Text.Range.range0 - let negRangeLtZero = mkAsmExpr ([AI_neg], [], [mkAsmExpr ([AI_clt], [], [range; zero], [g.int32_ty], Text.Range.range0)], [g.int32_ty], Text.Range.range0) - let anded = mkAsmExpr ([AI_and], [], [range; negRangeLtZero], [g.int32_ty], Text.Range.range0) - // range ^ (range & -(range < 0)) - // https://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax - let range = mkAsmExpr ([AI_xor], [], [range; anded], [g.int32_ty], Text.Range.range0) let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) - Some (mkCallArrayInit g m g.int32_ty range initializer) + + let expr = + mkCond + DebugPointAtBinding.NoneAtInvisible + m + (mkArrayType g g.int32_ty) + (mkILAsmClt g Text.Range.range0 finish start) + (mkArray (g.int32_ty, [], Text.Range.range0)) + (mkCallArrayInit g Text.Range.range0 g.int32_ty range initializer) + + Some expr | SeqToArray g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ArrayCollector_ty overallElemTy diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpr07.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpr07.fs.il.bsl index 6b0f84999c2..ab79b7b9b37 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpr07.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpr07.fs.il.bsl @@ -47,7 +47,46 @@ 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 'res7@10-1' + .class auto ansi serializable sealed nested assembly beforefieldinit 'res7@1-1' + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class Program/'res7@1-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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void Program/'res7@1-1'::.ctor() + IL_0005: stsfld class Program/'res7@1-1' Program/'res7@1-1'::@_instance + IL_000a: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit 'res7@10-2' extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> { .field public class [ComputationExprLibrary]Library.EventuallyBuilder builder@ @@ -67,10 +106,10 @@ 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 [ComputationExprLibrary]Library.EventuallyBuilder Program/'res7@10-1'::builder@ + IL_0008: stfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/'res7@10-2'::builder@ IL_000d: ldarg.0 IL_000e: ldarg.2 - IL_000f: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Program/'res7@10-1'::x + IL_000f: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Program/'res7@10-2'::x IL_0014: ret } @@ -83,15 +122,15 @@ IL_0000: ldarg.1 IL_0001: stloc.0 IL_0002: ldarg.0 - IL_0003: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Program/'res7@10-1'::x + IL_0003: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Program/'res7@10-2'::x IL_0008: ldarg.0 - IL_0009: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Program/'res7@10-1'::x + IL_0009: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Program/'res7@10-2'::x IL_000e: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::get_contents() IL_0013: ldloc.0 IL_0014: sub IL_0015: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::set_contents(!0) IL_001a: ldarg.0 - IL_001b: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/'res7@10-1'::builder@ + IL_001b: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/'res7@10-2'::builder@ IL_0020: tail. IL_0022: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Zero() IL_0027: ret @@ -99,7 +138,7 @@ } - .class auto ansi serializable sealed nested assembly beforefieldinit 'res7@12-2' + .class auto ansi serializable sealed nested assembly beforefieldinit 'res7@12-3' extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> { .field public class [ComputationExprLibrary]Library.EventuallyBuilder builder@ @@ -119,10 +158,10 @@ 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 [ComputationExprLibrary]Library.EventuallyBuilder Program/'res7@12-2'::builder@ + IL_0008: stfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/'res7@12-3'::builder@ IL_000d: ldarg.0 IL_000e: ldarg.2 - IL_000f: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Program/'res7@12-2'::x + IL_000f: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Program/'res7@12-3'::x IL_0014: ret } @@ -132,9 +171,9 @@ .maxstack 8 IL_0000: ldarg.0 - IL_0001: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/'res7@12-2'::builder@ + IL_0001: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/'res7@12-3'::builder@ IL_0006: ldarg.0 - IL_0007: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Program/'res7@12-2'::x + IL_0007: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 Program/'res7@12-3'::x IL_000c: call instance !0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::get_contents() IL_0011: tail. IL_0013: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Return(!!0) @@ -178,33 +217,42 @@ IL_0008: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ IL_000d: ldarg.0 IL_000e: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ - IL_0013: ldc.i4.0 - IL_0014: ldc.i4.1 - IL_0015: ldc.i4.3 - IL_0016: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_001b: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0020: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToList(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0025: ldarg.0 - IL_0026: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ - IL_002b: ldloc.0 - IL_002c: newobj instance void Program/'res7@10-1'::.ctor(class [ComputationExprLibrary]Library.EventuallyBuilder, + IL_0013: ldc.i4.3 + IL_0014: ldc.i4.0 + IL_0015: bge.s IL_001f + + IL_0017: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_001c: nop + IL_001d: br.s IL_002f + + IL_001f: ldc.i4.3 + IL_0020: ldc.i4.0 + IL_0021: sub + IL_0022: ldc.i4.1 + IL_0023: add + IL_0024: ldsfld class Program/'res7@1-1' Program/'res7@1-1'::@_instance + IL_0029: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_002e: nop + IL_002f: ldarg.0 + IL_0030: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ + IL_0035: ldloc.0 + IL_0036: newobj instance void Program/'res7@10-2'::.ctor(class [ComputationExprLibrary]Library.EventuallyBuilder, class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1) - IL_0031: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::For(class [runtime]System.Collections.Generic.IEnumerable`1, + IL_003b: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::For(class [runtime]System.Collections.Generic.IEnumerable`1, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) - IL_0036: ldarg.0 - IL_0037: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ - IL_003c: ldarg.0 - IL_003d: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ - IL_0042: ldloc.0 - IL_0043: newobj instance void Program/'res7@12-2'::.ctor(class [ComputationExprLibrary]Library.EventuallyBuilder, + IL_0040: ldarg.0 + IL_0041: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ + IL_0046: ldarg.0 + IL_0047: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ + IL_004c: ldloc.0 + IL_004d: newobj instance void Program/'res7@12-3'::.ctor(class [ComputationExprLibrary]Library.EventuallyBuilder, class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1) - IL_0048: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Delay(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) - IL_004d: tail. - IL_004f: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Combine(class [ComputationExprLibrary]Library.Eventually`1, + IL_0052: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Delay(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0057: tail. + IL_0059: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Combine(class [ComputationExprLibrary]Library.Eventually`1, class [ComputationExprLibrary]Library.Eventually`1) - IL_0054: ret + IL_005e: ret } } @@ -271,3 +319,7 @@ + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl index b734a546b40..5967e6f0bd2 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl @@ -47,53 +47,151 @@ 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 t1@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class assembly/CompareMicroPerfAndCodeGenerationTests/t1@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void assembly/CompareMicroPerfAndCodeGenerationTests/t1@1::.ctor() + IL_0005: stsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t1@1 assembly/CompareMicroPerfAndCodeGenerationTests/t1@1::@_instance + IL_000a: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit t2@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class assembly/CompareMicroPerfAndCodeGenerationTests/t2@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void assembly/CompareMicroPerfAndCodeGenerationTests/t2@1::.ctor() + IL_0005: stsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t2@1 assembly/CompareMicroPerfAndCodeGenerationTests/t2@1::@_instance + IL_000a: ret + } + + } + .method public static int32 f8() cil managed { - .maxstack 5 + .maxstack 4 .locals init (int32 V_0, int32[] V_1, int32[] V_2, int32 V_3) IL_0000: ldc.i4.1 IL_0001: stloc.0 - IL_0002: ldc.i4.0 - IL_0003: ldc.i4.1 - IL_0004: ldc.i4.s 100 - IL_0006: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_000b: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0010: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToArray(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0015: stloc.1 - IL_0016: ldc.i4.0 - IL_0017: ldc.i4.1 - IL_0018: ldc.i4.s 100 - IL_001a: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_001f: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0024: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToArray(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0029: stloc.2 - IL_002a: ldc.i4.0 - IL_002b: stloc.3 - IL_002c: br.s IL_003a - - IL_002e: ldloc.1 - IL_002f: ldloc.2 - IL_0030: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonIntrinsic(!!0, + IL_0002: nop + IL_0003: ldc.i4.s 100 + IL_0005: ldc.i4.0 + IL_0006: bge.s IL_0010 + + IL_0008: call !!0[] [runtime]System.Array::Empty() + IL_000d: nop + IL_000e: br.s IL_0021 + + IL_0010: ldc.i4.s 100 + IL_0012: ldc.i4.0 + IL_0013: sub + IL_0014: ldc.i4.1 + IL_0015: add + IL_0016: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t1@1 assembly/CompareMicroPerfAndCodeGenerationTests/t1@1::@_instance + IL_001b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0020: nop + IL_0021: stloc.1 + IL_0022: nop + IL_0023: ldc.i4.s 100 + IL_0025: ldc.i4.0 + IL_0026: bge.s IL_0030 + + IL_0028: call !!0[] [runtime]System.Array::Empty() + IL_002d: nop + IL_002e: br.s IL_0041 + + IL_0030: ldc.i4.s 100 + IL_0032: ldc.i4.0 + IL_0033: sub + IL_0034: ldc.i4.1 + IL_0035: add + IL_0036: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t2@1 assembly/CompareMicroPerfAndCodeGenerationTests/t2@1::@_instance + IL_003b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0040: nop + IL_0041: stloc.2 + IL_0042: ldc.i4.0 + IL_0043: stloc.3 + IL_0044: br.s IL_0052 + + IL_0046: ldloc.1 + IL_0047: ldloc.2 + IL_0048: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonIntrinsic(!!0, !!0) - IL_0035: stloc.0 - IL_0036: ldloc.3 - IL_0037: ldc.i4.1 - IL_0038: add - IL_0039: stloc.3 - IL_003a: ldloc.3 - IL_003b: ldc.i4 0x186a1 - IL_0040: blt.s IL_002e - - IL_0042: ldloc.0 - IL_0043: ret + IL_004d: stloc.0 + IL_004e: ldloc.3 + IL_004f: ldc.i4.1 + IL_0050: add + IL_0051: stloc.3 + IL_0052: ldloc.3 + IL_0053: ldc.i4 0x186a1 + IL_0058: blt.s IL_0046 + + IL_005a: ldloc.0 + IL_005b: ret } } @@ -118,3 +216,21 @@ +sx + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl index 6125092813b..e2c42a7030c 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl @@ -47,53 +47,151 @@ 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 t1@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class assembly/EqualsMicroPerfAndCodeGenerationTests/t1@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1::.ctor() + IL_0005: stsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1::@_instance + IL_000a: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit t2@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class assembly/EqualsMicroPerfAndCodeGenerationTests/t2@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1::.ctor() + IL_0005: stsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1::@_instance + IL_000a: ret + } + + } + .method public static bool f8() cil managed { - .maxstack 5 + .maxstack 4 .locals init (bool V_0, int32[] V_1, int32[] V_2, int32 V_3) IL_0000: ldc.i4.0 IL_0001: stloc.0 - IL_0002: ldc.i4.0 - IL_0003: ldc.i4.1 - IL_0004: ldc.i4.s 100 - IL_0006: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_000b: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0010: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToArray(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0015: stloc.1 - IL_0016: ldc.i4.0 - IL_0017: ldc.i4.1 - IL_0018: ldc.i4.s 100 - IL_001a: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_001f: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0024: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToArray(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0029: stloc.2 - IL_002a: ldc.i4.0 - IL_002b: stloc.3 - IL_002c: br.s IL_003a - - IL_002e: ldloc.1 - IL_002f: ldloc.2 - IL_0030: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityIntrinsic(!!0, + IL_0002: nop + IL_0003: ldc.i4.s 100 + IL_0005: ldc.i4.0 + IL_0006: bge.s IL_0010 + + IL_0008: call !!0[] [runtime]System.Array::Empty() + IL_000d: nop + IL_000e: br.s IL_0021 + + IL_0010: ldc.i4.s 100 + IL_0012: ldc.i4.0 + IL_0013: sub + IL_0014: ldc.i4.1 + IL_0015: add + IL_0016: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1::@_instance + IL_001b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0020: nop + IL_0021: stloc.1 + IL_0022: nop + IL_0023: ldc.i4.s 100 + IL_0025: ldc.i4.0 + IL_0026: bge.s IL_0030 + + IL_0028: call !!0[] [runtime]System.Array::Empty() + IL_002d: nop + IL_002e: br.s IL_0041 + + IL_0030: ldc.i4.s 100 + IL_0032: ldc.i4.0 + IL_0033: sub + IL_0034: ldc.i4.1 + IL_0035: add + IL_0036: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1::@_instance + IL_003b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0040: nop + IL_0041: stloc.2 + IL_0042: ldc.i4.0 + IL_0043: stloc.3 + IL_0044: br.s IL_0052 + + IL_0046: ldloc.1 + IL_0047: ldloc.2 + IL_0048: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityIntrinsic(!!0, !!0) - IL_0035: stloc.0 - IL_0036: ldloc.3 - IL_0037: ldc.i4.1 - IL_0038: add - IL_0039: stloc.3 - IL_003a: ldloc.3 - IL_003b: ldc.i4 0x989681 - IL_0040: blt.s IL_002e - - IL_0042: ldloc.0 - IL_0043: ret + IL_004d: stloc.0 + IL_004e: ldloc.3 + IL_004f: ldc.i4.1 + IL_0050: add + IL_0051: stloc.3 + IL_0052: ldloc.3 + IL_0053: ldc.i4 0x989681 + IL_0058: blt.s IL_0046 + + IL_005a: ldloc.0 + IL_005b: ret } } @@ -118,3 +216,21 @@ +sx + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl index ba62710f013..a66db1e8314 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl @@ -47,39 +47,88 @@ 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 arr@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class assembly/HashMicroPerfAndCodeGenerationTests/arr@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void assembly/HashMicroPerfAndCodeGenerationTests/arr@1::.ctor() + IL_0005: stsfld class assembly/HashMicroPerfAndCodeGenerationTests/arr@1 assembly/HashMicroPerfAndCodeGenerationTests/arr@1::@_instance + IL_000a: ret + } + + } + .method public static void f8() cil managed { - .maxstack 5 + .maxstack 4 .locals init (int32[] V_0, int32 V_1, int32 V_2) IL_0000: nop - IL_0001: ldc.i4.0 - IL_0002: ldc.i4.1 - IL_0003: ldc.i4.s 100 - IL_0005: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_000a: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_000f: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToArray(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0014: stloc.0 - IL_0015: ldc.i4.0 - IL_0016: stloc.1 - IL_0017: br.s IL_0024 - - IL_0019: ldloc.0 - IL_001a: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericHashIntrinsic(!!0) - IL_001f: stloc.2 - IL_0020: ldloc.1 - IL_0021: ldc.i4.1 - IL_0022: add - IL_0023: stloc.1 - IL_0024: ldloc.1 - IL_0025: ldc.i4 0x989681 - IL_002a: blt.s IL_0019 - - IL_002c: ret + IL_0001: nop + IL_0002: ldc.i4.s 100 + IL_0004: ldc.i4.0 + IL_0005: bge.s IL_000f + + IL_0007: call !!0[] [runtime]System.Array::Empty() + IL_000c: nop + IL_000d: br.s IL_0020 + + IL_000f: ldc.i4.s 100 + IL_0011: ldc.i4.0 + IL_0012: sub + IL_0013: ldc.i4.1 + IL_0014: add + IL_0015: ldsfld class assembly/HashMicroPerfAndCodeGenerationTests/arr@1 assembly/HashMicroPerfAndCodeGenerationTests/arr@1::@_instance + IL_001a: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_001f: nop + IL_0020: stloc.0 + IL_0021: ldc.i4.0 + IL_0022: stloc.1 + IL_0023: br.s IL_0030 + + IL_0025: ldloc.0 + IL_0026: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericHashIntrinsic(!!0) + IL_002b: stloc.2 + IL_002c: ldloc.1 + IL_002d: ldc.i4.1 + IL_002e: add + IL_002f: stloc.1 + IL_0030: ldloc.1 + IL_0031: ldc.i4 0x989681 + IL_0036: blt.s IL_0025 + + IL_0038: ret } } @@ -104,3 +153,18 @@ +ed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ListExpressionStepping/ListExpressionStepping02.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ListExpressionStepping/ListExpressionStepping02.fs.il.bsl index a8e6ce9949c..4c02a2d424e 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ListExpressionStepping/ListExpressionStepping02.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ListExpressionStepping/ListExpressionStepping02.fs.il.bsl @@ -47,6 +47,45 @@ 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 'Pipe #1 input #2 at line 16@1' + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1'::.ctor() + IL_0005: stsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1'::@_instance + IL_000a: ret + } + + } + .class auto ansi serializable sealed nested assembly beforefieldinit 'Pipe #1 stage #2 at line 18@18' extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,class [runtime]System.Tuple`2> { @@ -147,6 +186,84 @@ } + .class auto ansi serializable sealed nested assembly beforefieldinit 'Pipe #2 input #2 at line 22@1' + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1'::.ctor() + IL_0005: stsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1'::@_instance + IL_000a: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit 'Pipe #2 input #3 at line 22@1' + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1'::.ctor() + IL_0005: stsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1'::@_instance + IL_000a: ret + } + + } + .class auto ansi serializable sealed nested assembly beforefieldinit 'Pipe #2 stage #2 at line 24@24' extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2,class [runtime]System.Tuple`3> { @@ -314,81 +431,111 @@ IL_0012: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) IL_0017: stloc.1 - IL_0018: ldc.i4.0 - IL_0019: ldc.i4.1 - IL_001a: ldc.i4.2 - IL_001b: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_0020: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0025: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToList(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_002a: stloc.2 - IL_002b: ldloc.1 - IL_002c: ldloc.2 - IL_002d: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Zip(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, + IL_0018: nop + IL_0019: ldc.i4.2 + IL_001a: ldc.i4.0 + IL_001b: bge.s IL_0025 + + IL_001d: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_0022: nop + IL_0023: br.s IL_0035 + + IL_0025: ldc.i4.2 + IL_0026: ldc.i4.0 + IL_0027: sub + IL_0028: ldc.i4.1 + IL_0029: add + IL_002a: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1'::@_instance + IL_002f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0034: nop + IL_0035: stloc.2 + IL_0036: ldloc.1 + IL_0037: ldloc.2 + IL_0038: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Zip(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0032: stloc.3 - IL_0033: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 stage #2 at line 18@18' class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 stage #2 at line 18@18'::@_instance - IL_0038: ldloc.3 - IL_0039: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`2>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + IL_003d: stloc.3 + IL_003e: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 stage #2 at line 18@18' class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 stage #2 at line 18@18'::@_instance + IL_0043: ldloc.3 + IL_0044: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`2>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_003e: stloc.s V_4 - IL_0040: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs1@19 class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs1@19::@_instance - IL_0045: ldloc.s V_4 - IL_0047: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`2>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + IL_0049: stloc.s V_4 + IL_004b: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs1@19 class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs1@19::@_instance + IL_0050: ldloc.s V_4 + IL_0052: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`2>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_004c: stloc.0 - IL_004d: ldarg.0 - IL_004e: ldarg.0 - IL_004f: ldarg.0 - IL_0050: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_0055: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + IL_0057: stloc.0 + IL_0058: ldarg.0 + IL_0059: ldarg.0 + IL_005a: ldarg.0 + IL_005b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_0060: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_005a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + IL_0065: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_005f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + IL_006a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0064: stloc.s V_6 - IL_0066: ldc.i4.0 - IL_0067: ldc.i4.1 - IL_0068: ldc.i4.2 - IL_0069: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_006e: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0073: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToList(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0078: stloc.s V_7 - IL_007a: ldc.i4.0 - IL_007b: ldc.i4.1 - IL_007c: ldc.i4.2 - IL_007d: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_0082: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0087: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToList(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_008c: stloc.s V_8 - IL_008e: ldloc.s V_6 - IL_0090: ldloc.s V_7 - IL_0092: ldloc.s V_8 - IL_0094: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Zip3(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, + IL_006f: stloc.s V_6 + IL_0071: nop + IL_0072: ldc.i4.2 + IL_0073: ldc.i4.0 + IL_0074: bge.s IL_007e + + IL_0076: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_007b: nop + IL_007c: br.s IL_008e + + IL_007e: ldc.i4.2 + IL_007f: ldc.i4.0 + IL_0080: sub + IL_0081: ldc.i4.1 + IL_0082: add + IL_0083: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1'::@_instance + IL_0088: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_008d: nop + IL_008e: stloc.s V_7 + IL_0090: nop + IL_0091: ldc.i4.2 + IL_0092: ldc.i4.0 + IL_0093: bge.s IL_009d + + IL_0095: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_009a: nop + IL_009b: br.s IL_00ad + + IL_009d: ldc.i4.2 + IL_009e: ldc.i4.0 + IL_009f: sub + IL_00a0: ldc.i4.1 + IL_00a1: add + IL_00a2: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1'::@_instance + IL_00a7: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_00ac: nop + IL_00ad: stloc.s V_8 + IL_00af: ldloc.s V_6 + IL_00b1: ldloc.s V_7 + IL_00b3: ldloc.s V_8 + IL_00b5: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Zip3(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0099: stloc.s V_9 - IL_009b: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 stage #2 at line 24@24' class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 stage #2 at line 24@24'::@_instance - IL_00a0: ldloc.s V_9 - IL_00a2: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`3>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + IL_00ba: stloc.s V_9 + IL_00bc: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 stage #2 at line 24@24' class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 stage #2 at line 24@24'::@_instance + IL_00c1: ldloc.s V_9 + IL_00c3: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`3>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_00a7: stloc.s V_10 - IL_00a9: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs2@25 class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs2@25::@_instance - IL_00ae: ldloc.s V_10 - IL_00b0: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`3>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + IL_00c8: stloc.s V_10 + IL_00ca: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs2@25 class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs2@25::@_instance + IL_00cf: ldloc.s V_10 + IL_00d1: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`3>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_00b5: stloc.s V_5 - IL_00b7: ldloc.0 - IL_00b8: ldloc.s V_5 - IL_00ba: newobj instance void class [runtime]System.Tuple`2>,class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>>::.ctor(!0, + IL_00d6: stloc.s V_5 + IL_00d8: ldloc.0 + IL_00d9: ldloc.s V_5 + IL_00db: newobj instance void class [runtime]System.Tuple`2>,class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>>::.ctor(!0, !1) - IL_00bf: ret + IL_00e0: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/CodeGenRenamings01.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/CodeGenRenamings01.fs.il.bsl index 2e77dc87b3d..dd5659e05d8 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/CodeGenRenamings01.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/CodeGenRenamings01.fs.il.bsl @@ -43,6 +43,45 @@ 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 alist@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class assembly/alist@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void assembly/alist@1::.ctor() + IL_0005: stsfld class assembly/alist@1 assembly/alist@1::@_instance + IL_000a: ret + } + + } + .class auto autochar serializable sealed nested assembly beforefieldinit specialname seq1@9 extends class [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.GeneratedSequenceBase`1> { @@ -423,259 +462,269 @@ class [runtime]System.Tuple`4 V_18, class [runtime]System.Tuple`4 V_19, int32 V_20) - IL_0000: ldc.i4.1 - IL_0001: ldc.i4.1 - IL_0002: ldc.i4.s 10 - IL_0004: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_0009: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_000e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToList(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0013: dup - IL_0014: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::alist@5 - IL_0019: stloc.0 - IL_001a: ldc.i4.3 - IL_001b: newarr [runtime]System.Int32 - IL_0020: dup - IL_0021: ldc.i4.0 - IL_0022: ldc.i4.1 - IL_0023: stelem [runtime]System.Int32 - IL_0028: dup - IL_0029: ldc.i4.1 - IL_002a: ldc.i4.2 - IL_002b: stelem [runtime]System.Int32 - IL_0030: dup - IL_0031: ldc.i4.2 - IL_0032: ldc.i4.3 - IL_0033: stelem [runtime]System.Int32 - IL_0038: dup - IL_0039: stsfld int32[] ''.$assembly::array@6 - IL_003e: stloc.1 - IL_003f: ldc.i4.1 - IL_0040: ldc.i4.1 - IL_0041: ldc.i4.s 10 - IL_0043: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, + IL_0000: nop + IL_0001: ldc.i4.s 10 + IL_0003: ldc.i4.1 + IL_0004: bge.s IL_000e + + IL_0006: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_000b: nop + IL_000c: br.s IL_001f + + IL_000e: ldc.i4.s 10 + IL_0010: ldc.i4.1 + IL_0011: sub + IL_0012: ldc.i4.1 + IL_0013: add + IL_0014: ldsfld class assembly/alist@1 assembly/alist@1::@_instance + IL_0019: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_001e: nop + IL_001f: dup + IL_0020: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::alist@5 + IL_0025: stloc.0 + IL_0026: ldc.i4.3 + IL_0027: newarr [runtime]System.Int32 + IL_002c: dup + IL_002d: ldc.i4.0 + IL_002e: ldc.i4.1 + IL_002f: stelem [runtime]System.Int32 + IL_0034: dup + IL_0035: ldc.i4.1 + IL_0036: ldc.i4.2 + IL_0037: stelem [runtime]System.Int32 + IL_003c: dup + IL_003d: ldc.i4.2 + IL_003e: ldc.i4.3 + IL_003f: stelem [runtime]System.Int32 + IL_0044: dup + IL_0045: stsfld int32[] ''.$assembly::array@6 + IL_004a: stloc.1 + IL_004b: ldc.i4.1 + IL_004c: ldc.i4.1 + IL_004d: ldc.i4.s 10 + IL_004f: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, int32, int32) - IL_0048: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_004d: dup - IL_004e: stsfld class [runtime]System.Collections.Generic.IEnumerable`1 ''.$assembly::aseq@7 - IL_0053: stloc.2 - IL_0054: ldc.i4.1 - IL_0055: ldc.i4.1 - IL_0056: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, + IL_0054: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0059: dup + IL_005a: stsfld class [runtime]System.Collections.Generic.IEnumerable`1 ''.$assembly::aseq@7 + IL_005f: stloc.2 + IL_0060: ldc.i4.1 + IL_0061: ldc.i4.1 + IL_0062: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, !1) - IL_005b: ldc.i4.2 - IL_005c: ldc.i4.2 - IL_005d: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, + IL_0067: ldc.i4.2 + IL_0068: ldc.i4.2 + IL_0069: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, !1) - IL_0062: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::get_Empty() - IL_0067: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::Cons(!0, + IL_006e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::get_Empty() + IL_0073: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_006c: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::Cons(!0, + IL_0078: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0071: dup - IL_0072: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> ''.$assembly::list1@8 - IL_0077: stloc.3 - IL_0078: ldc.i4.0 - IL_0079: ldnull - IL_007a: newobj instance void assembly/seq1@9::.ctor(int32, + IL_007d: dup + IL_007e: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> ''.$assembly::list1@8 + IL_0083: stloc.3 + IL_0084: ldc.i4.0 + IL_0085: ldnull + IL_0086: newobj instance void assembly/seq1@9::.ctor(int32, class [runtime]System.Tuple`2) - IL_007f: dup - IL_0080: stsfld class [runtime]System.Collections.Generic.IEnumerable`1> ''.$assembly::seq1@9 - IL_0085: stloc.s V_4 - IL_0087: ldc.i4.2 - IL_0088: newarr class [runtime]System.Tuple`2 - IL_008d: dup - IL_008e: ldc.i4.0 - IL_008f: ldc.i4.1 - IL_0090: ldc.i4.1 - IL_0091: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, - !1) - IL_0096: stelem class [runtime]System.Tuple`2 - IL_009b: dup + IL_008b: dup + IL_008c: stsfld class [runtime]System.Collections.Generic.IEnumerable`1> ''.$assembly::seq1@9 + IL_0091: stloc.s V_4 + IL_0093: ldc.i4.2 + IL_0094: newarr class [runtime]System.Tuple`2 + IL_0099: dup + IL_009a: ldc.i4.0 + IL_009b: ldc.i4.1 IL_009c: ldc.i4.1 - IL_009d: ldc.i4.2 - IL_009e: ldc.i4.2 - IL_009f: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, + IL_009d: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, + !1) + IL_00a2: stelem class [runtime]System.Tuple`2 + IL_00a7: dup + IL_00a8: ldc.i4.1 + IL_00a9: ldc.i4.2 + IL_00aa: ldc.i4.2 + IL_00ab: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, !1) - IL_00a4: stelem class [runtime]System.Tuple`2 - IL_00a9: dup - IL_00aa: stsfld class [runtime]System.Tuple`2[] ''.$assembly::array1@10 - IL_00af: stloc.s V_5 - IL_00b1: ldc.i4.2 - IL_00b2: ldc.i4.2 - IL_00b3: ldc.i4.0 - IL_00b4: call !!0[0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Create(int32, + IL_00b0: stelem class [runtime]System.Tuple`2 + IL_00b5: dup + IL_00b6: stsfld class [runtime]System.Tuple`2[] ''.$assembly::array1@10 + IL_00bb: stloc.s V_5 + IL_00bd: ldc.i4.2 + IL_00be: ldc.i4.2 + IL_00bf: ldc.i4.0 + IL_00c0: call !!0[0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Create(int32, int32, !!0) - IL_00b9: dup - IL_00ba: stsfld int32[0...,0...] ''.$assembly::a3@11 - IL_00bf: stloc.s V_6 - IL_00c1: ldc.i4.3 - IL_00c2: ldc.i4.3 - IL_00c3: ldc.i4.3 - IL_00c4: ldc.i4.0 - IL_00c5: call !!0[0...,0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Create(int32, + IL_00c5: dup + IL_00c6: stsfld int32[0...,0...] ''.$assembly::a3@11 + IL_00cb: stloc.s V_6 + IL_00cd: ldc.i4.3 + IL_00ce: ldc.i4.3 + IL_00cf: ldc.i4.3 + IL_00d0: ldc.i4.0 + IL_00d1: call !!0[0...,0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Create(int32, int32, int32, !!0) - IL_00ca: dup - IL_00cb: stsfld int32[0...,0...,0...] ''.$assembly::array3D@12 - IL_00d0: stloc.s V_7 - IL_00d2: ldc.i4.4 - IL_00d3: ldc.i4.4 - IL_00d4: ldc.i4.4 - IL_00d5: ldc.i4.4 - IL_00d6: ldc.i4.0 - IL_00d7: call !!0[0...,0...,0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Create(int32, + IL_00d6: dup + IL_00d7: stsfld int32[0...,0...,0...] ''.$assembly::array3D@12 + IL_00dc: stloc.s V_7 + IL_00de: ldc.i4.4 + IL_00df: ldc.i4.4 + IL_00e0: ldc.i4.4 + IL_00e1: ldc.i4.4 + IL_00e2: ldc.i4.0 + IL_00e3: call !!0[0...,0...,0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Create(int32, int32, int32, int32, !!0) - IL_00dc: dup - IL_00dd: stsfld int32[0...,0...,0...,0...] ''.$assembly::array4D@13 - IL_00e2: stloc.s V_8 - IL_00e4: call int32[] assembly::get_array() - IL_00e9: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::OfArray(!!0[]) - IL_00ee: pop - IL_00ef: call class [runtime]System.Collections.Generic.IEnumerable`1 assembly::get_aseq() - IL_00f4: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_00f9: pop - IL_00fa: call class [runtime]System.Tuple`2[] assembly::get_array1() - IL_00ff: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfArray(class [runtime]System.Tuple`2[]) - IL_0104: pop - IL_0105: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> assembly::get_list1() - IL_010a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfList(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>) - IL_010f: pop - IL_0110: call class [runtime]System.Collections.Generic.IEnumerable`1> assembly::get_seq1() - IL_0115: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1>) - IL_011a: pop - IL_011b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_alist() - IL_0120: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::OfList(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0125: dup - IL_0126: stsfld int32[] ''.$assembly::a1@25 - IL_012b: stloc.s V_9 - IL_012d: call class [runtime]System.Collections.Generic.IEnumerable`1 assembly::get_aseq() - IL_0132: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0137: dup - IL_0138: stsfld int32[] ''.$assembly::a2@26 - IL_013d: stloc.s V_10 - IL_013f: call int32[] assembly::get_a1() - IL_0144: ldc.i4.0 - IL_0145: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Get(!!0[], + IL_00e8: dup + IL_00e9: stsfld int32[0...,0...,0...,0...] ''.$assembly::array4D@13 + IL_00ee: stloc.s V_8 + IL_00f0: call int32[] assembly::get_array() + IL_00f5: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::OfArray(!!0[]) + IL_00fa: pop + IL_00fb: call class [runtime]System.Collections.Generic.IEnumerable`1 assembly::get_aseq() + IL_0100: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0105: pop + IL_0106: call class [runtime]System.Tuple`2[] assembly::get_array1() + IL_010b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfArray(class [runtime]System.Tuple`2[]) + IL_0110: pop + IL_0111: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> assembly::get_list1() + IL_0116: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfList(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>) + IL_011b: pop + IL_011c: call class [runtime]System.Collections.Generic.IEnumerable`1> assembly::get_seq1() + IL_0121: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1>) + IL_0126: pop + IL_0127: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_alist() + IL_012c: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::OfList(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_0131: dup + IL_0132: stsfld int32[] ''.$assembly::a1@25 + IL_0137: stloc.s V_9 + IL_0139: call class [runtime]System.Collections.Generic.IEnumerable`1 assembly::get_aseq() + IL_013e: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0143: dup + IL_0144: stsfld int32[] ''.$assembly::a2@26 + IL_0149: stloc.s V_10 + IL_014b: call int32[] assembly::get_a1() + IL_0150: ldc.i4.0 + IL_0151: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Get(!!0[], int32) - IL_014a: stloc.s V_11 - IL_014c: call int32[] assembly::get_a2() - IL_0151: ldc.i4.0 - IL_0152: ldloc.s V_11 - IL_0154: call void [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Set(!!0[], + IL_0156: stloc.s V_11 + IL_0158: call int32[] assembly::get_a2() + IL_015d: ldc.i4.0 + IL_015e: ldloc.s V_11 + IL_0160: call void [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Set(!!0[], int32, !!0) - IL_0159: nop - IL_015a: call int32[0...,0...] assembly::get_a3() - IL_015f: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Length1(!!0[0...,0...]) - IL_0164: call int32[0...,0...] assembly::get_a3() - IL_0169: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Length2(!!0[0...,0...]) - IL_016e: call int32[0...,0...] assembly::get_a3() - IL_0173: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Base1(!!0[0...,0...]) - IL_0178: call int32[0...,0...] assembly::get_a3() - IL_017d: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Base2(!!0[0...,0...]) - IL_0182: newobj instance void class [runtime]System.Tuple`4::.ctor(!0, + IL_0165: nop + IL_0166: call int32[0...,0...] assembly::get_a3() + IL_016b: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Length1(!!0[0...,0...]) + IL_0170: call int32[0...,0...] assembly::get_a3() + IL_0175: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Length2(!!0[0...,0...]) + IL_017a: call int32[0...,0...] assembly::get_a3() + IL_017f: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Base1(!!0[0...,0...]) + IL_0184: call int32[0...,0...] assembly::get_a3() + IL_0189: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Base2(!!0[0...,0...]) + IL_018e: newobj instance void class [runtime]System.Tuple`4::.ctor(!0, !1, !2, !3) - IL_0187: stloc.s V_12 - IL_0189: ldloc.s V_12 - IL_018b: stloc.s V_13 - IL_018d: call int32[0...,0...] assembly::get_a3() - IL_0192: ldc.i4.0 - IL_0193: ldc.i4.0 - IL_0194: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Get(!!0[0...,0...], + IL_0193: stloc.s V_12 + IL_0195: ldloc.s V_12 + IL_0197: stloc.s V_13 + IL_0199: call int32[0...,0...] assembly::get_a3() + IL_019e: ldc.i4.0 + IL_019f: ldc.i4.0 + IL_01a0: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Get(!!0[0...,0...], int32, int32) - IL_0199: stloc.s V_14 - IL_019b: call int32[0...,0...] assembly::get_a3() - IL_01a0: ldc.i4.0 - IL_01a1: ldc.i4.0 - IL_01a2: ldloc.s V_14 - IL_01a4: call void [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Set(!!0[0...,0...], + IL_01a5: stloc.s V_14 + IL_01a7: call int32[0...,0...] assembly::get_a3() + IL_01ac: ldc.i4.0 + IL_01ad: ldc.i4.0 + IL_01ae: ldloc.s V_14 + IL_01b0: call void [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Set(!!0[0...,0...], int32, int32, !!0) - IL_01a9: nop - IL_01aa: call int32[0...,0...,0...] assembly::get_array3D() - IL_01af: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length1(!!0[0...,0...,0...]) - IL_01b4: call int32[0...,0...,0...] assembly::get_array3D() - IL_01b9: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length2(!!0[0...,0...,0...]) - IL_01be: call int32[0...,0...,0...] assembly::get_array3D() - IL_01c3: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length3(!!0[0...,0...,0...]) - IL_01c8: newobj instance void class [runtime]System.Tuple`3::.ctor(!0, + IL_01b5: nop + IL_01b6: call int32[0...,0...,0...] assembly::get_array3D() + IL_01bb: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length1(!!0[0...,0...,0...]) + IL_01c0: call int32[0...,0...,0...] assembly::get_array3D() + IL_01c5: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length2(!!0[0...,0...,0...]) + IL_01ca: call int32[0...,0...,0...] assembly::get_array3D() + IL_01cf: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length3(!!0[0...,0...,0...]) + IL_01d4: newobj instance void class [runtime]System.Tuple`3::.ctor(!0, !1, !2) - IL_01cd: stloc.s V_15 - IL_01cf: ldloc.s V_15 - IL_01d1: stloc.s V_16 - IL_01d3: call int32[0...,0...,0...] assembly::get_array3D() - IL_01d8: ldc.i4.0 - IL_01d9: ldc.i4.0 - IL_01da: ldc.i4.0 - IL_01db: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Get(!!0[0...,0...,0...], + IL_01d9: stloc.s V_15 + IL_01db: ldloc.s V_15 + IL_01dd: stloc.s V_16 + IL_01df: call int32[0...,0...,0...] assembly::get_array3D() + IL_01e4: ldc.i4.0 + IL_01e5: ldc.i4.0 + IL_01e6: ldc.i4.0 + IL_01e7: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Get(!!0[0...,0...,0...], int32, int32, int32) - IL_01e0: stloc.s V_17 - IL_01e2: call int32[0...,0...,0...] assembly::get_array3D() - IL_01e7: ldc.i4.0 - IL_01e8: ldc.i4.0 - IL_01e9: ldc.i4.0 - IL_01ea: ldloc.s V_17 - IL_01ec: call void [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Set(!!0[0...,0...,0...], + IL_01ec: stloc.s V_17 + IL_01ee: call int32[0...,0...,0...] assembly::get_array3D() + IL_01f3: ldc.i4.0 + IL_01f4: ldc.i4.0 + IL_01f5: ldc.i4.0 + IL_01f6: ldloc.s V_17 + IL_01f8: call void [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Set(!!0[0...,0...,0...], int32, int32, int32, !!0) - IL_01f1: nop - IL_01f2: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_01f7: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length1(!!0[0...,0...,0...,0...]) - IL_01fc: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_0201: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length2(!!0[0...,0...,0...,0...]) - IL_0206: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_020b: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length3(!!0[0...,0...,0...,0...]) - IL_0210: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_0215: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length4(!!0[0...,0...,0...,0...]) - IL_021a: newobj instance void class [runtime]System.Tuple`4::.ctor(!0, + IL_01fd: nop + IL_01fe: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_0203: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length1(!!0[0...,0...,0...,0...]) + IL_0208: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_020d: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length2(!!0[0...,0...,0...,0...]) + IL_0212: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_0217: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length3(!!0[0...,0...,0...,0...]) + IL_021c: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_0221: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length4(!!0[0...,0...,0...,0...]) + IL_0226: newobj instance void class [runtime]System.Tuple`4::.ctor(!0, !1, !2, !3) - IL_021f: stloc.s V_18 - IL_0221: ldloc.s V_18 - IL_0223: stloc.s V_19 - IL_0225: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_022a: ldc.i4.0 - IL_022b: ldc.i4.0 - IL_022c: ldc.i4.0 - IL_022d: ldc.i4.0 - IL_022e: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Get(!!0[0...,0...,0...,0...], + IL_022b: stloc.s V_18 + IL_022d: ldloc.s V_18 + IL_022f: stloc.s V_19 + IL_0231: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_0236: ldc.i4.0 + IL_0237: ldc.i4.0 + IL_0238: ldc.i4.0 + IL_0239: ldc.i4.0 + IL_023a: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Get(!!0[0...,0...,0...,0...], int32, int32, int32, int32) - IL_0233: stloc.s V_20 - IL_0235: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_023a: ldc.i4.0 - IL_023b: ldc.i4.0 - IL_023c: ldc.i4.0 - IL_023d: ldc.i4.0 - IL_023e: ldloc.s V_20 - IL_0240: call void [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Set(!!0[0...,0...,0...,0...], + IL_023f: stloc.s V_20 + IL_0241: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_0246: ldc.i4.0 + IL_0247: ldc.i4.0 + IL_0248: ldc.i4.0 + IL_0249: ldc.i4.0 + IL_024a: ldloc.s V_20 + IL_024c: call void [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Set(!!0[0...,0...,0...,0...], int32, int32, int32, int32, !!0) - IL_0245: nop - IL_0246: ret + IL_0251: nop + IL_0252: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ForLoop01.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ForLoop01.fs.il.bsl index 7d0d3f2f625..e5c6b9f25d3 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ForLoop01.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ForLoop01.fs.il.bsl @@ -43,6 +43,45 @@ 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 clo@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class assembly/clo@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void assembly/clo@1::.ctor() + IL_0005: stsfld class assembly/clo@1 assembly/clo@1::@_instance + IL_000a: ret + } + + } + } .class private abstract auto ansi sealed ''.$assembly @@ -56,42 +95,52 @@ { .entrypoint - .maxstack 5 + .maxstack 4 .locals init (class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_1, int32 V_2) - IL_0000: ldc.i4.1 - IL_0001: ldc.i4.1 - IL_0002: ldc.i4.3 - IL_0003: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_0008: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_000d: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToList(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0012: stloc.0 - IL_0013: ldloc.0 - IL_0014: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() - IL_0019: stloc.1 - IL_001a: br.s IL_0042 - - IL_001c: ldloc.0 - IL_001d: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() - IL_0022: stloc.2 - IL_0023: ldstr "%A" - IL_0028: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit,int32>::.ctor(string) - IL_002d: call !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine>(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4) - IL_0032: ldloc.2 - IL_0033: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_0038: pop - IL_0039: ldloc.1 - IL_003a: stloc.0 - IL_003b: ldloc.0 - IL_003c: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() - IL_0041: stloc.1 - IL_0042: ldloc.1 - IL_0043: brtrue.s IL_001c - - IL_0045: ret + IL_0000: nop + IL_0001: ldc.i4.3 + IL_0002: ldc.i4.1 + IL_0003: bge.s IL_000d + + IL_0005: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_000a: nop + IL_000b: br.s IL_001d + + IL_000d: ldc.i4.3 + IL_000e: ldc.i4.1 + IL_000f: sub + IL_0010: ldc.i4.1 + IL_0011: add + IL_0012: ldsfld class assembly/clo@1 assembly/clo@1::@_instance + IL_0017: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_001c: nop + IL_001d: stloc.0 + IL_001e: ldloc.0 + IL_001f: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0024: stloc.1 + IL_0025: br.s IL_004d + + IL_0027: ldloc.0 + IL_0028: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_002d: stloc.2 + IL_002e: ldstr "%A" + IL_0033: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit,int32>::.ctor(string) + IL_0038: call !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine>(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4) + IL_003d: ldloc.2 + IL_003e: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0043: pop + IL_0044: ldloc.1 + IL_0045: stloc.0 + IL_0046: ldloc.0 + IL_0047: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_004c: stloc.1 + IL_004d: ldloc.1 + IL_004e: brtrue.s IL_0027 + + IL_0050: ret } } diff --git a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs index 57b808f4ea2..b163b9db629 100644 --- a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs +++ b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs @@ -162,29 +162,21 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldc.i4.s 10 IL_0002: ldc.i4.1 - IL_0003: sub - IL_0004: ldc.i4.1 - IL_0005: add - IL_0006: ldc.i4.s 10 - IL_0008: ldc.i4.1 - IL_0009: sub - IL_000a: ldc.i4.1 - IL_000b: add - IL_000c: ldc.i4.s 10 - IL_000e: ldc.i4.1 - IL_000f: sub - IL_0010: ldc.i4.1 - IL_0011: add - IL_0012: ldc.i4.0 - IL_0013: clt - IL_0015: neg - IL_0016: and - IL_0017: xor - IL_0018: ldsfld class Test/test@1 Test/test@1::@_instance - IL_001d: tail. - IL_001f: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0003: bge.s IL_000b + + IL_0005: call !!0[] [runtime]System.Array::Empty() + IL_000a: ret + + IL_000b: ldc.i4.s 10 + IL_000d: ldc.i4.1 + IL_000e: sub + IL_000f: ldc.i4.1 + IL_0010: add + IL_0011: ldsfld class Test/test@1 Test/test@1::@_instance + IL_0016: tail. + IL_0018: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0024: ret + IL_001d: ret } } @@ -287,29 +279,21 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldc.i4 0x101 IL_0005: ldc.i4.1 - IL_0006: sub - IL_0007: ldc.i4.1 - IL_0008: add - IL_0009: ldc.i4 0x101 - IL_000e: ldc.i4.1 - IL_000f: sub - IL_0010: ldc.i4.1 - IL_0011: add - IL_0012: ldc.i4 0x101 - IL_0017: ldc.i4.1 - IL_0018: sub - IL_0019: ldc.i4.1 - IL_001a: add - IL_001b: ldc.i4.0 - IL_001c: clt - IL_001e: neg - IL_001f: and - IL_0020: xor - IL_0021: ldsfld class Test/test@1 Test/test@1::@_instance - IL_0026: tail. - IL_0028: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0006: bge.s IL_000e + + IL_0008: call !!0[] [runtime]System.Array::Empty() + IL_000d: ret + + IL_000e: ldc.i4 0x101 + IL_0013: ldc.i4.1 + IL_0014: sub + IL_0015: ldc.i4.1 + IL_0016: add + IL_0017: ldsfld class Test/test@1 Test/test@1::@_instance + IL_001c: tail. + IL_001e: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_002d: ret + IL_0023: ret } } @@ -408,30 +392,22 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldarg.1 IL_0001: ldarg.0 - IL_0002: sub - IL_0003: ldc.i4.1 - IL_0004: add - IL_0005: ldarg.1 - IL_0006: ldarg.0 - IL_0007: sub - IL_0008: ldc.i4.1 - IL_0009: add + IL_0002: bge.s IL_000a + + IL_0004: call !!0[] [runtime]System.Array::Empty() + IL_0009: ret + IL_000a: ldarg.1 IL_000b: ldarg.0 IL_000c: sub IL_000d: ldc.i4.1 IL_000e: add - IL_000f: ldc.i4.0 - IL_0010: clt - IL_0012: neg - IL_0013: and - IL_0014: xor - IL_0015: ldarg.0 - IL_0016: newobj instance void Test/test@1::.ctor(int32) - IL_001b: tail. - IL_001d: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_000f: ldarg.0 + IL_0010: newobj instance void Test/test@1::.ctor(int32) + IL_0015: tail. + IL_0017: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0022: ret + IL_001c: ret } } @@ -600,29 +576,21 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldc.i4.s 10 IL_0002: ldc.i4.1 - IL_0003: sub - IL_0004: ldc.i4.1 - IL_0005: add - IL_0006: ldc.i4.s 10 - IL_0008: ldc.i4.1 - IL_0009: sub - IL_000a: ldc.i4.1 - IL_000b: add - IL_000c: ldc.i4.s 10 - IL_000e: ldc.i4.1 - IL_000f: sub - IL_0010: ldc.i4.1 - IL_0011: add - IL_0012: ldc.i4.0 - IL_0013: clt - IL_0015: neg - IL_0016: and - IL_0017: xor - IL_0018: ldsfld class Test/test@1 Test/test@1::@_instance - IL_001d: tail. - IL_001f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_0003: bge.s IL_000b + + IL_0005: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_000a: ret + + IL_000b: ldc.i4.s 10 + IL_000d: ldc.i4.1 + IL_000e: sub + IL_000f: ldc.i4.1 + IL_0010: add + IL_0011: ldsfld class Test/test@1 Test/test@1::@_instance + IL_0016: tail. + IL_0018: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0024: ret + IL_001d: ret } } @@ -726,29 +694,21 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldc.i4.s 101 IL_0002: ldc.i4.1 - IL_0003: sub - IL_0004: ldc.i4.1 - IL_0005: add - IL_0006: ldc.i4.s 101 - IL_0008: ldc.i4.1 - IL_0009: sub - IL_000a: ldc.i4.1 - IL_000b: add - IL_000c: ldc.i4.s 101 - IL_000e: ldc.i4.1 - IL_000f: sub - IL_0010: ldc.i4.1 - IL_0011: add - IL_0012: ldc.i4.0 - IL_0013: clt - IL_0015: neg - IL_0016: and - IL_0017: xor - IL_0018: ldsfld class Test/test@1 Test/test@1::@_instance - IL_001d: tail. - IL_001f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_0003: bge.s IL_000b + + IL_0005: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_000a: ret + + IL_000b: ldc.i4.s 101 + IL_000d: ldc.i4.1 + IL_000e: sub + IL_000f: ldc.i4.1 + IL_0010: add + IL_0011: ldsfld class Test/test@1 Test/test@1::@_instance + IL_0016: tail. + IL_0018: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0024: ret + IL_001d: ret } } @@ -848,30 +808,22 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldarg.1 IL_0001: ldarg.0 - IL_0002: sub - IL_0003: ldc.i4.1 - IL_0004: add - IL_0005: ldarg.1 - IL_0006: ldarg.0 - IL_0007: sub - IL_0008: ldc.i4.1 - IL_0009: add + IL_0002: bge.s IL_000a + + IL_0004: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_0009: ret + IL_000a: ldarg.1 IL_000b: ldarg.0 IL_000c: sub IL_000d: ldc.i4.1 IL_000e: add - IL_000f: ldc.i4.0 - IL_0010: clt - IL_0012: neg - IL_0013: and - IL_0014: xor - IL_0015: ldarg.0 - IL_0016: newobj instance void Test/test@1::.ctor(int32) - IL_001b: tail. - IL_001d: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_000f: ldarg.0 + IL_0010: newobj instance void Test/test@1::.ctor(int32) + IL_0015: tail. + IL_0017: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0022: ret + IL_001c: ret } } From e55cc55098098c3d49b343f73a766057ecc50c9f Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Sat, 27 Jan 2024 14:12:36 -0500 Subject: [PATCH 16/25] Bind exprs to locals when needed --- .../Optimize/LowerComputedCollections.fs | 138 +++++++++--- ...onTrivialBranchingBindingInEnd03.fs.il.bsl | 212 ++++++++++++------ ...ivialBranchingBindingInEnd03.fs.opt.il.bsl | 212 ++++++++++++------ 3 files changed, 383 insertions(+), 179 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 2f8eed54c33..627cc699526 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -255,78 +255,142 @@ let (|SeqToArray|_|) g expr = | ValApp g g.seq_to_array_vref (_, [seqExpr], m) -> ValueSome (seqExpr, m) | _ -> ValueNone -/// 1..10 -[] -let (|ConstInt32Range|_|) g expr = - match expr with - | ValApp g g.range_int32_op_vref ([], [Expr.Const (value = Const.Int32 start); Expr.Const (value = Const.Int32 1); Expr.Const (value = Const.Int32 finish)], _), _ -> ValueSome (start, finish) - | _ -> ValueNone - /// start..finish [] -let (|Int32Range|_|) g expr = +let (|Int32Range|_|) g (expr, _ty) = match expr with - | ValApp g g.range_int32_op_vref ([], [start; Expr.Const (value = Const.Int32 1); finish], _), _ -> ValueSome (start, finish) + | ValApp g g.range_int32_op_vref ([], [start; Expr.Const (value = Const.Int32 1); finish], _) -> ValueSome (start, finish) | _ -> ValueNone let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = // If ListCollector is in FSharp.Core then this optimization kicks in if g.ListCollector_tcr.CanDeref then + /// Make an expression holding the count/length + /// to initialize the collection with. + let mkCount start finish = + let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) + mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) + + /// Make a lambda expression to pass into + /// the Array.init/List.init call. + let mkInitializer start = + let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty + let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) + mkLambda Text.Range.range0 v (body, g.int32_ty) + + /// Make an expression that initializes a list + /// with the values from start through finish. + let mkListInit m start finish = + mkCond + DebugPointAtBinding.NoneAtInvisible + m + (mkListTy g g.int32_ty) + (mkILAsmClt g Text.Range.range0 finish start) + (mkNil g Text.Range.range0 g.int32_ty) + (mkCallListInit g Text.Range.range0 g.int32_ty (mkCount start finish) (mkInitializer start)) + + /// Make an expression that initializes an array + /// with the values from start through finish. + let mkArrayInit m start finish = + mkCond + DebugPointAtBinding.NoneAtInvisible + m + (mkArrayType g g.int32_ty) + (mkILAsmClt g Text.Range.range0 finish start) + (mkArray (g.int32_ty, [], Text.Range.range0)) + (mkCallArrayInit g Text.Range.range0 g.int32_ty (mkCount start finish) (mkInitializer start)) + match overallExpr with // [5..1] → [] - | SeqToList g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when + | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (Expr.Const (value = Const.Int32 start), Expr.Const (value = Const.Int32 finish)))), m) when start > finish -> Some (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m)) // [start..finish] → if finish < start then [] else List.init (finish - start + 1) ((+) start) - | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> - let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) - let range = mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) - let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty - let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) - let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) + | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start & (Expr.Const _ | Expr.Val _), finish & (Expr.Const _ | Expr.Val _)))), m) -> + Some (mkListInit m start finish) + // [start..finishExpr] → + // let finish = finishExpr + // if finish < start then [] else List.init (finish - start + 1) ((+) start) + | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start & (Expr.Const _ | Expr.Val _), finish))), m) -> let expr = - mkCond - DebugPointAtBinding.NoneAtInvisible - m - (mkListTy g g.int32_ty) - (mkILAsmClt g Text.Range.range0 finish start) - (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], Text.Range.range0)) - (mkCallListInit g Text.Range.range0 g.int32_ty range initializer) + mkCompGenLetIn Text.Range.range0 (nameof finish) g.int32_ty finish (fun (_, finish) -> + mkListInit m start finish) Some expr + // [startExpr..finish] → + // let start = startExpr + // if finish < start then [] else List.init (finish - start + 1) ((+) start) + | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish & (Expr.Const _ | Expr.Val _)))), m) -> + let expr = + mkCompGenLetIn Text.Range.range0 (nameof start) g.int32_ty start (fun (_, start) -> + mkListInit m start finish) + + Some expr + + // [startExpr..finishExpr] → + // let start = startExpr + // let finish = finishExpr + // if finish < start then [] else List.init (finish - start + 1) ((+) start) + | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> + let expr = + mkCompGenLetIn Text.Range.range0 (nameof start) g.int32_ty start (fun (_, start) -> + mkCompGenLetIn Text.Range.range0 (nameof finish) g.int32_ty finish (fun (_, finish) -> + mkListInit m start finish)) + + Some expr + + // [(* Anything more complex. *)] | SeqToList g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ListCollector_ty overallElemTy LowerComputedListOrArraySeqExpr tcVal g amap m collectorTy overallSeqExpr // [|5..1|] → [||] - | SeqToArray g (OptionalCoerce (OptionalSeq g amap (ConstInt32Range g (start, finish))), m) when + | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (Expr.Const (value = Const.Int32 start), Expr.Const (value = Const.Int32 finish)))), m) when start > finish -> Some (mkArray (g.int32_ty, [], m)) // [|start..finish|] → if finish < start then [||] else Array.init (finish - start + 1) ((+) start) - | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> - let diff = mkAsmExpr ([AI_sub], [], [finish; start], [g.int32_ty], Text.Range.range0) - let range = mkAsmExpr ([AI_add], [], [diff; mkOne g Text.Range.range0], [g.int32_ty], Text.Range.range0) - let v, e = mkCompGenLocal Text.Range.range0 "i" g.int32_ty - let body = mkAsmExpr ([AI_add], [], [start; e], [g.int32_ty], Text.Range.range0) - let initializer = mkLambda Text.Range.range0 v (body, g.int32_ty) + | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start & (Expr.Const _ | Expr.Val _), finish & (Expr.Const _ | Expr.Val _)))), m) -> + Some (mkArrayInit m start finish) + // [|start..finishExpr|] → + // let finish = finishExpr + // if finish < start then [||] else Array.init (finish - start + 1) ((+) start) + | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start & (Expr.Const _ | Expr.Val _), finish))), m) -> + let expr = + mkCompGenLetIn Text.Range.range0 (nameof finish) g.int32_ty finish (fun (_, finish) -> + mkArrayInit m start finish) + + Some expr + + // [|startExpr..finish|] → + // let start = startExpr + // if finish < start then [||] else Array.init (finish - start + 1) ((+) start) + | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish & (Expr.Const _ | Expr.Val _)))), m) -> + let expr = + mkCompGenLetIn Text.Range.range0 (nameof start) g.int32_ty start (fun (_, start) -> + mkArrayInit m start finish) + + Some expr + + // [|startExpr..finishExpr|] → + // let start = startExpr + // let finish = finishExpr + // if finish < start then [||] else Array.init (finish - start + 1) ((+) start) + | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> let expr = - mkCond - DebugPointAtBinding.NoneAtInvisible - m - (mkArrayType g g.int32_ty) - (mkILAsmClt g Text.Range.range0 finish start) - (mkArray (g.int32_ty, [], Text.Range.range0)) - (mkCallArrayInit g Text.Range.range0 g.int32_ty range initializer) + mkCompGenLetIn Text.Range.range0 (nameof start) g.int32_ty start (fun (_, start) -> + mkCompGenLetIn Text.Range.range0 (nameof finish) g.int32_ty finish (fun (_, finish) -> + mkArrayInit m start finish)) Some expr + // [|(* Anything more complex. *)|] | SeqToArray g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> let collectorTy = g.mk_ArrayCollector_ty overallElemTy LowerComputedListOrArraySeqExpr tcVal g amap m collectorTy overallSeqExpr diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.il.bsl index f4f037c9936..2e04d20b56f 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.il.bsl @@ -43,6 +43,45 @@ 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 clo@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class assembly/clo@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void assembly/clo@1::.ctor() + IL_0005: stsfld class assembly/clo@1 assembly/clo@1::@_instance + IL_000a: ret + } + + } + .method public specialname static int32[] get_r() cil managed { @@ -188,77 +227,108 @@ IL_000e: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Create(int32, !!0) IL_0013: stsfld int32[] ''.$assembly::w@7 - IL_0018: ldc.i4.0 - IL_0019: ldc.i4.1 - IL_001a: call int32[] assembly::get_r() - IL_001f: ldlen - IL_0020: conv.i4 - IL_0021: stsfld int32 ''.$assembly::e1@1 - IL_0026: call int32[] assembly::get_w() - IL_002b: ldlen - IL_002c: conv.i4 - IL_002d: stsfld int32 ''.$assembly::e2@1 - IL_0032: call int32 assembly::get_e1@1() - IL_0037: call int32 assembly::get_e2@1() - IL_003c: bge.s IL_0046 - - IL_003e: call int32 assembly::get_e1@1() - IL_0043: nop - IL_0044: br.s IL_004c - - IL_0046: call int32 assembly::get_e2@1() - IL_004b: nop - IL_004c: ldc.i4.1 - IL_004d: sub - IL_004e: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_0053: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0058: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToList(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_005d: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::current@9 - IL_0062: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_current@9() - IL_0067: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() - IL_006c: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::next@9 - IL_0071: br.s IL_00b9 - - IL_0073: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_current@9() - IL_0078: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() - IL_007d: stloc.0 - IL_007e: call int32[] assembly::get_r() - IL_0083: ldloc.0 - IL_0084: call int32[] assembly::get_r() - IL_0089: ldloc.0 - IL_008a: ldelem [runtime]System.Int32 - IL_008f: call int32[] assembly::get_w() - IL_0094: ldloc.0 - IL_0095: ldelem [runtime]System.Int32 - IL_009a: add - IL_009b: stelem [runtime]System.Int32 - IL_00a0: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_next@9() - IL_00a5: call void assembly::set_current@9(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_00aa: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_current@9() - IL_00af: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() - IL_00b4: call void assembly::set_next@9(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_00b9: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_next@9() - IL_00be: brtrue.s IL_0073 - - IL_00c0: nop - IL_00c1: nop - IL_00c2: call int32[] assembly::get_r() - IL_00c7: ldc.i4.0 - IL_00c8: ldelem [runtime]System.Int32 - IL_00cd: ldc.i4.3 - IL_00ce: bne.un.s IL_00d4 - - IL_00d0: ldc.i4.0 - IL_00d1: nop - IL_00d2: br.s IL_00d6 - - IL_00d4: ldc.i4.1 - IL_00d5: nop - IL_00d6: call !!0 [FSharp.Core]Microsoft.FSharp.Core.Operators::Exit(int32) - IL_00db: pop - IL_00dc: ret + IL_0018: call int32[] assembly::get_r() + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: stsfld int32 ''.$assembly::e1@1 + IL_0024: call int32[] assembly::get_w() + IL_0029: ldlen + IL_002a: conv.i4 + IL_002b: stsfld int32 ''.$assembly::e2@1 + IL_0030: call int32 assembly::get_e1@1() + IL_0035: call int32 assembly::get_e2@1() + IL_003a: bge.s IL_0044 + + IL_003c: call int32 assembly::get_e1@1() + IL_0041: nop + IL_0042: br.s IL_004a + + IL_0044: call int32 assembly::get_e2@1() + IL_0049: nop + IL_004a: ldc.i4.1 + IL_004b: sub + IL_004c: stloc.0 + IL_004d: ldloc.0 + IL_004e: ldc.i4.0 + IL_004f: bge.s IL_0059 + + IL_0051: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_0056: nop + IL_0057: br.s IL_0069 + + IL_0059: ldloc.0 + IL_005a: ldc.i4.0 + IL_005b: sub + IL_005c: ldc.i4.1 + IL_005d: add + IL_005e: ldsfld class assembly/clo@1 assembly/clo@1::@_instance + IL_0063: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0068: nop + IL_0069: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::current@9 + IL_006e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_current@9() + IL_0073: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0078: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::next@9 + IL_007d: br.s IL_00c5 + + IL_007f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_current@9() + IL_0084: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0089: stloc.0 + IL_008a: call int32[] assembly::get_r() + IL_008f: ldloc.0 + IL_0090: call int32[] assembly::get_r() + IL_0095: ldloc.0 + IL_0096: ldelem [runtime]System.Int32 + IL_009b: call int32[] assembly::get_w() + IL_00a0: ldloc.0 + IL_00a1: ldelem [runtime]System.Int32 + IL_00a6: add + IL_00a7: stelem [runtime]System.Int32 + IL_00ac: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_next@9() + IL_00b1: call void assembly::set_current@9(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_00b6: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_current@9() + IL_00bb: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_00c0: call void assembly::set_next@9(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_00c5: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_next@9() + IL_00ca: brtrue.s IL_007f + + IL_00cc: nop + IL_00cd: nop + IL_00ce: call int32[] assembly::get_r() + IL_00d3: ldc.i4.0 + IL_00d4: ldelem [runtime]System.Int32 + IL_00d9: ldc.i4.3 + IL_00da: bne.un.s IL_00e0 + + IL_00dc: ldc.i4.0 + IL_00dd: nop + IL_00de: br.s IL_00e2 + + IL_00e0: ldc.i4.1 + IL_00e1: nop + IL_00e2: call !!0 [FSharp.Core]Microsoft.FSharp.Core.Operators::Exit(int32) + IL_00e7: pop + IL_00e8: ret + } + +} + + + + + + +.s IL_00e3 + + IL_00df: ldc.i4.0 + IL_00e0: nop + IL_00e1: br.s IL_00e5 + + IL_00e3: ldc.i4.1 + IL_00e4: nop + IL_00e5: call !!0 [FSharp.Core]Microsoft.FSharp.Core.Operators::Exit(int32) + IL_00ea: pop + IL_00eb: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.opt.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.opt.il.bsl index f4f037c9936..2e04d20b56f 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.opt.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.opt.il.bsl @@ -43,6 +43,45 @@ 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 clo@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class assembly/clo@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.FSharpFunc`2::.ctor() + IL_0006: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method private specialname rtspecialname static + void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void assembly/clo@1::.ctor() + IL_0005: stsfld class assembly/clo@1 assembly/clo@1::@_instance + IL_000a: ret + } + + } + .method public specialname static int32[] get_r() cil managed { @@ -188,77 +227,108 @@ IL_000e: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Create(int32, !!0) IL_0013: stsfld int32[] ''.$assembly::w@7 - IL_0018: ldc.i4.0 - IL_0019: ldc.i4.1 - IL_001a: call int32[] assembly::get_r() - IL_001f: ldlen - IL_0020: conv.i4 - IL_0021: stsfld int32 ''.$assembly::e1@1 - IL_0026: call int32[] assembly::get_w() - IL_002b: ldlen - IL_002c: conv.i4 - IL_002d: stsfld int32 ''.$assembly::e2@1 - IL_0032: call int32 assembly::get_e1@1() - IL_0037: call int32 assembly::get_e2@1() - IL_003c: bge.s IL_0046 - - IL_003e: call int32 assembly::get_e1@1() - IL_0043: nop - IL_0044: br.s IL_004c - - IL_0046: call int32 assembly::get_e2@1() - IL_004b: nop - IL_004c: ldc.i4.1 - IL_004d: sub - IL_004e: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, - int32, - int32) - IL_0053: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0058: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::ToList(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_005d: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::current@9 - IL_0062: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_current@9() - IL_0067: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() - IL_006c: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::next@9 - IL_0071: br.s IL_00b9 - - IL_0073: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_current@9() - IL_0078: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() - IL_007d: stloc.0 - IL_007e: call int32[] assembly::get_r() - IL_0083: ldloc.0 - IL_0084: call int32[] assembly::get_r() - IL_0089: ldloc.0 - IL_008a: ldelem [runtime]System.Int32 - IL_008f: call int32[] assembly::get_w() - IL_0094: ldloc.0 - IL_0095: ldelem [runtime]System.Int32 - IL_009a: add - IL_009b: stelem [runtime]System.Int32 - IL_00a0: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_next@9() - IL_00a5: call void assembly::set_current@9(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_00aa: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_current@9() - IL_00af: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() - IL_00b4: call void assembly::set_next@9(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_00b9: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_next@9() - IL_00be: brtrue.s IL_0073 - - IL_00c0: nop - IL_00c1: nop - IL_00c2: call int32[] assembly::get_r() - IL_00c7: ldc.i4.0 - IL_00c8: ldelem [runtime]System.Int32 - IL_00cd: ldc.i4.3 - IL_00ce: bne.un.s IL_00d4 - - IL_00d0: ldc.i4.0 - IL_00d1: nop - IL_00d2: br.s IL_00d6 - - IL_00d4: ldc.i4.1 - IL_00d5: nop - IL_00d6: call !!0 [FSharp.Core]Microsoft.FSharp.Core.Operators::Exit(int32) - IL_00db: pop - IL_00dc: ret + IL_0018: call int32[] assembly::get_r() + IL_001d: ldlen + IL_001e: conv.i4 + IL_001f: stsfld int32 ''.$assembly::e1@1 + IL_0024: call int32[] assembly::get_w() + IL_0029: ldlen + IL_002a: conv.i4 + IL_002b: stsfld int32 ''.$assembly::e2@1 + IL_0030: call int32 assembly::get_e1@1() + IL_0035: call int32 assembly::get_e2@1() + IL_003a: bge.s IL_0044 + + IL_003c: call int32 assembly::get_e1@1() + IL_0041: nop + IL_0042: br.s IL_004a + + IL_0044: call int32 assembly::get_e2@1() + IL_0049: nop + IL_004a: ldc.i4.1 + IL_004b: sub + IL_004c: stloc.0 + IL_004d: ldloc.0 + IL_004e: ldc.i4.0 + IL_004f: bge.s IL_0059 + + IL_0051: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_0056: nop + IL_0057: br.s IL_0069 + + IL_0059: ldloc.0 + IL_005a: ldc.i4.0 + IL_005b: sub + IL_005c: ldc.i4.1 + IL_005d: add + IL_005e: ldsfld class assembly/clo@1 assembly/clo@1::@_instance + IL_0063: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0068: nop + IL_0069: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::current@9 + IL_006e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_current@9() + IL_0073: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0078: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::next@9 + IL_007d: br.s IL_00c5 + + IL_007f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_current@9() + IL_0084: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0089: stloc.0 + IL_008a: call int32[] assembly::get_r() + IL_008f: ldloc.0 + IL_0090: call int32[] assembly::get_r() + IL_0095: ldloc.0 + IL_0096: ldelem [runtime]System.Int32 + IL_009b: call int32[] assembly::get_w() + IL_00a0: ldloc.0 + IL_00a1: ldelem [runtime]System.Int32 + IL_00a6: add + IL_00a7: stelem [runtime]System.Int32 + IL_00ac: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_next@9() + IL_00b1: call void assembly::set_current@9(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_00b6: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_current@9() + IL_00bb: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_00c0: call void assembly::set_next@9(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_00c5: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_next@9() + IL_00ca: brtrue.s IL_007f + + IL_00cc: nop + IL_00cd: nop + IL_00ce: call int32[] assembly::get_r() + IL_00d3: ldc.i4.0 + IL_00d4: ldelem [runtime]System.Int32 + IL_00d9: ldc.i4.3 + IL_00da: bne.un.s IL_00e0 + + IL_00dc: ldc.i4.0 + IL_00dd: nop + IL_00de: br.s IL_00e2 + + IL_00e0: ldc.i4.1 + IL_00e1: nop + IL_00e2: call !!0 [FSharp.Core]Microsoft.FSharp.Core.Operators::Exit(int32) + IL_00e7: pop + IL_00e8: ret + } + +} + + + + + + +.s IL_00e3 + + IL_00df: ldc.i4.0 + IL_00e0: nop + IL_00e1: br.s IL_00e5 + + IL_00e3: ldc.i4.1 + IL_00e4: nop + IL_00e5: call !!0 [FSharp.Core]Microsoft.FSharp.Core.Operators::Exit(int32) + IL_00ea: pop + IL_00eb: ret } } From 09511a72be05424da4c29ad464ae116bd9e92a3f Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Sat, 27 Jan 2024 14:18:25 -0500 Subject: [PATCH 17/25] Nest for clarity --- .../Optimize/LowerComputedCollections.fs | 188 +++++++++--------- 1 file changed, 97 insertions(+), 91 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 627cc699526..687e1fc0a97 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -257,7 +257,7 @@ let (|SeqToArray|_|) g expr = /// start..finish [] -let (|Int32Range|_|) g (expr, _ty) = +let (|Int32Range|_|) g expr = match expr with | ValApp g g.range_int32_op_vref ([], [start; Expr.Const (value = Const.Int32 1); finish], _) -> ValueSome (start, finish) | _ -> ValueNone @@ -301,99 +301,105 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = (mkCallArrayInit g Text.Range.range0 g.int32_ty (mkCount start finish) (mkInitializer start)) match overallExpr with - // [5..1] → [] - | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (Expr.Const (value = Const.Int32 start), Expr.Const (value = Const.Int32 finish)))), m) when - start > finish - -> - Some (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m)) - - // [start..finish] → if finish < start then [] else List.init (finish - start + 1) ((+) start) - | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start & (Expr.Const _ | Expr.Val _), finish & (Expr.Const _ | Expr.Val _)))), m) -> - Some (mkListInit m start finish) - - // [start..finishExpr] → - // let finish = finishExpr - // if finish < start then [] else List.init (finish - start + 1) ((+) start) - | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start & (Expr.Const _ | Expr.Val _), finish))), m) -> - let expr = - mkCompGenLetIn Text.Range.range0 (nameof finish) g.int32_ty finish (fun (_, finish) -> - mkListInit m start finish) - - Some expr - - // [startExpr..finish] → - // let start = startExpr - // if finish < start then [] else List.init (finish - start + 1) ((+) start) - | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish & (Expr.Const _ | Expr.Val _)))), m) -> - let expr = - mkCompGenLetIn Text.Range.range0 (nameof start) g.int32_ty start (fun (_, start) -> - mkListInit m start finish) - - Some expr - - // [startExpr..finishExpr] → - // let start = startExpr - // let finish = finishExpr - // if finish < start then [] else List.init (finish - start + 1) ((+) start) - | SeqToList g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> - let expr = - mkCompGenLetIn Text.Range.range0 (nameof start) g.int32_ty start (fun (_, start) -> - mkCompGenLetIn Text.Range.range0 (nameof finish) g.int32_ty finish (fun (_, finish) -> - mkListInit m start finish)) - - Some expr - - // [(* Anything more complex. *)] + // […] | SeqToList g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> - let collectorTy = g.mk_ListCollector_ty overallElemTy - LowerComputedListOrArraySeqExpr tcVal g amap m collectorTy overallSeqExpr - - // [|5..1|] → [||] - | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (Expr.Const (value = Const.Int32 start), Expr.Const (value = Const.Int32 finish)))), m) when - start > finish - -> - Some (mkArray (g.int32_ty, [], m)) - - // [|start..finish|] → if finish < start then [||] else Array.init (finish - start + 1) ((+) start) - | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start & (Expr.Const _ | Expr.Val _), finish & (Expr.Const _ | Expr.Val _)))), m) -> - Some (mkArrayInit m start finish) - - // [|start..finishExpr|] → - // let finish = finishExpr - // if finish < start then [||] else Array.init (finish - start + 1) ((+) start) - | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start & (Expr.Const _ | Expr.Val _), finish))), m) -> - let expr = - mkCompGenLetIn Text.Range.range0 (nameof finish) g.int32_ty finish (fun (_, finish) -> - mkArrayInit m start finish) - - Some expr - - // [|startExpr..finish|] → - // let start = startExpr - // if finish < start then [||] else Array.init (finish - start + 1) ((+) start) - | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish & (Expr.Const _ | Expr.Val _)))), m) -> - let expr = - mkCompGenLetIn Text.Range.range0 (nameof start) g.int32_ty start (fun (_, start) -> - mkArrayInit m start finish) - - Some expr - - // [|startExpr..finishExpr|] → - // let start = startExpr - // let finish = finishExpr - // if finish < start then [||] else Array.init (finish - start + 1) ((+) start) - | SeqToArray g (OptionalCoerce (OptionalSeq g amap (Int32Range g (start, finish))), m) -> - let expr = - mkCompGenLetIn Text.Range.range0 (nameof start) g.int32_ty start (fun (_, start) -> + match overallSeqExpr with + // [5..1] → [] + | Int32Range g (Expr.Const (value = Const.Int32 start), Expr.Const (value = Const.Int32 finish)) when + start > finish + -> + Some (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m)) + + // [start..finish] → if finish < start then [] else List.init (finish - start + 1) ((+) start) + | Int32Range g (start & (Expr.Const _ | Expr.Val _), finish & (Expr.Const _ | Expr.Val _)) -> + Some (mkListInit m start finish) + + // [start..finishExpr] → + // let finish = finishExpr + // if finish < start then [] else List.init (finish - start + 1) ((+) start) + | Int32Range g (start & (Expr.Const _ | Expr.Val _), finish) -> + let expr = mkCompGenLetIn Text.Range.range0 (nameof finish) g.int32_ty finish (fun (_, finish) -> - mkArrayInit m start finish)) - - Some expr - - // [|(* Anything more complex. *)|] + mkListInit m start finish) + + Some expr + + // [startExpr..finish] → + // let start = startExpr + // if finish < start then [] else List.init (finish - start + 1) ((+) start) + | Int32Range g (start, finish & (Expr.Const _ | Expr.Val _)) -> + let expr = + mkCompGenLetIn Text.Range.range0 (nameof start) g.int32_ty start (fun (_, start) -> + mkListInit m start finish) + + Some expr + + // [startExpr..finishExpr] → + // let start = startExpr + // let finish = finishExpr + // if finish < start then [] else List.init (finish - start + 1) ((+) start) + | Int32Range g (start, finish) -> + let expr = + mkCompGenLetIn Text.Range.range0 (nameof start) g.int32_ty start (fun (_, start) -> + mkCompGenLetIn Text.Range.range0 (nameof finish) g.int32_ty finish (fun (_, finish) -> + mkListInit m start finish)) + + Some expr + + // [(* Anything more complex. *)] + | _ -> + let collectorTy = g.mk_ListCollector_ty overallElemTy + LowerComputedListOrArraySeqExpr tcVal g amap m collectorTy overallSeqExpr + + // [|…|] | SeqToArray g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> - let collectorTy = g.mk_ArrayCollector_ty overallElemTy - LowerComputedListOrArraySeqExpr tcVal g amap m collectorTy overallSeqExpr + match overallSeqExpr with + // [|5..1|] → [||] + | Int32Range g (Expr.Const (value = Const.Int32 start), Expr.Const (value = Const.Int32 finish)) when + start > finish + -> + Some (mkArray (g.int32_ty, [], m)) + + // [|start..finish|] → if finish < start then [||] else Array.init (finish - start + 1) ((+) start) + | Int32Range g (start & (Expr.Const _ | Expr.Val _), finish & (Expr.Const _ | Expr.Val _)) -> + Some (mkArrayInit m start finish) + + // [|start..finishExpr|] → + // let finish = finishExpr + // if finish < start then [||] else Array.init (finish - start + 1) ((+) start) + | Int32Range g (start & (Expr.Const _ | Expr.Val _), finish) -> + let expr = + mkCompGenLetIn Text.Range.range0 (nameof finish) g.int32_ty finish (fun (_, finish) -> + mkArrayInit m start finish) + + Some expr + + // [|startExpr..finish|] → + // let start = startExpr + // if finish < start then [||] else Array.init (finish - start + 1) ((+) start) + | Int32Range g (start, finish & (Expr.Const _ | Expr.Val _)) -> + let expr = + mkCompGenLetIn Text.Range.range0 (nameof start) g.int32_ty start (fun (_, start) -> + mkArrayInit m start finish) + + Some expr + + // [|startExpr..finishExpr|] → + // let start = startExpr + // let finish = finishExpr + // if finish < start then [||] else Array.init (finish - start + 1) ((+) start) + | Int32Range g (start, finish) -> + let expr = + mkCompGenLetIn Text.Range.range0 (nameof start) g.int32_ty start (fun (_, start) -> + mkCompGenLetIn Text.Range.range0 (nameof finish) g.int32_ty finish (fun (_, finish) -> + mkArrayInit m start finish)) + + Some expr + + // [|(* Anything more complex. *)|] + | _ -> + let collectorTy = g.mk_ArrayCollector_ty overallElemTy + LowerComputedListOrArraySeqExpr tcVal g amap m collectorTy overallSeqExpr | _ -> None else From e2f2ef6d2ab75373406cdb080850b4acda72d37c Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Sat, 27 Jan 2024 14:26:32 -0500 Subject: [PATCH 18/25] Be consistent --- src/Compiler/Optimize/LowerComputedCollections.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 687e1fc0a97..4221db2792a 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -306,7 +306,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = match overallSeqExpr with // [5..1] → [] | Int32Range g (Expr.Const (value = Const.Int32 start), Expr.Const (value = Const.Int32 finish)) when - start > finish + finish < start -> Some (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m)) @@ -356,7 +356,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = match overallSeqExpr with // [|5..1|] → [||] | Int32Range g (Expr.Const (value = Const.Int32 start), Expr.Const (value = Const.Int32 finish)) when - start > finish + finish < start -> Some (mkArray (g.int32_ty, [], m)) From 2437e937e534d94001a7b88d5a890177de638e45 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Sat, 27 Jan 2024 14:32:54 -0500 Subject: [PATCH 19/25] Extra space --- src/Compiler/Optimize/LowerComputedCollections.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 4221db2792a..f736f929d54 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -280,7 +280,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = /// Make an expression that initializes a list /// with the values from start through finish. - let mkListInit m start finish = + let mkListInit m start finish = mkCond DebugPointAtBinding.NoneAtInvisible m From b0aa9023d9572f44ac15eb463f9e1d7be06a54cf Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Sat, 27 Jan 2024 14:42:42 -0500 Subject: [PATCH 20/25] Update baselines --- .../GenericComparison/Compare09.fsx.il.bsl | 138 +++++++++--------- .../GenericComparison/Equals08.fsx.il.bsl | 138 +++++++++--------- .../GenericComparison/Hash11.fsx.il.bsl | 90 +++++------- 3 files changed, 170 insertions(+), 196 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl index 5967e6f0bd2..2fbc10167f2 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl @@ -128,70 +128,80 @@ .method public static int32 f8() cil managed { - .maxstack 4 + .maxstack 6 .locals init (int32 V_0, int32[] V_1, int32[] V_2, int32 V_3) IL_0000: ldc.i4.1 IL_0001: stloc.0 - IL_0002: nop - IL_0003: ldc.i4.s 100 - IL_0005: ldc.i4.0 - IL_0006: bge.s IL_0010 - - IL_0008: call !!0[] [runtime]System.Array::Empty() - IL_000d: nop - IL_000e: br.s IL_0021 - - IL_0010: ldc.i4.s 100 - IL_0012: ldc.i4.0 - IL_0013: sub - IL_0014: ldc.i4.1 - IL_0015: add - IL_0016: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t1@1 assembly/CompareMicroPerfAndCodeGenerationTests/t1@1::@_instance - IL_001b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0002: ldc.i4.s 100 + IL_0004: ldc.i4.0 + IL_0005: sub + IL_0006: ldc.i4.1 + IL_0007: add + IL_0008: ldc.i4.s 100 + IL_000a: ldc.i4.0 + IL_000b: sub + IL_000c: ldc.i4.1 + IL_000d: add + IL_000e: ldc.i4.s 100 + IL_0010: ldc.i4.0 + IL_0011: sub + IL_0012: ldc.i4.1 + IL_0013: add + IL_0014: ldc.i4.0 + IL_0015: clt + IL_0017: neg + IL_0018: and + IL_0019: xor + IL_001a: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t1@1 assembly/CompareMicroPerfAndCodeGenerationTests/t1@1::@_instance + IL_001f: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0020: nop - IL_0021: stloc.1 - IL_0022: nop - IL_0023: ldc.i4.s 100 - IL_0025: ldc.i4.0 - IL_0026: bge.s IL_0030 - - IL_0028: call !!0[] [runtime]System.Array::Empty() - IL_002d: nop - IL_002e: br.s IL_0041 - - IL_0030: ldc.i4.s 100 - IL_0032: ldc.i4.0 - IL_0033: sub - IL_0034: ldc.i4.1 - IL_0035: add - IL_0036: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t2@1 assembly/CompareMicroPerfAndCodeGenerationTests/t2@1::@_instance - IL_003b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0024: stloc.1 + IL_0025: ldc.i4.s 100 + IL_0027: ldc.i4.0 + IL_0028: sub + IL_0029: ldc.i4.1 + IL_002a: add + IL_002b: ldc.i4.s 100 + IL_002d: ldc.i4.0 + IL_002e: sub + IL_002f: ldc.i4.1 + IL_0030: add + IL_0031: ldc.i4.s 100 + IL_0033: ldc.i4.0 + IL_0034: sub + IL_0035: ldc.i4.1 + IL_0036: add + IL_0037: ldc.i4.0 + IL_0038: clt + IL_003a: neg + IL_003b: and + IL_003c: xor + IL_003d: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t2@1 assembly/CompareMicroPerfAndCodeGenerationTests/t2@1::@_instance + IL_0042: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0040: nop - IL_0041: stloc.2 - IL_0042: ldc.i4.0 - IL_0043: stloc.3 - IL_0044: br.s IL_0052 - - IL_0046: ldloc.1 - IL_0047: ldloc.2 - IL_0048: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonIntrinsic(!!0, + IL_0047: stloc.2 + IL_0048: ldc.i4.0 + IL_0049: stloc.3 + IL_004a: br.s IL_0058 + + IL_004c: ldloc.1 + IL_004d: ldloc.2 + IL_004e: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonIntrinsic(!!0, !!0) - IL_004d: stloc.0 - IL_004e: ldloc.3 - IL_004f: ldc.i4.1 - IL_0050: add - IL_0051: stloc.3 - IL_0052: ldloc.3 - IL_0053: ldc.i4 0x186a1 - IL_0058: blt.s IL_0046 - - IL_005a: ldloc.0 - IL_005b: ret + IL_0053: stloc.0 + IL_0054: ldloc.3 + IL_0055: ldc.i4.1 + IL_0056: add + IL_0057: stloc.3 + IL_0058: ldloc.3 + IL_0059: ldc.i4 0x186a1 + IL_005e: blt.s IL_004c + + IL_0060: ldloc.0 + IL_0061: ret } } @@ -216,21 +226,3 @@ -sx - extends [runtime]System.Object -{ - .method public static void main@() cil managed - { - .entrypoint - - .maxstack 8 - IL_0000: ret - } - -} - - - - - - diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl index e2c42a7030c..da0c4d0720b 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl @@ -128,70 +128,80 @@ .method public static bool f8() cil managed { - .maxstack 4 + .maxstack 6 .locals init (bool V_0, int32[] V_1, int32[] V_2, int32 V_3) IL_0000: ldc.i4.0 IL_0001: stloc.0 - IL_0002: nop - IL_0003: ldc.i4.s 100 - IL_0005: ldc.i4.0 - IL_0006: bge.s IL_0010 - - IL_0008: call !!0[] [runtime]System.Array::Empty() - IL_000d: nop - IL_000e: br.s IL_0021 - - IL_0010: ldc.i4.s 100 - IL_0012: ldc.i4.0 - IL_0013: sub - IL_0014: ldc.i4.1 - IL_0015: add - IL_0016: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1::@_instance - IL_001b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0002: ldc.i4.s 100 + IL_0004: ldc.i4.0 + IL_0005: sub + IL_0006: ldc.i4.1 + IL_0007: add + IL_0008: ldc.i4.s 100 + IL_000a: ldc.i4.0 + IL_000b: sub + IL_000c: ldc.i4.1 + IL_000d: add + IL_000e: ldc.i4.s 100 + IL_0010: ldc.i4.0 + IL_0011: sub + IL_0012: ldc.i4.1 + IL_0013: add + IL_0014: ldc.i4.0 + IL_0015: clt + IL_0017: neg + IL_0018: and + IL_0019: xor + IL_001a: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1::@_instance + IL_001f: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0020: nop - IL_0021: stloc.1 - IL_0022: nop - IL_0023: ldc.i4.s 100 - IL_0025: ldc.i4.0 - IL_0026: bge.s IL_0030 - - IL_0028: call !!0[] [runtime]System.Array::Empty() - IL_002d: nop - IL_002e: br.s IL_0041 - - IL_0030: ldc.i4.s 100 - IL_0032: ldc.i4.0 - IL_0033: sub - IL_0034: ldc.i4.1 - IL_0035: add - IL_0036: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1::@_instance - IL_003b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0024: stloc.1 + IL_0025: ldc.i4.s 100 + IL_0027: ldc.i4.0 + IL_0028: sub + IL_0029: ldc.i4.1 + IL_002a: add + IL_002b: ldc.i4.s 100 + IL_002d: ldc.i4.0 + IL_002e: sub + IL_002f: ldc.i4.1 + IL_0030: add + IL_0031: ldc.i4.s 100 + IL_0033: ldc.i4.0 + IL_0034: sub + IL_0035: ldc.i4.1 + IL_0036: add + IL_0037: ldc.i4.0 + IL_0038: clt + IL_003a: neg + IL_003b: and + IL_003c: xor + IL_003d: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1::@_instance + IL_0042: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0040: nop - IL_0041: stloc.2 - IL_0042: ldc.i4.0 - IL_0043: stloc.3 - IL_0044: br.s IL_0052 - - IL_0046: ldloc.1 - IL_0047: ldloc.2 - IL_0048: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityIntrinsic(!!0, + IL_0047: stloc.2 + IL_0048: ldc.i4.0 + IL_0049: stloc.3 + IL_004a: br.s IL_0058 + + IL_004c: ldloc.1 + IL_004d: ldloc.2 + IL_004e: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityIntrinsic(!!0, !!0) - IL_004d: stloc.0 - IL_004e: ldloc.3 - IL_004f: ldc.i4.1 - IL_0050: add - IL_0051: stloc.3 - IL_0052: ldloc.3 - IL_0053: ldc.i4 0x989681 - IL_0058: blt.s IL_0046 - - IL_005a: ldloc.0 - IL_005b: ret + IL_0053: stloc.0 + IL_0054: ldloc.3 + IL_0055: ldc.i4.1 + IL_0056: add + IL_0057: stloc.3 + IL_0058: ldloc.3 + IL_0059: ldc.i4 0x989681 + IL_005e: blt.s IL_004c + + IL_0060: ldloc.0 + IL_0061: ret } } @@ -216,21 +226,3 @@ -sx - extends [runtime]System.Object -{ - .method public static void main@() cil managed - { - .entrypoint - - .maxstack 8 - IL_0000: ret - } - -} - - - - - - diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl index a66db1e8314..263d53923d2 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl @@ -89,46 +89,51 @@ .method public static void f8() cil managed { - .maxstack 4 + .maxstack 6 .locals init (int32[] V_0, int32 V_1, int32 V_2) IL_0000: nop - IL_0001: nop - IL_0002: ldc.i4.s 100 - IL_0004: ldc.i4.0 - IL_0005: bge.s IL_000f - - IL_0007: call !!0[] [runtime]System.Array::Empty() - IL_000c: nop - IL_000d: br.s IL_0020 - - IL_000f: ldc.i4.s 100 - IL_0011: ldc.i4.0 - IL_0012: sub - IL_0013: ldc.i4.1 - IL_0014: add - IL_0015: ldsfld class assembly/HashMicroPerfAndCodeGenerationTests/arr@1 assembly/HashMicroPerfAndCodeGenerationTests/arr@1::@_instance - IL_001a: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0001: ldc.i4.s 100 + IL_0003: ldc.i4.0 + IL_0004: sub + IL_0005: ldc.i4.1 + IL_0006: add + IL_0007: ldc.i4.s 100 + IL_0009: ldc.i4.0 + IL_000a: sub + IL_000b: ldc.i4.1 + IL_000c: add + IL_000d: ldc.i4.s 100 + IL_000f: ldc.i4.0 + IL_0010: sub + IL_0011: ldc.i4.1 + IL_0012: add + IL_0013: ldc.i4.0 + IL_0014: clt + IL_0016: neg + IL_0017: and + IL_0018: xor + IL_0019: ldsfld class assembly/HashMicroPerfAndCodeGenerationTests/arr@1 assembly/HashMicroPerfAndCodeGenerationTests/arr@1::@_instance + IL_001e: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_001f: nop - IL_0020: stloc.0 - IL_0021: ldc.i4.0 - IL_0022: stloc.1 - IL_0023: br.s IL_0030 - - IL_0025: ldloc.0 - IL_0026: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericHashIntrinsic(!!0) - IL_002b: stloc.2 - IL_002c: ldloc.1 - IL_002d: ldc.i4.1 - IL_002e: add - IL_002f: stloc.1 - IL_0030: ldloc.1 - IL_0031: ldc.i4 0x989681 - IL_0036: blt.s IL_0025 - - IL_0038: ret + IL_0023: stloc.0 + IL_0024: ldc.i4.0 + IL_0025: stloc.1 + IL_0026: br.s IL_0033 + + IL_0028: ldloc.0 + IL_0029: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericHashIntrinsic(!!0) + IL_002e: stloc.2 + IL_002f: ldloc.1 + IL_0030: ldc.i4.1 + IL_0031: add + IL_0032: stloc.1 + IL_0033: ldloc.1 + IL_0034: ldc.i4 0x989681 + IL_0039: blt.s IL_0028 + + IL_003b: ret } } @@ -153,18 +158,3 @@ -ed - { - .entrypoint - - .maxstack 8 - IL_0000: ret - } - -} - - - - - - From 1165eafd46565a5cb21b93b9d0f3013a9b5e057b Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Sat, 27 Jan 2024 15:50:09 -0500 Subject: [PATCH 21/25] Might as well do that at compile time --- src/Compiler/Optimize/LowerComputedCollections.fs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index f736f929d54..0d3fb3d70a7 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -310,6 +310,11 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = -> Some (mkUnionCaseExpr (g.nil_ucref, [g.int32_ty], [], m)) + // [1..5] → List.init 5 ((+) 5) + | Int32Range g (start & Expr.Const (value = Const.Int32 startVal), Expr.Const (value = Const.Int32 finishVal)) + -> + Some (mkCallListInit g Text.Range.range0 g.int32_ty (Expr.Const (Const.Int32 (finishVal - startVal + 1), Text.Range.range0, g.int32_ty)) (mkInitializer start)) + // [start..finish] → if finish < start then [] else List.init (finish - start + 1) ((+) start) | Int32Range g (start & (Expr.Const _ | Expr.Val _), finish & (Expr.Const _ | Expr.Val _)) -> Some (mkListInit m start finish) @@ -360,6 +365,11 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap overallExpr = -> Some (mkArray (g.int32_ty, [], m)) + // [|1..5|] → Array.init 5 ((+) 5) + | Int32Range g (start & Expr.Const (value = Const.Int32 startVal), Expr.Const (value = Const.Int32 finishVal)) + -> + Some (mkCallArrayInit g Text.Range.range0 g.int32_ty (Expr.Const (Const.Int32 (finishVal - startVal + 1), Text.Range.range0, g.int32_ty)) (mkInitializer start)) + // [|start..finish|] → if finish < start then [||] else Array.init (finish - start + 1) ((+) start) | Int32Range g (start & (Expr.Const _ | Expr.Val _), finish & (Expr.Const _ | Expr.Val _)) -> Some (mkArrayInit m start finish) From 4b67e5d8cad1ba2082c95ffdcec97b67c6a0ccc7 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Sat, 27 Jan 2024 15:50:17 -0500 Subject: [PATCH 22/25] Update baselines --- .../ComputationExpr07.fs.il.bsl | 89 ++-- ...onTrivialBranchingBindingInEnd03.fs.il.bsl | 20 - ...ivialBranchingBindingInEnd03.fs.opt.il.bsl | 20 - .../GenericComparison/Compare09.fsx.il.bsl | 156 +++--- .../GenericComparison/Equals08.fsx.il.bsl | 156 +++--- .../GenericComparison/Hash11.fsx.il.bsl | 100 ++-- .../ListExpressionStepping02.fs.il.bsl | 261 +++++----- .../Misc/CodeGenRenamings01.fs.il.bsl | 451 +++++++++--------- .../EmittedIL/Misc/ForLoop01.fs.il.bsl | 105 ++-- 9 files changed, 738 insertions(+), 620 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpr07.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpr07.fs.il.bsl index ab79b7b9b37..b26e7f6a528 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpr07.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpr07.fs.il.bsl @@ -67,11 +67,14 @@ Invoke(int32 i) cil managed { - .maxstack 8 + .maxstack 6 + .locals init (int32 V_0) IL_0000: ldc.i4.0 - IL_0001: ldarg.1 - IL_0002: add - IL_0003: ret + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldarg.1 + IL_0004: add + IL_0005: ret } .method private specialname rtspecialname static @@ -209,7 +212,11 @@ { .maxstack 9 - .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 V_0) + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 V_0, + int32 V_1, + int32 V_2, + int32 V_3, + int32 V_4) IL_0000: ldc.i4.1 IL_0001: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::.ctor(!0) IL_0006: stloc.0 @@ -218,41 +225,49 @@ IL_000d: ldarg.0 IL_000e: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ IL_0013: ldc.i4.3 - IL_0014: ldc.i4.0 - IL_0015: bge.s IL_001f - - IL_0017: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_001c: nop - IL_001d: br.s IL_002f - - IL_001f: ldc.i4.3 - IL_0020: ldc.i4.0 - IL_0021: sub - IL_0022: ldc.i4.1 - IL_0023: add - IL_0024: ldsfld class Program/'res7@1-1' Program/'res7@1-1'::@_instance - IL_0029: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_0014: stloc.1 + IL_0015: ldloc.1 + IL_0016: ldc.i4.0 + IL_0017: stloc.2 + IL_0018: ldloc.2 + IL_0019: bge.s IL_0023 + + IL_001b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_0020: nop + IL_0021: br.s IL_0039 + + IL_0023: ldc.i4.3 + IL_0024: stloc.3 + IL_0025: ldloc.3 + IL_0026: ldc.i4.0 + IL_0027: stloc.s V_4 + IL_0029: ldloc.s V_4 + IL_002b: sub + IL_002c: ldc.i4.1 + IL_002d: add + IL_002e: ldsfld class Program/'res7@1-1' Program/'res7@1-1'::@_instance + IL_0033: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_002e: nop - IL_002f: ldarg.0 - IL_0030: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ - IL_0035: ldloc.0 - IL_0036: newobj instance void Program/'res7@10-2'::.ctor(class [ComputationExprLibrary]Library.EventuallyBuilder, + IL_0038: nop + IL_0039: ldarg.0 + IL_003a: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ + IL_003f: ldloc.0 + IL_0040: newobj instance void Program/'res7@10-2'::.ctor(class [ComputationExprLibrary]Library.EventuallyBuilder, class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1) - IL_003b: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::For(class [runtime]System.Collections.Generic.IEnumerable`1, + IL_0045: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::For(class [runtime]System.Collections.Generic.IEnumerable`1, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) - IL_0040: ldarg.0 - IL_0041: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ - IL_0046: ldarg.0 - IL_0047: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ - IL_004c: ldloc.0 - IL_004d: newobj instance void Program/'res7@12-3'::.ctor(class [ComputationExprLibrary]Library.EventuallyBuilder, + IL_004a: ldarg.0 + IL_004b: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ + IL_0050: ldarg.0 + IL_0051: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ + IL_0056: ldloc.0 + IL_0057: newobj instance void Program/'res7@12-3'::.ctor(class [ComputationExprLibrary]Library.EventuallyBuilder, class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1) - IL_0052: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Delay(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) - IL_0057: tail. - IL_0059: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Combine(class [ComputationExprLibrary]Library.Eventually`1, + IL_005c: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Delay(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0061: tail. + IL_0063: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Combine(class [ComputationExprLibrary]Library.Eventually`1, class [ComputationExprLibrary]Library.Eventually`1) - IL_005e: ret + IL_0068: ret } } @@ -319,7 +334,3 @@ - - - - diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.il.bsl index 2e04d20b56f..501642202d8 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.il.bsl @@ -318,23 +318,3 @@ -.s IL_00e3 - - IL_00df: ldc.i4.0 - IL_00e0: nop - IL_00e1: br.s IL_00e5 - - IL_00e3: ldc.i4.1 - IL_00e4: nop - IL_00e5: call !!0 [FSharp.Core]Microsoft.FSharp.Core.Operators::Exit(int32) - IL_00ea: pop - IL_00eb: ret - } - -} - - - - - - diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.opt.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.opt.il.bsl index 2e04d20b56f..501642202d8 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.opt.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ForLoop/NonTrivialBranchingBindingInEnd03.fs.opt.il.bsl @@ -318,23 +318,3 @@ -.s IL_00e3 - - IL_00df: ldc.i4.0 - IL_00e0: nop - IL_00e1: br.s IL_00e5 - - IL_00e3: ldc.i4.1 - IL_00e4: nop - IL_00e5: call !!0 [FSharp.Core]Microsoft.FSharp.Core.Operators::Exit(int32) - IL_00ea: pop - IL_00eb: ret - } - -} - - - - - - diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl index 2fbc10167f2..3b759cafd16 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl @@ -128,80 +128,106 @@ .method public static int32 f8() cil managed { - .maxstack 6 + .maxstack 4 .locals init (int32 V_0, int32[] V_1, int32[] V_2, int32 V_3) IL_0000: ldc.i4.1 IL_0001: stloc.0 - IL_0002: ldc.i4.s 100 - IL_0004: ldc.i4.0 - IL_0005: sub - IL_0006: ldc.i4.1 - IL_0007: add - IL_0008: ldc.i4.s 100 - IL_000a: ldc.i4.0 - IL_000b: sub - IL_000c: ldc.i4.1 - IL_000d: add - IL_000e: ldc.i4.s 100 - IL_0010: ldc.i4.0 - IL_0011: sub - IL_0012: ldc.i4.1 - IL_0013: add - IL_0014: ldc.i4.0 - IL_0015: clt - IL_0017: neg - IL_0018: and - IL_0019: xor - IL_001a: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t1@1 assembly/CompareMicroPerfAndCodeGenerationTests/t1@1::@_instance - IL_001f: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0002: nop + IL_0003: ldc.i4.s 100 + IL_0005: ldc.i4.0 + IL_0006: bge.s IL_0010 + + IL_0008: call !!0[] [runtime]System.Array::Empty() + IL_000d: nop + IL_000e: br.s IL_0021 + + IL_0010: ldc.i4.s 100 + IL_0012: ldc.i4.0 + IL_0013: sub + IL_0014: ldc.i4.1 + IL_0015: add + IL_0016: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t1@1 assembly/CompareMicroPerfAndCodeGenerationTests/t1@1::@_instance + IL_001b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0024: stloc.1 - IL_0025: ldc.i4.s 100 - IL_0027: ldc.i4.0 - IL_0028: sub - IL_0029: ldc.i4.1 - IL_002a: add - IL_002b: ldc.i4.s 100 - IL_002d: ldc.i4.0 - IL_002e: sub - IL_002f: ldc.i4.1 - IL_0030: add - IL_0031: ldc.i4.s 100 - IL_0033: ldc.i4.0 - IL_0034: sub - IL_0035: ldc.i4.1 - IL_0036: add - IL_0037: ldc.i4.0 - IL_0038: clt - IL_003a: neg - IL_003b: and - IL_003c: xor - IL_003d: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t2@1 assembly/CompareMicroPerfAndCodeGenerationTests/t2@1::@_instance - IL_0042: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0020: nop + IL_0021: stloc.1 + IL_0022: nop + IL_0023: ldc.i4.s 100 + IL_0025: ldc.i4.0 + IL_0026: bge.s IL_0030 + + IL_0028: call !!0[] [runtime]System.Array::Empty() + IL_002d: nop + IL_002e: br.s IL_0041 + + IL_0030: ldc.i4.s 100 + IL_0032: ldc.i4.0 + IL_0033: sub + IL_0034: ldc.i4.1 + IL_0035: add + IL_0036: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t2@1 assembly/CompareMicroPerfAndCodeGenerationTests/t2@1::@_instance + IL_003b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0047: stloc.2 - IL_0048: ldc.i4.0 - IL_0049: stloc.3 - IL_004a: br.s IL_0058 - - IL_004c: ldloc.1 - IL_004d: ldloc.2 - IL_004e: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonIntrinsic(!!0, + IL_0040: nop + IL_0041: stloc.2 + IL_0042: ldc.i4.0 + IL_0043: stloc.3 + IL_0044: br.s IL_0052 + + IL_0046: ldloc.1 + IL_0047: ldloc.2 + IL_0048: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonIntrinsic(!!0, !!0) - IL_0053: stloc.0 - IL_0054: ldloc.3 - IL_0055: ldc.i4.1 - IL_0056: add - IL_0057: stloc.3 - IL_0058: ldloc.3 - IL_0059: ldc.i4 0x186a1 - IL_005e: blt.s IL_004c - - IL_0060: ldloc.0 - IL_0061: ret + IL_004d: stloc.0 + IL_004e: ldloc.3 + IL_004f: ldc.i4.1 + IL_0050: add + IL_0051: stloc.3 + IL_0052: ldloc.3 + IL_0053: ldc.i4 0x186a1 + IL_0058: blt.s IL_0046 + + IL_005a: ldloc.0 + IL_005b: ret + } + + } + +} + +.class private abstract auto ansi sealed ''.$assembly$fsx + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + + !!0) + IL_005d: stloc.0 + IL_005e: ldloc.2 + IL_005f: ldc.i4.1 + IL_0060: add + IL_0061: stloc.2 + IL_0062: ldloc.2 + IL_0063: ldc.i4 0x186a1 + IL_0068: blt.s IL_0056 + + IL_006a: ldloc.0 + IL_006b: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl index da0c4d0720b..dac2aa32e2d 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl @@ -128,80 +128,106 @@ .method public static bool f8() cil managed { - .maxstack 6 + .maxstack 4 .locals init (bool V_0, int32[] V_1, int32[] V_2, int32 V_3) IL_0000: ldc.i4.0 IL_0001: stloc.0 - IL_0002: ldc.i4.s 100 - IL_0004: ldc.i4.0 - IL_0005: sub - IL_0006: ldc.i4.1 - IL_0007: add - IL_0008: ldc.i4.s 100 - IL_000a: ldc.i4.0 - IL_000b: sub - IL_000c: ldc.i4.1 - IL_000d: add - IL_000e: ldc.i4.s 100 - IL_0010: ldc.i4.0 - IL_0011: sub - IL_0012: ldc.i4.1 - IL_0013: add - IL_0014: ldc.i4.0 - IL_0015: clt - IL_0017: neg - IL_0018: and - IL_0019: xor - IL_001a: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1::@_instance - IL_001f: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0002: nop + IL_0003: ldc.i4.s 100 + IL_0005: ldc.i4.0 + IL_0006: bge.s IL_0010 + + IL_0008: call !!0[] [runtime]System.Array::Empty() + IL_000d: nop + IL_000e: br.s IL_0021 + + IL_0010: ldc.i4.s 100 + IL_0012: ldc.i4.0 + IL_0013: sub + IL_0014: ldc.i4.1 + IL_0015: add + IL_0016: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1::@_instance + IL_001b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0024: stloc.1 - IL_0025: ldc.i4.s 100 - IL_0027: ldc.i4.0 - IL_0028: sub - IL_0029: ldc.i4.1 - IL_002a: add - IL_002b: ldc.i4.s 100 - IL_002d: ldc.i4.0 - IL_002e: sub - IL_002f: ldc.i4.1 - IL_0030: add - IL_0031: ldc.i4.s 100 - IL_0033: ldc.i4.0 - IL_0034: sub - IL_0035: ldc.i4.1 - IL_0036: add - IL_0037: ldc.i4.0 - IL_0038: clt - IL_003a: neg - IL_003b: and - IL_003c: xor - IL_003d: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1::@_instance - IL_0042: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0020: nop + IL_0021: stloc.1 + IL_0022: nop + IL_0023: ldc.i4.s 100 + IL_0025: ldc.i4.0 + IL_0026: bge.s IL_0030 + + IL_0028: call !!0[] [runtime]System.Array::Empty() + IL_002d: nop + IL_002e: br.s IL_0041 + + IL_0030: ldc.i4.s 100 + IL_0032: ldc.i4.0 + IL_0033: sub + IL_0034: ldc.i4.1 + IL_0035: add + IL_0036: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1::@_instance + IL_003b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0047: stloc.2 - IL_0048: ldc.i4.0 - IL_0049: stloc.3 - IL_004a: br.s IL_0058 - - IL_004c: ldloc.1 - IL_004d: ldloc.2 - IL_004e: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityIntrinsic(!!0, + IL_0040: nop + IL_0041: stloc.2 + IL_0042: ldc.i4.0 + IL_0043: stloc.3 + IL_0044: br.s IL_0052 + + IL_0046: ldloc.1 + IL_0047: ldloc.2 + IL_0048: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityIntrinsic(!!0, !!0) - IL_0053: stloc.0 - IL_0054: ldloc.3 - IL_0055: ldc.i4.1 - IL_0056: add - IL_0057: stloc.3 - IL_0058: ldloc.3 - IL_0059: ldc.i4 0x989681 - IL_005e: blt.s IL_004c - - IL_0060: ldloc.0 - IL_0061: ret + IL_004d: stloc.0 + IL_004e: ldloc.3 + IL_004f: ldc.i4.1 + IL_0050: add + IL_0051: stloc.3 + IL_0052: ldloc.3 + IL_0053: ldc.i4 0x989681 + IL_0058: blt.s IL_0046 + + IL_005a: ldloc.0 + IL_005b: ret + } + + } + +} + +.class private abstract auto ansi sealed ''.$assembly$fsx + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + + !!0) + IL_005d: stloc.0 + IL_005e: ldloc.2 + IL_005f: ldc.i4.1 + IL_0060: add + IL_0061: stloc.2 + IL_0062: ldloc.2 + IL_0063: ldc.i4 0x989681 + IL_0068: blt.s IL_0056 + + IL_006a: ldloc.0 + IL_006b: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl index 263d53923d2..f5c1c3f2a07 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl @@ -89,51 +89,71 @@ .method public static void f8() cil managed { - .maxstack 6 + .maxstack 4 .locals init (int32[] V_0, int32 V_1, int32 V_2) IL_0000: nop - IL_0001: ldc.i4.s 100 - IL_0003: ldc.i4.0 - IL_0004: sub - IL_0005: ldc.i4.1 - IL_0006: add - IL_0007: ldc.i4.s 100 - IL_0009: ldc.i4.0 - IL_000a: sub - IL_000b: ldc.i4.1 - IL_000c: add - IL_000d: ldc.i4.s 100 - IL_000f: ldc.i4.0 - IL_0010: sub - IL_0011: ldc.i4.1 - IL_0012: add - IL_0013: ldc.i4.0 - IL_0014: clt - IL_0016: neg - IL_0017: and - IL_0018: xor - IL_0019: ldsfld class assembly/HashMicroPerfAndCodeGenerationTests/arr@1 assembly/HashMicroPerfAndCodeGenerationTests/arr@1::@_instance - IL_001e: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0001: nop + IL_0002: ldc.i4.s 100 + IL_0004: ldc.i4.0 + IL_0005: bge.s IL_000f + + IL_0007: call !!0[] [runtime]System.Array::Empty() + IL_000c: nop + IL_000d: br.s IL_0020 + + IL_000f: ldc.i4.s 100 + IL_0011: ldc.i4.0 + IL_0012: sub + IL_0013: ldc.i4.1 + IL_0014: add + IL_0015: ldsfld class assembly/HashMicroPerfAndCodeGenerationTests/arr@1 assembly/HashMicroPerfAndCodeGenerationTests/arr@1::@_instance + IL_001a: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0023: stloc.0 - IL_0024: ldc.i4.0 - IL_0025: stloc.1 - IL_0026: br.s IL_0033 - - IL_0028: ldloc.0 - IL_0029: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericHashIntrinsic(!!0) - IL_002e: stloc.2 - IL_002f: ldloc.1 - IL_0030: ldc.i4.1 - IL_0031: add - IL_0032: stloc.1 - IL_0033: ldloc.1 - IL_0034: ldc.i4 0x989681 - IL_0039: blt.s IL_0028 - - IL_003b: ret + IL_001f: nop + IL_0020: stloc.0 + IL_0021: ldc.i4.0 + IL_0022: stloc.1 + IL_0023: br.s IL_0030 + + IL_0025: ldloc.0 + IL_0026: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericHashIntrinsic(!!0) + IL_002b: stloc.2 + IL_002c: ldloc.1 + IL_002d: ldc.i4.1 + IL_002e: add + IL_002f: stloc.1 + IL_0030: ldloc.1 + IL_0031: ldc.i4 0x989681 + IL_0036: blt.s IL_0025 + + IL_0038: ret + } + + } + +} + +.class private abstract auto ansi sealed ''.$assembly$fsx + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + + } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ListExpressionStepping/ListExpressionStepping02.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ListExpressionStepping/ListExpressionStepping02.fs.il.bsl index 4c02a2d424e..393f87507c5 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ListExpressionStepping/ListExpressionStepping02.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ListExpressionStepping/ListExpressionStepping02.fs.il.bsl @@ -67,11 +67,14 @@ Invoke(int32 i) cil managed { - .maxstack 8 + .maxstack 6 + .locals init (int32 V_0) IL_0000: ldc.i4.0 - IL_0001: ldarg.1 - IL_0002: add - IL_0003: ret + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldarg.1 + IL_0004: add + IL_0005: ret } .method private specialname rtspecialname static @@ -206,11 +209,14 @@ Invoke(int32 i) cil managed { - .maxstack 8 + .maxstack 6 + .locals init (int32 V_0) IL_0000: ldc.i4.0 - IL_0001: ldarg.1 - IL_0002: add - IL_0003: ret + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldarg.1 + IL_0004: add + IL_0005: ret } .method private specialname rtspecialname static @@ -245,11 +251,14 @@ Invoke(int32 i) cil managed { - .maxstack 8 + .maxstack 6 + .locals init (int32 V_0) IL_0000: ldc.i4.0 - IL_0001: ldarg.1 - IL_0002: add - IL_0003: ret + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldarg.1 + IL_0004: add + IL_0005: ret } .method private specialname rtspecialname static @@ -412,14 +421,26 @@ .locals init (class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_1, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_2, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_3, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_4, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_5, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_6, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_7, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_8, + int32 V_3, + int32 V_4, + int32 V_5, + int32 V_6, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_7, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_8, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_9, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_10) + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_10, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_11, + int32 V_12, + int32 V_13, + int32 V_14, + int32 V_15, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_16, + int32 V_17, + int32 V_18, + int32 V_19, + int32 V_20, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_21, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_22) IL_0000: ldarg.0 IL_0001: ldarg.0 IL_0002: ldarg.0 @@ -433,109 +454,133 @@ IL_0017: stloc.1 IL_0018: nop IL_0019: ldc.i4.2 - IL_001a: ldc.i4.0 - IL_001b: bge.s IL_0025 - - IL_001d: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_0022: nop - IL_0023: br.s IL_0035 - - IL_0025: ldc.i4.2 - IL_0026: ldc.i4.0 - IL_0027: sub - IL_0028: ldc.i4.1 - IL_0029: add - IL_002a: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1'::@_instance - IL_002f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_001a: stloc.3 + IL_001b: ldloc.3 + IL_001c: ldc.i4.0 + IL_001d: stloc.s V_4 + IL_001f: ldloc.s V_4 + IL_0021: bge.s IL_002b + + IL_0023: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_0028: nop + IL_0029: br.s IL_0043 + + IL_002b: ldc.i4.2 + IL_002c: stloc.s V_5 + IL_002e: ldloc.s V_5 + IL_0030: ldc.i4.0 + IL_0031: stloc.s V_6 + IL_0033: ldloc.s V_6 + IL_0035: sub + IL_0036: ldc.i4.1 + IL_0037: add + IL_0038: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1'::@_instance + IL_003d: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0034: nop - IL_0035: stloc.2 - IL_0036: ldloc.1 - IL_0037: ldloc.2 - IL_0038: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Zip(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, + IL_0042: nop + IL_0043: stloc.2 + IL_0044: ldloc.1 + IL_0045: ldloc.2 + IL_0046: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Zip(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_003d: stloc.3 - IL_003e: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 stage #2 at line 18@18' class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 stage #2 at line 18@18'::@_instance - IL_0043: ldloc.3 - IL_0044: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`2>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + IL_004b: stloc.s V_7 + IL_004d: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 stage #2 at line 18@18' class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 stage #2 at line 18@18'::@_instance + IL_0052: ldloc.s V_7 + IL_0054: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`2>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0049: stloc.s V_4 - IL_004b: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs1@19 class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs1@19::@_instance - IL_0050: ldloc.s V_4 - IL_0052: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`2>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + IL_0059: stloc.s V_8 + IL_005b: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs1@19 class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs1@19::@_instance + IL_0060: ldloc.s V_8 + IL_0062: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`2>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0057: stloc.0 - IL_0058: ldarg.0 - IL_0059: ldarg.0 - IL_005a: ldarg.0 - IL_005b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_0060: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + IL_0067: stloc.0 + IL_0068: ldarg.0 + IL_0069: ldarg.0 + IL_006a: ldarg.0 + IL_006b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_0070: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0065: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + IL_0075: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_006a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + IL_007a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_006f: stloc.s V_6 - IL_0071: nop - IL_0072: ldc.i4.2 - IL_0073: ldc.i4.0 - IL_0074: bge.s IL_007e - - IL_0076: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_007b: nop - IL_007c: br.s IL_008e - - IL_007e: ldc.i4.2 - IL_007f: ldc.i4.0 - IL_0080: sub - IL_0081: ldc.i4.1 - IL_0082: add - IL_0083: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1'::@_instance - IL_0088: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_007f: stloc.s V_10 + IL_0081: nop + IL_0082: ldc.i4.2 + IL_0083: stloc.s V_12 + IL_0085: ldloc.s V_12 + IL_0087: ldc.i4.0 + IL_0088: stloc.s V_13 + IL_008a: ldloc.s V_13 + IL_008c: bge.s IL_0096 + + IL_008e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_0093: nop + IL_0094: br.s IL_00ae + + IL_0096: ldc.i4.2 + IL_0097: stloc.s V_14 + IL_0099: ldloc.s V_14 + IL_009b: ldc.i4.0 + IL_009c: stloc.s V_15 + IL_009e: ldloc.s V_15 + IL_00a0: sub + IL_00a1: ldc.i4.1 + IL_00a2: add + IL_00a3: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1'::@_instance + IL_00a8: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_008d: nop - IL_008e: stloc.s V_7 - IL_0090: nop - IL_0091: ldc.i4.2 - IL_0092: ldc.i4.0 - IL_0093: bge.s IL_009d - - IL_0095: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_009a: nop - IL_009b: br.s IL_00ad - - IL_009d: ldc.i4.2 - IL_009e: ldc.i4.0 - IL_009f: sub - IL_00a0: ldc.i4.1 - IL_00a1: add - IL_00a2: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1'::@_instance - IL_00a7: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_00ad: nop + IL_00ae: stloc.s V_11 + IL_00b0: nop + IL_00b1: ldc.i4.2 + IL_00b2: stloc.s V_17 + IL_00b4: ldloc.s V_17 + IL_00b6: ldc.i4.0 + IL_00b7: stloc.s V_18 + IL_00b9: ldloc.s V_18 + IL_00bb: bge.s IL_00c5 + + IL_00bd: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_00c2: nop + IL_00c3: br.s IL_00dd + + IL_00c5: ldc.i4.2 + IL_00c6: stloc.s V_19 + IL_00c8: ldloc.s V_19 + IL_00ca: ldc.i4.0 + IL_00cb: stloc.s V_20 + IL_00cd: ldloc.s V_20 + IL_00cf: sub + IL_00d0: ldc.i4.1 + IL_00d1: add + IL_00d2: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1'::@_instance + IL_00d7: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_00ac: nop - IL_00ad: stloc.s V_8 - IL_00af: ldloc.s V_6 - IL_00b1: ldloc.s V_7 - IL_00b3: ldloc.s V_8 - IL_00b5: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Zip3(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, + IL_00dc: nop + IL_00dd: stloc.s V_16 + IL_00df: ldloc.s V_10 + IL_00e1: ldloc.s V_11 + IL_00e3: ldloc.s V_16 + IL_00e5: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Zip3(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_00ba: stloc.s V_9 - IL_00bc: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 stage #2 at line 24@24' class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 stage #2 at line 24@24'::@_instance - IL_00c1: ldloc.s V_9 - IL_00c3: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`3>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + IL_00ea: stloc.s V_21 + IL_00ec: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 stage #2 at line 24@24' class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 stage #2 at line 24@24'::@_instance + IL_00f1: ldloc.s V_21 + IL_00f3: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`3>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_00c8: stloc.s V_10 - IL_00ca: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs2@25 class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs2@25::@_instance - IL_00cf: ldloc.s V_10 - IL_00d1: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`3>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + IL_00f8: stloc.s V_22 + IL_00fa: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs2@25 class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs2@25::@_instance + IL_00ff: ldloc.s V_22 + IL_0101: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`3>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_00d6: stloc.s V_5 - IL_00d8: ldloc.0 - IL_00d9: ldloc.s V_5 - IL_00db: newobj instance void class [runtime]System.Tuple`2>,class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>>::.ctor(!0, + IL_0106: stloc.s V_9 + IL_0108: ldloc.0 + IL_0109: ldloc.s V_9 + IL_010b: newobj instance void class [runtime]System.Tuple`2>,class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>>::.ctor(!0, !1) - IL_00e0: ret + IL_0110: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/CodeGenRenamings01.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/CodeGenRenamings01.fs.il.bsl index dd5659e05d8..2b6f2b17ed0 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/CodeGenRenamings01.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/CodeGenRenamings01.fs.il.bsl @@ -63,11 +63,14 @@ Invoke(int32 i) cil managed { - .maxstack 8 + .maxstack 6 + .locals init (int32 V_0) IL_0000: ldc.i4.1 - IL_0001: ldarg.1 - IL_0002: add - IL_0003: ret + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldarg.1 + IL_0004: add + IL_0005: ret } .method private specialname rtspecialname static @@ -453,278 +456,290 @@ int32[] V_9, int32[] V_10, int32 V_11, - class [runtime]System.Tuple`4 V_12, - class [runtime]System.Tuple`4 V_13, + int32 V_12, + int32 V_13, int32 V_14, - class [runtime]System.Tuple`3 V_15, - class [runtime]System.Tuple`3 V_16, - int32 V_17, - class [runtime]System.Tuple`4 V_18, - class [runtime]System.Tuple`4 V_19, - int32 V_20) + int32 V_15, + class [runtime]System.Tuple`4 V_16, + class [runtime]System.Tuple`4 V_17, + int32 V_18, + class [runtime]System.Tuple`3 V_19, + class [runtime]System.Tuple`3 V_20, + int32 V_21, + class [runtime]System.Tuple`4 V_22, + class [runtime]System.Tuple`4 V_23, + int32 V_24) IL_0000: nop IL_0001: ldc.i4.s 10 - IL_0003: ldc.i4.1 - IL_0004: bge.s IL_000e - - IL_0006: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_000b: nop - IL_000c: br.s IL_001f - - IL_000e: ldc.i4.s 10 - IL_0010: ldc.i4.1 - IL_0011: sub - IL_0012: ldc.i4.1 - IL_0013: add - IL_0014: ldsfld class assembly/alist@1 assembly/alist@1::@_instance - IL_0019: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_0003: stloc.s V_11 + IL_0005: ldloc.s V_11 + IL_0007: ldc.i4.1 + IL_0008: stloc.s V_12 + IL_000a: ldloc.s V_12 + IL_000c: bge.s IL_0016 + + IL_000e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_0013: nop + IL_0014: br.s IL_002f + + IL_0016: ldc.i4.s 10 + IL_0018: stloc.s V_13 + IL_001a: ldloc.s V_13 + IL_001c: ldc.i4.1 + IL_001d: stloc.s V_14 + IL_001f: ldloc.s V_14 + IL_0021: sub + IL_0022: ldc.i4.1 + IL_0023: add + IL_0024: ldsfld class assembly/alist@1 assembly/alist@1::@_instance + IL_0029: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_001e: nop - IL_001f: dup - IL_0020: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::alist@5 - IL_0025: stloc.0 - IL_0026: ldc.i4.3 - IL_0027: newarr [runtime]System.Int32 - IL_002c: dup - IL_002d: ldc.i4.0 - IL_002e: ldc.i4.1 - IL_002f: stelem [runtime]System.Int32 - IL_0034: dup - IL_0035: ldc.i4.1 - IL_0036: ldc.i4.2 - IL_0037: stelem [runtime]System.Int32 + IL_002e: nop + IL_002f: dup + IL_0030: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::alist@5 + IL_0035: stloc.0 + IL_0036: ldc.i4.3 + IL_0037: newarr [runtime]System.Int32 IL_003c: dup - IL_003d: ldc.i4.2 - IL_003e: ldc.i4.3 + IL_003d: ldc.i4.0 + IL_003e: ldc.i4.1 IL_003f: stelem [runtime]System.Int32 IL_0044: dup - IL_0045: stsfld int32[] ''.$assembly::array@6 - IL_004a: stloc.1 - IL_004b: ldc.i4.1 - IL_004c: ldc.i4.1 - IL_004d: ldc.i4.s 10 - IL_004f: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, + IL_0045: ldc.i4.1 + IL_0046: ldc.i4.2 + IL_0047: stelem [runtime]System.Int32 + IL_004c: dup + IL_004d: ldc.i4.2 + IL_004e: ldc.i4.3 + IL_004f: stelem [runtime]System.Int32 + IL_0054: dup + IL_0055: stsfld int32[] ''.$assembly::array@6 + IL_005a: stloc.1 + IL_005b: ldc.i4.1 + IL_005c: ldc.i4.1 + IL_005d: ldc.i4.s 10 + IL_005f: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, int32, int32) - IL_0054: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0059: dup - IL_005a: stsfld class [runtime]System.Collections.Generic.IEnumerable`1 ''.$assembly::aseq@7 - IL_005f: stloc.2 - IL_0060: ldc.i4.1 - IL_0061: ldc.i4.1 - IL_0062: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, + IL_0064: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0069: dup + IL_006a: stsfld class [runtime]System.Collections.Generic.IEnumerable`1 ''.$assembly::aseq@7 + IL_006f: stloc.2 + IL_0070: ldc.i4.1 + IL_0071: ldc.i4.1 + IL_0072: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, !1) - IL_0067: ldc.i4.2 - IL_0068: ldc.i4.2 - IL_0069: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, + IL_0077: ldc.i4.2 + IL_0078: ldc.i4.2 + IL_0079: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, !1) - IL_006e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::get_Empty() - IL_0073: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::Cons(!0, + IL_007e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::get_Empty() + IL_0083: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0078: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::Cons(!0, + IL_0088: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_007d: dup - IL_007e: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> ''.$assembly::list1@8 - IL_0083: stloc.3 - IL_0084: ldc.i4.0 - IL_0085: ldnull - IL_0086: newobj instance void assembly/seq1@9::.ctor(int32, + IL_008d: dup + IL_008e: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> ''.$assembly::list1@8 + IL_0093: stloc.3 + IL_0094: ldc.i4.0 + IL_0095: ldnull + IL_0096: newobj instance void assembly/seq1@9::.ctor(int32, class [runtime]System.Tuple`2) - IL_008b: dup - IL_008c: stsfld class [runtime]System.Collections.Generic.IEnumerable`1> ''.$assembly::seq1@9 - IL_0091: stloc.s V_4 - IL_0093: ldc.i4.2 - IL_0094: newarr class [runtime]System.Tuple`2 - IL_0099: dup - IL_009a: ldc.i4.0 - IL_009b: ldc.i4.1 - IL_009c: ldc.i4.1 - IL_009d: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, + IL_009b: dup + IL_009c: stsfld class [runtime]System.Collections.Generic.IEnumerable`1> ''.$assembly::seq1@9 + IL_00a1: stloc.s V_4 + IL_00a3: ldc.i4.2 + IL_00a4: newarr class [runtime]System.Tuple`2 + IL_00a9: dup + IL_00aa: ldc.i4.0 + IL_00ab: ldc.i4.1 + IL_00ac: ldc.i4.1 + IL_00ad: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, !1) - IL_00a2: stelem class [runtime]System.Tuple`2 - IL_00a7: dup - IL_00a8: ldc.i4.1 - IL_00a9: ldc.i4.2 - IL_00aa: ldc.i4.2 - IL_00ab: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, + IL_00b2: stelem class [runtime]System.Tuple`2 + IL_00b7: dup + IL_00b8: ldc.i4.1 + IL_00b9: ldc.i4.2 + IL_00ba: ldc.i4.2 + IL_00bb: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, !1) - IL_00b0: stelem class [runtime]System.Tuple`2 - IL_00b5: dup - IL_00b6: stsfld class [runtime]System.Tuple`2[] ''.$assembly::array1@10 - IL_00bb: stloc.s V_5 - IL_00bd: ldc.i4.2 - IL_00be: ldc.i4.2 - IL_00bf: ldc.i4.0 - IL_00c0: call !!0[0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Create(int32, + IL_00c0: stelem class [runtime]System.Tuple`2 + IL_00c5: dup + IL_00c6: stsfld class [runtime]System.Tuple`2[] ''.$assembly::array1@10 + IL_00cb: stloc.s V_5 + IL_00cd: ldc.i4.2 + IL_00ce: ldc.i4.2 + IL_00cf: ldc.i4.0 + IL_00d0: call !!0[0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Create(int32, int32, !!0) - IL_00c5: dup - IL_00c6: stsfld int32[0...,0...] ''.$assembly::a3@11 - IL_00cb: stloc.s V_6 - IL_00cd: ldc.i4.3 - IL_00ce: ldc.i4.3 - IL_00cf: ldc.i4.3 - IL_00d0: ldc.i4.0 - IL_00d1: call !!0[0...,0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Create(int32, + IL_00d5: dup + IL_00d6: stsfld int32[0...,0...] ''.$assembly::a3@11 + IL_00db: stloc.s V_6 + IL_00dd: ldc.i4.3 + IL_00de: ldc.i4.3 + IL_00df: ldc.i4.3 + IL_00e0: ldc.i4.0 + IL_00e1: call !!0[0...,0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Create(int32, int32, int32, !!0) - IL_00d6: dup - IL_00d7: stsfld int32[0...,0...,0...] ''.$assembly::array3D@12 - IL_00dc: stloc.s V_7 - IL_00de: ldc.i4.4 - IL_00df: ldc.i4.4 - IL_00e0: ldc.i4.4 - IL_00e1: ldc.i4.4 - IL_00e2: ldc.i4.0 - IL_00e3: call !!0[0...,0...,0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Create(int32, + IL_00e6: dup + IL_00e7: stsfld int32[0...,0...,0...] ''.$assembly::array3D@12 + IL_00ec: stloc.s V_7 + IL_00ee: ldc.i4.4 + IL_00ef: ldc.i4.4 + IL_00f0: ldc.i4.4 + IL_00f1: ldc.i4.4 + IL_00f2: ldc.i4.0 + IL_00f3: call !!0[0...,0...,0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Create(int32, int32, int32, int32, !!0) - IL_00e8: dup - IL_00e9: stsfld int32[0...,0...,0...,0...] ''.$assembly::array4D@13 - IL_00ee: stloc.s V_8 - IL_00f0: call int32[] assembly::get_array() - IL_00f5: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::OfArray(!!0[]) - IL_00fa: pop - IL_00fb: call class [runtime]System.Collections.Generic.IEnumerable`1 assembly::get_aseq() - IL_0100: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0105: pop - IL_0106: call class [runtime]System.Tuple`2[] assembly::get_array1() - IL_010b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfArray(class [runtime]System.Tuple`2[]) - IL_0110: pop - IL_0111: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> assembly::get_list1() - IL_0116: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfList(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>) - IL_011b: pop - IL_011c: call class [runtime]System.Collections.Generic.IEnumerable`1> assembly::get_seq1() - IL_0121: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1>) - IL_0126: pop - IL_0127: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_alist() - IL_012c: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::OfList(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0131: dup - IL_0132: stsfld int32[] ''.$assembly::a1@25 - IL_0137: stloc.s V_9 - IL_0139: call class [runtime]System.Collections.Generic.IEnumerable`1 assembly::get_aseq() - IL_013e: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0143: dup - IL_0144: stsfld int32[] ''.$assembly::a2@26 - IL_0149: stloc.s V_10 - IL_014b: call int32[] assembly::get_a1() - IL_0150: ldc.i4.0 - IL_0151: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Get(!!0[], + IL_00f8: dup + IL_00f9: stsfld int32[0...,0...,0...,0...] ''.$assembly::array4D@13 + IL_00fe: stloc.s V_8 + IL_0100: call int32[] assembly::get_array() + IL_0105: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::OfArray(!!0[]) + IL_010a: pop + IL_010b: call class [runtime]System.Collections.Generic.IEnumerable`1 assembly::get_aseq() + IL_0110: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0115: pop + IL_0116: call class [runtime]System.Tuple`2[] assembly::get_array1() + IL_011b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfArray(class [runtime]System.Tuple`2[]) + IL_0120: pop + IL_0121: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> assembly::get_list1() + IL_0126: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfList(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>) + IL_012b: pop + IL_012c: call class [runtime]System.Collections.Generic.IEnumerable`1> assembly::get_seq1() + IL_0131: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1>) + IL_0136: pop + IL_0137: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_alist() + IL_013c: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::OfList(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_0141: dup + IL_0142: stsfld int32[] ''.$assembly::a1@25 + IL_0147: stloc.s V_9 + IL_0149: call class [runtime]System.Collections.Generic.IEnumerable`1 assembly::get_aseq() + IL_014e: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0153: dup + IL_0154: stsfld int32[] ''.$assembly::a2@26 + IL_0159: stloc.s V_10 + IL_015b: call int32[] assembly::get_a1() + IL_0160: ldc.i4.0 + IL_0161: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Get(!!0[], int32) - IL_0156: stloc.s V_11 - IL_0158: call int32[] assembly::get_a2() - IL_015d: ldc.i4.0 - IL_015e: ldloc.s V_11 - IL_0160: call void [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Set(!!0[], + IL_0166: stloc.s V_15 + IL_0168: call int32[] assembly::get_a2() + IL_016d: ldc.i4.0 + IL_016e: ldloc.s V_15 + IL_0170: call void [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Set(!!0[], int32, !!0) - IL_0165: nop - IL_0166: call int32[0...,0...] assembly::get_a3() - IL_016b: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Length1(!!0[0...,0...]) - IL_0170: call int32[0...,0...] assembly::get_a3() - IL_0175: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Length2(!!0[0...,0...]) - IL_017a: call int32[0...,0...] assembly::get_a3() - IL_017f: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Base1(!!0[0...,0...]) - IL_0184: call int32[0...,0...] assembly::get_a3() - IL_0189: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Base2(!!0[0...,0...]) - IL_018e: newobj instance void class [runtime]System.Tuple`4::.ctor(!0, + IL_0175: nop + IL_0176: call int32[0...,0...] assembly::get_a3() + IL_017b: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Length1(!!0[0...,0...]) + IL_0180: call int32[0...,0...] assembly::get_a3() + IL_0185: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Length2(!!0[0...,0...]) + IL_018a: call int32[0...,0...] assembly::get_a3() + IL_018f: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Base1(!!0[0...,0...]) + IL_0194: call int32[0...,0...] assembly::get_a3() + IL_0199: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Base2(!!0[0...,0...]) + IL_019e: newobj instance void class [runtime]System.Tuple`4::.ctor(!0, !1, !2, !3) - IL_0193: stloc.s V_12 - IL_0195: ldloc.s V_12 - IL_0197: stloc.s V_13 - IL_0199: call int32[0...,0...] assembly::get_a3() - IL_019e: ldc.i4.0 - IL_019f: ldc.i4.0 - IL_01a0: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Get(!!0[0...,0...], + IL_01a3: stloc.s V_16 + IL_01a5: ldloc.s V_16 + IL_01a7: stloc.s V_17 + IL_01a9: call int32[0...,0...] assembly::get_a3() + IL_01ae: ldc.i4.0 + IL_01af: ldc.i4.0 + IL_01b0: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Get(!!0[0...,0...], int32, int32) - IL_01a5: stloc.s V_14 - IL_01a7: call int32[0...,0...] assembly::get_a3() - IL_01ac: ldc.i4.0 - IL_01ad: ldc.i4.0 - IL_01ae: ldloc.s V_14 - IL_01b0: call void [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Set(!!0[0...,0...], + IL_01b5: stloc.s V_18 + IL_01b7: call int32[0...,0...] assembly::get_a3() + IL_01bc: ldc.i4.0 + IL_01bd: ldc.i4.0 + IL_01be: ldloc.s V_18 + IL_01c0: call void [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Set(!!0[0...,0...], int32, int32, !!0) - IL_01b5: nop - IL_01b6: call int32[0...,0...,0...] assembly::get_array3D() - IL_01bb: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length1(!!0[0...,0...,0...]) - IL_01c0: call int32[0...,0...,0...] assembly::get_array3D() - IL_01c5: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length2(!!0[0...,0...,0...]) - IL_01ca: call int32[0...,0...,0...] assembly::get_array3D() - IL_01cf: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length3(!!0[0...,0...,0...]) - IL_01d4: newobj instance void class [runtime]System.Tuple`3::.ctor(!0, + IL_01c5: nop + IL_01c6: call int32[0...,0...,0...] assembly::get_array3D() + IL_01cb: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length1(!!0[0...,0...,0...]) + IL_01d0: call int32[0...,0...,0...] assembly::get_array3D() + IL_01d5: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length2(!!0[0...,0...,0...]) + IL_01da: call int32[0...,0...,0...] assembly::get_array3D() + IL_01df: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length3(!!0[0...,0...,0...]) + IL_01e4: newobj instance void class [runtime]System.Tuple`3::.ctor(!0, !1, !2) - IL_01d9: stloc.s V_15 - IL_01db: ldloc.s V_15 - IL_01dd: stloc.s V_16 - IL_01df: call int32[0...,0...,0...] assembly::get_array3D() - IL_01e4: ldc.i4.0 - IL_01e5: ldc.i4.0 - IL_01e6: ldc.i4.0 - IL_01e7: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Get(!!0[0...,0...,0...], + IL_01e9: stloc.s V_19 + IL_01eb: ldloc.s V_19 + IL_01ed: stloc.s V_20 + IL_01ef: call int32[0...,0...,0...] assembly::get_array3D() + IL_01f4: ldc.i4.0 + IL_01f5: ldc.i4.0 + IL_01f6: ldc.i4.0 + IL_01f7: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Get(!!0[0...,0...,0...], int32, int32, int32) - IL_01ec: stloc.s V_17 - IL_01ee: call int32[0...,0...,0...] assembly::get_array3D() - IL_01f3: ldc.i4.0 - IL_01f4: ldc.i4.0 - IL_01f5: ldc.i4.0 - IL_01f6: ldloc.s V_17 - IL_01f8: call void [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Set(!!0[0...,0...,0...], + IL_01fc: stloc.s V_21 + IL_01fe: call int32[0...,0...,0...] assembly::get_array3D() + IL_0203: ldc.i4.0 + IL_0204: ldc.i4.0 + IL_0205: ldc.i4.0 + IL_0206: ldloc.s V_21 + IL_0208: call void [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Set(!!0[0...,0...,0...], int32, int32, int32, !!0) - IL_01fd: nop - IL_01fe: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_0203: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length1(!!0[0...,0...,0...,0...]) - IL_0208: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_020d: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length2(!!0[0...,0...,0...,0...]) - IL_0212: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_0217: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length3(!!0[0...,0...,0...,0...]) - IL_021c: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_0221: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length4(!!0[0...,0...,0...,0...]) - IL_0226: newobj instance void class [runtime]System.Tuple`4::.ctor(!0, + IL_020d: nop + IL_020e: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_0213: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length1(!!0[0...,0...,0...,0...]) + IL_0218: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_021d: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length2(!!0[0...,0...,0...,0...]) + IL_0222: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_0227: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length3(!!0[0...,0...,0...,0...]) + IL_022c: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_0231: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length4(!!0[0...,0...,0...,0...]) + IL_0236: newobj instance void class [runtime]System.Tuple`4::.ctor(!0, !1, !2, !3) - IL_022b: stloc.s V_18 - IL_022d: ldloc.s V_18 - IL_022f: stloc.s V_19 - IL_0231: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_0236: ldc.i4.0 - IL_0237: ldc.i4.0 - IL_0238: ldc.i4.0 - IL_0239: ldc.i4.0 - IL_023a: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Get(!!0[0...,0...,0...,0...], - int32, - int32, - int32, - int32) - IL_023f: stloc.s V_20 + IL_023b: stloc.s V_22 + IL_023d: ldloc.s V_22 + IL_023f: stloc.s V_23 IL_0241: call int32[0...,0...,0...,0...] assembly::get_array4D() IL_0246: ldc.i4.0 IL_0247: ldc.i4.0 IL_0248: ldc.i4.0 IL_0249: ldc.i4.0 - IL_024a: ldloc.s V_20 - IL_024c: call void [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Set(!!0[0...,0...,0...,0...], + IL_024a: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Get(!!0[0...,0...,0...,0...], + int32, + int32, + int32, + int32) + IL_024f: stloc.s V_24 + IL_0251: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_0256: ldc.i4.0 + IL_0257: ldc.i4.0 + IL_0258: ldc.i4.0 + IL_0259: ldc.i4.0 + IL_025a: ldloc.s V_24 + IL_025c: call void [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Set(!!0[0...,0...,0...,0...], int32, int32, int32, int32, !!0) - IL_0251: nop - IL_0252: ret + IL_0261: nop + IL_0262: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ForLoop01.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ForLoop01.fs.il.bsl index e5c6b9f25d3..87312556b8e 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ForLoop01.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ForLoop01.fs.il.bsl @@ -63,11 +63,14 @@ Invoke(int32 i) cil managed { - .maxstack 8 + .maxstack 6 + .locals init (int32 V_0) IL_0000: ldc.i4.1 - IL_0001: ldarg.1 - IL_0002: add - IL_0003: ret + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: ldarg.1 + IL_0004: add + IL_0005: ret } .method private specialname rtspecialname static @@ -97,50 +100,62 @@ .maxstack 4 .locals init (class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_0, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_1, - int32 V_2) + int32 V_1, + int32 V_2, + int32 V_3, + int32 V_4, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_5, + int32 V_6) IL_0000: nop IL_0001: ldc.i4.3 - IL_0002: ldc.i4.1 - IL_0003: bge.s IL_000d - - IL_0005: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_000a: nop - IL_000b: br.s IL_001d - - IL_000d: ldc.i4.3 - IL_000e: ldc.i4.1 - IL_000f: sub - IL_0010: ldc.i4.1 - IL_0011: add - IL_0012: ldsfld class assembly/clo@1 assembly/clo@1::@_instance - IL_0017: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: ldc.i4.1 + IL_0005: stloc.2 + IL_0006: ldloc.2 + IL_0007: bge.s IL_0011 + + IL_0009: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_000e: nop + IL_000f: br.s IL_0027 + + IL_0011: ldc.i4.3 + IL_0012: stloc.3 + IL_0013: ldloc.3 + IL_0014: ldc.i4.1 + IL_0015: stloc.s V_4 + IL_0017: ldloc.s V_4 + IL_0019: sub + IL_001a: ldc.i4.1 + IL_001b: add + IL_001c: ldsfld class assembly/clo@1 assembly/clo@1::@_instance + IL_0021: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_001c: nop - IL_001d: stloc.0 - IL_001e: ldloc.0 - IL_001f: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() - IL_0024: stloc.1 - IL_0025: br.s IL_004d - - IL_0027: ldloc.0 - IL_0028: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() - IL_002d: stloc.2 - IL_002e: ldstr "%A" - IL_0033: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit,int32>::.ctor(string) - IL_0038: call !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine>(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4) - IL_003d: ldloc.2 - IL_003e: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_0043: pop - IL_0044: ldloc.1 - IL_0045: stloc.0 - IL_0046: ldloc.0 - IL_0047: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() - IL_004c: stloc.1 - IL_004d: ldloc.1 - IL_004e: brtrue.s IL_0027 - - IL_0050: ret + IL_0026: nop + IL_0027: stloc.0 + IL_0028: ldloc.0 + IL_0029: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_002e: stloc.s V_5 + IL_0030: br.s IL_005c + + IL_0032: ldloc.0 + IL_0033: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0038: stloc.s V_6 + IL_003a: ldstr "%A" + IL_003f: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit,int32>::.ctor(string) + IL_0044: call !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine>(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4) + IL_0049: ldloc.s V_6 + IL_004b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0050: pop + IL_0051: ldloc.s V_5 + IL_0053: stloc.0 + IL_0054: ldloc.0 + IL_0055: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_005a: stloc.s V_5 + IL_005c: ldloc.s V_5 + IL_005e: brtrue.s IL_0032 + + IL_0060: ret } } From 34a2214f33c57299398bbe56e095e7876cfa4424 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Sat, 27 Jan 2024 16:09:03 -0500 Subject: [PATCH 23/25] Add tests for non-const, non-val args --- .../ComputedCollectionLoweringTests.fs | 385 +++++++++++++++--- 1 file changed, 325 insertions(+), 60 deletions(-) diff --git a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs index b163b9db629..b36b6fbcdbd 100644 --- a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs +++ b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs @@ -161,22 +161,11 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldc.i4.s 10 - IL_0002: ldc.i4.1 - IL_0003: bge.s IL_000b - - IL_0005: call !!0[] [runtime]System.Array::Empty() - IL_000a: ret - - IL_000b: ldc.i4.s 10 - IL_000d: ldc.i4.1 - IL_000e: sub - IL_000f: ldc.i4.1 - IL_0010: add - IL_0011: ldsfld class Test/test@1 Test/test@1::@_instance - IL_0016: tail. - IL_0018: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0002: ldsfld class Test/test@1 Test/test@1::@_instance + IL_0007: tail. + IL_0009: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_001d: ret + IL_000e: ret } } @@ -278,22 +267,11 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldc.i4 0x101 - IL_0005: ldc.i4.1 - IL_0006: bge.s IL_000e - - IL_0008: call !!0[] [runtime]System.Array::Empty() - IL_000d: ret - - IL_000e: ldc.i4 0x101 - IL_0013: ldc.i4.1 - IL_0014: sub - IL_0015: ldc.i4.1 - IL_0016: add - IL_0017: ldsfld class Test/test@1 Test/test@1::@_instance - IL_001c: tail. - IL_001e: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0005: ldsfld class Test/test@1 Test/test@1::@_instance + IL_000a: tail. + IL_000c: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0023: ret + IL_0011: ret } } @@ -419,6 +397,160 @@ module ComputedCollectionLoweringTests = """ ])) + [] + let ``Lone RangeInt32 with dynamic args that are complex exprs stores those in vars before calling init`` () = + CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], + """ + module Test + + let a () = (Array.zeroCreate 10).Length + let b () = (Array.zeroCreate 20).Length + + let test start finish = [|a ()..b ()|] + """, + (fun verifier -> verifier.VerifyIL [ + """ + .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 Test + 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 test@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public int32 start + .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 start) 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 int32 Test/test@1::start + IL_000d: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 Test/test@1::start + IL_0006: ldarg.1 + IL_0007: add + IL_0008: ret + } + + } + + .method public static int32 a() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.s 10 + IL_0002: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::ZeroCreate(int32) + IL_0007: ldlen + IL_0008: conv.i4 + IL_0009: ret + } + + .method public static int32 b() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.s 20 + IL_0002: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::ZeroCreate(int32) + IL_0007: ldlen + IL_0008: conv.i4 + IL_0009: ret + } + + .method public static int32[] test(!!a start, + !!b finish) 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 (int32 V_0, + int32 V_1) + IL_0000: ldc.i4.s 10 + IL_0002: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::ZeroCreate(int32) + IL_0007: ldlen + IL_0008: conv.i4 + IL_0009: stloc.0 + IL_000a: ldc.i4.s 20 + IL_000c: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::ZeroCreate(int32) + IL_0011: ldlen + IL_0012: conv.i4 + IL_0013: stloc.1 + IL_0014: ldloc.1 + IL_0015: ldloc.0 + IL_0016: bge.s IL_001e + + IL_0018: call !!0[] [runtime]System.Array::Empty() + IL_001d: ret + + IL_001e: ldloc.1 + IL_001f: ldloc.0 + IL_0020: sub + IL_0021: ldc.i4.1 + IL_0022: add + IL_0023: ldloc.0 + IL_0024: newobj instance void Test/test@1::.ctor(int32) + IL_0029: tail. + IL_002b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0030: ret + } + + } + + .class private abstract auto ansi sealed ''.$Test + extends [runtime]System.Object + { + } + """ + ])) + module List = [] let ``Lone RangeInt32 with const args when start > finish lowers to empty list`` () = @@ -575,22 +707,11 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldc.i4.s 10 - IL_0002: ldc.i4.1 - IL_0003: bge.s IL_000b - - IL_0005: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_000a: ret - - IL_000b: ldc.i4.s 10 - IL_000d: ldc.i4.1 - IL_000e: sub - IL_000f: ldc.i4.1 - IL_0010: add - IL_0011: ldsfld class Test/test@1 Test/test@1::@_instance - IL_0016: tail. - IL_0018: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_0002: ldsfld class Test/test@1 Test/test@1::@_instance + IL_0007: tail. + IL_0009: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_001d: ret + IL_000e: ret } } @@ -693,22 +814,11 @@ module ComputedCollectionLoweringTests = .maxstack 8 IL_0000: ldc.i4.s 101 - IL_0002: ldc.i4.1 - IL_0003: bge.s IL_000b - - IL_0005: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_000a: ret - - IL_000b: ldc.i4.s 101 - IL_000d: ldc.i4.1 - IL_000e: sub - IL_000f: ldc.i4.1 - IL_0010: add - IL_0011: ldsfld class Test/test@1 Test/test@1::@_instance - IL_0016: tail. - IL_0018: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_0002: ldsfld class Test/test@1 Test/test@1::@_instance + IL_0007: tail. + IL_0009: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_001d: ret + IL_000e: ret } } @@ -834,3 +944,158 @@ module ComputedCollectionLoweringTests = } """ ])) + + [] + let ``Lone RangeInt32 with dynamic args that are complex exprs stores those in vars before calling init`` () = + CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], + """ + module Test + + let a () = (Array.zeroCreate 10).Length + let b () = (Array.zeroCreate 20).Length + + let test start finish = [a ()..b ()] + """, + (fun verifier -> verifier.VerifyIL [ + """ + .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 Test + 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 test@1 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public int32 start + .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 start) 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 int32 Test/test@1::start + IL_000d: ret + } + + .method public strict virtual instance int32 + Invoke(int32 i) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 Test/test@1::start + IL_0006: ldarg.1 + IL_0007: add + IL_0008: ret + } + + } + + .method public static int32 a() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.s 10 + IL_0002: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::ZeroCreate(int32) + IL_0007: ldlen + IL_0008: conv.i4 + IL_0009: ret + } + + .method public static int32 b() cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.s 20 + IL_0002: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::ZeroCreate(int32) + IL_0007: ldlen + IL_0008: conv.i4 + IL_0009: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + test(!!a start, + !!b finish) 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 (int32 V_0, + int32 V_1) + IL_0000: ldc.i4.s 10 + IL_0002: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::ZeroCreate(int32) + IL_0007: ldlen + IL_0008: conv.i4 + IL_0009: stloc.0 + IL_000a: ldc.i4.s 20 + IL_000c: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::ZeroCreate(int32) + IL_0011: ldlen + IL_0012: conv.i4 + IL_0013: stloc.1 + IL_0014: ldloc.1 + IL_0015: ldloc.0 + IL_0016: bge.s IL_001e + + IL_0018: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_001d: ret + + IL_001e: ldloc.1 + IL_001f: ldloc.0 + IL_0020: sub + IL_0021: ldc.i4.1 + IL_0022: add + IL_0023: ldloc.0 + IL_0024: newobj instance void Test/test@1::.ctor(int32) + IL_0029: tail. + IL_002b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) + IL_0030: ret + } + + } + + .class private abstract auto ansi sealed ''.$Test + extends [runtime]System.Object + { + } + """ + ])) From b5596d02616ae5ef74c6d736e1fdb4233c46e218 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Sat, 27 Jan 2024 16:09:59 -0500 Subject: [PATCH 24/25] Simplify tests --- .../ComputedCollectionLoweringTests.fs | 217 +----------------- 1 file changed, 2 insertions(+), 215 deletions(-) diff --git a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs index b36b6fbcdbd..0aa0d2639df 100644 --- a/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs +++ b/tests/fsharp/Compiler/Language/ComputedCollectionLoweringTests.fs @@ -72,113 +72,7 @@ module ComputedCollectionLoweringTests = ])) [] - let ``Lone RangeInt32 with const args ≤ 1024 bytes lowers to call to init`` () = - CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], - """ - module Test - - let test () = [|1..10|] - """, - (fun verifier -> verifier.VerifyIL [ - """ - .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 Test - 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 test@1 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field static assembly initonly class Test/test@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.FSharpFunc`2::.ctor() - IL_0006: ret - } - - .method public strict virtual instance int32 - Invoke(int32 i) cil managed - { - - .maxstack 8 - IL_0000: ldc.i4.1 - IL_0001: ldarg.1 - IL_0002: add - IL_0003: ret - } - - .method private specialname rtspecialname static - void .cctor() cil managed - { - - .maxstack 10 - IL_0000: newobj instance void Test/test@1::.ctor() - IL_0005: stsfld class Test/test@1 Test/test@1::@_instance - IL_000a: ret - } - - } - - .method public static int32[] test() cil managed - { - - .maxstack 8 - IL_0000: ldc.i4.s 10 - IL_0002: ldsfld class Test/test@1 Test/test@1::@_instance - IL_0007: tail. - IL_0009: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, - class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_000e: ret - } - - } - - .class private abstract auto ansi sealed ''.$Test - extends [runtime]System.Object - { - } - """ - ])) - - [] - let ``Lone RangeInt32 with const args > 1024 bytes lowers to call to init`` () = + let ``Lone RangeInt32 with const args lowers to call to init`` () = CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], """ module Test @@ -617,114 +511,7 @@ module ComputedCollectionLoweringTests = ])) [] - let ``Lone small RangeInt32 with const args ≤ 100 lowers to call to init`` () = - CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], - """ - module Test - - let test () = [1..10] - """, - (fun verifier -> verifier.VerifyIL [ - """ - .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 Test - 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 test@1 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field static assembly initonly class Test/test@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.FSharpFunc`2::.ctor() - IL_0006: ret - } - - .method public strict virtual instance int32 - Invoke(int32 i) cil managed - { - - .maxstack 8 - IL_0000: ldc.i4.1 - IL_0001: ldarg.1 - IL_0002: add - IL_0003: ret - } - - .method private specialname rtspecialname static - void .cctor() cil managed - { - - .maxstack 10 - IL_0000: newobj instance void Test/test@1::.ctor() - IL_0005: stsfld class Test/test@1 Test/test@1::@_instance - IL_000a: ret - } - - } - - .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 - test() cil managed - { - - .maxstack 8 - IL_0000: ldc.i4.s 10 - IL_0002: ldsfld class Test/test@1 Test/test@1::@_instance - IL_0007: tail. - IL_0009: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, - class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_000e: ret - } - - } - - .class private abstract auto ansi sealed ''.$Test - extends [runtime]System.Object - { - } - """ - ])) - - [] - let ``Lone RangeInt32 with const args > 100 lowers to call to init`` () = + let ``Lone RangeInt32 with const args lowers to call to init`` () = CompilerAssert.CompileLibraryAndVerifyILWithOptions([|"--optimize+"|], """ module Test From c0494eb40a142f6cd2afeec548d97c4e508a8802 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Sat, 27 Jan 2024 17:04:30 -0500 Subject: [PATCH 25/25] Fix baselines --- .../ComputationExpr07.fs.il.bsl | 74 +-- .../GenericComparison/Compare09.fsx.il.bsl | 116 +---- .../GenericComparison/Equals08.fsx.il.bsl | 116 +---- .../GenericComparison/Hash11.fsx.il.bsl | 79 +-- .../ListExpressionStepping02.fs.il.bsl | 223 +++------ .../Misc/CodeGenRenamings01.fs.il.bsl | 449 ++++++++---------- .../EmittedIL/Misc/ForLoop01.fs.il.bsl | 95 ++-- 7 files changed, 406 insertions(+), 746 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpr07.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpr07.fs.il.bsl index b26e7f6a528..12d6e3e4f1e 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpr07.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputationExpressions/ComputationExpr07.fs.il.bsl @@ -67,14 +67,11 @@ Invoke(int32 i) cil managed { - .maxstack 6 - .locals init (int32 V_0) + .maxstack 8 IL_0000: ldc.i4.0 - IL_0001: stloc.0 - IL_0002: ldloc.0 - IL_0003: ldarg.1 - IL_0004: add - IL_0005: ret + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret } .method private specialname rtspecialname static @@ -212,11 +209,7 @@ { .maxstack 9 - .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 V_0, - int32 V_1, - int32 V_2, - int32 V_3, - int32 V_4) + .locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1 V_0) IL_0000: ldc.i4.1 IL_0001: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1::.ctor(!0) IL_0006: stloc.0 @@ -224,50 +217,29 @@ IL_0008: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ IL_000d: ldarg.0 IL_000e: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ - IL_0013: ldc.i4.3 - IL_0014: stloc.1 - IL_0015: ldloc.1 - IL_0016: ldc.i4.0 - IL_0017: stloc.2 - IL_0018: ldloc.2 - IL_0019: bge.s IL_0023 - - IL_001b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_0020: nop - IL_0021: br.s IL_0039 - - IL_0023: ldc.i4.3 - IL_0024: stloc.3 - IL_0025: ldloc.3 - IL_0026: ldc.i4.0 - IL_0027: stloc.s V_4 - IL_0029: ldloc.s V_4 - IL_002b: sub - IL_002c: ldc.i4.1 - IL_002d: add - IL_002e: ldsfld class Program/'res7@1-1' Program/'res7@1-1'::@_instance - IL_0033: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_0013: ldc.i4.4 + IL_0014: ldsfld class Program/'res7@1-1' Program/'res7@1-1'::@_instance + IL_0019: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0038: nop - IL_0039: ldarg.0 - IL_003a: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ - IL_003f: ldloc.0 - IL_0040: newobj instance void Program/'res7@10-2'::.ctor(class [ComputationExprLibrary]Library.EventuallyBuilder, + IL_001e: ldarg.0 + IL_001f: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ + IL_0024: ldloc.0 + IL_0025: newobj instance void Program/'res7@10-2'::.ctor(class [ComputationExprLibrary]Library.EventuallyBuilder, class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1) - IL_0045: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::For(class [runtime]System.Collections.Generic.IEnumerable`1, + IL_002a: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::For(class [runtime]System.Collections.Generic.IEnumerable`1, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) - IL_004a: ldarg.0 - IL_004b: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ - IL_0050: ldarg.0 - IL_0051: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ - IL_0056: ldloc.0 - IL_0057: newobj instance void Program/'res7@12-3'::.ctor(class [ComputationExprLibrary]Library.EventuallyBuilder, + IL_002f: ldarg.0 + IL_0030: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ + IL_0035: ldarg.0 + IL_0036: ldfld class [ComputationExprLibrary]Library.EventuallyBuilder Program/res7@9::builder@ + IL_003b: ldloc.0 + IL_003c: newobj instance void Program/'res7@12-3'::.ctor(class [ComputationExprLibrary]Library.EventuallyBuilder, class [FSharp.Core]Microsoft.FSharp.Core.FSharpRef`1) - IL_005c: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Delay(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) - IL_0061: tail. - IL_0063: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Combine(class [ComputationExprLibrary]Library.Eventually`1, + IL_0041: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Delay(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0046: tail. + IL_0048: callvirt instance class [ComputationExprLibrary]Library.Eventually`1 [ComputationExprLibrary]Library.EventuallyBuilder::Combine(class [ComputationExprLibrary]Library.Eventually`1, class [ComputationExprLibrary]Library.Eventually`1) - IL_0068: ret + IL_004d: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl index 3b759cafd16..f0da69869d8 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Compare09.fsx.il.bsl @@ -135,99 +135,35 @@ int32 V_3) IL_0000: ldc.i4.1 IL_0001: stloc.0 - IL_0002: nop - IL_0003: ldc.i4.s 100 - IL_0005: ldc.i4.0 - IL_0006: bge.s IL_0010 - - IL_0008: call !!0[] [runtime]System.Array::Empty() - IL_000d: nop - IL_000e: br.s IL_0021 - - IL_0010: ldc.i4.s 100 - IL_0012: ldc.i4.0 - IL_0013: sub - IL_0014: ldc.i4.1 - IL_0015: add - IL_0016: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t1@1 assembly/CompareMicroPerfAndCodeGenerationTests/t1@1::@_instance - IL_001b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0002: ldc.i4.s 101 + IL_0004: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t1@1 assembly/CompareMicroPerfAndCodeGenerationTests/t1@1::@_instance + IL_0009: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0020: nop - IL_0021: stloc.1 - IL_0022: nop - IL_0023: ldc.i4.s 100 - IL_0025: ldc.i4.0 - IL_0026: bge.s IL_0030 - - IL_0028: call !!0[] [runtime]System.Array::Empty() - IL_002d: nop - IL_002e: br.s IL_0041 - - IL_0030: ldc.i4.s 100 - IL_0032: ldc.i4.0 - IL_0033: sub - IL_0034: ldc.i4.1 - IL_0035: add - IL_0036: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t2@1 assembly/CompareMicroPerfAndCodeGenerationTests/t2@1::@_instance - IL_003b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_000e: stloc.1 + IL_000f: ldc.i4.s 101 + IL_0011: ldsfld class assembly/CompareMicroPerfAndCodeGenerationTests/t2@1 assembly/CompareMicroPerfAndCodeGenerationTests/t2@1::@_instance + IL_0016: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0040: nop - IL_0041: stloc.2 - IL_0042: ldc.i4.0 - IL_0043: stloc.3 - IL_0044: br.s IL_0052 - - IL_0046: ldloc.1 - IL_0047: ldloc.2 - IL_0048: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonIntrinsic(!!0, + IL_001b: stloc.2 + IL_001c: ldc.i4.0 + IL_001d: stloc.3 + IL_001e: br.s IL_002c + + IL_0020: ldloc.1 + IL_0021: ldloc.2 + IL_0022: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericComparisonIntrinsic(!!0, !!0) - IL_004d: stloc.0 - IL_004e: ldloc.3 - IL_004f: ldc.i4.1 - IL_0050: add - IL_0051: stloc.3 - IL_0052: ldloc.3 - IL_0053: ldc.i4 0x186a1 - IL_0058: blt.s IL_0046 - - IL_005a: ldloc.0 - IL_005b: ret - } - - } - -} - -.class private abstract auto ansi sealed ''.$assembly$fsx - extends [runtime]System.Object -{ - .method public static void main@() cil managed - { - .entrypoint - - .maxstack 8 - IL_0000: ret - } - -} - - - - - - - !!0) - IL_005d: stloc.0 - IL_005e: ldloc.2 - IL_005f: ldc.i4.1 - IL_0060: add - IL_0061: stloc.2 - IL_0062: ldloc.2 - IL_0063: ldc.i4 0x186a1 - IL_0068: blt.s IL_0056 - - IL_006a: ldloc.0 - IL_006b: ret + IL_0027: stloc.0 + IL_0028: ldloc.3 + IL_0029: ldc.i4.1 + IL_002a: add + IL_002b: stloc.3 + IL_002c: ldloc.3 + IL_002d: ldc.i4 0x186a1 + IL_0032: blt.s IL_0020 + + IL_0034: ldloc.0 + IL_0035: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl index dac2aa32e2d..a227168732a 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Equals08.fsx.il.bsl @@ -135,99 +135,35 @@ int32 V_3) IL_0000: ldc.i4.0 IL_0001: stloc.0 - IL_0002: nop - IL_0003: ldc.i4.s 100 - IL_0005: ldc.i4.0 - IL_0006: bge.s IL_0010 - - IL_0008: call !!0[] [runtime]System.Array::Empty() - IL_000d: nop - IL_000e: br.s IL_0021 - - IL_0010: ldc.i4.s 100 - IL_0012: ldc.i4.0 - IL_0013: sub - IL_0014: ldc.i4.1 - IL_0015: add - IL_0016: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1::@_instance - IL_001b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0002: ldc.i4.s 101 + IL_0004: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t1@1::@_instance + IL_0009: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0020: nop - IL_0021: stloc.1 - IL_0022: nop - IL_0023: ldc.i4.s 100 - IL_0025: ldc.i4.0 - IL_0026: bge.s IL_0030 - - IL_0028: call !!0[] [runtime]System.Array::Empty() - IL_002d: nop - IL_002e: br.s IL_0041 - - IL_0030: ldc.i4.s 100 - IL_0032: ldc.i4.0 - IL_0033: sub - IL_0034: ldc.i4.1 - IL_0035: add - IL_0036: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1::@_instance - IL_003b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_000e: stloc.1 + IL_000f: ldc.i4.s 101 + IL_0011: ldsfld class assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1 assembly/EqualsMicroPerfAndCodeGenerationTests/t2@1::@_instance + IL_0016: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0040: nop - IL_0041: stloc.2 - IL_0042: ldc.i4.0 - IL_0043: stloc.3 - IL_0044: br.s IL_0052 - - IL_0046: ldloc.1 - IL_0047: ldloc.2 - IL_0048: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityIntrinsic(!!0, + IL_001b: stloc.2 + IL_001c: ldc.i4.0 + IL_001d: stloc.3 + IL_001e: br.s IL_002c + + IL_0020: ldloc.1 + IL_0021: ldloc.2 + IL_0022: call bool [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericEqualityIntrinsic(!!0, !!0) - IL_004d: stloc.0 - IL_004e: ldloc.3 - IL_004f: ldc.i4.1 - IL_0050: add - IL_0051: stloc.3 - IL_0052: ldloc.3 - IL_0053: ldc.i4 0x989681 - IL_0058: blt.s IL_0046 - - IL_005a: ldloc.0 - IL_005b: ret - } - - } - -} - -.class private abstract auto ansi sealed ''.$assembly$fsx - extends [runtime]System.Object -{ - .method public static void main@() cil managed - { - .entrypoint - - .maxstack 8 - IL_0000: ret - } - -} - - - - - - - !!0) - IL_005d: stloc.0 - IL_005e: ldloc.2 - IL_005f: ldc.i4.1 - IL_0060: add - IL_0061: stloc.2 - IL_0062: ldloc.2 - IL_0063: ldc.i4 0x989681 - IL_0068: blt.s IL_0056 - - IL_006a: ldloc.0 - IL_006b: ret + IL_0027: stloc.0 + IL_0028: ldloc.3 + IL_0029: ldc.i4.1 + IL_002a: add + IL_002b: stloc.3 + IL_002c: ldloc.3 + IL_002d: ldc.i4 0x989681 + IL_0032: blt.s IL_0020 + + IL_0034: ldloc.0 + IL_0035: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl index f5c1c3f2a07..506853af82b 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/GenericComparison/Hash11.fsx.il.bsl @@ -94,66 +94,27 @@ int32 V_1, int32 V_2) IL_0000: nop - IL_0001: nop - IL_0002: ldc.i4.s 100 - IL_0004: ldc.i4.0 - IL_0005: bge.s IL_000f - - IL_0007: call !!0[] [runtime]System.Array::Empty() - IL_000c: nop - IL_000d: br.s IL_0020 - - IL_000f: ldc.i4.s 100 - IL_0011: ldc.i4.0 - IL_0012: sub - IL_0013: ldc.i4.1 - IL_0014: add - IL_0015: ldsfld class assembly/HashMicroPerfAndCodeGenerationTests/arr@1 assembly/HashMicroPerfAndCodeGenerationTests/arr@1::@_instance - IL_001a: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, + IL_0001: ldc.i4.s 101 + IL_0003: ldsfld class assembly/HashMicroPerfAndCodeGenerationTests/arr@1 assembly/HashMicroPerfAndCodeGenerationTests/arr@1::@_instance + IL_0008: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_001f: nop - IL_0020: stloc.0 - IL_0021: ldc.i4.0 - IL_0022: stloc.1 - IL_0023: br.s IL_0030 - - IL_0025: ldloc.0 - IL_0026: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericHashIntrinsic(!!0) - IL_002b: stloc.2 - IL_002c: ldloc.1 - IL_002d: ldc.i4.1 - IL_002e: add - IL_002f: stloc.1 - IL_0030: ldloc.1 - IL_0031: ldc.i4 0x989681 - IL_0036: blt.s IL_0025 - - IL_0038: ret - } - - } - -} - -.class private abstract auto ansi sealed ''.$assembly$fsx - extends [runtime]System.Object -{ - .method public static void main@() cil managed - { - .entrypoint - - .maxstack 8 - IL_0000: ret - } - -} - - - - - - - + IL_000d: stloc.0 + IL_000e: ldc.i4.0 + IL_000f: stloc.1 + IL_0010: br.s IL_001d + + IL_0012: ldloc.0 + IL_0013: call int32 [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/HashCompare::GenericHashIntrinsic(!!0) + IL_0018: stloc.2 + IL_0019: ldloc.1 + IL_001a: ldc.i4.1 + IL_001b: add + IL_001c: stloc.1 + IL_001d: ldloc.1 + IL_001e: ldc.i4 0x989681 + IL_0023: blt.s IL_0012 + + IL_0025: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ListExpressionStepping/ListExpressionStepping02.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ListExpressionStepping/ListExpressionStepping02.fs.il.bsl index 393f87507c5..d7c700d32da 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ListExpressionStepping/ListExpressionStepping02.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ListExpressionStepping/ListExpressionStepping02.fs.il.bsl @@ -67,14 +67,11 @@ Invoke(int32 i) cil managed { - .maxstack 6 - .locals init (int32 V_0) + .maxstack 8 IL_0000: ldc.i4.0 - IL_0001: stloc.0 - IL_0002: ldloc.0 - IL_0003: ldarg.1 - IL_0004: add - IL_0005: ret + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret } .method private specialname rtspecialname static @@ -209,14 +206,11 @@ Invoke(int32 i) cil managed { - .maxstack 6 - .locals init (int32 V_0) + .maxstack 8 IL_0000: ldc.i4.0 - IL_0001: stloc.0 - IL_0002: ldloc.0 - IL_0003: ldarg.1 - IL_0004: add - IL_0005: ret + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret } .method private specialname rtspecialname static @@ -251,14 +245,11 @@ Invoke(int32 i) cil managed { - .maxstack 6 - .locals init (int32 V_0) + .maxstack 8 IL_0000: ldc.i4.0 - IL_0001: stloc.0 - IL_0002: ldloc.0 - IL_0003: ldarg.1 - IL_0004: add - IL_0005: ret + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret } .method private specialname rtspecialname static @@ -421,26 +412,14 @@ .locals init (class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_1, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_2, - int32 V_3, - int32 V_4, - int32 V_5, - int32 V_6, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_7, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_8, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_3, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_4, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_5, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_6, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_7, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_8, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_9, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_10, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_11, - int32 V_12, - int32 V_13, - int32 V_14, - int32 V_15, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_16, - int32 V_17, - int32 V_18, - int32 V_19, - int32 V_20, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_21, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_22) + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> V_10) IL_0000: ldarg.0 IL_0001: ldarg.0 IL_0002: ldarg.0 @@ -452,135 +431,69 @@ IL_0012: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) IL_0017: stloc.1 - IL_0018: nop - IL_0019: ldc.i4.2 - IL_001a: stloc.3 - IL_001b: ldloc.3 - IL_001c: ldc.i4.0 - IL_001d: stloc.s V_4 - IL_001f: ldloc.s V_4 - IL_0021: bge.s IL_002b - - IL_0023: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_0028: nop - IL_0029: br.s IL_0043 - - IL_002b: ldc.i4.2 - IL_002c: stloc.s V_5 - IL_002e: ldloc.s V_5 - IL_0030: ldc.i4.0 - IL_0031: stloc.s V_6 - IL_0033: ldloc.s V_6 - IL_0035: sub - IL_0036: ldc.i4.1 - IL_0037: add - IL_0038: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1'::@_instance - IL_003d: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_0018: ldc.i4.3 + IL_0019: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 input #2 at line 16@1'::@_instance + IL_001e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0042: nop - IL_0043: stloc.2 - IL_0044: ldloc.1 - IL_0045: ldloc.2 - IL_0046: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Zip(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, + IL_0023: stloc.2 + IL_0024: ldloc.1 + IL_0025: ldloc.2 + IL_0026: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Zip(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_004b: stloc.s V_7 - IL_004d: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 stage #2 at line 18@18' class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 stage #2 at line 18@18'::@_instance - IL_0052: ldloc.s V_7 - IL_0054: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`2>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + IL_002b: stloc.3 + IL_002c: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 stage #2 at line 18@18' class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #1 stage #2 at line 18@18'::@_instance + IL_0031: ldloc.3 + IL_0032: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`2>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0059: stloc.s V_8 - IL_005b: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs1@19 class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs1@19::@_instance - IL_0060: ldloc.s V_8 - IL_0062: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`2>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + IL_0037: stloc.s V_4 + IL_0039: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs1@19 class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs1@19::@_instance + IL_003e: ldloc.s V_4 + IL_0040: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`2>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0067: stloc.0 - IL_0068: ldarg.0 - IL_0069: ldarg.0 - IL_006a: ldarg.0 - IL_006b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_0070: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + IL_0045: stloc.0 + IL_0046: ldarg.0 + IL_0047: ldarg.0 + IL_0048: ldarg.0 + IL_0049: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() + IL_004e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0075: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + IL_0053: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_007a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, + IL_0058: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_007f: stloc.s V_10 - IL_0081: nop - IL_0082: ldc.i4.2 - IL_0083: stloc.s V_12 - IL_0085: ldloc.s V_12 - IL_0087: ldc.i4.0 - IL_0088: stloc.s V_13 - IL_008a: ldloc.s V_13 - IL_008c: bge.s IL_0096 - - IL_008e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_0093: nop - IL_0094: br.s IL_00ae - - IL_0096: ldc.i4.2 - IL_0097: stloc.s V_14 - IL_0099: ldloc.s V_14 - IL_009b: ldc.i4.0 - IL_009c: stloc.s V_15 - IL_009e: ldloc.s V_15 - IL_00a0: sub - IL_00a1: ldc.i4.1 - IL_00a2: add - IL_00a3: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1'::@_instance - IL_00a8: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_005d: stloc.s V_6 + IL_005f: ldc.i4.3 + IL_0060: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #2 at line 22@1'::@_instance + IL_0065: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_00ad: nop - IL_00ae: stloc.s V_11 - IL_00b0: nop - IL_00b1: ldc.i4.2 - IL_00b2: stloc.s V_17 - IL_00b4: ldloc.s V_17 - IL_00b6: ldc.i4.0 - IL_00b7: stloc.s V_18 - IL_00b9: ldloc.s V_18 - IL_00bb: bge.s IL_00c5 - - IL_00bd: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_00c2: nop - IL_00c3: br.s IL_00dd - - IL_00c5: ldc.i4.2 - IL_00c6: stloc.s V_19 - IL_00c8: ldloc.s V_19 - IL_00ca: ldc.i4.0 - IL_00cb: stloc.s V_20 - IL_00cd: ldloc.s V_20 - IL_00cf: sub - IL_00d0: ldc.i4.1 - IL_00d1: add - IL_00d2: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1'::@_instance - IL_00d7: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + IL_006a: stloc.s V_7 + IL_006c: ldc.i4.3 + IL_006d: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1' ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 input #3 at line 22@1'::@_instance + IL_0072: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_00dc: nop - IL_00dd: stloc.s V_16 - IL_00df: ldloc.s V_10 - IL_00e1: ldloc.s V_11 - IL_00e3: ldloc.s V_16 - IL_00e5: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Zip3(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, + IL_0077: stloc.s V_8 + IL_0079: ldloc.s V_6 + IL_007b: ldloc.s V_7 + IL_007d: ldloc.s V_8 + IL_007f: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Zip3(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_00ea: stloc.s V_21 - IL_00ec: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 stage #2 at line 24@24' class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 stage #2 at line 24@24'::@_instance - IL_00f1: ldloc.s V_21 - IL_00f3: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`3>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + IL_0084: stloc.s V_9 + IL_0086: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 stage #2 at line 24@24' class ListExpressionSteppingTest2/ListExpressionSteppingTest2/'Pipe #2 stage #2 at line 24@24'::@_instance + IL_008b: ldloc.s V_9 + IL_008d: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`3>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_00f8: stloc.s V_22 - IL_00fa: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs2@25 class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs2@25::@_instance - IL_00ff: ldloc.s V_22 - IL_0101: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`3>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + IL_0092: stloc.s V_10 + IL_0094: ldsfld class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs2@25 class ListExpressionSteppingTest2/ListExpressionSteppingTest2/xs2@25::@_instance + IL_0099: ldloc.s V_10 + IL_009b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map,class [runtime]System.Tuple`3>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0106: stloc.s V_9 - IL_0108: ldloc.0 - IL_0109: ldloc.s V_9 - IL_010b: newobj instance void class [runtime]System.Tuple`2>,class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>>::.ctor(!0, + IL_00a0: stloc.s V_5 + IL_00a2: ldloc.0 + IL_00a3: ldloc.s V_5 + IL_00a5: newobj instance void class [runtime]System.Tuple`2>,class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>>::.ctor(!0, !1) - IL_0110: ret + IL_00aa: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/CodeGenRenamings01.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/CodeGenRenamings01.fs.il.bsl index 2b6f2b17ed0..50ad7127fe0 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/CodeGenRenamings01.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/CodeGenRenamings01.fs.il.bsl @@ -63,14 +63,11 @@ Invoke(int32 i) cil managed { - .maxstack 6 - .locals init (int32 V_0) + .maxstack 8 IL_0000: ldc.i4.1 - IL_0001: stloc.0 - IL_0002: ldloc.0 - IL_0003: ldarg.1 - IL_0004: add - IL_0005: ret + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret } .method private specialname rtspecialname static @@ -456,290 +453,264 @@ int32[] V_9, int32[] V_10, int32 V_11, - int32 V_12, - int32 V_13, + class [runtime]System.Tuple`4 V_12, + class [runtime]System.Tuple`4 V_13, int32 V_14, - int32 V_15, - class [runtime]System.Tuple`4 V_16, - class [runtime]System.Tuple`4 V_17, - int32 V_18, - class [runtime]System.Tuple`3 V_19, - class [runtime]System.Tuple`3 V_20, - int32 V_21, - class [runtime]System.Tuple`4 V_22, - class [runtime]System.Tuple`4 V_23, - int32 V_24) - IL_0000: nop - IL_0001: ldc.i4.s 10 - IL_0003: stloc.s V_11 - IL_0005: ldloc.s V_11 - IL_0007: ldc.i4.1 - IL_0008: stloc.s V_12 - IL_000a: ldloc.s V_12 - IL_000c: bge.s IL_0016 - - IL_000e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_0013: nop - IL_0014: br.s IL_002f - - IL_0016: ldc.i4.s 10 - IL_0018: stloc.s V_13 - IL_001a: ldloc.s V_13 - IL_001c: ldc.i4.1 - IL_001d: stloc.s V_14 - IL_001f: ldloc.s V_14 - IL_0021: sub - IL_0022: ldc.i4.1 - IL_0023: add - IL_0024: ldsfld class assembly/alist@1 assembly/alist@1::@_instance - IL_0029: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [runtime]System.Tuple`3 V_15, + class [runtime]System.Tuple`3 V_16, + int32 V_17, + class [runtime]System.Tuple`4 V_18, + class [runtime]System.Tuple`4 V_19, + int32 V_20) + IL_0000: ldc.i4.s 10 + IL_0002: ldsfld class assembly/alist@1 assembly/alist@1::@_instance + IL_0007: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_002e: nop - IL_002f: dup - IL_0030: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::alist@5 - IL_0035: stloc.0 - IL_0036: ldc.i4.3 - IL_0037: newarr [runtime]System.Int32 - IL_003c: dup - IL_003d: ldc.i4.0 - IL_003e: ldc.i4.1 - IL_003f: stelem [runtime]System.Int32 - IL_0044: dup - IL_0045: ldc.i4.1 - IL_0046: ldc.i4.2 - IL_0047: stelem [runtime]System.Int32 - IL_004c: dup - IL_004d: ldc.i4.2 - IL_004e: ldc.i4.3 - IL_004f: stelem [runtime]System.Int32 - IL_0054: dup - IL_0055: stsfld int32[] ''.$assembly::array@6 - IL_005a: stloc.1 - IL_005b: ldc.i4.1 - IL_005c: ldc.i4.1 - IL_005d: ldc.i4.s 10 - IL_005f: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, + IL_000c: dup + IL_000d: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 ''.$assembly::alist@5 + IL_0012: stloc.0 + IL_0013: ldc.i4.3 + IL_0014: newarr [runtime]System.Int32 + IL_0019: dup + IL_001a: ldc.i4.0 + IL_001b: ldc.i4.1 + IL_001c: stelem [runtime]System.Int32 + IL_0021: dup + IL_0022: ldc.i4.1 + IL_0023: ldc.i4.2 + IL_0024: stelem [runtime]System.Int32 + IL_0029: dup + IL_002a: ldc.i4.2 + IL_002b: ldc.i4.3 + IL_002c: stelem [runtime]System.Int32 + IL_0031: dup + IL_0032: stsfld int32[] ''.$assembly::array@6 + IL_0037: stloc.1 + IL_0038: ldc.i4.1 + IL_0039: ldc.i4.1 + IL_003a: ldc.i4.s 10 + IL_003c: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators/OperatorIntrinsics::RangeInt32(int32, int32, int32) - IL_0064: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0069: dup - IL_006a: stsfld class [runtime]System.Collections.Generic.IEnumerable`1 ''.$assembly::aseq@7 - IL_006f: stloc.2 - IL_0070: ldc.i4.1 - IL_0071: ldc.i4.1 - IL_0072: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, + IL_0041: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Core.Operators::CreateSequence(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0046: dup + IL_0047: stsfld class [runtime]System.Collections.Generic.IEnumerable`1 ''.$assembly::aseq@7 + IL_004c: stloc.2 + IL_004d: ldc.i4.1 + IL_004e: ldc.i4.1 + IL_004f: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, !1) - IL_0077: ldc.i4.2 - IL_0078: ldc.i4.2 - IL_0079: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, + IL_0054: ldc.i4.2 + IL_0055: ldc.i4.2 + IL_0056: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, !1) - IL_007e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::get_Empty() - IL_0083: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::Cons(!0, + IL_005b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::get_Empty() + IL_0060: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0088: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::Cons(!0, + IL_0065: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>::Cons(!0, class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_008d: dup - IL_008e: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> ''.$assembly::list1@8 - IL_0093: stloc.3 - IL_0094: ldc.i4.0 - IL_0095: ldnull - IL_0096: newobj instance void assembly/seq1@9::.ctor(int32, + IL_006a: dup + IL_006b: stsfld class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> ''.$assembly::list1@8 + IL_0070: stloc.3 + IL_0071: ldc.i4.0 + IL_0072: ldnull + IL_0073: newobj instance void assembly/seq1@9::.ctor(int32, class [runtime]System.Tuple`2) - IL_009b: dup - IL_009c: stsfld class [runtime]System.Collections.Generic.IEnumerable`1> ''.$assembly::seq1@9 - IL_00a1: stloc.s V_4 - IL_00a3: ldc.i4.2 - IL_00a4: newarr class [runtime]System.Tuple`2 - IL_00a9: dup - IL_00aa: ldc.i4.0 - IL_00ab: ldc.i4.1 - IL_00ac: ldc.i4.1 - IL_00ad: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, + IL_0078: dup + IL_0079: stsfld class [runtime]System.Collections.Generic.IEnumerable`1> ''.$assembly::seq1@9 + IL_007e: stloc.s V_4 + IL_0080: ldc.i4.2 + IL_0081: newarr class [runtime]System.Tuple`2 + IL_0086: dup + IL_0087: ldc.i4.0 + IL_0088: ldc.i4.1 + IL_0089: ldc.i4.1 + IL_008a: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, !1) - IL_00b2: stelem class [runtime]System.Tuple`2 - IL_00b7: dup - IL_00b8: ldc.i4.1 - IL_00b9: ldc.i4.2 - IL_00ba: ldc.i4.2 - IL_00bb: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, + IL_008f: stelem class [runtime]System.Tuple`2 + IL_0094: dup + IL_0095: ldc.i4.1 + IL_0096: ldc.i4.2 + IL_0097: ldc.i4.2 + IL_0098: newobj instance void class [runtime]System.Tuple`2::.ctor(!0, !1) - IL_00c0: stelem class [runtime]System.Tuple`2 - IL_00c5: dup - IL_00c6: stsfld class [runtime]System.Tuple`2[] ''.$assembly::array1@10 - IL_00cb: stloc.s V_5 - IL_00cd: ldc.i4.2 - IL_00ce: ldc.i4.2 - IL_00cf: ldc.i4.0 - IL_00d0: call !!0[0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Create(int32, + IL_009d: stelem class [runtime]System.Tuple`2 + IL_00a2: dup + IL_00a3: stsfld class [runtime]System.Tuple`2[] ''.$assembly::array1@10 + IL_00a8: stloc.s V_5 + IL_00aa: ldc.i4.2 + IL_00ab: ldc.i4.2 + IL_00ac: ldc.i4.0 + IL_00ad: call !!0[0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Create(int32, int32, !!0) - IL_00d5: dup - IL_00d6: stsfld int32[0...,0...] ''.$assembly::a3@11 - IL_00db: stloc.s V_6 - IL_00dd: ldc.i4.3 - IL_00de: ldc.i4.3 - IL_00df: ldc.i4.3 - IL_00e0: ldc.i4.0 - IL_00e1: call !!0[0...,0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Create(int32, + IL_00b2: dup + IL_00b3: stsfld int32[0...,0...] ''.$assembly::a3@11 + IL_00b8: stloc.s V_6 + IL_00ba: ldc.i4.3 + IL_00bb: ldc.i4.3 + IL_00bc: ldc.i4.3 + IL_00bd: ldc.i4.0 + IL_00be: call !!0[0...,0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Create(int32, int32, int32, !!0) - IL_00e6: dup - IL_00e7: stsfld int32[0...,0...,0...] ''.$assembly::array3D@12 - IL_00ec: stloc.s V_7 - IL_00ee: ldc.i4.4 - IL_00ef: ldc.i4.4 - IL_00f0: ldc.i4.4 - IL_00f1: ldc.i4.4 - IL_00f2: ldc.i4.0 - IL_00f3: call !!0[0...,0...,0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Create(int32, + IL_00c3: dup + IL_00c4: stsfld int32[0...,0...,0...] ''.$assembly::array3D@12 + IL_00c9: stloc.s V_7 + IL_00cb: ldc.i4.4 + IL_00cc: ldc.i4.4 + IL_00cd: ldc.i4.4 + IL_00ce: ldc.i4.4 + IL_00cf: ldc.i4.0 + IL_00d0: call !!0[0...,0...,0...,0...] [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Create(int32, int32, int32, int32, !!0) - IL_00f8: dup - IL_00f9: stsfld int32[0...,0...,0...,0...] ''.$assembly::array4D@13 - IL_00fe: stloc.s V_8 - IL_0100: call int32[] assembly::get_array() - IL_0105: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::OfArray(!!0[]) - IL_010a: pop - IL_010b: call class [runtime]System.Collections.Generic.IEnumerable`1 assembly::get_aseq() - IL_0110: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0115: pop - IL_0116: call class [runtime]System.Tuple`2[] assembly::get_array1() - IL_011b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfArray(class [runtime]System.Tuple`2[]) - IL_0120: pop - IL_0121: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> assembly::get_list1() - IL_0126: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfList(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>) - IL_012b: pop - IL_012c: call class [runtime]System.Collections.Generic.IEnumerable`1> assembly::get_seq1() - IL_0131: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1>) - IL_0136: pop - IL_0137: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_alist() - IL_013c: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::OfList(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0141: dup - IL_0142: stsfld int32[] ''.$assembly::a1@25 - IL_0147: stloc.s V_9 - IL_0149: call class [runtime]System.Collections.Generic.IEnumerable`1 assembly::get_aseq() - IL_014e: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1) - IL_0153: dup - IL_0154: stsfld int32[] ''.$assembly::a2@26 - IL_0159: stloc.s V_10 - IL_015b: call int32[] assembly::get_a1() - IL_0160: ldc.i4.0 - IL_0161: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Get(!!0[], + IL_00d5: dup + IL_00d6: stsfld int32[0...,0...,0...,0...] ''.$assembly::array4D@13 + IL_00db: stloc.s V_8 + IL_00dd: call int32[] assembly::get_array() + IL_00e2: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::OfArray(!!0[]) + IL_00e7: pop + IL_00e8: call class [runtime]System.Collections.Generic.IEnumerable`1 assembly::get_aseq() + IL_00ed: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_00f2: pop + IL_00f3: call class [runtime]System.Tuple`2[] assembly::get_array1() + IL_00f8: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfArray(class [runtime]System.Tuple`2[]) + IL_00fd: pop + IL_00fe: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1> assembly::get_list1() + IL_0103: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfList(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1>) + IL_0108: pop + IL_0109: call class [runtime]System.Collections.Generic.IEnumerable`1> assembly::get_seq1() + IL_010e: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpMap`2 [FSharp.Core]Microsoft.FSharp.Collections.MapModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1>) + IL_0113: pop + IL_0114: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 assembly::get_alist() + IL_0119: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::OfList(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_011e: dup + IL_011f: stsfld int32[] ''.$assembly::a1@25 + IL_0124: stloc.s V_9 + IL_0126: call class [runtime]System.Collections.Generic.IEnumerable`1 assembly::get_aseq() + IL_012b: call !!0[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::OfSeq(class [runtime]System.Collections.Generic.IEnumerable`1) + IL_0130: dup + IL_0131: stsfld int32[] ''.$assembly::a2@26 + IL_0136: stloc.s V_10 + IL_0138: call int32[] assembly::get_a1() + IL_013d: ldc.i4.0 + IL_013e: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Get(!!0[], int32) - IL_0166: stloc.s V_15 - IL_0168: call int32[] assembly::get_a2() - IL_016d: ldc.i4.0 - IL_016e: ldloc.s V_15 - IL_0170: call void [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Set(!!0[], + IL_0143: stloc.s V_11 + IL_0145: call int32[] assembly::get_a2() + IL_014a: ldc.i4.0 + IL_014b: ldloc.s V_11 + IL_014d: call void [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Set(!!0[], int32, !!0) - IL_0175: nop - IL_0176: call int32[0...,0...] assembly::get_a3() - IL_017b: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Length1(!!0[0...,0...]) - IL_0180: call int32[0...,0...] assembly::get_a3() - IL_0185: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Length2(!!0[0...,0...]) - IL_018a: call int32[0...,0...] assembly::get_a3() - IL_018f: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Base1(!!0[0...,0...]) - IL_0194: call int32[0...,0...] assembly::get_a3() - IL_0199: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Base2(!!0[0...,0...]) - IL_019e: newobj instance void class [runtime]System.Tuple`4::.ctor(!0, + IL_0152: nop + IL_0153: call int32[0...,0...] assembly::get_a3() + IL_0158: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Length1(!!0[0...,0...]) + IL_015d: call int32[0...,0...] assembly::get_a3() + IL_0162: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Length2(!!0[0...,0...]) + IL_0167: call int32[0...,0...] assembly::get_a3() + IL_016c: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Base1(!!0[0...,0...]) + IL_0171: call int32[0...,0...] assembly::get_a3() + IL_0176: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Base2(!!0[0...,0...]) + IL_017b: newobj instance void class [runtime]System.Tuple`4::.ctor(!0, !1, !2, !3) - IL_01a3: stloc.s V_16 - IL_01a5: ldloc.s V_16 - IL_01a7: stloc.s V_17 - IL_01a9: call int32[0...,0...] assembly::get_a3() - IL_01ae: ldc.i4.0 - IL_01af: ldc.i4.0 - IL_01b0: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Get(!!0[0...,0...], + IL_0180: stloc.s V_12 + IL_0182: ldloc.s V_12 + IL_0184: stloc.s V_13 + IL_0186: call int32[0...,0...] assembly::get_a3() + IL_018b: ldc.i4.0 + IL_018c: ldc.i4.0 + IL_018d: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Get(!!0[0...,0...], int32, int32) - IL_01b5: stloc.s V_18 - IL_01b7: call int32[0...,0...] assembly::get_a3() - IL_01bc: ldc.i4.0 - IL_01bd: ldc.i4.0 - IL_01be: ldloc.s V_18 - IL_01c0: call void [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Set(!!0[0...,0...], + IL_0192: stloc.s V_14 + IL_0194: call int32[0...,0...] assembly::get_a3() + IL_0199: ldc.i4.0 + IL_019a: ldc.i4.0 + IL_019b: ldloc.s V_14 + IL_019d: call void [FSharp.Core]Microsoft.FSharp.Collections.Array2DModule::Set(!!0[0...,0...], int32, int32, !!0) - IL_01c5: nop - IL_01c6: call int32[0...,0...,0...] assembly::get_array3D() - IL_01cb: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length1(!!0[0...,0...,0...]) - IL_01d0: call int32[0...,0...,0...] assembly::get_array3D() - IL_01d5: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length2(!!0[0...,0...,0...]) - IL_01da: call int32[0...,0...,0...] assembly::get_array3D() - IL_01df: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length3(!!0[0...,0...,0...]) - IL_01e4: newobj instance void class [runtime]System.Tuple`3::.ctor(!0, + IL_01a2: nop + IL_01a3: call int32[0...,0...,0...] assembly::get_array3D() + IL_01a8: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length1(!!0[0...,0...,0...]) + IL_01ad: call int32[0...,0...,0...] assembly::get_array3D() + IL_01b2: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length2(!!0[0...,0...,0...]) + IL_01b7: call int32[0...,0...,0...] assembly::get_array3D() + IL_01bc: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Length3(!!0[0...,0...,0...]) + IL_01c1: newobj instance void class [runtime]System.Tuple`3::.ctor(!0, !1, !2) - IL_01e9: stloc.s V_19 - IL_01eb: ldloc.s V_19 - IL_01ed: stloc.s V_20 - IL_01ef: call int32[0...,0...,0...] assembly::get_array3D() - IL_01f4: ldc.i4.0 - IL_01f5: ldc.i4.0 - IL_01f6: ldc.i4.0 - IL_01f7: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Get(!!0[0...,0...,0...], + IL_01c6: stloc.s V_15 + IL_01c8: ldloc.s V_15 + IL_01ca: stloc.s V_16 + IL_01cc: call int32[0...,0...,0...] assembly::get_array3D() + IL_01d1: ldc.i4.0 + IL_01d2: ldc.i4.0 + IL_01d3: ldc.i4.0 + IL_01d4: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Get(!!0[0...,0...,0...], int32, int32, int32) - IL_01fc: stloc.s V_21 - IL_01fe: call int32[0...,0...,0...] assembly::get_array3D() - IL_0203: ldc.i4.0 - IL_0204: ldc.i4.0 - IL_0205: ldc.i4.0 - IL_0206: ldloc.s V_21 - IL_0208: call void [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Set(!!0[0...,0...,0...], + IL_01d9: stloc.s V_17 + IL_01db: call int32[0...,0...,0...] assembly::get_array3D() + IL_01e0: ldc.i4.0 + IL_01e1: ldc.i4.0 + IL_01e2: ldc.i4.0 + IL_01e3: ldloc.s V_17 + IL_01e5: call void [FSharp.Core]Microsoft.FSharp.Collections.Array3DModule::Set(!!0[0...,0...,0...], int32, int32, int32, !!0) - IL_020d: nop - IL_020e: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_0213: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length1(!!0[0...,0...,0...,0...]) - IL_0218: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_021d: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length2(!!0[0...,0...,0...,0...]) - IL_0222: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_0227: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length3(!!0[0...,0...,0...,0...]) - IL_022c: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_0231: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length4(!!0[0...,0...,0...,0...]) - IL_0236: newobj instance void class [runtime]System.Tuple`4::.ctor(!0, + IL_01ea: nop + IL_01eb: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_01f0: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length1(!!0[0...,0...,0...,0...]) + IL_01f5: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_01fa: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length2(!!0[0...,0...,0...,0...]) + IL_01ff: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_0204: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length3(!!0[0...,0...,0...,0...]) + IL_0209: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_020e: call int32 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Length4(!!0[0...,0...,0...,0...]) + IL_0213: newobj instance void class [runtime]System.Tuple`4::.ctor(!0, !1, !2, !3) - IL_023b: stloc.s V_22 - IL_023d: ldloc.s V_22 - IL_023f: stloc.s V_23 - IL_0241: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_0246: ldc.i4.0 - IL_0247: ldc.i4.0 - IL_0248: ldc.i4.0 - IL_0249: ldc.i4.0 - IL_024a: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Get(!!0[0...,0...,0...,0...], + IL_0218: stloc.s V_18 + IL_021a: ldloc.s V_18 + IL_021c: stloc.s V_19 + IL_021e: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_0223: ldc.i4.0 + IL_0224: ldc.i4.0 + IL_0225: ldc.i4.0 + IL_0226: ldc.i4.0 + IL_0227: call !!0 [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Get(!!0[0...,0...,0...,0...], int32, int32, int32, int32) - IL_024f: stloc.s V_24 - IL_0251: call int32[0...,0...,0...,0...] assembly::get_array4D() - IL_0256: ldc.i4.0 - IL_0257: ldc.i4.0 - IL_0258: ldc.i4.0 - IL_0259: ldc.i4.0 - IL_025a: ldloc.s V_24 - IL_025c: call void [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Set(!!0[0...,0...,0...,0...], + IL_022c: stloc.s V_20 + IL_022e: call int32[0...,0...,0...,0...] assembly::get_array4D() + IL_0233: ldc.i4.0 + IL_0234: ldc.i4.0 + IL_0235: ldc.i4.0 + IL_0236: ldc.i4.0 + IL_0237: ldloc.s V_20 + IL_0239: call void [FSharp.Core]Microsoft.FSharp.Collections.Array4DModule::Set(!!0[0...,0...,0...,0...], int32, int32, int32, int32, !!0) - IL_0261: nop - IL_0262: ret + IL_023e: nop + IL_023f: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ForLoop01.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ForLoop01.fs.il.bsl index 87312556b8e..04cb7bed5c4 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ForLoop01.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/Misc/ForLoop01.fs.il.bsl @@ -63,14 +63,11 @@ Invoke(int32 i) cil managed { - .maxstack 6 - .locals init (int32 V_0) + .maxstack 8 IL_0000: ldc.i4.1 - IL_0001: stloc.0 - IL_0002: ldloc.0 - IL_0003: ldarg.1 - IL_0004: add - IL_0005: ret + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret } .method private specialname rtspecialname static @@ -100,62 +97,36 @@ .maxstack 4 .locals init (class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_0, - int32 V_1, - int32 V_2, - int32 V_3, - int32 V_4, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_5, - int32 V_6) - IL_0000: nop - IL_0001: ldc.i4.3 - IL_0002: stloc.1 - IL_0003: ldloc.1 - IL_0004: ldc.i4.1 - IL_0005: stloc.2 - IL_0006: ldloc.2 - IL_0007: bge.s IL_0011 - - IL_0009: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_Empty() - IL_000e: nop - IL_000f: br.s IL_0027 - - IL_0011: ldc.i4.3 - IL_0012: stloc.3 - IL_0013: ldloc.3 - IL_0014: ldc.i4.1 - IL_0015: stloc.s V_4 - IL_0017: ldloc.s V_4 - IL_0019: sub - IL_001a: ldc.i4.1 - IL_001b: add - IL_001c: ldsfld class assembly/clo@1 assembly/clo@1::@_instance - IL_0021: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_1, + int32 V_2) + IL_0000: ldc.i4.3 + IL_0001: ldsfld class assembly/clo@1 assembly/clo@1::@_instance + IL_0006: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Initialize(int32, class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0026: nop - IL_0027: stloc.0 - IL_0028: ldloc.0 - IL_0029: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() - IL_002e: stloc.s V_5 - IL_0030: br.s IL_005c - - IL_0032: ldloc.0 - IL_0033: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() - IL_0038: stloc.s V_6 - IL_003a: ldstr "%A" - IL_003f: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit,int32>::.ctor(string) - IL_0044: call !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine>(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4) - IL_0049: ldloc.s V_6 - IL_004b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_0050: pop - IL_0051: ldloc.s V_5 - IL_0053: stloc.0 - IL_0054: ldloc.0 - IL_0055: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() - IL_005a: stloc.s V_5 - IL_005c: ldloc.s V_5 - IL_005e: brtrue.s IL_0032 - - IL_0060: ret + IL_000b: stloc.0 + IL_000c: ldloc.0 + IL_000d: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0012: stloc.1 + IL_0013: br.s IL_003b + + IL_0015: ldloc.0 + IL_0016: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_001b: stloc.2 + IL_001c: ldstr "%A" + IL_0021: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit,int32>::.ctor(string) + IL_0026: call !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine>(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4) + IL_002b: ldloc.2 + IL_002c: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0031: pop + IL_0032: ldloc.1 + IL_0033: stloc.0 + IL_0034: ldloc.0 + IL_0035: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_003a: stloc.1 + IL_003b: ldloc.1 + IL_003c: brtrue.s IL_0015 + + IL_003e: ret } }