Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7791c9d

Browse files
dsymeKevinRansom
authored andcommitted
fix 3489 - struct unions (#3521)
* fix 3489 - struct unions* fix 3489 - struct unions - test* fix 3489 - struct unions - fix code gen* fix tests
1 parentf33e79f commit7791c9d

File tree

6 files changed

+106
-62
lines changed

6 files changed

+106
-62
lines changed

‎src/fsharp/AugmentWithHashCompare.fs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ let mkUnionCompare g tcref (tycon:Tycon) =
383383
tagsEqTested)
384384

385385
letexpr=if tycon.IsStructOrEnumTyconthen exprelse mkBindNullComparison g m thise thataddre expr
386-
thisv,thataddrv, expr
386+
letthatv,expr= mkThatVarBind g m ty thataddrv expr
387+
thisv,thatv, expr
387388

388389

389390
/// Build the comparison implementation for a union type when parameterized by a comparer
@@ -435,7 +436,7 @@ let mkUnionCompareWithComparer g tcref (tycon:Tycon) (_thisv,thise) (_thatobjv,t
435436
mkCond NoSequencePointAtStickyBinding SuppressSequencePointAtTarget m g.int_ty
436437
(mkILAsmCeq g m thistage thattage)
437438
expr
438-
(mkAsmExpr([ IL.AI_sub],[],[thistage; thattage],[g.int_ty],m))in
439+
(mkAsmExpr([ IL.AI_sub],[],[thistage; thattage],[g.int_ty],m))
439440
mkCompGenLet m thistagv
440441
(mkUnionCaseTagGetViaExprAddr(thise,tcref,tinst,m))
441442
(mkCompGenLet m thattagv

‎src/fsharp/IlxGen.fs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6635,11 +6635,17 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon:Tycon) =
66356635
cudDebugDisplayAttributes= ilDebugDisplayAttributes
66366636
cudAlternatives= alternatives
66376637
cudWhere= None}
6638+
66386639
letlayout=
66396640
if isStructTy cenv.g thisTythen
6640-
ILTypeDefLayout.Sequential{ Size=None; Pack=None}
6641+
if(match ilTypeDefKindwith ILTypeDefKind.ValueType->true|_->false)then
6642+
// Structs with no instance fields get size 1, pack 0
6643+
ILTypeDefLayout.Sequential{ Size=Some1; Pack=Some0us}
6644+
else
6645+
ILTypeDefLayout.Sequential{ Size=None; Pack=None}
66416646
else
66426647
ILTypeDefLayout.Auto
6648+
66436649
lettdef=
66446650
{ Name= ilTypeName
66456651
Layout= layout

‎src/fsharp/TypeChecker.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14571,6 +14571,7 @@ module EstablishTypeDefinitionCores =
1457114571
let isStructRecordOrUnionType =
1457214572
match synTyconRepr with
1457314573
| SynTypeDefnSimpleRepr.Record _
14574+
| TyconCoreAbbrevThatIsReallyAUnion (hasMeasureAttr,envinner,id) _
1457414575
| SynTypeDefnSimpleRepr.Union _ ->
1457514576
HasFSharpAttribute cenv.g cenv.g.attrib_StructAttribute attrs
1457614577
| _ ->

‎tests/fsharp/core/subtype/test.fsx‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let check s v1 v2 = test s (v1 = v2)
2424

2525
openSystem
2626
openSystem.IO
27-
27+
openSystem.Reflection
2828
openSystem.Collections.Generic
2929

3030
(* 'a[] :> ICollection<'a>*)
@@ -1705,6 +1705,35 @@ module InliningOnSubTypes1 =
17051705
do check"clkewlijwlkw"(f())(13,17)
17061706

17071707

1708+
#if!FX_RESHAPED_REFLECTION
1709+
moduleStructUnionSingleCase=
1710+
[<Struct>]
1711+
typeS= S
1712+
1713+
do check"wekew0ewek1"(typeof<S>.IsValueType)true
1714+
do check"wekew0ewek1b"(typeof<S>.BaseType) typeof<System.ValueType>
1715+
1716+
typeSAbbrev= S
1717+
1718+
do check"wekew0ewek2"(typeof<SAbbrev>.IsValueType)true
1719+
do check"wekew0ewek2b"(typeof<SAbbrev>.BaseType) typeof<System.ValueType>
1720+
1721+
typeS0= S0
1722+
do check"wekew0ewek3"(typeof<S0>.IsValueType)false
1723+
do check"wekew0ewek3b"(typeof<S0>.BaseType) typeof<obj>
1724+
1725+
[<Struct>]
1726+
typeS2=| S2
1727+
1728+
do check"wekew0ewek4"(typeof<S2>.IsValueType)true
1729+
do check"wekew0ewek4b"(typeof<S2>.BaseType) typeof<System.ValueType>
1730+
1731+
[<Struct>]
1732+
typeS3=| S2a| S3a
1733+
1734+
do check"wekew0ewek5"(typeof<S3>.IsValueType)true
1735+
do check"wekew0ewek5b"(typeof<S3>.BaseType) typeof<System.ValueType>
1736+
#endif
17081737

17091738
// See https://github.com/Microsoft/visualfsharp/issues/238
17101739
moduleGenericPropertyConstraintSolvedByRecord=

‎tests/fsharp/tests.fs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ module CoreTests =
357357

358358
fsc cfg"%s -a -o:lib.dll -g" cfg.fsc_flags["lib.fs"]
359359

360+
copy_y cfg(cfg.FSCBinPath++"System.ValueTuple.dll")("."++"System.ValueTuple.dll")
361+
360362
peverify cfg"lib.dll"
361363

362364
csc cfg"""/nologo /target:library /r:"%s" /r:lib.dll /out:lib2.dll""" cfg.FSCOREDLLPATH["lib2.cs"]

‎tests/fsharpqa/Source/Optimizations/Inlining/StructUnion01.il.bsl‎

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@
2525
}
2626
.mresource public FSharpSignatureData.StructUnion01
2727
{
28-
// Offset: 0x00000000 Length:0x00000884
28+
// Offset: 0x00000000 Length:0x0000088A
2929
}
3030
.mresource public FSharpOptimizationData.StructUnion01
3131
{
32-
// Offset:0x00000888 Length: 0x00000421
32+
// Offset:0x00000890 Length: 0x00000421
3333
}
3434
.module StructUnion01.dll
35-
// MVID: {58EED771-D3E9-6B24-A745-038371D7EE58}
35+
// MVID: {59A6DE42-D3E9-6B24-A745-038342DEA659}
3636
.imagebase 0x00400000
3737
.file alignment 0x00000200
3838
.stackreserve 0x00100000
3939
.subsystem 0x0003// WINDOWS_CUI
4040
.corflags 0x00000001// ILONLY
41-
// Image base:0x030C0000
41+
// Image base:0x00690000
4242

4343

4444
// =============== CLASS MEMBERS DECLARATION ===================
@@ -55,6 +55,8 @@
5555
[mscorlib]System.IComparable,
5656
[mscorlib]System.Collections.IStructuralComparable
5757
{
58+
.pack0
59+
.size1
5860
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.StructAttribute::.ctor()= (01000000 )
5961
.custom instance void [mscorlib]System.Diagnostics.DebuggerDisplayAttribute::.ctor(string)= (010015 7B 5F 5F446562756744697370 6C// ...{__DebugDispl
6062
61792829 2C 6E71 7D0000 )// ay(),nq}..
@@ -171,66 +173,69 @@
171173
instance int32 CompareTo(valuetype StructUnion01/U obj) cil managed
172174
{
173175
.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor()= (01000000 )
174-
// Code size77 (0x4d)
176+
// Code size86 (0x56)
175177
.maxstack4
176-
.locals init (int32 V_0,
177-
class [mscorlib]System.Collections.IComparer V_1,
178-
int32 V_2,
179-
int32 V_3)
180-
IL_0000: ldarg.0
181-
IL_0001: pop
182-
IL_0002: call class [mscorlib]System.Collections.IComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericComparer()
183-
IL_0007: stloc.1
184-
IL_0008: ldarg.0
185-
IL_0009: ldfld int32 StructUnion01/U::item1
186-
IL_000e: stloc.2
187-
IL_000f: ldarg.1
188-
IL_0010: ldfld int32 StructUnion01/U::item1
189-
IL_0015: stloc.3
190-
IL_0016: ldloc.2
191-
IL_0017: ldloc.3
192-
IL_0018: bge.s IL_001d
193-
194-
IL_001a: ldc.i4.m1
195-
IL_001b: br.s IL_0021
196-
197-
IL_001d: ldloc.2
198-
IL_001e: ldloc.3
199-
IL_001f: cgt
200-
IL_0021: stloc.0
201-
IL_0022: ldloc.0
202-
IL_0023: ldc.i4.0
203-
IL_0024: bge.s IL_0028
204-
205-
IL_0026: ldloc.0
206-
IL_0027: ret
207-
208-
IL_0028: ldloc.0
178+
.locals init (valuetype StructUnion01/U& V_0,
179+
int32 V_1,
180+
class [mscorlib]System.Collections.IComparer V_2,
181+
int32 V_3,
182+
int32 V_4)
183+
IL_0000: ldarga.s obj
184+
IL_0002: stloc.0
185+
IL_0003: ldarg.0
186+
IL_0004: pop
187+
IL_0005: call class [mscorlib]System.Collections.IComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericComparer()
188+
IL_000a: stloc.2
189+
IL_000b: ldarg.0
190+
IL_000c: ldfld int32 StructUnion01/U::item1
191+
IL_0011: stloc.3
192+
IL_0012: ldloc.0
193+
IL_0013: ldfld int32 StructUnion01/U::item1
194+
IL_0018: stloc.s V_4
195+
IL_001a: ldloc.3
196+
IL_001b: ldloc.s V_4
197+
IL_001d: bge.s IL_0022
198+
199+
IL_001f: ldc.i4.m1
200+
IL_0020: br.s IL_0027
201+
202+
IL_0022: ldloc.3
203+
IL_0023: ldloc.s V_4
204+
IL_0025: cgt
205+
IL_0027: stloc.1
206+
IL_0028: ldloc.1
209207
IL_0029: ldc.i4.0
210-
IL_002a:ble.s IL_002e
208+
IL_002a:bge.s IL_002e
211209

212-
IL_002c: ldloc.0
210+
IL_002c: ldloc.1
213211
IL_002d: ret
214212

215-
IL_002e: call class [mscorlib]System.Collections.IComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericComparer()
216-
IL_0033: stloc.1
217-
IL_0034: ldarg.0
218-
IL_0035: ldfld int32 StructUnion01/U::item2
219-
IL_003a: stloc.2
220-
IL_003b: ldarg.1
221-
IL_003c: ldfld int32 StructUnion01/U::item2
222-
IL_0041: stloc.3
223-
IL_0042: ldloc.2
224-
IL_0043: ldloc.3
225-
IL_0044: bge.s IL_0048
226-
227-
IL_0046: ldc.i4.m1
228-
IL_0047: ret
229-
230-
IL_0048: ldloc.2
213+
IL_002e: ldloc.1
214+
IL_002f: ldc.i4.0
215+
IL_0030: ble.s IL_0034
216+
217+
IL_0032: ldloc.1
218+
IL_0033: ret
219+
220+
IL_0034: call class [mscorlib]System.Collections.IComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericComparer()
221+
IL_0039: stloc.2
222+
IL_003a: ldarg.0
223+
IL_003b: ldfld int32 StructUnion01/U::item2
224+
IL_0040: stloc.3
225+
IL_0041: ldloc.0
226+
IL_0042: ldfld int32 StructUnion01/U::item2
227+
IL_0047: stloc.s V_4
231228
IL_0049: ldloc.3
232-
IL_004a: cgt
233-
IL_004c: ret
229+
IL_004a: ldloc.s V_4
230+
IL_004c: bge.s IL_0050
231+
232+
IL_004e: ldc.i4.m1
233+
IL_004f: ret
234+
235+
IL_0050: ldloc.3
236+
IL_0051: ldloc.s V_4
237+
IL_0053: cgt
238+
IL_0055: ret
234239
}// end of method U::CompareTo
235240

236241
.method public hidebysig virtual final

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp