Skip to content

Instantly share code, notes, and snippets.

@vzarytovskii
Created June 28, 2023 14:20
Show Gist options
  • Save vzarytovskii/106b3b3ae3fb2a1a25f90543a67df41d to your computer and use it in GitHub Desktop.
Save vzarytovskii/106b3b3ae3fb2a1a25f90543a67df41d to your computer and use it in GitHub Desktop.
let getTypeCheck (syntaxTree: SyntaxTree) : NodeCode<TypeCheck> =
node {
let! input, _sourceRange, fileName, parseErrors = syntaxTree.ParseNode.GetOrComputeValue()
use _ = Activity.start "BoundModel.TypeCheck" [| Activity.Tags.fileName, fileName |]
IncrementalBuilderEventTesting.MRU.Add(IncrementalBuilderEventTesting.IBETypechecked fileName)
let capturingDiagnosticsLogger = CapturingDiagnosticsLogger("TypeCheck")
let diagnosticsLogger = GetDiagnosticsLoggerFilteringByScopedPragmas(false, input.ScopedPragmas, tcConfig.diagnosticsOptions, capturingDiagnosticsLogger)
use _ = new CompilationGlobalsScope(diagnosticsLogger, BuildPhase.TypeCheck)
beforeFileChecked.Trigger fileName
ApplyMetaCommandsFromInputToTcConfig (tcConfig, input, Path.GetDirectoryName fileName, tcImports.DependencyProvider) |> ignore
let sink = TcResultsSinkImpl(tcGlobals)
let hadParseErrors = not (Array.isEmpty parseErrors)
let input, moduleNamesDict = DeduplicateParsedInputModuleName prevTcInfo.moduleNamesDict input
let! (tcEnvAtEndOfFile, topAttribs, implFile, ccuSigForFile), tcState =
CheckOneInput (
(fun () -> hadParseErrors || diagnosticsLogger.ErrorCount > 0),
tcConfig, tcImports,
tcGlobals,
None,
TcResultsSink.WithSink sink,
prevTcInfo.tcState, input )
fileChecked.Trigger fileName
let newErrors = Array.append parseErrors (capturingDiagnosticsLogger.Diagnostics |> List.toArray)
let tcEnvAtEndOfFile = if keepAllBackgroundResolutions then tcEnvAtEndOfFile else tcState.TcEnvFromImpls
let tcInfo =
{
tcState = tcState
tcEnvAtEndOfFile = tcEnvAtEndOfFile
moduleNamesDict = moduleNamesDict
latestCcuSigForFile = Some ccuSigForFile
tcDiagnosticsRev = newErrors :: prevTcInfo.tcDiagnosticsRev
topAttribs = Some topAttribs
tcDependencyFiles = fileName :: prevTcInfo.tcDependencyFiles
sigNameOpt =
match input with
| ParsedInput.SigFile sigFile ->
Some(sigFile.FileName, sigFile.QualifiedName)
| _ ->
None
}
return tcInfo, sink, implFile, fileName, newErrors
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment