Skip to content

Commit 02fbcbf

Browse files
committed
Fix CG Equals for DU and reenable realsig+
1 parent 18315fa commit 02fbcbf

File tree

5 files changed

+89
-2
lines changed

5 files changed

+89
-2
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
-->
3939
<OtherFlags Condition="'$(Configuration)' != 'Proto' and '$(TestingLegacyInternalSignature)' != 'true'">$(OtherFlags) --realsig-</OtherFlags>
4040
<!-- TBD: Fix MEF Export visibility issues in VS -->
41-
<OtherFlags Condition="'$(Configuration)' != 'Proto' and '$(TestingLegacyInternalSignature)' == 'true'">$(OtherFlags) --realsig-</OtherFlags>
41+
<OtherFlags Condition="'$(Configuration)' != 'Proto' and '$(TestingLegacyInternalSignature)' == 'true'">$(OtherFlags) --realsig+</OtherFlags>
4242

4343
</PropertyGroup>
4444

src/Compiler/Checking/AugmentWithHashCompare.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,10 @@ let MakeValsForEqualsAugmentation g (tcref: TyconRef) =
13471347

13481348
let MakeValsForEqualityWithComparerAugmentation g (tcref: TyconRef) =
13491349
let _, ty = mkMinimalTy g tcref
1350-
let vis = tcref.TypeReprAccessibility
1350+
let vis =
1351+
// Equality method for union types match the union type visibility rather than the TypeReprAccessibility
1352+
if tcref.IsUnionTycon then tcref.Accessibility
1353+
else tcref.TypeReprAccessibility
13511354
let tps = tcref.Typars tcref.Range
13521355

13531356
let objGetHashCodeVal =

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,77 @@ module CCtorDUWithMember =
8080
|> asFs
8181
|> withAdditionalSourceFile (SourceFromPath (__SOURCE_DIRECTORY__ ++ "CCtorDUWithMember04.fs"))
8282
|> verifyCompilation
83+
84+
[<Theory; Directory(__SOURCE_DIRECTORY__, BaselineSuffix=".RealInternalSignatureOff", Includes=[| "CCtorDUWithMember05.fs" |])>]
85+
let ``CCtorDUWithMember05_RealInternalSignatureOff_fs`` compilation =
86+
compilation
87+
|> withRealInternalSignatureOff
88+
|> asFs
89+
|> verifyCompilation
90+
91+
92+
let withRealInternalSignature realSig compilation =
93+
compilation
94+
|> withOptions [if realSig then "--realsig+" else "--realsig-" ]
95+
96+
[<InlineData(true)>] // RealSig
97+
[<InlineData(false)>] // Regular
98+
[<Theory>]
99+
let ``public - DU internal case specified in fsi file`` (realSig) =
100+
Fsi """
101+
namespace RealInternalSignature
102+
103+
[<StructuralEquality; StructuralComparison>]
104+
type ILArrayShape =
105+
internal
106+
| One
107+
"""
108+
|> withAdditionalSourceFile (FsSource ("""
109+
namespace RealInternalSignature
110+
111+
[<StructuralEquality; StructuralComparison>]
112+
type ILArrayShape =
113+
| One
114+
"""))
115+
|> asLibrary
116+
|> withLangVersionPreview
117+
|> withRealInternalSignature realSig
118+
|> compile
119+
|> withILContains [
120+
"""
121+
.method public hidebysig instance bool
122+
Equals(class RealInternalSignature.ILArrayShape obj,
123+
class [runtime]System.Collections.IEqualityComparer comp) cil managed
124+
{
125+
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
126+
"""
127+
]
128+
|> shouldSucceed
129+
130+
[<InlineData(true)>] // RealSig
131+
[<InlineData(false)>] // Regular
132+
[<Theory>]
133+
let ``public - DU internal case specified in fs file`` (realSig) =
134+
FSharp """
135+
namespace RealInternalSignature
136+
137+
[<StructuralEquality; StructuralComparison>]
138+
type ILArrayShape =
139+
internal
140+
| One
141+
"""
142+
|> asLibrary
143+
|> withLangVersionPreview
144+
|> withRealInternalSignature realSig
145+
|> compile
146+
|> withILContains [
147+
"""
148+
.method public hidebysig instance bool
149+
Equals(class RealInternalSignature.ILArrayShape obj,
150+
class [runtime]System.Collections.IEqualityComparer comp) cil managed
151+
{
152+
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
153+
"""
154+
]
155+
|> shouldSucceed
156+

tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.debug.bsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ FSharp.Compiler.AbstractIL.IL+ILArgConvention: Int32 Tag
5151
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Int32 get_Tag()
5252
FSharp.Compiler.AbstractIL.IL+ILArgConvention: System.String ToString()
5353
FSharp.Compiler.AbstractIL.IL+ILArrayShape: Boolean Equals(ILArrayShape)
54+
FSharp.Compiler.AbstractIL.IL+ILArrayShape: Boolean Equals(ILArrayShape, System.Collections.IEqualityComparer)
5455
FSharp.Compiler.AbstractIL.IL+ILArrayShape: Boolean Equals(System.Object)
5556
FSharp.Compiler.AbstractIL.IL+ILArrayShape: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
5657
FSharp.Compiler.AbstractIL.IL+ILArrayShape: ILArrayShape FromRank(Int32)
@@ -65,6 +66,7 @@ FSharp.Compiler.AbstractIL.IL+ILArrayShape: Int32 Rank
6566
FSharp.Compiler.AbstractIL.IL+ILArrayShape: Int32 get_Rank()
6667
FSharp.Compiler.AbstractIL.IL+ILArrayShape: System.String ToString()
6768
FSharp.Compiler.AbstractIL.IL+ILAssemblyLongevity: Boolean Equals(ILAssemblyLongevity)
69+
FSharp.Compiler.AbstractIL.IL+ILAssemblyLongevity: Boolean Equals(ILAssemblyLongevity, System.Collections.IEqualityComparer)
6870
FSharp.Compiler.AbstractIL.IL+ILAssemblyLongevity: Boolean Equals(System.Object)
6971
FSharp.Compiler.AbstractIL.IL+ILAssemblyLongevity: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
7072
FSharp.Compiler.AbstractIL.IL+ILAssemblyLongevity: ILAssemblyLongevity Default
@@ -950,6 +952,7 @@ FSharp.Compiler.AbstractIL.IL+ILModuleRef: System.String Name
950952
FSharp.Compiler.AbstractIL.IL+ILModuleRef: System.String ToString()
951953
FSharp.Compiler.AbstractIL.IL+ILModuleRef: System.String get_Name()
952954
FSharp.Compiler.AbstractIL.IL+ILNativeResource: Boolean Equals(ILNativeResource)
955+
FSharp.Compiler.AbstractIL.IL+ILNativeResource: Boolean Equals(ILNativeResource, System.Collections.IEqualityComparer)
953956
FSharp.Compiler.AbstractIL.IL+ILNativeResource: Boolean Equals(System.Object)
954957
FSharp.Compiler.AbstractIL.IL+ILNativeResource: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
955958
FSharp.Compiler.AbstractIL.IL+ILNativeResource: Int32 CompareTo(ILNativeResource)
@@ -1224,6 +1227,7 @@ FSharp.Compiler.AbstractIL.IL+ILParameter: Microsoft.FSharp.Core.FSharpOption`1[
12241227
FSharp.Compiler.AbstractIL.IL+ILParameter: System.String ToString()
12251228
FSharp.Compiler.AbstractIL.IL+ILParameter: Void .ctor(Microsoft.FSharp.Core.FSharpOption`1[System.String], ILType, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.AbstractIL.IL+ILFieldInit], Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.AbstractIL.IL+ILNativeType], Boolean, Boolean, Boolean, ILAttributesStored, Int32)
12261229
FSharp.Compiler.AbstractIL.IL+ILPlatform: Boolean Equals(ILPlatform)
1230+
FSharp.Compiler.AbstractIL.IL+ILPlatform: Boolean Equals(ILPlatform, System.Collections.IEqualityComparer)
12271231
FSharp.Compiler.AbstractIL.IL+ILPlatform: Boolean Equals(System.Object)
12281232
FSharp.Compiler.AbstractIL.IL+ILPlatform: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
12291233
FSharp.Compiler.AbstractIL.IL+ILPlatform: Int32 CompareTo(ILPlatform)
@@ -2286,6 +2290,7 @@ FSharp.Compiler.CodeAnalysis.FSharpSymbolUse: System.String FileName
22862290
FSharp.Compiler.CodeAnalysis.FSharpSymbolUse: System.String ToString()
22872291
FSharp.Compiler.CodeAnalysis.FSharpSymbolUse: System.String get_FileName()
22882292
FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet: Boolean Equals(FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet)
2293+
FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet: Boolean Equals(FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet, System.Collections.IEqualityComparer)
22892294
FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet: Boolean Equals(System.Object)
22902295
FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
22912296
FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet: Int32 GetHashCode()

tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.release.bsl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ FSharp.Compiler.AbstractIL.IL+ILArgConvention: Int32 Tag
5151
FSharp.Compiler.AbstractIL.IL+ILArgConvention: Int32 get_Tag()
5252
FSharp.Compiler.AbstractIL.IL+ILArgConvention: System.String ToString()
5353
FSharp.Compiler.AbstractIL.IL+ILArrayShape: Boolean Equals(ILArrayShape)
54+
FSharp.Compiler.AbstractIL.IL+ILArrayShape: Boolean Equals(ILArrayShape, System.Collections.IEqualityComparer)
5455
FSharp.Compiler.AbstractIL.IL+ILArrayShape: Boolean Equals(System.Object)
5556
FSharp.Compiler.AbstractIL.IL+ILArrayShape: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
5657
FSharp.Compiler.AbstractIL.IL+ILArrayShape: ILArrayShape FromRank(Int32)
@@ -65,6 +66,7 @@ FSharp.Compiler.AbstractIL.IL+ILArrayShape: Int32 Rank
6566
FSharp.Compiler.AbstractIL.IL+ILArrayShape: Int32 get_Rank()
6667
FSharp.Compiler.AbstractIL.IL+ILArrayShape: System.String ToString()
6768
FSharp.Compiler.AbstractIL.IL+ILAssemblyLongevity: Boolean Equals(ILAssemblyLongevity)
69+
FSharp.Compiler.AbstractIL.IL+ILAssemblyLongevity: Boolean Equals(ILAssemblyLongevity, System.Collections.IEqualityComparer)
6870
FSharp.Compiler.AbstractIL.IL+ILAssemblyLongevity: Boolean Equals(System.Object)
6971
FSharp.Compiler.AbstractIL.IL+ILAssemblyLongevity: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
7072
FSharp.Compiler.AbstractIL.IL+ILAssemblyLongevity: ILAssemblyLongevity Default
@@ -950,6 +952,7 @@ FSharp.Compiler.AbstractIL.IL+ILModuleRef: System.String Name
950952
FSharp.Compiler.AbstractIL.IL+ILModuleRef: System.String ToString()
951953
FSharp.Compiler.AbstractIL.IL+ILModuleRef: System.String get_Name()
952954
FSharp.Compiler.AbstractIL.IL+ILNativeResource: Boolean Equals(ILNativeResource)
955+
FSharp.Compiler.AbstractIL.IL+ILNativeResource: Boolean Equals(ILNativeResource, System.Collections.IEqualityComparer)
953956
FSharp.Compiler.AbstractIL.IL+ILNativeResource: Boolean Equals(System.Object)
954957
FSharp.Compiler.AbstractIL.IL+ILNativeResource: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
955958
FSharp.Compiler.AbstractIL.IL+ILNativeResource: Int32 CompareTo(ILNativeResource)
@@ -1224,6 +1227,7 @@ FSharp.Compiler.AbstractIL.IL+ILParameter: Microsoft.FSharp.Core.FSharpOption`1[
12241227
FSharp.Compiler.AbstractIL.IL+ILParameter: System.String ToString()
12251228
FSharp.Compiler.AbstractIL.IL+ILParameter: Void .ctor(Microsoft.FSharp.Core.FSharpOption`1[System.String], ILType, Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.AbstractIL.IL+ILFieldInit], Microsoft.FSharp.Core.FSharpOption`1[FSharp.Compiler.AbstractIL.IL+ILNativeType], Boolean, Boolean, Boolean, ILAttributesStored, Int32)
12261229
FSharp.Compiler.AbstractIL.IL+ILPlatform: Boolean Equals(ILPlatform)
1230+
FSharp.Compiler.AbstractIL.IL+ILPlatform: Boolean Equals(ILPlatform, System.Collections.IEqualityComparer)
12271231
FSharp.Compiler.AbstractIL.IL+ILPlatform: Boolean Equals(System.Object)
12281232
FSharp.Compiler.AbstractIL.IL+ILPlatform: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
12291233
FSharp.Compiler.AbstractIL.IL+ILPlatform: Int32 CompareTo(ILPlatform)
@@ -2286,6 +2290,7 @@ FSharp.Compiler.CodeAnalysis.FSharpSymbolUse: System.String FileName
22862290
FSharp.Compiler.CodeAnalysis.FSharpSymbolUse: System.String ToString()
22872291
FSharp.Compiler.CodeAnalysis.FSharpSymbolUse: System.String get_FileName()
22882292
FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet: Boolean Equals(FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet)
2293+
FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet: Boolean Equals(FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet, System.Collections.IEqualityComparer)
22892294
FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet: Boolean Equals(System.Object)
22902295
FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet: Boolean Equals(System.Object, System.Collections.IEqualityComparer)
22912296
FSharp.Compiler.CodeAnalysis.FSharpUnresolvedReferencesSet: Int32 GetHashCode()

0 commit comments

Comments
 (0)