Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vzarytovskii committed Sep 30, 2024
1 parent 81f2145 commit f5047d8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/Compiler/Checking/TypeRelations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ let rec TypeFeasiblySubsumesType ndeep (g: TcGlobals) (amap: ImportMap) m (ty1:
let ty2 = stripTyEqns g ty2

// Check if language feature supported
let key = TTypeCacheKey (ty1, ty2, canCoerce, g)
let key = TTypeCacheKey.FromStrippedTypes (ty1, ty2, canCoerce, g)

match TryGetCachedTypeSubsumption g amap key with
| ValueSome subsumes ->
Expand Down Expand Up @@ -154,7 +154,7 @@ let rec TypeFeasiblySubsumesType ndeep (g: TcGlobals) (amap: ImportMap) m (ty1:
else
let interfaces = GetImmediateInterfacesOfType SkipUnrefInterfaces.Yes g amap m ty2
// See if any interface in type hierarchy of ty2 is a supertype of ty1
Seq.exists (TypeFeasiblySubsumesType (ndeep + 1) g amap m ty1 NoCoerce) interfaces
List.exists (TypeFeasiblySubsumesType (ndeep + 1) g amap m ty1 NoCoerce) interfaces

UpdateCachedTypeSubsumption g amap key subsumes

Expand Down
25 changes: 10 additions & 15 deletions src/Compiler/Checking/import.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,20 @@ type [<Struct; NoComparison; CustomEquality>] TTypeCacheKey =
val canCoerce: CanCoerce
val tcGlobals: TcGlobals

new (ty1, ty2, canCoerce, tcGlobals) =
private new (ty1, ty2, canCoerce, tcGlobals) =
{ ty1 = ty1; ty2 = ty2; canCoerce = canCoerce; tcGlobals = tcGlobals }

static member FromStrippedTypes (ty1, ty2, canCoerce, tcGlobals) =
TTypeCacheKey(ty1, ty2, canCoerce, tcGlobals)

interface System.IEquatable<TTypeCacheKey> with
member this.Equals other =
let ty1 = this.ty1
let ty2 = this.ty2
let otherTy1 = stripTyEqns this.tcGlobals other.ty1
let otherTy2 = stripTyEqns this.tcGlobals other.ty2

if stampEquals this.tcGlobals ty1 otherTy1 && stampEquals this.tcGlobals ty2 otherTy2 && this.canCoerce = other.canCoerce then
if stampEquals this.tcGlobals this.ty1 other.ty1 && stampEquals this.tcGlobals this.ty2 other.ty2 && this.canCoerce = other.canCoerce then
true
else
(
LanguagePrimitives.PhysicalEquality ty1 otherTy1
&& LanguagePrimitives.PhysicalEquality ty2 otherTy2
LanguagePrimitives.PhysicalEquality this.ty1 other.ty1
&& LanguagePrimitives.PhysicalEquality this.ty2 other.ty2
&& this.canCoerce = other.canCoerce
)

Expand All @@ -85,11 +83,8 @@ type [<Struct; NoComparison; CustomEquality>] TTypeCacheKey =
override this.GetHashCode() : int =
let g = this.tcGlobals

let ty1 = stripTyEqns g this.ty1
let ty2 = stripTyEqns g this.ty2

let ty1Hash = combineHash (hashStamp g ty1) (hashTType g ty1)
let ty2Hash = combineHash (hashStamp g ty1) (hashTType g ty2)
let ty1Hash = combineHash (hashStamp g this.ty1) (hashTType g this.ty1)
let ty2Hash = combineHash (hashStamp g this.ty1) (hashTType g this.ty2)

let combined = combineHash (combineHash ty1Hash ty2Hash) (hash this.canCoerce)

Expand All @@ -111,7 +106,7 @@ type [<Struct; NoComparison; CustomEquality>] TTypeCacheKey =
type ImportMap(g: TcGlobals, assemblyLoader: AssemblyLoader) =
let typeRefToTyconRefCache = ConcurrentDictionary<ILTypeRef, TyconRef>()

let typeSubsumptionCache = ConcurrentDictionary<TTypeCacheKey, bool>()
let typeSubsumptionCache = ConcurrentDictionary<TTypeCacheKey, bool>(System.Environment.ProcessorCount, 1024)

member _.g = g

Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Checking/import.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ type CanCoerce =
[<Struct; NoComparison; CustomEquality>]
type TTypeCacheKey =
interface System.IEquatable<TTypeCacheKey>
new: ty1: TType * ty2: TType * canCoerce: CanCoerce * tcGlobals: TcGlobals -> TTypeCacheKey
private new: ty1: TType * ty2: TType * canCoerce: CanCoerce * tcGlobals: TcGlobals -> TTypeCacheKey
static member FromStrippedTypes: ty1: TType * ty2: TType * canCoerce: CanCoerce * tcGlobals: TcGlobals -> TTypeCacheKey
val ty1: TType
val ty2: TType
val canCoerce: CanCoerce
Expand Down

0 comments on commit f5047d8

Please sign in to comment.