Skip to content

Commit 4020cf9

Browse files
committed
Auto merge of #125853 - tesuji:promote-fail-fast, r=<try>
promote_consts: fail fast if there are no candidates
2 parents acaf0ae + 9a1a5a2 commit 4020cf9

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

compiler/rustc_mir_transform/src/promote_consts.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ struct Collector<'a, 'tcx> {
9898
}
9999

100100
impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
101+
#[instrument(level = "debug", skip(self))]
101102
fn visit_local(&mut self, index: Local, context: PlaceContext, location: Location) {
102-
debug!("visit_local: index={:?} context={:?} location={:?}", index, context, location);
103103
// We're only interested in temporaries and the return place
104104
match self.ccx.body.local_kind(index) {
105105
LocalKind::Arg => return,
@@ -111,20 +111,15 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
111111
// then it's constant and thus drop is noop.
112112
// Non-uses are also irrelevant.
113113
if context.is_drop() || !context.is_use() {
114-
debug!(
115-
"visit_local: context.is_drop={:?} context.is_use={:?}",
116-
context.is_drop(),
117-
context.is_use(),
118-
);
114+
debug!(is_drop = context.is_drop(), is_use = context.is_use());
119115
return;
120116
}
121117

122118
let temp = &mut self.temps[index];
123-
debug!("visit_local: temp={:?}", temp);
119+
debug!(?temp);
124120
*temp = match *temp {
125121
TempState::Undefined => match context {
126-
PlaceContext::MutatingUse(MutatingUseContext::Store)
127-
| PlaceContext::MutatingUse(MutatingUseContext::Call) => {
122+
PlaceContext::MutatingUse(MutatingUseContext::Store | MutatingUseContext::Call) => {
128123
TempState::Defined { location, uses: 0, valid: Err(()) }
129124
}
130125
_ => TempState::Unpromotable,
@@ -137,7 +132,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
137132
| PlaceContext::NonMutatingUse(_) => true,
138133
PlaceContext::MutatingUse(_) | PlaceContext::NonUse(_) => false,
139134
};
140-
debug!("visit_local: allowed_use={:?}", allowed_use);
135+
debug!(?allowed_use);
141136
if allowed_use {
142137
*uses += 1;
143138
return;
@@ -146,6 +141,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> {
146141
}
147142
TempState::Unpromotable | TempState::PromotedOut => TempState::Unpromotable,
148143
};
144+
debug!(?temp);
149145
}
150146

151147
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
@@ -972,7 +968,12 @@ fn promote_candidates<'tcx>(
972968
candidates: Vec<Candidate>,
973969
) -> IndexVec<Promoted, Body<'tcx>> {
974970
// Visit candidates in reverse, in case they're nested.
975-
debug!("promote_candidates({:?})", candidates);
971+
debug!(promote_candidates = ?candidates);
972+
973+
// eagerly fail fast
974+
if candidates.is_empty() {
975+
return IndexVec::new();
976+
}
976977

977978
let mut promotions = IndexVec::new();
978979

library/panic_unwind/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ alloc = { path = "../alloc" }
1616
core = { path = "../core" }
1717
unwind = { path = "../unwind" }
1818
compiler_builtins = "0.1.0"
19-
cfg-if = "1.0"
19+
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
2020

2121
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
2222
libc = { version = "0.2", default-features = false }

0 commit comments

Comments
 (0)