Skip to content

Commit eb54a50

Browse files
committed
Auto merge of #135370 - matthiaskrgr:rollup-g2w6d5n, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #134030 (add `-Zmin-function-alignment`) - #134776 (Avoid ICE: Account for `for<'a>` types when checking for non-structural type in constant as pattern) - #135205 (Rename `BitSet` to `DenseBitSet`) - #135314 (Eagerly collect mono items for non-generic closures) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fb65a3e + 076c047 commit eb54a50

File tree

89 files changed

+706
-437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+706
-437
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22
use std::ops::Index;
33

44
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
5-
use rustc_index::bit_set::BitSet;
5+
use rustc_index::bit_set::DenseBitSet;
66
use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor};
77
use rustc_middle::mir::{self, Body, Local, Location, traversal};
88
use rustc_middle::span_bug;
@@ -131,7 +131,7 @@ impl<'tcx> fmt::Display for BorrowData<'tcx> {
131131

132132
pub enum LocalsStateAtExit {
133133
AllAreInvalidated,
134-
SomeAreInvalidated { has_storage_dead_or_moved: BitSet<Local> },
134+
SomeAreInvalidated { has_storage_dead_or_moved: DenseBitSet<Local> },
135135
}
136136

137137
impl LocalsStateAtExit {
@@ -140,7 +140,7 @@ impl LocalsStateAtExit {
140140
body: &Body<'tcx>,
141141
move_data: &MoveData<'tcx>,
142142
) -> Self {
143-
struct HasStorageDead(BitSet<Local>);
143+
struct HasStorageDead(DenseBitSet<Local>);
144144

145145
impl<'tcx> Visitor<'tcx> for HasStorageDead {
146146
fn visit_local(&mut self, local: Local, ctx: PlaceContext, _: Location) {
@@ -153,7 +153,8 @@ impl LocalsStateAtExit {
153153
if locals_are_invalidated_at_exit {
154154
LocalsStateAtExit::AllAreInvalidated
155155
} else {
156-
let mut has_storage_dead = HasStorageDead(BitSet::new_empty(body.local_decls.len()));
156+
let mut has_storage_dead =
157+
HasStorageDead(DenseBitSet::new_empty(body.local_decls.len()));
157158
has_storage_dead.visit_body(body);
158159
let mut has_storage_dead_or_moved = has_storage_dead.0;
159160
for move_out in &move_data.moves {

compiler/rustc_borrowck/src/dataflow.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22

33
use rustc_data_structures::fx::FxIndexMap;
44
use rustc_data_structures::graph;
5-
use rustc_index::bit_set::BitSet;
5+
use rustc_index::bit_set::DenseBitSet;
66
use rustc_middle::mir::{
77
self, BasicBlock, Body, CallReturnPlaces, Location, Place, TerminatorEdges,
88
};
@@ -180,7 +180,7 @@ pub struct Borrows<'a, 'tcx> {
180180
}
181181

182182
struct OutOfScopePrecomputer<'a, 'tcx> {
183-
visited: BitSet<mir::BasicBlock>,
183+
visited: DenseBitSet<mir::BasicBlock>,
184184
visit_stack: Vec<mir::BasicBlock>,
185185
body: &'a Body<'tcx>,
186186
regioncx: &'a RegionInferenceContext<'tcx>,
@@ -190,7 +190,7 @@ struct OutOfScopePrecomputer<'a, 'tcx> {
190190
impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> {
191191
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
192192
OutOfScopePrecomputer {
193-
visited: BitSet::new_empty(body.basic_blocks.len()),
193+
visited: DenseBitSet::new_empty(body.basic_blocks.len()),
194194
visit_stack: vec![],
195195
body,
196196
regioncx,
@@ -292,7 +292,7 @@ pub fn calculate_borrows_out_of_scope_at_location<'tcx>(
292292
}
293293

294294
struct PoloniusOutOfScopePrecomputer<'a, 'tcx> {
295-
visited: BitSet<mir::BasicBlock>,
295+
visited: DenseBitSet<mir::BasicBlock>,
296296
visit_stack: Vec<mir::BasicBlock>,
297297
body: &'a Body<'tcx>,
298298
regioncx: &'a RegionInferenceContext<'tcx>,
@@ -303,7 +303,7 @@ struct PoloniusOutOfScopePrecomputer<'a, 'tcx> {
303303
impl<'a, 'tcx> PoloniusOutOfScopePrecomputer<'a, 'tcx> {
304304
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
305305
Self {
306-
visited: BitSet::new_empty(body.basic_blocks.len()),
306+
visited: DenseBitSet::new_empty(body.basic_blocks.len()),
307307
visit_stack: vec![],
308308
body,
309309
regioncx,
@@ -559,7 +559,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
559559
}
560560
}
561561

562-
type BorrowsDomain = BitSet<BorrowIndex>;
562+
type BorrowsDomain = DenseBitSet<BorrowIndex>;
563563

564564
/// Forward dataflow computation of the set of borrows that are in scope at a particular location.
565565
/// - we gen the introduced loans
@@ -575,7 +575,7 @@ impl<'tcx> rustc_mir_dataflow::Analysis<'tcx> for Borrows<'_, 'tcx> {
575575

576576
fn bottom_value(&self, _: &mir::Body<'tcx>) -> Self::Domain {
577577
// bottom = nothing is reserved or activated yet;
578-
BitSet::new_empty(self.borrow_set.len())
578+
DenseBitSet::new_empty(self.borrow_set.len())
579579
}
580580

581581
fn initialize_start_block(&self, _: &mir::Body<'tcx>, _: &mut Self::Domain) {

compiler/rustc_borrowck/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_errors::LintDiagnostic;
2828
use rustc_hir as hir;
2929
use rustc_hir::CRATE_HIR_ID;
3030
use rustc_hir::def_id::LocalDefId;
31-
use rustc_index::bit_set::{BitSet, MixedBitSet};
31+
use rustc_index::bit_set::{DenseBitSet, MixedBitSet};
3232
use rustc_index::{IndexSlice, IndexVec};
3333
use rustc_infer::infer::{
3434
InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
@@ -1017,11 +1017,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
10171017
&self,
10181018
location: Location,
10191019
state: &'s BorrowckDomain,
1020-
) -> Cow<'s, BitSet<BorrowIndex>> {
1020+
) -> Cow<'s, DenseBitSet<BorrowIndex>> {
10211021
if let Some(polonius) = &self.polonius_output {
10221022
// Use polonius output if it has been enabled.
10231023
let location = self.location_table.start_index(location);
1024-
let mut polonius_output = BitSet::new_empty(self.borrow_set.len());
1024+
let mut polonius_output = DenseBitSet::new_empty(self.borrow_set.len());
10251025
for &idx in polonius.errors_at(location) {
10261026
polonius_output.insert(idx);
10271027
}

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
2-
use rustc_index::bit_set::BitSet;
2+
use rustc_index::bit_set::DenseBitSet;
33
use rustc_index::interval::IntervalSet;
44
use rustc_infer::infer::canonical::QueryRegionConstraints;
55
use rustc_infer::infer::outlives::for_liveness;
@@ -129,7 +129,7 @@ struct LivenessResults<'a, 'typeck, 'b, 'tcx> {
129129
cx: LivenessContext<'a, 'typeck, 'b, 'tcx>,
130130

131131
/// Set of points that define the current local.
132-
defs: BitSet<PointIndex>,
132+
defs: DenseBitSet<PointIndex>,
133133

134134
/// Points where the current variable is "use live" -- meaning
135135
/// that there is a future "full use" that may use its value.
@@ -152,7 +152,7 @@ impl<'a, 'typeck, 'b, 'tcx> LivenessResults<'a, 'typeck, 'b, 'tcx> {
152152
let num_points = cx.location_map.num_points();
153153
LivenessResults {
154154
cx,
155-
defs: BitSet::new_empty(num_points),
155+
defs: DenseBitSet::new_empty(num_points),
156156
use_live_at: IntervalSet::new(num_points),
157157
drop_live_at: IntervalSet::new(num_points),
158158
drop_locations: vec![],

compiler/rustc_codegen_gcc/src/debuginfo.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use gccjit::{Location, RValue};
44
use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, VariableKind};
55
use rustc_codegen_ssa::traits::{DebugInfoBuilderMethods, DebugInfoCodegenMethods};
66
use rustc_data_structures::sync::Lrc;
7-
use rustc_index::bit_set::BitSet;
7+
use rustc_index::bit_set::DenseBitSet;
88
use rustc_index::{Idx, IndexVec};
99
use rustc_middle::mir::{self, Body, SourceScope};
1010
use rustc_middle::ty::{Instance, PolyExistentialTraitRef, Ty};
@@ -69,7 +69,7 @@ fn compute_mir_scopes<'gcc, 'tcx>(
6969
) {
7070
// Find all scopes with variables defined in them.
7171
let variables = if cx.sess().opts.debuginfo == DebugInfo::Full {
72-
let mut vars = BitSet::new_empty(mir.source_scopes.len());
72+
let mut vars = DenseBitSet::new_empty(mir.source_scopes.len());
7373
// FIXME(eddyb) take into account that arguments always have debuginfo,
7474
// irrespective of their name (assuming full debuginfo is enabled).
7575
// NOTE(eddyb) actually, on second thought, those are always in the
@@ -82,7 +82,7 @@ fn compute_mir_scopes<'gcc, 'tcx>(
8282
// Nothing to emit, of course.
8383
None
8484
};
85-
let mut instantiated = BitSet::new_empty(mir.source_scopes.len());
85+
let mut instantiated = DenseBitSet::new_empty(mir.source_scopes.len());
8686
// Instantiate all scopes.
8787
for idx in 0..mir.source_scopes.len() {
8888
let scope = SourceScope::new(idx);
@@ -101,9 +101,9 @@ fn make_mir_scope<'gcc, 'tcx>(
101101
cx: &CodegenCx<'gcc, 'tcx>,
102102
_instance: Instance<'tcx>,
103103
mir: &Body<'tcx>,
104-
variables: &Option<BitSet<SourceScope>>,
104+
variables: &Option<DenseBitSet<SourceScope>>,
105105
debug_context: &mut FunctionDebugContext<'tcx, (), Location<'gcc>>,
106-
instantiated: &mut BitSet<SourceScope>,
106+
instantiated: &mut DenseBitSet<SourceScope>,
107107
scope: SourceScope,
108108
) {
109109
if instantiated.contains(scope) {

compiler/rustc_codegen_llvm/src/attributes.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,11 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
474474
let allocated_pointer = AttributeKind::AllocatedPointer.create_attr(cx.llcx);
475475
attributes::apply_to_llfn(llfn, AttributePlace::Argument(0), &[allocated_pointer]);
476476
}
477-
if let Some(align) = codegen_fn_attrs.alignment {
477+
// function alignment can be set globally with the `-Zmin-function-alignment=<n>` flag;
478+
// the alignment from a `#[repr(align(<n>))]` is used if it specifies a higher alignment.
479+
if let Some(align) =
480+
Ord::max(cx.tcx.sess.opts.unstable_opts.min_function_alignment, codegen_fn_attrs.alignment)
481+
{
478482
llvm::set_alignment(llfn, align);
479483
}
480484
if let Some(backchain) = backchain_attr(cx) {

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext};
44
use rustc_codegen_ssa::traits::*;
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_index::Idx;
7-
use rustc_index::bit_set::BitSet;
7+
use rustc_index::bit_set::DenseBitSet;
88
use rustc_middle::mir::{Body, SourceScope};
99
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv};
1010
use rustc_middle::ty::{self, Instance};
@@ -27,7 +27,7 @@ pub(crate) fn compute_mir_scopes<'ll, 'tcx>(
2727
) {
2828
// Find all scopes with variables defined in them.
2929
let variables = if cx.sess().opts.debuginfo == DebugInfo::Full {
30-
let mut vars = BitSet::new_empty(mir.source_scopes.len());
30+
let mut vars = DenseBitSet::new_empty(mir.source_scopes.len());
3131
// FIXME(eddyb) take into account that arguments always have debuginfo,
3232
// irrespective of their name (assuming full debuginfo is enabled).
3333
// NOTE(eddyb) actually, on second thought, those are always in the
@@ -40,7 +40,7 @@ pub(crate) fn compute_mir_scopes<'ll, 'tcx>(
4040
// Nothing to emit, of course.
4141
None
4242
};
43-
let mut instantiated = BitSet::new_empty(mir.source_scopes.len());
43+
let mut instantiated = DenseBitSet::new_empty(mir.source_scopes.len());
4444
let mut discriminators = FxHashMap::default();
4545
// Instantiate all scopes.
4646
for idx in 0..mir.source_scopes.len() {
@@ -63,9 +63,9 @@ fn make_mir_scope<'ll, 'tcx>(
6363
cx: &CodegenCx<'ll, 'tcx>,
6464
instance: Instance<'tcx>,
6565
mir: &Body<'tcx>,
66-
variables: &Option<BitSet<SourceScope>>,
66+
variables: &Option<DenseBitSet<SourceScope>>,
6767
debug_context: &mut FunctionDebugContext<'tcx, &'ll DIScope, &'ll DILocation>,
68-
instantiated: &mut BitSet<SourceScope>,
68+
instantiated: &mut DenseBitSet<SourceScope>,
6969
discriminators: &mut FxHashMap<BytePos, u32>,
7070
scope: SourceScope,
7171
) {

compiler/rustc_codegen_ssa/src/mir/analyze.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! which do not.
33
44
use rustc_data_structures::graph::dominators::Dominators;
5-
use rustc_index::bit_set::BitSet;
5+
use rustc_index::bit_set::DenseBitSet;
66
use rustc_index::{IndexSlice, IndexVec};
77
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
88
use rustc_middle::mir::{self, DefLocation, Location, TerminatorKind, traversal};
@@ -16,7 +16,7 @@ use crate::traits::*;
1616
pub(crate) fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
1717
fx: &FunctionCx<'a, 'tcx, Bx>,
1818
traversal_order: &[mir::BasicBlock],
19-
) -> BitSet<mir::Local> {
19+
) -> DenseBitSet<mir::Local> {
2020
let mir = fx.mir;
2121
let dominators = mir.basic_blocks.dominators();
2222
let locals = mir
@@ -44,7 +44,7 @@ pub(crate) fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
4444
analyzer.visit_basic_block_data(bb, data);
4545
}
4646

47-
let mut non_ssa_locals = BitSet::new_empty(analyzer.locals.len());
47+
let mut non_ssa_locals = DenseBitSet::new_empty(analyzer.locals.len());
4848
for (local, kind) in analyzer.locals.iter_enumerated() {
4949
if matches!(kind, LocalKind::Memory) {
5050
non_ssa_locals.insert(local);

compiler/rustc_codegen_ssa/src/mir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::iter;
22

33
use rustc_index::IndexVec;
4-
use rustc_index::bit_set::BitSet;
4+
use rustc_index::bit_set::DenseBitSet;
55
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
66
use rustc_middle::mir::{UnwindTerminateReason, traversal};
77
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, TyAndLayout};
@@ -293,7 +293,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
293293
// So drop the builder of `start_llbb` to avoid having two at the same time.
294294
drop(start_bx);
295295

296-
let mut unreached_blocks = BitSet::new_filled(mir.basic_blocks.len());
296+
let mut unreached_blocks = DenseBitSet::new_filled(mir.basic_blocks.len());
297297
// Codegen the body of each reachable block using our reverse postorder list.
298298
for bb in traversal_order {
299299
fx.codegen_block(bb);
@@ -316,7 +316,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
316316
fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
317317
bx: &mut Bx,
318318
fx: &mut FunctionCx<'a, 'tcx, Bx>,
319-
memory_locals: &BitSet<mir::Local>,
319+
memory_locals: &DenseBitSet<mir::Local>,
320320
) -> Vec<LocalRef<'tcx, Bx::Value>> {
321321
let mir = fx.mir;
322322
let mut idx = 0;

compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,13 @@ fn prefix_and_suffix<'tcx>(
132132

133133
let attrs = tcx.codegen_fn_attrs(instance.def_id());
134134
let link_section = attrs.link_section.map(|symbol| symbol.as_str().to_string());
135-
let align = attrs.alignment.map(|a| a.bytes()).unwrap_or(4);
136135

137-
// See https://sourceware.org/binutils/docs/as/ARM-Directives.html for info on these directives.
136+
// function alignment can be set globally with the `-Zmin-function-alignment=<n>` flag;
137+
// the alignment from a `#[repr(align(<n>))]` is used if it specifies a higher alignment.
138+
// if no alignment is specified, an alignment of 4 bytes is used.
139+
let min_function_alignment = tcx.sess.opts.unstable_opts.min_function_alignment;
140+
let align = Ord::max(min_function_alignment, attrs.alignment).map(|a| a.bytes()).unwrap_or(4);
141+
138142
// In particular, `.arm` can also be written `.code 32` and `.thumb` as `.code 16`.
139143
let (arch_prefix, arch_suffix) = if is_arm {
140144
(

compiler/rustc_const_eval/src/check_consts/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_attr_parsing::{ConstStability, StabilityLevel};
1010
use rustc_errors::{Diag, ErrorGuaranteed};
1111
use rustc_hir::def_id::DefId;
1212
use rustc_hir::{self as hir, LangItem};
13-
use rustc_index::bit_set::BitSet;
13+
use rustc_index::bit_set::DenseBitSet;
1414
use rustc_infer::infer::TyCtxtInferExt;
1515
use rustc_middle::mir::visit::Visitor;
1616
use rustc_middle::mir::*;
@@ -172,7 +172,7 @@ pub struct Checker<'mir, 'tcx> {
172172

173173
/// A set that stores for each local whether it is "transient", i.e. guaranteed to be dead
174174
/// when this MIR body returns.
175-
transient_locals: Option<BitSet<Local>>,
175+
transient_locals: Option<DenseBitSet<Local>>,
176176

177177
error_emitted: Option<ErrorGuaranteed>,
178178
secondary_errors: Vec<Diag<'tcx>>,
@@ -242,7 +242,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
242242

243243
// And then check all `Return` in the MIR, and if a local is "maybe live" at a
244244
// `Return` then it is definitely not transient.
245-
let mut transient = BitSet::new_filled(ccx.body.local_decls.len());
245+
let mut transient = DenseBitSet::new_filled(ccx.body.local_decls.len());
246246
// Make sure to only visit reachable blocks, the dataflow engine can ICE otherwise.
247247
for (bb, data) in traversal::reachable(&ccx.body) {
248248
if matches!(data.terminator().kind, TerminatorKind::Return) {

compiler/rustc_data_structures/src/graph/implementation/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
2323
use std::fmt::Debug;
2424

25-
use rustc_index::bit_set::BitSet;
25+
use rustc_index::bit_set::DenseBitSet;
2626
use tracing::debug;
2727

2828
#[cfg(test)]
@@ -214,7 +214,7 @@ impl<N: Debug, E: Debug> Graph<N, E> {
214214
direction: Direction,
215215
entry_node: NodeIndex,
216216
) -> Vec<NodeIndex> {
217-
let mut visited = BitSet::new_empty(self.len_nodes());
217+
let mut visited = DenseBitSet::new_empty(self.len_nodes());
218218
let mut stack = vec![];
219219
let mut result = Vec::with_capacity(self.len_nodes());
220220
let mut push_node = |stack: &mut Vec<_>, node: NodeIndex| {
@@ -287,7 +287,7 @@ impl<'g, N: Debug, E: Debug> Iterator for AdjacentEdges<'g, N, E> {
287287
pub struct DepthFirstTraversal<'g, N, E> {
288288
graph: &'g Graph<N, E>,
289289
stack: Vec<NodeIndex>,
290-
visited: BitSet<usize>,
290+
visited: DenseBitSet<usize>,
291291
direction: Direction,
292292
}
293293

@@ -297,7 +297,7 @@ impl<'g, N: Debug, E: Debug> DepthFirstTraversal<'g, N, E> {
297297
start_node: NodeIndex,
298298
direction: Direction,
299299
) -> Self {
300-
let mut visited = BitSet::new_empty(graph.len_nodes());
300+
let mut visited = DenseBitSet::new_empty(graph.len_nodes());
301301
visited.insert(start_node.node_id());
302302
DepthFirstTraversal { graph, stack: vec![start_node], visited, direction }
303303
}

0 commit comments

Comments
 (0)