Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Compiler/Service/TransparentCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type internal BootstrapInfo =

LoadClosure: LoadClosure option
LastFileName: string
ImportsInvalidatedByTypeProvider: Event<unit>
}

type internal TcIntermediateResult = TcInfo * TcResultsSinkImpl * CheckedImplFile option * string
Expand Down Expand Up @@ -742,9 +743,10 @@ type internal TransparentCompiler

/// Bootstrap info that does not depend source files
let ComputeBootstrapInfoStatic (projectSnapshot: ProjectCore, tcConfig: TcConfig, assemblyName: string, loadClosureOpt) =
let cacheKey = projectSnapshot.CacheKeyWith("BootstrapInfoStatic", assemblyName)

caches.BootstrapInfoStatic.Get(
projectSnapshot.CacheKeyWith("BootstrapInfoStatic", assemblyName),
cacheKey,
node {
use _ =
Activity.start
Expand Down Expand Up @@ -816,6 +818,14 @@ type internal TransparentCompiler

let bootstrapId = Interlocked.Increment &BootstrapInfoIdCounter

importsInvalidatedByTypeProvider.Publish.Add(fun () ->
// caches.BootstrapInfoStatic.Clear()
// caches.BootstrapInfo.Clear()
caches.Clear(Set.singleton projectSnapshot.Identifier)
// TODO: Should we clear more caches?
// caches.BootstrapInfoStatic.Clear(fun kv -> kv = cacheKey.GetKey())
)

return bootstrapId, tcImports, tcGlobals, initialTcInfo, importsInvalidatedByTypeProvider
}
)
Expand Down Expand Up @@ -865,7 +875,7 @@ type internal TransparentCompiler
let tcConfig = TcConfig.Create(tcConfigB, validate = true)
let outFile, _, assemblyName = tcConfigB.DecideNames sourceFiles

let! bootstrapId, tcImports, tcGlobals, initialTcInfo, _importsInvalidatedByTypeProvider =
let! bootstrapId, tcImports, tcGlobals, initialTcInfo, importsInvalidatedByTypeProvider =
ComputeBootstrapInfoStatic(projectSnapshot.ProjectCore, tcConfig, assemblyName, loadClosureOpt)

// Check for the existence of loaded sources and prepend them to the sources list if present.
Expand All @@ -889,7 +899,7 @@ type internal TransparentCompiler
LoadedSources = loadedSources
LoadClosure = loadClosureOpt
LastFileName = sourceFiles |> List.tryLast |> Option.defaultValue ""
//ImportsInvalidatedByTypeProvider = importsInvalidatedByTypeProvider
ImportsInvalidatedByTypeProvider = importsInvalidatedByTypeProvider
}
}

Expand Down Expand Up @@ -1732,7 +1742,6 @@ type internal TransparentCompiler
| None, creationDiags ->
return FSharpCheckProjectResults(projectSnapshot.ProjectFileName, None, keepAssemblyContents, creationDiags, None)
| Some bootstrapInfo, creationDiags ->

let! snapshotWithSources = LoadSources bootstrapInfo projectSnapshot

let! tcInfo, ilAssemRef, assemblyDataResult, checkedImplFiles = ComputeProjectExtras bootstrapInfo snapshotWithSources
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Service/TransparentCompiler.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ type internal BootstrapInfo =
InitialTcInfo: TcInfo
LoadedSources: (range * ProjectSnapshot.FSharpFileSnapshot) list
LoadClosure: LoadClosure option
LastFileName: string }
LastFileName: string
ImportsInvalidatedByTypeProvider: Event<unit> }

type internal TcIntermediateResult = TcInfo * TcResultsSinkImpl * CheckedImplFile option * string

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,8 @@ module Stuff =
/// References projects are expected to have been built.
let localResponseFiles =
[|
@"C:\Projects\fantomas\src\Fantomas.Core.Tests\Fantomas.Core.Tests.rsp"
// @"C:\Projects\fantomas\src\Fantomas.Core.Tests\Fantomas.Core.Tests.rsp"
@"C:\Users\nojaf\Projects\TypeProviderSample\TypeProviderSample.rsp"
|]
|> Array.collect (fun f ->
[|
Expand All @@ -815,7 +816,7 @@ let localResponseFiles =
)

// Uncomment this attribute if you want run this test against local response files.
// [<Theory>]
[<Theory>]
[<MemberData(nameof(localResponseFiles))>]
let ``TypeCheck last file in project with transparent compiler`` useTransparentCompiler responseFile =
let responseFile = FileInfo responseFile
Expand All @@ -837,9 +838,23 @@ let ``TypeCheck last file in project with transparent compiler`` useTransparentC
| None -> failwithf "Last file of project could not be found"
| Some lastFile ->

let updatedSource = "
open FSharp.Data

type Simple = JsonProvider<\"\"\" { \"name\":\"John\", \"level\": \"s\" } \"\"\">
let simple = Simple.Parse(\"\"\" { \"name\":\"Tomas\", \"level\": \"a\" } \"\"\")

ignore (simple.Level, simple.Name)

// For more information see https://aka.ms/fsharp-console-apps
printfn \"Hello from F#\"
"

workflow {
clearCache
checkFile lastFile expectOk
updateFile lastFile (fun sf -> { sf with Source = updatedSource})
checkFile lastFile expectOk
}

[<Fact>]
Expand Down