1
+ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2
+
3
+ namespace FSharp.Compiler.UnitTests.CodeGen.EmittedIL
4
+
5
+ open FSharp.Compiler .UnitTests
6
+ open NUnit.Framework
7
+
8
+ [<TestFixture>]
9
+ module ` `Mutation`` =
10
+ // Regression test for FSHARP1.0:1206
11
+
12
+ [<Test>]
13
+ let ``Mutation 01`` () =
14
+ CompilerAssert.CompileLibraryAndVerifyILWithOptions [| " -g" ; " --optimize-" |]
15
+ """
16
+ module Mutation01
17
+ type Test = struct
18
+ val mutable v: int
19
+ member t.setV v = t.v <- 0
20
+ end
21
+ """
22
+ ( fun verifier -> verifier.VerifyIL [
23
+ """
24
+ .class sequential ansi serializable sealed nested public Test
25
+ """
26
+ """
27
+ .field public int32 v
28
+ """
29
+ """
30
+ .method public hidebysig instance void
31
+ setV<a>(!!a v) cil managed
32
+ {
33
+
34
+ .maxstack 8
35
+ IL_0000: ldarg.0
36
+ IL_0001: ldc.i4.0
37
+ IL_0002: stfld int32 Mutation01/Test::v
38
+ IL_0007: ret
39
+ }
40
+ """
41
+ ])
42
+
43
+ [<Test>]
44
+ let ``Mutation 02`` () =
45
+ CompilerAssert.CompileLibraryAndVerifyILWithOptions [| " -g" ; " --optimize-" |]
46
+ """
47
+ module Mutation02
48
+ let x = System.TimeSpan.MinValue
49
+ x.ToString()
50
+ """
51
+ ( fun verifier -> verifier.VerifyIL [
52
+ """
53
+ .method public specialname static valuetype [mscorlib]System.TimeSpan
54
+ get_x() cil managed
55
+ {
56
+
57
+ .maxstack 8
58
+ IL_0000: ldsfld valuetype [mscorlib]System.TimeSpan '<StartupCode$assembly>'.$Mutation02::x@3
59
+ IL_0005: ret
60
+ }
61
+ """
62
+ """
63
+ .property valuetype [mscorlib]System.TimeSpan
64
+ x()
65
+ {
66
+ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 )
67
+ .get valuetype [mscorlib]System.TimeSpan Mutation02::get_x()
68
+ }
69
+ """
70
+ """
71
+ void .cctor() cil managed
72
+ {
73
+
74
+ .maxstack 4
75
+ .locals init (valuetype [runtime]System.TimeSpan V_0,
76
+ valuetype [runtime]System.TimeSpan V_1)
77
+ IL_0000: ldsfld valuetype [runtime]System.TimeSpan [runtime]System.TimeSpan::MinValue
78
+ IL_0005: dup
79
+ IL_0006: stsfld valuetype [runtime]System.TimeSpan '<StartupCode$assembly>'.$Mutation02::x@3
80
+ IL_000b: stloc.0
81
+ IL_000c: call valuetype [runtime]System.TimeSpan Mutation02::get_x()
82
+ IL_0011: stloc.1
83
+ IL_0012: ldloca.s V_1
84
+ IL_0014: constrained. [runtime]System.TimeSpan
85
+ IL_001a: callvirt instance string [runtime]System.Object::ToString()
86
+ IL_001f: pop
87
+ IL_0020: ret
88
+ }
89
+ """
90
+ ])
91
+
92
+ [<Test>]
93
+ let ``Mutation 03`` () =
94
+ CompilerAssert.CompileLibraryAndVerifyILWithOptions [| " -g" ; " --optimize-" |]
95
+ """
96
+ module Mutation03
97
+ let x = System.DateTime.Now
98
+ x.Day
99
+ """
100
+ ( fun verifier -> verifier.VerifyIL [
101
+ """
102
+ .method public specialname static valuetype [mscorlib]System.DateTime
103
+ get_x() cil managed
104
+ {
105
+
106
+ .maxstack 8
107
+ IL_0000: ldsfld valuetype [mscorlib]System.DateTime '<StartupCode$assembly>'.$Mutation03::x@3
108
+ IL_0005: ret
109
+ }
110
+ """
111
+ """
112
+ .property valuetype [mscorlib]System.DateTime
113
+ x()
114
+ {
115
+ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 )
116
+ .get valuetype [mscorlib]System.DateTime Mutation03::get_x()
117
+ }
118
+ """
119
+ """
120
+ void .cctor() cil managed
121
+ {
122
+
123
+ .maxstack 4
124
+ .locals init (valuetype [runtime]System.DateTime V_0,
125
+ valuetype [runtime]System.DateTime V_1)
126
+ IL_0000: call valuetype [runtime]System.DateTime [runtime]System.DateTime::get_Now()
127
+ IL_0005: dup
128
+ IL_0006: stsfld valuetype [runtime]System.DateTime '<StartupCode$assembly>'.$Mutation03::x@3
129
+ IL_000b: stloc.0
130
+ IL_000c: call valuetype [runtime]System.DateTime Mutation03::get_x()
131
+ IL_0011: stloc.1
132
+ IL_0012: ldloca.s V_1
133
+ IL_0014: call instance int32 [runtime]System.DateTime::get_Day()
134
+ IL_0019: pop
135
+ IL_001a: ret
136
+ }
137
+ """
138
+ ])
139
+
140
+ [<Test>]
141
+ let ``Mutation 04`` () =
142
+ CompilerAssert.CompileLibraryAndVerifyILWithOptions [| " -g" ; " --optimize-" |]
143
+ """
144
+ module Mutation04
145
+ let x = System.Decimal.MaxValue
146
+ x.ToString()
147
+ """
148
+ ( fun verifier -> verifier.VerifyIL [
149
+ """
150
+ .method public specialname static valuetype [mscorlib]System.Decimal
151
+ get_x() cil managed
152
+ {
153
+
154
+ .maxstack 8
155
+ IL_0000: ldsfld valuetype [mscorlib]System.Decimal '<StartupCode$assembly>'.$Mutation04::x@3
156
+ IL_0005: ret
157
+ }
158
+ """
159
+ """
160
+ .property valuetype [mscorlib]System.Decimal
161
+ x()
162
+ {
163
+ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 09 00 00 00 00 00 )
164
+ .get valuetype [mscorlib]System.Decimal Mutation04::get_x()
165
+ }
166
+ """
167
+ """
168
+ void .cctor() cil managed
169
+ {
170
+
171
+ .maxstack 4
172
+ .locals init (valuetype [runtime]System.Decimal V_0,
173
+ valuetype [runtime]System.Decimal V_1)
174
+ IL_0000: ldsfld valuetype [runtime]System.Decimal [runtime]System.Decimal::MaxValue
175
+ IL_0005: dup
176
+ IL_0006: stsfld valuetype [runtime]System.Decimal '<StartupCode$assembly>'.$Mutation04::x@3
177
+ IL_000b: stloc.0
178
+ IL_000c: call valuetype [runtime]System.Decimal Mutation04::get_x()
179
+ IL_0011: stloc.1
180
+ IL_0012: ldloca.s V_1
181
+ IL_0014: constrained. [runtime]System.Decimal
182
+ IL_001a: callvirt instance string [runtime]System.Object::ToString()
183
+ IL_001f: pop
184
+ IL_0020: ret
185
+ }
186
+ """
187
+ ])
188
+
189
+ [<Test>]
190
+ let ``Mutation 05`` () =
191
+ CompilerAssert.CompileLibraryAndVerifyILWithOptions [| " -g" ; " --optimize-" |]
192
+ """
193
+ module Mutation05
194
+ type C() =
195
+ [<VolatileFieldAttribute>]
196
+ let mutable x = 1
197
+
198
+ member this.X with get() = x and set v = x <- v
199
+
200
+
201
+ type StaticC() =
202
+ [<VolatileFieldAttribute>]
203
+ static let mutable x = 1
204
+
205
+ static member X with get() = x and set v = x <- v
206
+ """
207
+ ( fun verifier -> verifier.VerifyIL [
208
+ """
209
+ .class auto ansi serializable nested public C
210
+ extends [mscorlib]System.Object
211
+ {
212
+ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 )
213
+ .field assembly int32 x
214
+ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.VolatileFieldAttribute::.ctor() = ( 01 00 00 00 )
215
+ .method public specialname rtspecialname
216
+ instance void .ctor() cil managed
217
+ {
218
+
219
+ .maxstack 8
220
+ IL_0000: ldarg.0
221
+ IL_0001: callvirt instance void [mscorlib]System.Object::.ctor()
222
+ IL_0006: ldarg.0
223
+ IL_0007: pop
224
+ IL_0008: ldarg.0
225
+ IL_0009: ldc.i4.1
226
+ IL_000a: volatile.
227
+ IL_000c: stfld int32 Mutation05/C::x
228
+ IL_0011: ret
229
+ }
230
+
231
+ .method public hidebysig specialname
232
+ instance int32 get_X() cil managed
233
+ {
234
+
235
+ .maxstack 8
236
+ IL_0000: ldarg.0
237
+ IL_0001: volatile.
238
+ IL_0003: ldfld int32 Mutation05/C::x
239
+ IL_0008: ret
240
+ }
241
+
242
+ .method public hidebysig specialname
243
+ instance void set_X(int32 v) cil managed
244
+ {
245
+
246
+ .maxstack 8
247
+ IL_0000: ldarg.0
248
+ IL_0001: ldarg.1
249
+ IL_0002: volatile.
250
+ IL_0004: stfld int32 Mutation05/C::x
251
+ IL_0009: ret
252
+ }
253
+
254
+ .property instance int32 X()
255
+ {
256
+ .set instance void Mutation05/C::set_X(int32)
257
+ .get instance int32 Mutation05/C::get_X()
258
+ }
259
+ }
260
+ """
261
+ """
262
+ .class auto ansi serializable nested public StaticC
263
+ extends [mscorlib]System.Object
264
+ {
265
+ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 )
266
+ .field static assembly int32 x
267
+ .custom instance void [FSharp.Core]Microsoft.FSharp.Core.VolatileFieldAttribute::.ctor() = ( 01 00 00 00 )
268
+ .field static assembly int32 init@10
269
+ .method public specialname rtspecialname
270
+ instance void .ctor() cil managed
271
+ {
272
+
273
+ .maxstack 8
274
+ IL_0000: ldarg.0
275
+ IL_0001: callvirt instance void [mscorlib]System.Object::.ctor()
276
+ IL_0006: ldarg.0
277
+ IL_0007: pop
278
+ IL_0008: ret
279
+ }
280
+
281
+ .method public specialname static int32
282
+ get_X() cil managed
283
+ {
284
+
285
+ .maxstack 8
286
+ IL_0000: volatile.
287
+ IL_0002: ldsfld int32 Mutation05/StaticC::init@10
288
+ IL_0007: ldc.i4.1
289
+ IL_0008: bge.s IL_000c
290
+
291
+ IL_000a: br.s IL_000e
292
+
293
+ IL_000c: br.s IL_0017
294
+
295
+ IL_000e: call void [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/IntrinsicFunctions::FailStaticInit()
296
+ IL_0013: nop
297
+ IL_0014: nop
298
+ IL_0015: br.s IL_0018
299
+
300
+ IL_0017: nop
301
+ IL_0018: volatile.
302
+ IL_001a: ldsfld int32 Mutation05/StaticC::x
303
+ IL_001f: ret
304
+ }
305
+
306
+ .method public specialname static void
307
+ set_X(int32 v) cil managed
308
+ {
309
+
310
+ .maxstack 8
311
+ IL_0000: volatile.
312
+ IL_0002: ldsfld int32 Mutation05/StaticC::init@10
313
+ IL_0007: ldc.i4.1
314
+ IL_0008: bge.s IL_000c
315
+
316
+ IL_000a: br.s IL_000e
317
+
318
+ IL_000c: br.s IL_0017
319
+
320
+ IL_000e: call void [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives/IntrinsicFunctions::FailStaticInit()
321
+ IL_0013: nop
322
+ IL_0014: nop
323
+ IL_0015: br.s IL_0018
324
+
325
+ IL_0017: nop
326
+ IL_0018: ldarg.0
327
+ IL_0019: volatile.
328
+ IL_001b: stsfld int32 Mutation05/StaticC::x
329
+ IL_0020: ret
330
+ }
331
+
332
+ .method private specialname rtspecialname static
333
+ void .cctor() cil managed
334
+ {
335
+
336
+ .maxstack 8
337
+ IL_0000: ldc.i4.0
338
+ IL_0001: stsfld int32 '<StartupCode$assembly>'.$Mutation05::init@
339
+ IL_0006: ldsfld int32 '<StartupCode$assembly>'.$Mutation05::init@
340
+ IL_000b: pop
341
+ IL_000c: ret
342
+ }
343
+
344
+ .property int32 X()
345
+ {
346
+ .set void Mutation05/StaticC::set_X(int32)
347
+ .get int32 Mutation05/StaticC::get_X()
348
+ }
349
+ }
350
+ """
351
+ """
352
+ IL_0000: ldc.i4.1
353
+ IL_0001: volatile.
354
+ IL_0003: stsfld int32 Mutation05/StaticC::x
355
+ IL_0008: ldc.i4.1
356
+ IL_0009: volatile.
357
+ IL_000b: stsfld int32 Mutation05/StaticC::init@10
358
+ IL_0010: ret
359
+ """
360
+ ])
0 commit comments