Skip to content

Commit 39173f6

Browse files
Vasily KirichenkoVasily Kirichenko
authored andcommitted
try to pass parent namespace to Entity
1 parent d225014 commit 39173f6

6 files changed

Lines changed: 43 additions & 30 deletions

File tree

src/fsharp/TastOps.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ let ensureCcuHasModuleOrNamespaceAtPath (ccu:CcuThunk) path (CompPath(_, cpath))
996996
| (hpath::tpath), ((_, mkind)::tcpath) ->
997997
let modName = hpath.idText
998998
if not (Map.containsKey modName mtype.AllEntitiesByCompiledAndLogicalMangledNames) then
999-
let smodul = NewModuleOrNamespace (Some(CompPath(scoref, prior_cpath))) taccessPublic hpath xml [] (MaybeLazy.Strict (NewEmptyModuleOrNamespaceType mkind))
999+
let smodul = NewModuleOrNamespace (Some(CompPath(scoref, prior_cpath))) taccessPublic hpath xml [] (MaybeLazy.Strict (NewEmptyModuleOrNamespaceType mkind)) (Some modul)
10001000
mtype.AddModuleOrNamespaceByMutation(smodul);
10011001
let modul = Map.find modName mtype.AllEntitiesByCompiledAndLogicalMangledNames
10021002
loop (prior_cpath@[(modName, Namespace)]) tpath tcpath modul
@@ -3652,15 +3652,15 @@ end
36523652
// Helpers related to type checking modules & namespaces
36533653
//--------------------------------------------------------------------------
36543654

3655-
let wrapModuleOrNamespaceType id cpath mtyp =
3656-
NewModuleOrNamespace (Some cpath) taccessPublic id XmlDoc.Empty [] (MaybeLazy.Strict mtyp)
3655+
let wrapModuleOrNamespaceType id cpath mtyp parentNs =
3656+
NewModuleOrNamespace (Some cpath) taccessPublic id XmlDoc.Empty [] (MaybeLazy.Strict mtyp) parentNs
36573657

3658-
let wrapModuleOrNamespaceTypeInNamespace id cpath mtyp =
3659-
let mspec = wrapModuleOrNamespaceType id cpath mtyp
3658+
let wrapModuleOrNamespaceTypeInNamespace id cpath mtyp parentNs =
3659+
let mspec = wrapModuleOrNamespaceType id cpath mtyp parentNs
36603660
NewModuleOrNamespaceType Namespace [ mspec ] [], mspec
36613661

3662-
let wrapModuleOrNamespaceExprInNamespace (id :Ident) cpath mexpr =
3663-
let mspec = wrapModuleOrNamespaceType id cpath (NewEmptyModuleOrNamespaceType Namespace)
3662+
let wrapModuleOrNamespaceExprInNamespace (id: Ident) cpath mexpr parentNs =
3663+
let mspec = wrapModuleOrNamespaceType id cpath (NewEmptyModuleOrNamespaceType Namespace) parentNs
36643664
TMDefRec (false, [], [ModuleOrNamespaceBinding.Module(mspec, mexpr)], id.idRange)
36653665

36663666
// cleanup: make this a property

src/fsharp/TastOps.fsi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,9 @@ val ComputeRemappingFromImplementationToSignature : TcGlobals -> ModuleOrNamespa
803803
val ComputeHidingInfoAtAssemblyBoundary : ModuleOrNamespaceType -> SignatureHidingInfo -> SignatureHidingInfo
804804
val mkRepackageRemapping : SignatureRepackageInfo -> Remap
805805

806-
val wrapModuleOrNamespaceExprInNamespace : Ident -> CompilationPath -> ModuleOrNamespaceExpr -> ModuleOrNamespaceExpr
807-
val wrapModuleOrNamespaceTypeInNamespace : Ident -> CompilationPath -> ModuleOrNamespaceType -> ModuleOrNamespaceType * ModuleOrNamespace
808-
val wrapModuleOrNamespaceType : Ident -> CompilationPath -> ModuleOrNamespaceType -> ModuleOrNamespace
806+
val wrapModuleOrNamespaceExprInNamespace : Ident -> CompilationPath -> ModuleOrNamespaceExpr -> Entity option -> ModuleOrNamespaceExpr
807+
val wrapModuleOrNamespaceTypeInNamespace : Ident -> CompilationPath -> ModuleOrNamespaceType -> Entity option -> ModuleOrNamespaceType * ModuleOrNamespace
808+
val wrapModuleOrNamespaceType : Ident -> CompilationPath -> ModuleOrNamespaceType -> Entity option -> ModuleOrNamespace
809809

810810
val SigTypeOfImplFile : TypedImplFile -> ModuleOrNamespaceType
811811

src/fsharp/TastPickle.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,7 @@ and u_entity_spec_data st : Entity =
20032003
entity_modul_contents=MaybeLazy.Lazy x13
20042004
entity_exn_info=x14
20052005
entity_il_repr_cache=newCache()
2006+
entity_parent_namespace=None //todo
20062007
}
20072008

20082009
and u_tcaug st =

src/fsharp/TypeChecker.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ let LocateEnv ccu env enclosingNamespacePath =
667667
let BuildRootModuleType enclosingNamespacePath (cpath:CompilationPath) mtyp =
668668
(enclosingNamespacePath, (cpath, (mtyp, None)))
669669
||> List.foldBack (fun id (cpath, (mtyp, mspec)) ->
670-
let a, b = wrapModuleOrNamespaceTypeInNamespace id cpath.ParentCompPath mtyp
670+
let a, b = wrapModuleOrNamespaceTypeInNamespace id cpath.ParentCompPath mtyp None
671671
cpath.ParentCompPath, (a, match mspec with Some _ -> mspec | None -> Some b))
672672
|> snd
673673

src/fsharp/import.fs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
/// Functions to import .NET binary metadata as TAST objects
44
module internal Microsoft.FSharp.Compiler.Import
55

6+
#nowarn "40"
7+
68
open System.Reflection
79
open System.Collections.Generic
810
open Internal.Utilities
@@ -442,7 +444,7 @@ let multisetDiscriminateAndMap nodef tipf (items: ('Key list * 'Value) list) =
442444

443445

444446
/// Import an IL type definition as a new F# TAST Entity node.
445-
let rec ImportILTypeDef amap m scoref (cpath:CompilationPath) enc nm (tdef:ILTypeDef) =
447+
let rec ImportILTypeDef amap m scoref (cpath:CompilationPath) enc nm (tdef:ILTypeDef) (parentNs: Entity option) =
446448
let lazyModuleOrNamespaceTypeForNestedTypes =
447449
lazy
448450
let cpath = cpath.NestedCompPath nm ModuleOrType
@@ -456,11 +458,11 @@ let rec ImportILTypeDef amap m scoref (cpath:CompilationPath) enc nm (tdef:ILTyp
456458
(LazyWithContext.Create((fun m -> ImportILGenericParameters amap m scoref [] tdef.GenericParams), ErrorLogger.findOriginalException))
457459
(scoref,enc,tdef)
458460
(MaybeLazy.Lazy lazyModuleOrNamespaceTypeForNestedTypes)
461+
parentNs
459462

460-
461463
/// Import a list of (possibly nested) IL types as a new ModuleOrNamespaceType node
462464
/// containing new entities, bucketing by namespace along the way.
463-
and ImportILTypeDefList amap m (cpath:CompilationPath) enc items =
465+
and ImportILTypeDefList amap m (cpath:CompilationPath) enc (parentNs: Entity option) items =
464466
// Split into the ones with namespaces and without. Add the ones with namespaces in buckets.
465467
// That is, discriminate based in the first element of the namespace list (e.g. "System")
466468
// and, for each bag, fold-in a lazy computation to add the types under that bag .
@@ -473,11 +475,12 @@ and ImportILTypeDefList amap m (cpath:CompilationPath) enc items =
473475
items
474476
|> multisetDiscriminateAndMap
475477
(fun n tgs ->
476-
let modty = lazy (ImportILTypeDefList amap m (cpath.NestedCompPath n Namespace) enc tgs)
477-
NewModuleOrNamespace (Some cpath) taccessPublic (mkSynId m n) XmlDoc.Empty [] (MaybeLazy.Lazy modty))
478+
let rec modty = lazy (ImportILTypeDefList amap m (cpath.NestedCompPath n Namespace) enc (Some ns) tgs)
479+
and ns = NewModuleOrNamespace (Some cpath) taccessPublic (mkSynId m n) XmlDoc.Empty [] (MaybeLazy.Lazy modty) parentNs
480+
in ns)
478481
(fun (n,info:Lazy<_>) ->
479482
let (scoref2,_,lazyTypeDef:Lazy<ILTypeDef>) = info.Force()
480-
ImportILTypeDef amap m scoref2 cpath enc n (lazyTypeDef.Force()))
483+
ImportILTypeDef amap m scoref2 cpath enc n (lazyTypeDef.Force()) parentNs)
481484

482485
let kind = match enc with [] -> Namespace | _ -> ModuleOrType
483486
NewModuleOrNamespaceType kind entities []
@@ -489,7 +492,7 @@ and ImportILTypeDefs amap m scoref cpath enc (tdefs: ILTypeDefs) =
489492
tdefs.AsArrayOfLazyTypeDefs
490493
|> Array.map (fun (ns,n,attrs,lazyTypeDef) -> (ns,(n,notlazy(scoref,attrs,lazyTypeDef))))
491494
|> Array.toList
492-
|> ImportILTypeDefList amap m cpath enc
495+
|> ImportILTypeDefList amap m cpath enc None
493496

494497
/// Import the main type definitions in an IL assembly.
495498
///
@@ -518,7 +521,7 @@ let ImportILAssemblyExportedType amap m auxModLoader (scoref:ILScopeRef) (export
518521
scoref,exportedType.CustomAttrs,lazyTypeDef)
519522

520523
let ns,n = splitILTypeName exportedType.Name
521-
[ ImportILTypeDefList amap m (CompPath(scoref,[])) [] [(ns,(n,info))] ]
524+
[ ImportILTypeDefList amap m (CompPath(scoref,[])) [] None [(ns,(n,info))] ]
522525

523526
/// Import the "exported types" table for multi-module assemblies.
524527
let ImportILAssemblyExportedTypes amap m auxModLoader scoref (exportedTypes: ILExportedTypesAndForwarders) =
@@ -572,7 +575,7 @@ let ImportILAssembly(amap:(unit -> ImportMap),m,auxModuleLoader,sref,sourceDir,f
572575
ImportProvidedType = (fun ty -> ImportProvidedType (amap()) m ty)
573576
#endif
574577
QualifiedName= Some sref.QualifiedName
575-
Contents = NewCcuContents sref m nm mty
578+
Contents = NewCcuContents sref m nm mty None
576579
ILScopeRef = sref
577580
Stamp = newStamp()
578581
SourceCodeDirectory = sourceDir // note: not an accurate value, but IL assemblies don't give us this information in any attributes.

src/fsharp/tast.fs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ type Entity =
574574
/// Used during codegen to hold the ILX representation indicating how to access the type
575575
// MUTABILITY: only for unpickle linkage and caching
576576
mutable entity_il_repr_cache : CompiledTypeRepr cache
577+
578+
mutable entity_parent_namespace : Entity option
577579
}
578580
/// The name of the namespace, module or type, possibly with mangling, e.g. List`1, List or FailureException
579581
member x.LogicalName = x.entity_logical_name
@@ -845,6 +847,7 @@ type Entity =
845847
| Some x -> NameMap.tryFind n x.CasesTable.CasesByName
846848
| None -> None
847849

850+
member x.ParentNamespace = x.entity_parent_namespace
848851

849852
/// Create a new entity with empty, unlinked data. Only used during unpickling of F# metadata.
850853
static member NewUnlinked() : Entity =
@@ -868,7 +871,8 @@ type Entity =
868871
entity_pubpath = Unchecked.defaultof<_>
869872
entity_accessiblity= Unchecked.defaultof<_>
870873
entity_cpath = Unchecked.defaultof<_>
871-
entity_il_repr_cache = Unchecked.defaultof<_> }
874+
entity_il_repr_cache = Unchecked.defaultof<_>
875+
entity_parent_namespace = Unchecked.defaultof<_> }
872876

873877
/// Create a new entity with the given backing data. Only used during unpickling of F# metadata.
874878
static member New _reason (data: Entity) : Entity = data
@@ -1828,10 +1832,11 @@ and Construct =
18281832
entity_xmldocsig=""
18291833
entity_pubpath = Some pubpath
18301834
entity_cpath = Some cpath
1831-
entity_il_repr_cache = newCache() }
1835+
entity_il_repr_cache = newCache()
1836+
entity_parent_namespace = None } // todo how to get an Entiry namespace for provided types?
18321837
#endif
18331838

1834-
static member NewModuleOrNamespace cpath access (id:Ident) xml attribs mtype =
1839+
static member NewModuleOrNamespace cpath access (id:Ident) xml attribs mtype parentNs =
18351840
let stamp = newStamp()
18361841
// Put the module suffix on if needed
18371842
Tycon.New "mspec"
@@ -1855,7 +1860,8 @@ and Construct =
18551860
entity_attribs=attribs
18561861
entity_xmldoc=xml
18571862
entity_xmldocsig=""
1858-
entity_il_repr_cache = newCache() }
1863+
entity_il_repr_cache = newCache()
1864+
entity_parent_namespace = parentNs }
18591865

18601866
and Accessibility =
18611867
/// Indicates the construct can only be accessed from any code in the given type constructor, module or assembly. [] indicates global scope.
@@ -2742,6 +2748,7 @@ and NonLocalEntityRef =
27422748
(Some cpath)
27432749
(TAccess []) (ident(path.[k],m)) XmlDoc.Empty []
27442750
(MaybeLazy.Strict (Construct.NewEmptyModuleOrNamespaceType Namespace))
2751+
(Some entity)
27452752
entity.ModuleOrNamespaceType.AddModuleOrNamespaceByMutation(newEntity)
27462753
injectNamespacesFromIToJ newEntity (k+1)
27472754
let newEntity = injectNamespacesFromIToJ entity i
@@ -4895,7 +4902,7 @@ let NewModuleOrNamespaceType mkind tycons vals =
48954902
let NewEmptyModuleOrNamespaceType mkind = NewModuleOrNamespaceType mkind [] []
48964903

48974904
/// Create a new TAST Entity node for an F# exception definition
4898-
let NewExn cpath (id:Ident) access repr attribs doc =
4905+
let NewExn cpath (id:Ident) access repr attribs doc parentNs =
48994906
Tycon.New "exnc"
49004907
{ entity_stamp=newStamp()
49014908
entity_attribs=attribs
@@ -4917,7 +4924,8 @@ let NewExn cpath (id:Ident) access repr attribs doc =
49174924
entity_tycon_abbrev = None
49184925
entity_tycon_repr = TNoRepr
49194926
entity_flags=EntityFlags(usesPrefixDisplay=false, isModuleOrNamespace=false, preEstablishedHasDefaultCtor=false, hasSelfReferentialCtor=false, isStructRecordOrUnionType=false)
4920-
entity_il_repr_cache= newCache() }
4927+
entity_il_repr_cache= newCache()
4928+
entity_parent_namespace = parentNs }
49214929

49224930
/// Create a new TAST RecdField node for an F# class, struct or record field
49234931
let NewRecdField stat konst id ty isMutable isVolatile pattribs fattribs docOption access secret =
@@ -4936,7 +4944,7 @@ let NewRecdField stat konst id ty isMutable isVolatile pattribs fattribs docOpt
49364944
rfield_other_range = None }
49374945

49384946

4939-
let NewTycon (cpath, nm, m, access, reprAccess, kind, typars, docOption, usesPrefixDisplay, preEstablishedHasDefaultCtor, hasSelfReferentialCtor, mtyp) =
4947+
let NewTycon (cpath, nm, m, access, reprAccess, kind, typars, docOption, usesPrefixDisplay, preEstablishedHasDefaultCtor, hasSelfReferentialCtor, mtyp, parentNs) =
49404948
let stamp = newStamp()
49414949
Tycon.New "tycon"
49424950
{ entity_stamp=stamp
@@ -4959,14 +4967,15 @@ let NewTycon (cpath, nm, m, access, reprAccess, kind, typars, docOption, usesPre
49594967
entity_xmldocsig=""
49604968
entity_pubpath=cpath |> Option.map (fun (cp:CompilationPath) -> cp.NestedPublicPath (mkSynId m nm))
49614969
entity_cpath = cpath
4962-
entity_il_repr_cache = newCache() }
4970+
entity_il_repr_cache = newCache()
4971+
entity_parent_namespace = parentNs }
49634972

49644973

4965-
let NewILTycon nlpath (nm,m) tps (scoref:ILScopeRef, enc, tdef:ILTypeDef) mtyp =
4974+
let NewILTycon nlpath (nm,m) tps (scoref:ILScopeRef, enc, tdef:ILTypeDef) mtyp (parentNs: Entity option) =
49664975

49674976
// NOTE: hasSelfReferentialCtor=false is an assumption about mscorlib
49684977
let hasSelfReferentialCtor = tdef.IsClass && (not scoref.IsAssemblyRef && scoref.AssemblyRef.Name = "mscorlib")
4969-
let tycon = NewTycon(nlpath, nm, m, taccessPublic, taccessPublic, TyparKind.Type, tps, XmlDoc.Empty, true, false, hasSelfReferentialCtor, mtyp)
4978+
let tycon = NewTycon(nlpath, nm, m, taccessPublic, taccessPublic, TyparKind.Type, tps, XmlDoc.Empty, true, false, hasSelfReferentialCtor, mtyp, parentNs)
49704979

49714980
tycon.entity_tycon_repr <- TILObjectRepr (TILObjectReprData (scoref,enc,tdef))
49724981
tycon.TypeContents.tcaug_closed <- true

0 commit comments

Comments
 (0)