Page: the host checks text before it runs
Job: explanation
Level: mid grug (level 2 of 6)
Source lines:
SageFs.FsiHost/FcsQueries.fs:47#checkWithSymbolsSageFs.FsiHost/FcsQueries.fs:71#evalConfig
the host checks text before it runs
this page says why the code has this shape and what a reader must be careful of.
grug measure SageFs.FsiHost/FcsQueries.fs:
- reflection in 1 place(s) (line 104): reflection reads types while the program runs, so the compiler does not check what it does
this sign only tells grug where to look. open the file and look before grug says the demon is there.
why this exists
The point of SageFS is feedback on an edit you have not saved. The FSI host takes the text, asks the compiler to parse and check it, and turns diagnostics into wire values. keeps symbols for the dependency graph, and SageFs.FsiHost/FcsQueries.fs:47#checkWithSymbols uses the same compiler session for configuration text.SageFs.FsiHost/FcsQueries.fs:71#evalConfig
run sed -n '71,82p' SageFs.FsiHost/FcsQueries.fs
It prints:
let evalConfig (session: FsiEvaluationSession) (content: string) : ConfigOutcome =
try
session.EvalInteractionNonThrowing "open SageFs;;" |> ignore
let result, diagnostics = session.EvalExpressionNonThrowing content
let errors = diagnostics |> Array.filter (fun d -> d.Severity = FSharpDiagnosticSeverity.Error)
match errors.Length > 0 with
| true -> ConfigRejected(ConfigDoesNotCompile(errors |> Array.map toWire |> Array.toList))
| false ->
match result with
| Choice1Of2(Some value) ->
match value.ReflectionValue with
| :? DirectoryConfig as config -> ConfigEvaluated config
The cited file SageFs.FsiHost/FcsQueries.fs ships with this site at the same path. Run the command from the school folder, or open SageFs.FsiHost/FcsQueries.fs.
what breaks
If the host checked only saved files, the feedback loop would follow the editor's save button. If it skipped the check phase, diagnostics would arrive after evaluation instead of before it.
where it fits
Live test routing decides which session a changed file reaches. This host decides what that session learns about the text before it evaluates it.
try it
Run the grep above from this repository root. Then type a bad symbol into an unsaved buffer. The diagnostic comes from this path, before any evaluation result is shown.
reference: every connection to this page
This is reference. The next page in the reading order is at the bottom of the page.
path order: repo paths are found at runtime
flowchart LR A0["repo paths are found at runtime"] H["you are here: the host checks text before it runs"] A0 --> H
grill: say it out loud, then tap
Grug asks. Say the answer out loud, then tap. Grug remembers what you miss and asks again in the pop quiz.
a badge says two things: the number is its level, the colour is the kind of answer it asks for. The six levels are level 1 of 6 recall a fact; level 2 of 6 recall a detail; level 3 of 6 trace a path; level 4 of 6 trace a longer path; level 5 of 6 predict or judge; level 6 of 6 judge a transfer. Colour and level are independent: a high-level question can still ask for a fact, and the colour tells you which it is.
try first, then show answer
3. The text sent from the editor buffer
The host receives the editor text directly, so a file need not be saved before the compiler sees it.
try first, then show answer
checkWithSymbols
checkWithSymbols returns diagnostics plus the symbol references the live dependency graph uses.
try first, then show answer
3. After parse and check, before evaluation
Parse and check run on the supplied text first, so diagnostics arrive before evaluation results.
try first, then show answer
grep -n 'let check (' SageFs.FsiHost/FcsQueries.fs
The grep in the lesson prints the exact declaration line for the check door.