Skip to content

Commit 75e435e

Browse files
authored
Use Roslyn for backing metadata bytes in VS (#4586)
* weak ByteFile * cleanup, only use in VS * cleanup flags * some comments * some comments * use Roslyn memory manager for metadata in VS * report statistics only with --times, clarify flags2 * minor updates * us in VS * fix build * fix build * fix build * add SFH to FileSystem * fix build * fix build * fix build * fix build * add some comments
1 parent 3273ed0 commit 75e435e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1904
-1475
lines changed

fcs/build.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let isMono = false
2424
// Utilities
2525
// --------------------------------------------------------------------------------------
2626

27-
let dotnetExePath = DotNetCli.InstallDotNetSDK "2.1.4"
27+
let dotnetExePath = DotNetCli.InstallDotNetSDK "2.1.100"
2828

2929
let runDotnet workingDir args =
3030
let result =

src/absil/il.fs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,7 @@ type MethodBody =
13241324
| PInvoke of PInvokeMethod (* platform invoke to native *)
13251325
| Abstract
13261326
| Native
1327+
| NotAvailable
13271328

13281329
type ILLazyMethodBody =
13291330
| ILLazyMethodBody of Lazy<MethodBody >
@@ -1859,7 +1860,8 @@ type ILResourceAccess =
18591860

18601861
[<RequireQualifiedAccess>]
18611862
type ILResourceLocation =
1862-
| Local of (unit -> byte[])
1863+
| LocalIn of string * int * int
1864+
| LocalOut of byte[]
18631865
| File of ILModuleRef * int32
18641866
| Assembly of ILAssemblyRef
18651867

@@ -1868,15 +1870,16 @@ type ILResource =
18681870
Location: ILResourceLocation;
18691871
Access: ILResourceAccess;
18701872
CustomAttrs: ILAttributes }
1871-
/// Read the bytes from a resource local to an assembly
1872-
member r.Bytes =
1873-
match r.Location with
1874-
| ILResourceLocation.Local b -> b()
1875-
| _ -> failwith "Bytes"
1873+
member r.GetBytes() =
1874+
match r.Location with
1875+
| ILResourceLocation.LocalIn (file, start, len) ->
1876+
FileSystem.ReadAllBytesShim(file).[start .. start + len - 1]
1877+
| ILResourceLocation.LocalOut bytes -> bytes
1878+
| _ -> failwith "GetBytes"
18761879

18771880
type ILResources =
1878-
| ILResources of Lazy<ILResource list>
1879-
member x.AsList = let (ILResources ltab) = x in (ltab.Force())
1881+
| ILResources of ILResource list
1882+
member x.AsList = let (ILResources ltab) = x in ltab
18801883

18811884
// --------------------------------------------------------------------
18821885
// One module in the "current" assembly
@@ -1912,6 +1915,11 @@ type ILAssemblyManifest =
19121915
EntrypointElsewhere: ILModuleRef option
19131916
}
19141917

1918+
[<RequireQualifiedAccess>]
1919+
type ILNativeResource =
1920+
| In of fileName: string * linkedResourceBase: int * linkedResourceStart: int * linkedResourceLength: int
1921+
| Out of unlinkedResource: byte[]
1922+
19151923
type ILModuleDef =
19161924
{ Manifest: ILAssemblyManifest option
19171925
CustomAttrs: ILAttributes
@@ -1923,7 +1931,7 @@ type ILModuleDef =
19231931
SubSystemFlags: int32
19241932
IsDLL: bool
19251933
IsILOnly: bool
1926-
Platform: ILPlatform option
1934+
Platform: ILPlatform option
19271935
StackReserveSize: int32 option
19281936
Is32Bit: bool
19291937
Is32BitPreferred: bool
@@ -1933,7 +1941,7 @@ type ILModuleDef =
19331941
ImageBase: int32
19341942
MetadataVersion: string
19351943
Resources: ILResources
1936-
NativeResources: list<Lazy<byte[]>> (* e.g. win32 resources *)
1944+
NativeResources: ILNativeResource list (* e.g. win32 resources *)
19371945
}
19381946
member x.ManifestOfAssembly =
19391947
match x.Manifest with
@@ -2515,6 +2523,9 @@ let mkMethodBody (zeroinit,locals,maxstack,code,tag) = MethodBody.IL (mkILMethod
25152523

25162524
let mkILVoidReturn = mkILReturn ILType.Void
25172525

2526+
let methBodyNotAvailable = mkMethBodyAux MethodBody.NotAvailable
2527+
let methBodyAbstract = mkMethBodyAux MethodBody.Abstract
2528+
let methBodyNative = mkMethBodyAux MethodBody.Native
25182529

25192530
let mkILCtor (access,args,impl) =
25202531
ILMethodDef(name=".ctor",
@@ -2764,8 +2775,7 @@ let mkILNestedExportedTypes l =
27642775
let mkILNestedExportedTypesLazy (l:Lazy<_>) =
27652776
ILNestedExportedTypes (lazy (List.foldBack addNestedExportedTypeToTable (l.Force()) Map.empty))
27662777

2767-
let mkILResources l = ILResources (notlazy l)
2768-
let mkILResourcesLazy l = ILResources l
2778+
let mkILResources l = ILResources l
27692779

27702780
let addMethodImplToTable y tab =
27712781
let key = (y.Overrides.MethodRef.Name,y.Overrides.MethodRef.ArgTypes.Length)
@@ -3751,7 +3761,8 @@ and refs_of_exported_types s (tab: ILExportedTypesAndForwarders) = List.iter (re
37513761

37523762
and refs_of_resource_where s x =
37533763
match x with
3754-
| ILResourceLocation.Local _ -> ()
3764+
| ILResourceLocation.LocalIn _ -> ()
3765+
| ILResourceLocation.LocalOut _ -> ()
37553766
| ILResourceLocation.File (mref,_) -> refs_of_modref s mref
37563767
| ILResourceLocation.Assembly aref -> refs_of_assref s aref
37573768

src/absil/il.fsi

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,7 @@ type MethodBody =
988988
| PInvoke of PInvokeMethod (* platform invoke to native *)
989989
| Abstract
990990
| Native
991+
| NotAvailable
991992

992993
// REVIEW: fold this into ILMethodDef.
993994
[<RequireQualifiedAccess>]
@@ -1426,8 +1427,16 @@ type ILResourceAccess =
14261427

14271428
[<RequireQualifiedAccess>]
14281429
type ILResourceLocation =
1429-
| Local of (unit -> byte[]) (* resources may be re-read each time this function is called *)
1430+
/// Represents a manifest resource that can be read from within the PE file
1431+
| LocalIn of string * int * int
1432+
1433+
/// Represents a manifest resource that is due to be written to the output PE file
1434+
| LocalOut of byte[]
1435+
1436+
/// Represents a manifest resource in an associated file
14301437
| File of ILModuleRef * int32
1438+
1439+
/// Represents a manifest resource in a different assembly
14311440
| Assembly of ILAssemblyRef
14321441

14331442
/// "Manifest ILResources" are chunks of resource data, being one of:
@@ -1439,8 +1448,9 @@ type ILResource =
14391448
Location: ILResourceLocation
14401449
Access: ILResourceAccess
14411450
CustomAttrs: ILAttributes }
1442-
/// Read the bytes from a resource local to an assembly
1443-
member Bytes: byte[]
1451+
1452+
/// Read the bytes from a resource local to an assembly. Will fail for non-local resources.
1453+
member GetBytes : unit -> byte[]
14441454

14451455
/// Table of resources in a module.
14461456
[<NoEquality; NoComparison>]
@@ -1487,7 +1497,15 @@ type ILAssemblyManifest =
14871497
/// Records whether the entrypoint resides in another module.
14881498
EntrypointElsewhere: ILModuleRef option
14891499
}
1490-
1500+
1501+
[<RequireQualifiedAccess>]
1502+
type ILNativeResource =
1503+
/// Represents a native resource to be read from the PE file
1504+
| In of fileName: string * linkedResourceBase: int * linkedResourceStart: int * linkedResourceLength: int
1505+
1506+
/// Represents a native resource to be written in an output file
1507+
| Out of unlinkedResource: byte[]
1508+
14911509
/// One module in the "current" assembly, either a main-module or
14921510
/// an auxiliary module. The main module will have a manifest.
14931511
///
@@ -1512,9 +1530,9 @@ type ILModuleDef =
15121530
PhysicalAlignment: int32
15131531
ImageBase: int32
15141532
MetadataVersion: string
1515-
Resources: ILResources
1516-
/// e.g. win86 resources, as the exact contents of a .res or .obj file.
1517-
NativeResources: Lazy<byte[]> list }
1533+
Resources: ILResources
1534+
/// e.g. win86 resources, as the exact contents of a .res or .obj file. Must be unlinked manually.
1535+
NativeResources: ILNativeResource list }
15181536
member ManifestOfAssembly: ILAssemblyManifest
15191537
member HasManifest: bool
15201538

@@ -1749,6 +1767,9 @@ val mkILEmptyGenericParams: ILGenericParameterDefs
17491767
/// Make method definitions.
17501768
val mkILMethodBody: initlocals:bool * ILLocals * int * ILCode * ILSourceMarker option -> ILMethodBody
17511769
val mkMethodBody: bool * ILLocals * int * ILCode * ILSourceMarker option -> MethodBody
1770+
val methBodyNotAvailable: ILLazyMethodBody
1771+
val methBodyAbstract: ILLazyMethodBody
1772+
val methBodyNative: ILLazyMethodBody
17521773

17531774
val mkILCtor: ILMemberAccess * ILParameter list * MethodBody -> ILMethodDef
17541775
val mkILClassCtor: MethodBody -> ILMethodDef
@@ -1863,7 +1884,6 @@ val mkILExportedTypes: ILExportedTypeOrForwarder list -> ILExportedTypesAndForwa
18631884
val mkILExportedTypesLazy: Lazy<ILExportedTypeOrForwarder list> -> ILExportedTypesAndForwarders
18641885

18651886
val mkILResources: ILResource list -> ILResources
1866-
val mkILResourcesLazy: Lazy<ILResource list> -> ILResources
18671887

18681888
/// Making modules.
18691889
val mkILSimpleModule: assemblyName:string -> moduleName:string -> dll:bool -> subsystemVersion: (int * int) -> useHighEntropyVA: bool -> ILTypeDefs -> int32 option -> string option -> int -> ILExportedTypesAndForwarders -> string -> ILModuleDef

0 commit comments

Comments
 (0)