Skip to content
This repository has been archived by the owner on Jul 19, 2019. It is now read-only.

Commit

Permalink
Keep source hashes through watch compilations
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro authored and ncave committed Feb 22, 2019
1 parent e3c9888 commit c761b9b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions fcs/FSharp.Compiler.Service/service_slim.fs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type InteractiveChecker internal (tcConfig, tcGlobals, tcImports, tcInitialState
let tcInitialEnv = GetInitialTcEnv (assemblyName, rangeStartup, tcConfig, tcImports, tcGlobals)
let tcInitialState = GetInitialTcState (rangeStartup, assemblyName, tcConfig, tcGlobals, tcImports, niceNameGen, tcInitialEnv)

let reactorOps =
let reactorOps =
{ new IReactorOperations with
member __.EnqueueAndAwaitOpAsync (userOpName, opName, opArg, op) =
async.Return (Cancellable.runWithoutCancellation (op ctok))
Expand Down Expand Up @@ -115,11 +115,11 @@ type InteractiveChecker internal (tcConfig, tcGlobals, tcImports, tcInitialState
// restore all cached typecheck entries above file
cachedAbove |> Array.iter (fun (key, value) -> checkCache.TryAdd(key, value) |> ignore)

member private x.ParseFile (fileName: string, source: string, parsingOptions: FSharpParsingOptions) =
let parseCacheKey = fileName, hash source
member private x.ParseFile (fileName: string, sourceHash: int, source: Lazy<string>, parsingOptions: FSharpParsingOptions) =
let parseCacheKey = fileName, sourceHash
parseCache.GetOrAdd(parseCacheKey, fun _ ->
x.ClearStaleCache(fileName, parsingOptions)
let parseErrors, parseTreeOpt, anyErrors = Parser.parseFile (source, fileName, parsingOptions, userOpName)
let parseErrors, parseTreeOpt, anyErrors = Parser.parseFile (source.Value, fileName, parsingOptions, userOpName)
let dependencyFiles = [||] // interactions have no dependencies
FSharpParseFileResults (parseErrors, parseTreeOpt, anyErrors, dependencyFiles) )

Expand Down Expand Up @@ -196,11 +196,12 @@ type InteractiveChecker internal (tcConfig, tcGlobals, tcImports, tcInitialState
/// Parses and checks the whole project, good for compilers (Fable etc.)
/// Does not retain name resolutions and symbol uses which are quite memory hungry (so no intellisense etc.).
/// Already parsed files will be cached so subsequent compilations will be faster.
member x.ParseAndCheckProject (projectFileName: string, fileNames: string[], sources: string[]) =
member x.ParseAndCheckProject (projectFileName: string, fileNames: string[], sourceReader: string->int*Lazy<string>) =
// parse files
let parsingOptions = FSharpParsingOptions.FromTcConfig(tcConfig, fileNames, false)
let parseFile (fileName, source) = x.ParseFile (fileName, source, parsingOptions)
let parseResults = Array.zip fileNames sources |> Array.map parseFile
let parseResults = fileNames |> Array.map (fun fileName ->
let sourceHash, source = sourceReader fileName
x.ParseFile(fileName, sourceHash, source, parsingOptions))

// type check files
let tcState, topAttrs, tcImplFiles, _tcEnvAtEnd, _moduleNamesDict, tcErrors =
Expand All @@ -227,7 +228,7 @@ type InteractiveChecker internal (tcConfig, tcGlobals, tcImports, tcInitialState

// parse files before file
let parsingOptions = FSharpParsingOptions.FromTcConfig(tcConfig, fileNames, false)
let parseFile (fileName, source) = x.ParseFile (fileName, source, parsingOptions)
let parseFile (fileName, source) = x.ParseFile (fileName, hash source, lazy source, parsingOptions)
let parseResults = Array.zip fileNamesBeforeFile sourcesBeforeFile |> Array.map parseFile

// type check files before file
Expand Down

0 comments on commit c761b9b

Please sign in to comment.