Skip to content

Commit 0e240cd

Browse files
authored
Fix ilread cache (#1605)
While working on FSharp.Compiler.Service for .NET Core I noticed that there is a flaw in the cache used for IL readers in ilread.fs: the cache key should include the primary assembly name (i.e. the cache could incorrectly confuse mscorlib-based interpretations of assemblies with System.Runtime-based interpretations). For example this could repro in situations where Visual Studio was being used to edit a mix of projects using both System.Runtime Profiles and mscorlib profiles. This is significant enough that we need to integrate the fix back into this repo. * fix ilread cache * fix build
1 parent f6b3c33 commit 0e240cd

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/fsharp/CompileOps.fs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3713,10 +3713,6 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
37133713
| None -> false
37143714
| None -> false
37153715

3716-
member tcImports.SetBase(baseTcImports) =
3717-
CheckDisposed()
3718-
importsBase <- Some(baseTcImports)
3719-
37203716
member private tcImports.Base =
37213717
CheckDisposed()
37223718
importsBase

src/fsharp/CompileOps.fsi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ type TcAssemblyResolutions =
582582
type TcImports =
583583
interface System.IDisposable
584584
//new : TcImports option -> TcImports
585-
member SetBase : TcImports -> unit
586585
member DllTable : NameMap<ImportedBinary> with get
587586
member GetImportedAssemblies : unit -> ImportedAssembly list
588587
member GetCcusInDeclOrder : unit -> CcuThunk list

src/fsharp/TcGlobals.fs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,25 +1336,35 @@ 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+
let dict = dict.Value
1348+
let key = tcref.LogicalName
1349+
if dict.ContainsKey key then dict.[key] tcref tinst
13451350
else None )
13461351
else
13471352
// This map is for use in normal times (not building FSharp.Core.dll). It is indexed by tcref stamp which is
13481353
// faster than the indexing technique used in the case above.
13491354
//
13501355
// So this dictionary is indexed by integers.
1356+
//
1357+
// Make it lazy to avoid dereferencing while setting up the base imports.
13511358
let dict =
1359+
lazy
13521360
entries
13531361
|> List.filter (fun (_,tcref,_) -> tcref.CanDeref)
13541362
|> List.map (fun (_,tcref,builder) -> tcref.Stamp, builder)
13551363
|> Dictionary.ofList
13561364
(fun tcref2 tinst ->
1357-
if dict.ContainsKey tcref2.Stamp then Some(dict.[tcref2.Stamp] tinst)
1365+
let dict = dict.Value
1366+
let key = tcref2.Stamp
1367+
if dict.ContainsKey key then Some(dict.[key] tinst)
13581368
else None)
13591369
end
13601370

0 commit comments

Comments
 (0)