Skip to content

Commit

Permalink
AllMethInfosOfTypeInScope with shortcut of extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Feb 10, 2019
1 parent 1bbb60a commit e361521
Show file tree
Hide file tree
Showing 4 changed files with 631 additions and 620 deletions.
6 changes: 3 additions & 3 deletions src/fsharp/MethodCalls.fs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ type CalledMeth<'T>
| _ ->
let epinfos =
match nameEnv with
| Some(ne) -> ExtensionPropInfosOfTypeInScope infoReader ne (Some(nm), ad) m returnedObjTy
| Some ne -> ExtensionPropInfosOfTypeInScope ResultCollectionSettings.AllResults infoReader ne (Some nm) ad m returnedObjTy
| _ -> []
match epinfos with
| [pinfo] when pinfo.HasSetter && not pinfo.IsIndexer ->
Expand All @@ -337,8 +337,8 @@ type CalledMeth<'T>
| _ -> freshenMethInfo m pminfo

let pminst = match tyargsOpt with
| Some(TType.TType_app(_, types)) -> types
| _ -> pminst
| Some(TType.TType_app(_, types)) -> types
| _ -> pminst
Choice1Of2(AssignedItemSetter(id, AssignedPropSetter(pinfo, pminfo, pminst), e))
| _ ->
match infoReader.GetILFieldInfosOfType(Some(nm), ad, m, returnedObjTy) with
Expand Down
91 changes: 51 additions & 40 deletions src/fsharp/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,7 +1941,7 @@ let ResolveObjectConstructor (ncenv:NameResolver) edenv m ad ty =
//-------------------------------------------------------------------------

/// Query the declared properties of a type (including inherited properties)
let IntrinsicPropInfosOfTypeInScope (infoReader:InfoReader) (optFilter, ad) findFlag m ty =
let IntrinsicPropInfosOfTypeInScope (infoReader:InfoReader) optFilter ad findFlag m ty =
let g = infoReader.g
let amap = infoReader.amap
let pinfos = GetIntrinsicPropInfoSetsOfType infoReader (optFilter, ad, AllowMultiIntfInstantiations.Yes) findFlag m ty
Expand All @@ -1968,25 +1968,29 @@ let SelectPropInfosFromExtMembers (infoReader:InfoReader,ad,optFilter) declaring
propCollector.Close()

/// Query the available extension properties of a type (including extension properties for inherited types)
let ExtensionPropInfosOfTypeInScope (infoReader:InfoReader) (nenv: NameResolutionEnv) (optFilter, ad) m ty =
let ExtensionPropInfosOfTypeInScope (collectionSettings:ResultCollectionSettings) (infoReader:InfoReader) (nenv: NameResolutionEnv) optFilter ad m ty =
let g = infoReader.g

let extMemsFromHierarchy =
infoReader.GetEntireTypeHierachy(AllowMultiIntfInstantiations.Yes,m,ty) |> List.collect (fun ty ->
if isAppTy g ty then
let tcref = tcrefOfAppTy g ty
let extMemInfos = nenv.eIndexedExtensionMembers.Find tcref
SelectPropInfosFromExtMembers (infoReader,ad,optFilter) ty m extMemInfos
else [])
let extMemsDangling = SelectPropInfosFromExtMembers (infoReader,ad,optFilter) ty m nenv.eUnindexedExtensionMembers

let extMemsDangling = SelectPropInfosFromExtMembers (infoReader,ad,optFilter) ty m nenv.eUnindexedExtensionMembers
extMemsDangling @ extMemsFromHierarchy
if collectionSettings = ResultCollectionSettings.AtMostOneResult && not (List.isEmpty extMemsDangling) then
extMemsDangling
else
let extMemsFromHierarchy =
infoReader.GetEntireTypeHierachy(AllowMultiIntfInstantiations.Yes,m,ty)
|> List.collect (fun ty ->
if isAppTy g ty then
let tcref = tcrefOfAppTy g ty
let extMemInfos = nenv.eIndexedExtensionMembers.Find tcref
SelectPropInfosFromExtMembers (infoReader,ad,optFilter) ty m extMemInfos
else [])

extMemsDangling @ extMemsFromHierarchy

/// Get all the available properties of a type (both intrinsic and extension)
let AllPropInfosOfTypeInScope infoReader nenv (optFilter, ad) findFlag m ty =
IntrinsicPropInfosOfTypeInScope infoReader (optFilter, ad) findFlag m ty
@ ExtensionPropInfosOfTypeInScope infoReader nenv (optFilter, ad) m ty
let AllPropInfosOfTypeInScope collectionSettings infoReader nenv optFilter ad findFlag m ty =
IntrinsicPropInfosOfTypeInScope infoReader optFilter ad findFlag m ty
@ ExtensionPropInfosOfTypeInScope collectionSettings infoReader nenv optFilter ad m ty

/// Get the available methods of a type (both declared and inherited)
let IntrinsicMethInfosOfType (infoReader:InfoReader) (optFilter,ad,allowMultiIntfInst) findFlag m ty =
Expand Down Expand Up @@ -2031,22 +2035,29 @@ let SelectMethInfosFromExtMembers (infoReader:InfoReader) optFilter apparentTy m
]

/// Query the available extension properties of a methods (including extension methods for inherited types)
let ExtensionMethInfosOfTypeInScope (infoReader:InfoReader) (nenv: NameResolutionEnv) optFilter m ty =
let extMemsDangling = SelectMethInfosFromExtMembers infoReader optFilter ty m nenv.eUnindexedExtensionMembers
let extMemsFromHierarchy =
infoReader.GetEntireTypeHierachy(AllowMultiIntfInstantiations.Yes,m,ty) |> List.collect (fun ty ->
let g = infoReader.g
if isAppTy g ty then
let tcref = tcrefOfAppTy g ty
let extValRefs = nenv.eIndexedExtensionMembers.Find tcref
SelectMethInfosFromExtMembers infoReader optFilter ty m extValRefs
else [])
extMemsDangling @ extMemsFromHierarchy
let ExtensionMethInfosOfTypeInScope (collectionSettings:ResultCollectionSettings) (infoReader:InfoReader) (nenv: NameResolutionEnv) optFilter m ty =
let extMemsDangling = SelectMethInfosFromExtMembers infoReader optFilter ty m nenv.eUnindexedExtensionMembers
if collectionSettings = ResultCollectionSettings.AtMostOneResult && not (List.isEmpty extMemsDangling) then
extMemsDangling
else
let extMemsFromHierarchy =
infoReader.GetEntireTypeHierachy(AllowMultiIntfInstantiations.Yes,m,ty)
|> List.collect (fun ty ->
let g = infoReader.g
if isAppTy g ty then
let tcref = tcrefOfAppTy g ty
let extValRefs = nenv.eIndexedExtensionMembers.Find tcref
SelectMethInfosFromExtMembers infoReader optFilter ty m extValRefs
else [])
extMemsDangling @ extMemsFromHierarchy

/// Get all the available methods of a type (both intrinsic and extension)
let AllMethInfosOfTypeInScope infoReader nenv (optFilter,ad) findFlag m ty =
IntrinsicMethInfosOfType infoReader (optFilter,ad,AllowMultiIntfInstantiations.Yes) findFlag m ty
@ ExtensionMethInfosOfTypeInScope infoReader nenv optFilter m ty
let AllMethInfosOfTypeInScope collectionSettings infoReader nenv optFilter ad findFlag m ty =
let intrinsic = IntrinsicMethInfosOfType infoReader (optFilter,ad,AllowMultiIntfInstantiations.Yes) findFlag m ty
if collectionSettings = ResultCollectionSettings.AtMostOneResult && not (List.isEmpty intrinsic) then
intrinsic
else
intrinsic @ ExtensionMethInfosOfTypeInScope collectionSettings infoReader nenv optFilter m ty


/// Used to report an error condition where name resolution failed due to an indeterminate type
Expand Down Expand Up @@ -2152,7 +2163,7 @@ let rec ResolveLongIdentInTypePrim (ncenv:NameResolver) nenv lookupKind (resInfo
let pinfos = psets |> ExcludeHiddenOfPropInfos g ncenv.amap m

// fold the available extension members into the overload resolution
let extensionPropInfos = ExtensionPropInfosOfTypeInScope ncenv.InfoReader nenv (optFilter,ad) m ty
let extensionPropInfos = ExtensionPropInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv optFilter ad m ty

// make sure to keep the intrinsic pinfos before the extension pinfos in the list,
// since later on this logic is used when giving preference to intrinsic definitions
Expand All @@ -2164,7 +2175,7 @@ let rec ResolveLongIdentInTypePrim (ncenv:NameResolver) nenv lookupKind (resInfo
let minfos = msets |> ExcludeHiddenOfMethInfos g ncenv.amap m

// fold the available extension members into the overload resolution
let extensionMethInfos = ExtensionMethInfosOfTypeInScope ncenv.InfoReader nenv optFilter m ty
let extensionMethInfos = ExtensionMethInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv optFilter m ty

success [resInfo,Item.MakeMethGroup (nm,minfos@extensionMethInfos),rest]
| Some (ILFieldItem (finfo:: _)) when (match lookupKind with LookupKind.Expr | LookupKind.Pattern -> true | _ -> false) ->
Expand All @@ -2178,9 +2189,9 @@ let rec ResolveLongIdentInTypePrim (ncenv:NameResolver) nenv lookupKind (resInfo

| _ ->

let pinfos = ExtensionPropInfosOfTypeInScope ncenv.InfoReader nenv (optFilter, ad) m ty
let pinfos = ExtensionPropInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv optFilter ad m ty
if not (isNil pinfos) && isLookUpExpr then OneResult(success (resInfo,Item.Property (nm,pinfos),rest)) else
let minfos = ExtensionMethInfosOfTypeInScope ncenv.InfoReader nenv optFilter m ty
let minfos = ExtensionMethInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv optFilter m ty

if not (isNil minfos) && isLookUpExpr then
success [resInfo,Item.MakeMethGroup (nm,minfos),rest]
Expand Down Expand Up @@ -2215,11 +2226,11 @@ let rec ResolveLongIdentInTypePrim (ncenv:NameResolver) nenv lookupKind (resInfo
| _ ->
let suggestMembers() =
let suggestions1 =
ExtensionPropInfosOfTypeInScope ncenv.InfoReader nenv (None, ad) m ty
ExtensionPropInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv None ad m ty
|> List.map (fun p -> p.PropertyName)

let suggestions2 =
ExtensionMethInfosOfTypeInScope ncenv.InfoReader nenv None m ty
ExtensionMethInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv None m ty
|> List.map (fun m -> m.DisplayName)

let suggestions3 =
Expand Down Expand Up @@ -3521,7 +3532,7 @@ let ResolveCompletionsInType (ncenv: NameResolver) nenv (completionTargets: Reso
IsILFieldInfoAccessible g amap m ad x)

let pinfosIncludingUnseen =
AllPropInfosOfTypeInScope ncenv.InfoReader nenv (None,ad) PreferOverrides m ty
AllPropInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv None ad PreferOverrides m ty
|> List.filter (fun x ->
x.IsStatic = statics &&
IsPropInfoAccessible g amap m ad x)
Expand Down Expand Up @@ -3612,7 +3623,7 @@ let ResolveCompletionsInType (ncenv: NameResolver) nenv (completionTargets: Reso
// REVIEW: add a name filter here in the common cases?
let minfos =
if completionTargets.ResolveAll then
let minfos = AllMethInfosOfTypeInScope ncenv.InfoReader nenv (None,ad) PreferOverrides m ty
let minfos = AllMethInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv None ad PreferOverrides m ty
if isNil minfos then
[]
else
Expand Down Expand Up @@ -3714,7 +3725,7 @@ let rec ResolvePartialLongIdentInType (ncenv: NameResolver) nenv isApplicableMet
rty

(ty
|> AllPropInfosOfTypeInScope ncenv.InfoReader nenv (Some id,ad) IgnoreOverrides m
|> AllPropInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv (Some id) ad IgnoreOverrides m
|> List.filter (fun pinfo -> pinfo.IsStatic = statics && IsPropInfoAccessible g amap m ad pinfo)
|> List.collect (fun pinfo -> (FullTypeOfPinfo pinfo) |> ResolvePartialLongIdentInType ncenv nenv isApplicableMeth m ad false rest)) @

Expand Down Expand Up @@ -4228,7 +4239,7 @@ let ResolveCompletionsInTypeForItem (ncenv: NameResolver) nenv m ad statics ty (
| _ -> ()

let pinfosIncludingUnseen =
AllPropInfosOfTypeInScope ncenv.InfoReader nenv (None,ad) PreferOverrides m ty
AllPropInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv None ad PreferOverrides m ty
|> List.filter (fun x ->
x.IsStatic = statics &&
IsPropInfoAccessible g amap m ad x)
Expand Down Expand Up @@ -4314,7 +4325,7 @@ let ResolveCompletionsInTypeForItem (ncenv: NameResolver) nenv m ad statics ty (
| Item.MethodGroup _ ->
// REVIEW: add a name filter here in the common cases?
let minfos =
let minfos = AllMethInfosOfTypeInScope ncenv.InfoReader nenv (None,ad) PreferOverrides m ty
let minfos = AllMethInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv None ad PreferOverrides m ty
if isNil minfos then [] else

let suppressedMethNames = Zset.ofList String.order (pinfoMethNames @ einfoMethNames)
Expand Down Expand Up @@ -4397,7 +4408,7 @@ let rec ResolvePartialLongIdentInTypeForItem (ncenv: NameResolver) nenv m ad sta

let pinfos =
ty
|> AllPropInfosOfTypeInScope ncenv.InfoReader nenv (Some id,ad) IgnoreOverrides m
|> AllPropInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv (Some id) ad IgnoreOverrides m
|> List.filter (fun pinfo -> pinfo.IsStatic = statics && IsPropInfoAccessible g amap m ad pinfo)

for pinfo in pinfos do
Expand Down
Loading

0 comments on commit e361521

Please sign in to comment.