Skip to content

fix: binder shadowing in Veil elaboration - #192

Draft
dranov wants to merge 8 commits into
mainfrom
codex/binding-shadowing-tests
Draft

dranov wants to merge 8 commits into
mainfrom
codex/binding-shadowing-tests

Conversation

@dranov

@dranov dranov commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #180.

Core problem

A ghost definition could resolve an explicit parameter to a same-named theory or state field. The definition still elaborated, so invariant checking and symbolic traces could use a different predicate from the one the author wrote.

Wider problem

User names and generated names shared the same lookup scope. A local could hide a field needed to reconstruct the state for a ghost call, and a generated binder such as st0 could hide a field in a symbolic query.

This PR fixes the two remaining cases reported in #156. A theory field named st could break invariant elaboration, and a state field named st' could break transition elaboration. The original has, hinv, and core fixes are already on main through #157 and #160.

How the fix works

  • Give generated code private references to the actual theory and state fields. User-facing names resolve in binding order from theory fields to state fields, parameters, and lexical locals. Later binders take precedence, and Veil warns on shadowing.
  • Use the private field references for implicit ghost arguments and transition framing. Mentioning a primed field still marks it as changed.
  • Give generated binders fresh names where they surround user terms, including in temporal formulas, symbolic traces, and IC3.
  • Pass Lean’s optional expected type through the field-view elaborator. An unannotated ghost function can infer its return type from its body, and an annotated function can use its declared type during elaboration.

Simplifications

  • Use one pass over Lean’s elaborated binders for local shadowing warnings and reuse the field lookup for action parameter warnings.
  • Share batched field binding between actions and declarative terms, and share symbolic transition binder generation between sat trace and IC3.
  • Remove the old framing macro and the unused existential representation of trace binders.

Validation

  • Added regressions for ghost parameter capture, implicit ghost arguments, transitions, temporal properties, generated-name collisions in traces and IC3, unannotated List.foldl, and contextual typing.
  • Verified the original has, hinv, and core cases on the PR head. The st and st' cases fail on the pre-PR control and pass on this branch, including #check_invariants.
  • lake --no-cache build VeilTest Examples passed all 1,620 jobs. CI passed on Linux and macOS.

@dranov dranov linked an issue Nov 21, 2026 that may be closed by this pull request
@dranov
dranov requested a review from zqy1018 November 21, 2026 04:12
@dranov
dranov marked this pull request as ready for review November 21, 2026 04:12
@dranov
dranov marked this pull request as draft November 21, 2026 04:38
@dranov
dranov added this pull request to stack #198 November 21, 2026 04:39
@dranov
dranov force-pushed the codex/binding-shadowing-tests branch from 82c1504 to 76eed06 Compare November 21, 2026 05:23
@zqy1018

zqy1018 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Is this (together with the PRs on top of it) ready for review?

@dranov

dranov commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

@zqy1018 Not yet, I'll ping you when it is.

@dranov dranov changed the title Fix binder shadowing in Veil elaboration fix: binder shadowing in Veil elaboration Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants