Skip to content

Commit 27d4652

Browse files
authored
Merge pull request #8254 from dsyme/pre-ext
pre-cleanup related to #6805
2 parents 0595fec + c0cc024 commit 27d4652

14 files changed

+252
-177
lines changed

src/fsharp/ConstraintSolver.fsi

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,48 @@ val FreshenMethInfo : range -> MethInfo -> TType list
4747
[<RequireQualifiedAccess>]
4848
/// Information about the context of a type equation.
4949
type ContextInfo =
50-
/// No context was given.
51-
| NoContext
52-
/// The type equation comes from an IF expression.
53-
| IfExpression of range
54-
/// The type equation comes from an omitted else branch.
55-
| OmittedElseBranch of range
56-
/// The type equation comes from a type check of the result of an else branch.
57-
| ElseBranchResult of range
58-
/// The type equation comes from the verification of record fields.
59-
| RecordFields
60-
/// The type equation comes from the verification of a tuple in record fields.
61-
| TupleInRecordFields
62-
/// The type equation comes from a list or array constructor
63-
| CollectionElement of bool * range
64-
/// The type equation comes from a return in a computation expression.
65-
| ReturnInComputationExpression
66-
/// The type equation comes from a yield in a computation expression.
67-
| YieldInComputationExpression
68-
/// The type equation comes from a runtime type test.
69-
| RuntimeTypeTest of bool
70-
/// The type equation comes from an downcast where a upcast could be used.
71-
| DowncastUsedInsteadOfUpcast of bool
72-
/// The type equation comes from a return type of a pattern match clause (not the first clause).
73-
| FollowingPatternMatchClause of range
74-
/// The type equation comes from a pattern match guard.
75-
| PatternMatchGuard of range
76-
/// The type equation comes from a sequence expression.
77-
| SequenceExpression of TType
50+
51+
/// No context was given.
52+
| NoContext
53+
54+
/// The type equation comes from an IF expression.
55+
| IfExpression of range
56+
57+
/// The type equation comes from an omitted else branch.
58+
| OmittedElseBranch of range
59+
60+
/// The type equation comes from a type check of the result of an else branch.
61+
| ElseBranchResult of range
62+
63+
/// The type equation comes from the verification of record fields.
64+
| RecordFields
65+
66+
/// The type equation comes from the verification of a tuple in record fields.
67+
| TupleInRecordFields
68+
69+
/// The type equation comes from a list or array constructor
70+
| CollectionElement of bool * range
71+
72+
/// The type equation comes from a return in a computation expression.
73+
| ReturnInComputationExpression
74+
75+
/// The type equation comes from a yield in a computation expression.
76+
| YieldInComputationExpression
77+
78+
/// The type equation comes from a runtime type test.
79+
| RuntimeTypeTest of bool
80+
81+
/// The type equation comes from an downcast where a upcast could be used.
82+
| DowncastUsedInsteadOfUpcast of bool
83+
84+
/// The type equation comes from a return type of a pattern match clause (not the first clause).
85+
| FollowingPatternMatchClause of range
86+
87+
/// The type equation comes from a pattern match guard.
88+
| PatternMatchGuard of range
89+
90+
/// The type equation comes from a sequence expression.
91+
| SequenceExpression of TType
7892

7993
exception ConstraintSolverTupleDiffLengths of displayEnv: DisplayEnv * TType list * TType list * range * range
8094
exception ConstraintSolverInfiniteTypes of displayEnv: DisplayEnv * contextInfo: ContextInfo * TType * TType * range * range
@@ -116,7 +130,10 @@ type OptionalTrace =
116130
val SimplifyMeasuresInTypeScheme : TcGlobals -> bool -> Typars -> TType -> TyparConstraint list -> Typars
117131
val SolveTyparEqualsType : ConstraintSolverEnv -> int -> range -> OptionalTrace -> TType -> TType -> OperationResult<unit>
118132
val SolveTypeEqualsTypeKeepAbbrevs : ConstraintSolverEnv -> int -> range -> OptionalTrace -> TType -> TType -> OperationResult<unit>
133+
134+
/// Canonicalize constraints prior to generalization
119135
val CanonicalizeRelevantMemberConstraints : ConstraintSolverEnv -> int -> OptionalTrace -> Typars -> OperationResult<unit>
136+
120137
val ResolveOverloading : ConstraintSolverEnv -> OptionalTrace -> string -> ndeep: int -> TraitConstraintInfo option -> int * int -> AccessorDomain -> CalledMeth<Expr> list -> bool -> TType option -> CalledMeth<Expr> option * OperationResult<unit>
121138
val UnifyUniqueOverloading : ConstraintSolverEnv -> int * int -> string -> AccessorDomain -> CalledMeth<SynExpr> list -> TType -> OperationResult<bool>
122139
val EliminateConstraintsForGeneralizedTypars : ConstraintSolverEnv -> OptionalTrace -> Typars -> unit

src/fsharp/IlxGen.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5273,7 +5273,7 @@ and GenBindingAfterSequencePoint cenv cgbuf eenv sp (TBind(vspec, rhsExpr, _)) s
52735273
// Workaround for .NET and Visual Studio restriction w.r.t debugger type proxys
52745274
// Mark internal constructors in internal classes as public.
52755275
let access =
5276-
if access = ILMemberAccess.Assembly && vspec.IsConstructor && IsHiddenTycon g eenv.sigToImplRemapInfo vspec.MemberApparentEntity.Deref then
5276+
if access = ILMemberAccess.Assembly && vspec.IsConstructor && IsHiddenTycon eenv.sigToImplRemapInfo vspec.MemberApparentEntity.Deref then
52775277
ILMemberAccess.Public
52785278
else
52795279
access
@@ -6488,7 +6488,7 @@ and GenModuleBinding cenv (cgbuf: CodeGenBuffer) (qname: QualifiedNameOfFile) la
64886488
GenLetRecBindings cenv cgbuf eenv ([bind], m)
64896489

64906490
| ModuleOrNamespaceBinding.Module (mspec, mdef) ->
6491-
let hidden = IsHiddenTycon cenv.g eenv.sigToImplRemapInfo mspec
6491+
let hidden = IsHiddenTycon eenv.sigToImplRemapInfo mspec
64926492

64936493
let eenvinner =
64946494
if mspec.IsNamespace then eenv else
@@ -6827,8 +6827,8 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) =
68276827
let ilIntfTys = tycon.ImmediateInterfaceTypesOfFSharpTycon |> List.map (GenType cenv.amap m eenvinner.tyenv)
68286828
let ilTypeName = tref.Name
68296829

6830-
let hidden = IsHiddenTycon g eenv.sigToImplRemapInfo tycon
6831-
let hiddenRepr = hidden || IsHiddenTyconRepr g eenv.sigToImplRemapInfo tycon
6830+
let hidden = IsHiddenTycon eenv.sigToImplRemapInfo tycon
6831+
let hiddenRepr = hidden || IsHiddenTyconRepr eenv.sigToImplRemapInfo tycon
68326832
let access = ComputeTypeAccess tref hidden
68336833

68346834
// The implicit augmentation doesn't actually create CompareTo(object) or Object.Equals
@@ -7411,7 +7411,7 @@ and GenExnDef cenv mgbuf eenv m (exnc: Tycon) =
74117411
| TExnFresh _ ->
74127412
let ilThisTy = GenExnType cenv.amap m eenv.tyenv exncref
74137413
let tref = ilThisTy.TypeRef
7414-
let isHidden = IsHiddenTycon g eenv.sigToImplRemapInfo exnc
7414+
let isHidden = IsHiddenTycon eenv.sigToImplRemapInfo exnc
74157415
let access = ComputeTypeAccess tref isHidden
74167416
let reprAccess = ComputeMemberAccess isHidden
74177417
let fspecs = exnc.TrueInstanceFieldsAsList

src/fsharp/InfoReader.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ open FSharp.Compiler.Tastops
1919
open FSharp.Compiler.TcGlobals
2020

2121
/// Use the given function to select some of the member values from the members of an F# type
22-
let private SelectImmediateMemberVals g optFilter f (tcref: TyconRef) =
22+
let SelectImmediateMemberVals g optFilter f (tcref: TyconRef) =
2323
let chooser (vref: ValRef) =
2424
match vref.MemberInfo with
2525
// The 'when' condition is a workaround for the fact that values providing

src/fsharp/MethodCalls.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ type CalledMeth<'T>
498498

499499
member x.TotalNumAssignedNamedArgs = x.ArgSets |> List.sumBy (fun x -> x.NumAssignedNamedArgs)
500500

501+
override x.ToString() = "call to " + minfo.ToString()
502+
501503
let NamesOfCalledArgs (calledArgs: CalledArg list) =
502504
calledArgs |> List.choose (fun x -> x.NameOpt)
503505

@@ -1050,15 +1052,20 @@ let BuildFSharpMethodCall g m (ty, vref: ValRef) valUseFlags minst args =
10501052
/// calls to the type-directed solutions to member constraints.
10511053
let MakeMethInfoCall amap m minfo minst args =
10521054
let valUseFlags = NormalValUse // correct unless if we allow wild trait constraints like "T has a ctor and can be used as a parent class"
1055+
10531056
match minfo with
1057+
10541058
| ILMeth(g, ilminfo, _) ->
10551059
let direct = not minfo.IsVirtual
10561060
let isProp = false // not necessarily correct, but this is only used post-creflect where this flag is irrelevant
10571061
BuildILMethInfoCall g amap m isProp ilminfo valUseFlags minst direct args |> fst
1062+
10581063
| FSMeth(g, ty, vref, _) ->
10591064
BuildFSharpMethodCall g m (ty, vref) valUseFlags minst args |> fst
1065+
10601066
| DefaultStructCtor(_, ty) ->
10611067
mkDefault (m, ty)
1068+
10621069
#if !NO_EXTENSIONTYPING
10631070
| ProvidedMeth(amap, mi, _, m) ->
10641071
let isProp = false // not necessarily correct, but this is only used post-creflect where this flag is irrelevant

src/fsharp/NameResolution.fs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -550,15 +550,30 @@ let AllPropInfosOfTypeInScope collectionSettings infoReader nenv optFilter ad fi
550550
@ ExtensionPropInfosOfTypeInScope collectionSettings infoReader nenv optFilter ad m ty
551551

552552
/// Get the available methods of a type (both declared and inherited)
553-
let IntrinsicMethInfosOfType (infoReader:InfoReader) optFilter ad allowMultiIntfInst findFlag m ty =
553+
let IntrinsicMethInfosOfType (infoReader: InfoReader) optFilter ad allowMultiIntfInst findFlag m ty =
554554
let g = infoReader.g
555555
let amap = infoReader.amap
556556
let minfos = GetIntrinsicMethInfoSetsOfType infoReader optFilter ad allowMultiIntfInst findFlag m ty
557557
let minfos = minfos |> ExcludeHiddenOfMethInfos g amap m
558558
minfos
559559

560+
let TrySelectExtensionMethInfoOfILExtMem m amap apparentTy (actualParent, minfo, pri) =
561+
match minfo with
562+
| ILMeth(_,ilminfo,_) ->
563+
MethInfo.CreateILExtensionMeth (amap, m, apparentTy, actualParent, Some pri, ilminfo.RawMetadata) |> Some
564+
// F#-defined IL-style extension methods are not seen as extension methods in F# code
565+
| FSMeth(g,_,vref,_) ->
566+
FSMeth(g, apparentTy, vref, Some pri) |> Some
567+
#if !NO_EXTENSIONTYPING
568+
// // Provided extension methods are not yet supported
569+
| ProvidedMeth(amap,providedMeth,_,m) ->
570+
ProvidedMeth(amap, providedMeth, Some pri,m) |> Some
571+
#endif
572+
| DefaultStructCtor _ ->
573+
None
574+
560575
/// Select from a list of extension methods
561-
let SelectMethInfosFromExtMembers (infoReader:InfoReader) optFilter apparentTy m extMemInfos =
576+
let SelectMethInfosFromExtMembers (infoReader: InfoReader) optFilter apparentTy m extMemInfos =
562577
let g = infoReader.g
563578
// NOTE: multiple "open"'s push multiple duplicate values into eIndexedExtensionMembers
564579
let seen = HashSet(ExtensionMember.Comparer g)
@@ -575,24 +590,14 @@ let SelectMethInfosFromExtMembers (infoReader:InfoReader) optFilter apparentTy m
575590
| _ -> ()
576591
| ILExtMem (actualParent, minfo, pri) when (match optFilter with None -> true | Some nm -> nm = minfo.LogicalName) ->
577592
// Make a reference to the type containing the extension members
578-
match minfo with
579-
| ILMeth(_, ilminfo, _) ->
580-
yield (MethInfo.CreateILExtensionMeth (infoReader.amap, m, apparentTy, actualParent, Some pri, ilminfo.RawMetadata))
581-
// F#-defined IL-style extension methods are not seen as extension methods in F# code
582-
| FSMeth(g, _, vref, _) ->
583-
yield (FSMeth(g, apparentTy, vref, Some pri))
584-
#if !NO_EXTENSIONTYPING
585-
// // Provided extension methods are not yet supported
586-
| ProvidedMeth(amap, providedMeth, _, m) ->
587-
yield (ProvidedMeth(amap, providedMeth, Some pri, m))
588-
#endif
589-
| DefaultStructCtor _ ->
590-
()
593+
match TrySelectExtensionMethInfoOfILExtMem m infoReader.amap apparentTy (actualParent, minfo, pri) with
594+
| Some minfo -> yield minfo
595+
| None -> ()
591596
| _ -> ()
592597
]
593598

594599
/// Query the available extension properties of a methods (including extension methods for inherited types)
595-
let ExtensionMethInfosOfTypeInScope (collectionSettings:ResultCollectionSettings) (infoReader:InfoReader) (nenv: NameResolutionEnv) optFilter m ty =
600+
let ExtensionMethInfosOfTypeInScope (collectionSettings: ResultCollectionSettings) (infoReader: InfoReader) (nenv: NameResolutionEnv) optFilter m ty =
596601
let extMemsDangling = SelectMethInfosFromExtMembers infoReader optFilter ty m nenv.eUnindexedExtensionMembers
597602
if collectionSettings = ResultCollectionSettings.AtMostOneResult && not (isNil extMemsDangling) then
598603
extMemsDangling

src/fsharp/NameResolution.fsi

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,68 @@ val ItemWithNoInst : Item -> ItemWithInst
141141
type FieldResolution = FieldResolution of RecdFieldRef * bool
142142

143143
/// Information about an extension member held in the name resolution environment
144-
[<Sealed>]
145-
type ExtensionMember
144+
type ExtensionMember =
145+
/// F#-style Extrinsic extension member, defined in F# code
146+
| FSExtMem of ValRef * ExtensionMethodPriority
147+
148+
/// ILExtMem(declaringTyconRef, ilMetadata, pri)
149+
///
150+
/// IL-style extension member, backed by some kind of method with an [<Extension>] attribute
151+
| ILExtMem of TyconRef * MethInfo * ExtensionMethodPriority
152+
153+
/// Describes the sequence order of the introduction of an extension method. Extension methods that are introduced
154+
/// later through 'open' get priority in overload resolution.
155+
member Priority : ExtensionMethodPriority
146156

147157
/// The environment of information used to resolve names
148158
[<NoEquality; NoComparison>]
149159
type NameResolutionEnv =
150-
{eDisplayEnv: DisplayEnv
151-
eUnqualifiedItems: LayeredMap<string,Item>
152-
ePatItems: NameMap<Item>
153-
eModulesAndNamespaces: NameMultiMap<ModuleOrNamespaceRef>
154-
eFullyQualifiedModulesAndNamespaces: NameMultiMap<ModuleOrNamespaceRef>
155-
eFieldLabels: NameMultiMap<RecdFieldRef>
156-
eTyconsByAccessNames: LayeredMultiMap<string,TyconRef>
157-
eFullyQualifiedTyconsByAccessNames: LayeredMultiMap<string,TyconRef>
158-
eTyconsByDemangledNameAndArity: LayeredMap<NameArityPair,TyconRef>
159-
eFullyQualifiedTyconsByDemangledNameAndArity: LayeredMap<NameArityPair,TyconRef>
160-
eIndexedExtensionMembers: TyconRefMultiMap<ExtensionMember>
161-
eUnindexedExtensionMembers: ExtensionMember list
162-
eTypars: NameMap<Typar> }
160+
{ /// Display environment information for output
161+
eDisplayEnv: DisplayEnv
162+
163+
/// Values and Data Tags available by unqualified name
164+
eUnqualifiedItems: LayeredMap<string,Item>
165+
166+
/// Data Tags and Active Pattern Tags available by unqualified name
167+
ePatItems: NameMap<Item>
168+
169+
/// Modules accessible via "." notation. Note this is a multi-map.
170+
/// Adding a module abbreviation adds it a local entry to this List.map.
171+
/// Likewise adding a ccu or opening a path adds entries to this List.map.
172+
eModulesAndNamespaces: NameMultiMap<Tast.ModuleOrNamespaceRef>
173+
174+
/// Fully qualified modules and namespaces. 'open' does not change this.
175+
eFullyQualifiedModulesAndNamespaces: NameMultiMap<Tast.ModuleOrNamespaceRef>
176+
177+
/// RecdField labels in scope. RecdField labels are those where type are inferred
178+
/// by label rather than by known type annotation.
179+
/// Bools indicate if from a record, where no warning is given on indeterminate lookup
180+
eFieldLabels: NameMultiMap<Tast.RecdFieldRef>
181+
182+
/// Tycons indexed by the various names that may be used to access them, e.g.
183+
/// "List" --> multiple TyconRef's for the various tycons accessible by this name.
184+
/// "List`1" --> TyconRef
185+
eTyconsByAccessNames: LayeredMultiMap<string,TyconRef>
186+
187+
eFullyQualifiedTyconsByAccessNames: LayeredMultiMap<string,TyconRef>
188+
189+
/// Tycons available by unqualified, demangled names (i.e. (List,1) --> TyconRef)
190+
eTyconsByDemangledNameAndArity: LayeredMap<NameArityPair,TyconRef>
191+
192+
/// Tycons available by unqualified, demangled names (i.e. (List,1) --> TyconRef)
193+
eFullyQualifiedTyconsByDemangledNameAndArity: LayeredMap<NameArityPair,TyconRef>
194+
195+
/// Extension members by type and name
196+
eIndexedExtensionMembers: TyconRefMultiMap<ExtensionMember>
197+
198+
/// Other extension members unindexed by type
199+
eUnindexedExtensionMembers: ExtensionMember list
200+
201+
/// Typars (always available by unqualified names). Further typars can be
202+
/// in the tpenv, a structure folded through each top-level definition.
203+
eTypars: NameMap<Typar>
204+
205+
}
163206
static member Empty : g:TcGlobals -> NameResolutionEnv
164207
member DisplayEnv : DisplayEnv
165208
member FindUnqualifiedItem : string -> Item
@@ -545,3 +588,6 @@ val ResolveCompletionsInType : NameResolver -> NameResolutionEnv -> Resolv
545588
val GetVisibleNamespacesAndModulesAtPoint : NameResolver -> NameResolutionEnv -> range -> AccessorDomain -> ModuleOrNamespaceRef list
546589

547590
val IsItemResolvable : NameResolver -> NameResolutionEnv -> range -> AccessorDomain -> string list -> Item -> bool
591+
592+
val TrySelectExtensionMethInfoOfILExtMem : range -> ImportMap -> TType -> TyconRef * MethInfo * ExtensionMethodPriority -> MethInfo option
593+

src/fsharp/PostInferenceChecks.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,8 +1926,8 @@ let CheckRecdField isUnion cenv env (tycon: Tycon) (rfield: RecdField) =
19261926
let m = rfield.Range
19271927
let fieldTy = stripTyEqns cenv.g rfield.FormalType
19281928
let isHidden =
1929-
IsHiddenTycon cenv.g env.sigToImplRemapInfo tycon ||
1930-
IsHiddenTyconRepr cenv.g env.sigToImplRemapInfo tycon ||
1929+
IsHiddenTycon env.sigToImplRemapInfo tycon ||
1930+
IsHiddenTyconRepr env.sigToImplRemapInfo tycon ||
19311931
(not isUnion && IsHiddenRecdField env.sigToImplRemapInfo (tcref.MakeNestedRecdFieldRef rfield))
19321932
let access = AdjustAccess isHidden (fun () -> tycon.CompilationPath) rfield.Accessibility
19331933
CheckTypeForAccess cenv env (fun () -> rfield.Name) access m fieldTy
@@ -2189,7 +2189,7 @@ let CheckEntityDefn cenv env (tycon: Entity) =
21892189
uc.RecdFieldsArray |> Array.iter (CheckRecdField true cenv env tycon))
21902190

21912191
// Access checks
2192-
let access = AdjustAccess (IsHiddenTycon g env.sigToImplRemapInfo tycon) (fun () -> tycon.CompilationPath) tycon.Accessibility
2192+
let access = AdjustAccess (IsHiddenTycon env.sigToImplRemapInfo tycon) (fun () -> tycon.CompilationPath) tycon.Accessibility
21932193
let visitType ty = CheckTypeForAccess cenv env (fun () -> tycon.DisplayNameWithStaticParametersAndUnderscoreTypars) access tycon.Range ty
21942194

21952195
abstractSlotValsOfTycons [tycon] |> List.iter (typeOfVal >> visitType)

0 commit comments

Comments
 (0)