Skip to content

Commit 794b7c2

Browse files
authored
Merge pull request #14536 from dotnet/merges/main-to-release/dev17.5
Merge main to release/dev17.5
2 parents 4ed76da + f4443f0 commit 794b7c2

File tree

9 files changed

+126
-8
lines changed

9 files changed

+126
-8
lines changed

src/FSharp.Core/map.fs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,41 @@ type Map<[<EqualityConditionalOn>] 'Key, [<EqualityConditionalOn; ComparisonCond
882882
override this.GetHashCode() =
883883
this.ComputeHashCode()
884884

885+
interface IStructuralEquatable with
886+
member this.Equals(that, comparer) =
887+
match that with
888+
| :? Map<'Key, 'Value> as that ->
889+
use e1 = (this :> seq<_>).GetEnumerator()
890+
use e2 = (that :> seq<_>).GetEnumerator()
891+
892+
let rec loop () =
893+
let m1 = e1.MoveNext()
894+
let m2 = e2.MoveNext()
895+
896+
(m1 = m2)
897+
&& (not m1
898+
|| (let e1c = e1.Current
899+
let e2c = e2.Current
900+
901+
(comparer.Equals(e1c.Key, e2c.Key)
902+
&& comparer.Equals(e1c.Value, e2c.Value)
903+
&& loop ())))
904+
905+
loop ()
906+
| _ -> false
907+
908+
member this.GetHashCode(comparer) =
909+
let combineHash x y =
910+
(x <<< 1) + y + 631
911+
912+
let mutable res = 0
913+
914+
for (KeyValue (x, y)) in this do
915+
res <- combineHash res (comparer.GetHashCode x)
916+
res <- combineHash res (comparer.GetHashCode y)
917+
918+
res
919+
885920
interface IEnumerable<KeyValuePair<'Key, 'Value>> with
886921
member _.GetEnumerator() =
887922
MapTree.mkIEnumerator tree

src/FSharp.Core/map.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ type Map<[<EqualityConditionalOn>] 'Key, [<EqualityConditionalOn; ComparisonCond
210210
interface ICollection<KeyValuePair<'Key, 'Value>>
211211
interface IEnumerable<KeyValuePair<'Key, 'Value>>
212212
interface System.IComparable
213+
interface System.Collections.IStructuralEquatable
213214
interface System.Collections.IEnumerable
214215
interface IReadOnlyCollection<KeyValuePair<'Key, 'Value>>
215216
interface IReadOnlyDictionary<'Key, 'Value>

src/FSharp.Core/set.fs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ type Set<[<EqualityConditionalOn>] 'T when 'T: comparison>(comparer: IComparer<'
872872
member x.ToArray() =
873873
SetTree.toArray x.Tree
874874

875-
member this.ComputeHashCode() =
875+
member private this.ComputeHashCode() =
876876
let combineHash x y =
877877
(x <<< 1) + y + 631
878878

@@ -904,6 +904,32 @@ type Set<[<EqualityConditionalOn>] 'T when 'T: comparison>(comparer: IComparer<'
904904
member this.CompareTo(that: obj) =
905905
SetTree.compare this.Comparer this.Tree ((that :?> Set<'T>).Tree)
906906

907+
interface IStructuralEquatable with
908+
member this.Equals(that, comparer) =
909+
match that with
910+
| :? Set<'T> as that ->
911+
use e1 = (this :> seq<_>).GetEnumerator()
912+
use e2 = (that :> seq<_>).GetEnumerator()
913+
914+
let rec loop () =
915+
let m1 = e1.MoveNext()
916+
let m2 = e2.MoveNext()
917+
(m1 = m2) && (not m1 || ((comparer.Equals(e1.Current, e2.Current)) && loop ()))
918+
919+
loop ()
920+
| _ -> false
921+
922+
member this.GetHashCode(comparer) =
923+
let combineHash x y =
924+
(x <<< 1) + y + 631
925+
926+
let mutable res = 0
927+
928+
for x in this do
929+
res <- combineHash res (comparer.GetHashCode(x))
930+
931+
res
932+
907933
interface ICollection<'T> with
908934
member s.Add x =
909935
ignore x

src/FSharp.Core/set.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ type Set<[<EqualityConditionalOn>] 'T when 'T: comparison> =
229229
interface IEnumerable<'T>
230230
interface System.Collections.IEnumerable
231231
interface System.IComparable
232+
interface System.Collections.IStructuralEquatable
232233
interface IReadOnlyCollection<'T>
233234
override Equals: obj -> bool
234235

tests/FSharp.Core.UnitTests/FSharp.Core/PrimTypes.fs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,45 @@ type LanguagePrimitivesModule() =
202202

203203
let resultNul = LanguagePrimitives.GenericEquality "ABC" null
204204
Assert.False(resultNul)
205+
206+
[<Fact>]
207+
member _.GenericEqualityForNans() =
208+
Assert.DoesNotContain(true,
209+
[| LanguagePrimitives.GenericEquality nan nan
210+
LanguagePrimitives.GenericEquality [nan] [nan]
211+
LanguagePrimitives.GenericEquality [|nan|] [|nan|]
212+
LanguagePrimitives.GenericEquality (Set.ofList [nan]) (Set.ofList [nan])
213+
LanguagePrimitives.GenericEquality (Map.ofList [1,nan]) (Map.ofList [1,nan])
214+
LanguagePrimitives.GenericEquality (Map.ofList [nan,1]) (Map.ofList [nan,1])
215+
LanguagePrimitives.GenericEquality (Map.ofList [nan,nan]) (Map.ofList [nan,nan])
216+
217+
LanguagePrimitives.GenericEquality nanf nanf
218+
LanguagePrimitives.GenericEquality [nanf] [nanf]
219+
LanguagePrimitives.GenericEquality [|nanf|] [|nanf|]
220+
LanguagePrimitives.GenericEquality (Set.ofList [nanf]) (Set.ofList [nanf])
221+
LanguagePrimitives.GenericEquality (Map.ofList [1,nanf]) (Map.ofList [1,nanf])
222+
LanguagePrimitives.GenericEquality (Map.ofList [nanf,1]) (Map.ofList [nanf,1])
223+
LanguagePrimitives.GenericEquality (Map.ofList [nanf,nanf]) (Map.ofList [nanf,nanf])|])
224+
225+
[<Fact>]
226+
member _.GenericEqualityER() =
227+
Assert.DoesNotContain(false,
228+
[| LanguagePrimitives.GenericEqualityER nan nan
229+
LanguagePrimitives.GenericEqualityER [nan] [nan]
230+
LanguagePrimitives.GenericEqualityER [|nan|] [|nan|]
231+
LanguagePrimitives.GenericEqualityER (Set.ofList [nan]) (Set.ofList [nan])
232+
LanguagePrimitives.GenericEqualityER (Map.ofList [1,nan]) (Map.ofList [1,nan])
233+
LanguagePrimitives.GenericEqualityER (Map.ofList [nan,1]) (Map.ofList [nan,1])
234+
LanguagePrimitives.GenericEqualityER (Map.ofList [nan,nan]) (Map.ofList [nan,nan])
235+
236+
LanguagePrimitives.GenericEqualityER nanf nanf
237+
LanguagePrimitives.GenericEqualityER [nanf] [nanf]
238+
LanguagePrimitives.GenericEqualityER [|nanf|] [|nanf|]
239+
LanguagePrimitives.GenericEqualityER (Set.ofList [nanf]) (Set.ofList [nanf])
240+
LanguagePrimitives.GenericEqualityER (Map.ofList [1,nanf]) (Map.ofList [1,nanf])
241+
LanguagePrimitives.GenericEqualityER (Map.ofList [nanf,1]) (Map.ofList [nanf,1])
242+
LanguagePrimitives.GenericEqualityER (Map.ofList [nanf,nanf]) (Map.ofList [nanf,nanf])|])
243+
205244

206245
[<Fact>]
207246
member this.GenericGreaterOrEqual() =

tests/projects/SelfContained_Trimming_Test/check.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (-not ($output -eq $expected))
1414
}
1515

1616
# Checking that FSharp.Core binary is of expected size (needs adjustments if test is updated).
17-
$expected_len = 245248 # In bytes
17+
$expected_len = 246272 # In bytes
1818
$file = Get-Item .\bin\Release\net7.0\win-x64\publish\FSharp.Core.dll
1919
$file_len = $file.Length
2020
if (-not ($file_len -eq $expected_len))

vsintegration/src/FSharp.Editor/Hints/InlineParameterNameHints.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,12 @@ module InlineParameterNameHints =
6969
symbol.DeclaringEntity
7070
|> Option.exists (fun entity -> entity.CompiledName <> "Operators")
7171

72+
let isNotCustomOperation =
73+
not <| symbol.HasAttribute<CustomOperationAttribute>()
74+
7275
(symbol.IsFunction && isNotBuiltInOperator) // arguably, hints for those would be rather useless
7376
|| symbol.IsConstructor
74-
|| symbol.IsMethod
77+
|| (symbol.IsMethod && isNotCustomOperation)
7578
else
7679
false
7780

vsintegration/tests/FSharp.Editor.Tests/Hints/InlineParameterNameHintTests.fs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,17 @@ let test sequences =
478478

479479
let actual = getParameterNameHints document
480480

481-
Assert.AreEqual(expected, actual)
481+
Assert.AreEqual(expected, actual)
482+
483+
[<Test>]
484+
let ``Hints are not shown when CustomOperation attribute is detected`` () =
485+
let code =
486+
"""
487+
let q = query { for x in { 1 .. 10 } do select x }
488+
"""
489+
490+
let document = getFsDocument code
491+
492+
let actual = getParameterNameHints document
493+
494+
Assert.IsEmpty actual

vsintegration/tests/FSharp.Editor.Tests/Hints/OptionParserTests.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module OptionParserTests =
2222

2323
let actual = OptionParser.getHintKinds options
2424

25-
Assert.AreEqual(expected, actual)
25+
CollectionAssert.AreEquivalent(expected, actual)
2626

2727
[<Test>]
2828
let ``Type hints on, parameter name hints off`` () =
@@ -36,7 +36,7 @@ module OptionParserTests =
3636

3737
let actual = OptionParser.getHintKinds options
3838

39-
Assert.AreEqual(expected, actual)
39+
CollectionAssert.AreEquivalent(expected, actual)
4040

4141
[<Test>]
4242
let ``Type hints off, parameter name hints on`` () =
@@ -50,7 +50,7 @@ module OptionParserTests =
5050

5151
let actual = OptionParser.getHintKinds options
5252

53-
Assert.AreEqual(expected, actual)
53+
CollectionAssert.AreEquivalent(expected, actual)
5454

5555
[<Test>]
5656
let ``Type hints on, parameter name hints on`` () =
@@ -64,4 +64,4 @@ module OptionParserTests =
6464

6565
let actual = OptionParser.getHintKinds options
6666

67-
Assert.AreEqual(expected, actual)
67+
CollectionAssert.AreEquivalent(expected, actual)

0 commit comments

Comments
 (0)