Skip to content

Introduce a "scope" mechanism to judgments and use for binder instantiation - #463

Merged
nikomatsakis merged 2 commits into
mainfrom
judgment-scope
Oct 16, 2026
Merged

nikomatsakis merged 2 commits into
mainfrom
judgment-scope

Conversation

@jackh726

@jackh726 jackh726 commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

This introduces a new scope(...) primitive to judgement functions, which effectively function like a closure. This can allow us to run some code when we exit that scope.

AI disclosure

  • I used an AI to author the main logic of the code

@rustbot

rustbot commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks for contributing to formality! :)
A reviewer will take a look at your PR within a week or two. If not, come talk to us on https://rust-lang.zulipchat.com/#narrow/channel/402470-t-types.2Fformality

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@nikomatsakis

Copy link
Copy Markdown
Contributor

My thoughts:I really like the scope mechanism. Quite nice. I'd like to see it factored out into its own PR that we can land first, that should be relatively easy to merge, and then to look more closely at the follow-up changes.

@nikomatsakis nikomatsakis left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel Jack about splitting out the generalized mechanism from the semantic changes?

View changes since this review

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@nikomatsakis nikomatsakis left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a change to document this in the mdbook; otherwise looks good!

View changes since this review

jackh726 and others added 2 commits October 16, 2026 09:10
A rule can prove some of its conditions inside a scope:

    (
        (scope(enter_forall(env, binder) => (env, body)) with(c)
            (prove(env, body) => c))
        --------------------
        (prove(env, Goal::ForAll(binder)) => c)
    )

* The expression enters the scope. It evaluates to a pair: the scope, and
  what is inside it, which the pattern binds for the nested conditions.
  Like any other condition's expression, it may fail; the rule then does
  not apply.
* Those bindings, and any the nested conditions make, end with the
  `scope` condition.
* Only the `with` variables come out. Each proof of the nested conditions
  leaves the scope with its values for them (`Scope::leave`), and the
  rest of the rule sees what that yields.

So a rule cannot forget to leave a scope, nor use what was inside it
afterwards.
@rustbot

rustbot commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@nikomatsakis
nikomatsakis added this pull request to the merge queue Oct 16, 2026
Merged via the queue into main with commit e0b0c69 Oct 16, 2026
6 checks passed
@jackh726
jackh726 deleted the judgment-scope branch October 16, 2026 14:06
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.

3 participants