Skip to content

Commit

Permalink
Moved CodeGen/EmittedIL/TailCalls over to NUnit (dotnet#7386)
Browse files Browse the repository at this point in the history
* TailCalls test migration

* fix the diff in IL

* fix for netcore
  • Loading branch information
sergey-tihon authored and nosami committed Feb 22, 2021
1 parent c47efcb commit c5788af
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 587 deletions.
253 changes: 253 additions & 0 deletions tests/fsharp/Compiler/CodeGen/EmittedIL/TailCalls.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Compiler.UnitTests.CodeGen.EmittedIL

open FSharp.Compiler.UnitTests
open NUnit.Framework

[<TestFixture>]
module ``TailCalls`` =
// Regression test for DevDiv:72571

[<Test>]
let ``TailCall 01``() =
CompilerAssert.CompileLibraryAndVerifyILWithOptions [|"-g"; "--optimize-"; "--tailcalls+"|]
"""
module TailCall01
let foo(x:int, y) = printfn "%d" x
let run() = let x = 0 in foo(x,5)
"""
(fun verifier -> verifier.VerifyIL [
"""
.method public static void foo<a>(int32 x,
!!a y) cil managed
{
.maxstack 4
.locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit> V_0,
int32 V_1)
IL_0000: ldstr "%d"
IL_0005: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5<class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit>,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit,int32>::.ctor(string)
IL_000a: call !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine<class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit>>(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4<!!0,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit>)
IL_000f: stloc.0
IL_0010: ldarg.0
IL_0011: stloc.1
IL_0012: ldloc.0
IL_0013: ldloc.1
IL_0014: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit>::Invoke(!0)
IL_0019: pop
IL_001a: ret
}
"""
"""
.method public static void run() cil managed
{
.maxstack 4
.locals init (int32 V_0)
IL_0000: ldc.i4.0
IL_0001: stloc.0
IL_0002: ldloc.0
IL_0003: ldc.i4.5
IL_0004: tail.
IL_0006: call void TailCall01::foo<int32>(int32,
!!0)
IL_000b: ret
}
"""
])

[<Test>]
let ``TailCall 02``() =
CompilerAssert.CompileLibraryAndVerifyILWithOptions [|"-g"; "--optimize-"; "--tailcalls+"|]
"""
module TailCall02
let foo(x:int byref) = x
let run() = let mutable x = 0 in foo(&x)
"""
(fun verifier -> verifier.VerifyIL [
"""
.method public static int32 foo(int32& x) cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldobj [runtime]System.Int32
IL_0006: ret
}
"""
"""
.method public static int32 run() cil managed
{
.maxstack 3
.locals init (int32 V_0)
IL_0000: ldc.i4.0
IL_0001: stloc.0
IL_0002: ldloca.s V_0
IL_0004: call int32 TailCall02::foo(int32&)
IL_0009: ret
}
"""
])

[<Test>]
let ``TailCall 03``() =
CompilerAssert.CompileLibraryAndVerifyILWithOptions [|"-g"; "--optimize-"; "--tailcalls+"|]
"""
module TailCall03
let foo (x:int byref) (y:int byref) z = printfn "%d" (x+y)
let run() = let mutable x = 0 in foo &x &x 5
"""
(fun verifier -> verifier.VerifyIL [
"""
.method public static void foo<a>(int32& x,
int32& y,
!!a z) 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 (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit> V_0,
int32 V_1)
IL_0000: ldstr "%d"
IL_0005: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5<class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit>,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit,int32>::.ctor(string)
IL_000a: call !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine<class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit>>(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4<!!0,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit>)
IL_000f: stloc.0
IL_0010: ldarg.0
IL_0011: ldobj [runtime]System.Int32
IL_0016: ldarg.1
IL_0017: ldobj [runtime]System.Int32
IL_001c: add
IL_001d: stloc.1
IL_001e: ldloc.0
IL_001f: ldloc.1
IL_0020: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit>::Invoke(!0)
IL_0025: pop
IL_0026: ret
}
"""
"""
.method public static void run() cil managed
{
.maxstack 5
.locals init (int32 V_0)
IL_0000: ldc.i4.0
IL_0001: stloc.0
IL_0002: ldloca.s V_0
IL_0004: ldloca.s V_0
IL_0006: ldc.i4.5
IL_0007: call void TailCall03::foo<int32>(int32&,
int32&,
!!0)
IL_000c: nop
IL_000d: ret
}
"""
])

[<Test>]
let ``TailCall 04``() =
CompilerAssert.CompileLibraryAndVerifyILWithOptions [|"-g"; "--optimize-"; "--tailcalls+"|]
"""
module TailCall04
let foo(x:int byref, y) = printfn "%d" x
let run() = let mutable x = 0 in foo(&x,5)
"""
(fun verifier -> verifier.VerifyIL [
"""
.method public static void foo<a>(int32& x,
!!a y) cil managed
{
.maxstack 4
.locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit> V_0,
int32 V_1)
IL_0000: ldstr "%d"
IL_0005: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5<class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit>,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit,int32>::.ctor(string)
IL_000a: call !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine<class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit>>(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4<!!0,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit>)
IL_000f: stloc.0
IL_0010: ldarg.0
IL_0011: ldobj [runtime]System.Int32
IL_0016: stloc.1
IL_0017: ldloc.0
IL_0018: ldloc.1
IL_0019: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit>::Invoke(!0)
IL_001e: pop
IL_001f: ret
}
"""
"""
.method public static void run() cil managed
{
.maxstack 4
.locals init (int32 V_0)
IL_0000: ldc.i4.0
IL_0001: stloc.0
IL_0002: ldloca.s V_0
IL_0004: ldc.i4.5
IL_0005: call void TailCall04::foo<int32>(int32&,
!!0)
IL_000a: nop
IL_000b: ret
"""
])

[<Test>]
let ``TailCall 05``() =
CompilerAssert.CompileLibraryAndVerifyILWithOptions [|"-g"; "--optimize-"; "--tailcalls+"|]
"""
module TailCall05
let foo(x:int byref, y:int byref, z) = printfn "%d" (x+y)
let run() = let mutable x = 0 in foo(&x,&x,5)
"""
(fun verifier -> verifier.VerifyIL [
"""
.method public static void foo<a>(int32& x,
int32& y,
!!a z) cil managed
{
.maxstack 4
.locals init (class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit> V_0,
int32 V_1)
IL_0000: ldstr "%d"
IL_0005: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5<class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit>,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit,int32>::.ctor(string)
IL_000a: call !!0 [FSharp.Core]Microsoft.FSharp.Core.ExtraTopLevelOperators::PrintFormatLine<class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit>>(class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4<!!0,class [runtime]System.IO.TextWriter,class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit>)
IL_000f: stloc.0
IL_0010: ldarg.0
IL_0011: ldobj [runtime]System.Int32
IL_0016: ldarg.1
IL_0017: ldobj [runtime]System.Int32
IL_001c: add
IL_001d: stloc.1
IL_001e: ldloc.0
IL_001f: ldloc.1
IL_0020: callvirt instance !1 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<int32,class [FSharp.Core]Microsoft.FSharp.Core.Unit>::Invoke(!0)
IL_0025: pop
IL_0026: ret
}
"""
"""
.method public static void run() cil managed
{
.maxstack 5
.locals init (int32 V_0)
IL_0000: ldc.i4.0
IL_0001: stloc.0
IL_0002: ldloca.s V_0
IL_0004: ldloca.s V_0
IL_0006: ldc.i4.5
IL_0007: call void TailCall05::foo<int32>(int32&,
int32&,
!!0)
IL_000c: nop
IL_000d: ret
}
"""
])
2 changes: 1 addition & 1 deletion tests/fsharp/Compiler/ILChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module ILChecker =

let unifyRuntimeAssemblyName ilCode =
System.Text.RegularExpressions.Regex.Replace(ilCode,
"\[System.Runtime\]|\[mscorlib\]","[runtime]",
"\[System.Runtime\]|\[System.Runtime.Extensions\]|\[mscorlib\]","[runtime]",
System.Text.RegularExpressions.RegexOptions.Singleline)

let text =
Expand Down
1 change: 1 addition & 0 deletions tests/fsharp/FSharpSuite.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Compile Include="Compiler\CompilerAssert.fs" />
<Compile Include="Compiler\CodeGen\EmittedIL\LiteralValue.fs" />
<Compile Include="Compiler\CodeGen\EmittedIL\Mutation.fs" />
<Compile Include="Compiler\CodeGen\EmittedIL\TailCalls.fs" />
<Compile Include="Compiler\Conformance\BasicGrammarElements\BasicConstants.fs" />
<Compile Include="Compiler\ErrorMessages\ConstructorTests.fs" />
<Compile Include="Compiler\ErrorMessages\ClassesTests.fs" />
Expand Down

This file was deleted.

111 changes: 0 additions & 111 deletions tests/fsharpqa/Source/CodeGen/EmittedIL/TailCalls/TailCall01.il.bsl

This file was deleted.

This file was deleted.

Loading

0 comments on commit c5788af

Please sign in to comment.