Repository navigation
Cache type checking per statement (#1301) - #1305
Merged
Merged
Conversation
check_deduce caches each statement's type check per module, keyed by its structural hash and a fingerprint of what it depends on: the statements defining the names it mentions (transitively, and every candidate of an overloaded name) plus every statement that is not a plain named definition (views, models, associative, imports, ...). A statement that only moved reuses its entry with its own locations shifted. Statements whose check reported an error or warning are not cached, and the postulate report bypasses the cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jsiek
marked this pull request as ready for review
November 20, 2026 13:47
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c28eec1e90
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Two files with the same base name share a module name, so a check of one could reuse the other's checked statements, which still name the first file (Codex review on #1305). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1301.
Example
checker_cache.get_cache_stats()on a warm LSP re-check oftest/should-validate/IntTests.pf:Warm
lsp.query.checktimes (steady-state runs, no profiler):test/should-validate/IntTests.pftest/should-validate/doc_reference.pfHow it works
check_deducenow keeps, per module, the type-checked statements of its last check (checker_cache._type_check_cache).Key: the statement's structural hash (
_hash_ast, location-free) andtype_check_fingerprints, which folds in:fun f(x : M)usestype M = NandMchanges toK, then a theorem that only mentionsfis re-checked;_collect_referenced_namesnow adds all ofOverloadedVar.resolved_names; before, it added only the first;associative,auto, imports, ...). Those are found by type or have file-wide effects, and type checking uses the whole file's env.Moved statements: the entry also stores the statement's layout (its locations relative to where it starts) and its start. If a statement has the same hash and layout but starts elsewhere,
_relocatedshifts the cached statement's own locations (lines and character positions) to where it is now. A theorem takes its proof from the fresh parse, since type checking passes proofs through unchanged.Not cached:
Memory: each check replaces the module's entries with the ones it used or created, so the cache holds one file per module.
Known limitations
test_moving_statements_apart_rechecks_one_carrying_anothers_location.check_proofscache. Filed as Inserting a top-level statement renames every later statement, defeating the per-statement caches #1303.Tests
New
test/lsp/test_type_check_cache.pycovers:auto);goal_atin a moved theorem.test/lsp/test_snapshot.pynow expects the type-check miss in its exact stats.make static,test-deduce.py(260 s, the same as before, so no cost for CLI runs) andpytest test/lsp test/unit(1319 passed after rebasing on #1300) all pass.🤖 Generated with Claude Code