-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't rerun MIR passes when inlining #55244
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
37e1d29
Don't rerun Mir passes when inlining
nikomatsakis 895a4b2
Remove the `suite_index` parameter of the `run_passes!()` macro
wesleywiser c535147
Replace the `run_passes!` macro with a regular function
wesleywiser 4655866
Fix CR feedback
wesleywiser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
use borrow_check::nll::type_check; | ||
use build; | ||
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; | ||
use rustc::mir::{Mir, Promoted}; | ||
use rustc::mir::{Mir, MirPhase, Promoted}; | ||
use rustc::ty::TyCtxt; | ||
use rustc::ty::query::Providers; | ||
use rustc::ty::steal::Steal; | ||
|
@@ -155,53 +155,68 @@ pub trait MirPass { | |
mir: &mut Mir<'tcx>); | ||
} | ||
|
||
pub macro run_passes($tcx:ident, $mir:ident, $def_id:ident, $suite_index:expr; $($pass:expr,)*) {{ | ||
let suite_index: usize = $suite_index; | ||
let run_passes = |mir: &mut _, promoted| { | ||
pub fn run_passes( | ||
tcx: TyCtxt<'a, 'tcx, 'tcx>, | ||
mir: &mut Mir<'tcx>, | ||
def_id: DefId, | ||
mir_phase: MirPhase, | ||
passes: &[&dyn MirPass]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: rustfmt would put the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I was unsure of the convention here. |
||
let phase_index = mir_phase.phase_index(); | ||
|
||
let run_passes = |mir: &mut Mir<'tcx>, promoted| { | ||
if mir.phase >= mir_phase { | ||
return; | ||
} | ||
|
||
let source = MirSource { | ||
def_id: $def_id, | ||
promoted | ||
def_id, | ||
promoted, | ||
}; | ||
let mut index = 0; | ||
let mut run_pass = |pass: &dyn MirPass| { | ||
let run_hooks = |mir: &_, index, is_after| { | ||
dump_mir::on_mir_pass($tcx, &format_args!("{:03}-{:03}", suite_index, index), | ||
dump_mir::on_mir_pass(tcx, &format_args!("{:03}-{:03}", phase_index, index), | ||
&pass.name(), source, mir, is_after); | ||
}; | ||
run_hooks(mir, index, false); | ||
pass.run_pass($tcx, source, mir); | ||
pass.run_pass(tcx, source, mir); | ||
run_hooks(mir, index, true); | ||
|
||
index += 1; | ||
}; | ||
$(run_pass(&$pass);)* | ||
|
||
for pass in passes { | ||
run_pass(*pass); | ||
} | ||
|
||
mir.phase = mir_phase; | ||
}; | ||
|
||
run_passes(&mut $mir, None); | ||
run_passes(mir, None); | ||
|
||
for (index, promoted_mir) in $mir.promoted.iter_enumerated_mut() { | ||
for (index, promoted_mir) in mir.promoted.iter_enumerated_mut() { | ||
run_passes(promoted_mir, Some(index)); | ||
|
||
// Let's make sure we don't miss any nested instances | ||
assert!(promoted_mir.promoted.is_empty()); | ||
//Let's make sure we don't miss any nested instances | ||
assert!(promoted_mir.promoted.is_empty()) | ||
} | ||
}} | ||
} | ||
|
||
fn mir_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Steal<Mir<'tcx>> { | ||
// Unsafety check uses the raw mir, so make sure it is run | ||
let _ = tcx.unsafety_check_result(def_id); | ||
|
||
let mut mir = tcx.mir_built(def_id).steal(); | ||
run_passes![tcx, mir, def_id, 0; | ||
run_passes(tcx, &mut mir, def_id, MirPhase::Const, &[ | ||
// Remove all `EndRegion` statements that are not involved in borrows. | ||
cleanup_post_borrowck::CleanEndRegions, | ||
&cleanup_post_borrowck::CleanEndRegions, | ||
|
||
// What we need to do constant evaluation. | ||
simplify::SimplifyCfg::new("initial"), | ||
type_check::TypeckMir, | ||
rustc_peek::SanityCheck, | ||
uniform_array_move_out::UniformArrayMoveOut, | ||
]; | ||
&simplify::SimplifyCfg::new("initial"), | ||
&type_check::TypeckMir, | ||
&rustc_peek::SanityCheck, | ||
&uniform_array_move_out::UniformArrayMoveOut, | ||
]); | ||
tcx.alloc_steal_mir(mir) | ||
} | ||
|
||
|
@@ -214,11 +229,11 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx | |
} | ||
|
||
let mut mir = tcx.mir_const(def_id).steal(); | ||
run_passes![tcx, mir, def_id, 1; | ||
run_passes(tcx, &mut mir, def_id, MirPhase::Validated, &[ | ||
// What we need to run borrowck etc. | ||
qualify_consts::QualifyAndPromoteConstants, | ||
simplify::SimplifyCfg::new("qualify-consts"), | ||
]; | ||
&qualify_consts::QualifyAndPromoteConstants, | ||
&simplify::SimplifyCfg::new("qualify-consts"), | ||
]); | ||
tcx.alloc_steal_mir(mir) | ||
} | ||
|
||
|
@@ -232,59 +247,59 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx | |
} | ||
|
||
let mut mir = tcx.mir_validated(def_id).steal(); | ||
run_passes![tcx, mir, def_id, 2; | ||
run_passes(tcx, &mut mir, def_id, MirPhase::Optimized, &[ | ||
// Remove all things not needed by analysis | ||
no_landing_pads::NoLandingPads, | ||
simplify_branches::SimplifyBranches::new("initial"), | ||
remove_noop_landing_pads::RemoveNoopLandingPads, | ||
&no_landing_pads::NoLandingPads, | ||
&simplify_branches::SimplifyBranches::new("initial"), | ||
&remove_noop_landing_pads::RemoveNoopLandingPads, | ||
// Remove all `AscribeUserType` statements. | ||
cleanup_post_borrowck::CleanAscribeUserType, | ||
&cleanup_post_borrowck::CleanAscribeUserType, | ||
// Remove all `FakeRead` statements and the borrows that are only | ||
// used for checking matches | ||
cleanup_post_borrowck::CleanFakeReadsAndBorrows, | ||
simplify::SimplifyCfg::new("early-opt"), | ||
&cleanup_post_borrowck::CleanFakeReadsAndBorrows, | ||
&simplify::SimplifyCfg::new("early-opt"), | ||
|
||
// These next passes must be executed together | ||
add_call_guards::CriticalCallEdges, | ||
elaborate_drops::ElaborateDrops, | ||
no_landing_pads::NoLandingPads, | ||
&add_call_guards::CriticalCallEdges, | ||
&elaborate_drops::ElaborateDrops, | ||
&no_landing_pads::NoLandingPads, | ||
// AddValidation needs to run after ElaborateDrops and before EraseRegions, and it needs | ||
// an AllCallEdges pass right before it. | ||
add_call_guards::AllCallEdges, | ||
add_validation::AddValidation, | ||
&add_call_guards::AllCallEdges, | ||
&add_validation::AddValidation, | ||
// AddMovesForPackedDrops needs to run after drop | ||
// elaboration. | ||
add_moves_for_packed_drops::AddMovesForPackedDrops, | ||
&add_moves_for_packed_drops::AddMovesForPackedDrops, | ||
|
||
simplify::SimplifyCfg::new("elaborate-drops"), | ||
&simplify::SimplifyCfg::new("elaborate-drops"), | ||
|
||
// No lifetime analysis based on borrowing can be done from here on out. | ||
|
||
// From here on out, regions are gone. | ||
erase_regions::EraseRegions, | ||
&erase_regions::EraseRegions, | ||
|
||
lower_128bit::Lower128Bit, | ||
&lower_128bit::Lower128Bit, | ||
|
||
|
||
// Optimizations begin. | ||
uniform_array_move_out::RestoreSubsliceArrayMoveOut, | ||
inline::Inline, | ||
&uniform_array_move_out::RestoreSubsliceArrayMoveOut, | ||
&inline::Inline, | ||
|
||
// Lowering generator control-flow and variables | ||
// has to happen before we do anything else to them. | ||
generator::StateTransform, | ||
|
||
instcombine::InstCombine, | ||
const_prop::ConstProp, | ||
simplify_branches::SimplifyBranches::new("after-const-prop"), | ||
deaggregator::Deaggregator, | ||
copy_prop::CopyPropagation, | ||
remove_noop_landing_pads::RemoveNoopLandingPads, | ||
simplify::SimplifyCfg::new("final"), | ||
simplify::SimplifyLocals, | ||
|
||
add_call_guards::CriticalCallEdges, | ||
dump_mir::Marker("PreCodegen"), | ||
]; | ||
&generator::StateTransform, | ||
|
||
&instcombine::InstCombine, | ||
&const_prop::ConstProp, | ||
&simplify_branches::SimplifyBranches::new("after-const-prop"), | ||
&deaggregator::Deaggregator, | ||
©_prop::CopyPropagation, | ||
&remove_noop_landing_pads::RemoveNoopLandingPads, | ||
&simplify::SimplifyCfg::new("final"), | ||
&simplify::SimplifyLocals, | ||
|
||
&add_call_guards::CriticalCallEdges, | ||
&dump_mir::Marker("PreCodegen"), | ||
]); | ||
tcx.alloc_mir(mir) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Regression test for #50411: the MIR inliner was causing problems | ||
// here because it would inline promoted code (which had already had | ||
// elaborate-drops invoked on it) and then try to elaboate drops a | ||
// second time. Uncool. | ||
|
||
// compile-flags:-Zmir-opt-level=3 | ||
// compile-pass | ||
|
||
fn main() { | ||
let _ = (0 .. 1).filter(|_| [1].iter().all(|_| true)).count(); | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use
self as usize
instead of matching?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then please assign the discriminants explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can change that.