Skip to content

fix: track init and move in borrowck#372

Open
acegikmoo wants to merge 2 commits into
rust-lang:mainfrom
acegikmoo:borrowck
Open

fix: track init and move in borrowck#372
acegikmoo wants to merge 2 commits into
rust-lang:mainfrom
acegikmoo:borrowck

Conversation

@acegikmoo
Copy link
Copy Markdown

@acegikmoo acegikmoo commented Jun 1, 2026

What does this PR do?

This pr is the implementation of approach-1 in the zulip chat, similar what we do in the compiler. This adds a Set<PlaceExpr> to the flow state that tracks which places are uninitialized. It's a forward analysis in terms of approach-2(liveness) and it uses union at joins.

related issue #296

How does it work, what questions do you have?

Tracks Set<PlaceExpr> of uninitialized places in PointFlowState.uninit. Union at control-flow joins.
On access: check_place_initialized fails if any prefix or sub-path is in the set.
On assignment: check_place_writable fails if a strict prefix is in the set, then marks LHS initialized.
On move: marks the place uninit.
On no init: marks uninit.

Questions:

  1. move_in_loop still ignored- some direction on handling that would be appreciated

AI disclosure

  • used to understand the codebase, improve naming and to keep comments consistent to the codebase

Signed-off-by: acegikmoo <rubairakib11@gmail.com>
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 1, 2026

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (NB. this repo may be misconfigured) some time within the next two weeks.

@acegikmoo
Copy link
Copy Markdown
Author

r? nikomatsakis

Copy link
Copy Markdown
Member

@tiif tiif left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! I left some suggestions.

View changes since this review

Comment thread crates/formality-rust/src/check/borrow_check/flow_state.rs Outdated
Comment thread crates/formality-rust/src/check/borrow_check/flow_state.rs
Comment on lines +230 to +241
pub fn with_initialized(&self, place: &PlaceExpr) -> Self {
let mut this = self.clone();
this.current.mark_initialized(place);
this
}

pub fn with_uninit(&self, place: &PlaceExpr) -> Self {
let mut this = self.clone();
this.current.mark_uninit(place);
this
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would it be better if we just call this.current.mark_initializeddirectly at the call site?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

maybe, idk, i think as they follow the same pattern as with_loan, with_outlives, with_break, etc its bit consistent to the codebase. Also its not costing us anything either way.

if you still prefer it, it's pretty straightforward ig and i can take the stab

Comment thread crates/formality-rust/src/check/borrow_check/nll.rs Outdated
Signed-off-by: acegikmoo <rubairakib11@gmail.com>
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.

4 participants