Skip to content

Commit e7ac187

Browse files
committed
Added test
1 parent 8b3a93f commit e7ac187

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

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

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,93 @@ module AssemblyBoundary =
8888
compilation
8989
|> withReferences [typeLib02]
9090
|> verifyCompileAndExecution
91+
92+
[<Fact>]
93+
let ``copyOfStruct doesn't reallocate local in case of cross-assembly inlining`` () =
94+
let library =
95+
FSharp """
96+
namespace Library
97+
98+
#nowarn "346"
99+
100+
[<Struct>]
101+
type ID (value : string) =
102+
member _.Value = value
103+
member inline this.Hello(other: ID) = System.Console.WriteLine(this.Value + " " + other.Value)
104+
105+
type ID2 = { Value : ID } with
106+
member inline this.Hello(other: ID2) = this.Value.Hello other.Value
107+
"""
108+
|> asLibrary
109+
|> withName "Library"
110+
|> withOptimize
111+
112+
let program =
113+
FSharp """
114+
open Library
115+
116+
[<EntryPoint>]
117+
let main _ =
118+
119+
let aBar = { Value = ID "first" }
120+
let bBar = { Value = ID "second" }
121+
122+
aBar.Hello(bBar)
123+
124+
0
125+
"""
126+
|> withReferences [library]
127+
|> withOptimize
128+
129+
let compilation =
130+
program
131+
|> asExe
132+
|> compile
133+
134+
compilation
135+
|> shouldSucceed
136+
|> run
137+
|> shouldSucceed
138+
|> verifyOutputContains [| "first second" |]
139+
|> verifyIL
140+
[ """
141+
.method public static int32 main(string[] _arg1) cil managed
142+
{
143+
.entrypoint
144+
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.EntryPointAttribute::.ctor() = ( 01 00 00 00 )
145+
146+
.maxstack 5
147+
.locals init (class [Library]Library.ID2 V_0,
148+
class [Library]Library.ID2 V_1,
149+
valuetype [Library]Library.ID& V_2,
150+
valuetype [Library]Library.ID V_3,
151+
valuetype [Library]Library.ID V_4)
152+
IL_0000: ldstr "first"
153+
IL_0005: newobj instance void [Library]Library.ID::.ctor(string)
154+
IL_000a: newobj instance void [Library]Library.ID2::.ctor(valuetype [Library]Library.ID)
155+
IL_000f: stloc.0
156+
IL_0010: ldstr "second"
157+
IL_0015: newobj instance void [Library]Library.ID::.ctor(string)
158+
IL_001a: newobj instance void [Library]Library.ID2::.ctor(valuetype [Library]Library.ID)
159+
IL_001f: stloc.1
160+
IL_0020: ldloc.0
161+
IL_0021: call instance valuetype [Library]Library.ID [Library]Library.ID2::get_Value()
162+
IL_0026: stloc.3
163+
IL_0027: ldloca.s V_3
164+
IL_0029: stloc.2
165+
IL_002a: ldloc.1
166+
IL_002b: call instance valuetype [Library]Library.ID [Library]Library.ID2::get_Value()
167+
IL_0030: stloc.s V_4
168+
IL_0032: ldloc.2
169+
IL_0033: call instance string [Library]Library.ID::get_Value()
170+
IL_0038: ldstr " "
171+
IL_003d: ldloca.s V_4
172+
IL_003f: call instance string [Library]Library.ID::get_Value()
173+
IL_0044: call string [runtime]System.String::Concat(string,
174+
string,
175+
string)
176+
IL_0049: call void [runtime]System.Console::WriteLine(string)
177+
IL_004e: ldc.i4.0
178+
IL_004f: ret
179+
}
180+
"""]

0 commit comments

Comments
 (0)