Skip to content

Name uniquify scopes after statements, not positions (#1303) - #1312

Merged
jsiek merged 1 commit into
mainfrom
issue-1303-stable-scopes
Nov 20, 2026
Merged

jsiek merged 1 commit into
mainfrom
issue-1303-stable-scopes

Conversation

@jsiek

@jsiek jsiek commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Fixes #1303.

Example

The issue's repro, three theorems and then a new theorem added at the top:

before:  new theorem at top   {'hits': {}, 'misses': {'type_check': 4, 'check_proofs': 4}}
after:   new theorem at top   {'hits': {'type_check': 3, 'check_proofs': 3}, 'misses': {'type_check': 1, 'check_proofs': 1}}

The bound variable pP in theorem t1 used to be pP.s0_1. It is now pP.2t1_1 wherever t1 sits in the file.

Changes

  • abstract_syntax/ops.py: uniquify_deduce names each statement's scope segment after the statement, not its index (_statement_scope). The segment is <len><key><count>_, where:
    • the key is the statement's name, or its lowercased kind for unnamed statements (assert, print, ...), which can't collide with identifiers;
    • the count tells apart statements with the same key, so two assert statements are 6assert_ and 6assert1_;
    • the length prefix keeps segments distinct from one another, including the scopes made by nesting them (an imported module inside its import).
  • checker_cache.py: every statement that is not a plain named definition (_NAME_ONLY_STATEMENTS) is now a barrier for the check_proofs cache too, as it already was for the type-check cache.
    • Before, deleting a statement renamed everything after it, which happened to invalidate everything after it.
    • That hid a gap, caught by test/lsp/test_warm_check.py::test_user_inductive_does_not_leak_into_later_checks: deleting inductive TwoList by tl_induction left the theorem that relies on it a cache hit, because Inductive wasn't a barrier. Views and associative were in the same position.

Fixtures

Regenerated the ones that print unique names:

Tests

  • test/lsp/test_check_proofs_cache.py: inserting or deleting a theorem leaves the others hits.
  • test/lsp/test_uniquify_determinism.py: the scope test now uses the new segments, plus a new test that inserting a statement keeps the others' names and that two asserts get distinct scopes.

make static, test-deduce.py and pytest test/lsp test/unit (1321 passed) all pass.

make tests-compile fails on main and on this branch in the same three places. All are already tracked: source_map.pf (#1309), ViewDecl (#1211) and ConceptDecl (#1292). run_lower.py passes apart from source_map.pf, and run_separate.py passes.

🤖 Generated with Claude Code

uniquify_deduce gave each top-level statement the scope s<index>_, so
inserting or deleting a statement renamed every statement after it and
both per-statement caches missed on all of them. The segment is now
<len><name><count>_ (the keyword for an unnamed statement), so the
others keep their names.

Removing a statement used to invalidate everything after it as a side
effect, which hid that the check_proofs cache did not treat
(and views, , ...) as barriers. Every statement that is not
a plain named definition is now a barrier for both caches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jsiek
jsiek marked this pull request as ready for review November 20, 2026 15:44
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T15:46:40.749900Z 301b253 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jsiek
jsiek merged commit e935249 into main Nov 20, 2026
15 checks passed
@jsiek
jsiek deleted the issue-1303-stable-scopes branch November 20, 2026 15:51
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.

Inserting a top-level statement renames every later statement, defeating the per-statement caches

1 participant