Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b3b02b9
remove unnecessary filtering and deduplication
vasily-kirichenko Jan 14, 2017
990b01e
write lazy early return functions for SimplifyName analyzer
vasily-kirichenko Jan 14, 2017
0982b92
make the rest of nr lazy
vasily-kirichenko Jan 14, 2017
f6d4a7d
fix cache locking
vasily-kirichenko Jan 14, 2017
7eeb470
do not try to resolve ctors for non-ctor Item
vasily-kirichenko Jan 14, 2017
4fc2f9b
more lazyness to NameResolution
vasily-kirichenko Jan 14, 2017
c8edcc3
optimize GetBestEnvForPos by indexing nameres environments (scopes) b…
vasily-kirichenko Jan 14, 2017
cba5226
look for best resolution env on previous line as well
vasily-kirichenko Jan 15, 2017
c30aab1
Reformat ResolveObjectConstructorPrim
forki Jan 15, 2017
8f92284
Merge pull request #5 from forki/name-ana
vasily-kirichenko Jan 15, 2017
9d5db9a
remove double hash table lookup in NotifyNameResolution
vasily-kirichenko Jan 15, 2017
a2f791d
make CurrentSink non-optional
vasily-kirichenko Jan 15, 2017
b67938e
eliminate a list creation
vasily-kirichenko Jan 15, 2017
d9501f6
renaming
vasily-kirichenko Jan 15, 2017
0295e8e
optimize ValRef
vasily-kirichenko Jan 15, 2017
8581466
small optimizations
vasily-kirichenko Jan 15, 2017
d3c1e72
make Ident a struct
vasily-kirichenko Jan 15, 2017
e2b8b10
add MaybeLazy
vasily-kirichenko Jan 15, 2017
8cb7567
SimplifyNameDiagnosticAnalyzer should do semantic analysis, not synta…
vasily-kirichenko Jan 16, 2017
0acd7ce
Merge remote-tracking branch 'origin/master' into optimize-simplify-n…
Jan 16, 2017
fe1f967
Merge branch 'master' into optimize-simplify-name-analyzer
vasily-kirichenko Jan 21, 2017
e134de1
Merge branch 'master' into optimize-simplify-name-analyzer
vasily-kirichenko Jan 28, 2017
2e636c8
remove dead code
vasily-kirichenko Jan 28, 2017
72124d6
Merge remote-tracking branch 'origin/master' into optimize-simplify-n…
vasily-kirichenko Feb 11, 2017
f750dbb
fix after merge
vasily-kirichenko Feb 11, 2017
6887a33
Revert "make CurrentSink non-optional"
vasily-kirichenko Feb 11, 2017
69563dd
Revert "optimize GetBestEnvForPos by indexing nameres environments (s…
vasily-kirichenko Feb 11, 2017
4766680
turn off SimplifyNameDiagnosticAnalyzer for now
vasily-kirichenko Feb 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3957,7 +3957,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
| None ->
// Build up the artificial namespace if there is not a real one.
let cpath = CompPath(ILScopeRef.Local, injectedNamspace |> List.rev |> List.map (fun n -> (n,ModuleOrNamespaceKind.Namespace)) )
let newNamespace = NewModuleOrNamespace (Some cpath) taccessPublic (ident(next,rangeStartup)) XmlDoc.Empty [] (notlazy (NewEmptyModuleOrNamespaceType Namespace))
let newNamespace = NewModuleOrNamespace (Some cpath) taccessPublic (ident(next,rangeStartup)) XmlDoc.Empty [] (MaybeLazy.Strict (NewEmptyModuleOrNamespaceType Namespace))
entity.ModuleOrNamespaceType.AddModuleOrNamespaceByMutation(newNamespace)
tcImports.InjectProvidedNamespaceOrTypeIntoEntity (typeProviderEnvironment, tcConfig, m, newNamespace, next::injectedNamspace, rest, provider, st)
| [] ->
Expand Down
459 changes: 430 additions & 29 deletions src/fsharp/NameResolution.fs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/fsharp/NameResolution.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,5 @@ type ResolveCompletionTargets =
/// Resolve a (possibly incomplete) long identifier to a set of possible resolutions, qualified by type.
val ResolveCompletionsInType : NameResolver -> NameResolutionEnv -> ResolveCompletionTargets -> Range.range -> AccessorDomain -> bool -> TType -> Item list

val GetVisibleNamespacesAndModulesAtPoint : NameResolver -> NameResolutionEnv -> range -> AccessorDomain -> ModuleOrNamespaceRef list

val IsItemResolvable : NameResolver -> NameResolutionEnv -> range -> AccessorDomain -> string list -> Item -> bool
2 changes: 1 addition & 1 deletion src/fsharp/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3087,7 +3087,7 @@ and OptimizeModuleExpr cenv env x =
mty
and elimModSpec (mspec:ModuleOrNamespace) =
let mtyp = elimModTy mspec.ModuleOrNamespaceType
mspec.Data.entity_modul_contents <- notlazy mtyp
mspec.Data.entity_modul_contents <- MaybeLazy.Strict mtyp

let rec elimModDef x =
match x with
Expand Down
15 changes: 6 additions & 9 deletions src/fsharp/TastOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ let ensureCcuHasModuleOrNamespaceAtPath (ccu:CcuThunk) path (CompPath(_,cpath))
| (hpath::tpath),((_,mkind)::tcpath) ->
let modName = hpath.idText
if not (Map.containsKey modName mtype.AllEntitiesByCompiledAndLogicalMangledNames) then
let smodul = NewModuleOrNamespace (Some(CompPath(scoref,prior_cpath))) taccessPublic hpath xml [] (notlazy (NewEmptyModuleOrNamespaceType mkind))
let smodul = NewModuleOrNamespace (Some(CompPath(scoref,prior_cpath))) taccessPublic hpath xml [] (MaybeLazy.Strict (NewEmptyModuleOrNamespaceType mkind))
mtype.AddModuleOrNamespaceByMutation(smodul);
let modul = Map.find modName mtype.AllEntitiesByCompiledAndLogicalMangledNames
loop (prior_cpath@[(modName,Namespace)]) tpath tcpath modul
Expand Down Expand Up @@ -3566,7 +3566,7 @@ end
//--------------------------------------------------------------------------

let wrapModuleOrNamespaceType id cpath mtyp =
NewModuleOrNamespace (Some cpath) taccessPublic id XmlDoc.Empty [] (notlazy mtyp)
NewModuleOrNamespace (Some cpath) taccessPublic id XmlDoc.Empty [] (MaybeLazy.Strict mtyp)

let wrapModuleOrNamespaceTypeInNamespace id cpath mtyp =
let mspec = wrapModuleOrNamespaceType id cpath mtyp
Expand Down Expand Up @@ -4972,9 +4972,8 @@ and copyAndRemapAndBindTyconsAndVals g compgen tmenv tycons vs =
tcd'.entity_tycon_repr <- tcd.entity_tycon_repr |> remapTyconRepr g tmenvinner2;
tcd'.entity_tycon_abbrev <- tcd.entity_tycon_abbrev |> Option.map (remapType tmenvinner2) ;
tcd'.entity_tycon_tcaug <- tcd.entity_tycon_tcaug |> remapTyconAug tmenvinner2 ;
tcd'.entity_modul_contents <- notlazy (tcd.entity_modul_contents
|> Lazy.force
|> mapImmediateValsAndTycons lookupTycon lookupVal);
tcd'.entity_modul_contents <- MaybeLazy.Strict (tcd.entity_modul_contents.Value
|> mapImmediateValsAndTycons lookupTycon lookupVal);
tcd'.entity_exn_info <- tcd.entity_exn_info |> remapTyconExnInfo g tmenvinner2) ;
tycons',vs', tmenvinner

Expand Down Expand Up @@ -7637,10 +7636,8 @@ let rec remapEntityDataToNonLocal g tmenv (d: EntityData) =
entity_tycon_abbrev = d.entity_tycon_abbrev |> Option.map (remapType tmenvinner) ;
entity_tycon_tcaug = d.entity_tycon_tcaug |> remapTyconAug tmenvinner ;
entity_modul_contents =
notlazy (d.entity_modul_contents
|> Lazy.force
|> mapImmediateValsAndTycons (remapTyconToNonLocal g tmenv)
(remapValToNonLocal g tmenv));
MaybeLazy.Strict (d.entity_modul_contents.Value
|> mapImmediateValsAndTycons (remapTyconToNonLocal g tmenv) (remapValToNonLocal g tmenv));
entity_exn_info = d.entity_exn_info |> remapTyconExnInfo g tmenvinner}

and remapTyconToNonLocal g tmenv x =
Expand Down
13 changes: 9 additions & 4 deletions src/fsharp/TastPickle.fs
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ let p_option f x st =
// Pickle lazy values in such a way that they can, in some future F# compiler version, be read back
// lazily. However, a lazy reader is not used in this version because the value may contain the definitions of some
// OSGN nodes.
let p_lazy p x st =
let v = Lazy.force x
let private p_lazy_impl p v st =
let fixupPos1 = st.os.Position
// We fix these up after
prim_p_int32 0 st;
Expand Down Expand Up @@ -473,6 +472,12 @@ let p_lazy p x st =
st.os.FixupInt32 fixupPos6 ovalsIdx1;
st.os.FixupInt32 fixupPos7 ovalsIdx2

let p_lazy p x st =
p_lazy_impl p (Lazy.force x) st

let p_maybe_lazy p (x: MaybeLazy<_>) st =
p_lazy_impl p x.Value st

let p_hole () =
let h = ref (None : 'T pickler option)
(fun f -> h := Some f),(fun x st -> match !h with Some f -> f x st | None -> pfailwith st "p_hole: unfilled hole")
Expand Down Expand Up @@ -1727,7 +1732,7 @@ and p_entity_spec_data (x:EntityData) st =
p_kind x.entity_kind st
p_int64 (x.entity_flags.PickledBits ||| (if flagBit then EntityFlags.ReservedBitForPickleFormatTyconReprFlag else 0L)) st
p_option p_cpath x.entity_cpath st
p_lazy p_modul_typ x.entity_modul_contents st
p_maybe_lazy p_modul_typ x.entity_modul_contents st
p_exnc_repr x.entity_exn_info st
p_space 1 space st

Expand Down Expand Up @@ -2012,7 +2017,7 @@ and u_entity_spec_data st : EntityData =
entity_kind=x10b;
entity_flags=EntityFlags(x11);
entity_cpath=x12;
entity_modul_contents= x13;
entity_modul_contents=MaybeLazy.Lazy x13;
entity_exn_info=x14;
entity_il_repr_cache=newCache();
}
Expand Down
20 changes: 10 additions & 10 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ let UpdateAccModuleOrNamespaceType cenv env f =
if cenv.compilingCanonicalFslibModuleType then
let nleref = mkNonLocalEntityRef cenv.topCcu (arrPathOfLid env.ePath)
let modul = nleref.Deref
modul.Data.entity_modul_contents <- notlazy (f true modul.ModuleOrNamespaceType)
modul.Data.entity_modul_contents <- MaybeLazy.Strict (f true modul.ModuleOrNamespaceType)
SetCurrAccumulatedModuleOrNamespaceType env (f false (GetCurrAccumulatedModuleOrNamespaceType env))

let PublishModuleDefn cenv env mspec =
Expand Down Expand Up @@ -13385,13 +13385,13 @@ module MutRecBindingChecking =
let TcMutRecDefns_UpdateNSContents mutRecNSInfo =
match mutRecNSInfo with
| Some (Some (mspecNS: ModuleOrNamespace), mtypeAcc) ->
mspecNS.Data.entity_modul_contents <- notlazy !mtypeAcc
mspecNS.Data.entity_modul_contents <- MaybeLazy.Strict !mtypeAcc
| _ -> ()

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

TcMutRecDefns_UpdateNSContents mutRecNSInfo

Expand Down Expand Up @@ -14344,7 +14344,7 @@ module EstablishTypeDefinitionCores =
CheckNamespaceModuleOrTypeName cenv.g id

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

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

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

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

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

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

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

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

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

TMDefRec(true,tycons,binds,m)
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ type ParserDetail =

// PERFORMANCE: consider making this a struct.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// CONSISTENCY: consider removing this comment.

[<System.Diagnostics.DebuggerDisplay("{idText}")>]
[<Sealed>]
[<Struct>]
Copy link
Contributor

@dsyme dsyme Feb 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only now reviewing these changes. Please make sure I'm listed as a reviewer for all changes to the core compiler data structures, just to double check.

Do we know for sure this as a good idea? range is already a largish struct, and we had previously held off making Ident a struct too until we had some data

[<NoEquality; NoComparison>]
type Ident (text,range) =
type Ident (text: string, range: range) =
member x.idText = text
member x.idRange = range
override x.ToString() = text
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/import.fs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ let rec ImportILTypeDef amap m scoref (cpath:CompilationPath) enc nm (tdef:ILTyp
// Make sure we reraise the original exception one occurs - see findOriginalException.
(LazyWithContext.Create((fun m -> ImportILGenericParameters amap m scoref [] tdef.GenericParams), ErrorLogger.findOriginalException))
(scoref,enc,tdef)
lazyModuleOrNamespaceTypeForNestedTypes
(MaybeLazy.Lazy lazyModuleOrNamespaceTypeForNestedTypes)


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