Skip to content

Commit

Permalink
FSI: make scripting temp directory one per session instead of global (#…
Browse files Browse the repository at this point in the history
…17760)

* make scripting temp per session

* release notes
  • Loading branch information
majocha committed Sep 18, 2024
1 parent f564cc9 commit 5f958fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@
* Optimize ILTypeDef interface impls reading from metadata. ([PR #17382](https://github.com/dotnet/fsharp/pull/17382))
* Make ILTypeDef interface impls calculation lazy. ([PR #17392](https://github.com/dotnet/fsharp/pull/17392))
* Better error reporting for active patterns. ([PR #17666](https://github.com/dotnet/fsharp/pull/17666))
* Multiple fsi sessions use separate temporary directories ([PR #17760](https://github.com/dotnet/fsharp/pull/17760))

### Breaking Changes
57 changes: 28 additions & 29 deletions src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,34 +1675,6 @@ let internal mkBoundValueTypedImpl tcGlobals m moduleName name ty =
let qname = QualifiedNameOfFile.QualifiedNameOfFile(Ident(moduleName, m))
entity, v, CheckedImplFile.CheckedImplFile(qname, [], mty, contents, false, false, StampMap.Empty, Map.empty)

let scriptingSymbolsPath =
let createDirectory (path: string) =
lazy
try
if not (Directory.Exists(path)) then
Directory.CreateDirectory(path) |> ignore

path
with _ ->
path

createDirectory (Path.Combine(Path.GetTempPath(), $"{DateTime.Now:s}-{Guid.NewGuid():n}".Replace(':', '-')))

let deleteScriptingSymbols () =
try
#if !DEBUG
if scriptingSymbolsPath.IsValueCreated then
if Directory.Exists(scriptingSymbolsPath.Value) then
Directory.Delete(scriptingSymbolsPath.Value, true)
#else
()
#endif
with _ ->
()

AppDomain.CurrentDomain.ProcessExit
|> Event.add (fun _ -> deleteScriptingSymbols ())

let dynamicCcuName = "FSI-ASSEMBLY"

/// Encapsulates the coordination of the typechecking, optimization and code generation
Expand Down Expand Up @@ -1764,6 +1736,33 @@ type internal FsiDynamicCompiler

let reportedAssemblies = Dictionary<string, DateTime>()

let scriptingSymbolsPath =
let createDirectory (path: string) =
try
if not (Directory.Exists(path)) then
Directory.CreateDirectory(path) |> ignore

path
with _ ->
path

createDirectory (Path.Combine(Path.GetTempPath(), $"{DateTime.Now:s}-{Guid.NewGuid():n}".Replace(':', '-')))

let deleteScriptingSymbols () =
try
#if !DEBUG
if Directory.Exists(scriptingSymbolsPath) then
Directory.Delete(scriptingSymbolsPath, true)
#else
()
#endif
with _ ->
()

do
AppDomain.CurrentDomain.ProcessExit
|> Event.add (fun _ -> deleteScriptingSymbols ())

/// Add attributes
let CreateModuleFragment (tcConfigB: TcConfigBuilder, dynamicCcuName, codegenResults) =
if progress then
Expand Down Expand Up @@ -1841,7 +1840,7 @@ type internal FsiDynamicCompiler
{
ilg = tcGlobals.ilg
outfile = $"{multiAssemblyName}-{dynamicAssemblyId}.dll"
pdbfile = Some(Path.Combine(scriptingSymbolsPath.Value, $"{multiAssemblyName}-{dynamicAssemblyId}.pdb"))
pdbfile = Some(Path.Combine(scriptingSymbolsPath, $"{multiAssemblyName}-{dynamicAssemblyId}.pdb"))
emitTailcalls = tcConfig.emitTailcalls
deterministic = tcConfig.deterministic
portablePDB = true
Expand Down

0 comments on commit 5f958fb

Please sign in to comment.