From 3efce6f2777560917fec5ee082c60915f4741a05 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Thu, 18 Apr 2024 11:40:04 -0400 Subject: [PATCH 01/10] Gather up any prelude & reapply after lowering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * E.g., ```fsharp [let y = f () in for … in … -> …] ``` and ```fsharp [f (); g (); for … in … -> …] ``` are transformed into something like ```fsharp let y = f () in [for … in … -> …] ``` and ```fsharp f (); g (); [for … in … -> …] ``` so that the existing pattern recognition of simple mappings and integral ranges may succeed. --- .../Optimize/LowerComputedCollections.fs | 74 +++++++++++++------ 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 5d755daf4b1..52a4c13859d 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -426,6 +426,36 @@ let (|SimpleSequential|_|) g expr = loop expr Expr.Sequential +/// Extracts any let-bindings or sequential +/// expressions that directly precede the specified mapping application, e.g., +/// +/// [let y = f () in for … in … -> …] +/// +/// [f (); g (); for … in … -> …] +/// +/// Returns a function that will re-prefix the prelude to the +/// lowered mapping, as well as the mapping to lower, i.e., +/// to transform the above into something like: +/// +/// let y = f () in [for … in … -> …] +/// +/// f (); g (); [for … in … -> …] +let gatherPrelude ((|App|_|) : _ -> _ voption) expr = + let rec loop expr cont = + match expr with + | Expr.Let (binding, DebugPoints (body, debug), m, frees) -> + loop body (cont << fun body -> Expr.Let (binding, debug body, m, frees)) + + | Expr.Sequential (expr1, DebugPoints (body, debug), kind, m) -> + loop body (cont << fun body -> Expr.Sequential (expr1, debug body, kind, m)) + + | App contents -> + ValueSome (cont, contents) + + | _ -> ValueNone + + loop expr id + /// The representation used for /// /// for … in … -> … @@ -434,21 +464,23 @@ let (|SimpleSequential|_|) g expr = /// /// for … in … do yield … [] -let (|SeqMap|_|) g expr = - match expr with - | ValApp g g.seq_map_vref ([ty1; ty2], [Expr.Lambda (valParams = [loopVal]; bodyExpr = body) as mapping; input], _) -> - ValueSome (ty1, ty2, input, mapping, loopVal, body) - | _ -> ValueNone +let (|SeqMap|_|) g = + gatherPrelude (function + | ValApp g g.seq_map_vref ([ty1; ty2], [Expr.Lambda (valParams = [loopVal]; bodyExpr = body) as mapping; input], _) -> + ValueSome (ty1, ty2, input, mapping, loopVal, body) + + | _ -> ValueNone) /// The representation used for /// /// for … in … do f (); …; yield … [] -let (|SeqCollectSingle|_|) g expr = - match expr with - | ValApp g g.seq_collect_vref ([ty1; _; ty2], [Expr.Lambda (valParams = [loopVal]; bodyExpr = SimpleSequential g body) as mapping; input], _) -> - ValueSome (ty1, ty2, input, mapping, loopVal, body) - | _ -> ValueNone +let (|SeqCollectSingle|_|) g = + gatherPrelude (function + | ValApp g g.seq_collect_vref ([ty1; _; ty2], [Expr.Lambda (valParams = [loopVal]; bodyExpr = SimpleSequential g body) as mapping; input], _) -> + ValueSome (ty1, ty2, input, mapping, loopVal, body) + + | _ -> ValueNone) /// for … in … -> … /// for … in … do yield … @@ -458,11 +490,11 @@ let (|SimpleMapping|_|) g expr = match expr with // for … in … -> … // for … in … do yield … - | ValApp g g.seq_delay_vref (_, [Expr.Lambda (bodyExpr = SeqMap g (ty1, ty2, input, mapping, loopVal, body))], _) + | ValApp g g.seq_delay_vref (_, [Expr.Lambda (bodyExpr = DebugPoints (SeqMap g (cont, (ty1, ty2, input, mapping, loopVal, body)), debug))], _) // for … in … do f (); …; yield … - | ValApp g g.seq_delay_vref (_, [Expr.Lambda (bodyExpr = SeqCollectSingle g (ty1, ty2, input, mapping, loopVal, body))], _) -> - ValueSome (ty1, ty2, input, mapping, loopVal, body) + | ValApp g g.seq_delay_vref (_, [Expr.Lambda (bodyExpr = DebugPoints (SeqCollectSingle g (cont, (ty1, ty2, input, mapping, loopVal, body)), debug))], _) -> + ValueSome (debug >> cont, (ty1, ty2, input, mapping, loopVal, body)) | _ -> ValueNone @@ -484,10 +516,10 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap ilTyForTy overallExpr | SeqToList g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> match overallSeqExpr with // [for … in xs -> …] (* When xs is a list. *) - | SimpleMapping g (ty1, ty2, List g list, mapping, _, _) when + | SimpleMapping g (cont, (ty1, ty2, List g list, mapping, _, _)) when g.langVersion.SupportsFeature LanguageFeature.LowerSimpleMappingsInComprehensionsToDirectCallsToMap -> - Some (mkCallListMap g m ty1 ty2 mapping list) + Some (cont (mkCallListMap g m ty1 ty2 mapping list)) // [start..finish] // [start..step..finish] @@ -498,10 +530,10 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap ilTyForTy overallExpr // [for … in start..finish -> …] // [for … in start..step..finish -> …] - | SimpleMapping g (_, _, rangeExpr & IntegralRange g (rangeTy, (start, step, finish)), _, loopVal, body) when + | SimpleMapping g (cont, (_, _, rangeExpr & DebugPoints (IntegralRange g (rangeTy, (start, step, finish)), debug), _, loopVal, body)) when g.langVersion.SupportsFeature LanguageFeature.LowerIntegralRangesToFastLoops -> - Some (List.mkFromIntegralRange tcVal g amap m rangeTy overallElemTy rangeExpr start step finish (Some (loopVal, body))) + Some (cont (debug (List.mkFromIntegralRange tcVal g amap m rangeTy overallElemTy rangeExpr start step finish (Some (loopVal, body))))) // [(* Anything more complex. *)] | _ -> @@ -512,10 +544,10 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap ilTyForTy overallExpr | SeqToArray g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> match overallSeqExpr with // [|for … in xs -> …|] (* When xs is an array. *) - | SimpleMapping g (ty1, ty2, Array g array, mapping, _, _) when + | SimpleMapping g (cont, (ty1, ty2, Array g array, mapping, _, _)) when g.langVersion.SupportsFeature LanguageFeature.LowerSimpleMappingsInComprehensionsToDirectCallsToMap -> - Some (mkCallArrayMap g m ty1 ty2 mapping array) + Some (cont (mkCallArrayMap g m ty1 ty2 mapping array)) // [|start..finish|] // [|start..step..finish|] @@ -526,10 +558,10 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap ilTyForTy overallExpr // [|for … in start..finish -> …|] // [|for … in start..step..finish -> …|] - | SimpleMapping g (_, _, rangeExpr & IntegralRange g (rangeTy, (start, step, finish)), _, loopVal, body) when + | SimpleMapping g (cont, (_, _, rangeExpr & DebugPoints (IntegralRange g (rangeTy, (start, step, finish)), debug), _, loopVal, body)) when g.langVersion.SupportsFeature LanguageFeature.LowerIntegralRangesToFastLoops -> - Some (Array.mkFromIntegralRange g m rangeTy (ilTyForTy overallElemTy) overallElemTy rangeExpr start step finish (Some (loopVal, body))) + Some (cont (debug (Array.mkFromIntegralRange g m rangeTy (ilTyForTy overallElemTy) overallElemTy rangeExpr start step finish (Some (loopVal, body))))) // [|(* Anything more complex. *)|] | _ -> From 068ad30a1f5f848aa18394735e440a23ed18cacf Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Thu, 18 Apr 2024 11:43:42 -0400 Subject: [PATCH 02/10] Add prelude tests & update baselines --- .../ComputedCollections/ForNInRangeArrays.fs | 5 + .../ForNInRangeArrays.fs.il.bsl | 236 +++++++++++++++ .../ComputedCollections/ForNInRangeLists.fs | 5 + .../ForNInRangeLists.fs.il.bsl | 220 ++++++++++++++ .../ForXInArray_ToArray.fs | 5 + .../ForXInArray_ToArray.fs.il.bsl | 245 +++++++++++++++ .../ComputedCollections/ForXInArray_ToList.fs | 5 + .../ForXInArray_ToList.fs.il.bsl | 280 ++++++++++++++++++ .../ComputedCollections/ForXInList_ToArray.fs | 5 + .../ForXInList_ToArray.fs.il.bsl | 276 +++++++++++++++++ .../ComputedCollections/ForXInList_ToList.fs | 5 + .../ForXInList_ToList.fs.il.bsl | 249 ++++++++++++++++ .../ComputedCollections/ForXInSeq_ToArray.fs | 5 + .../ForXInSeq_ToArray.fs.il.bsl | 276 +++++++++++++++++ .../ComputedCollections/ForXInSeq_ToList.fs | 5 + .../ForXInSeq_ToList.fs.il.bsl | 280 ++++++++++++++++++ 16 files changed, 2102 insertions(+) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeArrays.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeArrays.fs index 5e2867fae3a..e2466ab7f5f 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeArrays.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeArrays.fs @@ -30,3 +30,8 @@ let f25 f g h = [|for n in f ()..g ()..h () -> n|] let f26 start step finish = [|for n in start..step..finish -> n, float n|] let f27 start step finish = [|for n in start..step..finish -> struct (n, float n)|] let f28 start step finish = [|for n in start..step..finish -> let x = n + 1 in n * n|] + +let f29 f g = [|let y = f () in let z = g () in for x in 1..2..10 -> x + y + z|] +let f30 f g = [|let y = f () in g (); for x in 1..2..10 -> x + y|] +let f31 f g = [|f (); g (); for x in 1..2..10 -> x|] +let f32 f g = [|f (); let y = g () in for x in 1..2..10 -> x + y|] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeArrays.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeArrays.fs.il.bsl index 2d2e4a99be3..980616689ba 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeArrays.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeArrays.fs.il.bsl @@ -2431,6 +2431,242 @@ IL_007a: ret } + .method public static int32[] f29(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g) 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 6 + .locals init (int32 V_0, + int32 V_1, + int32[] V_2, + uint64 V_3, + int32 V_4, + int32 V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.0 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.1 + IL_0011: ldc.i4.5 + IL_0012: conv.i8 + IL_0013: conv.ovf.i.un + IL_0014: newarr [runtime]System.Int32 + IL_0019: stloc.2 + IL_001a: ldc.i4.0 + IL_001b: conv.i8 + IL_001c: stloc.3 + IL_001d: ldc.i4.1 + IL_001e: stloc.s V_4 + IL_0020: br.s IL_003b + + IL_0022: ldloc.2 + IL_0023: ldloc.3 + IL_0024: conv.i + IL_0025: ldloc.s V_4 + IL_0027: stloc.s V_5 + IL_0029: ldloc.s V_5 + IL_002b: ldloc.0 + IL_002c: add + IL_002d: ldloc.1 + IL_002e: add + IL_002f: stelem.i4 + IL_0030: ldloc.s V_4 + IL_0032: ldc.i4.2 + IL_0033: add + IL_0034: stloc.s V_4 + IL_0036: ldloc.3 + IL_0037: ldc.i4.1 + IL_0038: conv.i8 + IL_0039: add + IL_003a: stloc.3 + IL_003b: ldloc.3 + IL_003c: ldc.i4.5 + IL_003d: conv.i8 + IL_003e: blt.un.s IL_0022 + + IL_0040: ldloc.2 + IL_0041: ret + } + + .method public static int32[] f30(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g) 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 6 + .locals init (int32 V_0, + int32[] V_1, + uint64 V_2, + int32 V_3, + int32 V_4) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.0 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: ldc.i4.5 + IL_0012: conv.i8 + IL_0013: conv.ovf.i.un + IL_0014: newarr [runtime]System.Int32 + IL_0019: stloc.1 + IL_001a: ldc.i4.0 + IL_001b: conv.i8 + IL_001c: stloc.2 + IL_001d: ldc.i4.1 + IL_001e: stloc.3 + IL_001f: br.s IL_0035 + + IL_0021: ldloc.1 + IL_0022: ldloc.2 + IL_0023: conv.i + IL_0024: ldloc.3 + IL_0025: stloc.s V_4 + IL_0027: ldloc.s V_4 + IL_0029: ldloc.0 + IL_002a: add + IL_002b: stelem.i4 + IL_002c: ldloc.3 + IL_002d: ldc.i4.2 + IL_002e: add + IL_002f: stloc.3 + IL_0030: ldloc.2 + IL_0031: ldc.i4.1 + IL_0032: conv.i8 + IL_0033: add + IL_0034: stloc.2 + IL_0035: ldloc.2 + IL_0036: ldc.i4.5 + IL_0037: conv.i8 + IL_0038: blt.un.s IL_0021 + + IL_003a: ldloc.1 + IL_003b: ret + } + + .method public static int32[] f31(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 5 + .locals init (int32[] V_0, + uint64 V_1, + int32 V_2, + int32 V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: ldc.i4.5 + IL_0012: conv.i8 + IL_0013: conv.ovf.i.un + IL_0014: newarr [runtime]System.Int32 + IL_0019: stloc.0 + IL_001a: ldc.i4.0 + IL_001b: conv.i8 + IL_001c: stloc.1 + IL_001d: ldc.i4.1 + IL_001e: stloc.2 + IL_001f: br.s IL_0031 + + IL_0021: ldloc.0 + IL_0022: ldloc.1 + IL_0023: conv.i + IL_0024: ldloc.2 + IL_0025: stloc.3 + IL_0026: ldloc.3 + IL_0027: stelem.i4 + IL_0028: ldloc.2 + IL_0029: ldc.i4.2 + IL_002a: add + IL_002b: stloc.2 + IL_002c: ldloc.1 + IL_002d: ldc.i4.1 + IL_002e: conv.i8 + IL_002f: add + IL_0030: stloc.1 + IL_0031: ldloc.1 + IL_0032: ldc.i4.5 + IL_0033: conv.i8 + IL_0034: blt.un.s IL_0021 + + IL_0036: ldloc.0 + IL_0037: ret + } + + .method public static int32[] f32(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g) 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 6 + .locals init (int32 V_0, + int32[] V_1, + uint64 V_2, + int32 V_3, + int32 V_4) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.0 + IL_0011: ldc.i4.5 + IL_0012: conv.i8 + IL_0013: conv.ovf.i.un + IL_0014: newarr [runtime]System.Int32 + IL_0019: stloc.1 + IL_001a: ldc.i4.0 + IL_001b: conv.i8 + IL_001c: stloc.2 + IL_001d: ldc.i4.1 + IL_001e: stloc.3 + IL_001f: br.s IL_0035 + + IL_0021: ldloc.1 + IL_0022: ldloc.2 + IL_0023: conv.i + IL_0024: ldloc.3 + IL_0025: stloc.s V_4 + IL_0027: ldloc.s V_4 + IL_0029: ldloc.0 + IL_002a: add + IL_002b: stelem.i4 + IL_002c: ldloc.3 + IL_002d: ldc.i4.2 + IL_002e: add + IL_002f: stloc.3 + IL_0030: ldloc.2 + IL_0031: ldc.i4.1 + IL_0032: conv.i8 + IL_0033: add + IL_0034: stloc.2 + IL_0035: ldloc.2 + IL_0036: ldc.i4.5 + IL_0037: conv.i8 + IL_0038: blt.un.s IL_0021 + + IL_003a: ldloc.1 + IL_003b: ret + } + } .class private abstract auto ansi sealed ''.$assembly diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeLists.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeLists.fs index 3562a5bfa71..28a0890e1e4 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeLists.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeLists.fs @@ -30,3 +30,8 @@ let f25 f g h = [for n in f ()..g ()..h () -> n] let f26 start step finish = [for n in start..step..finish -> n, float n] let f27 start step finish = [for n in start..step..finish -> struct (n, float n)] let f28 start step finish = [for n in start..step..finish -> let x = n + 1 in n * n] + +let f29 f g = [let y = f () in let z = g () in for x in 1..2..10 -> x + y + z] +let f30 f g = [let y = f () in g (); for x in 1..2..10 -> x + y] +let f31 f g = [f (); g (); for x in 1..2..10 -> x] +let f32 f g = [f (); let y = g () in for x in 1..2..10 -> x + y] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeLists.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeLists.fs.il.bsl index e5a3adcb69c..5b7741302d7 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeLists.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForNInRangeLists.fs.il.bsl @@ -2144,6 +2144,226 @@ IL_006d: ret } + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f29(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 5 + .locals init (int32 V_0, + int32 V_1, + valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_2, + uint64 V_3, + int32 V_4, + int32 V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.0 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.1 + IL_0011: ldc.i4.0 + IL_0012: conv.i8 + IL_0013: stloc.3 + IL_0014: ldc.i4.1 + IL_0015: stloc.s V_4 + IL_0017: br.s IL_0036 + + IL_0019: ldloca.s V_2 + IL_001b: ldloc.s V_4 + IL_001d: stloc.s V_5 + IL_001f: ldloc.s V_5 + IL_0021: ldloc.0 + IL_0022: add + IL_0023: ldloc.1 + IL_0024: add + IL_0025: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_002a: nop + IL_002b: ldloc.s V_4 + IL_002d: ldc.i4.2 + IL_002e: add + IL_002f: stloc.s V_4 + IL_0031: ldloc.3 + IL_0032: ldc.i4.1 + IL_0033: conv.i8 + IL_0034: add + IL_0035: stloc.3 + IL_0036: ldloc.3 + IL_0037: ldc.i4.5 + IL_0038: conv.i8 + IL_0039: blt.un.s IL_0019 + + IL_003b: ldloca.s V_2 + IL_003d: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0042: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f30(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 5 + .locals init (int32 V_0, + valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_1, + uint64 V_2, + int32 V_3, + int32 V_4) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.0 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: ldc.i4.0 + IL_0012: conv.i8 + IL_0013: stloc.2 + IL_0014: ldc.i4.1 + IL_0015: stloc.3 + IL_0016: br.s IL_0030 + + IL_0018: ldloca.s V_1 + IL_001a: ldloc.3 + IL_001b: stloc.s V_4 + IL_001d: ldloc.s V_4 + IL_001f: ldloc.0 + IL_0020: add + IL_0021: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_0026: nop + IL_0027: ldloc.3 + IL_0028: ldc.i4.2 + IL_0029: add + IL_002a: stloc.3 + IL_002b: ldloc.2 + IL_002c: ldc.i4.1 + IL_002d: conv.i8 + IL_002e: add + IL_002f: stloc.2 + IL_0030: ldloc.2 + IL_0031: ldc.i4.5 + IL_0032: conv.i8 + IL_0033: blt.un.s IL_0018 + + IL_0035: ldloca.s V_1 + IL_0037: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_003c: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f31(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g) 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 (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_0, + uint64 V_1, + int32 V_2, + int32 V_3) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: ldc.i4.0 + IL_0012: conv.i8 + IL_0013: stloc.1 + IL_0014: ldc.i4.1 + IL_0015: stloc.2 + IL_0016: br.s IL_002c + + IL_0018: ldloca.s V_0 + IL_001a: ldloc.2 + IL_001b: stloc.3 + IL_001c: ldloc.3 + IL_001d: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_0022: nop + IL_0023: ldloc.2 + IL_0024: ldc.i4.2 + IL_0025: add + IL_0026: stloc.2 + IL_0027: ldloc.1 + IL_0028: ldc.i4.1 + IL_0029: conv.i8 + IL_002a: add + IL_002b: stloc.1 + IL_002c: ldloc.1 + IL_002d: ldc.i4.5 + IL_002e: conv.i8 + IL_002f: blt.un.s IL_0018 + + IL_0031: ldloca.s V_0 + IL_0033: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0038: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f32(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 5 + .locals init (int32 V_0, + valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_1, + uint64 V_2, + int32 V_3, + int32 V_4) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.0 + IL_0011: ldc.i4.0 + IL_0012: conv.i8 + IL_0013: stloc.2 + IL_0014: ldc.i4.1 + IL_0015: stloc.3 + IL_0016: br.s IL_0030 + + IL_0018: ldloca.s V_1 + IL_001a: ldloc.3 + IL_001b: stloc.s V_4 + IL_001d: ldloc.s V_4 + IL_001f: ldloc.0 + IL_0020: add + IL_0021: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_0026: nop + IL_0027: ldloc.3 + IL_0028: ldc.i4.2 + IL_0029: add + IL_002a: stloc.3 + IL_002b: ldloc.2 + IL_002c: ldc.i4.1 + IL_002d: conv.i8 + IL_002e: add + IL_002f: stloc.2 + IL_0030: ldloc.2 + IL_0031: ldc.i4.5 + IL_0032: conv.i8 + IL_0033: blt.un.s IL_0018 + + IL_0035: ldloca.s V_1 + IL_0037: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_003c: ret + } + } .class private abstract auto ansi sealed ''.$assembly diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs index 148a7f971ee..c552cb7dee1 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs @@ -5,3 +5,8 @@ let f4 f g (array: int array) = [|for x in array -> f (); g(); x|] let f5 (array: int array) = [|for x in array do yield x|] let f6 f (array: int array) = [|for x in array do f (); yield x|] let f7 f g (array: int array) = [|for x in array do f (); g (); yield x|] + +let f8 f g (array: int array) = [|let y = f () in let z = g () in for x in array -> x + y + z|] +let f9 f g (array: int array) = [|let y = f () in g (); for x in array -> x + y|] +let f10 f g (array: int array) = [|f (); g (); for x in array -> x|] +let f11 f g (array: int array) = [|f (); let y = g () in for x in array -> x + y|] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl index dc64917f820..e17c1a50908 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl @@ -301,6 +301,142 @@ } + .class auto ansi serializable sealed nested assembly beforefieldinit f8@9 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public int32 y + .field public int32 z + .method assembly specialname rtspecialname + instance void .ctor(int32 y, + int32 z) 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 assembly/f8@9::y + IL_000d: ldarg.0 + IL_000e: ldarg.2 + IL_000f: stfld int32 assembly/f8@9::z + IL_0014: ret + } + + .method public strict virtual instance int32 Invoke(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.0 + IL_0002: ldfld int32 assembly/f8@9::y + IL_0007: add + IL_0008: ldarg.0 + IL_0009: ldfld int32 assembly/f8@9::z + IL_000e: add + IL_000f: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit f9@10 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public int32 y + .method assembly specialname rtspecialname instance void .ctor(int32 y) 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 assembly/f9@10::y + IL_000d: ret + } + + .method public strict virtual instance int32 Invoke(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.0 + IL_0002: ldfld int32 assembly/f9@10::y + IL_0007: add + IL_0008: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit f10@11 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class assembly/f10@11 @_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 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void assembly/f10@11::.ctor() + IL_0005: stsfld class assembly/f10@11 assembly/f10@11::@_instance + IL_000a: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit f11@12 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public int32 y + .method assembly specialname rtspecialname instance void .ctor(int32 y) 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 assembly/f11@12::y + IL_000d: ret + } + + .method public strict virtual instance int32 Invoke(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.0 + IL_0002: ldfld int32 assembly/f11@12::y + IL_0007: add + IL_0008: ret + } + + } + .method public static int32[] f1(int32[] 'array') cil managed { @@ -408,6 +544,115 @@ IL_000f: ret } + .method public static int32[] f8(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + int32[] 'array') cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 4 + .locals init (int32 V_0, + int32 V_1) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.0 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.1 + IL_0011: ldloc.0 + IL_0012: ldloc.1 + IL_0013: newobj instance void assembly/f8@9::.ctor(int32, + int32) + IL_0018: ldarg.2 + IL_0019: tail. + IL_001b: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + !!0[]) + IL_0020: ret + } + + .method public static int32[] f9(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + int32[] 'array') cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 4 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.0 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: ldloc.0 + IL_0012: newobj instance void assembly/f9@10::.ctor(int32) + IL_0017: ldarg.2 + IL_0018: tail. + IL_001a: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + !!0[]) + IL_001f: ret + } + + .method public static int32[] f10(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + int32[] 'array') cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: ldsfld class assembly/f10@11 assembly/f10@11::@_instance + IL_0016: ldarg.2 + IL_0017: tail. + IL_0019: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + !!0[]) + IL_001e: ret + } + + .method public static int32[] f11(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + int32[] 'array') cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 4 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.0 + IL_0011: ldloc.0 + IL_0012: newobj instance void assembly/f11@12::.ctor(int32) + IL_0017: ldarg.2 + IL_0018: tail. + IL_001a: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + !!0[]) + IL_001f: ret + } + } .class private abstract auto ansi sealed ''.$assembly diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToList.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToList.fs index 9aaf97f514b..fb12ad5c4de 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToList.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToList.fs @@ -5,3 +5,8 @@ let f4 f g (array: int array) = [for x in array -> f (); g(); x] let f5 (array: int array) = [for x in array do yield x] let f6 f (array: int array) = [for x in array do f (); yield x] let f7 f g (array: int array) = [for x in array do f (); g (); yield x] + +let f8 f g (array: int array) = [let y = f () in let z = g () in for x in array -> x + y + z] +let f9 f g (array: int array) = [let y = f () in g (); for x in array -> x + y] +let f10 f g (array: int array) = [f (); g (); for x in array -> x] +let f11 f g (array: int array) = [f (); let y = g () in for x in array -> x + y] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToList.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToList.fs.il.bsl index 4118a624e8a..9cc03990ad7 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToList.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToList.fs.il.bsl @@ -459,6 +459,286 @@ IL_0054: ret } + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f8(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + int32[] 'array') cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_0, + int32 V_1, + int32 V_2, + class [runtime]System.Collections.Generic.IEnumerator`1 V_3, + class [runtime]System.Collections.Generic.IEnumerable`1 V_4, + int32 V_5, + class [runtime]System.IDisposable V_6) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.1 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.2 + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.3 + .try + { + IL_0019: br.s IL_0031 + + IL_001b: ldloc.3 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.s V_5 + IL_0023: ldloca.s V_0 + IL_0025: ldloc.s V_5 + IL_0027: ldloc.1 + IL_0028: add + IL_0029: ldloc.2 + IL_002a: add + IL_002b: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_0030: nop + IL_0031: ldloc.3 + IL_0032: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0037: brtrue.s IL_001b + + IL_0039: ldnull + IL_003a: stloc.s V_4 + IL_003c: leave.s IL_0053 + + } + finally + { + IL_003e: ldloc.3 + IL_003f: isinst [runtime]System.IDisposable + IL_0044: stloc.s V_6 + IL_0046: ldloc.s V_6 + IL_0048: brfalse.s IL_0052 + + IL_004a: ldloc.s V_6 + IL_004c: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0051: endfinally + IL_0052: endfinally + } + IL_0053: ldloc.s V_4 + IL_0055: pop + IL_0056: ldloca.s V_0 + IL_0058: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_005d: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f9(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + int32[] 'array') cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_0, + int32 V_1, + class [runtime]System.Collections.Generic.IEnumerator`1 V_2, + class [runtime]System.Collections.Generic.IEnumerable`1 V_3, + int32 V_4, + class [runtime]System.IDisposable V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.1 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.2 + .try + { + IL_0019: br.s IL_002f + + IL_001b: ldloc.2 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.s V_4 + IL_0023: ldloca.s V_0 + IL_0025: ldloc.s V_4 + IL_0027: ldloc.1 + IL_0028: add + IL_0029: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_002e: nop + IL_002f: ldloc.2 + IL_0030: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0035: brtrue.s IL_001b + + IL_0037: ldnull + IL_0038: stloc.3 + IL_0039: leave.s IL_0050 + + } + finally + { + IL_003b: ldloc.2 + IL_003c: isinst [runtime]System.IDisposable + IL_0041: stloc.s V_5 + IL_0043: ldloc.s V_5 + IL_0045: brfalse.s IL_004f + + IL_0047: ldloc.s V_5 + IL_0049: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004e: endfinally + IL_004f: endfinally + } + IL_0050: ldloc.3 + IL_0051: pop + IL_0052: ldloca.s V_0 + IL_0054: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0059: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f10(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + int32[] 'array') cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 4 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_0, + class [runtime]System.Collections.Generic.IEnumerator`1 V_1, + class [runtime]System.Collections.Generic.IEnumerable`1 V_2, + int32 V_3, + class [runtime]System.IDisposable V_4) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.1 + .try + { + IL_0019: br.s IL_002b + + IL_001b: ldloc.1 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.3 + IL_0022: ldloca.s V_0 + IL_0024: ldloc.3 + IL_0025: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_002a: nop + IL_002b: ldloc.1 + IL_002c: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0031: brtrue.s IL_001b + + IL_0033: ldnull + IL_0034: stloc.2 + IL_0035: leave.s IL_004c + + } + finally + { + IL_0037: ldloc.1 + IL_0038: isinst [runtime]System.IDisposable + IL_003d: stloc.s V_4 + IL_003f: ldloc.s V_4 + IL_0041: brfalse.s IL_004b + + IL_0043: ldloc.s V_4 + IL_0045: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004a: endfinally + IL_004b: endfinally + } + IL_004c: ldloc.2 + IL_004d: pop + IL_004e: ldloca.s V_0 + IL_0050: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0055: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f11(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + int32[] 'array') cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_0, + int32 V_1, + class [runtime]System.Collections.Generic.IEnumerator`1 V_2, + class [runtime]System.Collections.Generic.IEnumerable`1 V_3, + int32 V_4, + class [runtime]System.IDisposable V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.1 + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.2 + .try + { + IL_0019: br.s IL_002f + + IL_001b: ldloc.2 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.s V_4 + IL_0023: ldloca.s V_0 + IL_0025: ldloc.s V_4 + IL_0027: ldloc.1 + IL_0028: add + IL_0029: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_002e: nop + IL_002f: ldloc.2 + IL_0030: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0035: brtrue.s IL_001b + + IL_0037: ldnull + IL_0038: stloc.3 + IL_0039: leave.s IL_0050 + + } + finally + { + IL_003b: ldloc.2 + IL_003c: isinst [runtime]System.IDisposable + IL_0041: stloc.s V_5 + IL_0043: ldloc.s V_5 + IL_0045: brfalse.s IL_004f + + IL_0047: ldloc.s V_5 + IL_0049: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004e: endfinally + IL_004f: endfinally + } + IL_0050: ldloc.3 + IL_0051: pop + IL_0052: ldloca.s V_0 + IL_0054: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0059: ret + } + } .class private abstract auto ansi sealed ''.$assembly diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToArray.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToArray.fs index 4ffd4887562..62b7b9bc6c0 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToArray.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToArray.fs @@ -5,3 +5,8 @@ let f4 f g (list: int list) = [|for x in list -> f (); g(); x|] let f5 (list: int list) = [|for x in list do yield x|] let f6 f (list: int list) = [|for x in list do f (); yield x|] let f7 f g (list: int list) = [|for x in list do f (); g (); yield x|] + +let f8 f g (list: int list) = [|let y = f () in let z = g () in for x in list -> x + y + z|] +let f9 f g (list: int list) = [|let y = f () in g (); for x in list -> x + y|] +let f10 f g (list: int list) = [|f (); g (); for x in list -> x|] +let f11 f g (list: int list) = [|f (); let y = g () in for x in list -> x + y|] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToArray.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToArray.fs.il.bsl index 67fb0aca055..34dd7e2af69 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToArray.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToArray.fs.il.bsl @@ -454,6 +454,282 @@ IL_0054: ret } + .method public static int32[] f8(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 list) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1 V_0, + int32 V_1, + int32 V_2, + class [runtime]System.Collections.Generic.IEnumerator`1 V_3, + class [runtime]System.Collections.Generic.IEnumerable`1 V_4, + int32 V_5, + class [runtime]System.IDisposable V_6) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.1 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.2 + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.3 + .try + { + IL_0019: br.s IL_0031 + + IL_001b: ldloc.3 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.s V_5 + IL_0023: ldloca.s V_0 + IL_0025: ldloc.s V_5 + IL_0027: ldloc.1 + IL_0028: add + IL_0029: ldloc.2 + IL_002a: add + IL_002b: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Add(!0) + IL_0030: nop + IL_0031: ldloc.3 + IL_0032: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0037: brtrue.s IL_001b + + IL_0039: ldnull + IL_003a: stloc.s V_4 + IL_003c: leave.s IL_0053 + + } + finally + { + IL_003e: ldloc.3 + IL_003f: isinst [runtime]System.IDisposable + IL_0044: stloc.s V_6 + IL_0046: ldloc.s V_6 + IL_0048: brfalse.s IL_0052 + + IL_004a: ldloc.s V_6 + IL_004c: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0051: endfinally + IL_0052: endfinally + } + IL_0053: ldloc.s V_4 + IL_0055: pop + IL_0056: ldloca.s V_0 + IL_0058: call instance !0[] valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Close() + IL_005d: ret + } + + .method public static int32[] f9(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 list) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1 V_0, + int32 V_1, + class [runtime]System.Collections.Generic.IEnumerator`1 V_2, + class [runtime]System.Collections.Generic.IEnumerable`1 V_3, + int32 V_4, + class [runtime]System.IDisposable V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.1 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.2 + .try + { + IL_0019: br.s IL_002f + + IL_001b: ldloc.2 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.s V_4 + IL_0023: ldloca.s V_0 + IL_0025: ldloc.s V_4 + IL_0027: ldloc.1 + IL_0028: add + IL_0029: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Add(!0) + IL_002e: nop + IL_002f: ldloc.2 + IL_0030: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0035: brtrue.s IL_001b + + IL_0037: ldnull + IL_0038: stloc.3 + IL_0039: leave.s IL_0050 + + } + finally + { + IL_003b: ldloc.2 + IL_003c: isinst [runtime]System.IDisposable + IL_0041: stloc.s V_5 + IL_0043: ldloc.s V_5 + IL_0045: brfalse.s IL_004f + + IL_0047: ldloc.s V_5 + IL_0049: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004e: endfinally + IL_004f: endfinally + } + IL_0050: ldloc.3 + IL_0051: pop + IL_0052: ldloca.s V_0 + IL_0054: call instance !0[] valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Close() + IL_0059: ret + } + + .method public static int32[] f10(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 list) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 4 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1 V_0, + class [runtime]System.Collections.Generic.IEnumerator`1 V_1, + class [runtime]System.Collections.Generic.IEnumerable`1 V_2, + int32 V_3, + class [runtime]System.IDisposable V_4) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.1 + .try + { + IL_0019: br.s IL_002b + + IL_001b: ldloc.1 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.3 + IL_0022: ldloca.s V_0 + IL_0024: ldloc.3 + IL_0025: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Add(!0) + IL_002a: nop + IL_002b: ldloc.1 + IL_002c: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0031: brtrue.s IL_001b + + IL_0033: ldnull + IL_0034: stloc.2 + IL_0035: leave.s IL_004c + + } + finally + { + IL_0037: ldloc.1 + IL_0038: isinst [runtime]System.IDisposable + IL_003d: stloc.s V_4 + IL_003f: ldloc.s V_4 + IL_0041: brfalse.s IL_004b + + IL_0043: ldloc.s V_4 + IL_0045: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004a: endfinally + IL_004b: endfinally + } + IL_004c: ldloc.2 + IL_004d: pop + IL_004e: ldloca.s V_0 + IL_0050: call instance !0[] valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Close() + IL_0055: ret + } + + .method public static int32[] f11(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 list) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1 V_0, + int32 V_1, + class [runtime]System.Collections.Generic.IEnumerator`1 V_2, + class [runtime]System.Collections.Generic.IEnumerable`1 V_3, + int32 V_4, + class [runtime]System.IDisposable V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.1 + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.2 + .try + { + IL_0019: br.s IL_002f + + IL_001b: ldloc.2 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.s V_4 + IL_0023: ldloca.s V_0 + IL_0025: ldloc.s V_4 + IL_0027: ldloc.1 + IL_0028: add + IL_0029: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Add(!0) + IL_002e: nop + IL_002f: ldloc.2 + IL_0030: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0035: brtrue.s IL_001b + + IL_0037: ldnull + IL_0038: stloc.3 + IL_0039: leave.s IL_0050 + + } + finally + { + IL_003b: ldloc.2 + IL_003c: isinst [runtime]System.IDisposable + IL_0041: stloc.s V_5 + IL_0043: ldloc.s V_5 + IL_0045: brfalse.s IL_004f + + IL_0047: ldloc.s V_5 + IL_0049: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004e: endfinally + IL_004f: endfinally + } + IL_0050: ldloc.3 + IL_0051: pop + IL_0052: ldloca.s V_0 + IL_0054: call instance !0[] valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Close() + IL_0059: ret + } + } .class private abstract auto ansi sealed ''.$assembly diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToList.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToList.fs index 5d9b73f6ef4..cfbb0fb567f 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToList.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToList.fs @@ -5,3 +5,8 @@ let f4 f g (list: int list) = [for x in list -> f (); g(); x] let f5 (list: int list) = [for x in list do yield x] let f6 f (list: int list) = [for x in list do f (); yield x] let f7 f g (list: int list) = [for x in list do f (); g (); yield x] + +let f8 f g (list: int list) = [let y = f () in let z = g () in for x in list -> x + y + z] +let f9 f g (list: int list) = [let y = f () in g (); for x in list -> x + y] +let f10 f g (list: int list) = [f (); g (); for x in list -> x] +let f11 f g (list: int list) = [f (); let y = g () in for x in list -> x + y] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToList.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToList.fs.il.bsl index 51145b138c7..c07c2764232 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToList.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToList.fs.il.bsl @@ -301,6 +301,142 @@ } + .class auto ansi serializable sealed nested assembly beforefieldinit f8@9 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public int32 y + .field public int32 z + .method assembly specialname rtspecialname + instance void .ctor(int32 y, + int32 z) 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 assembly/f8@9::y + IL_000d: ldarg.0 + IL_000e: ldarg.2 + IL_000f: stfld int32 assembly/f8@9::z + IL_0014: ret + } + + .method public strict virtual instance int32 Invoke(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.0 + IL_0002: ldfld int32 assembly/f8@9::y + IL_0007: add + IL_0008: ldarg.0 + IL_0009: ldfld int32 assembly/f8@9::z + IL_000e: add + IL_000f: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit f9@10 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public int32 y + .method assembly specialname rtspecialname instance void .ctor(int32 y) 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 assembly/f9@10::y + IL_000d: ret + } + + .method public strict virtual instance int32 Invoke(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.0 + IL_0002: ldfld int32 assembly/f9@10::y + IL_0007: add + IL_0008: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit f10@11 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field static assembly initonly class assembly/f10@11 @_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 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } + + .method private specialname rtspecialname static void .cctor() cil managed + { + + .maxstack 10 + IL_0000: newobj instance void assembly/f10@11::.ctor() + IL_0005: stsfld class assembly/f10@11 assembly/f10@11::@_instance + IL_000a: ret + } + + } + + .class auto ansi serializable sealed nested assembly beforefieldinit f11@12 + extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 + { + .field public int32 y + .method assembly specialname rtspecialname instance void .ctor(int32 y) 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 assembly/f11@12::y + IL_000d: ret + } + + .method public strict virtual instance int32 Invoke(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.0 + IL_0002: ldfld int32 assembly/f11@12::y + IL_0007: add + IL_0008: ret + } + + } + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 f1(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 list) cil managed { @@ -413,6 +549,119 @@ IL_000f: ret } + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f8(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 list) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 4 + .locals init (int32 V_0, + int32 V_1) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.0 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.1 + IL_0011: ldloc.0 + IL_0012: ldloc.1 + IL_0013: newobj instance void assembly/f8@9::.ctor(int32, + int32) + IL_0018: ldarg.2 + IL_0019: tail. + IL_001b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_0020: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f9(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 list) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 4 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.0 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: ldloc.0 + IL_0012: newobj instance void assembly/f9@10::.ctor(int32) + IL_0017: ldarg.2 + IL_0018: tail. + IL_001a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_001f: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f10(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 list) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: ldsfld class assembly/f10@11 assembly/f10@11::@_instance + IL_0016: ldarg.2 + IL_0017: tail. + IL_0019: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_001e: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f11(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 list) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 4 + .locals init (int32 V_0) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.0 + IL_0011: ldloc.0 + IL_0012: newobj instance void assembly/f11@12::.ctor(int32) + IL_0017: ldarg.2 + IL_0018: tail. + IL_001a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) + IL_001f: ret + } + } .class private abstract auto ansi sealed ''.$assembly diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToArray.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToArray.fs index b8656c8dbe6..f4a28b47626 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToArray.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToArray.fs @@ -5,3 +5,8 @@ let f4 f g (seq: int seq) = [|for x in seq -> f (); g(); x|] let f5 (seq: int seq) = [|for x in seq do yield x|] let f6 f (seq: int seq) = [|for x in seq do f (); yield x|] let f7 f g (seq: int seq) = [|for x in seq do f (); g (); yield x|] + +let f8 f g (seq: int seq) = [|let y = f () in let z = g () in for x in seq -> x + y + z|] +let f9 f g (seq: int seq) = [|let y = f () in g (); for x in seq -> x + y|] +let f10 f g (seq: int seq) = [|f (); g (); for x in seq -> x|] +let f11 f g (seq: int seq) = [|f (); let y = g () in for x in seq -> x + y|] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToArray.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToArray.fs.il.bsl index d94bd0b406b..446a17b4fd9 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToArray.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToArray.fs.il.bsl @@ -454,6 +454,282 @@ IL_0054: ret } + .method public static int32[] f8(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [runtime]System.Collections.Generic.IEnumerable`1 seq) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1 V_0, + int32 V_1, + int32 V_2, + class [runtime]System.Collections.Generic.IEnumerator`1 V_3, + class [runtime]System.Collections.Generic.IEnumerable`1 V_4, + int32 V_5, + class [runtime]System.IDisposable V_6) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.1 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.2 + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.3 + .try + { + IL_0019: br.s IL_0031 + + IL_001b: ldloc.3 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.s V_5 + IL_0023: ldloca.s V_0 + IL_0025: ldloc.s V_5 + IL_0027: ldloc.1 + IL_0028: add + IL_0029: ldloc.2 + IL_002a: add + IL_002b: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Add(!0) + IL_0030: nop + IL_0031: ldloc.3 + IL_0032: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0037: brtrue.s IL_001b + + IL_0039: ldnull + IL_003a: stloc.s V_4 + IL_003c: leave.s IL_0053 + + } + finally + { + IL_003e: ldloc.3 + IL_003f: isinst [runtime]System.IDisposable + IL_0044: stloc.s V_6 + IL_0046: ldloc.s V_6 + IL_0048: brfalse.s IL_0052 + + IL_004a: ldloc.s V_6 + IL_004c: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0051: endfinally + IL_0052: endfinally + } + IL_0053: ldloc.s V_4 + IL_0055: pop + IL_0056: ldloca.s V_0 + IL_0058: call instance !0[] valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Close() + IL_005d: ret + } + + .method public static int32[] f9(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [runtime]System.Collections.Generic.IEnumerable`1 seq) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1 V_0, + int32 V_1, + class [runtime]System.Collections.Generic.IEnumerator`1 V_2, + class [runtime]System.Collections.Generic.IEnumerable`1 V_3, + int32 V_4, + class [runtime]System.IDisposable V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.1 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.2 + .try + { + IL_0019: br.s IL_002f + + IL_001b: ldloc.2 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.s V_4 + IL_0023: ldloca.s V_0 + IL_0025: ldloc.s V_4 + IL_0027: ldloc.1 + IL_0028: add + IL_0029: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Add(!0) + IL_002e: nop + IL_002f: ldloc.2 + IL_0030: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0035: brtrue.s IL_001b + + IL_0037: ldnull + IL_0038: stloc.3 + IL_0039: leave.s IL_0050 + + } + finally + { + IL_003b: ldloc.2 + IL_003c: isinst [runtime]System.IDisposable + IL_0041: stloc.s V_5 + IL_0043: ldloc.s V_5 + IL_0045: brfalse.s IL_004f + + IL_0047: ldloc.s V_5 + IL_0049: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004e: endfinally + IL_004f: endfinally + } + IL_0050: ldloc.3 + IL_0051: pop + IL_0052: ldloca.s V_0 + IL_0054: call instance !0[] valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Close() + IL_0059: ret + } + + .method public static int32[] f10(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [runtime]System.Collections.Generic.IEnumerable`1 seq) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 4 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1 V_0, + class [runtime]System.Collections.Generic.IEnumerator`1 V_1, + class [runtime]System.Collections.Generic.IEnumerable`1 V_2, + int32 V_3, + class [runtime]System.IDisposable V_4) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.1 + .try + { + IL_0019: br.s IL_002b + + IL_001b: ldloc.1 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.3 + IL_0022: ldloca.s V_0 + IL_0024: ldloc.3 + IL_0025: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Add(!0) + IL_002a: nop + IL_002b: ldloc.1 + IL_002c: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0031: brtrue.s IL_001b + + IL_0033: ldnull + IL_0034: stloc.2 + IL_0035: leave.s IL_004c + + } + finally + { + IL_0037: ldloc.1 + IL_0038: isinst [runtime]System.IDisposable + IL_003d: stloc.s V_4 + IL_003f: ldloc.s V_4 + IL_0041: brfalse.s IL_004b + + IL_0043: ldloc.s V_4 + IL_0045: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004a: endfinally + IL_004b: endfinally + } + IL_004c: ldloc.2 + IL_004d: pop + IL_004e: ldloca.s V_0 + IL_0050: call instance !0[] valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Close() + IL_0055: ret + } + + .method public static int32[] f11(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [runtime]System.Collections.Generic.IEnumerable`1 seq) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1 V_0, + int32 V_1, + class [runtime]System.Collections.Generic.IEnumerator`1 V_2, + class [runtime]System.Collections.Generic.IEnumerable`1 V_3, + int32 V_4, + class [runtime]System.IDisposable V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.1 + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.2 + .try + { + IL_0019: br.s IL_002f + + IL_001b: ldloc.2 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.s V_4 + IL_0023: ldloca.s V_0 + IL_0025: ldloc.s V_4 + IL_0027: ldloc.1 + IL_0028: add + IL_0029: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Add(!0) + IL_002e: nop + IL_002f: ldloc.2 + IL_0030: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0035: brtrue.s IL_001b + + IL_0037: ldnull + IL_0038: stloc.3 + IL_0039: leave.s IL_0050 + + } + finally + { + IL_003b: ldloc.2 + IL_003c: isinst [runtime]System.IDisposable + IL_0041: stloc.s V_5 + IL_0043: ldloc.s V_5 + IL_0045: brfalse.s IL_004f + + IL_0047: ldloc.s V_5 + IL_0049: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004e: endfinally + IL_004f: endfinally + } + IL_0050: ldloc.3 + IL_0051: pop + IL_0052: ldloca.s V_0 + IL_0054: call instance !0[] valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ArrayCollector`1::Close() + IL_0059: ret + } + } .class private abstract auto ansi sealed ''.$assembly diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToList.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToList.fs index 05be5e9f2d7..9c88ace26d3 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToList.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToList.fs @@ -5,3 +5,8 @@ let f4 f g (seq: int seq) = [for x in seq -> f (); g(); x] let f5 (seq: int seq) = [for x in seq do yield x] let f6 f (seq: int seq) = [for x in seq do f (); yield x] let f7 f g (seq: int seq) = [for x in seq do f (); g (); yield x] + +let f8 f g (seq: int seq) = [let y = f () in let z = g () in for x in seq -> x + y + z] +let f9 f g (seq: int seq) = [let y = f () in g (); for x in seq -> x + y] +let f10 f g (seq: int seq) = [f (); g (); for x in seq -> x] +let f11 f g (seq: int seq) = [f (); let y = g () in for x in seq -> x + y] diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToList.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToList.fs.il.bsl index 6fe2894fc3a..bf3e4bf6eab 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToList.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInSeq_ToList.fs.il.bsl @@ -459,6 +459,286 @@ IL_0054: ret } + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f8(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [runtime]System.Collections.Generic.IEnumerable`1 seq) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_0, + int32 V_1, + int32 V_2, + class [runtime]System.Collections.Generic.IEnumerator`1 V_3, + class [runtime]System.Collections.Generic.IEnumerable`1 V_4, + int32 V_5, + class [runtime]System.IDisposable V_6) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.1 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.2 + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.3 + .try + { + IL_0019: br.s IL_0031 + + IL_001b: ldloc.3 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.s V_5 + IL_0023: ldloca.s V_0 + IL_0025: ldloc.s V_5 + IL_0027: ldloc.1 + IL_0028: add + IL_0029: ldloc.2 + IL_002a: add + IL_002b: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_0030: nop + IL_0031: ldloc.3 + IL_0032: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0037: brtrue.s IL_001b + + IL_0039: ldnull + IL_003a: stloc.s V_4 + IL_003c: leave.s IL_0053 + + } + finally + { + IL_003e: ldloc.3 + IL_003f: isinst [runtime]System.IDisposable + IL_0044: stloc.s V_6 + IL_0046: ldloc.s V_6 + IL_0048: brfalse.s IL_0052 + + IL_004a: ldloc.s V_6 + IL_004c: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_0051: endfinally + IL_0052: endfinally + } + IL_0053: ldloc.s V_4 + IL_0055: pop + IL_0056: ldloca.s V_0 + IL_0058: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_005d: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f9(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [runtime]System.Collections.Generic.IEnumerable`1 seq) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_0, + int32 V_1, + class [runtime]System.Collections.Generic.IEnumerator`1 V_2, + class [runtime]System.Collections.Generic.IEnumerable`1 V_3, + int32 V_4, + class [runtime]System.IDisposable V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: stloc.1 + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.2 + .try + { + IL_0019: br.s IL_002f + + IL_001b: ldloc.2 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.s V_4 + IL_0023: ldloca.s V_0 + IL_0025: ldloc.s V_4 + IL_0027: ldloc.1 + IL_0028: add + IL_0029: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_002e: nop + IL_002f: ldloc.2 + IL_0030: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0035: brtrue.s IL_001b + + IL_0037: ldnull + IL_0038: stloc.3 + IL_0039: leave.s IL_0050 + + } + finally + { + IL_003b: ldloc.2 + IL_003c: isinst [runtime]System.IDisposable + IL_0041: stloc.s V_5 + IL_0043: ldloc.s V_5 + IL_0045: brfalse.s IL_004f + + IL_0047: ldloc.s V_5 + IL_0049: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004e: endfinally + IL_004f: endfinally + } + IL_0050: ldloc.3 + IL_0051: pop + IL_0052: ldloca.s V_0 + IL_0054: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0059: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f10(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [runtime]System.Collections.Generic.IEnumerable`1 seq) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 4 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_0, + class [runtime]System.Collections.Generic.IEnumerator`1 V_1, + class [runtime]System.Collections.Generic.IEnumerable`1 V_2, + int32 V_3, + class [runtime]System.IDisposable V_4) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: pop + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.1 + .try + { + IL_0019: br.s IL_002b + + IL_001b: ldloc.1 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.3 + IL_0022: ldloca.s V_0 + IL_0024: ldloc.3 + IL_0025: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_002a: nop + IL_002b: ldloc.1 + IL_002c: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0031: brtrue.s IL_001b + + IL_0033: ldnull + IL_0034: stloc.2 + IL_0035: leave.s IL_004c + + } + finally + { + IL_0037: ldloc.1 + IL_0038: isinst [runtime]System.IDisposable + IL_003d: stloc.s V_4 + IL_003f: ldloc.s V_4 + IL_0041: brfalse.s IL_004b + + IL_0043: ldloc.s V_4 + IL_0045: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004a: endfinally + IL_004b: endfinally + } + IL_004c: ldloc.2 + IL_004d: pop + IL_004e: ldloca.s V_0 + IL_0050: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0055: ret + } + + .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 + f11(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, + class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g, + class [runtime]System.Collections.Generic.IEnumerable`1 seq) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_0, + int32 V_1, + class [runtime]System.Collections.Generic.IEnumerator`1 V_2, + class [runtime]System.Collections.Generic.IEnumerable`1 V_3, + int32 V_4, + class [runtime]System.IDisposable V_5) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldnull + IL_0003: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0008: pop + IL_0009: ldarg.1 + IL_000a: ldnull + IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0010: stloc.1 + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: callvirt instance class [runtime]System.Collections.Generic.IEnumerator`1 class [runtime]System.Collections.Generic.IEnumerable`1::GetEnumerator() + IL_0018: stloc.2 + .try + { + IL_0019: br.s IL_002f + + IL_001b: ldloc.2 + IL_001c: callvirt instance !0 class [runtime]System.Collections.Generic.IEnumerator`1::get_Current() + IL_0021: stloc.s V_4 + IL_0023: ldloca.s V_0 + IL_0025: ldloc.s V_4 + IL_0027: ldloc.1 + IL_0028: add + IL_0029: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_002e: nop + IL_002f: ldloc.2 + IL_0030: callvirt instance bool [runtime]System.Collections.IEnumerator::MoveNext() + IL_0035: brtrue.s IL_001b + + IL_0037: ldnull + IL_0038: stloc.3 + IL_0039: leave.s IL_0050 + + } + finally + { + IL_003b: ldloc.2 + IL_003c: isinst [runtime]System.IDisposable + IL_0041: stloc.s V_5 + IL_0043: ldloc.s V_5 + IL_0045: brfalse.s IL_004f + + IL_0047: ldloc.s V_5 + IL_0049: callvirt instance void [runtime]System.IDisposable::Dispose() + IL_004e: endfinally + IL_004f: endfinally + } + IL_0050: ldloc.3 + IL_0051: pop + IL_0052: ldloca.s V_0 + IL_0054: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0059: ret + } + } .class private abstract auto ansi sealed ''.$assembly From 7cd743e9e9c66685b5bfd660ed12620ed02eb84f Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Thu, 18 Apr 2024 11:58:11 -0400 Subject: [PATCH 03/10] Update release notes --- docs/release-notes/.FSharp.Compiler.Service/8.0.400.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md b/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md index b24a17b85fb..da27191f8dc 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md +++ b/docs/release-notes/.FSharp.Compiler.Service/8.0.400.md @@ -1,5 +1,6 @@ ### Fixed +* Optimize simple mappings with preludes in computed collections. ([PR #17067](https://github.com/dotnet/fsharp/pull/17067)) * Static abstract method on classes no longer yields internal error. ([Issue #17044](https://github.com/dotnet/fsharp/issues/17044), [PR #17055](https://github.com/dotnet/fsharp/pull/17055)) * Disallow calling abstract methods directly on interfaces. ([Issue #14012](https://github.com/dotnet/fsharp/issues/14012), [Issue #16299](https://github.com/dotnet/fsharp/issues/16299), [PR #17021](https://github.com/dotnet/fsharp/pull/17021)) * Various parenthesization API fixes. ([PR #16977](https://github.com/dotnet/fsharp/pull/16977)) From 646ef7080251aafcc6055a6ce0a734ed512247f9 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Wed, 24 Apr 2024 10:23:41 -0400 Subject: [PATCH 04/10] Use better ranges --- .../Optimize/LowerComputedCollections.fs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 52a4c13859d..ccb3865b433 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -258,7 +258,7 @@ let (|SeqToArray|_|) g expr = module List = /// Makes an expression that will build a list from an integral range. - let mkFromIntegralRange tcVal (g: TcGlobals) amap m rangeTy overallElemTy rangeExpr start step finish body = + let mkFromIntegralRange tcVal (g: TcGlobals) amap m rangeTy overallElemTy (rangeExpr: Expr) start step finish (body: (Val * Expr) option) = let collectorTy = g.mk_ListCollector_ty overallElemTy /// let collector = ListCollector () in @@ -281,9 +281,12 @@ module List = mkSequential m loop close ) + let mRangeExpr = rangeExpr.Range + let mBody = body |> Option.map (fun (_, body) -> body.Range) |> Option.defaultValue m + mkOptimizedRangeLoop g - (m, m, m, DebugPointAtWhile.No) + (mBody, mRangeExpr, mRangeExpr, DebugPointAtWhile.Yes mRangeExpr) (rangeTy, rangeExpr) (start, step, finish) (fun count mkLoop -> @@ -310,7 +313,7 @@ module Array = | NoCheckOvf /// Makes an expression that will build an array from an integral range. - let mkFromIntegralRange g m rangeTy ilTy overallElemTy rangeExpr start step finish body = + let mkFromIntegralRange g m rangeTy ilTy overallElemTy (rangeExpr: Expr) start step finish (body: (Val * Expr) option) = let arrayTy = mkArrayType g overallElemTy let convToNativeInt ovf expr = @@ -376,9 +379,12 @@ module Array = mkSequential m loop array) + let mRangeExpr = rangeExpr.Range + let mBody = body |> Option.map (fun (_, body) -> body.Range) |> Option.defaultValue m + mkOptimizedRangeLoop g - (m, m, m, DebugPointAtWhile.No) + (mBody, mRangeExpr, mRangeExpr, DebugPointAtWhile.Yes mRangeExpr) (rangeTy, rangeExpr) (start, step, finish) (fun count mkLoop -> @@ -530,7 +536,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap ilTyForTy overallExpr // [for … in start..finish -> …] // [for … in start..step..finish -> …] - | SimpleMapping g (cont, (_, _, rangeExpr & DebugPoints (IntegralRange g (rangeTy, (start, step, finish)), debug), _, loopVal, body)) when + | SimpleMapping g (cont, (_, _, DebugPoints (rangeExpr & IntegralRange g (rangeTy, (start, step, finish)), debug), _, loopVal, body)) when g.langVersion.SupportsFeature LanguageFeature.LowerIntegralRangesToFastLoops -> Some (cont (debug (List.mkFromIntegralRange tcVal g amap m rangeTy overallElemTy rangeExpr start step finish (Some (loopVal, body))))) @@ -558,7 +564,7 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap ilTyForTy overallExpr // [|for … in start..finish -> …|] // [|for … in start..step..finish -> …|] - | SimpleMapping g (cont, (_, _, rangeExpr & DebugPoints (IntegralRange g (rangeTy, (start, step, finish)), debug), _, loopVal, body)) when + | SimpleMapping g (cont, (_, _, DebugPoints (rangeExpr & IntegralRange g (rangeTy, (start, step, finish)), debug), _, loopVal, body)) when g.langVersion.SupportsFeature LanguageFeature.LowerIntegralRangesToFastLoops -> Some (cont (debug (Array.mkFromIntegralRange g m rangeTy (ilTyForTy overallElemTy) overallElemTy rangeExpr start step finish (Some (loopVal, body))))) From a38c49a02a1f437075c3b9e41fbcc02513da7d0b Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Mon, 29 Apr 2024 16:17:06 -0400 Subject: [PATCH 05/10] Emit fast map loops directly * Now emit fast map loops directly (instead of calling Array.map and List.map). * Use better ranges for debugging. I don't think these are perfect, but the ranges used for loops are already inconsistent, so I am not exactly sure what perfect would look like. The emission of inlined loops does make stepping through the mapping body work right, though. --- .../Optimize/LowerComputedCollections.fs | 217 ++++- .../ForXInArray_ToArray.fs.il.bsl | 888 ++++++++---------- .../ForXInList_ToList.fs.il.bsl | 866 ++++++++--------- .../TheBigFileOfDebugStepping.fsx | 152 +++ 4 files changed, 1096 insertions(+), 1027 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index ccb3865b433..7f537925cf2 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -11,8 +11,10 @@ open FSharp.Compiler.LowerSequenceExpressions open FSharp.Compiler.MethodCalls open FSharp.Compiler.Syntax open FSharp.Compiler.TcGlobals +open FSharp.Compiler.Text open FSharp.Compiler.TypeRelations open FSharp.Compiler.TypedTree +open FSharp.Compiler.TypedTreeBasics open FSharp.Compiler.TypedTreeOps open FSharp.Compiler.TypeHierarchy @@ -257,8 +259,63 @@ let (|SeqToArray|_|) g expr = | _ -> ValueNone module List = + /// Makes the equivalent of an inlined call to List.map. + let mkMap tcVal (g: TcGlobals) amap m (mBody, spFor, _spIn, mFor, mIn, spInWhile) srcList overallElemTy loopVal body = + let collectorTy = g.mk_ListCollector_ty overallElemTy + let srcListTy = tyOfExpr g srcList + + mkCompGenLetMutableIn m "collector" collectorTy (mkDefault (m, collectorTy)) (fun (_, collector) -> + let reader = InfoReader (g, amap) + + // Adapted from DetectAndOptimizeForEachExpression in TypedTreeOps.fs. + + let IndexHead = 0 + let IndexTail = 1 + + let currentVar, currentExpr = mkMutableCompGenLocal mIn "current" srcListTy + let nextVar, nextExpr = mkMutableCompGenLocal mIn "next" srcListTy + let srcElemTy = loopVal.val_type + + let guardExpr = mkNonNullTest g mFor nextExpr + let headOrDefaultExpr = mkUnionCaseFieldGetUnprovenViaExprAddr (currentExpr, g.cons_ucref, [srcElemTy], IndexHead, mIn) + let tailOrNullExpr = mkUnionCaseFieldGetUnprovenViaExprAddr (currentExpr, g.cons_ucref, [srcElemTy], IndexTail, mIn) + + let body = + mkInvisibleLet mIn loopVal headOrDefaultExpr + (mkSequential mIn + (mkCallCollectorAdd tcVal g reader mIn collector body) + (mkSequential mIn + (mkValSet mIn (mkLocalValRef currentVar) nextExpr) + (mkValSet mIn (mkLocalValRef nextVar) tailOrNullExpr))) + + let loop = + // let mutable current = enumerableExpr + mkLet spFor m currentVar srcList + // let mutable next = current.TailOrNull + (mkInvisibleLet mFor nextVar tailOrNullExpr + // while nonNull next do + (mkWhile g (spInWhile, WhileLoopForCompiledForEachExprMarker, guardExpr, body, mBody))) + + let close = mkCallCollectorClose tcVal g reader m collector + + mkSequential m loop close + ) + /// Makes an expression that will build a list from an integral range. - let mkFromIntegralRange tcVal (g: TcGlobals) amap m rangeTy overallElemTy (rangeExpr: Expr) start step finish (body: (Val * Expr) option) = + let mkFromIntegralRange + tcVal + (g: TcGlobals) + amap + m + (mBody, _spFor, _spIn, mFor, mIn, spInWhile) + rangeTy + overallElemTy + (rangeExpr: Expr) + start + step + finish + (body: (Val * Expr) option) + = let collectorTy = g.mk_ListCollector_ty overallElemTy /// let collector = ListCollector () in @@ -275,18 +332,15 @@ module List = |> Option.map (fun (loopVal, body) -> mkInvisibleLet m loopVal loopVar body) |> Option.defaultValue loopVar - mkCallCollectorAdd tcVal g reader m collector body) + mkCallCollectorAdd tcVal g reader mBody collector body) - let close = mkCallCollectorClose tcVal g reader m collector + let close = mkCallCollectorClose tcVal g reader mBody collector mkSequential m loop close ) - let mRangeExpr = rangeExpr.Range - let mBody = body |> Option.map (fun (_, body) -> body.Range) |> Option.defaultValue m - mkOptimizedRangeLoop g - (mBody, mRangeExpr, mRangeExpr, DebugPointAtWhile.Yes mRangeExpr) + (mBody, mFor, mIn, spInWhile) (rangeTy, rangeExpr) (start, step, finish) (fun count mkLoop -> @@ -302,6 +356,74 @@ module List = ) module Array = + let private mkIlInstr (g: TcGlobals) specific any ilTy = + if ilTy = g.ilg.typ_Int32 then specific DT_I4 + elif ilTy = g.ilg.typ_Int64 then specific DT_I8 + elif ilTy = g.ilg.typ_UInt64 then specific DT_U8 + elif ilTy = g.ilg.typ_UInt32 then specific DT_U4 + elif ilTy = g.ilg.typ_IntPtr then specific DT_I + elif ilTy = g.ilg.typ_UIntPtr then specific DT_U + elif ilTy = g.ilg.typ_Int16 then specific DT_I2 + elif ilTy = g.ilg.typ_UInt16 then specific DT_U2 + elif ilTy = g.ilg.typ_SByte then specific DT_I1 + elif ilTy = g.ilg.typ_Byte then specific DT_U1 + elif ilTy = g.ilg.typ_Char then specific DT_U2 + elif ilTy = g.ilg.typ_Double then specific DT_R8 + elif ilTy = g.ilg.typ_Single then specific DT_R4 + else any ilTy + + /// Makes the equivalent of an inlined call to Array.map. + let mkMap g m (mBody, _spFor, _spIn, mFor, mIn, spInWhile) srcArray srcIlTy destIlTy overallElemTy loopVal body = + let len = mkLdlen g mIn srcArray + let arrayTy = mkArrayType g overallElemTy + + /// (# "newarr !0" type ('T) count : 'T array #) + let array = + mkAsmExpr + ( + [I_newarr (ILArrayShape.SingleDimensional, destIlTy)], + [], + [len], + [arrayTy], + m + ) + + let ldelem = mkIlInstr g I_ldelem (fun ilTy -> I_ldelem_any (ILArrayShape.SingleDimensional, ilTy)) srcIlTy + let stelem = mkIlInstr g I_stelem (fun ilTy -> I_stelem_any (ILArrayShape.SingleDimensional, ilTy)) destIlTy + + mkCompGenLetIn m (nameof array) arrayTy array (fun (_, array) -> + mkCompGenLetMutableIn mIn "i" g.int32_ty (mkTypedZero g mIn g.int32_ty) (fun (iVal, i) -> + let body = + // Rebind the loop val to pull directly from the source array. + let body = mkInvisibleLet mBody loopVal (mkAsmExpr ([ldelem], [], [srcArray; i], [loopVal.val_type], mBody)) body + + // destArray[i] <- body srcArray[i] + let setArrSubI = mkAsmExpr ([stelem], [], [array; i; body], [], mIn) + + // i <- i + 1 + let incrI = mkValSet mIn (mkLocalValRef iVal) (mkAsmExpr ([AI_add], [], [i; mkTypedOne g mIn g.int32_ty], [g.int32_ty], mIn)) + + mkSequential mIn setArrSubI incrI + + let guard = mkILAsmClt g mFor i (mkLdlen g mFor array) + + let loop = + mkWhile + g + ( + spInWhile, + WhileLoopForCompiledForEachExprMarker, + guard, + body, + mFor + ) + + // while i < array.Length do done + // array + mkSequential m loop array + ) + ) + /// Whether to check for overflow when converting a value to a native int. [] type Ovf = @@ -313,7 +435,7 @@ module Array = | NoCheckOvf /// Makes an expression that will build an array from an integral range. - let mkFromIntegralRange g m rangeTy ilTy overallElemTy (rangeExpr: Expr) start step finish (body: (Val * Expr) option) = + let mkFromIntegralRange g m (mBody, _spFor, _spIn, mFor, mIn, spInWhile) rangeTy ilTy overallElemTy (rangeExpr: Expr) start step finish (body: (Val * Expr) option) = let arrayTy = mkArrayType g overallElemTy let convToNativeInt ovf expr = @@ -326,31 +448,17 @@ module Array = | CheckOvf -> AI_conv_ovf_un DT_I if typeEquivAux EraseMeasures g ty g.int64_ty then - mkAsmExpr ([conv], [], [expr], [g.nativeint_ty], m) + mkAsmExpr ([conv], [], [expr], [g.nativeint_ty], mIn) elif typeEquivAux EraseMeasures g ty g.nativeint_ty then - mkAsmExpr ([conv], [], [mkAsmExpr ([AI_conv DT_I8], [], [expr], [g.int64_ty], m)], [g.nativeint_ty], m) + mkAsmExpr ([conv], [], [mkAsmExpr ([AI_conv DT_I8], [], [expr], [g.int64_ty], mIn)], [g.nativeint_ty], mIn) elif typeEquivAux EraseMeasures g ty g.uint64_ty then - mkAsmExpr ([conv], [], [expr], [g.nativeint_ty], m) + mkAsmExpr ([conv], [], [expr], [g.nativeint_ty], mIn) elif typeEquivAux EraseMeasures g ty g.unativeint_ty then - mkAsmExpr ([conv], [], [mkAsmExpr ([AI_conv DT_U8], [], [expr], [g.uint64_ty], m)], [g.nativeint_ty], m) + mkAsmExpr ([conv], [], [mkAsmExpr ([AI_conv DT_U8], [], [expr], [g.uint64_ty], mIn)], [g.nativeint_ty], mIn) else expr - let stelem = - if ilTy = g.ilg.typ_Int32 then I_stelem DT_I4 - elif ilTy = g.ilg.typ_Int64 then I_stelem DT_I8 - elif ilTy = g.ilg.typ_UInt64 then I_stelem DT_U8 - elif ilTy = g.ilg.typ_UInt32 then I_stelem DT_U4 - elif ilTy = g.ilg.typ_IntPtr then I_stelem DT_I - elif ilTy = g.ilg.typ_UIntPtr then I_stelem DT_U - elif ilTy = g.ilg.typ_Int16 then I_stelem DT_I2 - elif ilTy = g.ilg.typ_UInt16 then I_stelem DT_U2 - elif ilTy = g.ilg.typ_SByte then I_stelem DT_I1 - elif ilTy = g.ilg.typ_Byte then I_stelem DT_U1 - elif ilTy = g.ilg.typ_Char then I_stelem DT_U2 - elif ilTy = g.ilg.typ_Double then I_stelem DT_R8 - elif ilTy = g.ilg.typ_Single then I_stelem DT_R4 - else I_stelem_any (ILArrayShape.SingleDimensional, ilTy) + let stelem = mkIlInstr g I_stelem (fun ilTy -> I_stelem_any (ILArrayShape.SingleDimensional, ilTy)) ilTy /// (# "newarr !0" type ('T) count : 'T array #) let mkNewArray count = @@ -367,24 +475,21 @@ module Array = /// /// array let mkArrayInit count mkLoop = - mkCompGenLetIn m "array" arrayTy (mkNewArray count) (fun (_, array) -> + mkCompGenLetIn mFor "array" arrayTy (mkNewArray count) (fun (_, array) -> let loop = mkLoop (fun idxVar loopVar -> let body = body - |> Option.map (fun (loopVal, body) -> mkInvisibleLet m loopVal loopVar body) + |> Option.map (fun (loopVal, body) -> mkInvisibleLet mBody loopVal loopVar body) |> Option.defaultValue loopVar - mkAsmExpr ([stelem], [], [array; convToNativeInt NoCheckOvf idxVar; body], [], m)) + mkAsmExpr ([stelem], [], [array; convToNativeInt NoCheckOvf idxVar; body], [], mBody)) mkSequential m loop array) - let mRangeExpr = rangeExpr.Range - let mBody = body |> Option.map (fun (_, body) -> body.Range) |> Option.defaultValue m - mkOptimizedRangeLoop g - (mBody, mRangeExpr, mRangeExpr, DebugPointAtWhile.Yes mRangeExpr) + (mBody, mFor, mIn, spInWhile) (rangeTy, rangeExpr) (start, step, finish) (fun count mkLoop -> @@ -472,8 +577,12 @@ let gatherPrelude ((|App|_|) : _ -> _ voption) expr = [] let (|SeqMap|_|) g = gatherPrelude (function - | ValApp g g.seq_map_vref ([ty1; ty2], [Expr.Lambda (valParams = [loopVal]; bodyExpr = body) as mapping; input], _) -> - ValueSome (ty1, ty2, input, mapping, loopVal, body) + | ValApp g g.seq_map_vref ([ty1; ty2], [Expr.Lambda (valParams = [loopVal]; bodyExpr = body; range = mIn) as mapping; input], mFor) -> + let spIn = match mIn.NotedSourceConstruct with NotedSourceConstruct.InOrTo -> DebugPointAtInOrTo.Yes mIn | _ -> DebugPointAtInOrTo.No + let spFor = match mFor.NotedSourceConstruct with NotedSourceConstruct.For -> DebugPointAtBinding.Yes mFor | _ -> DebugPointAtBinding.NoneAtInvisible + let spInWhile = match spIn with DebugPointAtInOrTo.Yes m -> DebugPointAtWhile.Yes m | DebugPointAtInOrTo.No -> DebugPointAtWhile.No + let ranges = body.Range, spFor, spIn, mFor, mIn, spInWhile + ValueSome (ty1, ty2, input, mapping, loopVal, body, ranges) | _ -> ValueNone) @@ -483,8 +592,12 @@ let (|SeqMap|_|) g = [] let (|SeqCollectSingle|_|) g = gatherPrelude (function - | ValApp g g.seq_collect_vref ([ty1; _; ty2], [Expr.Lambda (valParams = [loopVal]; bodyExpr = SimpleSequential g body) as mapping; input], _) -> - ValueSome (ty1, ty2, input, mapping, loopVal, body) + | ValApp g g.seq_collect_vref ([ty1; _; ty2], [Expr.Lambda (valParams = [loopVal]; bodyExpr = SimpleSequential g body; range = mIn) as mapping; input], mFor) -> + let spIn = match mIn.NotedSourceConstruct with NotedSourceConstruct.InOrTo -> DebugPointAtInOrTo.Yes mIn | _ -> DebugPointAtInOrTo.No + let spFor = match mFor.NotedSourceConstruct with NotedSourceConstruct.For -> DebugPointAtBinding.Yes mFor | _ -> DebugPointAtBinding.NoneAtInvisible + let spInWhile = match spIn with DebugPointAtInOrTo.Yes m -> DebugPointAtWhile.Yes m | DebugPointAtInOrTo.No -> DebugPointAtWhile.No + let ranges = body.Range, spFor, spIn, mFor, mIn, spInWhile + ValueSome (ty1, ty2, input, mapping, loopVal, body, ranges) | _ -> ValueNone) @@ -496,11 +609,11 @@ let (|SimpleMapping|_|) g expr = match expr with // for … in … -> … // for … in … do yield … - | ValApp g g.seq_delay_vref (_, [Expr.Lambda (bodyExpr = DebugPoints (SeqMap g (cont, (ty1, ty2, input, mapping, loopVal, body)), debug))], _) + | ValApp g g.seq_delay_vref (_, [Expr.Lambda (bodyExpr = DebugPoints (SeqMap g (cont, (ty1, ty2, input, mapping, loopVal, body, ranges)), debug))], _) // for … in … do f (); …; yield … - | ValApp g g.seq_delay_vref (_, [Expr.Lambda (bodyExpr = DebugPoints (SeqCollectSingle g (cont, (ty1, ty2, input, mapping, loopVal, body)), debug))], _) -> - ValueSome (debug >> cont, (ty1, ty2, input, mapping, loopVal, body)) + | ValApp g g.seq_delay_vref (_, [Expr.Lambda (bodyExpr = DebugPoints (SeqCollectSingle g (cont, (ty1, ty2, input, mapping, loopVal, body, ranges)), debug))], _) -> + ValueSome (debug >> cont, (ty1, ty2, input, mapping, loopVal, body, ranges)) | _ -> ValueNone @@ -522,24 +635,25 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap ilTyForTy overallExpr | SeqToList g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> match overallSeqExpr with // [for … in xs -> …] (* When xs is a list. *) - | SimpleMapping g (cont, (ty1, ty2, List g list, mapping, _, _)) when + | SimpleMapping g (cont, (_, _, List g list, _, loopVal, body, ranges)) when g.langVersion.SupportsFeature LanguageFeature.LowerSimpleMappingsInComprehensionsToDirectCallsToMap -> - Some (cont (mkCallListMap g m ty1 ty2 mapping list)) + Some (cont (List.mkMap tcVal g amap m ranges list overallElemTy loopVal body)) // [start..finish] // [start..step..finish] | IntegralRange g (rangeTy, (start, step, finish)) when g.langVersion.SupportsFeature LanguageFeature.LowerIntegralRangesToFastLoops -> - Some (List.mkFromIntegralRange tcVal g amap m rangeTy overallElemTy overallSeqExpr start step finish None) + let ranges = m, DebugPointAtBinding.NoneAtInvisible, DebugPointAtInOrTo.No, m, m, DebugPointAtWhile.No + Some (List.mkFromIntegralRange tcVal g amap m ranges rangeTy overallElemTy overallSeqExpr start step finish None) // [for … in start..finish -> …] // [for … in start..step..finish -> …] - | SimpleMapping g (cont, (_, _, DebugPoints (rangeExpr & IntegralRange g (rangeTy, (start, step, finish)), debug), _, loopVal, body)) when + | SimpleMapping g (cont, (_, _, DebugPoints (rangeExpr & IntegralRange g (rangeTy, (start, step, finish)), debug), _, loopVal, body, ranges)) when g.langVersion.SupportsFeature LanguageFeature.LowerIntegralRangesToFastLoops -> - Some (cont (debug (List.mkFromIntegralRange tcVal g amap m rangeTy overallElemTy rangeExpr start step finish (Some (loopVal, body))))) + Some (cont (debug (List.mkFromIntegralRange tcVal g amap m ranges rangeTy overallElemTy rangeExpr start step finish (Some (loopVal, body))))) // [(* Anything more complex. *)] | _ -> @@ -550,24 +664,25 @@ let LowerComputedListOrArrayExpr tcVal (g: TcGlobals) amap ilTyForTy overallExpr | SeqToArray g (OptionalCoerce (OptionalSeq g amap (overallSeqExpr, overallElemTy)), m) -> match overallSeqExpr with // [|for … in xs -> …|] (* When xs is an array. *) - | SimpleMapping g (cont, (ty1, ty2, Array g array, mapping, _, _)) when + | SimpleMapping g (cont, (ty1, ty2, Array g array, _, loopVal, body, ranges)) when g.langVersion.SupportsFeature LanguageFeature.LowerSimpleMappingsInComprehensionsToDirectCallsToMap -> - Some (cont (mkCallArrayMap g m ty1 ty2 mapping array)) + Some (cont (Array.mkMap g m ranges array (ilTyForTy ty1) (ilTyForTy ty2) overallElemTy loopVal body)) // [|start..finish|] // [|start..step..finish|] | IntegralRange g (rangeTy, (start, step, finish)) when g.langVersion.SupportsFeature LanguageFeature.LowerIntegralRangesToFastLoops -> - Some (Array.mkFromIntegralRange g m rangeTy (ilTyForTy overallElemTy) overallElemTy overallSeqExpr start step finish None) + let ranges = m, DebugPointAtBinding.NoneAtInvisible, DebugPointAtInOrTo.No, m, m, DebugPointAtWhile.No + Some (Array.mkFromIntegralRange g m ranges rangeTy (ilTyForTy overallElemTy) overallElemTy overallSeqExpr start step finish None) // [|for … in start..finish -> …|] // [|for … in start..step..finish -> …|] - | SimpleMapping g (cont, (_, _, DebugPoints (rangeExpr & IntegralRange g (rangeTy, (start, step, finish)), debug), _, loopVal, body)) when + | SimpleMapping g (cont, (_, _, DebugPoints (rangeExpr & IntegralRange g (rangeTy, (start, step, finish)), debug), _, loopVal, body, ranges)) when g.langVersion.SupportsFeature LanguageFeature.LowerIntegralRangesToFastLoops -> - Some (cont (debug (Array.mkFromIntegralRange g m rangeTy (ilTyForTy overallElemTy) overallElemTy rangeExpr start step finish (Some (loopVal, body))))) + Some (cont (debug (Array.mkFromIntegralRange g m ranges rangeTy (ilTyForTy overallElemTy) overallElemTy rangeExpr start step finish (Some (loopVal, body))))) // [|(* Anything more complex. *)|] | _ -> diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl index e17c1a50908..a7eb1b8f729 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl @@ -43,410 +43,42 @@ 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 f1@1 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field static assembly initonly class assembly/f1@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 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ret - } - - .method private specialname rtspecialname static void .cctor() cil managed - { - - .maxstack 10 - IL_0000: newobj instance void assembly/f1@1::.ctor() - IL_0005: stsfld class assembly/f1@1 assembly/f1@1::@_instance - IL_000a: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f2@2 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f - .method assembly specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f) cil managed - { - .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 class assembly/f2@2::f - IL_000d: ret - } - - .method public strict virtual instance !a Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 class assembly/f2@2::f - IL_0006: ldarg.1 - IL_0007: tail. - IL_0009: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_000e: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f3@3 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f - .method assembly specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f) cil managed - { - .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f3@3::f - IL_000d: ret - } - - .method public strict virtual instance int32 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f3@3::f - IL_0006: ldnull - IL_0007: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_000c: pop - IL_000d: ldarg.1 - IL_000e: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f4@4 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g - .method assembly specialname rtspecialname - instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, - class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g) cil managed - { - .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f4@4::f - IL_000d: ldarg.0 - IL_000e: ldarg.2 - IL_000f: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f4@4::g - IL_0014: ret - } - - .method public strict virtual instance int32 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f4@4::f - IL_0006: ldnull - IL_0007: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_000c: pop - IL_000d: ldarg.0 - IL_000e: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f4@4::g - IL_0013: ldnull - IL_0014: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_0019: pop - IL_001a: ldarg.1 - IL_001b: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f5@5 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field static assembly initonly class assembly/f5@5 @_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 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ret - } - - .method private specialname rtspecialname static void .cctor() cil managed - { - - .maxstack 10 - IL_0000: newobj instance void assembly/f5@5::.ctor() - IL_0005: stsfld class assembly/f5@5 assembly/f5@5::@_instance - IL_000a: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f6@6 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> - { - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f - .method assembly specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f) cil managed - { - .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f6@6::f - IL_000d: ret - } - - .method public strict virtual instance class [runtime]System.Collections.Generic.IEnumerable`1 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f6@6::f - IL_0006: ldnull - IL_0007: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_000c: pop - IL_000d: ldarg.1 - IL_000e: tail. - IL_0010: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::Singleton(!!0) - IL_0015: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f7@7 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> - { - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g - .method assembly specialname rtspecialname - instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, - class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g) cil managed - { - .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f7@7::f - IL_000d: ldarg.0 - IL_000e: ldarg.2 - IL_000f: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f7@7::g - IL_0014: ret - } - - .method public strict virtual instance class [runtime]System.Collections.Generic.IEnumerable`1 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f7@7::f - IL_0006: ldnull - IL_0007: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_000c: pop - IL_000d: ldarg.0 - IL_000e: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f7@7::g - IL_0013: ldnull - IL_0014: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_0019: pop - IL_001a: ldarg.1 - IL_001b: tail. - IL_001d: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::Singleton(!!0) - IL_0022: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f8@9 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field public int32 y - .field public int32 z - .method assembly specialname rtspecialname - instance void .ctor(int32 y, - int32 z) 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 assembly/f8@9::y - IL_000d: ldarg.0 - IL_000e: ldarg.2 - IL_000f: stfld int32 assembly/f8@9::z - IL_0014: ret - } - - .method public strict virtual instance int32 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ldarg.0 - IL_0002: ldfld int32 assembly/f8@9::y - IL_0007: add - IL_0008: ldarg.0 - IL_0009: ldfld int32 assembly/f8@9::z - IL_000e: add - IL_000f: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f9@10 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field public int32 y - .method assembly specialname rtspecialname instance void .ctor(int32 y) 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 assembly/f9@10::y - IL_000d: ret - } - - .method public strict virtual instance int32 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ldarg.0 - IL_0002: ldfld int32 assembly/f9@10::y - IL_0007: add - IL_0008: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f10@11 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field static assembly initonly class assembly/f10@11 @_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 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ret - } - - .method private specialname rtspecialname static void .cctor() cil managed - { - - .maxstack 10 - IL_0000: newobj instance void assembly/f10@11::.ctor() - IL_0005: stsfld class assembly/f10@11 assembly/f10@11::@_instance - IL_000a: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f11@12 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field public int32 y - .method assembly specialname rtspecialname instance void .ctor(int32 y) 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 assembly/f11@12::y - IL_000d: ret - } - - .method public strict virtual instance int32 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ldarg.0 - IL_0002: ldfld int32 assembly/f11@12::y - IL_0007: add - IL_0008: ret - } - - } - .method public static int32[] f1(int32[] 'array') cil managed { - .maxstack 8 - IL_0000: ldsfld class assembly/f1@1 assembly/f1@1::@_instance - IL_0005: ldarg.0 - IL_0006: tail. - IL_0008: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - !!0[]) - IL_000d: ret + .maxstack 6 + .locals init (int32[] V_0, + int32 V_1, + int32 V_2) + IL_0000: ldarg.0 + IL_0001: ldlen + IL_0002: conv.i4 + IL_0003: newarr [runtime]System.Int32 + IL_0008: stloc.0 + IL_0009: ldc.i4.0 + IL_000a: stloc.1 + IL_000b: br.s IL_0019 + + IL_000d: ldloc.0 + IL_000e: ldloc.1 + IL_000f: ldarg.0 + IL_0010: ldloc.1 + IL_0011: ldelem.i4 + IL_0012: stloc.2 + IL_0013: ldloc.2 + IL_0014: stelem.i4 + IL_0015: ldloc.1 + IL_0016: ldc.i4.1 + IL_0017: add + IL_0018: stloc.1 + IL_0019: ldloc.1 + IL_001a: ldloc.0 + IL_001b: ldlen + IL_001c: conv.i4 + IL_001d: blt.s IL_000d + + IL_001f: ldloc.0 + IL_0020: ret } .method public static !!a[] f2(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -454,14 +86,41 @@ { .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: newobj instance void class assembly/f2@2::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0006: ldarg.1 - IL_0007: tail. - IL_0009: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - !!0[]) - IL_000e: ret + .maxstack 6 + .locals init (!!a[] V_0, + int32 V_1, + int32 V_2) + IL_0000: ldarg.1 + IL_0001: ldlen + IL_0002: conv.i4 + IL_0003: newarr !!a + IL_0008: stloc.0 + IL_0009: ldc.i4.0 + IL_000a: stloc.1 + IL_000b: br.s IL_0023 + + IL_000d: ldloc.0 + IL_000e: ldloc.1 + IL_000f: ldarg.1 + IL_0010: ldloc.1 + IL_0011: ldelem.i4 + IL_0012: stloc.2 + IL_0013: ldarg.0 + IL_0014: ldloc.2 + IL_0015: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001a: stelem !!a + IL_001f: ldloc.1 + IL_0020: ldc.i4.1 + IL_0021: add + IL_0022: stloc.1 + IL_0023: ldloc.1 + IL_0024: ldloc.0 + IL_0025: ldlen + IL_0026: conv.i4 + IL_0027: blt.s IL_000d + + IL_0029: ldloc.0 + IL_002a: ret } .method public static int32[] f3(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -469,14 +128,43 @@ { .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: newobj instance void assembly/f3@3::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0006: ldarg.1 - IL_0007: tail. - IL_0009: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - !!0[]) - IL_000e: ret + .maxstack 6 + .locals init (int32[] V_0, + int32 V_1, + int32 V_2) + IL_0000: ldarg.1 + IL_0001: ldlen + IL_0002: conv.i4 + IL_0003: newarr [runtime]System.Int32 + IL_0008: stloc.0 + IL_0009: ldc.i4.0 + IL_000a: stloc.1 + IL_000b: br.s IL_0021 + + IL_000d: ldloc.0 + IL_000e: ldloc.1 + IL_000f: ldarg.1 + IL_0010: ldloc.1 + IL_0011: ldelem.i4 + IL_0012: stloc.2 + IL_0013: ldarg.0 + IL_0014: ldnull + IL_0015: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001a: pop + IL_001b: ldloc.2 + IL_001c: stelem.i4 + IL_001d: ldloc.1 + IL_001e: ldc.i4.1 + IL_001f: add + IL_0020: stloc.1 + IL_0021: ldloc.1 + IL_0022: ldloc.0 + IL_0023: ldlen + IL_0024: conv.i4 + IL_0025: blt.s IL_000d + + IL_0027: ldloc.0 + IL_0028: ret } .method public static int32[] f4(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -486,28 +174,85 @@ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 ) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldarg.1 - IL_0002: newobj instance void assembly/f4@4::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0007: ldarg.2 - IL_0008: tail. - IL_000a: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - !!0[]) - IL_000f: ret + .maxstack 6 + .locals init (int32[] V_0, + int32 V_1, + int32 V_2) + IL_0000: ldarg.2 + IL_0001: ldlen + IL_0002: conv.i4 + IL_0003: newarr [runtime]System.Int32 + IL_0008: stloc.0 + IL_0009: ldc.i4.0 + IL_000a: stloc.1 + IL_000b: br.s IL_0029 + + IL_000d: ldloc.0 + IL_000e: ldloc.1 + IL_000f: ldarg.2 + IL_0010: ldloc.1 + IL_0011: ldelem.i4 + IL_0012: stloc.2 + IL_0013: ldarg.0 + IL_0014: ldnull + IL_0015: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001a: pop + IL_001b: ldarg.1 + IL_001c: ldnull + IL_001d: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0022: pop + IL_0023: ldloc.2 + IL_0024: stelem.i4 + IL_0025: ldloc.1 + IL_0026: ldc.i4.1 + IL_0027: add + IL_0028: stloc.1 + IL_0029: ldloc.1 + IL_002a: ldloc.0 + IL_002b: ldlen + IL_002c: conv.i4 + IL_002d: blt.s IL_000d + + IL_002f: ldloc.0 + IL_0030: ret } .method public static int32[] f5(int32[] 'array') cil managed { - .maxstack 8 - IL_0000: ldsfld class assembly/f5@5 assembly/f5@5::@_instance - IL_0005: ldarg.0 - IL_0006: tail. - IL_0008: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - !!0[]) - IL_000d: ret + .maxstack 6 + .locals init (int32[] V_0, + int32 V_1, + int32 V_2) + IL_0000: ldarg.0 + IL_0001: ldlen + IL_0002: conv.i4 + IL_0003: newarr [runtime]System.Int32 + IL_0008: stloc.0 + IL_0009: ldc.i4.0 + IL_000a: stloc.1 + IL_000b: br.s IL_0019 + + IL_000d: ldloc.0 + IL_000e: ldloc.1 + IL_000f: ldarg.0 + IL_0010: ldloc.1 + IL_0011: ldelem.i4 + IL_0012: stloc.2 + IL_0013: ldloc.2 + IL_0014: stelem.i4 + IL_0015: ldloc.1 + IL_0016: ldc.i4.1 + IL_0017: add + IL_0018: stloc.1 + IL_0019: ldloc.1 + IL_001a: ldloc.0 + IL_001b: ldlen + IL_001c: conv.i4 + IL_001d: blt.s IL_000d + + IL_001f: ldloc.0 + IL_0020: ret } .method public static int32[] f6(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -515,14 +260,43 @@ { .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: newobj instance void assembly/f6@6::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0006: ldarg.1 - IL_0007: tail. - IL_0009: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - !!0[]) - IL_000e: ret + .maxstack 6 + .locals init (int32[] V_0, + int32 V_1, + int32 V_2) + IL_0000: ldarg.1 + IL_0001: ldlen + IL_0002: conv.i4 + IL_0003: newarr [runtime]System.Int32 + IL_0008: stloc.0 + IL_0009: ldc.i4.0 + IL_000a: stloc.1 + IL_000b: br.s IL_0021 + + IL_000d: ldloc.0 + IL_000e: ldloc.1 + IL_000f: ldarg.1 + IL_0010: ldloc.1 + IL_0011: ldelem.i4 + IL_0012: stloc.2 + IL_0013: ldarg.0 + IL_0014: ldnull + IL_0015: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001a: pop + IL_001b: ldloc.2 + IL_001c: stelem.i4 + IL_001d: ldloc.1 + IL_001e: ldc.i4.1 + IL_001f: add + IL_0020: stloc.1 + IL_0021: ldloc.1 + IL_0022: ldloc.0 + IL_0023: ldlen + IL_0024: conv.i4 + IL_0025: blt.s IL_000d + + IL_0027: ldloc.0 + IL_0028: ret } .method public static int32[] f7(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -532,16 +306,47 @@ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 ) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldarg.1 - IL_0002: newobj instance void assembly/f7@7::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0007: ldarg.2 - IL_0008: tail. - IL_000a: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - !!0[]) - IL_000f: ret + .maxstack 6 + .locals init (int32[] V_0, + int32 V_1, + int32 V_2) + IL_0000: ldarg.2 + IL_0001: ldlen + IL_0002: conv.i4 + IL_0003: newarr [runtime]System.Int32 + IL_0008: stloc.0 + IL_0009: ldc.i4.0 + IL_000a: stloc.1 + IL_000b: br.s IL_0029 + + IL_000d: ldloc.0 + IL_000e: ldloc.1 + IL_000f: ldarg.2 + IL_0010: ldloc.1 + IL_0011: ldelem.i4 + IL_0012: stloc.2 + IL_0013: ldarg.0 + IL_0014: ldnull + IL_0015: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001a: pop + IL_001b: ldarg.1 + IL_001c: ldnull + IL_001d: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0022: pop + IL_0023: ldloc.2 + IL_0024: stelem.i4 + IL_0025: ldloc.1 + IL_0026: ldc.i4.1 + IL_0027: add + IL_0028: stloc.1 + IL_0029: ldloc.1 + IL_002a: ldloc.0 + IL_002b: ldlen + IL_002c: conv.i4 + IL_002d: blt.s IL_000d + + IL_002f: ldloc.0 + IL_0030: ret } .method public static int32[] f8(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -551,9 +356,12 @@ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 ) - .maxstack 4 + .maxstack 6 .locals init (int32 V_0, - int32 V_1) + int32 V_1, + int32[] V_2, + int32 V_3, + int32 V_4) IL_0000: nop IL_0001: ldarg.0 IL_0002: ldnull @@ -563,15 +371,39 @@ IL_000a: ldnull IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) IL_0010: stloc.1 - IL_0011: ldloc.0 - IL_0012: ldloc.1 - IL_0013: newobj instance void assembly/f8@9::.ctor(int32, - int32) - IL_0018: ldarg.2 - IL_0019: tail. - IL_001b: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - !!0[]) - IL_0020: ret + IL_0011: ldarg.2 + IL_0012: ldlen + IL_0013: conv.i4 + IL_0014: newarr [runtime]System.Int32 + IL_0019: stloc.2 + IL_001a: ldc.i4.0 + IL_001b: stloc.3 + IL_001c: br.s IL_0030 + + IL_001e: ldloc.2 + IL_001f: ldloc.3 + IL_0020: ldarg.2 + IL_0021: ldloc.3 + IL_0022: ldelem.i4 + IL_0023: stloc.s V_4 + IL_0025: ldloc.s V_4 + IL_0027: ldloc.0 + IL_0028: add + IL_0029: ldloc.1 + IL_002a: add + IL_002b: stelem.i4 + IL_002c: ldloc.3 + IL_002d: ldc.i4.1 + IL_002e: add + IL_002f: stloc.3 + IL_0030: ldloc.3 + IL_0031: ldloc.2 + IL_0032: ldlen + IL_0033: conv.i4 + IL_0034: blt.s IL_001e + + IL_0036: ldloc.2 + IL_0037: ret } .method public static int32[] f9(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -581,8 +413,11 @@ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 ) - .maxstack 4 - .locals init (int32 V_0) + .maxstack 6 + .locals init (int32 V_0, + int32[] V_1, + int32 V_2, + int32 V_3) IL_0000: nop IL_0001: ldarg.0 IL_0002: ldnull @@ -592,13 +427,37 @@ IL_000a: ldnull IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) IL_0010: pop - IL_0011: ldloc.0 - IL_0012: newobj instance void assembly/f9@10::.ctor(int32) - IL_0017: ldarg.2 - IL_0018: tail. - IL_001a: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - !!0[]) - IL_001f: ret + IL_0011: ldarg.2 + IL_0012: ldlen + IL_0013: conv.i4 + IL_0014: newarr [runtime]System.Int32 + IL_0019: stloc.1 + IL_001a: ldc.i4.0 + IL_001b: stloc.2 + IL_001c: br.s IL_002c + + IL_001e: ldloc.1 + IL_001f: ldloc.2 + IL_0020: ldarg.2 + IL_0021: ldloc.2 + IL_0022: ldelem.i4 + IL_0023: stloc.3 + IL_0024: ldloc.3 + IL_0025: ldloc.0 + IL_0026: add + IL_0027: stelem.i4 + IL_0028: ldloc.2 + IL_0029: ldc.i4.1 + IL_002a: add + IL_002b: stloc.2 + IL_002c: ldloc.2 + IL_002d: ldloc.1 + IL_002e: ldlen + IL_002f: conv.i4 + IL_0030: blt.s IL_001e + + IL_0032: ldloc.1 + IL_0033: ret } .method public static int32[] f10(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -608,7 +467,10 @@ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 ) - .maxstack 8 + .maxstack 6 + .locals init (int32[] V_0, + int32 V_1, + int32 V_2) IL_0000: nop IL_0001: ldarg.0 IL_0002: ldnull @@ -618,12 +480,35 @@ IL_000a: ldnull IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) IL_0010: pop - IL_0011: ldsfld class assembly/f10@11 assembly/f10@11::@_instance - IL_0016: ldarg.2 - IL_0017: tail. - IL_0019: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - !!0[]) - IL_001e: ret + IL_0011: ldarg.2 + IL_0012: ldlen + IL_0013: conv.i4 + IL_0014: newarr [runtime]System.Int32 + IL_0019: stloc.0 + IL_001a: ldc.i4.0 + IL_001b: stloc.1 + IL_001c: br.s IL_002a + + IL_001e: ldloc.0 + IL_001f: ldloc.1 + IL_0020: ldarg.2 + IL_0021: ldloc.1 + IL_0022: ldelem.i4 + IL_0023: stloc.2 + IL_0024: ldloc.2 + IL_0025: stelem.i4 + IL_0026: ldloc.1 + IL_0027: ldc.i4.1 + IL_0028: add + IL_0029: stloc.1 + IL_002a: ldloc.1 + IL_002b: ldloc.0 + IL_002c: ldlen + IL_002d: conv.i4 + IL_002e: blt.s IL_001e + + IL_0030: ldloc.0 + IL_0031: ret } .method public static int32[] f11(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -633,8 +518,11 @@ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 ) - .maxstack 4 - .locals init (int32 V_0) + .maxstack 6 + .locals init (int32 V_0, + int32[] V_1, + int32 V_2, + int32 V_3) IL_0000: nop IL_0001: ldarg.0 IL_0002: ldnull @@ -644,13 +532,37 @@ IL_000a: ldnull IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) IL_0010: stloc.0 - IL_0011: ldloc.0 - IL_0012: newobj instance void assembly/f11@12::.ctor(int32) - IL_0017: ldarg.2 - IL_0018: tail. - IL_001a: call !!1[] [FSharp.Core]Microsoft.FSharp.Collections.ArrayModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - !!0[]) - IL_001f: ret + IL_0011: ldarg.2 + IL_0012: ldlen + IL_0013: conv.i4 + IL_0014: newarr [runtime]System.Int32 + IL_0019: stloc.1 + IL_001a: ldc.i4.0 + IL_001b: stloc.2 + IL_001c: br.s IL_002c + + IL_001e: ldloc.1 + IL_001f: ldloc.2 + IL_0020: ldarg.2 + IL_0021: ldloc.2 + IL_0022: ldelem.i4 + IL_0023: stloc.3 + IL_0024: ldloc.3 + IL_0025: ldloc.0 + IL_0026: add + IL_0027: stelem.i4 + IL_0028: ldloc.2 + IL_0029: ldc.i4.1 + IL_002a: add + IL_002b: stloc.2 + IL_002c: ldloc.2 + IL_002d: ldloc.1 + IL_002e: ldlen + IL_002f: conv.i4 + IL_0030: blt.s IL_001e + + IL_0032: ldloc.1 + IL_0033: ret } } diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToList.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToList.fs.il.bsl index c07c2764232..81eaa9d474f 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToList.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInList_ToList.fs.il.bsl @@ -43,410 +43,40 @@ 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 f1@1 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field static assembly initonly class assembly/f1@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 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ret - } - - .method private specialname rtspecialname static void .cctor() cil managed - { - - .maxstack 10 - IL_0000: newobj instance void assembly/f1@1::.ctor() - IL_0005: stsfld class assembly/f1@1 assembly/f1@1::@_instance - IL_000a: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f2@2 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f - .method assembly specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f) cil managed - { - .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 class assembly/f2@2::f - IL_000d: ret - } - - .method public strict virtual instance !a Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 class assembly/f2@2::f - IL_0006: ldarg.1 - IL_0007: tail. - IL_0009: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_000e: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f3@3 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f - .method assembly specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f) cil managed - { - .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f3@3::f - IL_000d: ret - } - - .method public strict virtual instance int32 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f3@3::f - IL_0006: ldnull - IL_0007: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_000c: pop - IL_000d: ldarg.1 - IL_000e: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f4@4 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g - .method assembly specialname rtspecialname - instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, - class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g) cil managed - { - .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f4@4::f - IL_000d: ldarg.0 - IL_000e: ldarg.2 - IL_000f: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f4@4::g - IL_0014: ret - } - - .method public strict virtual instance int32 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f4@4::f - IL_0006: ldnull - IL_0007: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_000c: pop - IL_000d: ldarg.0 - IL_000e: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f4@4::g - IL_0013: ldnull - IL_0014: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_0019: pop - IL_001a: ldarg.1 - IL_001b: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f5@5 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field static assembly initonly class assembly/f5@5 @_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 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ret - } - - .method private specialname rtspecialname static void .cctor() cil managed - { - - .maxstack 10 - IL_0000: newobj instance void assembly/f5@5::.ctor() - IL_0005: stsfld class assembly/f5@5 assembly/f5@5::@_instance - IL_000a: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f6@6 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> - { - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f - .method assembly specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f) cil managed - { - .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f6@6::f - IL_000d: ret - } - - .method public strict virtual instance class [runtime]System.Collections.Generic.IEnumerable`1 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f6@6::f - IL_0006: ldnull - IL_0007: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_000c: pop - IL_000d: ldarg.1 - IL_000e: tail. - IL_0010: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::Singleton(!!0) - IL_0015: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f7@7 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> - { - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f - .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g - .method assembly specialname rtspecialname - instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, - class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 g) cil managed - { - .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) - .custom instance void [runtime]System.Diagnostics.DebuggerNonUserCodeAttribute::.ctor() = ( 01 00 00 00 ) - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: call instance void class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>::.ctor() - IL_0006: ldarg.0 - IL_0007: ldarg.1 - IL_0008: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f7@7::f - IL_000d: ldarg.0 - IL_000e: ldarg.2 - IL_000f: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f7@7::g - IL_0014: ret - } - - .method public strict virtual instance class [runtime]System.Collections.Generic.IEnumerable`1 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f7@7::f - IL_0006: ldnull - IL_0007: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_000c: pop - IL_000d: ldarg.0 - IL_000e: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 assembly/f7@7::g - IL_0013: ldnull - IL_0014: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_0019: pop - IL_001a: ldarg.1 - IL_001b: tail. - IL_001d: call class [runtime]System.Collections.Generic.IEnumerable`1 [FSharp.Core]Microsoft.FSharp.Collections.SeqModule::Singleton(!!0) - IL_0022: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f8@9 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field public int32 y - .field public int32 z - .method assembly specialname rtspecialname - instance void .ctor(int32 y, - int32 z) 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 assembly/f8@9::y - IL_000d: ldarg.0 - IL_000e: ldarg.2 - IL_000f: stfld int32 assembly/f8@9::z - IL_0014: ret - } - - .method public strict virtual instance int32 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ldarg.0 - IL_0002: ldfld int32 assembly/f8@9::y - IL_0007: add - IL_0008: ldarg.0 - IL_0009: ldfld int32 assembly/f8@9::z - IL_000e: add - IL_000f: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f9@10 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field public int32 y - .method assembly specialname rtspecialname instance void .ctor(int32 y) 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 assembly/f9@10::y - IL_000d: ret - } - - .method public strict virtual instance int32 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ldarg.0 - IL_0002: ldfld int32 assembly/f9@10::y - IL_0007: add - IL_0008: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f10@11 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field static assembly initonly class assembly/f10@11 @_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 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ret - } - - .method private specialname rtspecialname static void .cctor() cil managed - { - - .maxstack 10 - IL_0000: newobj instance void assembly/f10@11::.ctor() - IL_0005: stsfld class assembly/f10@11 assembly/f10@11::@_instance - IL_000a: ret - } - - } - - .class auto ansi serializable sealed nested assembly beforefieldinit f11@12 - extends class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 - { - .field public int32 y - .method assembly specialname rtspecialname instance void .ctor(int32 y) 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 assembly/f11@12::y - IL_000d: ret - } - - .method public strict virtual instance int32 Invoke(int32 x) cil managed - { - - .maxstack 8 - IL_0000: ldarg.1 - IL_0001: ldarg.0 - IL_0002: ldfld int32 assembly/f11@12::y - IL_0007: add - IL_0008: ret - } - - } - .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 f1(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 list) cil managed { - .maxstack 8 - IL_0000: ldsfld class assembly/f1@1 assembly/f1@1::@_instance - IL_0005: ldarg.0 - IL_0006: tail. - IL_0008: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_000d: ret + .maxstack 4 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`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) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0009: stloc.2 + IL_000a: br.s IL_0025 + + IL_000c: ldloc.1 + IL_000d: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0012: stloc.3 + IL_0013: ldloca.s V_0 + IL_0015: ldloc.3 + IL_0016: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_001b: nop + IL_001c: ldloc.2 + IL_001d: stloc.1 + IL_001e: ldloc.1 + 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.2 + IL_0025: ldloc.2 + IL_0026: brtrue.s IL_000c + + IL_0028: ldloca.s V_0 + IL_002a: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_002f: ret } .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 @@ -455,14 +85,39 @@ { .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: newobj instance void class assembly/f2@2::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0006: ldarg.1 - IL_0007: tail. - IL_0009: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_000e: ret + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`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) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0009: stloc.2 + IL_000a: br.s IL_002b + + IL_000c: ldloc.1 + IL_000d: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0012: stloc.3 + IL_0013: ldloca.s V_0 + IL_0015: ldarg.0 + IL_0016: ldloc.3 + IL_0017: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001c: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_0021: nop + IL_0022: ldloc.2 + IL_0023: stloc.1 + IL_0024: ldloc.1 + IL_0025: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_002a: stloc.2 + IL_002b: ldloc.2 + IL_002c: brtrue.s IL_000c + + IL_002e: ldloca.s V_0 + IL_0030: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0035: ret } .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 @@ -471,14 +126,41 @@ { .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: newobj instance void assembly/f3@3::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0006: ldarg.1 - IL_0007: tail. - IL_0009: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_000e: ret + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`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) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0009: stloc.2 + IL_000a: br.s IL_002d + + IL_000c: ldloc.1 + IL_000d: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0012: stloc.3 + IL_0013: ldloca.s V_0 + IL_0015: ldarg.0 + IL_0016: ldnull + IL_0017: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001c: pop + IL_001d: ldloc.3 + IL_001e: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_0023: nop + IL_0024: ldloc.2 + IL_0025: stloc.1 + IL_0026: ldloc.1 + IL_0027: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_002c: stloc.2 + IL_002d: ldloc.2 + IL_002e: brtrue.s IL_000c + + IL_0030: ldloca.s V_0 + IL_0032: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0037: ret } .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 @@ -489,28 +171,81 @@ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 ) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldarg.1 - IL_0002: newobj instance void assembly/f4@4::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0007: ldarg.2 - IL_0008: tail. - IL_000a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_000f: ret + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`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) + IL_0000: nop + IL_0001: ldarg.2 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0009: stloc.2 + IL_000a: br.s IL_0035 + + IL_000c: ldloc.1 + IL_000d: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0012: stloc.3 + IL_0013: ldloca.s V_0 + IL_0015: ldarg.0 + IL_0016: ldnull + IL_0017: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001c: pop + IL_001d: ldarg.1 + IL_001e: ldnull + IL_001f: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0024: pop + IL_0025: ldloc.3 + IL_0026: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_002b: nop + IL_002c: ldloc.2 + IL_002d: stloc.1 + IL_002e: ldloc.1 + IL_002f: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0034: stloc.2 + IL_0035: ldloc.2 + IL_0036: brtrue.s IL_000c + + IL_0038: ldloca.s V_0 + IL_003a: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_003f: ret } .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 f5(class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 list) cil managed { - .maxstack 8 - IL_0000: ldsfld class assembly/f5@5 assembly/f5@5::@_instance - IL_0005: ldarg.0 - IL_0006: tail. - IL_0008: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_000d: ret + .maxstack 4 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`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) + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0009: stloc.2 + IL_000a: br.s IL_0025 + + IL_000c: ldloc.1 + IL_000d: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0012: stloc.3 + IL_0013: ldloca.s V_0 + IL_0015: ldloc.3 + IL_0016: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_001b: nop + IL_001c: ldloc.2 + IL_001d: stloc.1 + IL_001e: ldloc.1 + 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.2 + IL_0025: ldloc.2 + IL_0026: brtrue.s IL_000c + + IL_0028: ldloca.s V_0 + IL_002a: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_002f: ret } .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 @@ -519,14 +254,41 @@ { .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: newobj instance void assembly/f6@6::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0006: ldarg.1 - IL_0007: tail. - IL_0009: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_000e: ret + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`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) + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0009: stloc.2 + IL_000a: br.s IL_002d + + IL_000c: ldloc.1 + IL_000d: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0012: stloc.3 + IL_0013: ldloca.s V_0 + IL_0015: ldarg.0 + IL_0016: ldnull + IL_0017: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001c: pop + IL_001d: ldloc.3 + IL_001e: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_0023: nop + IL_0024: ldloc.2 + IL_0025: stloc.1 + IL_0026: ldloc.1 + IL_0027: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_002c: stloc.2 + IL_002d: ldloc.2 + IL_002e: brtrue.s IL_000c + + IL_0030: ldloca.s V_0 + IL_0032: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0037: ret } .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 @@ -537,16 +299,45 @@ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 ) - .maxstack 8 - IL_0000: ldarg.0 - IL_0001: ldarg.1 - IL_0002: newobj instance void assembly/f7@7::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2) - IL_0007: ldarg.2 - IL_0008: tail. - IL_000a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_000f: ret + .maxstack 5 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`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) + IL_0000: nop + IL_0001: ldarg.2 + IL_0002: stloc.1 + IL_0003: ldloc.1 + IL_0004: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0009: stloc.2 + IL_000a: br.s IL_0035 + + IL_000c: ldloc.1 + IL_000d: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0012: stloc.3 + IL_0013: ldloca.s V_0 + IL_0015: ldarg.0 + IL_0016: ldnull + IL_0017: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001c: pop + IL_001d: ldarg.1 + IL_001e: ldnull + IL_001f: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0024: pop + IL_0025: ldloc.3 + IL_0026: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_002b: nop + IL_002c: ldloc.2 + IL_002d: stloc.1 + IL_002e: ldloc.1 + IL_002f: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0034: stloc.2 + IL_0035: ldloc.2 + IL_0036: brtrue.s IL_000c + + IL_0038: ldloca.s V_0 + IL_003a: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_003f: ret } .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 @@ -557,9 +348,13 @@ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 ) - .maxstack 4 + .maxstack 5 .locals init (int32 V_0, - int32 V_1) + int32 V_1, + valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_2, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_3, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_4, + int32 V_5) IL_0000: nop IL_0001: ldarg.0 IL_0002: ldnull @@ -569,15 +364,36 @@ IL_000a: ldnull IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) IL_0010: stloc.1 - IL_0011: ldloc.0 - IL_0012: ldloc.1 - IL_0013: newobj instance void assembly/f8@9::.ctor(int32, - int32) - IL_0018: ldarg.2 - IL_0019: tail. - IL_001b: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_0020: ret + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: stloc.3 + IL_0014: ldloc.3 + IL_0015: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_001a: stloc.s V_4 + IL_001c: br.s IL_003f + + IL_001e: ldloc.3 + IL_001f: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0024: stloc.s V_5 + IL_0026: ldloca.s V_2 + IL_0028: ldloc.s V_5 + IL_002a: ldloc.0 + IL_002b: add + IL_002c: ldloc.1 + IL_002d: add + IL_002e: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_0033: nop + IL_0034: ldloc.s V_4 + IL_0036: stloc.3 + IL_0037: ldloc.3 + IL_0038: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_003d: stloc.s V_4 + IL_003f: ldloc.s V_4 + IL_0041: brtrue.s IL_001e + + IL_0043: ldloca.s V_2 + IL_0045: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_004a: ret } .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 @@ -588,8 +404,12 @@ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 ) - .maxstack 4 - .locals init (int32 V_0) + .maxstack 5 + .locals init (int32 V_0, + valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_1, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_2, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_3, + int32 V_4) IL_0000: nop IL_0001: ldarg.0 IL_0002: ldnull @@ -599,13 +419,34 @@ IL_000a: ldnull IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) IL_0010: pop - IL_0011: ldloc.0 - IL_0012: newobj instance void assembly/f9@10::.ctor(int32) - IL_0017: ldarg.2 - IL_0018: tail. - IL_001a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_001f: ret + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: stloc.2 + IL_0014: ldloc.2 + IL_0015: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_001a: stloc.3 + IL_001b: br.s IL_003a + + IL_001d: ldloc.2 + IL_001e: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0023: stloc.s V_4 + IL_0025: ldloca.s V_1 + IL_0027: ldloc.s V_4 + IL_0029: ldloc.0 + IL_002a: add + IL_002b: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_0030: nop + IL_0031: ldloc.3 + IL_0032: stloc.2 + IL_0033: ldloc.2 + IL_0034: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0039: stloc.3 + IL_003a: ldloc.3 + IL_003b: brtrue.s IL_001d + + IL_003d: ldloca.s V_1 + IL_003f: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0044: ret } .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 @@ -616,7 +457,11 @@ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 ) - .maxstack 8 + .maxstack 4 + .locals init (valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`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) IL_0000: nop IL_0001: ldarg.0 IL_0002: ldnull @@ -626,12 +471,32 @@ IL_000a: ldnull IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) IL_0010: pop - IL_0011: ldsfld class assembly/f10@11 assembly/f10@11::@_instance - IL_0016: ldarg.2 - IL_0017: tail. - IL_0019: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_001e: ret + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: stloc.1 + IL_0014: ldloc.1 + IL_0015: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_001a: stloc.2 + IL_001b: br.s IL_0036 + + IL_001d: ldloc.1 + IL_001e: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0023: stloc.3 + IL_0024: ldloca.s V_0 + IL_0026: ldloc.3 + IL_0027: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_002c: nop + IL_002d: ldloc.2 + IL_002e: stloc.1 + IL_002f: ldloc.1 + IL_0030: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0035: stloc.2 + IL_0036: ldloc.2 + IL_0037: brtrue.s IL_001d + + IL_0039: ldloca.s V_0 + IL_003b: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0040: ret } .method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 @@ -642,8 +507,12 @@ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 00 00 00 00 ) - .maxstack 4 - .locals init (int32 V_0) + .maxstack 5 + .locals init (int32 V_0, + valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1 V_1, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_2, + class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 V_3, + int32 V_4) IL_0000: nop IL_0001: ldarg.0 IL_0002: ldnull @@ -653,13 +522,34 @@ IL_000a: ldnull IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) IL_0010: stloc.0 - IL_0011: ldloc.0 - IL_0012: newobj instance void assembly/f11@12::.ctor(int32) - IL_0017: ldarg.2 - IL_0018: tail. - IL_001a: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2, - class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1) - IL_001f: ret + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: stloc.2 + IL_0014: ldloc.2 + IL_0015: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_001a: stloc.3 + IL_001b: br.s IL_003a + + IL_001d: ldloc.2 + IL_001e: call instance !0 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_HeadOrDefault() + IL_0023: stloc.s V_4 + IL_0025: ldloca.s V_1 + IL_0027: ldloc.s V_4 + IL_0029: ldloc.0 + IL_002a: add + IL_002b: call instance void valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Add(!0) + IL_0030: nop + IL_0031: ldloc.3 + IL_0032: stloc.2 + IL_0033: ldloc.2 + IL_0034: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1::get_TailOrNull() + IL_0039: stloc.3 + IL_003a: ldloc.3 + IL_003b: brtrue.s IL_001d + + IL_003d: ldloca.s V_1 + IL_003f: call instance class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1 valuetype [FSharp.Core]Microsoft.FSharp.Core.CompilerServices.ListCollector`1::Close() + IL_0044: ret } } diff --git a/tests/walkthroughs/DebugStepping/TheBigFileOfDebugStepping.fsx b/tests/walkthroughs/DebugStepping/TheBigFileOfDebugStepping.fsx index b72489a9358..346761cc478 100644 --- a/tests/walkthroughs/DebugStepping/TheBigFileOfDebugStepping.fsx +++ b/tests/walkthroughs/DebugStepping/TheBigFileOfDebugStepping.fsx @@ -1194,6 +1194,20 @@ module ForLoopInGeneratedList = [ for x in inp do yield x + 1 ] + let testSimpleListEachListLoopWithInitialLetBindings f g (inp:int list) = + [ let y = f () + let z = g () + for x in inp do + printfn $"hello, x = {x}" + yield x + y + z ] + + let testSimpleListEachListLoopWithInitialSequentialExpression f g (inp:int list) = + [ f () + g () + for x in inp do + printfn $"hello, x = {x}" + yield x + 1 ] + let testSimpleListEachListLoopWithTwoStatements (inp:int list) = [ for x in inp do printfn $"hello, x = {x}" @@ -1212,6 +1226,19 @@ module ForLoopInGeneratedList = [ for x in start .. stop do yield x + 1 ] + let testSimpleListEachIntRangeLoopWithInitialLetBindings f g (start, stop) = + [ let y = f () + let z = g () + for x in start .. stop do + printfn $"hello, x = {x}" + yield x + y + z ] + + let testSimpleListEachIntRangeLoopWithInitialSequentialExpression f g (start, stop) = + [ f () + g () + for x in start .. stop do + yield x + 1 ] + let testSimpleListEachIntRangeLoopWithTwoStatements (start, stop) = [ for x in start .. stop do printfn $"hello, x = {x}" @@ -1249,10 +1276,14 @@ module ForLoopInGeneratedList = testSimpleListEachArrayLoopWithOneStatement [|1;2;3|] testSimpleListEachArrayLoopWithTwoStatements [|1;2;3|] testSimpleListEachListLoopWithOneStatement [1;2;3] + testSimpleListEachListLoopWithInitialLetBindings (fun () -> 7) (fun () -> 8) [1;2;3] + testSimpleListEachListLoopWithInitialSequentialExpression (fun () -> printfn "7") (fun () -> printfn "8") [1;2;3] testSimpleListEachListLoopWithTwoStatements [1;2;3] testSimpleListEachStringLoopWithOneStatement "123" testSimpleListEachStringLoopWithTwoStatements "123" testSimpleListEachIntRangeLoopWithOneStatement (1, 3) + testSimpleListEachIntRangeLoopWithInitialLetBindings (fun () -> 7) (fun () -> 8) (1, 3) + testSimpleListEachIntRangeLoopWithInitialSequentialExpression (fun () -> printfn "7") (fun () -> printfn "8") (1, 3) testSimpleListEachIntRangeLoopWithTwoStatements (1, 3) testSimpleListEachIntRangeLoopDownWithOneStatement (1, 3) testSimpleListEachIntRangeLoopDownWithTwoStatements (1, 3) @@ -1261,6 +1292,127 @@ module ForLoopInGeneratedList = testSimpleListEachIntLoopDownWithOneStatement (1, 3) testSimpleListEachIntLoopDownWithTwoStatements (1, 3) +module ForLoopInGeneratedArray = + let testSimpleArrayEachSeqLoopWithOneStatement inp = + [| for x in inp do + yield x+1 |] + + let testSimpleArrayEachSeqLoopWithTwoStatements inp = + [| for x in inp do + printfn $"hello, x = {x}" + yield x + 1 |] + + let testSimpleArrayEachArrayLoopWithOneStatement (inp:int array) = + [| for x in inp do + yield x + 1 |] + + let testSimpleArrayEachArrayLoopWithTwoStatements (inp:int array) = + [| for x in inp do + printfn $"hello, x = {x}" + yield x + 1 |] + + let testSimpleArrayEachListLoopWithOneStatement (inp:int list) = + [| for x in inp do + yield x + 1 |] + + let testSimpleArrayEachListLoopWithInitialLetBindings f g (inp:int array) = + [| let y = f () + let z = g () + for x in inp do + printfn $"hello, x = {x}" + yield x + y + z |] + + let testSimpleArrayEachListLoopWithInitialSequentialExpression f g (inp:int array) = + [| f () + g () + for x in inp do + printfn $"hello, x = {x}" + yield x + 1 |] + + let testSimpleArrayEachListLoopWithTwoStatements (inp:int list) = + [| for x in inp do + printfn $"hello, x = {x}" + yield x + 1 |] + + let testSimpleArrayEachStringLoopWithOneStatement (inp:string) = + [| for x in inp do + yield x |] + + let testSimpleArrayEachStringLoopWithTwoStatements (inp:string) = + [| for x in inp do + printfn $"hello, x = {x}" + yield x |] + + let testSimpleArrayEachIntRangeLoopWithOneStatement (start, stop) = + [| for x in start .. stop do + yield x + 1 |] + + let testSimpleArrayEachIntRangeLoopWithInitialLetBindings f g (start, stop) = + [| let y = f () + let z = g () + for x in start .. stop do + printfn $"hello, x = {x}" + yield x + y + z |] + + let testSimpleArrayEachIntRangeLoopWithInitialSequentialExpression f g (start, stop) = + [| f () + g () + for x in start .. stop do + yield x + 1 |] + + let testSimpleArrayEachIntRangeLoopWithTwoStatements (start, stop) = + [| for x in start .. stop do + printfn $"hello, x = {x}" + yield x + 1 |] + + let testSimpleArrayEachIntRangeLoopDownWithOneStatement (start, stop) = + [| for x in stop .. -1 .. start do + yield x + 1 |] + + let testSimpleArrayEachIntRangeLoopDownWithTwoStatements (start, stop) = + [| for x in stop .. -1 .. stop do + printfn $"hello, x = {x}" + yield x + 1 |] + + let testSimpleArrayEachIntLoopWithOneStatement (start, stop) = + [| for x = start to stop do + yield x + 1 |] + + let testSimpleArrayEachIntLoopWithTwoStatements (start, stop) = + [| for x = start to stop do + printfn $"hello, x = {x}" + yield x + 1 |] + + let testSimpleArrayEachIntLoopDownWithOneStatement (start, stop) = + [| for x = stop downto start do + yield x + 1 |] + + let testSimpleArrayEachIntLoopDownWithTwoStatements (start, stop) = + [| for x = stop downto start do + printfn $"hello, x = {x}" + yield x + 1 |] + + testSimpleArrayEachSeqLoopWithOneStatement [1;2;3] + testSimpleArrayEachSeqLoopWithTwoStatements [1;2;3] + testSimpleArrayEachArrayLoopWithOneStatement [|1;2;3|] + testSimpleArrayEachArrayLoopWithTwoStatements [|1;2;3|] + testSimpleArrayEachListLoopWithOneStatement [1;2;3] + testSimpleArrayEachListLoopWithInitialLetBindings (fun () -> 7) (fun () -> 8) [|1;2;3|] + testSimpleArrayEachListLoopWithInitialSequentialExpression (fun () -> printfn "7") (fun () -> printfn "8") [|1;2;3|] + testSimpleArrayEachListLoopWithTwoStatements [1;2;3] + testSimpleArrayEachStringLoopWithOneStatement "123" + testSimpleArrayEachStringLoopWithTwoStatements "123" + testSimpleArrayEachIntRangeLoopWithOneStatement (1, 3) + testSimpleArrayEachIntRangeLoopWithInitialLetBindings (fun () -> 7) (fun () -> 8) (1, 3) + testSimpleArrayEachIntRangeLoopWithInitialSequentialExpression (fun () -> printfn "7") (fun () -> printfn "8") (1, 3) + testSimpleArrayEachIntRangeLoopWithTwoStatements (1, 3) + testSimpleArrayEachIntRangeLoopDownWithOneStatement (1, 3) + testSimpleArrayEachIntRangeLoopDownWithTwoStatements (1, 3) + testSimpleArrayEachIntLoopWithOneStatement (1, 3) + testSimpleArrayEachIntLoopWithTwoStatements (1, 3) + testSimpleArrayEachIntLoopDownWithOneStatement (1, 3) + testSimpleArrayEachIntLoopDownWithTwoStatements (1, 3) + #if NETCOREAPP let testSimpleListEachReadOnlySpanLoopWithOneStatement (inp: System.ReadOnlySpan) = [ for x in inp do From f9b9a7bac5b0036fb45fc3eeaccd3949c4afb08d Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Tue, 30 Apr 2024 11:29:51 -0400 Subject: [PATCH 06/10] We'll always have a for --- 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 7f537925cf2..d411d5fe6d3 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -579,7 +579,7 @@ let (|SeqMap|_|) g = gatherPrelude (function | ValApp g g.seq_map_vref ([ty1; ty2], [Expr.Lambda (valParams = [loopVal]; bodyExpr = body; range = mIn) as mapping; input], mFor) -> let spIn = match mIn.NotedSourceConstruct with NotedSourceConstruct.InOrTo -> DebugPointAtInOrTo.Yes mIn | _ -> DebugPointAtInOrTo.No - let spFor = match mFor.NotedSourceConstruct with NotedSourceConstruct.For -> DebugPointAtBinding.Yes mFor | _ -> DebugPointAtBinding.NoneAtInvisible + let spFor = DebugPointAtBinding.Yes mFor let spInWhile = match spIn with DebugPointAtInOrTo.Yes m -> DebugPointAtWhile.Yes m | DebugPointAtInOrTo.No -> DebugPointAtWhile.No let ranges = body.Range, spFor, spIn, mFor, mIn, spInWhile ValueSome (ty1, ty2, input, mapping, loopVal, body, ranges) @@ -594,7 +594,7 @@ let (|SeqCollectSingle|_|) g = gatherPrelude (function | ValApp g g.seq_collect_vref ([ty1; _; ty2], [Expr.Lambda (valParams = [loopVal]; bodyExpr = SimpleSequential g body; range = mIn) as mapping; input], mFor) -> let spIn = match mIn.NotedSourceConstruct with NotedSourceConstruct.InOrTo -> DebugPointAtInOrTo.Yes mIn | _ -> DebugPointAtInOrTo.No - let spFor = match mFor.NotedSourceConstruct with NotedSourceConstruct.For -> DebugPointAtBinding.Yes mFor | _ -> DebugPointAtBinding.NoneAtInvisible + let spFor = DebugPointAtBinding.Yes mFor let spInWhile = match spIn with DebugPointAtInOrTo.Yes m -> DebugPointAtWhile.Yes m | DebugPointAtInOrTo.No -> DebugPointAtWhile.No let ranges = body.Range, spFor, spIn, mFor, mIn, spInWhile ValueSome (ty1, ty2, input, mapping, loopVal, body, ranges) From 33d8e4ddc936f22e98e1f0af0d842d865e461a97 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Tue, 30 Apr 2024 11:31:12 -0400 Subject: [PATCH 07/10] Add a debug point for for in arrays --- .../Optimize/LowerComputedCollections.fs | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index d411d5fe6d3..012bbc5318b 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -391,38 +391,42 @@ module Array = let ldelem = mkIlInstr g I_ldelem (fun ilTy -> I_ldelem_any (ILArrayShape.SingleDimensional, ilTy)) srcIlTy let stelem = mkIlInstr g I_stelem (fun ilTy -> I_stelem_any (ILArrayShape.SingleDimensional, ilTy)) destIlTy - mkCompGenLetIn m (nameof array) arrayTy array (fun (_, array) -> - mkCompGenLetMutableIn mIn "i" g.int32_ty (mkTypedZero g mIn g.int32_ty) (fun (iVal, i) -> - let body = - // Rebind the loop val to pull directly from the source array. - let body = mkInvisibleLet mBody loopVal (mkAsmExpr ([ldelem], [], [srcArray; i], [loopVal.val_type], mBody)) body - - // destArray[i] <- body srcArray[i] - let setArrSubI = mkAsmExpr ([stelem], [], [array; i; body], [], mIn) - - // i <- i + 1 - let incrI = mkValSet mIn (mkLocalValRef iVal) (mkAsmExpr ([AI_add], [], [i; mkTypedOne g mIn g.int32_ty], [g.int32_ty], mIn)) - - mkSequential mIn setArrSubI incrI - - let guard = mkILAsmClt g mFor i (mkLdlen g mFor array) - - let loop = - mkWhile - g - ( - spInWhile, - WhileLoopForCompiledForEachExprMarker, - guard, - body, - mFor - ) - - // while i < array.Length do done - // array - mkSequential m loop array + let mapping = + mkCompGenLetIn m (nameof array) arrayTy array (fun (_, array) -> + mkCompGenLetMutableIn mFor "i" g.int32_ty (mkTypedZero g mIn g.int32_ty) (fun (iVal, i) -> + let body = + // Rebind the loop val to pull directly from the source array. + let body = mkInvisibleLet mBody loopVal (mkAsmExpr ([ldelem], [], [srcArray; i], [loopVal.val_type], mBody)) body + + // destArray[i] <- body srcArray[i] + let setArrSubI = mkAsmExpr ([stelem], [], [array; i; body], [], mIn) + + // i <- i + 1 + let incrI = mkValSet mIn (mkLocalValRef iVal) (mkAsmExpr ([AI_add], [], [i; mkTypedOne g mIn g.int32_ty], [g.int32_ty], mIn)) + + mkSequential mIn setArrSubI incrI + + let guard = mkILAsmClt g mFor i (mkLdlen g mFor array) + + let loop = + mkWhile + g + ( + spInWhile, + NoSpecialWhileLoopMarker, + guard, + body, + mIn + ) + + // while i < array.Length do done + // array + mkSequential m loop array + ) ) - ) + + // Add a debug point at the `for`, before anything gets evaluated. + Expr.DebugPoint (DebugPointAtLeafExpr.Yes mFor, mapping) /// Whether to check for overflow when converting a value to a native int. [] From dc0d5d318cef316d63fc1d3e240c06016f88b653 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Tue, 30 Apr 2024 13:32:41 -0400 Subject: [PATCH 08/10] Update baselines --- .../ForXInArray_ToArray.fs.il.bsl | 707 +++++++++--------- 1 file changed, 359 insertions(+), 348 deletions(-) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl index a7eb1b8f729..b91b49aec7d 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ComputedCollections/ForXInArray_ToArray.fs.il.bsl @@ -50,35 +50,36 @@ .locals init (int32[] V_0, int32 V_1, int32 V_2) - IL_0000: ldarg.0 - IL_0001: ldlen - IL_0002: conv.i4 - IL_0003: newarr [runtime]System.Int32 - IL_0008: stloc.0 - IL_0009: ldc.i4.0 - IL_000a: stloc.1 - IL_000b: br.s IL_0019 - - IL_000d: ldloc.0 - IL_000e: ldloc.1 - IL_000f: ldarg.0 - IL_0010: ldloc.1 - IL_0011: ldelem.i4 - IL_0012: stloc.2 - IL_0013: ldloc.2 - IL_0014: stelem.i4 - IL_0015: ldloc.1 - IL_0016: ldc.i4.1 - IL_0017: add - IL_0018: stloc.1 - IL_0019: ldloc.1 - IL_001a: ldloc.0 - IL_001b: ldlen - IL_001c: conv.i4 - IL_001d: blt.s IL_000d - - IL_001f: ldloc.0 - IL_0020: ret + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldlen + IL_0003: conv.i4 + IL_0004: newarr [runtime]System.Int32 + IL_0009: stloc.0 + IL_000a: ldc.i4.0 + IL_000b: stloc.1 + IL_000c: br.s IL_001a + + IL_000e: ldloc.0 + IL_000f: ldloc.1 + IL_0010: ldarg.0 + IL_0011: ldloc.1 + IL_0012: ldelem.i4 + IL_0013: stloc.2 + IL_0014: ldloc.2 + IL_0015: stelem.i4 + IL_0016: ldloc.1 + IL_0017: ldc.i4.1 + IL_0018: add + IL_0019: stloc.1 + IL_001a: ldloc.1 + IL_001b: ldloc.0 + IL_001c: ldlen + IL_001d: conv.i4 + IL_001e: blt.s IL_000e + + IL_0020: ldloc.0 + IL_0021: ret } .method public static !!a[] f2(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -90,37 +91,38 @@ .locals init (!!a[] V_0, int32 V_1, int32 V_2) - IL_0000: ldarg.1 - IL_0001: ldlen - IL_0002: conv.i4 - IL_0003: newarr !!a - IL_0008: stloc.0 - IL_0009: ldc.i4.0 - IL_000a: stloc.1 - IL_000b: br.s IL_0023 - - IL_000d: ldloc.0 - IL_000e: ldloc.1 - IL_000f: ldarg.1 - IL_0010: ldloc.1 - IL_0011: ldelem.i4 - IL_0012: stloc.2 - IL_0013: ldarg.0 - IL_0014: ldloc.2 - IL_0015: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_001a: stelem !!a - IL_001f: ldloc.1 - IL_0020: ldc.i4.1 - IL_0021: add - IL_0022: stloc.1 - IL_0023: ldloc.1 - IL_0024: ldloc.0 - IL_0025: ldlen - IL_0026: conv.i4 - IL_0027: blt.s IL_000d - - IL_0029: ldloc.0 - IL_002a: ret + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldlen + IL_0003: conv.i4 + IL_0004: newarr !!a + IL_0009: stloc.0 + IL_000a: ldc.i4.0 + IL_000b: stloc.1 + IL_000c: br.s IL_0024 + + IL_000e: ldloc.0 + IL_000f: ldloc.1 + IL_0010: ldarg.1 + IL_0011: ldloc.1 + IL_0012: ldelem.i4 + IL_0013: stloc.2 + IL_0014: ldarg.0 + IL_0015: ldloc.2 + IL_0016: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001b: stelem !!a + IL_0020: ldloc.1 + IL_0021: ldc.i4.1 + IL_0022: add + IL_0023: stloc.1 + IL_0024: ldloc.1 + IL_0025: ldloc.0 + IL_0026: ldlen + IL_0027: conv.i4 + IL_0028: blt.s IL_000e + + IL_002a: ldloc.0 + IL_002b: ret } .method public static int32[] f3(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -132,39 +134,40 @@ .locals init (int32[] V_0, int32 V_1, int32 V_2) - IL_0000: ldarg.1 - IL_0001: ldlen - IL_0002: conv.i4 - IL_0003: newarr [runtime]System.Int32 - IL_0008: stloc.0 - IL_0009: ldc.i4.0 - IL_000a: stloc.1 - IL_000b: br.s IL_0021 - - IL_000d: ldloc.0 - IL_000e: ldloc.1 - IL_000f: ldarg.1 - IL_0010: ldloc.1 - IL_0011: ldelem.i4 - IL_0012: stloc.2 - IL_0013: ldarg.0 - IL_0014: ldnull - IL_0015: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_001a: pop - IL_001b: ldloc.2 - IL_001c: stelem.i4 - IL_001d: ldloc.1 - IL_001e: ldc.i4.1 - IL_001f: add - IL_0020: stloc.1 - IL_0021: ldloc.1 - IL_0022: ldloc.0 - IL_0023: ldlen - IL_0024: conv.i4 - IL_0025: blt.s IL_000d - - IL_0027: ldloc.0 - IL_0028: ret + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldlen + IL_0003: conv.i4 + IL_0004: newarr [runtime]System.Int32 + IL_0009: stloc.0 + IL_000a: ldc.i4.0 + IL_000b: stloc.1 + IL_000c: br.s IL_0022 + + IL_000e: ldloc.0 + IL_000f: ldloc.1 + IL_0010: ldarg.1 + IL_0011: ldloc.1 + IL_0012: ldelem.i4 + IL_0013: stloc.2 + IL_0014: ldarg.0 + IL_0015: ldnull + IL_0016: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001b: pop + IL_001c: ldloc.2 + IL_001d: stelem.i4 + IL_001e: ldloc.1 + IL_001f: ldc.i4.1 + IL_0020: add + IL_0021: stloc.1 + IL_0022: ldloc.1 + IL_0023: ldloc.0 + IL_0024: ldlen + IL_0025: conv.i4 + IL_0026: blt.s IL_000e + + IL_0028: ldloc.0 + IL_0029: ret } .method public static int32[] f4(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -178,43 +181,44 @@ .locals init (int32[] V_0, int32 V_1, int32 V_2) - IL_0000: ldarg.2 - IL_0001: ldlen - IL_0002: conv.i4 - IL_0003: newarr [runtime]System.Int32 - IL_0008: stloc.0 - IL_0009: ldc.i4.0 - IL_000a: stloc.1 - IL_000b: br.s IL_0029 - - IL_000d: ldloc.0 - IL_000e: ldloc.1 - IL_000f: ldarg.2 - IL_0010: ldloc.1 - IL_0011: ldelem.i4 - IL_0012: stloc.2 - IL_0013: ldarg.0 - IL_0014: ldnull - IL_0015: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_001a: pop - IL_001b: ldarg.1 - IL_001c: ldnull - IL_001d: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_0022: pop - IL_0023: ldloc.2 - IL_0024: stelem.i4 - IL_0025: ldloc.1 - IL_0026: ldc.i4.1 - IL_0027: add - IL_0028: stloc.1 - IL_0029: ldloc.1 - IL_002a: ldloc.0 - IL_002b: ldlen - IL_002c: conv.i4 - IL_002d: blt.s IL_000d + IL_0000: nop + IL_0001: ldarg.2 + IL_0002: ldlen + IL_0003: conv.i4 + IL_0004: newarr [runtime]System.Int32 + IL_0009: stloc.0 + IL_000a: ldc.i4.0 + IL_000b: stloc.1 + IL_000c: br.s IL_002a + + IL_000e: ldloc.0 + IL_000f: ldloc.1 + IL_0010: ldarg.2 + IL_0011: ldloc.1 + IL_0012: ldelem.i4 + IL_0013: stloc.2 + IL_0014: ldarg.0 + IL_0015: ldnull + IL_0016: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001b: pop + IL_001c: ldarg.1 + IL_001d: ldnull + IL_001e: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0023: pop + IL_0024: ldloc.2 + IL_0025: stelem.i4 + IL_0026: ldloc.1 + IL_0027: ldc.i4.1 + IL_0028: add + IL_0029: stloc.1 + IL_002a: ldloc.1 + IL_002b: ldloc.0 + IL_002c: ldlen + IL_002d: conv.i4 + IL_002e: blt.s IL_000e - IL_002f: ldloc.0 - IL_0030: ret + IL_0030: ldloc.0 + IL_0031: ret } .method public static int32[] f5(int32[] 'array') cil managed @@ -224,35 +228,36 @@ .locals init (int32[] V_0, int32 V_1, int32 V_2) - IL_0000: ldarg.0 - IL_0001: ldlen - IL_0002: conv.i4 - IL_0003: newarr [runtime]System.Int32 - IL_0008: stloc.0 - IL_0009: ldc.i4.0 - IL_000a: stloc.1 - IL_000b: br.s IL_0019 - - IL_000d: ldloc.0 - IL_000e: ldloc.1 - IL_000f: ldarg.0 - IL_0010: ldloc.1 - IL_0011: ldelem.i4 - IL_0012: stloc.2 - IL_0013: ldloc.2 - IL_0014: stelem.i4 - IL_0015: ldloc.1 - IL_0016: ldc.i4.1 - IL_0017: add - IL_0018: stloc.1 - IL_0019: ldloc.1 - IL_001a: ldloc.0 - IL_001b: ldlen - IL_001c: conv.i4 - IL_001d: blt.s IL_000d - - IL_001f: ldloc.0 - IL_0020: ret + IL_0000: nop + IL_0001: ldarg.0 + IL_0002: ldlen + IL_0003: conv.i4 + IL_0004: newarr [runtime]System.Int32 + IL_0009: stloc.0 + IL_000a: ldc.i4.0 + IL_000b: stloc.1 + IL_000c: br.s IL_001a + + IL_000e: ldloc.0 + IL_000f: ldloc.1 + IL_0010: ldarg.0 + IL_0011: ldloc.1 + IL_0012: ldelem.i4 + IL_0013: stloc.2 + IL_0014: ldloc.2 + IL_0015: stelem.i4 + IL_0016: ldloc.1 + IL_0017: ldc.i4.1 + IL_0018: add + IL_0019: stloc.1 + IL_001a: ldloc.1 + IL_001b: ldloc.0 + IL_001c: ldlen + IL_001d: conv.i4 + IL_001e: blt.s IL_000e + + IL_0020: ldloc.0 + IL_0021: ret } .method public static int32[] f6(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -264,39 +269,40 @@ .locals init (int32[] V_0, int32 V_1, int32 V_2) - IL_0000: ldarg.1 - IL_0001: ldlen - IL_0002: conv.i4 - IL_0003: newarr [runtime]System.Int32 - IL_0008: stloc.0 - IL_0009: ldc.i4.0 - IL_000a: stloc.1 - IL_000b: br.s IL_0021 - - IL_000d: ldloc.0 - IL_000e: ldloc.1 - IL_000f: ldarg.1 - IL_0010: ldloc.1 - IL_0011: ldelem.i4 - IL_0012: stloc.2 - IL_0013: ldarg.0 - IL_0014: ldnull - IL_0015: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_001a: pop - IL_001b: ldloc.2 - IL_001c: stelem.i4 - IL_001d: ldloc.1 - IL_001e: ldc.i4.1 - IL_001f: add - IL_0020: stloc.1 - IL_0021: ldloc.1 - IL_0022: ldloc.0 - IL_0023: ldlen - IL_0024: conv.i4 - IL_0025: blt.s IL_000d - - IL_0027: ldloc.0 - IL_0028: ret + IL_0000: nop + IL_0001: ldarg.1 + IL_0002: ldlen + IL_0003: conv.i4 + IL_0004: newarr [runtime]System.Int32 + IL_0009: stloc.0 + IL_000a: ldc.i4.0 + IL_000b: stloc.1 + IL_000c: br.s IL_0022 + + IL_000e: ldloc.0 + IL_000f: ldloc.1 + IL_0010: ldarg.1 + IL_0011: ldloc.1 + IL_0012: ldelem.i4 + IL_0013: stloc.2 + IL_0014: ldarg.0 + IL_0015: ldnull + IL_0016: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001b: pop + IL_001c: ldloc.2 + IL_001d: stelem.i4 + IL_001e: ldloc.1 + IL_001f: ldc.i4.1 + IL_0020: add + IL_0021: stloc.1 + IL_0022: ldloc.1 + IL_0023: ldloc.0 + IL_0024: ldlen + IL_0025: conv.i4 + IL_0026: blt.s IL_000e + + IL_0028: ldloc.0 + IL_0029: ret } .method public static int32[] f7(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -310,43 +316,44 @@ .locals init (int32[] V_0, int32 V_1, int32 V_2) - IL_0000: ldarg.2 - IL_0001: ldlen - IL_0002: conv.i4 - IL_0003: newarr [runtime]System.Int32 - IL_0008: stloc.0 - IL_0009: ldc.i4.0 - IL_000a: stloc.1 - IL_000b: br.s IL_0029 - - IL_000d: ldloc.0 - IL_000e: ldloc.1 - IL_000f: ldarg.2 - IL_0010: ldloc.1 - IL_0011: ldelem.i4 - IL_0012: stloc.2 - IL_0013: ldarg.0 - IL_0014: ldnull - IL_0015: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_001a: pop - IL_001b: ldarg.1 - IL_001c: ldnull - IL_001d: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) - IL_0022: pop - IL_0023: ldloc.2 - IL_0024: stelem.i4 - IL_0025: ldloc.1 - IL_0026: ldc.i4.1 - IL_0027: add - IL_0028: stloc.1 - IL_0029: ldloc.1 - IL_002a: ldloc.0 - IL_002b: ldlen - IL_002c: conv.i4 - IL_002d: blt.s IL_000d + IL_0000: nop + IL_0001: ldarg.2 + IL_0002: ldlen + IL_0003: conv.i4 + IL_0004: newarr [runtime]System.Int32 + IL_0009: stloc.0 + IL_000a: ldc.i4.0 + IL_000b: stloc.1 + IL_000c: br.s IL_002a + + IL_000e: ldloc.0 + IL_000f: ldloc.1 + IL_0010: ldarg.2 + IL_0011: ldloc.1 + IL_0012: ldelem.i4 + IL_0013: stloc.2 + IL_0014: ldarg.0 + IL_0015: ldnull + IL_0016: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_001b: pop + IL_001c: ldarg.1 + IL_001d: ldnull + IL_001e: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) + IL_0023: pop + IL_0024: ldloc.2 + IL_0025: stelem.i4 + IL_0026: ldloc.1 + IL_0027: ldc.i4.1 + IL_0028: add + IL_0029: stloc.1 + IL_002a: ldloc.1 + IL_002b: ldloc.0 + IL_002c: ldlen + IL_002d: conv.i4 + IL_002e: blt.s IL_000e - IL_002f: ldloc.0 - IL_0030: ret + IL_0030: ldloc.0 + IL_0031: ret } .method public static int32[] f8(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -371,39 +378,40 @@ IL_000a: ldnull IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) IL_0010: stloc.1 - IL_0011: ldarg.2 - IL_0012: ldlen - IL_0013: conv.i4 - IL_0014: newarr [runtime]System.Int32 - IL_0019: stloc.2 - IL_001a: ldc.i4.0 - IL_001b: stloc.3 - IL_001c: br.s IL_0030 - - IL_001e: ldloc.2 - IL_001f: ldloc.3 - IL_0020: ldarg.2 - IL_0021: ldloc.3 - IL_0022: ldelem.i4 - IL_0023: stloc.s V_4 - IL_0025: ldloc.s V_4 - IL_0027: ldloc.0 - IL_0028: add - IL_0029: ldloc.1 - IL_002a: add - IL_002b: stelem.i4 - IL_002c: ldloc.3 - IL_002d: ldc.i4.1 - IL_002e: add - IL_002f: stloc.3 - IL_0030: ldloc.3 - IL_0031: ldloc.2 - IL_0032: ldlen - IL_0033: conv.i4 - IL_0034: blt.s IL_001e - - IL_0036: ldloc.2 - IL_0037: ret + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: ldlen + IL_0014: conv.i4 + IL_0015: newarr [runtime]System.Int32 + IL_001a: stloc.2 + IL_001b: ldc.i4.0 + IL_001c: stloc.3 + IL_001d: br.s IL_0031 + + IL_001f: ldloc.2 + IL_0020: ldloc.3 + IL_0021: ldarg.2 + IL_0022: ldloc.3 + IL_0023: ldelem.i4 + IL_0024: stloc.s V_4 + IL_0026: ldloc.s V_4 + IL_0028: ldloc.0 + IL_0029: add + IL_002a: ldloc.1 + IL_002b: add + IL_002c: stelem.i4 + IL_002d: ldloc.3 + IL_002e: ldc.i4.1 + IL_002f: add + IL_0030: stloc.3 + IL_0031: ldloc.3 + IL_0032: ldloc.2 + IL_0033: ldlen + IL_0034: conv.i4 + IL_0035: blt.s IL_001f + + IL_0037: ldloc.2 + IL_0038: ret } .method public static int32[] f9(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -427,37 +435,38 @@ IL_000a: ldnull IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) IL_0010: pop - IL_0011: ldarg.2 - IL_0012: ldlen - IL_0013: conv.i4 - IL_0014: newarr [runtime]System.Int32 - IL_0019: stloc.1 - IL_001a: ldc.i4.0 - IL_001b: stloc.2 - IL_001c: br.s IL_002c + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: ldlen + IL_0014: conv.i4 + IL_0015: newarr [runtime]System.Int32 + IL_001a: stloc.1 + IL_001b: ldc.i4.0 + IL_001c: stloc.2 + IL_001d: br.s IL_002d - IL_001e: ldloc.1 - IL_001f: ldloc.2 - IL_0020: ldarg.2 - IL_0021: ldloc.2 - IL_0022: ldelem.i4 - IL_0023: stloc.3 - IL_0024: ldloc.3 - IL_0025: ldloc.0 - IL_0026: add - IL_0027: stelem.i4 - IL_0028: ldloc.2 - IL_0029: ldc.i4.1 - IL_002a: add - IL_002b: stloc.2 - IL_002c: ldloc.2 - IL_002d: ldloc.1 - IL_002e: ldlen - IL_002f: conv.i4 - IL_0030: blt.s IL_001e - - IL_0032: ldloc.1 - IL_0033: ret + IL_001f: ldloc.1 + IL_0020: ldloc.2 + IL_0021: ldarg.2 + IL_0022: ldloc.2 + IL_0023: ldelem.i4 + IL_0024: stloc.3 + IL_0025: ldloc.3 + IL_0026: ldloc.0 + IL_0027: add + IL_0028: stelem.i4 + IL_0029: ldloc.2 + IL_002a: ldc.i4.1 + IL_002b: add + IL_002c: stloc.2 + IL_002d: ldloc.2 + IL_002e: ldloc.1 + IL_002f: ldlen + IL_0030: conv.i4 + IL_0031: blt.s IL_001f + + IL_0033: ldloc.1 + IL_0034: ret } .method public static int32[] f10(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -480,35 +489,36 @@ IL_000a: ldnull IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) IL_0010: pop - IL_0011: ldarg.2 - IL_0012: ldlen - IL_0013: conv.i4 - IL_0014: newarr [runtime]System.Int32 - IL_0019: stloc.0 - IL_001a: ldc.i4.0 - IL_001b: stloc.1 - IL_001c: br.s IL_002a - - IL_001e: ldloc.0 - IL_001f: ldloc.1 - IL_0020: ldarg.2 - IL_0021: ldloc.1 - IL_0022: ldelem.i4 - IL_0023: stloc.2 - IL_0024: ldloc.2 - IL_0025: stelem.i4 - IL_0026: ldloc.1 - IL_0027: ldc.i4.1 - IL_0028: add - IL_0029: stloc.1 - IL_002a: ldloc.1 - IL_002b: ldloc.0 - IL_002c: ldlen - IL_002d: conv.i4 - IL_002e: blt.s IL_001e + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: ldlen + IL_0014: conv.i4 + IL_0015: newarr [runtime]System.Int32 + IL_001a: stloc.0 + IL_001b: ldc.i4.0 + IL_001c: stloc.1 + IL_001d: br.s IL_002b - IL_0030: ldloc.0 - IL_0031: ret + IL_001f: ldloc.0 + IL_0020: ldloc.1 + IL_0021: ldarg.2 + IL_0022: ldloc.1 + IL_0023: ldelem.i4 + IL_0024: stloc.2 + IL_0025: ldloc.2 + IL_0026: stelem.i4 + IL_0027: ldloc.1 + IL_0028: ldc.i4.1 + IL_0029: add + IL_002a: stloc.1 + IL_002b: ldloc.1 + IL_002c: ldloc.0 + IL_002d: ldlen + IL_002e: conv.i4 + IL_002f: blt.s IL_001f + + IL_0031: ldloc.0 + IL_0032: ret } .method public static int32[] f11(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2 f, @@ -532,37 +542,38 @@ IL_000a: ldnull IL_000b: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::Invoke(!0) IL_0010: stloc.0 - IL_0011: ldarg.2 - IL_0012: ldlen - IL_0013: conv.i4 - IL_0014: newarr [runtime]System.Int32 - IL_0019: stloc.1 - IL_001a: ldc.i4.0 - IL_001b: stloc.2 - IL_001c: br.s IL_002c + IL_0011: nop + IL_0012: ldarg.2 + IL_0013: ldlen + IL_0014: conv.i4 + IL_0015: newarr [runtime]System.Int32 + IL_001a: stloc.1 + IL_001b: ldc.i4.0 + IL_001c: stloc.2 + IL_001d: br.s IL_002d - IL_001e: ldloc.1 - IL_001f: ldloc.2 - IL_0020: ldarg.2 - IL_0021: ldloc.2 - IL_0022: ldelem.i4 - IL_0023: stloc.3 - IL_0024: ldloc.3 - IL_0025: ldloc.0 - IL_0026: add - IL_0027: stelem.i4 - IL_0028: ldloc.2 - IL_0029: ldc.i4.1 - IL_002a: add - IL_002b: stloc.2 - IL_002c: ldloc.2 - IL_002d: ldloc.1 - IL_002e: ldlen - IL_002f: conv.i4 - IL_0030: blt.s IL_001e - - IL_0032: ldloc.1 - IL_0033: ret + IL_001f: ldloc.1 + IL_0020: ldloc.2 + IL_0021: ldarg.2 + IL_0022: ldloc.2 + IL_0023: ldelem.i4 + IL_0024: stloc.3 + IL_0025: ldloc.3 + IL_0026: ldloc.0 + IL_0027: add + IL_0028: stelem.i4 + IL_0029: ldloc.2 + IL_002a: ldc.i4.1 + IL_002b: add + IL_002c: stloc.2 + IL_002d: ldloc.2 + IL_002e: ldloc.1 + IL_002f: ldlen + IL_0030: conv.i4 + IL_0031: blt.s IL_001f + + IL_0033: ldloc.1 + IL_0034: ret } } From 090a30a3e1390e31e5dd65b82d88dc3eebcb0b59 Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Mon, 6 May 2024 10:39:33 -0400 Subject: [PATCH 09/10] Reapply all debug points --- src/Compiler/Optimize/LowerComputedCollections.fs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index 012bbc5318b..cf80e416ea2 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -528,18 +528,15 @@ module Array = /// /// E.g., in [for x in … do f (); …; yield x] [] -let (|SimpleSequential|_|) g expr = +let (|SimpleSequential|_|) g expr : Expr voption = let rec loop expr cont = match expr with - | Expr.Sequential (expr1, DebugPoints (ValApp g g.seq_singleton_vref (_, [body], _), debug), kind, m) -> - ValueSome (cont (expr1, debug body, kind, m)) - - | Expr.Sequential (expr1, body, kind, m) -> - loop body (cont >> fun body -> Expr.Sequential (expr1, body, kind, m)) + | Expr.Sequential (expr1, DebugPoints ((ValApp g g.seq_singleton_vref (_, [body], _) | body), debug), kind, m) -> + loop body (cont << fun body -> Expr.Sequential (expr1, debug body, kind, m)) | _ -> ValueNone - loop expr Expr.Sequential + loop expr id /// Extracts any let-bindings or sequential /// expressions that directly precede the specified mapping application, e.g., From 93e74db2d9ab37d9d3262016e5543d525c8aa80c Mon Sep 17 00:00:00 2001 From: Brian Rourke Boll Date: Mon, 6 May 2024 11:33:17 -0400 Subject: [PATCH 10/10] Match the right thing --- src/Compiler/Optimize/LowerComputedCollections.fs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Compiler/Optimize/LowerComputedCollections.fs b/src/Compiler/Optimize/LowerComputedCollections.fs index cf80e416ea2..2d2e02a9df3 100644 --- a/src/Compiler/Optimize/LowerComputedCollections.fs +++ b/src/Compiler/Optimize/LowerComputedCollections.fs @@ -531,12 +531,15 @@ module Array = let (|SimpleSequential|_|) g expr : Expr voption = let rec loop expr cont = match expr with - | Expr.Sequential (expr1, DebugPoints ((ValApp g g.seq_singleton_vref (_, [body], _) | body), debug), kind, m) -> - loop body (cont << fun body -> Expr.Sequential (expr1, debug body, kind, m)) + | Expr.Sequential (expr1, DebugPoints (ValApp g g.seq_singleton_vref (_, [body], _), debug), kind, m) -> + ValueSome (cont (expr1, debug body, kind, m)) + + | Expr.Sequential (expr1, DebugPoints (body, debug), kind, m) -> + loop body (cont >> fun body -> Expr.Sequential (expr1, debug body, kind, m)) | _ -> ValueNone - loop expr id + loop expr Expr.Sequential /// Extracts any let-bindings or sequential /// expressions that directly precede the specified mapping application, e.g.,