From 06aee7ee03a87a53c29f72f08e41469b9d88232e Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 1 Jun 2024 11:14:14 +0000 Subject: [PATCH 1/5] use rustc-dep-of-std in panic_unwind Wihout it, std keeps rebuiling when unchanged. But we could use `--keep-stage=1` to make it not rebuild. --- library/panic_unwind/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/panic_unwind/Cargo.toml b/library/panic_unwind/Cargo.toml index dce2da3164440..f830808d19648 100644 --- a/library/panic_unwind/Cargo.toml +++ b/library/panic_unwind/Cargo.toml @@ -16,7 +16,7 @@ alloc = { path = "../alloc" } core = { path = "../core" } unwind = { path = "../unwind" } compiler_builtins = "0.1.0" -cfg-if = "1.0" +cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] } [target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies] libc = { version = "0.2", default-features = false } From 28708912fb011f1c7666281ba5a22862f4503d4d Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 1 Jun 2024 11:18:21 +0000 Subject: [PATCH 2/5] prefer tracing::instrument over debug strings --- .../rustc_mir_transform/src/promote_consts.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index ecd1179ca9959..a0ee4c432c6c4 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -98,8 +98,8 @@ struct Collector<'a, 'tcx> { } impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> { + #[instrument(level = "debug", skip(self))] fn visit_local(&mut self, index: Local, context: PlaceContext, location: Location) { - debug!("visit_local: index={:?} context={:?} location={:?}", index, context, location); // We're only interested in temporaries and the return place match self.ccx.body.local_kind(index) { LocalKind::Arg => return, @@ -111,20 +111,15 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> { // then it's constant and thus drop is noop. // Non-uses are also irrelevant. if context.is_drop() || !context.is_use() { - debug!( - "visit_local: context.is_drop={:?} context.is_use={:?}", - context.is_drop(), - context.is_use(), - ); + debug!(is_drop = context.is_drop(), is_use = context.is_use()); return; } let temp = &mut self.temps[index]; - debug!("visit_local: temp={:?}", temp); + debug!(?temp); *temp = match *temp { TempState::Undefined => match context { - PlaceContext::MutatingUse(MutatingUseContext::Store) - | PlaceContext::MutatingUse(MutatingUseContext::Call) => { + PlaceContext::MutatingUse(MutatingUseContext::Store | MutatingUseContext::Call) => { TempState::Defined { location, uses: 0, valid: Err(()) } } _ => TempState::Unpromotable, @@ -137,7 +132,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> { | PlaceContext::NonMutatingUse(_) => true, PlaceContext::MutatingUse(_) | PlaceContext::NonUse(_) => false, }; - debug!("visit_local: allowed_use={:?}", allowed_use); + debug!(?allowed_use); if allowed_use { *uses += 1; return; @@ -146,6 +141,7 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> { } TempState::Unpromotable | TempState::PromotedOut => TempState::Unpromotable, }; + debug!(?temp); } fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { @@ -972,7 +968,7 @@ fn promote_candidates<'tcx>( candidates: Vec, ) -> IndexVec> { // Visit candidates in reverse, in case they're nested. - debug!("promote_candidates({:?})", candidates); + debug!(promote_candidates = ?candidates); let mut promotions = IndexVec::new(); From c03659443a70b018e49f2ae72645d64eac58c7f7 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 1 Jun 2024 11:18:34 +0000 Subject: [PATCH 3/5] promote_consts: eargerly return when there are no candidates There is no need to do it when mustn't. --- compiler/rustc_mir_transform/src/promote_consts.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index a0ee4c432c6c4..2f7d8d96eaccc 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -970,6 +970,11 @@ fn promote_candidates<'tcx>( // Visit candidates in reverse, in case they're nested. debug!(promote_candidates = ?candidates); + // eagerly fail fast + if candidates.is_empty() { + return IndexVec::new(); + } + let mut promotions = IndexVec::new(); let mut extra_statements = vec![]; From 62a287528a55bfc96e4e97d7889af68fb9bb8307 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 16 Jun 2024 10:00:23 +0000 Subject: [PATCH 4/5] Reuse allocation for Vec --- compiler/rustc_mir_transform/src/promote_consts.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index 2f7d8d96eaccc..ba7c5f2fee607 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -60,7 +60,7 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> { let ccx = ConstCx::new(tcx, body); let (mut temps, all_candidates) = collect_temps_and_candidates(&ccx); - let promotable_candidates = validate_candidates(&ccx, &mut temps, &all_candidates); + let promotable_candidates = validate_candidates(&ccx, &mut temps, all_candidates); let promoted = promote_candidates(body, tcx, temps, promotable_candidates); self.promoted_fragments.set(promoted); @@ -691,15 +691,12 @@ impl<'tcx> Validator<'_, 'tcx> { fn validate_candidates( ccx: &ConstCx<'_, '_>, temps: &mut IndexSlice, - candidates: &[Candidate], + mut candidates: Vec, ) -> Vec { let mut validator = Validator { ccx, temps, promotion_safe_blocks: None }; + candidates.retain(|&candidate| validator.validate_candidate(candidate).is_ok()); candidates - .iter() - .copied() - .filter(|&candidate| validator.validate_candidate(candidate).is_ok()) - .collect() } struct Promoter<'a, 'tcx> { From 7002a3f37f93fff2edceabbfea348d60dc444c55 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Thu, 13 Jun 2024 08:15:00 +0000 Subject: [PATCH 5/5] interpret: use trace to reduce noice --- compiler/rustc_const_eval/src/interpret/place.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 08d3165867c16..baaee67e7871c 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -441,7 +441,7 @@ where /// Take an operand, representing a pointer, and dereference it to a place. /// Corresponds to the `*` operator in Rust. - #[instrument(skip(self), level = "debug")] + #[instrument(skip(self), level = "trace")] pub fn deref_pointer( &self, src: &impl Readable<'tcx, M::Provenance>, @@ -533,7 +533,7 @@ where /// Computes a place. You should only use this if you intend to write into this /// place; for reading, a more efficient alternative is `eval_place_to_op`. - #[instrument(skip(self), level = "debug")] + #[instrument(skip(self), level = "trace")] pub fn eval_place( &self, mir_place: mir::Place<'tcx>, @@ -570,7 +570,7 @@ where /// Write an immediate to a place #[inline(always)] - #[instrument(skip(self), level = "debug")] + #[instrument(skip(self), level = "trace")] pub fn write_immediate( &mut self, src: Immediate, @@ -808,7 +808,7 @@ where /// Copies the data from an operand to a place. /// `allow_transmute` indicates whether the layouts may disagree. #[inline(always)] - #[instrument(skip(self), level = "debug")] + #[instrument(skip(self), level = "trace")] fn copy_op_inner( &mut self, src: &impl Readable<'tcx, M::Provenance>, @@ -837,7 +837,7 @@ where /// `allow_transmute` indicates whether the layouts may disagree. /// Also, if you use this you are responsible for validating that things get copied at the /// right type. - #[instrument(skip(self), level = "debug")] + #[instrument(skip(self), level = "trace")] fn copy_op_no_validate( &mut self, src: &impl Readable<'tcx, M::Provenance>, @@ -914,7 +914,7 @@ where /// If the place currently refers to a local that doesn't yet have a matching allocation, /// create such an allocation. /// This is essentially `force_to_memplace`. - #[instrument(skip(self), level = "debug")] + #[instrument(skip(self), level = "trace")] pub fn force_allocation( &mut self, place: &PlaceTy<'tcx, M::Provenance>,