-
Notifications
You must be signed in to change notification settings - Fork 90
Open
Labels
Description
From here: dotnet/fsharp#5930 (comment)
The following code ends up reading all of FSharp.Core.dll and one of mscorlib.dll/system.runtime.dll/netstandard.dll into byte arrays upon type provider instantiation:
FSharp.TypeProviders.SDK/src/ProvidedTypes.fs
Lines 8572 to 8608 in 6d90bfc
| let systemRuntimeScopeRef = | |
| lazy | |
| referencedAssemblyPaths |> List.tryPick (fun path -> | |
| try | |
| let simpleName = Path.GetFileNameWithoutExtension path | |
| if simpleName = "mscorlib" || simpleName = "System.Runtime" || simpleName = "netstandard" then | |
| let reader = ILModuleReaderAfterReadingAllBytes (path, mkILGlobals EcmaMscorlibScopeRef) | |
| let mdef = reader.ILModuleDef | |
| match mdef.TypeDefs.TryFindByName(USome "System", "Object") with | |
| | None -> None | |
| | Some _ -> | |
| let m = mdef.ManifestOfAssembly | |
| let assRef = ILAssemblyRef(m.Name, UNone, (match m.PublicKey with USome k -> USome (PublicKey.KeyAsToken(k)) | UNone -> UNone), m.Retargetable, m.Version, m.Locale) | |
| Some (ILScopeRef.Assembly assRef) | |
| else | |
| None | |
| with _ -> None ) | |
| |> function | |
| | None -> EcmaMscorlibScopeRef // failwith "no reference to mscorlib.dll or System.Runtime.dll or netstandard.dll found" | |
| | Some r -> r | |
| let fsharpCoreRefVersion = | |
| lazy | |
| referencedAssemblyPaths |> List.tryPick (fun path -> | |
| try | |
| let simpleName = Path.GetFileNameWithoutExtension path | |
| if simpleName = "FSharp.Core" then | |
| let reader = ILModuleReaderAfterReadingAllBytes (path, mkILGlobals (systemRuntimeScopeRef.Force())) | |
| match reader.ILModuleDef.Manifest with | |
| | Some m -> match m.Version with USome v -> Some v | UNone -> None | |
| | None -> None | |
| else | |
| None | |
| with _ -> None ) | |
| |> function | |
| | None -> typeof<int list>.Assembly.GetName().Version // failwith "no reference to FSharp.Core found" | |
| | Some r -> r |
This work is unnecessary because the F# compiler already knows this information. However, changing this would require work both in here and the compiler. Perhaps there's a cheaper way than allocating multiple MB on the LOH?