Skip to content

Let a cancel stop a running type check - #3441

Open
plajjan wants to merge 1 commit into
mainfrom
cancel-type-check
Open

plajjan wants to merge 1 commit into
mainfrom
cancel-type-check

Conversation

@plajjan

@plajjan plajjan commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Stage threads run masked, and the parse and type check passes never block, so a cancel waited until a running check finished. In the LSP server and acton watch, every edit made during a long type check blocked until then.

The parse and check passes now run interruptible, so a cancel stops them where they are. The .tydb commit, the outputs and the module cache update stay masked.

startCompile cancels the previous generation's run, and the run's
finalizer cancels its running stages. Stage threads start under the
coordinator's mask and inherit it. So do the threads that a stage
starts, such as the type checker's workers and its progress reporter.
A masked thread receives a cancel only where it blocks. The parse and
the front passes are pure evaluation, forced with evaluate and force,
and do not block.

A stage's parse now runs under interruptible. So does the checking part
of its front passes: building the environment, kinds, types, forcing
the type check's results, escape analysis and hashing. interruptible
unmasks only these passes, and every thread they start inherits the
unmasked state. What a stage commits keeps the coordinator's mask: the
.tydb, the doc and --tydb copy outputs, and the module cache entry.
That masked region runs from the .tydb commit through the cache update
with no unmasked gap in between. The front stage of a cached module
whose dependencies changed parses the source again, and that parse
also runs under interruptible.

Before: the LSP server and acton watch call startCompile on every edit
or save. startCompile holds the scheduler's MVar while it cancels the
previous run, and the cancel waited until every running parse and type
check of that run had finished. An edit made during a long type check
blocked the LSP handler or watch for the rest of that check, before
the debounce delay even started. stopCompile, and a failed front stage
that cancels its dependents' parse stages, waited the same way.

After: a cancel stops running parse and check passes where they are.
startCompile returns without waiting for them, and the debounce starts
at once.

Unchanged: a run still waits for every background output its stages
started before it ends, and a stale generation still writes nothing.
A stage's commit keeps the coordinator's mask, so a cancel still
reaches it only where it blocks.

Test 61 in the incremental suite fails without this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant