Skip to content

Commit 5ced3da

Browse files
committed
Auto merge of #125853 - tesuji:promote-fail-fast, r=cjgillot
promote_consts: some clean-up after experimenting This is some clean-up after experimenting in #125916, Prefer to review commit-by-commit.
2 parents 25c9f2c + 7002a3f commit 5ced3da

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

compiler/rustc_const_eval/src/interpret/place.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ where
441441

442442
/// Take an operand, representing a pointer, and dereference it to a place.
443443
/// Corresponds to the `*` operator in Rust.
444-
#[instrument(skip(self), level = "debug")]
444+
#[instrument(skip(self), level = "trace")]
445445
pub fn deref_pointer(
446446
&self,
447447
src: &impl Readable<'tcx, M::Provenance>,
@@ -533,7 +533,7 @@ where
533533

534534
/// Computes a place. You should only use this if you intend to write into this
535535
/// place; for reading, a more efficient alternative is `eval_place_to_op`.
536-
#[instrument(skip(self), level = "debug")]
536+
#[instrument(skip(self), level = "trace")]
537537
pub fn eval_place(
538538
&self,
539539
mir_place: mir::Place<'tcx>,
@@ -570,7 +570,7 @@ where
570570

571571
/// Write an immediate to a place
572572
#[inline(always)]
573-
#[instrument(skip(self), level = "debug")]
573+
#[instrument(skip(self), level = "trace")]
574574
pub fn write_immediate(
575575
&mut self,
576576
src: Immediate<M::Provenance>,
@@ -808,7 +808,7 @@ where
808808
/// Copies the data from an operand to a place.
809809
/// `allow_transmute` indicates whether the layouts may disagree.
810810
#[inline(always)]
811-
#[instrument(skip(self), level = "debug")]
811+
#[instrument(skip(self), level = "trace")]
812812
fn copy_op_inner(
813813
&mut self,
814814
src: &impl Readable<'tcx, M::Provenance>,
@@ -837,7 +837,7 @@ where
837837
/// `allow_transmute` indicates whether the layouts may disagree.
838838
/// Also, if you use this you are responsible for validating that things get copied at the
839839
/// right type.
840-
#[instrument(skip(self), level = "debug")]
840+
#[instrument(skip(self), level = "trace")]
841841
fn copy_op_no_validate(
842842
&mut self,
843843
src: &impl Readable<'tcx, M::Provenance>,
@@ -914,7 +914,7 @@ where
914914
/// If the place currently refers to a local that doesn't yet have a matching allocation,
915915
/// create such an allocation.
916916
/// This is essentially `force_to_memplace`.
917-
#[instrument(skip(self), level = "debug")]
917+
#[instrument(skip(self), level = "trace")]
918918
pub fn force_allocation(
919919
&mut self,
920920
place: &PlaceTy<'tcx, M::Provenance>,

compiler/rustc_mir_transform/src/promote_consts.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> {
6060
let ccx = ConstCx::new(tcx, body);
6161
let (mut temps, all_candidates) = collect_temps_and_candidates(&ccx);
6262

63-
let promotable_candidates = validate_candidates(&ccx, &mut temps, &all_candidates);
63+
let promotable_candidates = validate_candidates(&ccx, &mut temps, all_candidates);
6464

6565
let promoted = promote_candidates(body, tcx, temps, promotable_candidates);
6666
self.promoted_fragments.set(promoted);
@@ -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) {
@@ -695,15 +691,12 @@ impl<'tcx> Validator<'_, 'tcx> {
695691
fn validate_candidates(
696692
ccx: &ConstCx<'_, '_>,
697693
temps: &mut IndexSlice<Local, TempState>,
698-
candidates: &[Candidate],
694+
mut candidates: Vec<Candidate>,
699695
) -> Vec<Candidate> {
700696
let mut validator = Validator { ccx, temps, promotion_safe_blocks: None };
701697

698+
candidates.retain(|&candidate| validator.validate_candidate(candidate).is_ok());
702699
candidates
703-
.iter()
704-
.copied()
705-
.filter(|&candidate| validator.validate_candidate(candidate).is_ok())
706-
.collect()
707700
}
708701

709702
struct Promoter<'a, 'tcx> {
@@ -972,7 +965,12 @@ fn promote_candidates<'tcx>(
972965
candidates: Vec<Candidate>,
973966
) -> IndexVec<Promoted, Body<'tcx>> {
974967
// Visit candidates in reverse, in case they're nested.
975-
debug!("promote_candidates({:?})", candidates);
968+
debug!(promote_candidates = ?candidates);
969+
970+
// eagerly fail fast
971+
if candidates.is_empty() {
972+
return IndexVec::new();
973+
}
976974

977975
let mut promotions = IndexVec::new();
978976

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)