diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index 1fb2afd1b0d..cdedfaf815a 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -195,6 +195,7 @@ * Stabilized several `preview` language features into F# 11.0 (`--langversion:11.0`, enabled by default with a .NET 11 SDK): `MethodOverloadsCache`, `ErrorOnMissingSignatureAttribute`, `DirectDelegateConstruction`, `AccessProtectedBaseFieldFromClosure`, and `RecordSpreads`. `FromEndSlicing` intentionally remains in `preview`. ([PR #20199](https://github.com/dotnet/fsharp/pull/20199)) * Interpolated string holes (e.g. `$"{x}"`) are now formatted with invariant culture (via the `string` operator) instead of the current thread culture. ([PR #19971](https://github.com/dotnet/fsharp/pull/19971)) * Lines starting with `#:` are now ignored ([Language suggestion 1440](https://github.com/fsharp/fslang-suggestions/issues/1440), [RFC FS-1337](https://github.com/fsharp/fslang-design/pull/830), [PR #20212](https://github.com/dotnet/fsharp/pull/20212)) +* Calculate Entity.PublicPath instead of storing ([PR #20285](https://github.com/dotnet/fsharp/pull/20285)) ### Breaking Changes * Add `ExtendedLayoutAttribute` support for future .NET runtime interop. `ILTypeDefLayout` has a new `Extended` case. ([Issue #19190](https://github.com/dotnet/fsharp/issues/19190), [PR #19194](https://github.com/dotnet/fsharp/pull/19194)) diff --git a/src/Compiler/Checking/NameResolution.fs b/src/Compiler/Checking/NameResolution.fs index 1ce55448a7f..e520c6235f6 100644 --- a/src/Compiler/Checking/NameResolution.fs +++ b/src/Compiler/Checking/NameResolution.fs @@ -1174,11 +1174,11 @@ let ResolveProvidedTypeNameInEntity (amap, m, typeName, modref: ModuleOrNamespac match modref.TypeReprInfo with | TProvidedNamespaceRepr(resolutionEnvironment, resolvers) -> match modref.Deref.PublicPath with - | Some(PubPath path) -> + | ValueSome pubpath -> resolvers - |> List.choose (fun r-> TryResolveProvidedType(r, m, path, typeName)) + |> List.choose (fun r -> TryResolveProvidedType(r, m, pubpath.FullPath, typeName)) |> List.map (fun st -> AddEntityForProvidedType (amap, modref, resolutionEnvironment, st, m)) - | None -> [] + | ValueNone -> [] // We have a provided type, look up its nested types (populating them on-demand if necessary) | TProvidedTypeRepr info -> diff --git a/src/Compiler/Checking/OverloadResolutionRules.fs b/src/Compiler/Checking/OverloadResolutionRules.fs index d099c936883..62a08c57ec8 100644 --- a/src/Compiler/Checking/OverloadResolutionRules.fs +++ b/src/Compiler/Checking/OverloadResolutionRules.fs @@ -309,7 +309,7 @@ let private compareArg (ctx: OverloadResolutionContext) (calledArg1: CalledArg) | ValueSome tcref1 when tcref1.DisplayName = "Func" && (match tcref1.PublicPath with - | Some p -> p.EnclosingPath = [| "System" |] + | ValueSome p -> p.EnclosingPath = [| "System" |] | _ -> false) && isDelegateTy g ty1 && isDelegateTy g ty2 diff --git a/src/Compiler/Service/FSharpCheckerResults.fs b/src/Compiler/Service/FSharpCheckerResults.fs index a125c74a783..155d1b5f702 100644 --- a/src/Compiler/Service/FSharpCheckerResults.fs +++ b/src/Compiler/Service/FSharpCheckerResults.fs @@ -2741,8 +2741,8 @@ type internal TypeCheckInfo None else match tr.TypeReprInfo, tr.PublicPath with - | TILObjectRepr(TILObjectReprData(ILScopeRef.Assembly assemblyRef, _, _)), Some(PubPath parts) -> - let fullName = parts |> String.concat "." + | TILObjectRepr(TILObjectReprData(ILScopeRef.Assembly assemblyRef, _, _)), ValueSome pubpath -> + let fullName = pubpath.FullPath |> String.concat "." Some(FindDeclResult.ExternalDecl(assemblyRef.Name, FindDeclExternalSymbol.Type fullName)) | _ -> None | _ -> None diff --git a/src/Compiler/Service/ServiceDeclarationLists.fs b/src/Compiler/Service/ServiceDeclarationLists.fs index e5d76901a02..6142e72cf3c 100644 --- a/src/Compiler/Service/ServiceDeclarationLists.fs +++ b/src/Compiler/Service/ServiceDeclarationLists.fs @@ -143,17 +143,16 @@ module DeclarationListHelpers = member x.Equals(item1, item2) = nullSafeEquality item1 item2 (fun item1 item2 -> fullDisplayTextOfModRef item1 = fullDisplayTextOfModRef item2) member x.GetHashCode item = hash item.Stamp } - let OutputFullName displayFullName ppF fnF r = + let OutputFullName displayFullName hasPubPath fnF r = // Only display full names in quick info, not declaration lists or method lists - if not displayFullName then - match ppF r with - | None -> emptyL - | Some _ -> wordL (tagText (FSComp.SR.typeInfoFullName())) ^^ RightL.colon ^^ (fnF r) + if not displayFullName then + if hasPubPath r then wordL (tagText (FSComp.SR.typeInfoFullName())) ^^ RightL.colon ^^ (fnF r) + else emptyL else emptyL - let pubpathOfValRef (v: ValRef) = v.PublicPath + let hasPubPathValRef (v: ValRef) = v.PublicPath.IsSome - let pubpathOfTyconRef (x: TyconRef) = x.PublicPath + let hasPubPathTyconRef (x: TyconRef) = x.PublicPath.IsSome /// Output the quick info information of a language item let rec FormatItemDescriptionToToolTipElement displayFullName (infoReader: InfoReader) ad m denv (item: ItemWithInst) symbol (width: int option) = @@ -169,7 +168,7 @@ module DeclarationListHelpers = | Item.Value vref | Item.CustomBuilder (_, vref) -> let prettyTyparInst, resL = layoutQualifiedValOrMember denv infoReader item.TyparInstantiation vref - let remarks = OutputFullName displayFullName pubpathOfValRef fullDisplayTextOfValRefAsLayout vref + let remarks = OutputFullName displayFullName hasPubPathValRef fullDisplayTextOfValRefAsLayout vref let tpsL = FormatTyparMapping denv prettyTyparInst let typeMapping = List.map toRichText tpsL let resL = PrintUtilities.squashToWidth width resL @@ -212,7 +211,7 @@ module DeclarationListHelpers = let vTauTy = v.TauType // REVIEW: use _cxs here let (prettyTyparInst, prettyTy), _cxs = PrettyTypes.PrettifyInstAndType denv.g (item.TyparInstantiation, vTauTy) - let remarks = OutputFullName displayFullName pubpathOfValRef fullDisplayTextOfValRefAsLayout v + let remarks = OutputFullName displayFullName hasPubPathValRef fullDisplayTextOfValRefAsLayout v let layout = wordL (tagText (FSComp.SR.typeInfoActiveRecognizer())) ^^ wordL (tagActivePatternCase apref.DisplayName |> mkNav v.DefinitionRange) ^^ @@ -231,7 +230,7 @@ module DeclarationListHelpers = | Item.ExnCase ecref -> let layout = layoutExnDef denv infoReader ecref let layout = PrintUtilities.squashToWidth width layout - let remarks = OutputFullName displayFullName pubpathOfTyconRef fullDisplayTextOfExnRefAsLayout ecref + let remarks = OutputFullName displayFullName hasPubPathTyconRef fullDisplayTextOfExnRefAsLayout ecref let mainDescription = toRichText layout let remarks = toRichText remarks ToolTipElement.Single (mainDescription, xml, remarks=remarks, ?symbol = symbol) @@ -388,7 +387,7 @@ module DeclarationListHelpers = showDocumentation = false } let layout = layoutTyconDefn denv infoReader ad m (* width *) tcref.Deref let layout = PrintUtilities.squashToWidth width layout - let remarks = OutputFullName displayFullName pubpathOfTyconRef fullDisplayTextOfTyconRefAsLayout tcref + let remarks = OutputFullName displayFullName hasPubPathTyconRef fullDisplayTextOfTyconRefAsLayout tcref let mainDescription = toRichText layout let remarks = toRichText remarks ToolTipElement.Single (mainDescription, xml, remarks=remarks, ?symbol = symbol) diff --git a/src/Compiler/Symbols/Exprs.fs b/src/Compiler/Symbols/Exprs.fs index 4b6ecbec6db..caaf9cfb577 100644 --- a/src/Compiler/Symbols/Exprs.fs +++ b/src/Compiler/Symbols/Exprs.fs @@ -1065,7 +1065,11 @@ module FSharpExprConvert = |> Seq.filter (fun v -> (v.CompiledName g.CompilerGlobalState) = vName && match v.TryDeclaringEntity with - | Parent p -> p.PublicPath = enclosingEntity.PublicPath + | Parent p -> + (match p.PublicPath, enclosingEntity.PublicPath with + | ValueSome pp1, ValueSome pp2 -> pubPathEq pp1 pp2 + | ValueNone, ValueNone -> true + | _ -> false) | _ -> false ) |> List.ofSeq match findModuleMemberByName with @@ -1205,7 +1209,7 @@ module FSharpExprConvert = let argCount = (List.sumBy List.length argTys) + (if isStatic then 0 else 1) let key = ValLinkageFullKey({ MemberParentMangledName=memberParentName; MemberIsOverride=false; LogicalName=logicalName; TotalArgCount= argCount }, Some linkageType) - let (PubPath p) = tcref.PublicPath.Value + let p = tcref.PublicPath.Value.FullPath let enclosingNonLocalRef = mkNonLocalEntityRef tcref.nlr.Ccu p let vref = mkNonLocalValRef enclosingNonLocalRef key makeFSExpr isMember vref diff --git a/src/Compiler/TypedTree/TypedTree.fs b/src/Compiler/TypedTree/TypedTree.fs index 1c053557cf1..5030f59334d 100644 --- a/src/Compiler/TypedTree/TypedTree.fs +++ b/src/Compiler/TypedTree/TypedTree.fs @@ -556,15 +556,6 @@ type ModuleOrNamespaceKind = | ModuleOrType -> 1 | Namespace _ -> 2 -/// A public path records where a construct lives within the global namespace -/// of a CCU. -type PublicPath = - | PubPath of string[] - member x.EnclosingPath = - let (PubPath pp) = x - assert (pp.Length >= 1) - pp[0..pp.Length-2] - /// Represents the specified visibility of the accessibility -- used to ensure IL visibility [] type SyntaxAccess = @@ -583,9 +574,7 @@ type CompilationPath = member x.MangledPath = List.map fst x.AccessPath - member x.NestedPublicPath (id: Ident) = PubPath(Array.append (Array.ofList x.MangledPath) [| id.idText |]) - - member x.ParentCompPath = + member x.ParentCompPath = let a, _ = List.frontAndBack x.AccessPath CompPath(x.ILScopeRef, x.SyntaxAccess, a) @@ -603,6 +592,31 @@ type CompilationPath = member x.SyntaxAccess = let (CompPath(_, access, _)) = x in access +[] +type PublicPath = + | PubPath of enclosing: CompilationPath * name: string + + member x.EnclosingCompilationPath = let (PubPath(cp, _)) = x in cp + + member x.Name = let (PubPath(_, nm)) = x in nm + + member x.EnclosingPath: string[] = Array.ofList x.EnclosingCompilationPath.MangledPath + + member x.FullPath: string[] = + let enclosing = x.EnclosingCompilationPath.MangledPath + let res = Array.zeroCreate (List.length enclosing + 1) + let mutable i = 0 + + for nm in enclosing do + res[i] <- nm + i <- i + 1 + + res[i] <- x.Name + res + + member x.HasEmptyEnclosingPath = List.isEmpty x.EnclosingCompilationPath.AccessPath + + [] type EntityOptionalData = { @@ -693,12 +707,7 @@ type Entity = // when compiling fslib to fixup compiler forward references to internal items mutable entity_modul_type: MaybeLazy - /// The stable path to the type, e.g. Microsoft.FSharp.Core.FSharpFunc`2 - // REVIEW: it looks like entity_cpath subsumes this - // MUTABILITY: only for unpickle linkage - mutable entity_pubpath: PublicPath option - - /// The stable path to the type, e.g. Microsoft.FSharp.Core.FSharpFunc`2 + /// The stable path to the type, e.g. Microsoft.FSharp.Core.FSharpFunc`2 // MUTABILITY: only for unpickle linkage mutable entity_cpath: CompilationPath option @@ -960,7 +969,10 @@ type Entity = | c -> c /// Get a blob of data indicating how this type is nested in other namespaces, modules or types. - member x.PublicPath = x.entity_pubpath + member x.PublicPath: PublicPath voption = + match x.entity_cpath with + | Some cpath -> ValueSome(PubPath(cpath, x.entity_logical_name)) + | None -> ValueNone /// Get the value representing the accessibility of an F# type definition or module. member x.Accessibility = @@ -1106,7 +1118,6 @@ type Entity = entity_tycon_repr= Unchecked.defaultof<_> entity_tycon_tcaug= Unchecked.defaultof<_> entity_modul_type= Unchecked.defaultof<_> - entity_pubpath = Unchecked.defaultof<_> entity_cpath = Unchecked.defaultof<_> entity_il_repr_cache = Unchecked.defaultof<_> entity_opt_data = Unchecked.defaultof<_>} @@ -1125,8 +1136,7 @@ type Entity = x.entity_tycon_repr <- tg.entity_tycon_repr x.entity_tycon_tcaug <- tg.entity_tycon_tcaug x.entity_modul_type <- tg.entity_modul_type - x.entity_pubpath <- tg.entity_pubpath - x.entity_cpath <- tg.entity_cpath + x.entity_cpath <- tg.entity_cpath x.entity_il_repr_cache <- tg.entity_il_repr_cache match tg.entity_opt_data with | Some tg -> @@ -3287,9 +3297,9 @@ type Val = member x.PublicPath = match x.TryDeclaringEntity with | Parent eref -> - match eref.PublicPath with - | None -> None - | Some p -> Some(ValPubPath(p, x.GetLinkageFullKey())) + match eref.PublicPath with + | ValueNone -> None + | ValueSome p -> Some(ValPubPath(p, x.GetLinkageFullKey())) | ParentNone -> None @@ -3946,7 +3956,7 @@ type EntityRef = member x.CompiledReprCache = x.Deref.CompiledReprCache /// Get a blob of data indicating how this type is nested in other namespaces, modules or types. - member x.PublicPath: PublicPath option = x.Deref.PublicPath + member x.PublicPath: PublicPath voption = x.Deref.PublicPath /// Get the value representing the accessibility of an F# type definition or module. member x.Accessibility = x.Deref.Accessibility @@ -6324,7 +6334,6 @@ type Construct() = static member NewProvidedTycon(resolutionEnvironment, st: Tainted, importProvidedType, isSuppressRelocate, m, ?access, ?cpath) = let stamp = newStamp() let name = st.PUntaint((fun st -> st.Name), m) - let id = ident (name, m) let kind = let isMeasure = st.PApplyWithProvider((fun (st, provider) -> @@ -6344,7 +6353,6 @@ type Construct() = let enclosingName = GetFSharpPathToProvidedType(st, m) CompPath(ilScopeRef, SyntaxAccess.Unknown, enclosingName |> List.map(fun id->id, ModuleOrNamespaceKind.Namespace true)) | Some p -> p - let pubpath = cpath.NestedPublicPath id let repr = Construct.NewProvidedTyconRepr(resolutionEnvironment, st, importProvidedType, isSuppressRelocate, m) @@ -6359,7 +6367,6 @@ type Construct() = entity_tycon_tcaug=TyconAugmentation.Create() entity_modul_type = MaybeLazy.Lazy(InterruptibleLazy(fun _ -> ModuleOrNamespaceType(Namespace true, QueueList.ofList [], QueueList.ofList []))) // Generated types get internal accessibility - entity_pubpath = Some pubpath entity_cpath = Some cpath entity_il_repr_cache = null entity_opt_data = @@ -6383,7 +6390,6 @@ type Construct() = entity_typars=LazyWithContext.NotLazy [] entity_tycon_repr = TNoRepr entity_tycon_tcaug=TyconAugmentation.Create() - entity_pubpath=cpath |> Option.map (fun (cp: CompilationPath) -> cp.NestedPublicPath id) entity_cpath=cpath entity_attribs=WellKnownEntityAttribs.Create(attribs) entity_il_repr_cache = null @@ -6458,7 +6464,6 @@ type Construct() = entity_logical_name = id.idText entity_range = id.idRange entity_tycon_tcaug = TyconAugmentation.Create() - entity_pubpath = cpath |> Option.map (fun (cp: CompilationPath) -> cp.NestedPublicPath id) entity_modul_type = MaybeLazy.Strict (Construct.NewEmptyModuleOrNamespaceType ModuleOrType) entity_cpath = cpath entity_typars = LazyWithContext.NotLazy [] @@ -6501,7 +6506,6 @@ type Construct() = entity_tycon_repr = TNoRepr entity_tycon_tcaug=TyconAugmentation.Create() entity_modul_type = mtyp - entity_pubpath=cpath |> Option.map (fun (cp: CompilationPath) -> cp.NestedPublicPath (mkSynId m nm)) entity_cpath = cpath entity_il_repr_cache = null entity_opt_data = diff --git a/src/Compiler/TypedTree/TypedTree.fsi b/src/Compiler/TypedTree/TypedTree.fsi index d97811bdd6c..d706237e468 100644 --- a/src/Compiler/TypedTree/TypedTree.fsi +++ b/src/Compiler/TypedTree/TypedTree.fsi @@ -340,13 +340,6 @@ type ModuleOrNamespaceKind = /// If false, this namespace was implicitly constructed during type checking. isExplicit: bool -/// A public path records where a construct lives within the global namespace -/// of a CCU. -type PublicPath = - | PubPath of string[] - - member EnclosingPath: string[] - /// Represents the specified visibility of the accessibility -- used to ensure IL visibility [] type SyntaxAccess = @@ -364,8 +357,6 @@ type CompilationPath = member NestedCompPath: n: string -> moduleKind: ModuleOrNamespaceKind -> CompilationPath - member NestedPublicPath: id: Ident -> PublicPath - member AccessPath: (string * ModuleOrNamespaceKind) list member DemangledPath: string list @@ -378,6 +369,24 @@ type CompilationPath = member SyntaxAccess: SyntaxAccess +/// A public path records where a construct lives within the global namespace of a CCU. +/// +/// Comparison goes through pubPathEq: derived equality would also compare the enclosing path's +/// ILScopeRef and SyntaxAccess, besides boxing this struct. +[] +type PublicPath = + | PubPath of enclosing: CompilationPath * name: string + + member EnclosingCompilationPath: CompilationPath + + member Name: string + + member EnclosingPath: string[] + + member FullPath: string[] + + member HasEmptyEnclosingPath: bool + [] type EntityOptionalData = { @@ -449,9 +458,6 @@ type Entity = /// This field is used when the 'tycon' is really a module definition. It holds statically nested type definitions type nested modules mutable entity_modul_type: MaybeLazy - /// The stable path to the type, e.g. Microsoft.FSharp.Core.FSharpFunc`2 - mutable entity_pubpath: PublicPath option - /// The stable path to the type, e.g. Microsoft.FSharp.Core.FSharpFunc`2 mutable entity_cpath: CompilationPath option @@ -768,7 +774,7 @@ type Entity = member PreEstablishedHasDefaultConstructor: bool /// Get a blob of data indicating how this type is nested in other namespaces, modules or types. - member PublicPath: PublicPath option + member PublicPath: PublicPath voption /// The code location where the module, namespace or type is defined. member Range: range @@ -2750,7 +2756,7 @@ type EntityRef = member PreEstablishedHasDefaultConstructor: bool /// Get a blob of data indicating how this type is nested in other namespaces, modules or types. - member PublicPath: PublicPath option + member PublicPath: PublicPath voption /// The code location where the module, namespace or type is defined. member Range: range diff --git a/src/Compiler/TypedTree/TypedTreeBasics.fs b/src/Compiler/TypedTree/TypedTreeBasics.fs index 6c14530109a..ee55156caca 100644 --- a/src/Compiler/TypedTree/TypedTreeBasics.fs +++ b/src/Compiler/TypedTree/TypedTreeBasics.fs @@ -366,10 +366,10 @@ let mkNestedValRef (cref: EntityRef) (v: Val) : ValRef = mkNonLocalValRefPreResolved v nlr key /// From Ref_private to Ref_nonlocal when exporting data. -let rescopePubPathToParent viewedCcu (PubPath p) = NonLocalEntityRef(viewedCcu, p[0..p.Length-2]) +let rescopePubPathToParent viewedCcu (pp: PublicPath) = NonLocalEntityRef(viewedCcu, pp.EnclosingPath) /// From Ref_private to Ref_nonlocal when exporting data. -let rescopePubPath viewedCcu (PubPath p) = NonLocalEntityRef(viewedCcu, p) +let rescopePubPath viewedCcu (pp: PublicPath) = NonLocalEntityRef(viewedCcu, pp.FullPath) //--------------------------------------------------------------------------- // Equality between TAST items. @@ -414,10 +414,20 @@ let nonLocalRefEq (NonLocalEntityRef(x1, y1) as smr1) (NonLocalEntityRef(x2, y2) let nonLocalRefDefinitelyNotEq (NonLocalEntityRef(_, y1)) (NonLocalEntityRef(_, y2)) = not (arrayPathEq y1 y2) -let pubPathEq (PubPath path1) (PubPath path2) = arrayPathEq path1 path2 +// A function rather than a member on PublicPath: the optimizer does not see through a struct member +// call when inferring MightMakeCriticalTailcall, and this runs in tail position from fslibEntityRefEq. +let pubPathEq (path1: PublicPath) (path2: PublicPath) = + let rec loop p1 p2 = + match p1, p2 with + | [], [] -> true + | (nm1, _) :: rest1, (nm2, _) :: rest2 -> nm1 = nm2 && loop rest1 rest2 + | _ -> false + + path1.Name = path2.Name + && loop path1.EnclosingCompilationPath.AccessPath path2.EnclosingCompilationPath.AccessPath -let fslibRefEq (nlr1: NonLocalEntityRef) (PubPath path2) = - arrayPathEq nlr1.Path path2 +let fslibRefEq (nlr1: NonLocalEntityRef) (path2: PublicPath) = + arrayPathEq nlr1.Path path2.FullPath // Compare two EntityRef's for equality when compiling fslib (FSharp.Core.dll) // @@ -430,12 +440,12 @@ let fslibEntityRefEq fslibCcu (eref1: EntityRef) (eref2: EntityRef) = | ERefNonLocal nlr1, ERefLocal x2 | ERefLocal x2, ERefNonLocal nlr1 -> ccuEq nlr1.Ccu fslibCcu && - match x2.PublicPath with - | Some pp2 -> fslibRefEq nlr1 pp2 - | None -> false + match x2.PublicPath with + | ValueSome pp2 -> fslibRefEq nlr1 pp2 + | ValueNone -> false | ERefLocal e1, ERefLocal e2 -> - match e1.PublicPath, e2.PublicPath with - | Some pp1, Some pp2 -> pubPathEq pp1 pp2 + match e1.PublicPath, e2.PublicPath with + | ValueSome pp1, ValueSome pp2 -> pubPathEq pp1 pp2 | _ -> false | _ -> false diff --git a/src/Compiler/TypedTree/TypedTreeOps.Attributes.fs b/src/Compiler/TypedTree/TypedTreeOps.Attributes.fs index 771f6036e25..3210c1714e2 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.Attributes.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.Attributes.fs @@ -255,8 +255,8 @@ module internal AttributeHelpers = struct (ValueSome nlr.Path, ValueNone) elif g.compilingFSharpCore then match tcref.Deref.PublicPath with - | Some(PubPath pp) -> struct (ValueNone, ValueSome pp) - | None -> struct (ValueNone, ValueNone) + | ValueSome pubpath -> struct (ValueNone, ValueSome pubpath.FullPath) + | ValueNone -> struct (ValueNone, ValueNone) else struct (ValueNone, ValueNone) diff --git a/src/Compiler/TypedTree/TypedTreeOps.ExprConstruction.fs b/src/Compiler/TypedTree/TypedTreeOps.ExprConstruction.fs index 7cd2846f7ca..5c0763f2216 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.ExprConstruction.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.ExprConstruction.fs @@ -596,8 +596,8 @@ module internal TypeTesters = /// Try to create a EntityRef suitable for accessing the given Entity from another assembly let tryRescopeEntity viewedCcu (entity: Entity) : EntityRef voption = match entity.PublicPath with - | Some pubpath -> ValueSome(ERefNonLocal(rescopePubPath viewedCcu pubpath)) - | None -> ValueNone + | ValueSome pubpath -> ValueSome(ERefNonLocal(rescopePubPath viewedCcu pubpath)) + | ValueNone -> ValueNone /// Try to create a ValRef suitable for accessing the given Val from another assembly let tryRescopeVal viewedCcu (entityRemap: Remap) (vspec: Val) : ValRef voption = diff --git a/src/Compiler/TypedTree/TypedTreeOps.FreeVars.fs b/src/Compiler/TypedTree/TypedTreeOps.FreeVars.fs index 50f7af9014b..975ff6cfb3a 100644 --- a/src/Compiler/TypedTree/TypedTreeOps.FreeVars.fs +++ b/src/Compiler/TypedTree/TypedTreeOps.FreeVars.fs @@ -1313,18 +1313,20 @@ module internal MemberRepresentation = let layoutOfPath p = sepListL SepL.dot (List.map (tagNamespace >> wordL) p) - let fullNameOfParentOfPubPath pp = - match pp with - | PubPath([| _ |]) -> ValueNone - | pp -> ValueSome(textOfPath pp.EnclosingPath) + let fullNameOfParentOfPubPath (pp: PublicPath) = + if pp.HasEmptyEnclosingPath then + ValueNone + else + ValueSome(textOfPath pp.EnclosingPath) - let fullNameOfParentOfPubPathAsLayout pp = - match pp with - | PubPath([| _ |]) -> ValueNone - | pp -> ValueSome(layoutOfPath (Array.toList pp.EnclosingPath)) + let fullNameOfParentOfPubPathAsLayout (pp: PublicPath) = + if pp.HasEmptyEnclosingPath then + ValueNone + else + ValueSome(layoutOfPath pp.EnclosingCompilationPath.MangledPath) - let fullNameOfPubPath (PubPath p) = textOfPath p - let fullNameOfPubPathAsLayout (PubPath p) = layoutOfPath (Array.toList p) + let fullNameOfPubPath (pp: PublicPath) = textOfPath pp.FullPath + let fullNameOfPubPathAsLayout (pp: PublicPath) = layoutOfPath (Array.toList pp.FullPath) let fullNameOfParentOfNonLocalEntityRef (nlr: NonLocalEntityRef) = if nlr.Path.Length < 2 then @@ -1342,16 +1344,16 @@ module internal MemberRepresentation = match eref with | ERefLocal x -> match x.PublicPath with - | None -> ValueNone - | Some ppath -> fullNameOfParentOfPubPath ppath + | ValueNone -> ValueNone + | ValueSome ppath -> fullNameOfParentOfPubPath ppath | ERefNonLocal nlr -> fullNameOfParentOfNonLocalEntityRef nlr let fullNameOfParentOfEntityRefAsLayout eref = match eref with | ERefLocal x -> match x.PublicPath with - | None -> ValueNone - | Some ppath -> fullNameOfParentOfPubPathAsLayout ppath + | ValueNone -> ValueNone + | ValueSome ppath -> fullNameOfParentOfPubPathAsLayout ppath | ERefNonLocal nlr -> fullNameOfParentOfNonLocalEntityRefAsLayout nlr let fullNameOfEntityRef nmF xref = @@ -1529,8 +1531,8 @@ module internal MemberRepresentation = match tcref with | ERefLocal _ -> (match tcref.PublicPath with - | None -> [||] - | Some pp -> pp.EnclosingPath) + | ValueNone -> [||] + | ValueSome pp -> pp.EnclosingPath) | ERefNonLocal nlr -> nlr.EnclosingMangledPath /// generates a name like 'System.IComparable.Get' diff --git a/src/Compiler/TypedTree/TypedTreePickle.fs b/src/Compiler/TypedTree/TypedTreePickle.fs index 90bb7e9482f..921f194ce34 100644 --- a/src/Compiler/TypedTree/TypedTreePickle.fs +++ b/src/Compiler/TypedTree/TypedTreePickle.fs @@ -200,7 +200,7 @@ type ReaderState = ivals: NodeInTable ianoninfos: NodeInTable istrings: InputTable - ipubpaths: InputTable + ipubpaths: InputTable inlerefs: InputTable isimpletys: InputTable ifile: string @@ -869,12 +869,12 @@ let p_ccuref s st = p_int (encode_ccuref st.occus s) st // References to public items in this module // A huge number of these occur in pickled F# data, so make them unique let decode_pubpath st stringTab a = - PubPath(Array.map (lookup_string st stringTab) a) + Array.map (lookup_string st stringTab) a let u_encoded_pubpath = u_array u_int let u_pubpath st = lookup_uniq st st.ipubpaths (u_int st) -let encode_pubpath stringTab pubpathTab (PubPath a) = +let encode_pubpath stringTab pubpathTab (a: string[]) = encode_uniq pubpathTab (Array.map (encode_string stringTab) a) let p_encoded_pubpath = p_array p_int @@ -897,7 +897,7 @@ let encode_nleref ccuTab stringTab nlerefTab thisCcu (nleref: NonLocalEntityRef) // References to these nodes _do_ appear in F# assembly metadata, because they may be public. let nleref = match nleref.Deref.PublicPath with - | Some pubpath when nleref.Deref.IsProvidedGeneratedTycon -> + | ValueSome pubpath when nleref.Deref.IsProvidedGeneratedTycon -> if verbose then dprintfn "remapping pickled reference to provider-generated type %s" nleref.Deref.DisplayNameWithStaticParameters @@ -2818,7 +2818,11 @@ and p_entity_spec_data (x: Entity) st = p_string x.entity_logical_name st p_option p_string x.EntityCompiledName st p_range x.entity_range st - p_option p_pubpath x.entity_pubpath st + let pubPathOpt = + match x.PublicPath with + | ValueSome pubpath -> Some pubpath.FullPath + | ValueNone -> None + p_option p_pubpath pubPathOpt st p_access x.Accessibility st p_access x.TypeReprAccessibility st p_attribs (x.entity_attribs.AsList()) st @@ -3147,7 +3151,7 @@ and u_rfield_table st = Construct.MakeRecdFieldsTable(u_list u_recdfield_spec st) and u_entity_spec_data st : Entity = - let x1, x2a, x2b, x2c, x3, (x4a, x4b), x6, x7f, x8, x9, _x10, x10b, x11, x12, x13, x14, x15 = + let x1, x2a, x2b, x2c, _x3, (x4a, x4b), x6, x7f, x8, x9, _x10, x10b, x11, x12, x13, x14, x15 = u_tup17 u_tyar_specs u_string @@ -3176,7 +3180,6 @@ and u_entity_spec_data st : Entity = entity_stamp = newStamp () entity_logical_name = x2a entity_range = x2c - entity_pubpath = x3 entity_attribs = WellKnownEntityAttribs.Create(x6) entity_tycon_repr = x7 entity_tycon_tcaug = x9