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

Commit6efa3b3

Browse files
vasily-kirichenkoKevinRansom
authored andcommitted
Optimize simplify name analyzer (dotnet#2254)
* remove unnecessary filtering and deduplication* write lazy early return functions for SimplifyName analyzer* make the rest of nr lazyadd cache* fix cache locking* do not try to resolve ctors for non-ctor Item* more lazyness to NameResolution* optimize GetBestEnvForPos by indexing nameres environments (scopes) by line number* look for best resolution env on previous line as well* Reformat ResolveObjectConstructorPrim* remove double hash table lookup in NotifyNameResolution* make CurrentSink non-optional* eliminate a list creation* renaming* optimize ValRef* small optimizations* make Ident a struct* add MaybeLazy* SimplifyNameDiagnosticAnalyzer should do semantic analysis, not syntax one* remove dead code* fix after merge* Revert "make CurrentSink non-optional"This reverts commita2f791d.# Conflicts:#src/fsharp/TypeChecker.fs* Revert "optimize GetBestEnvForPos by indexing nameres environments (scopes) by line number"This reverts commitc8edcc3.# Conflicts:#src/fsharp/vs/service.fs#src/fsharp/vs/service.fsi* turn off SimplifyNameDiagnosticAnalyzer for now
1 parent7755f90 commit6efa3b3

File tree

13 files changed

+580
-161
lines changed

13 files changed

+580
-161
lines changed

‎src/fsharp/CompileOps.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3957,7 +3957,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
39573957
| None->
39583958
// Build up the artificial namespace if there is not a real one.
39593959
letcpath= CompPath(ILScopeRef.Local, injectedNamspace|> List.rev|> List.map(fun n->(n,ModuleOrNamespaceKind.Namespace)))
3960-
letnewNamespace= NewModuleOrNamespace(Some cpath) taccessPublic(ident(next,rangeStartup)) XmlDoc.Empty[](notlazy(NewEmptyModuleOrNamespaceType Namespace))
3960+
letnewNamespace= NewModuleOrNamespace(Some cpath) taccessPublic(ident(next,rangeStartup)) XmlDoc.Empty[](MaybeLazy.Strict(NewEmptyModuleOrNamespaceType Namespace))
39613961
entity.ModuleOrNamespaceType.AddModuleOrNamespaceByMutation(newNamespace)
39623962
tcImports.InjectProvidedNamespaceOrTypeIntoEntity(typeProviderEnvironment, tcConfig, m, newNamespace, next::injectedNamspace, rest, provider, st)
39633963
|[]->

‎src/fsharp/NameResolution.fs‎

Lines changed: 430 additions & 29 deletions
Large diffs are not rendered by default.

‎src/fsharp/NameResolution.fsi‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,5 @@ type ResolveCompletionTargets =
418418
/// Resolve a (possibly incomplete) long identifier to a set of possible resolutions, qualified by type.
419419
valResolveCompletionsInType:NameResolver->NameResolutionEnv->ResolveCompletionTargets->Range.range->AccessorDomain->bool->TType->Item list
420420

421-
valGetVisibleNamespacesAndModulesAtPoint:NameResolver->NameResolutionEnv->range->AccessorDomain->ModuleOrNamespaceRef list
421+
422+
valIsItemResolvable:NameResolver->NameResolutionEnv->range->AccessorDomain->string list->Item->bool

‎src/fsharp/Optimizer.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3087,7 +3087,7 @@ and OptimizeModuleExpr cenv env x =
30873087
mty
30883088
andelimModSpec(mspec:ModuleOrNamespace)=
30893089
letmtyp= elimModTy mspec.ModuleOrNamespaceType
3090-
mspec.Data.entity_modul_contents<-notlazy mtyp
3090+
mspec.Data.entity_modul_contents<-MaybeLazy.Strict mtyp
30913091

30923092
let recelimModDef x=
30933093
match xwith

‎src/fsharp/TastOps.fs‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ let ensureCcuHasModuleOrNamespaceAtPath (ccu:CcuThunk) path (CompPath(_,cpath))
980980
|(hpath::tpath),((_,mkind)::tcpath)->
981981
letmodName= hpath.idText
982982
ifnot(Map.containsKey modName mtype.AllEntitiesByCompiledAndLogicalMangledNames)then
983-
letsmodul= NewModuleOrNamespace(Some(CompPath(scoref,prior_cpath))) taccessPublic hpath xml[](notlazy(NewEmptyModuleOrNamespaceType mkind))
983+
letsmodul= NewModuleOrNamespace(Some(CompPath(scoref,prior_cpath))) taccessPublic hpath xml[](MaybeLazy.Strict(NewEmptyModuleOrNamespaceType mkind))
984984
mtype.AddModuleOrNamespaceByMutation(smodul);
985985
letmodul= Map.find modName mtype.AllEntitiesByCompiledAndLogicalMangledNames
986986
loop(prior_cpath@[(modName,Namespace)]) tpath tcpath modul
@@ -3566,7 +3566,7 @@ end
35663566
//--------------------------------------------------------------------------
35673567

35683568
letwrapModuleOrNamespaceType id cpath mtyp=
3569-
NewModuleOrNamespace(Some cpath) taccessPublic id XmlDoc.Empty[](notlazy mtyp)
3569+
NewModuleOrNamespace(Some cpath) taccessPublic id XmlDoc.Empty[](MaybeLazy.Strict mtyp)
35703570

35713571
letwrapModuleOrNamespaceTypeInNamespace id cpath mtyp=
35723572
letmspec= wrapModuleOrNamespaceType id cpath mtyp
@@ -4972,9 +4972,8 @@ and copyAndRemapAndBindTyconsAndVals g compgen tmenv tycons vs =
49724972
tcd'.entity_tycon_repr<- tcd.entity_tycon_repr|> remapTyconRepr g tmenvinner2;
49734973
tcd'.entity_tycon_abbrev<- tcd.entity_tycon_abbrev|> Option.map(remapType tmenvinner2);
49744974
tcd'.entity_tycon_tcaug<- tcd.entity_tycon_tcaug|> remapTyconAug tmenvinner2;
4975-
tcd'.entity_modul_contents<- notlazy(tcd.entity_modul_contents
4976-
|> Lazy.force
4977-
|> mapImmediateValsAndTycons lookupTycon lookupVal);
4975+
tcd'.entity_modul_contents<- MaybeLazy.Strict(tcd.entity_modul_contents.Value
4976+
|> mapImmediateValsAndTycons lookupTycon lookupVal);
49784977
tcd'.entity_exn_info<- tcd.entity_exn_info|> remapTyconExnInfo g tmenvinner2);
49794978
tycons',vs', tmenvinner
49804979

@@ -7637,10 +7636,8 @@ let rec remapEntityDataToNonLocal g tmenv (d: EntityData) =
76377636
entity_tycon_abbrev= d.entity_tycon_abbrev|> Option.map(remapType tmenvinner);
76387637
entity_tycon_tcaug= d.entity_tycon_tcaug|> remapTyconAug tmenvinner;
76397638
entity_modul_contents=
7640-
notlazy(d.entity_modul_contents
7641-
|> Lazy.force
7642-
|> mapImmediateValsAndTycons(remapTyconToNonLocal g tmenv)
7643-
(remapValToNonLocal g tmenv));
7639+
MaybeLazy.Strict(d.entity_modul_contents.Value
7640+
|> mapImmediateValsAndTycons(remapTyconToNonLocal g tmenv)(remapValToNonLocal g tmenv));
76447641
entity_exn_info= d.entity_exn_info|> remapTyconExnInfo g tmenvinner}
76457642

76467643
andremapTyconToNonLocal g tmenv x=

‎src/fsharp/TastPickle.fs‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,7 @@ let p_option f x st =
436436
// Pickle lazy values in such a way that they can, in some future F# compiler version, be read back
437437
// lazily. However, a lazy reader is not used in this version because the value may contain the definitions of some
438438
// OSGN nodes.
439-
letp_lazy p x st=
440-
letv= Lazy.force x
439+
letprivatep_lazy_impl p v st=
441440
letfixupPos1= st.os.Position
442441
// We fix these up after
443442
prim_p_int320 st;
@@ -473,6 +472,12 @@ let p_lazy p x st =
473472
st.os.FixupInt32 fixupPos6 ovalsIdx1;
474473
st.os.FixupInt32 fixupPos7 ovalsIdx2
475474

475+
letp_lazy p x st=
476+
p_lazy_impl p(Lazy.force x) st
477+
478+
letp_maybe_lazy p(x:MaybeLazy<_>)st=
479+
p_lazy_impl p x.Value st
480+
476481
letp_hole()=
477482
leth= ref(None: 'T pickler option)
478483
(fun f-> h:= Some f),(fun x st->match!hwith Some f-> f x st| None-> pfailwith st"p_hole: unfilled hole")
@@ -1727,7 +1732,7 @@ and p_entity_spec_data (x:EntityData) st =
17271732
p_kind x.entity_kind st
17281733
p_int64(x.entity_flags.PickledBits|||(if flagBitthen EntityFlags.ReservedBitForPickleFormatTyconReprFlagelse0L)) st
17291734
p_option p_cpath x.entity_cpath st
1730-
p_lazy p_modul_typ x.entity_modul_contents st
1735+
p_maybe_lazy p_modul_typ x.entity_modul_contents st
17311736
p_exnc_repr x.entity_exn_info st
17321737
p_space1 space st
17331738

@@ -2012,7 +2017,7 @@ and u_entity_spec_data st : EntityData =
20122017
entity_kind=x10b;
20132018
entity_flags=EntityFlags(x11);
20142019
entity_cpath=x12;
2015-
entity_modul_contents= x13;
2020+
entity_modul_contents=MaybeLazy.Lazy x13;
20162021
entity_exn_info=x14;
20172022
entity_il_repr_cache=newCache();
20182023
}

‎src/fsharp/TypeChecker.fs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ let UpdateAccModuleOrNamespaceType cenv env f =
13151315
if cenv.compilingCanonicalFslibModuleType then
13161316
let nleref = mkNonLocalEntityRef cenv.topCcu (arrPathOfLid env.ePath)
13171317
let modul = nleref.Deref
1318-
modul.Data.entity_modul_contents <-notlazy (f true modul.ModuleOrNamespaceType)
1318+
modul.Data.entity_modul_contents <-MaybeLazy.Strict (f true modul.ModuleOrNamespaceType)
13191319
SetCurrAccumulatedModuleOrNamespaceType env (f false (GetCurrAccumulatedModuleOrNamespaceType env))
13201320

13211321
let PublishModuleDefn cenv env mspec =
@@ -13385,13 +13385,13 @@ module MutRecBindingChecking =
1338513385
let TcMutRecDefns_UpdateNSContents mutRecNSInfo =
1338613386
match mutRecNSInfo with
1338713387
| Some (Some (mspecNS: ModuleOrNamespace), mtypeAcc) ->
13388-
mspecNS.Data.entity_modul_contents <-notlazy !mtypeAcc
13388+
mspecNS.Data.entity_modul_contents <-MaybeLazy.Strict !mtypeAcc
1338913389
| _ -> ()
1339013390

1339113391
/// Updates the types of the modules to contain the contents so far
1339213392
let TcMutRecDefns_UpdateModuleContents mutRecNSInfo defns =
1339313393
defns |> MutRecShapes.iterModules (fun (MutRecDefnsPhase2DataForModule (mtypeAcc, mspec), _) ->
13394-
mspec.Data.entity_modul_contents <-notlazy !mtypeAcc)
13394+
mspec.Data.entity_modul_contents <-MaybeLazy.Strict !mtypeAcc)
1339513395

1339613396
TcMutRecDefns_UpdateNSContents mutRecNSInfo
1339713397

@@ -14344,7 +14344,7 @@ module EstablishTypeDefinitionCores =
1434414344
CheckNamespaceModuleOrTypeName cenv.g id
1434514345

1434614346
let envForDecls, mtypeAcc = MakeInnerEnv envInitial id modKind
14347-
let mspec = NewModuleOrNamespace (Some envInitial.eCompPath) vis id (xml.ToXmlDoc()) modAttrs (notlazy (NewEmptyModuleOrNamespaceType modKind))
14347+
let mspec = NewModuleOrNamespace (Some envInitial.eCompPath) vis id (xml.ToXmlDoc()) modAttrs (MaybeLazy.Strict (NewEmptyModuleOrNamespaceType modKind))
1434814348
let innerParent = Parent (mkLocalModRef mspec)
1434914349
let typeNames = TypeNamesInMutRecDecls compDecls
1435014350
MutRecDefnsPhase2DataForModule (mtypeAcc, mspec), (innerParent, typeNames, envForDecls)
@@ -14385,7 +14385,7 @@ module EstablishTypeDefinitionCores =
1438514385
let visOfRepr,_ = ComputeAccessAndCompPath env None id.idRange synVisOfRepr None parent
1438614386
let visOfRepr = combineAccess vis visOfRepr
1438714387
// If we supported nested types and modules then additions would be needed here
14388-
let lmtyp =notlazy (NewEmptyModuleOrNamespaceType ModuleOrType)
14388+
let lmtyp =MaybeLazy.Strict (NewEmptyModuleOrNamespaceType ModuleOrType)
1438914389

1439014390
NewTycon(cpath, id.idText, id.idRange, vis, visOfRepr, TyparKind.Type, LazyWithContext.NotLazy checkedTypars, doc.ToXmlDoc(), preferPostfix, preEstablishedHasDefaultCtor, hasSelfReferentialCtor, lmtyp)
1439114391

@@ -16101,11 +16101,11 @@ let rec TcSignatureElementNonMutRec cenv parent typeNames endm (env: TcEnv) synS
1610116101
// Now typecheck the signature, accumulating and then recording the submodule description.
1610216102
let id = ident (modName, id.idRange)
1610316103

16104-
let mspec = NewModuleOrNamespace (Some env.eCompPath) vis id (xml.ToXmlDoc()) attribs (notlazy (NewEmptyModuleOrNamespaceType modKind))
16104+
let mspec = NewModuleOrNamespace (Some env.eCompPath) vis id (xml.ToXmlDoc()) attribs (MaybeLazy.Strict (NewEmptyModuleOrNamespaceType modKind))
1610516105

1610616106
let! (mtyp,_) = TcModuleOrNamespaceSignatureElementsNonMutRec cenv (Parent (mkLocalModRef mspec)) env (id,modKind,mdefs,m,xml)
1610716107

16108-
mspec.Data.entity_modul_contents <-notlazy mtyp
16108+
mspec.Data.entity_modul_contents <-MaybeLazy.Strict mtyp
1610916109
let scopem = unionRanges m endm
1611016110
PublishModuleDefn cenv env mspec
1611116111
let env = AddLocalSubModuleAndReport cenv.tcSink scopem cenv.g cenv.amap m env mspec
@@ -16421,13 +16421,13 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv:cenv) parent typeNames scopem
1642116421

1642216422
// Create the new module specification to hold the accumulated results of the type of the module
1642316423
// Also record this in the environment as the accumulator
16424-
let mspec = NewModuleOrNamespace (Some env.eCompPath) vis id (xml.ToXmlDoc()) modAttrs (notlazy (NewEmptyModuleOrNamespaceType modKind))
16424+
let mspec = NewModuleOrNamespace (Some env.eCompPath) vis id (xml.ToXmlDoc()) modAttrs (MaybeLazy.Strict (NewEmptyModuleOrNamespaceType modKind))
1642516425

1642616426
// Now typecheck.
1642716427
let! mexpr, topAttrsNew, envAtEnd = TcModuleOrNamespaceElements cenv (Parent (mkLocalModRef mspec)) endm envForModule xml None mdefs
1642816428

1642916429
// Get the inferred type of the decls and record it in the mspec.
16430-
mspec.Data.entity_modul_contents <-notlazy !mtypeAcc
16430+
mspec.Data.entity_modul_contents <-MaybeLazy.Strict !mtypeAcc
1643116431
let modDefn = TMDefRec(false,[],[ModuleOrNamespaceBinding.Module(mspec,mexpr)],m)
1643216432
PublishModuleDefn cenv env mspec
1643316433
let env = AddLocalSubModuleAndReport cenv.tcSink scopem cenv.g cenv.amap m env mspec
@@ -16614,7 +16614,7 @@ and TcMutRecDefsFinish cenv defs m =
1661416614
binds |> List.map ModuleOrNamespaceBinding.Binding
1661516615
| MutRecShape.Module ((MutRecDefnsPhase2DataForModule(mtypeAcc, mspec), _),mdefs) ->
1661616616
let mexpr = TcMutRecDefsFinish cenv mdefs m
16617-
mspec.Data.entity_modul_contents <-notlazy !mtypeAcc
16617+
mspec.Data.entity_modul_contents <-MaybeLazy.Strict !mtypeAcc
1661816618
[ ModuleOrNamespaceBinding.Module(mspec,mexpr) ])
1661916619

1662016620
TMDefRec(true,tycons,binds,m)

‎src/fsharp/ast.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ type ParserDetail =
135135

136136
// PERFORMANCE: consider making this a struct.
137137
[<System.Diagnostics.DebuggerDisplay("{idText}")>]
138-
[<Sealed>]
138+
[<Struct>]
139139
[<NoEquality; NoComparison>]
140-
typeIdent(text,range)=
140+
typeIdent(text: string,range:range)=
141141
memberx.idText= text
142142
memberx.idRange= range
143143
overridex.ToString()= text

‎src/fsharp/import.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ let rec ImportILTypeDef amap m scoref (cpath:CompilationPath) enc nm (tdef:ILTyp
455455
// Make sure we reraise the original exception one occurs - see findOriginalException.
456456
(LazyWithContext.Create((fun m-> ImportILGenericParameters amap m scoref[] tdef.GenericParams), ErrorLogger.findOriginalException))
457457
(scoref,enc,tdef)
458-
lazyModuleOrNamespaceTypeForNestedTypes
458+
(MaybeLazy.Lazy lazyModuleOrNamespaceTypeForNestedTypes)
459459

460460

461461
/// Import a list of (possibly nested) IL types as a new ModuleOrNamespaceType node
@@ -474,7 +474,7 @@ and ImportILTypeDefList amap m (cpath:CompilationPath) enc items =
474474
|> multisetDiscriminateAndMap
475475
(fun n tgs->
476476
letmodty=lazy(ImportILTypeDefList amap m(cpath.NestedCompPath n Namespace) enc tgs)
477-
NewModuleOrNamespace(Some cpath) taccessPublic(mkSynId m n) XmlDoc.Empty[] modty)
477+
NewModuleOrNamespace(Some cpath) taccessPublic(mkSynId m n) XmlDoc.Empty[](MaybeLazy.Lazymodty))
478478
(fun(n,info:Lazy<_>)->
479479
let(scoref2,_,lazyTypeDef:Lazy<ILTypeDef>)= info.Force()
480480
ImportILTypeDef amap m scoref2 cpath enc n(lazyTypeDef.Force()))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp