Simulate NLL and Polonius Alpha borrowck - #411
Merged
Merged
Conversation
Collaborator
|
Thanks for contributing to formality! :) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
- Add PoloniusUnlocked feature gate - Redo borrowck with all outlives for NLL - Port rustc tests where polonius alpha differs from nll or legacy - In nll and alpha, consider place prefix as live - Do not add function def places as live - Kill loans from dropped locals - Add outlives constraints for reborrows - Verify universal outlives constraints for all outlives in alpha
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
requested changes
Jul 22, 2026
| // Prescan for locals declared in this list so that later uses of | ||
| // those names are treated as locals, not fn names. (This slightly | ||
| // over-approximates scope — a name is treated as local even before | ||
| // its `let` — which errs toward marking places live.) |
Contributor
There was a problem hiding this comment.
I---- oh, we do some kind of "simple name resolution" here, I guess?
nikomatsakis
approved these changes
Jul 24, 2026
Merged
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.
Background and Motivation
As we move towards stabilization of Polonius Alpha in rustc, we want to be confident in its soundness. formality already has an existing borrow-checker, although in many ways is both closer to an "ideal" borrow checker, but is also incomplete in some areas of the language, e.g. opaque types.
In the rustc test suite, we have a number of tests that are specifically different between NLL, Polonius Alpha, and Polonius Legacy. These specifically highlight the differences between these three borrow-checking modes.
In this PR, those tests are ported to formality tests. Further, feature gating is done to match formality's borrow-checking modes to rustc's - along with a few other minor adjustments to bring consistency with rustc.
A non-goal of this work is to model any one complete borrow-checker for all language features (including those not yet modeled by formality). Specifically, the ported tests are sufficient to model the differences between the existing NLL and the soon-to-be-stabilized Polonius Alpha. It is possible that unimplemented language features interact in significant ways with the model - but the idea is that those differences are likely downstream of the differences visible under the ported tests. So, aligning with rustc for the currently-implemented language features is enough for us to reason about the soundness of Polonius Alpha.
What this PR does
existsboundaries)<TypeckEnv as Debug>not printProgramThis is a little unfortunate on performance, because it essentially duplicates all borrow checking - because we need a first pass just to collect outlives constraints. There are a couple alternatives, I think:
trigger_bugissue_46589_trigger_bugremove_last_node_recursiveissue_63908_remove_last_node_recursiveremove_last_node_iterativeissue_63908_remove_last_node_iterativeno_control_flowissue_57165_no_control_flowconditionalissue_57165_conditionalconditional_with_indirectionissue_57165_conditional_with_indirectionto_refsissue_46859_to_refsto_refs2issue_46859_to_refs2to_refs3(need to PR)issue_46859_to_refs3Decoder::nextissue_46859_decoder_nextFilter::nextissue_92985_filtering_lending_iteratoruse_itflow_sensitive_invariance_use_ituse_it_but_its_the_same_regionflow_sensitive_invariance_same_regionflow_sensitive_invariance_use_bothissue_70044_location_insensitive_constraintsAI disclosure