Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit37fc87c

Browse files
vasily-kirichenkoTIHan
authored andcommitted
Notify nameresenv about partially checked namespaces or modules (#4012)
* notify nameresenv about partially checked namespaces or modules* notify nenv about partially checked namespaces in qualified type hints* update tests* fix a test* filter out module or namespace uses duplicates from captured nres* use range instead of end pos for better hashing* do not simplify open statements (refixed)
1 parent1d5a782 commit37fc87c

File tree

6 files changed

+240
-226
lines changed

6 files changed

+240
-226
lines changed

‎src/fsharp/NameResolution.fs‎

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,11 +1478,19 @@ type TcResultsSinkImpl(g, ?source: string) =
14781478
letcapturedExprTypings= ResizeArray<_>()
14791479
letcapturedNameResolutions= ResizeArray<_>()
14801480
letcapturedFormatSpecifierLocations= ResizeArray<_>()
1481+
14811482
letcapturedNameResolutionIdentifiers=
14821483
new System.Collections.Generic.HashSet<pos* string>
14831484
({new IEqualityComparer<_>with
14841485
member__.GetHashCode((p:pos,i))= p.Line+101* p.Column+ hash i
14851486
member__.Equals((p1,i1),(p2,i2))= posEq p1 p2&& i1= i2})
1487+
1488+
letcapturedModulesAndNamespaces=
1489+
new System.Collections.Generic.HashSet<range* Item>
1490+
({new IEqualityComparer<range* Item>with
1491+
member__.GetHashCode((m,_))= hash m
1492+
member__.Equals((m1, item1),(m2, item2))= m1= m2&& ItemsAreEffectivelyEqual g item1 item2})
1493+
14861494
letcapturedMethodGroupResolutions= ResizeArray<_>()
14871495
letcapturedOpenDeclarations= ResizeArray<_>()
14881496
letallowedRange(m:range)=not m.IsSynthetic
@@ -1508,25 +1516,29 @@ type TcResultsSinkImpl(g, ?source: string) =
15081516
// Desugaring some F# constructs (notably computation expressions with custom operators)
15091517
// results in duplication of textual variables. So we ensure we never record two name resolutions
15101518
// for the same identifier at the same location.
1511-
if allowedRange mthen
1512-
letkeyOpt=
1513-
match itemwith
1514-
| Item.Value vref-> Some(endPos, vref.DisplayName)
1515-
| Item.ArgName(id,_,_)-> Some(endPos, id.idText)
1516-
|_-> None
1517-
1518-
letalreadyDone=
1519-
match keyOptwith
1520-
| Some key->not(capturedNameResolutionIdentifiers.Add key)
1521-
|_->false
1522-
1519+
if allowedRange mthen
15231520
if replacethen
15241521
capturedNameResolutions.RemoveAll(fun cnr-> cnr.Range= m)|> ignore
15251522
capturedMethodGroupResolutions.RemoveAll(fun cnr-> cnr.Range= m)|> ignore
1523+
else
1524+
letalreadyDone=
1525+
match itemwith
1526+
| Item.ModuleOrNamespaces_->
1527+
not(capturedModulesAndNamespaces.Add(m, item))
1528+
|_->
1529+
letkeyOpt=
1530+
match itemwith
1531+
| Item.Value vref-> Some(endPos, vref.DisplayName)
1532+
| Item.ArgName(id,_,_)-> Some(endPos, id.idText)
1533+
|_-> None
1534+
1535+
match keyOptwith
1536+
| Some key->not(capturedNameResolutionIdentifiers.Add key)
1537+
|_->false
15261538

1527-
ifnot alreadyDonethen
1528-
capturedNameResolutions.Add(CapturedNameResolution(endPos,item,tpinst,occurenceType,denv,nenv,ad,m))
1529-
capturedMethodGroupResolutions.Add(CapturedNameResolution(endPos,itemMethodGroup,[],occurenceType,denv,nenv,ad,m))
1539+
ifnot alreadyDonethen
1540+
capturedNameResolutions.Add(CapturedNameResolution(endPos,item,tpinst,occurenceType,denv,nenv,ad,m))
1541+
capturedMethodGroupResolutions.Add(CapturedNameResolution(endPos,itemMethodGroup,[],occurenceType,denv,nenv,ad,m))
15301542

15311543
membersink.NotifyFormatSpecifierLocation(m,numArgs)=
15321544
capturedFormatSpecifierLocations.Add((m, numArgs))
@@ -1747,15 +1759,15 @@ let CheckForTypeLegitimacyAndMultipleGenericTypeAmbiguities
17471759
//-------------------------------------------------------------------------
17481760

17491761
/// Perform name resolution for an identifier which must resolve to be a namespace or module.
1750-
let recResolveLongIndentAsModuleOrNamespace atMostOne amap m fullyQualified(nenv:NameResolutionEnv)ad(lid:Ident list)=
1762+
let recResolveLongIndentAsModuleOrNamespacesinkatMostOne amap m fullyQualified(nenv:NameResolutionEnv)ad(lid:Ident list)isOpenDecl=
17511763
match lidwith
17521764
|[]-> NoResultsOrUsefulErrors
17531765

17541766
| id:: restwhen id.idText= MangledGlobalName->
17551767
if isNil restthen
17561768
error(Error(FSComp.SR.nrGlobalUsedOnlyAsFirstName(), id.idRange))
17571769
else
1758-
ResolveLongIndentAsModuleOrNamespace atMostOne amap m FullyQualified nenv ad rest
1770+
ResolveLongIndentAsModuleOrNamespacesinkatMostOne amap m FullyQualified nenv ad rest isOpenDecl
17591771

17601772
| id:: rest->
17611773
letmoduleOrNamespaces= nenv.ModulesAndNamespaces fullyQualified
@@ -1784,6 +1796,11 @@ let rec ResolveLongIndentAsModuleOrNamespace atMostOne amap m fullyQualified (ne
17841796
moduleNotFoundErrorCache<- Some(id.idRange, error)
17851797
error
17861798

1799+
letnotifyNameResolution(modref:ModuleOrNamespaceRef)m=
1800+
letitem= Item.ModuleOrNamespaces[modref]
1801+
letoccurence=if isOpenDeclthen ItemOccurence.Openelse ItemOccurence.Use
1802+
CallNameResolutionSink sink(m, nenv, item, item, emptyTyparInst, occurence, nenv.DisplayEnv, ad)
1803+
17871804
match moduleOrNamespaces.TryFind id.idTextwith
17881805
| Some modrefs->
17891806
/// Look through the sub-namespaces and/or modules
@@ -1795,24 +1812,27 @@ let rec ResolveLongIndentAsModuleOrNamespace atMostOne amap m fullyQualified (ne
17951812
| Some mspec->
17961813
letsubref= modref.NestedTyconRef mspec
17971814
if IsEntityAccessible amap m ad subrefthen
1815+
notifyNameResolution subref id.idRange
17981816
look(depth+1) subref mspec.ModuleOrNamespaceType rest
17991817
else
18001818
moduleNotFound modref mty id depth
18011819
|_-> moduleNotFound modref mty id depth
18021820

1821+
18031822
modrefs|> CollectResults2 atMostOne(fun modref->
1804-
if IsEntityAccessible amap m ad modrefthen
1823+
if IsEntityAccessible amap m ad modrefthen
1824+
notifyNameResolution modref id.idRange
18051825
look1 modref modref.ModuleOrNamespaceType rest
18061826
else
18071827
raze(namespaceNotFound.Force()))
18081828
| None-> raze(namespaceNotFound.Force())
18091829

18101830

1811-
letResolveLongIndentAsModuleOrNamespaceThen atMostOne amap m fullyQualified(nenv:NameResolutionEnv)ad lid f=
1831+
letResolveLongIndentAsModuleOrNamespaceThensinkatMostOne amap m fullyQualified(nenv:NameResolutionEnv)ad lid isOpenDecl f=
18121832
match lidwith
18131833
|[]-> NoResultsOrUsefulErrors
18141834
| id:: rest->
1815-
match ResolveLongIndentAsModuleOrNamespace ResultCollectionSettings.AllResults amap m fullyQualified nenv ad[id]with
1835+
match ResolveLongIndentAsModuleOrNamespacesinkResultCollectionSettings.AllResults amap m fullyQualified nenv ad[id] isOpenDeclwith
18161836
| Result modrefs->
18171837
modrefs|> CollectResults2 atMostOne(fun(depth,modref,mty)->
18181838
letresInfo= ResolutionInfo.Empty.AddEntity(id.idRange,modref)
@@ -2315,7 +2335,7 @@ let ChooseTyconRefInExpr (ncenv:NameResolver, m, ad, nenv, id:Ident, typeNameRes
23152335
/// Resolve F# "A.B.C" syntax in expressions
23162336
/// Not all of the sequence will necessarily be swallowed, i.e. we return some identifiers
23172337
/// that may represent further actions, e.g. further lookups.
2318-
let recResolveExprLongIdentPrim sink(ncenv:NameResolver)fullyQualified m ad nenv(typeNameResInfo:TypeNameResolutionInfo)lid=
2338+
let recResolveExprLongIdentPrim sink(ncenv:NameResolver)fullyQualified m ad nenv(typeNameResInfo:TypeNameResolutionInfo)lidisOpenDecl=
23192339
letresInfo= ResolutionInfo.Empty
23202340
match lidwith
23212341
|[]-> error(Error(FSComp.SR.nrInvalidExpression(textOfLid lid), m))
@@ -2324,10 +2344,10 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) fullyQualified m ad n
23242344
error(Error(FSComp.SR.nrGlobalUsedOnlyAsFirstName(), id.idRange))
23252345

23262346
|[id;next]when id.idText= MangledGlobalName->
2327-
ResolveExprLongIdentPrim sink ncenv fullyQualified m ad nenv typeNameResInfo[next]
2347+
ResolveExprLongIdentPrim sink ncenv fullyQualified m ad nenv typeNameResInfo[next] isOpenDecl
23282348

23292349
| id:: lidwhen id.idText= MangledGlobalName->
2330-
ResolveExprLongIdentPrim sink ncenv FullyQualified m ad nenv typeNameResInfo lid
2350+
ResolveExprLongIdentPrim sink ncenv FullyQualified m ad nenv typeNameResInfo lid isOpenDecl
23312351

23322352
|[id]when fullyQualified<> FullyQualified->
23332353
lettypeError= ref None
@@ -2452,7 +2472,7 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) fullyQualified m ad n
24522472
// Otherwise modules are searched first. REVIEW: modules and types should be searched together.
24532473
// For each module referenced by 'id', search the module as if it were an F# module and/or a .NET namespace.
24542474
letmoduleSearch ad=
2455-
ResolveLongIndentAsModuleOrNamespaceThen ResultCollectionSettings.AtMostOneResult ncenv.amap m fullyQualified nenv ad lid
2475+
ResolveLongIndentAsModuleOrNamespaceThensinkResultCollectionSettings.AtMostOneResult ncenv.amap m fullyQualified nenv ad lidisOpenDecl
24562476
(ResolveExprLongIdentInModuleOrNamespace ncenv nenv typeNameResInfo ad)
24572477

24582478
// REVIEW: somewhat surprisingly, this shows up on performance traces, with tcrefs non-nil.
@@ -2544,7 +2564,7 @@ let rec ResolveExprLongIdentPrim sink (ncenv:NameResolver) fullyQualified m ad n
25442564
item,rest
25452565

25462566
letResolveExprLongIdent sink(ncenv:NameResolver)m ad nenv typeNameResInfo lid=
2547-
ResolveExprLongIdentPrim sink ncenv OpenQualified m ad nenv typeNameResInfo lid
2567+
ResolveExprLongIdentPrim sink ncenv OpenQualified m ad nenv typeNameResInfo lidfalse
25482568

25492569
//-------------------------------------------------------------------------
25502570
// Resolve F#/IL "." syntax in patterns
@@ -2673,7 +2693,7 @@ let rec ResolvePatternLongIdentPrim sink (ncenv:NameResolver) fullyQualified war
26732693
// Long identifiers in patterns
26742694
|_->
26752695
letmoduleSearch ad=
2676-
ResolveLongIndentAsModuleOrNamespaceThen ResultCollectionSettings.AtMostOneResult ncenv.amap m fullyQualified nenv ad lid
2696+
ResolveLongIndentAsModuleOrNamespaceThensinkResultCollectionSettings.AtMostOneResult ncenv.amap m fullyQualified nenv ad lidfalse
26772697
(ResolvePatternLongIdentInModuleOrNamespace ncenv nenv numTyArgsOpt ad)
26782698
lettyconSearch ad=
26792699
match lidwith
@@ -2783,7 +2803,7 @@ let SuggestTypeLongIdentInModuleOrNamespace depth (modref:ModuleOrNamespaceRef)
27832803
UndefinedName(depth,errorTextF,id,suggestPossibleTypes)
27842804

27852805
/// Resolve a long identifier representing a type in a module or namespace
2786-
let recprivateResolveTypeLongIdentInModuleOrNamespace(ncenv:NameResolver)(typeNameResInfo:TypeNameResolutionInfo)ad genOk(resInfo:ResolutionInfo)depth m modref _mty(lid:Ident list)=
2806+
let recprivateResolveTypeLongIdentInModuleOrNamespacesink nenv(ncenv:NameResolver)(typeNameResInfo:TypeNameResolutionInfo)ad genOk(resInfo:ResolutionInfo)depth m modref _mty(lid:Ident list)=
27872807
match lidwith
27882808
|[]-> error(Error(FSComp.SR.nrUnexpectedEmptyLongId(),m))
27892809
|[id]->
@@ -2797,8 +2817,10 @@ let rec private ResolveTypeLongIdentInModuleOrNamespace (ncenv:NameResolver) (ty
27972817
letmodulSearch=
27982818
match modref.ModuleOrNamespaceType.ModulesAndNamespacesByDemangledName.TryFind(id.idText)with
27992819
| Some(AccessibleEntityRef ncenv.amap m ad modref submodref)->
2820+
letitem= Item.ModuleOrNamespaces[submodref]
2821+
CallNameResolutionSink sink(id.idRange, nenv, item, item, emptyTyparInst, ItemOccurence.Use, nenv.DisplayEnv, ad)
28002822
letresInfo= resInfo.AddEntity(id.idRange,submodref)
2801-
ResolveTypeLongIdentInModuleOrNamespace ncenv typeNameResInfo ad genOk resInfo(depth+1) m submodref submodref.ModuleOrNamespaceType rest
2823+
ResolveTypeLongIdentInModuleOrNamespacesink nenvncenv typeNameResInfo ad genOk resInfo(depth+1) m submodref submodref.ModuleOrNamespaceType rest
28022824
|_->
28032825
letsuggestPossibleModules()=
28042826
modref.ModuleOrNamespaceType.ModulesAndNamespacesByDemangledName
@@ -2821,7 +2843,7 @@ let rec private ResolveTypeLongIdentInModuleOrNamespace (ncenv:NameResolver) (ty
28212843
tyconSearch+++ modulSearch
28222844

28232845
/// Resolve a long identifier representing a type
2824-
let recResolveTypeLongIdentPrim(ncenv:NameResolver)occurence fullyQualified m nenv ad(lid:Ident list)(staticResInfo:TypeNameResolutionStaticArgsInfo)genOk=
2846+
let recResolveTypeLongIdentPrimsink(ncenv:NameResolver)occurence fullyQualified m nenv ad(lid:Ident list)(staticResInfo:TypeNameResolutionStaticArgsInfo)genOk=
28252847
lettypeNameResInfo= TypeNameResolutionInfo.ResolveToTypeRefs staticResInfo
28262848
match lidwith
28272849
|[]-> error(Error(FSComp.SR.nrUnexpectedEmptyLongId(),m))
@@ -2830,7 +2852,7 @@ let rec ResolveTypeLongIdentPrim (ncenv:NameResolver) occurence fullyQualified m
28302852
error(Error(FSComp.SR.nrGlobalUsedOnlyAsFirstName(), id.idRange))
28312853

28322854
| id:: lidwhen id.idText= MangledGlobalName->
2833-
ResolveTypeLongIdentPrim ncenv occurence FullyQualified m nenv ad lid staticResInfo genOk
2855+
ResolveTypeLongIdentPrimsinkncenv occurence FullyQualified m nenv ad lid staticResInfo genOk
28342856

28352857
|[id]->
28362858
match LookupTypeNameInEnvHaveArity fullyQualified id.idText staticResInfo.NumStaticArgs nenvwith
@@ -2876,13 +2898,13 @@ let rec ResolveTypeLongIdentPrim (ncenv:NameResolver) occurence fullyQualified m
28762898
NoResultsOrUsefulErrors
28772899

28782900
letmodulSearch=
2879-
ResolveLongIndentAsModuleOrNamespaceThen ResultCollectionSettings.AllResults ncenv.amap m fullyQualified nenv ad lid
2880-
(ResolveTypeLongIdentInModuleOrNamespace ncenv typeNameResInfo ad genOk)
2901+
ResolveLongIndentAsModuleOrNamespaceThensinkResultCollectionSettings.AllResults ncenv.amap m fullyQualified nenv ad lidfalse
2902+
(ResolveTypeLongIdentInModuleOrNamespacesink nenvncenv typeNameResInfo ad genOk)
28812903
|?> List.concat
28822904

28832905
letmodulSearchFailed()=
2884-
ResolveLongIndentAsModuleOrNamespaceThen ResultCollectionSettings.AllResults ncenv.amap m fullyQualified nenv AccessibleFromSomeFSharpCode lid
2885-
(ResolveTypeLongIdentInModuleOrNamespace ncenv typeNameResInfo.DropStaticArgsInfo AccessibleFromSomeFSharpCode genOk)
2906+
ResolveLongIndentAsModuleOrNamespaceThensinkResultCollectionSettings.AllResults ncenv.amap m fullyQualified nenv AccessibleFromSomeFSharpCode lidfalse
2907+
(ResolveTypeLongIdentInModuleOrNamespacesink nenvncenv typeNameResInfo.DropStaticArgsInfo AccessibleFromSomeFSharpCode genOk)
28862908
|?> List.concat
28872909

28882910
letsearchSoFar= tyconSearch+++ modulSearch
@@ -2908,7 +2930,7 @@ let rec ResolveTypeLongIdentPrim (ncenv:NameResolver) occurence fullyQualified m
29082930
/// Resolve a long identifier representing a type and report it
29092931
letResolveTypeLongIdent sink(ncenv:NameResolver)occurence fullyQualified nenv ad(lid:Ident list)staticResInfo genOk=
29102932
letm= rangeOfLid lid
2911-
letres= ResolveTypeLongIdentPrim ncenv occurence fullyQualified m nenv ad lid staticResInfo genOk
2933+
letres= ResolveTypeLongIdentPrimsinkncenv occurence fullyQualified m nenv ad lid staticResInfo genOk
29122934
// Register the result as a name resolution
29132935
match reswith
29142936
| Result(resInfo,tcref)->
@@ -3037,7 +3059,7 @@ let SuggestLabelsOfRelatedRecords g (nenv:NameResolutionEnv) (id:Ident) (allFiel
30373059
UndefinedName(0,FSComp.SR.undefinedNameRecordLabel, id, suggestLabels)
30383060

30393061
/// Resolve a long identifier representing a record field
3040-
letResolveFieldPrim(ncenv:NameResolver)nenv ad typ(mp,id:Ident)allFields=
3062+
letResolveFieldPrimsink(ncenv:NameResolver)nenv ad typ(mp,id:Ident)allFields=
30413063
lettypeNameResInfo= TypeNameResolutionInfo.Default
30423064
letg= ncenv.g
30433065
letm= id.idRange
@@ -3085,7 +3107,7 @@ let ResolveFieldPrim (ncenv:NameResolver) nenv ad typ (mp,id:Ident) allFields =
30853107
|_-> NoResultsOrUsefulErrors
30863108

30873109
letmodulSearch ad=
3088-
ResolveLongIndentAsModuleOrNamespaceThen ResultCollectionSettings.AtMostOneResult ncenv.amap m OpenQualified nenv ad lid
3110+
ResolveLongIndentAsModuleOrNamespaceThensinkResultCollectionSettings.AtMostOneResult ncenv.amap m OpenQualified nenv ad lidfalse
30893111
(ResolveFieldInModuleOrNamespace ncenv nenv ad)
30903112

30913113
letsearch=
@@ -3118,7 +3140,7 @@ let ResolveFieldPrim (ncenv:NameResolver) nenv ad typ (mp,id:Ident) allFields =
31183140
[(resInfo,item)]
31193141

31203142
letResolveField sink ncenv nenv ad typ(mp,id)allFields=
3121-
letres= ResolveFieldPrim ncenv nenv ad typ(mp,id) allFields
3143+
letres= ResolveFieldPrimsinkncenv nenv ad typ(mp,id) allFields
31223144
// Register the results of any field paths "Module.Type" in "Module.Type.field" as a name resolution. (Note, the path resolution
31233145
// info is only non-empty if there was a unique resolution of the field)
31243146
letchecker= ResultTyparChecker(fun()->true)

‎src/fsharp/NameResolution.fsi‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ type ResultCollectionSettings =
444444
| AtMostOneResult
445445

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

449449
/// Resolve a long identifier to an object constructor.
450450
valinternalResolveObjectConstructor:NameResolver->DisplayEnv->range->AccessorDomain->TType->ResultOrException<Item>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp