Skip to content

Commit

Permalink
Shim/file system: fix the shim is captured during the analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
auduchinok committed Dec 13, 2024
1 parent ccc9c7b commit 2bb09cd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Compiler/Driver/fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,10 @@ let main6
DoesNotRequireCompilerThreadTokenAndCouldPossiblyBeMadeConcurrent ctok

let pdbfile =
pdbfile |> Option.map (tcConfig.MakePathAbsolute >> FileSystem.GetFullPathShim)
pdbfile |> Option.map (fun s ->
let absolutePath = tcConfig.MakePathAbsolute s
FileSystem.GetFullPathShim(absolutePath)
)

let normalizeAssemblyRefs (aref: ILAssemblyRef) =
match tcImports.TryFindDllInfo(ctok, rangeStartup, aref.Name, lookupOnly = false) with
Expand Down
8 changes: 7 additions & 1 deletion src/Compiler/TypedTree/TcGlobals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,14 @@ type TcGlobals(

let mkSourceDoc fileName = ILSourceDocument.Create(language=None, vendor=None, documentType=None, file=fileName)

let compute i =
let path = fileOfFileIndex i
let fullPath = FileSystem.GetFullFilePathInDirectoryShim directoryToResolveRelativePaths path
mkSourceDoc fullPath

// Build the memoization table for files
let v_memoize_file = MemoizationTable<int, ILSourceDocument>((fileOfFileIndex >> FileSystem.GetFullFilePathInDirectoryShim directoryToResolveRelativePaths >> mkSourceDoc), keyComparer=HashIdentity.Structural)
let v_memoize_file =
MemoizationTable<int, ILSourceDocument>(compute, keyComparer = HashIdentity.Structural)

let v_and_info = makeIntrinsicValRef(fslib_MFIntrinsicOperators_nleref, CompileOpName "&" , None , None , [], mk_rel_sig v_bool_ty)
let v_addrof_info = makeIntrinsicValRef(fslib_MFIntrinsicOperators_nleref, CompileOpName "~&" , None , None , [vara], ([[varaTy]], mkByrefTy varaTy))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ let getResolver () =
|]

let rooted, unrooted =
references |> Array.partition (fst >> FileSystem.IsPathRootedShim)
references |> Array.partition (fun (path, _) -> FileSystem.IsPathRootedShim(path))

let rootedResults =
ResolveCore(
Expand Down
18 changes: 18 additions & 0 deletions tests/FSharp.Compiler.Service.Tests/FileSystemTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,21 @@ let ``FileSystem compilation test``() =
results.AssemblySignature.Entities.Count |> shouldEqual 2
results.AssemblySignature.Entities[0].MembersFunctionsAndValues.Count |> shouldEqual 1
results.AssemblySignature.Entities[0].MembersFunctionsAndValues[0].DisplayName |> shouldEqual "B"

let checkEmptyScriptWithFsShim () =
let shim = DefaultFileSystem()
let ref: WeakReference = WeakReference(shim)

use _ = useFileSystemShim shim
getParseAndCheckResults "" |> ignore

ref

[<Fact>]
let ``File system shim should not leak`` () =
let shimRef = checkEmptyScriptWithFsShim ()

GC.Collect()
GC.WaitForPendingFinalizers()

Assert.False(shimRef.IsAlive)

0 comments on commit 2bb09cd

Please sign in to comment.