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 Mar 7, 2018
1 parent beadbdb commit 6a92131
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 79 deletions.
68 changes: 39 additions & 29 deletions src/fsharp/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1903,25 +1903,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 typ =
let ExtensionPropInfosOfTypeInScope (collectionSettings:ResultCollectionSettings) (infoReader:InfoReader) (nenv: NameResolutionEnv) optFilter ad m typ =
let g = infoReader.g
let extMemsDangling = SelectPropInfosFromExtMembers (infoReader,ad,optFilter) typ m nenv.eUnindexedExtensionMembers

if collectionSettings = ResultCollectionSettings.AtMostOneResult && not (List.isEmpty extMemsDangling) then extMemsDangling else

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

let extMemsDangling = SelectPropInfosFromExtMembers (infoReader,ad,optFilter) typ m nenv.eUnindexedExtensionMembers

extMemsDangling @ extMemsFromHierarchy


/// Get all the available properties of a type (both intrinsic and extension)
let AllPropInfosOfTypeInScope infoReader nenv (optFilter, ad) findFlag m typ =
IntrinsicPropInfosOfTypeInScope infoReader (optFilter, ad) findFlag m typ
@ ExtensionPropInfosOfTypeInScope infoReader nenv (optFilter, ad) m typ
let AllPropInfosOfTypeInScope (collectionSettings:ResultCollectionSettings) infoReader nenv optFilter ad findFlag m typ =
let intrinsic = IntrinsicPropInfosOfTypeInScope infoReader (optFilter, ad) findFlag m typ
if collectionSettings = ResultCollectionSettings.AtMostOneResult && not (List.isEmpty intrinsic) then intrinsic else
intrinsic @ ExtensionPropInfosOfTypeInScope collectionSettings infoReader nenv optFilter ad m typ

/// Get the available methods of a type (both declared and inherited)
let IntrinsicMethInfosOfType (infoReader:InfoReader) (optFilter,ad,allowMultiIntfInst) findFlag m typ =
Expand Down Expand Up @@ -1966,23 +1970,28 @@ 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 typ =
let extMemsDangling = SelectMethInfosFromExtMembers infoReader optFilter typ m nenv.eUnindexedExtensionMembers
let ExtensionMethInfosOfTypeInScope (collectionSettings:ResultCollectionSettings) (infoReader:InfoReader) (nenv: NameResolutionEnv) optFilter m typ =
let extMemsDangling = SelectMethInfosFromExtMembers infoReader optFilter typ m nenv.eUnindexedExtensionMembers

if collectionSettings = ResultCollectionSettings.AtMostOneResult && not (List.isEmpty extMemsDangling) then extMemsDangling else

let extMemsFromHierarchy =
infoReader.GetEntireTypeHierachy(AllowMultiIntfInstantiations.Yes,m,typ) |> List.collect (fun typ ->
infoReader.GetEntireTypeHierachy(AllowMultiIntfInstantiations.Yes,m,typ)
|> List.collect (fun typ ->
let g = infoReader.g
if isAppTy g typ then
let tcref = tcrefOfAppTy g typ
let extValRefs = nenv.eIndexedExtensionMembers.Find tcref
SelectMethInfosFromExtMembers infoReader optFilter typ m extValRefs
SelectMethInfosFromExtMembers infoReader optFilter typ 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 typ =
IntrinsicMethInfosOfType infoReader (optFilter,ad,AllowMultiIntfInstantiations.Yes) findFlag m typ
@ ExtensionMethInfosOfTypeInScope infoReader nenv optFilter m typ

let AllMethInfosOfTypeInScope (collectionSettings:ResultCollectionSettings) infoReader nenv optFilter ad findFlag m typ =
let intrinsic = IntrinsicMethInfosOfType infoReader (optFilter,ad,AllowMultiIntfInstantiations.Yes) findFlag m typ
if collectionSettings = ResultCollectionSettings.AtMostOneResult && not (List.isEmpty intrinsic) then intrinsic else
intrinsic @ ExtensionMethInfosOfTypeInScope collectionSettings infoReader nenv optFilter m typ

/// Used to report an error condition where name resolution failed due to an indeterminate type
exception IndeterminateType of range
Expand Down Expand Up @@ -2073,7 +2082,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 typ
let extensionPropInfos = ExtensionPropInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv optFilter ad m typ

// 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 @@ -2084,7 +2093,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 typ
let extensionMethInfos = ExtensionMethInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv optFilter m typ

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

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

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

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

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

let pinfosIncludingUnseen =
AllPropInfosOfTypeInScope ncenv.InfoReader nenv (None,ad) PreferOverrides m typ
AllPropInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv None ad PreferOverrides m typ
|> List.filter (fun x ->
x.IsStatic = statics &&
IsPropInfoAccessible g amap m ad x)
Expand Down Expand Up @@ -3581,7 +3590,7 @@ let ResolveCompletionsInType (ncenv: NameResolver) nenv (completionTargets: Reso
let minfos =
if completionTargets.ResolveAll then
let minfos =
AllMethInfosOfTypeInScope ncenv.InfoReader nenv (None,ad) PreferOverrides m typ
AllMethInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv None ad PreferOverrides m typ
|> List.filter minfoFilter

let minfos =
Expand Down Expand Up @@ -3655,9 +3664,10 @@ let rec ResolvePartialLongIdentInType (ncenv: NameResolver) nenv isApplicableMet
let FullTypeOfPinfo(pinfo:PropInfo) =
let rty = pinfo.GetPropertyType(amap,m)
let rty = if pinfo.IsIndexer then mkRefTupledTy g (pinfo.GetParamTypes(amap, m)) --> rty else rty
rty
rty

(typ
|> AllPropInfosOfTypeInScope ncenv.InfoReader nenv (Some id,ad) IgnoreOverrides m
|> AllPropInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv (Some id) ad IgnoreOverrides m
|> List.filter (fun x -> x.IsStatic = statics)
|> List.filter (IsPropInfoAccessible g amap m ad)
|> List.collect (fun pinfo -> (FullTypeOfPinfo pinfo) |> ResolvePartialLongIdentInType ncenv nenv isApplicableMeth m ad false rest)) @
Expand Down Expand Up @@ -4122,7 +4132,7 @@ let ResolveCompletionsInTypeForItem (ncenv: NameResolver) nenv m ad statics typ
yield! typ |> GetNestedTypesOfType (ad, ncenv, None, TypeNameResolutionStaticArgsInfo.Indefinite, false, m) |> List.map (ItemOfTy g)
| _ ->
let pinfosIncludingUnseen =
AllPropInfosOfTypeInScope ncenv.InfoReader nenv (None,ad) PreferOverrides m typ
AllPropInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv None ad PreferOverrides m typ
|> List.filter (fun x ->
x.IsStatic = statics &&
IsPropInfoAccessible g amap m ad x)
Expand Down Expand Up @@ -4210,7 +4220,7 @@ let ResolveCompletionsInTypeForItem (ncenv: NameResolver) nenv m ad statics typ
// REVIEW: add a name filter here in the common cases?
let minfos =
let minfos =
AllMethInfosOfTypeInScope ncenv.InfoReader nenv (None,ad) PreferOverrides m typ
AllMethInfosOfTypeInScope ResultCollectionSettings.AllResults ncenv.InfoReader nenv None ad PreferOverrides m typ
|> List.filter minfoFilter

let minfos =
Expand Down Expand Up @@ -4282,7 +4292,7 @@ let rec ResolvePartialLongIdentInTypeForItem (ncenv: NameResolver) nenv m ad sta

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

Expand Down
18 changes: 9 additions & 9 deletions src/fsharp/NameResolution.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ type TcResultsSink =
static member NoSink : TcResultsSink
static member WithSink : ITypecheckResultsSink -> TcResultsSink

/// Indicates if we only need one result or all possible results from a resolution.
[<RequireQualifiedAccess>]
type ResultCollectionSettings =
| AllResults
| AtMostOneResult

/// Temporarily redirect reporting of name resolution and type checking results
val internal WithNewTypecheckResultsSink : ITypecheckResultsSink * TcResultsSink -> System.IDisposable

Expand All @@ -398,13 +404,13 @@ val internal CallExprHasTypeSink : TcResultsSink -> range * NameResolutio
val internal CallOpenDeclarationSink : TcResultsSink -> OpenDeclaration -> unit

/// Get all the available properties of a type (both intrinsic and extension)
val internal AllPropInfosOfTypeInScope : InfoReader -> NameResolutionEnv -> string option * AccessorDomain -> FindMemberFlag -> range -> TType -> PropInfo list
val internal AllPropInfosOfTypeInScope : ResultCollectionSettings -> InfoReader -> NameResolutionEnv -> string option -> AccessorDomain -> FindMemberFlag -> range -> TType -> PropInfo list

/// Get all the available properties of a type (only extension)
val internal ExtensionPropInfosOfTypeInScope : InfoReader -> NameResolutionEnv -> string option * AccessorDomain -> range -> TType -> PropInfo list
val internal ExtensionPropInfosOfTypeInScope : ResultCollectionSettings -> InfoReader -> NameResolutionEnv -> string option -> AccessorDomain -> range -> TType -> PropInfo list

/// Get the available methods of a type (both declared and inherited)
val internal AllMethInfosOfTypeInScope : InfoReader -> NameResolutionEnv -> string option * AccessorDomain -> FindMemberFlag -> range -> TType -> MethInfo list
val internal AllMethInfosOfTypeInScope : ResultCollectionSettings -> InfoReader -> NameResolutionEnv -> string option -> AccessorDomain -> FindMemberFlag -> range -> TType -> MethInfo list

/// Used to report an error condition where name resolution failed due to an indeterminate type
exception internal IndeterminateType of range
Expand Down Expand Up @@ -437,12 +443,6 @@ type PermitDirectReferenceToGeneratedType =
| Yes
| No

/// Indicates if we only need one result or all possible results from a resolution.
[<RequireQualifiedAccess>]
type ResultCollectionSettings =
| AllResults
| AtMostOneResult

/// Resolve a long identifier to a namespace or module.
val internal ResolveLongIndentAsModuleOrNamespace : TcResultsSink -> ResultCollectionSettings -> Import.ImportMap -> range -> FullyQualifiedFlag -> NameResolutionEnv -> AccessorDomain -> Ident list -> isOpenDecl: bool -> ResultOrException<(int * ModuleOrNamespaceRef * ModuleOrNamespaceType) list >

Expand Down
Loading

0 comments on commit 6a92131

Please sign in to comment.