Skip to content

Commit 8aa25b1

Browse files
T-GroCopilot
andcommitted
Split AttribChecking into ResumableCodePatterns, SeqExprPatterns, ExtensionAndMiscHelpers
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 21d9638 commit 8aa25b1

2 files changed

Lines changed: 71 additions & 62 deletions

File tree

src/Compiler/TypedTree/TypedTreeOps.Transforms.fs

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,23 +2723,7 @@ module internal LoopAndConstantOptimization =
27232723
| _ -> ValueNone
27242724

27252725
[<AutoOpen>]
2726-
module internal AttribChecking =
2727-
2728-
/// An immutable mapping from witnesses to some data.
2729-
///
2730-
/// Note: this uses an immutable HashMap/Dictionary with an IEqualityComparer that captures TcGlobals, see EmptyTraitWitnessInfoHashMap
2731-
type TraitWitnessInfoHashMap<'T> = ImmutableDictionary<TraitWitnessInfo, 'T>
2732-
2733-
/// Create an empty immutable mapping from witnesses to some data
2734-
let EmptyTraitWitnessInfoHashMap g : TraitWitnessInfoHashMap<'T> =
2735-
ImmutableDictionary.Create(
2736-
{ new IEqualityComparer<_> with
2737-
member _.Equals(a, b) =
2738-
nullSafeEquality a b (fun a b -> traitKeysAEquiv g TypeEquivEnv.EmptyIgnoreNulls a b)
2739-
2740-
member _.GetHashCode(a) = hash a.MemberName
2741-
}
2742-
)
2726+
module internal ResumableCodePatterns =
27432727

27442728
[<return: Struct>]
27452729
let (|MatchTwoCasesExpr|_|) expr =
@@ -2900,39 +2884,8 @@ module internal AttribChecking =
29002884
ValueSome(iref, f, args, m, (fun (f2, args2) -> Expr.App((iref, a, b, (f2 :: args2), m))))
29012885
| _ -> ValueNone
29022886

2903-
let ComputeUseMethodImpl g (v: Val) =
2904-
v.ImplementedSlotSigs
2905-
|> List.exists (fun slotsig ->
2906-
let oty = slotsig.DeclaringType
2907-
let otcref = tcrefOfAppTy g oty
2908-
let tcref = v.MemberApparentEntity
2909-
2910-
// REVIEW: it would be good to get rid of this special casing of Compare and GetHashCode
2911-
isInterfaceTy g oty
2912-
&&
2913-
2914-
(let isCompare =
2915-
tcref.GeneratedCompareToValues.IsSome
2916-
&& (typeEquiv g oty g.mk_IComparable_ty
2917-
|| tyconRefEq g g.system_GenericIComparable_tcref otcref)
2918-
2919-
not isCompare)
2920-
&&
2921-
2922-
(let isGenericEquals =
2923-
tcref.GeneratedHashAndEqualsWithComparerValues.IsSome
2924-
&& tyconRefEq g g.system_GenericIEquatable_tcref otcref
2925-
2926-
not isGenericEquals)
2927-
&&
2928-
2929-
(let isStructural =
2930-
(tcref.GeneratedCompareToWithComparerValues.IsSome
2931-
&& typeEquiv g oty g.mk_IStructuralComparable_ty)
2932-
|| (tcref.GeneratedHashAndEqualsWithComparerValues.IsSome
2933-
&& typeEquiv g oty g.mk_IStructuralEquatable_ty)
2934-
2935-
not isStructural))
2887+
[<AutoOpen>]
2888+
module internal SeqExprPatterns =
29362889

29372890
[<return: Struct>]
29382891
let (|Seq|_|) g expr =
@@ -3054,6 +3007,58 @@ module internal AttribChecking =
30543007
| ValApp g g.seq_empty_vref (_, [], m) -> ValueSome m
30553008
| _ -> ValueNone
30563009

3010+
[<AutoOpen>]
3011+
module internal ExtensionAndMiscHelpers =
3012+
3013+
/// An immutable mapping from witnesses to some data.
3014+
///
3015+
/// Note: this uses an immutable HashMap/Dictionary with an IEqualityComparer that captures TcGlobals, see EmptyTraitWitnessInfoHashMap
3016+
type TraitWitnessInfoHashMap<'T> = ImmutableDictionary<TraitWitnessInfo, 'T>
3017+
3018+
/// Create an empty immutable mapping from witnesses to some data
3019+
let EmptyTraitWitnessInfoHashMap g : TraitWitnessInfoHashMap<'T> =
3020+
ImmutableDictionary.Create(
3021+
{ new IEqualityComparer<_> with
3022+
member _.Equals(a, b) =
3023+
nullSafeEquality a b (fun a b -> traitKeysAEquiv g TypeEquivEnv.EmptyIgnoreNulls a b)
3024+
3025+
member _.GetHashCode(a) = hash a.MemberName
3026+
}
3027+
)
3028+
3029+
let ComputeUseMethodImpl g (v: Val) =
3030+
v.ImplementedSlotSigs
3031+
|> List.exists (fun slotsig ->
3032+
let oty = slotsig.DeclaringType
3033+
let otcref = tcrefOfAppTy g oty
3034+
let tcref = v.MemberApparentEntity
3035+
3036+
// REVIEW: it would be good to get rid of this special casing of Compare and GetHashCode
3037+
isInterfaceTy g oty
3038+
&&
3039+
3040+
(let isCompare =
3041+
tcref.GeneratedCompareToValues.IsSome
3042+
&& (typeEquiv g oty g.mk_IComparable_ty
3043+
|| tyconRefEq g g.system_GenericIComparable_tcref otcref)
3044+
3045+
not isCompare)
3046+
&&
3047+
3048+
(let isGenericEquals =
3049+
tcref.GeneratedHashAndEqualsWithComparerValues.IsSome
3050+
&& tyconRefEq g g.system_GenericIEquatable_tcref otcref
3051+
3052+
not isGenericEquals)
3053+
&&
3054+
3055+
(let isStructural =
3056+
(tcref.GeneratedCompareToWithComparerValues.IsSome
3057+
&& typeEquiv g oty g.mk_IStructuralComparable_ty)
3058+
|| (tcref.GeneratedHashAndEqualsWithComparerValues.IsSome
3059+
&& typeEquiv g oty g.mk_IStructuralEquatable_ty)
3060+
3061+
not isStructural))
30573062

30583063
[<return: Struct>]
30593064
let (|EmptyModuleOrNamespaces|_|) (moduleOrNamespaceContents: ModuleOrNamespaceContents) =

src/Compiler/TypedTree/TypedTreeOps.Transforms.fsi

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,7 @@ module internal LoopAndConstantOptimization =
273273
val (|IfUseResumableStateMachinesExpr|_|): TcGlobals -> Expr -> (Expr * Expr) voption
274274

275275
[<AutoOpen>]
276-
module internal AttribChecking =
277-
278-
/// An immutable mapping from witnesses to some data.
279-
///
280-
/// Note: this uses an immutable HashMap/Dictionary with an IEqualityComparer that captures TcGlobals, see EmptyTraitWitnessInfoHashMap
281-
type TraitWitnessInfoHashMap<'T> = ImmutableDictionary<TraitWitnessInfo, 'T>
282-
283-
/// Create an empty immutable mapping from witnesses to some data
284-
val EmptyTraitWitnessInfoHashMap: TcGlobals -> TraitWitnessInfoHashMap<'T>
276+
module internal ResumableCodePatterns =
285277

286278
/// Recognise a 'match __resumableEntry() with ...' expression
287279
[<return: Struct>]
@@ -308,8 +300,8 @@ module internal AttribChecking =
308300
val (|ResumableCodeInvoke|_|):
309301
g: TcGlobals -> expr: Expr -> (Expr * Expr * Expr list * range * (Expr * Expr list -> Expr)) voption
310302

311-
/// Determine if a value is a method implementing an interface dispatch slot using a private method impl
312-
val ComputeUseMethodImpl: g: TcGlobals -> v: Val -> bool
303+
[<AutoOpen>]
304+
module internal SeqExprPatterns =
313305

314306
/// Detect the de-sugared form of a 'yield x' within a 'seq { ... }'
315307
[<return: Struct>]
@@ -347,6 +339,19 @@ module internal AttribChecking =
347339
[<return: Struct>]
348340
val (|Seq|_|): TcGlobals -> Expr -> (Expr * TType) voption
349341

342+
[<AutoOpen>]
343+
module internal ExtensionAndMiscHelpers =
344+
345+
/// An immutable mapping from witnesses to some data.
346+
///
347+
/// Note: this uses an immutable HashMap/Dictionary with an IEqualityComparer that captures TcGlobals, see EmptyTraitWitnessInfoHashMap
348+
type TraitWitnessInfoHashMap<'T> = ImmutableDictionary<TraitWitnessInfo, 'T>
349+
350+
/// Create an empty immutable mapping from witnesses to some data
351+
val EmptyTraitWitnessInfoHashMap: TcGlobals -> TraitWitnessInfoHashMap<'T>
352+
353+
/// Determine if a value is a method implementing an interface dispatch slot using a private method impl
354+
val ComputeUseMethodImpl: g: TcGlobals -> v: Val -> bool
350355

351356
/// Matches a ModuleOrNamespaceContents that is empty from a signature printing point of view.
352357
/// Signatures printed via the typed tree in NicePrint don't print TMDefOpens or TMDefDo.
@@ -373,4 +378,3 @@ module internal AttribChecking =
373378
Entity
374379

375380

376-

0 commit comments

Comments
 (0)