Repository navigation
replace TypingEnv::post_analysis() with mir::Body::typing_env() - #164077
adwinwhite wants to merge 1 commit into
Conversation
This comment has been minimized.
This comment has been minimized.
2d08b00 to
0b642e2
Compare
This comment has been minimized.
This comment has been minimized.
0b642e2 to
53c2b35
Compare
| match self.phase { | ||
| MirPhase::Built | MirPhase::Analysis(_) => TypingEnv::new( | ||
| match self.typing_mode { | ||
| BodyTypingMode::Borrowck | BodyTypingMode::PostBorrowck => TypingEnv::new( |
There was a problem hiding this comment.
when do we encounter this?
There was a problem hiding this comment.
The initial mode is BodyTypingMode::Borrowck. After mir_borrowck, we set it to PostBorrowck.
There was a problem hiding this comment.
promote_consts pass would use BodyTypingMode::Borrowck since it's run before borrowck.
| StableHash, | ||
| TypeFoldable, | ||
| TypeVisitable | ||
| )] |
There was a problem hiding this comment.
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
5e23058 to
23a44a9
Compare
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
This comment has been minimized.
| #[derive(Copy, Clone, PartialEq, Debug)] | ||
| #[derive(TyEncodable, TyDecodable, StableHash, TypeFoldable, TypeVisitable)] | ||
| pub enum BodyTypingMode { | ||
| Borrowck, |
There was a problem hiding this comment.
| // This branch happens for drop glue and fn ptr shims. | ||
| // FIXME: why do we do any of this analysis on drop glue etc? | ||
| // This should ideally all be skipped. | ||
| TypingEnv::post_analysis(tcx, self.source.def_id()) |
There was a problem hiding this comment.
should this be the case or could we change drop glue and fn ptr shims to just start out in TypingMode::PostAnalysis?
There was a problem hiding this comment.
We already use PostAnalysis mode for them. I guess this branch is actually useless.
|
|
||
| debug!("runtime_mir_cleanup({:?})", did); | ||
| run_runtime_cleanup_passes(tcx, body); | ||
| assert!(body.typing_mode == BodyTypingMode::PostAnalysis, "{:?}", body.typing_mode); |
There was a problem hiding this comment.
| // We try to guard against future MIR building procedures that don't go through the usual | ||
| // lowering. The final validation is expected to run in `TypingMode::PostAnalysis`. | ||
| if new_phase == MirPhase::Runtime(RuntimePhase::Optimized) { | ||
| assert_eq!(body.typing_mode, BodyTypingMode::PostAnalysis,); |
There was a problem hiding this comment.
| assert_eq!(body.typing_mode, BodyTypingMode::PostAnalysis,); | |
| assert_eq!(body.typing_mode, BodyTypingMode::PostAnalysis); |
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
23a44a9 to
a5cc7e2
Compare
|
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. |
This comment has been minimized.
This comment has been minimized.
4bbe3be to
3958cd2
Compare
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
replace `TypingEnv::post_analysis()` with `mir::Body::typing_env()`
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (ca63c4d): comparison URL. Overall result: ❌ regressions - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 2.4%, secondary 1.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -6.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 480.462s -> 479.565s (-0.19%) |
|
@rustbot ready r? project-trait-system-refactor |
|
The review request |
|
r? @jdonszelmann or @ShoyuVanilla |
|
|
|
I can take this one |
| match self.typing_mode { | ||
| BodyTypingMode::PostTypeckThroughBorrowck => { | ||
| let local_def_id = | ||
| self.source.def_id().as_local().expect("We only build MIR for local body"); |
There was a problem hiding this comment.
typo "local bodies"
| @@ -848,6 +849,7 @@ fn promoted_mir(tcx: TyCtxt<'_>, def: LocalDefId) -> &IndexVec<Promoted, Body<'_ | |||
| let mut promoted = tcx.mir_promoted(def).1.steal(); | |||
|
|
|||
| for body in &mut promoted { | |||
| body.typing_mode = BodyTypingMode::PostBorrowck; | |||
There was a problem hiding this comment.
I'm slightly worried about this. Should the typing mode maybe be tied to the phase change mechanism? One example that came to mind is build_adt_ctor in compiler/rustc_mir_transform/src/shim.rs which does a phase change on a mir body not through the normal mechanisms (later than normal). I think we may not care about the typing mode there, but the fact that we kind of just set the typing mode of a body in random places scares me.
There was a problem hiding this comment.
I wrote a summary of all the transitions for different kinds of bodies, only to find that "yeah, following phase change is simpler" as long as we give up PostBorrowck, which isn't really used in passes.
3958cd2 to
5c53b5b
Compare
This comment has been minimized.
This comment has been minimized.
5c53b5b to
8b7f115
Compare
|
The job Click to see the possible cause of the failure (guessed by this bot) |
View all comments
This PR fixes the correspondence between typing modes and MIR phases so that some passes don't have to fix that inconsistency themselves.
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.
r? lcnr