Skip to content

Commit 53f83b0

Browse files
committed
avoid eager dereferencing when building globals
1 parent ddd76ba commit 53f83b0

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

src/fsharp/CompileOps.fs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3793,10 +3793,6 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
37933793
| None -> false
37943794
| None -> false
37953795

3796-
member tcImports.SetBase(baseTcImports) =
3797-
CheckDisposed()
3798-
importsBase <- Some(baseTcImports)
3799-
38003796
member private tcImports.Base =
38013797
CheckDisposed()
38023798
importsBase
@@ -4078,7 +4074,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
40784074
| None ->
40794075
match importsBase with
40804076
| Some b -> b.GetTcGlobals()
4081-
| None -> failwith "unreachable: GetGlobals - are the references to mscorlib.dll and FSharp.Core.dll valid?"
4077+
| None -> failwith (sprintf "unreachable: GetGlobals - are the references to mscorlib.dll and FSharp.Core.dll valid? STACK: \n%s" ((System.Diagnostics.StackTrace()).ToString()))
40824078

40834079
member private tcImports.SetILGlobals ilg =
40844080
CheckDisposed()

src/fsharp/CompileOps.fsi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ type TcAssemblyResolutions =
598598
type TcImports =
599599
interface System.IDisposable
600600
//new : TcImports option -> TcImports
601-
member SetBase : TcImports -> unit
602601
member DllTable : NameMap<ImportedBinary> with get
603602
member GetImportedAssemblies : unit -> ImportedAssembly list
604603
member GetCcusInDeclOrder : unit -> CcuThunk list

src/fsharp/TcGlobals.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,25 +1336,31 @@ let mkTcGlobals (compilingFslib,sysCcu,ilg,fslibCcu,directoryToResolveRelativePa
13361336
// the TyconRef's we have in our hands, hence we can't dereference them to find their stamps.
13371337

13381338
// So this dictionary is indexed by names.
1339+
//
1340+
// Make it lazy to avoid dereferencing while setting up the base imports.
13391341
let dict =
1342+
lazy
13401343
entries
13411344
|> List.map (fun (nm,tcref,builder) -> nm, (fun tcref2 tinst -> if tyconRefEq tcref tcref2 then Some(builder tinst) else None))
13421345
|> Dictionary.ofList
13431346
(fun tcref tinst ->
1344-
if dict.ContainsKey tcref.LogicalName then dict.[tcref.LogicalName] tcref tinst
1347+
if dict.Value.ContainsKey tcref.LogicalName then dict.Value.[tcref.LogicalName] tcref tinst
13451348
else None )
13461349
else
13471350
// This map is for use in normal times (not building FSharp.Core.dll). It is indexed by tcref stamp which is
13481351
// faster than the indexing technique used in the case above.
13491352
//
13501353
// So this dictionary is indexed by integers.
1354+
//
1355+
// Make it lazy to avoid dereferencing while setting up the base imports.
13511356
let dict =
1357+
lazy
13521358
entries
13531359
|> List.filter (fun (_,tcref,_) -> tcref.CanDeref)
13541360
|> List.map (fun (_,tcref,builder) -> tcref.Stamp, builder)
13551361
|> Dictionary.ofList
13561362
(fun tcref2 tinst ->
1357-
if dict.ContainsKey tcref2.Stamp then Some(dict.[tcref2.Stamp] tinst)
1363+
if dict.Value.ContainsKey tcref2.Stamp then Some(dict.Value.[tcref2.Stamp] tinst)
13581364
else None)
13591365
end
13601366

tests/service/Common.fs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ let mkProjectCommandLineArgs (dllName, fileNames) =
6767
yield "--noframework"
6868
yield "--debug:full"
6969
yield "--define:DEBUG"
70-
//#if NETCOREAPP1_0
70+
#if NETCOREAPP1_0
7171
yield "--targetprofile:netcore"
72-
//#endif
72+
#endif
7373
yield "--optimize-"
7474
yield "--out:" + dllName
7575
yield "--doc:test.xml"
@@ -103,9 +103,9 @@ let mkProjectCommandLineArgsForScript (dllName, fileNames) =
103103
yield "--noframework"
104104
yield "--debug:full"
105105
yield "--define:DEBUG"
106-
//#if NETCOREAPP1_0
106+
#if NETCOREAPP1_0
107107
yield "--targetprofile:netcore"
108-
//#endif
108+
#endif
109109
yield "--optimize-"
110110
yield "--out:" + dllName
111111
yield "--doc:test.xml"
@@ -115,15 +115,12 @@ let mkProjectCommandLineArgsForScript (dllName, fileNames) =
115115
yield "--target:library"
116116
for x in fileNames do
117117
yield x
118-
let implDir = Path.GetDirectoryName(typeof<System.Object>.Assembly.Location)
118+
// let implDir = Path.GetDirectoryName(typeof<System.Object>.Assembly.Location)
119119
let references =
120-
[ yield Path.Combine(implDir,"mscorlib.dll");
121-
yield Path.Combine(implDir,"System.Private.CoreLib.dll");
122-
yield! Path.Combine(__SOURCE_DIRECTORY__, "../projects/Sample_NETCoreSDK_FSharp_Library_netstandard1.6/obj/Debug/netstandard1.6/dotnet-compile-fsc.rsp")
123-
|> File.ReadAllLines
124-
|> Array.filter (fun s -> s.StartsWith("-r:"))
125-
|> Array.map (fun s -> s.Replace("-r:",""))
126-
|> Array.map (fun s -> Path.Combine(implDir,s)) ]
120+
Path.Combine(__SOURCE_DIRECTORY__, "../projects/Sample_NETCoreSDK_FSharp_Library_netstandard1.6/obj/Debug/netstandard1.6/dotnet-compile-fsc.rsp")
121+
|> File.ReadAllLines
122+
|> Array.filter (fun s -> s.StartsWith("-r:"))
123+
|> Array.map (fun s -> s.Replace("-r:",""))
127124
for r in references do
128125
yield "-r:" + r
129126
|]

0 commit comments

Comments
 (0)