Skip to content

Commit efe3c9d

Browse files
authored
Prevent tailcalls when pinning locals; add regression coverage (#19148)
1 parent ba99dd5 commit efe3c9d

File tree

3 files changed

+44
-59
lines changed

3 files changed

+44
-59
lines changed

tests/FSharp.Compiler.ComponentTests/EmittedIL/Structure/FloatsAndDoubles.fs.RealInternalSignatureOff.il.release.bsl

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@
1616

1717
.hash algorithm 0x00008004
1818
.ver 0:0:0:0
19-
}
20-
.mresource public FSharpSignatureCompressedData.assembly
21-
{
22-
23-
24-
}
25-
.mresource public FSharpOptimizationCompressedData.assembly
26-
{
27-
28-
2919
}
3020
.module assembly.exe
3121

@@ -130,9 +120,7 @@
130120
IL_000c: ret
131121
}
132122

133-
.method public hidebysig virtual final
134-
instance int32 CompareTo(object obj,
135-
class [runtime]System.Collections.IComparer comp) cil managed
123+
.method public hidebysig virtual final instance int32 CompareTo(object obj, class [runtime]System.Collections.IComparer comp) cil managed
136124
{
137125
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
138126

@@ -228,9 +216,7 @@
228216
IL_000b: ret
229217
}
230218

231-
.method public hidebysig instance bool
232-
Equals(valuetype floatsanddoubles/Float obj,
233-
class [runtime]System.Collections.IEqualityComparer comp) cil managed
219+
.method public hidebysig instance bool Equals(valuetype floatsanddoubles/Float obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed
234220
{
235221
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
236222

@@ -249,9 +235,7 @@
249235
IL_0013: ret
250236
}
251237

252-
.method public hidebysig virtual final
253-
instance bool Equals(object obj,
254-
class [runtime]System.Collections.IEqualityComparer comp) cil managed
238+
.method public hidebysig virtual final instance bool Equals(object obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed
255239
{
256240
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
257241

@@ -451,9 +435,7 @@
451435
IL_000c: ret
452436
}
453437

454-
.method public hidebysig virtual final
455-
instance int32 CompareTo(object obj,
456-
class [runtime]System.Collections.IComparer comp) cil managed
438+
.method public hidebysig virtual final instance int32 CompareTo(object obj, class [runtime]System.Collections.IComparer comp) cil managed
457439
{
458440
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
459441

@@ -549,9 +531,7 @@
549531
IL_000b: ret
550532
}
551533

552-
.method public hidebysig instance bool
553-
Equals(valuetype floatsanddoubles/Double obj,
554-
class [runtime]System.Collections.IEqualityComparer comp) cil managed
534+
.method public hidebysig instance bool Equals(valuetype floatsanddoubles/Double obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed
555535
{
556536
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
557537

@@ -570,9 +550,7 @@
570550
IL_0013: ret
571551
}
572552

573-
.method public hidebysig virtual final
574-
instance bool Equals(object obj,
575-
class [runtime]System.Collections.IEqualityComparer comp) cil managed
553+
.method public hidebysig virtual final instance bool Equals(object obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed
576554
{
577555
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
578556

@@ -1400,4 +1378,3 @@
14001378

14011379

14021380

1403-

tests/FSharp.Compiler.ComponentTests/EmittedIL/Structure/FloatsAndDoubles.fs.RealInternalSignatureOn.il.release.bsl

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@
1616

1717
.hash algorithm 0x00008004
1818
.ver 0:0:0:0
19-
}
20-
.mresource public FSharpSignatureCompressedData.assembly
21-
{
22-
23-
24-
}
25-
.mresource public FSharpOptimizationCompressedData.assembly
26-
{
27-
28-
2919
}
3020
.module assembly.exe
3121

@@ -130,9 +120,7 @@
130120
IL_000c: ret
131121
}
132122

133-
.method public hidebysig virtual final
134-
instance int32 CompareTo(object obj,
135-
class [runtime]System.Collections.IComparer comp) cil managed
123+
.method public hidebysig virtual final instance int32 CompareTo(object obj, class [runtime]System.Collections.IComparer comp) cil managed
136124
{
137125
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
138126

@@ -228,9 +216,7 @@
228216
IL_000b: ret
229217
}
230218

231-
.method public hidebysig instance bool
232-
Equals(valuetype floatsanddoubles/Float obj,
233-
class [runtime]System.Collections.IEqualityComparer comp) cil managed
219+
.method public hidebysig instance bool Equals(valuetype floatsanddoubles/Float obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed
234220
{
235221
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
236222

@@ -249,9 +235,7 @@
249235
IL_0013: ret
250236
}
251237

252-
.method public hidebysig virtual final
253-
instance bool Equals(object obj,
254-
class [runtime]System.Collections.IEqualityComparer comp) cil managed
238+
.method public hidebysig virtual final instance bool Equals(object obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed
255239
{
256240
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
257241

@@ -451,9 +435,7 @@
451435
IL_000c: ret
452436
}
453437

454-
.method public hidebysig virtual final
455-
instance int32 CompareTo(object obj,
456-
class [runtime]System.Collections.IComparer comp) cil managed
438+
.method public hidebysig virtual final instance int32 CompareTo(object obj, class [runtime]System.Collections.IComparer comp) cil managed
457439
{
458440
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
459441

@@ -549,9 +531,7 @@
549531
IL_000b: ret
550532
}
551533

552-
.method public hidebysig instance bool
553-
Equals(valuetype floatsanddoubles/Double obj,
554-
class [runtime]System.Collections.IEqualityComparer comp) cil managed
534+
.method public hidebysig instance bool Equals(valuetype floatsanddoubles/Double obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed
555535
{
556536
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
557537

@@ -570,9 +550,7 @@
570550
IL_0013: ret
571551
}
572552

573-
.method public hidebysig virtual final
574-
instance bool Equals(object obj,
575-
class [runtime]System.Collections.IEqualityComparer comp) cil managed
553+
.method public hidebysig virtual final instance bool Equals(object obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed
576554
{
577555
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
578556

@@ -1410,4 +1388,3 @@
14101388

14111389

14121390

1413-

tests/FSharp.Compiler.ComponentTests/EmittedIL/TailCalls.fs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ let run() =
251251
IL_0040: ldc.i4.s 42
252252
IL_0042: ldc.i4.5
253253
IL_0043: call void TailCall06::foo<int32>(int32,
254-
!!0)
254+
!!0)
255255
"""
256256
]
257257

@@ -276,3 +276,34 @@ let rec countdown n =
276276
"""
277277
]
278278

279+
[<Fact>]
280+
let ``TailCall 08 - No tail call when pinning local byref``() =
281+
FSharp """
282+
module TailCall08
283+
284+
open Microsoft.FSharp.NativeInterop
285+
open System.Runtime.CompilerServices
286+
287+
[<MethodImpl(MethodImplOptions.NoInlining)>]
288+
let bar (pValue: nativeptr<int>) : unit =
289+
let value = NativePtr.read pValue
290+
printfn "value = %A" value
291+
292+
[<MethodImpl(MethodImplOptions.NoInlining)>]
293+
let foo() =
294+
let mutable value = 42
295+
use ptr = fixed &value
296+
bar ptr
297+
298+
[<EntryPoint>]
299+
let main _ =
300+
foo()
301+
0
302+
"""
303+
|> asExe
304+
|> compileWithTailCalls
305+
|> shouldSucceed
306+
|> run
307+
|> shouldSucceed
308+
|> verifyOutput "value = 42\n"
309+

0 commit comments

Comments
 (0)