Skip to content

Commit 7eafa28

Browse files
authored
Merge branch 'main' into copilot/fix-d3cd8406-6c3a-4d7d-ae87-d71de8a5417d
2 parents 0a59d94 + c1b13e3 commit 7eafa28

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

docs/release-notes/.FSharp.Compiler.Service/11.0.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Scripts: Fix resolving the dotnet host path when an SDK directory is specified. ([PR #18960](https://github.com/dotnet/fsharp/pull/18960))
44
* Fix excessive StackGuard thread jumping ([PR #18971](https://github.com/dotnet/fsharp/pull/18971))
55
* Fix name is bound multiple times is not reported in 'as' pattern ([PR #18984](https://github.com/dotnet/fsharp/pull/18984))
6+
* Type relations cache: handle potentially "infinite" types ([PR #19010](https://github.com/dotnet/fsharp/pull/19010))
67

78
### Added
89

eng/Version.Details.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ This file should be imported by eng/Versions.props
66
<Project>
77
<PropertyGroup>
88
<!-- dotnet/msbuild dependencies -->
9-
<MicrosoftBuildPackageVersion>18.1.0-preview-25514-02</MicrosoftBuildPackageVersion>
10-
<MicrosoftBuildFrameworkPackageVersion>18.1.0-preview-25514-02</MicrosoftBuildFrameworkPackageVersion>
11-
<MicrosoftBuildTasksCorePackageVersion>18.1.0-preview-25514-02</MicrosoftBuildTasksCorePackageVersion>
12-
<MicrosoftBuildUtilitiesCorePackageVersion>18.1.0-preview-25514-02</MicrosoftBuildUtilitiesCorePackageVersion>
9+
<MicrosoftBuildPackageVersion>18.1.0-preview-25515-01</MicrosoftBuildPackageVersion>
10+
<MicrosoftBuildFrameworkPackageVersion>18.1.0-preview-25515-01</MicrosoftBuildFrameworkPackageVersion>
11+
<MicrosoftBuildTasksCorePackageVersion>18.1.0-preview-25515-01</MicrosoftBuildTasksCorePackageVersion>
12+
<MicrosoftBuildUtilitiesCorePackageVersion>18.1.0-preview-25515-01</MicrosoftBuildUtilitiesCorePackageVersion>
1313
<!-- dotnet/runtime dependencies -->
1414
<SystemCollectionsImmutablePackageVersion>9.0.0</SystemCollectionsImmutablePackageVersion>
1515
<SystemComponentModelCompositionPackageVersion>9.0.0</SystemComponentModelCompositionPackageVersion>

eng/Version.Details.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
<Dependencies>
33
<Source Uri="https://github.com/dotnet/dotnet" Mapping="fsharp" Sha="01abb3ec5c4cbffec5b33e02156bd3d2a8913b04" BarId="286825" />
44
<ProductDependencies>
5-
<Dependency Name="Microsoft.Build" Version="18.1.0-preview-25514-02">
5+
<Dependency Name="Microsoft.Build" Version="18.1.0-preview-25515-01">
66
<Uri>https://github.com/dotnet/msbuild</Uri>
7-
<Sha>ce41c053ea92f0f9cf5f68d44015490ec30edfa6</Sha>
7+
<Sha>5e273ccd45ba73d9db9b34fceaf9a110412e64e8</Sha>
88
</Dependency>
9-
<Dependency Name="Microsoft.Build.Framework" Version="18.1.0-preview-25514-02">
9+
<Dependency Name="Microsoft.Build.Framework" Version="18.1.0-preview-25515-01">
1010
<Uri>https://github.com/dotnet/msbuild</Uri>
11-
<Sha>ce41c053ea92f0f9cf5f68d44015490ec30edfa6</Sha>
11+
<Sha>5e273ccd45ba73d9db9b34fceaf9a110412e64e8</Sha>
1212
</Dependency>
13-
<Dependency Name="Microsoft.Build.Tasks.Core" Version="18.1.0-preview-25514-02">
13+
<Dependency Name="Microsoft.Build.Tasks.Core" Version="18.1.0-preview-25515-01">
1414
<Uri>https://github.com/dotnet/msbuild</Uri>
15-
<Sha>ce41c053ea92f0f9cf5f68d44015490ec30edfa6</Sha>
15+
<Sha>5e273ccd45ba73d9db9b34fceaf9a110412e64e8</Sha>
1616
</Dependency>
17-
<Dependency Name="Microsoft.Build.Utilities.Core" Version="18.1.0-preview-25514-02">
17+
<Dependency Name="Microsoft.Build.Utilities.Core" Version="18.1.0-preview-25515-01">
1818
<Uri>https://github.com/dotnet/msbuild</Uri>
19-
<Sha>ce41c053ea92f0f9cf5f68d44015490ec30edfa6</Sha>
19+
<Sha>5e273ccd45ba73d9db9b34fceaf9a110412e64e8</Sha>
2020
</Dependency>
2121
<Dependency Name="System.Reflection.Metadata" Version="9.0.0">
2222
<Uri>https://github.com/dotnet/runtime</Uri>

src/Compiler/Checking/TypeRelations.fs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ type CanCoerce =
2828
[<Struct; NoComparison>]
2929
type TTypeCacheKey =
3030
| TTypeCacheKey of TypeStructure * TypeStructure * CanCoerce
31-
static member FromStrippedTypes(ty1, ty2, canCoerce) =
32-
TTypeCacheKey(getTypeStructure ty1, getTypeStructure ty2, canCoerce)
31+
static member TryGetFromStrippedTypes(ty1, ty2, canCoerce) =
32+
let t1, t2 = getTypeStructure ty1, getTypeStructure ty2
33+
if t1.IsPossiblyInfinite || t2.IsPossiblyInfinite then
34+
ValueNone
35+
else
36+
ValueSome (TTypeCacheKey(t1, t2, canCoerce))
3337

3438
let getTypeSubsumptionCache =
3539
let factory (g: TcGlobals) =
@@ -157,8 +161,10 @@ let rec TypeFeasiblySubsumesType ndeep (g: TcGlobals) (amap: ImportMap) m (ty1:
157161
List.exists (TypeFeasiblySubsumesType (ndeep + 1) g amap m ty1 NoCoerce) interfaces
158162

159163
if g.langVersion.SupportsFeature LanguageFeature.UseTypeSubsumptionCache then
160-
let key = TTypeCacheKey.FromStrippedTypes(ty1, ty2, canCoerce)
161-
(getTypeSubsumptionCache g).GetOrAdd(key, fun _ -> checkSubsumes ty1 ty2)
164+
match TTypeCacheKey.TryGetFromStrippedTypes(ty1, ty2, canCoerce) with
165+
| ValueSome key ->
166+
(getTypeSubsumptionCache g).GetOrAdd(key, fun _ -> checkSubsumes ty1 ty2)
167+
| _ -> checkSubsumes ty1 ty2
162168
else
163169
checkSubsumes ty1 ty2
164170

src/Compiler/Utilities/TypeHashing.fs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,9 @@ module StructuralUtilities =
401401
| MeasureRational of int * int
402402
| NeverEqual of never: NeverEqual
403403

404-
type TypeStructure = TypeStructure of ImmutableArray<TypeToken>
404+
type TypeStructure =
405+
| TypeStructure of TypeToken[]
406+
| PossiblyInfinite of never: NeverEqual
405407

406408
let inline toNullnessToken (n: Nullness) =
407409
match n.TryEvaluate() with
@@ -464,6 +466,15 @@ module StructuralUtilities =
464466
| TType_measure m -> yield! accumulateMeasure m
465467
}
466468

469+
// If the sequence got too long, just drop it, we could be dealing with an infinite type.
470+
let private toTypeStructure tokens =
471+
let tokens = tokens |> Seq.truncate 256 |> Array.ofSeq
472+
473+
if tokens.Length = 256 then
474+
PossiblyInfinite NeverEqual.Singleton
475+
else
476+
TypeStructure tokens
477+
467478
/// Get the full structure of a type as a sequence of tokens, suitable for equality
468479
let getTypeStructure =
469-
Extras.WeakMap.getOrCreate (fun ty -> accumulateTType ty |> ImmutableArray.ofSeq |> TypeStructure)
480+
Extras.WeakMap.getOrCreate (fun ty -> accumulateTType ty |> toTypeStructure)

0 commit comments

Comments
 (0)