From 45a0de5446e855a9d17962c78886fd463db36eca Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 27 Aug 2026 20:24:51 +1000 Subject: [PATCH] [EXPERIMENT] Use insert2 in all remaining compiler crates - rustc_abi - rustc_codegen_ssa - rustc_hir_analysis - rustc_ty_utils --- compiler/rustc_abi/src/layout/coroutine.rs | 6 +++--- compiler/rustc_codegen_ssa/src/mir/analyze.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/debuginfo.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/mod.rs | 2 +- compiler/rustc_hir_analysis/src/check/check.rs | 2 +- compiler/rustc_index/src/bit_set.rs | 12 ++++++++++++ compiler/rustc_ty_utils/src/representability.rs | 2 +- compiler/rustc_ty_utils/src/ty.rs | 2 +- 8 files changed, 21 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_abi/src/layout/coroutine.rs b/compiler/rustc_abi/src/layout/coroutine.rs index fd68d06c93829..7b2486d33ac8d 100644 --- a/compiler/rustc_abi/src/layout/coroutine.rs +++ b/compiler/rustc_abi/src/layout/coroutine.rs @@ -67,7 +67,7 @@ fn coroutine_saved_local_eligibility1 variant ({:?}, {:?})", local, variant_index, idx ); - ineligible_locals.insert(*local); + ineligible_locals.insert2(*local); assignments[*local] = Ineligible(None); } Ineligible(_) => {} @@ -98,7 +98,7 @@ fn coroutine_saved_local_eligibility conflicts_b { (local_a, local_b) } else { (local_b, local_a) }; - ineligible_locals.insert(remove); + ineligible_locals.insert2(remove); assignments[remove] = Ineligible(None); trace!("removing local {:?} due to conflict with {:?}", remove, other); } @@ -113,7 +113,7 @@ fn coroutine_saved_local_eligibility>( let mut non_ssa_locals = DenseBitSet::new_empty(analyzer.locals.len()); for (local, kind) in analyzer.locals.iter_enumerated() { if matches!(kind, LocalKind::Memory) { - non_ssa_locals.insert(local); + non_ssa_locals.insert2(local); } } diff --git a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs index 77b2c9c73f69f..16b6b61219d03 100644 --- a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs @@ -752,7 +752,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // NOTE(eddyb) actually, on second thought, those are always in the // function scope, which always exists. for var_debug_info in &self.mir.var_debug_info { - vars.insert(var_debug_info.source_info.scope); + vars.insert2(var_debug_info.source_info.scope); } Some(vars) } else { diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index 6e87a295e9d2b..4e226ee9831fa 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -296,7 +296,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let mut reachable = DenseBitSet::new_empty(mir.basic_blocks.len()); let mut to_visit = vec![mir::START_BLOCK]; while let Some(next) = to_visit.pop() { - if !reachable.insert(next) { + if !reachable.insert2(next) { continue; } diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 1895f586df2f0..8e834c241fb1e 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -2111,7 +2111,7 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD && let ty::Param(param) = leaf_ty.kind() { debug!("found use of ty param {:?}", param); - params_used.insert(param.index); + params_used.insert2(param.index); } } diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index aa3c759a6adbd..f7811ba91343a 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -161,6 +161,18 @@ impl DenseBitSet { new_word != word } + /// Insert `elem`. Returns whether the set has changed. + #[inline] + pub fn insert2(&mut self, elem: T) -> bool { + assert!(elem.index() < self.domain_size,); + let (word_index, mask) = word_index_and_mask(elem); + let word_ref = &mut self.words[word_index]; + let word = *word_ref; + let new_word = word | mask; + *word_ref = new_word; + new_word != word + } + #[inline] pub fn insert_range(&mut self, elems: impl RangeBounds) { let Some((start, end)) = inclusive_start_end(elems, self.domain_size) else { diff --git a/compiler/rustc_ty_utils/src/representability.rs b/compiler/rustc_ty_utils/src/representability.rs index 6b147b383eb0a..19a486d90ea1c 100644 --- a/compiler/rustc_ty_utils/src/representability.rs +++ b/compiler/rustc_ty_utils/src/representability.rs @@ -117,7 +117,7 @@ fn params_in_repr_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, params_in_repr: &mut ty::Array(ty, _) => params_in_repr_ty(tcx, ty, params_in_repr), ty::Tuple(tys) => tys.iter().for_each(|ty| params_in_repr_ty(tcx, ty, params_in_repr)), ty::Param(param) => { - params_in_repr.insert(param.index); + params_in_repr.insert2(param.index); } _ => {} } diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index e54e8f098d175..ebca6444669ce 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -329,7 +329,7 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> DenseBitSe let mut unsizing_params = DenseBitSet::new_empty(num_params); for arg in tcx.type_of(tail_field.did).instantiate_identity().skip_norm_wip().walk() { if let Some(i) = maybe_unsizing_param_idx(arg) { - unsizing_params.insert(i); + unsizing_params.insert2(i); } }