Skip to content

Commit be2636f

Browse files
authored
Merge pull request #17783 from KevinRansom/fix17773
Requires tactics approval - Fix17773 - cherry pick optimized equals bug fixes to 8.0.4*
2 parents 5e47613 + 5cb3356 commit be2636f

File tree

17 files changed

+319
-175
lines changed

17 files changed

+319
-175
lines changed

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<!-- F# Version components -->
1515
<FSMajorVersion>8</FSMajorVersion>
1616
<FSMinorVersion>0</FSMinorVersion>
17-
<FSBuildVersion>401</FSBuildVersion>
17+
<FSBuildVersion>402</FSBuildVersion>
1818
<FSRevisionVersion>0</FSRevisionVersion>
1919
<!-- -->
2020
<!-- F# Language version -->

src/Compiler/Checking/AugmentWithHashCompare.fs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ let MakeValsForCompareWithComparerAugmentation g (tcref: TyconRef) =
13221322
let MakeValsForEqualsAugmentation g (tcref: TyconRef) =
13231323
let m = tcref.Range
13241324
let _, ty = mkMinimalTy g tcref
1325-
let vis = tcref.TypeReprAccessibility
1325+
let vis = tcref.Accessibility
13261326
let tps = tcref.Typars m
13271327

13281328
let objEqualsVal =
@@ -1347,16 +1347,13 @@ let MakeValsForEqualsAugmentation g (tcref: TyconRef) =
13471347

13481348
let MakeValsForEqualityWithComparerAugmentation g (tcref: TyconRef) =
13491349
let _, ty = mkMinimalTy g tcref
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
1350+
let vis = tcref.Accessibility
13541351
let tps = tcref.Typars tcref.Range
13551352

13561353
let objGetHashCodeVal =
13571354
mkValSpec g tcref ty vis (Some(mkGetHashCodeSlotSig g)) "GetHashCode" (tps +-> (mkHashTy g ty)) unitArg false
13581355

1359-
let withcGetHashCodeVal =
1356+
let withGetHashCodeVal =
13601357
mkValSpec
13611358
g
13621359
tcref
@@ -1368,10 +1365,11 @@ let MakeValsForEqualityWithComparerAugmentation g (tcref: TyconRef) =
13681365
unaryArg
13691366
false
13701367

1371-
let withcEqualsVal =
1368+
let withEqualsVal =
13721369
mkValSpec g tcref ty vis (Some(mkIStructuralEquatableEqualsSlotSig g)) "Equals" (tps +-> (mkEqualsWithComparerTy g ty)) tupArg false
13731370

1374-
let withcEqualsValExact =
1371+
let withEqualsExactWithComparer =
1372+
let vis = TAccess (updateSyntaxAccessForCompPath (vis.CompilationPaths) SyntaxAccess.Public)
13751373
mkValSpec
13761374
g
13771375
tcref
@@ -1383,12 +1381,11 @@ let MakeValsForEqualityWithComparerAugmentation g (tcref: TyconRef) =
13831381
(tps +-> (mkEqualsWithComparerTyExact g ty))
13841382
tupArg
13851383
false
1386-
13871384
{
13881385
GetHashCode = objGetHashCodeVal
1389-
GetHashCodeWithComparer = withcGetHashCodeVal
1390-
EqualsWithComparer = withcEqualsVal
1391-
EqualsExactWithComparer = withcEqualsValExact
1386+
GetHashCodeWithComparer = withGetHashCodeVal
1387+
EqualsWithComparer = withEqualsVal
1388+
EqualsExactWithComparer = withEqualsExactWithComparer
13921389
}
13931390

13941391
let MakeBindingsForCompareAugmentation g (tycon: Tycon) =

tests/FSharp.Compiler.ComponentTests/Conformance/Types/TypeConstraints/IWSAMsAndSRTPs/IWSAMsAndSRTPsTests.fs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,7 @@ let main _ =
769769
|> shouldSucceed
770770
|> verifyIL [
771771
"""
772-
.method public specialname static class [FSharp.Core]Microsoft.FSharp.Core.FSharpChoice`2<class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit>
773-
'|IsEqual|IsNonEqual|'<(class [Potato]Potato.Lib/IPotato`1<!!T>) T>(!!T x,
774-
!!T y) cil managed
772+
.method public specialname static class [FSharp.Core]Microsoft.FSharp.Core.FSharpChoice`2<class [FSharp.Core]Microsoft.FSharp.Core.Unit,class [FSharp.Core]Microsoft.FSharp.Core.Unit> '|IsEqual|IsNonEqual|'<(class [Potato]Potato.Lib/IPotato`1<!!T>) T>(!!T x, !!T y) cil managed
775773
{
776774
777775
.maxstack 8

tests/FSharp.Compiler.ComponentTests/Conformance/Types/UnionTypes/UnionStructTypes.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,7 @@ let main args =
877877
IL_0002: newobj instance void Foo/StructUnion::.ctor(int32)
878878
IL_0007: ret
879879
}""";(*This is a 'maker method' New{CaseName} used for cases which do have fields associated with them, + the _tag gets initialized*)"""
880-
NewCase3(string _field1_3,
881-
string _field2_3) cil managed
880+
NewCase3(string _field1_3, string _field2_3) cil managed
882881
{
883882
.custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags,
884883
int32) = ( 01 00 08 00 00 00 02 00 00 00 00 00 )

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,7 @@ type C() =
283283
.get instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute) Test/C::get_X()
284284
}"""
285285

286-
let verifyMethod = """.method public hidebysig specialname
287-
instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute)
288-
get_X() cil managed
286+
let verifyMethod = """.method public hidebysig specialname instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute) get_X() cil managed
289287
{
290288
.param [0]
291289
.custom instance void [runtime]System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )"""
@@ -313,9 +311,7 @@ type C() =
313311
.get instance int32& modreq([netstandard]System.Runtime.InteropServices.InAttribute) Test/C::get_X()
314312
}"""
315313

316-
let verifyMethod = """.method public hidebysig specialname
317-
instance int32& modreq([netstandard]System.Runtime.InteropServices.InAttribute)
318-
get_X() cil managed
314+
let verifyMethod = """.method public hidebysig specialname instance int32& modreq([netstandard]System.Runtime.InteropServices.InAttribute) get_X() cil managed
319315
{
320316
.param [0]
321317
.custom instance void System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )"""
@@ -452,9 +448,7 @@ type C<'T>() =
452448
abstract X<'U> : unit -> inref<'U>
453449
"""
454450

455-
let verifyMethod = """.method public hidebysig abstract virtual
456-
instance !!U& modreq([runtime]System.Runtime.InteropServices.InAttribute)
457-
X<U>() cil managed
451+
let verifyMethod = """.method public hidebysig abstract virtual instance !!U& modreq([runtime]System.Runtime.InteropServices.InAttribute) X<U>() cil managed
458452
{
459453
.param [0]
460454
.custom instance void [runtime]System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )"""
@@ -481,9 +475,7 @@ type C =
481475
.get instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute) Test/C::get_X()
482476
}"""
483477

484-
let verifyMethod = """.method public hidebysig specialname abstract virtual
485-
instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute)
486-
get_X() cil managed
478+
let verifyMethod = """.method public hidebysig specialname abstract virtual instance int32& modreq([runtime]System.Runtime.InteropServices.InAttribute) get_X() cil managed
487479
{
488480
.param [0]
489481
.custom instance void [runtime]System.Runtime.CompilerServices.IsReadOnlyAttribute::.ctor() = ( 01 00 00 00 )"""

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,59 @@ type ILArrayShape =
146146
]
147147
|> shouldSucceed
148148

149+
[<InlineData(true, "public")>] // RealSig
150+
[<InlineData(false, "assembly")>] // Regular
151+
[<Theory>]
152+
let ``private DU in module`` (realSig, expected) =
153+
FSharp """
154+
module RealInternalSignature
155+
module Module =
156+
type private DU = ABC | YYZ
157+
158+
let publicFunction () : bool =
159+
ABC = YYZ
160+
161+
Module.publicFunction () |> printfn "%b"
162+
"""
163+
|> asExe
164+
|> withRealInternalSignature realSig
165+
|> compileAndRun
166+
|> withILContains [
167+
$$"""
168+
.method {{expected}} hidebysig instance bool Equals(class RealInternalSignature/Module/DU obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed
169+
{
170+
.custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 )
171+
172+
.maxstack 4
173+
.locals init (int32 V_0,
174+
int32 V_1)
175+
IL_0000: ldarg.0
176+
IL_0001: brfalse.s IL_001b
177+
178+
IL_0003: ldarg.1
179+
IL_0004: brfalse.s IL_0019
180+
181+
IL_0006: ldarg.0
182+
IL_0007: ldfld int32 RealInternalSignature/Module/DU::_tag
183+
IL_000c: stloc.0
184+
IL_000d: ldarg.1
185+
IL_000e: ldfld int32 RealInternalSignature/Module/DU::_tag
186+
IL_0013: stloc.1
187+
IL_0014: ldloc.0
188+
IL_0015: ldloc.1
189+
IL_0016: ceq
190+
IL_0018: ret
191+
192+
IL_0019: ldc.i4.0
193+
IL_001a: ret
194+
195+
IL_001b: ldarg.1
196+
IL_001c: ldnull
197+
IL_001d: cgt.un
198+
IL_001f: ldc.i4.0
199+
IL_0020: ceq
200+
IL_0022: ret
201+
}
202+
"""
203+
]
204+
|> shouldSucceed

0 commit comments

Comments
 (0)