Skip to content

replace TypingEnv::post_analysis() with mir::Body::typing_env() - #164077

Open
adwinwhite wants to merge 1 commit into
rust-lang:mainfrom
adwinwhite:phase-hack
Open

adwinwhite wants to merge 1 commit into
rust-lang:mainfrom
adwinwhite:phase-hack

Conversation

@adwinwhite

@adwinwhite adwinwhite commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Similar to #163745

We should discourage constructing a typing env by hand when it can be derived from context.
This simplifies reasoning and reduces the mistake of not resetting rigidness markers across typing envs.

This PR adds an field to mir::Body to track the typing mode.

r? lcnr

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 10, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

match self.phase {
MirPhase::Built | MirPhase::Analysis(_) => TypingEnv::new(
match self.typing_mode {
BodyTypingMode::Borrowck | BodyTypingMode::PostBorrowck => TypingEnv::new(

@lcnr lcnr Oct 12, 2026 •

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.

when do we encounter this?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The initial mode is BodyTypingMode::Borrowck. After mir_borrowck, we set it to PostBorrowck.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

promote_consts pass would use BodyTypingMode::Borrowck since it's run before borrowck.

/// us to see the difference and forego optimization on the inlined promoted items.
pub phase: MirPhase,

pub typing_mode: BodyTypingMode,

@lcnr lcnr Oct 12, 2026 •

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.

comment please :>

View changes since the review

Comment thread compiler/rustc_middle/src/mir/mod.rs Outdated
StableHash,
TypeFoldable,
TypeVisitable
)]

@lcnr lcnr Oct 12, 2026 •

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.

should also have a comment, or maybe just change the field to go "see [BodyTypingMode] for more info"

also, mind splitting the derive in two so that it doesn't get spread out like this

View changes since the review

@adwinwhite
adwinwhite marked this pull request as ready for review October 19, 2026 07:53
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 19, 2026
@rustbot

rustbot commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 19, 2026
@rust-bors

rust-bors Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #164757) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants