Skip to content

Commit c5da378

Browse files
authored
Fix debug tailcalls for pipelines if /tailcalls+ is explicitly specified (#12430)
* don't suppress tailcalls in pipeline debugging if tailcalls are on * don't suppress tailcalls in pipeline debugging if tailcalls are on
1 parent 3d15c43 commit c5da378

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

src/fsharp/IlxGen.fs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2941,26 +2941,35 @@ and GenLinearExpr cenv cgbuf eenv sp expr sequel preSteps (contf: FakeUnit -> Fa
29412941
// Compiler generated sequential executions result in suppressions of debug points on both
29422942
// left and right of the sequence
29432943
let spStmt, spExpr =
2944-
(match spSeq with
2945-
| DebugPointAtSequential.SuppressNeither -> SPAlways, SPAlways
2946-
| DebugPointAtSequential.SuppressStmt -> SPSuppress, sp
2947-
| DebugPointAtSequential.SuppressExpr -> sp, SPSuppress
2948-
| DebugPointAtSequential.SuppressBoth -> SPSuppress, SPSuppress)
2944+
match spSeq with
2945+
| DebugPointAtSequential.SuppressNeither -> SPAlways, SPAlways
2946+
| DebugPointAtSequential.SuppressStmt -> SPSuppress, sp
2947+
| DebugPointAtSequential.SuppressExpr -> sp, SPSuppress
2948+
| DebugPointAtSequential.SuppressBoth -> SPSuppress, SPSuppress
2949+
29492950
match specialSeqFlag with
29502951
| NormalSeq ->
29512952
GenExpr cenv cgbuf eenv spStmt e1 discard
29522953
GenLinearExpr cenv cgbuf eenv spExpr e2 sequel true contf
29532954
| ThenDoSeq ->
2954-
let g = cenv.g
2955-
let isUnit = isUnitTy g (tyOfExpr g e1)
2956-
if isUnit then
2957-
GenExpr cenv cgbuf eenv spExpr e1 discard
2958-
GenExpr cenv cgbuf eenv spStmt e2 discard
2959-
GenUnitThenSequel cenv eenv e2.Range eenv.cloc cgbuf sequel
2960-
else
2961-
GenExpr cenv cgbuf eenv spExpr e1 Continue
2962-
GenExpr cenv cgbuf eenv spStmt e2 discard
2963-
GenSequel cenv eenv.cloc cgbuf sequel
2955+
// "e then ()" with DebugPointAtSequential.SuppressStmt is used
2956+
// in mkDebugPoint to emit a debug point on "e". However we don't want this to interfere
2957+
// with tailcalls, so detect this case and throw the "then ()" away, having already
2958+
// worked out "spExpr" up above.
2959+
match e2 with
2960+
| Expr.Const (Const.Unit, _, _) ->
2961+
GenExpr cenv cgbuf eenv spExpr e1 sequel
2962+
| _ ->
2963+
let g = cenv.g
2964+
let isUnit = isUnitTy g (tyOfExpr g e1)
2965+
if isUnit then
2966+
GenExpr cenv cgbuf eenv spExpr e1 discard
2967+
GenExpr cenv cgbuf eenv spStmt e2 discard
2968+
GenUnitThenSequel cenv eenv e2.Range eenv.cloc cgbuf sequel
2969+
else
2970+
GenExpr cenv cgbuf eenv spExpr e1 Continue
2971+
GenExpr cenv cgbuf eenv spStmt e2 discard
2972+
GenSequel cenv eenv.cloc cgbuf sequel
29642973
contf Fake
29652974

29662975
| Expr.Let (bind, body, _, _) ->

tests/fsharpqa/Source/CodeGen/EmittedIL/TestFunctions/Testfunction15.il.bsl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
.assembly extern FSharp.Core
1414
{
1515
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....:
16-
.ver 5:0:0:0
16+
.ver 6:0:0:0
1717
}
1818
.assembly TestFunction15
1919
{
@@ -36,13 +36,13 @@
3636
// Offset: 0x000001F0 Length: 0x00000072
3737
}
3838
.module TestFunction15.exe
39-
// MVID: {611B0ED4-A624-4662-A745-0383D40E1B61}
39+
// MVID: {6197D1F9-A624-4662-A745-0383F9D19761}
4040
.imagebase 0x00400000
4141
.file alignment 0x00000200
4242
.stackreserve 0x00100000
4343
.subsystem 0x0003 // WINDOWS_CUI
4444
.corflags 0x00000001 // ILONLY
45-
// Image base: 0x07120000
45+
// Image base: 0x06AD0000
4646

4747

4848
// =============== CLASS MEMBERS DECLARATION ===================
@@ -95,7 +95,7 @@
9595
.method public static class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<int32>
9696
TestFunction15(int32 inp) cil managed
9797
{
98-
// Code size 40 (0x28)
98+
// Code size 42 (0x2a)
9999
.maxstack 6
100100
.locals init ([0] int32 x,
101101
[1] class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<int32> 'Pipe #1 input at line 6')
@@ -119,9 +119,10 @@
119119
.line 6,6 : 16,41 ''
120120
IL_001c: ldsfld class TestFunction15/TestFunction15@6 TestFunction15/TestFunction15@6::@_instance
121121
IL_0021: ldloc.1
122-
IL_0022: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!!1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map<int32,int32>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<!!0,!!1>,
122+
IL_0022: tail.
123+
IL_0024: call class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!!1> [FSharp.Core]Microsoft.FSharp.Collections.ListModule::Map<int32,int32>(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<!!0,!!1>,
123124
class [FSharp.Core]Microsoft.FSharp.Collections.FSharpList`1<!!0>)
124-
IL_0027: ret
125+
IL_0029: ret
125126
} // end of method TestFunction15::TestFunction15
126127

127128
} // end of class TestFunction15

0 commit comments

Comments
 (0)