Skip to content

Commit c1d6fc8

Browse files
auduchinokbaronfel
authored andcommitted
Make ILPreTypeDef interface (#7649)
1 parent 9adbbe8 commit c1d6fc8

File tree

3 files changed

+38
-27
lines changed

3 files changed

+38
-27
lines changed

src/absil/il.fs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,26 +2133,33 @@ and [<Sealed>] ILTypeDefs(f : unit -> ILPreTypeDef[]) =
21332133
let ns, n = splitILTypeName nm
21342134
dict.Value.[(ns, n)].GetTypeDef()
21352135

2136+
2137+
and [<NoEquality; NoComparison>] ILPreTypeDef =
2138+
abstract Namespace: string list
2139+
abstract Name: string
2140+
abstract GetTypeDef: unit -> ILTypeDef
2141+
2142+
21362143
/// This is a memory-critical class. Very many of these objects get allocated and held to represent the contents of .NET assemblies.
2137-
and [<Sealed>] ILPreTypeDef(nameSpace: string list, name: string, metadataIndex: int32, storage: ILTypeDefStored) =
2144+
and [<Sealed>] ILPreTypeDefImpl(nameSpace: string list, name: string, metadataIndex: int32, storage: ILTypeDefStored) =
21382145
let mutable store : ILTypeDef = Unchecked.defaultof<_>
21392146

2140-
member __.Namespace = nameSpace
2141-
member __.Name = name
2142-
member __.MetadataIndex = metadataIndex
2147+
interface ILPreTypeDef with
2148+
member __.Namespace = nameSpace
2149+
member __.Name = name
21432150

2144-
member x.GetTypeDef() =
2145-
match box store with
2146-
| null ->
2147-
match storage with
2148-
| ILTypeDefStored.Given td ->
2149-
store <- td
2150-
td
2151-
| ILTypeDefStored.Computed f ->
2152-
LazyInitializer.EnsureInitialized<ILTypeDef>(&store, Func<_>(fun () -> f()))
2153-
| ILTypeDefStored.Reader f ->
2154-
LazyInitializer.EnsureInitialized<ILTypeDef>(&store, Func<_>(fun () -> f x.MetadataIndex))
2155-
| _ -> store
2151+
member x.GetTypeDef() =
2152+
match box store with
2153+
| null ->
2154+
match storage with
2155+
| ILTypeDefStored.Given td ->
2156+
store <- td
2157+
td
2158+
| ILTypeDefStored.Computed f ->
2159+
LazyInitializer.EnsureInitialized<ILTypeDef>(&store, Func<_>(fun () -> f()))
2160+
| ILTypeDefStored.Reader f ->
2161+
LazyInitializer.EnsureInitialized<ILTypeDef>(&store, Func<_>(fun () -> f metadataIndex))
2162+
| _ -> store
21562163

21572164
and ILTypeDefStored =
21582165
| Given of ILTypeDef
@@ -2491,11 +2498,11 @@ let mkRefForNestedILTypeDef scope (enc: ILTypeDef list, td: ILTypeDef) =
24912498

24922499
let mkILPreTypeDef (td: ILTypeDef) =
24932500
let ns, n = splitILTypeName td.Name
2494-
ILPreTypeDef (ns, n, NoMetadataIdx, ILTypeDefStored.Given td)
2501+
ILPreTypeDefImpl (ns, n, NoMetadataIdx, ILTypeDefStored.Given td) :> ILPreTypeDef
24952502
let mkILPreTypeDefComputed (ns, n, f) =
2496-
ILPreTypeDef (ns, n, NoMetadataIdx, ILTypeDefStored.Computed f)
2503+
ILPreTypeDefImpl (ns, n, NoMetadataIdx, ILTypeDefStored.Computed f) :> ILPreTypeDef
24972504
let mkILPreTypeDefRead (ns, n, idx, f) =
2498-
ILPreTypeDef (ns, n, idx, f)
2505+
ILPreTypeDefImpl (ns, n, idx, f) :> ILPreTypeDef
24992506

25002507

25012508
let addILTypeDef td (tdefs: ILTypeDefs) = ILTypeDefs (fun () -> [| yield mkILPreTypeDef td; yield! tdefs.AsArrayOfPreTypeDefs |])

src/absil/il.fsi

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,12 +1322,16 @@ and [<NoComparison; NoEquality>]
13221322
/// The information is enough to perform name resolution for the F# compiler, probe attributes
13231323
/// for ExtensionAttribute etc. This is key to the on-demand exploration of .NET metadata.
13241324
/// This information has to be "Goldilocks" - not too much, not too little, just right.
1325-
and [<NoEquality; NoComparison; Sealed>] ILPreTypeDef =
1326-
member Namespace: string list
1327-
member Name: string
1328-
member MetadataIndex: int32
1325+
and [<NoEquality; NoComparison>] ILPreTypeDef =
1326+
abstract Namespace: string list
1327+
abstract Name: string
13291328
/// Realise the actual full typedef
1330-
member GetTypeDef : unit -> ILTypeDef
1329+
abstract GetTypeDef : unit -> ILTypeDef
1330+
1331+
1332+
and [<NoEquality; NoComparison; Sealed>] ILPreTypeDefImpl =
1333+
interface ILPreTypeDef
1334+
13311335

13321336
and [<Sealed>] ILTypeDefStored
13331337

src/fsharp/import.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ and ImportILTypeDefList amap m (cpath: CompilationPath) enc items =
478478
let modty = lazy (ImportILTypeDefList amap m (cpath.NestedCompPath n Namespace) enc tgs)
479479
NewModuleOrNamespace (Some cpath) taccessPublic (mkSynId m n) XmlDoc.Empty [] (MaybeLazy.Lazy modty))
480480
(fun (n, info: Lazy<_>) ->
481-
let (scoref2, _, lazyTypeDef: ILPreTypeDef) = info.Force()
481+
let (scoref2, lazyTypeDef: ILPreTypeDef) = info.Force()
482482
ImportILTypeDef amap m scoref2 cpath enc n (lazyTypeDef.GetTypeDef()))
483483

484484
let kind = match enc with [] -> Namespace | _ -> ModuleOrType
@@ -489,7 +489,7 @@ and ImportILTypeDefList amap m (cpath: CompilationPath) enc items =
489489
and ImportILTypeDefs amap m scoref cpath enc (tdefs: ILTypeDefs) =
490490
// We be very careful not to force a read of the type defs here
491491
tdefs.AsArrayOfPreTypeDefs
492-
|> Array.map (fun pre -> (pre.Namespace, (pre.Name, notlazy(scoref, pre.MetadataIndex, pre))))
492+
|> Array.map (fun pre -> (pre.Namespace, (pre.Name, notlazy(scoref, pre))))
493493
|> Array.toList
494494
|> ImportILTypeDefList amap m cpath enc
495495

@@ -519,7 +519,7 @@ let ImportILAssemblyExportedType amap m auxModLoader (scoref: ILScopeRef) (expor
519519
| None ->
520520
error(Error(FSComp.SR.impReferenceToDllRequiredByAssembly(exportedType.ScopeRef.QualifiedName, scoref.QualifiedName, exportedType.Name), m))
521521
| Some preTypeDef ->
522-
scoref, -1, preTypeDef)
522+
scoref, preTypeDef)
523523

524524
[ ImportILTypeDefList amap m (CompPath(scoref, [])) [] [(ns, (n, info))] ]
525525

0 commit comments

Comments
 (0)