Skip to content

Commit c3f34de

Browse files
committed
Add IL baseline tests for print and printn
Verify that inline specialization produces direct calls to Int32.ToString, Double.ToString with InvariantCulture, and Console.Out.Write/WriteLine for the respective types.
1 parent 1c1389a commit c3f34de

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+
namespace EmittedIL
4+
5+
open Xunit
6+
open FSharp.Test.Compiler
7+
8+
module PrintFunction =
9+
10+
[<Fact>]
11+
let ``print with int specializes to Int32 ToString with InvariantCulture``() =
12+
FSharp """
13+
module PrintInt
14+
15+
let printInt () = print 42
16+
"""
17+
|> withOptimize
18+
|> compile
19+
|> shouldSucceed
20+
|> verifyIL [
21+
"""call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out()"""
22+
"""call class [netstandard]System.Globalization.CultureInfo [netstandard]System.Globalization.CultureInfo::get_InvariantCulture()"""
23+
"""call instance string [netstandard]System.Int32::ToString(string,"""
24+
"""callvirt instance void [netstandard]System.IO.TextWriter::Write(string)"""]
25+
26+
[<Fact>]
27+
let ``printn with int specializes to Int32 ToString with InvariantCulture``() =
28+
FSharp """
29+
module PrintnInt
30+
31+
let printnInt () = printn 42
32+
"""
33+
|> withOptimize
34+
|> compile
35+
|> shouldSucceed
36+
|> verifyIL [
37+
"""call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out()"""
38+
"""call class [netstandard]System.Globalization.CultureInfo [netstandard]System.Globalization.CultureInfo::get_InvariantCulture()"""
39+
"""call instance string [netstandard]System.Int32::ToString(string,"""
40+
"""callvirt instance void [netstandard]System.IO.TextWriter::WriteLine(string)"""]
41+
42+
[<Fact>]
43+
let ``print with string writes to Console Out``() =
44+
FSharp """
45+
module PrintString
46+
47+
let printStr () = print "hello"
48+
"""
49+
|> withOptimize
50+
|> compile
51+
|> shouldSucceed
52+
|> verifyIL [
53+
"""call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out()"""
54+
"""callvirt instance void [netstandard]System.IO.TextWriter::Write(string)"""]
55+
56+
[<Fact>]
57+
let ``printn with float specializes to Double ToString with InvariantCulture``() =
58+
FSharp """
59+
module PrintnFloat
60+
61+
let printnFloat () = printn 3.14
62+
"""
63+
|> withOptimize
64+
|> compile
65+
|> shouldSucceed
66+
|> verifyIL [
67+
"""call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out()"""
68+
"""call class [netstandard]System.Globalization.CultureInfo [netstandard]System.Globalization.CultureInfo::get_InvariantCulture()"""
69+
"""call instance string [netstandard]System.Double::ToString(string,"""
70+
"""callvirt instance void [netstandard]System.IO.TextWriter::WriteLine(string)"""]

tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@
235235
<Compile Include="EmittedIL\DebugPointsOnStack\DebugPointsOnStack.fs" />
236236
<Compile Include="EmittedIL\Enums.fs" />
237237
<Compile Include="EmittedIL\Literals.fs" />
238+
<Compile Include="EmittedIL\PrintFunction.fs" />
238239
<Compile Include="EmittedIL\NoCompilerInlining.fs" />
239240
<Compile Include="EmittedIL\RealInternalSignature\ModuleVisibility.fs" />
240241
<Compile Include="EmittedIL\RealInternalSignature\ModuleInitialization.fs" />

0 commit comments

Comments
 (0)