Skip to content

Commit 798a011

Browse files
committed
Auto merge of #153865 - Zalathar:rollup-tKflfa5, r=Zalathar
Rollup of 5 pull requests Successful merges: - #153769 (target specs: stricter checks for LLVM ABI values, and correlate that with cfg(target_abi)) - #153811 (Don't pass a separate `DepKind` to `query_feed`) - #153817 (relocate several ui tests) - #153840 (tests/debuginfo/basic-stepping.rs: Add cdb test) - #153858 (Use named fields in ChunkedBitSet's `Chunk::Mixed`)
2 parents fd26499 + 4f3a0ff commit 798a011

31 files changed

Lines changed: 386 additions & 126 deletions

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,13 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
294294
_ => elf::EF_MIPS_ARCH_64R2,
295295
};
296296

297-
// If the ABI is explicitly given, use it, or default to O32 on 32-bit MIPS,
298-
// which is the only "true" 32-bit option that LLVM supports.
297+
// Use the explicitly given ABI.
299298
match sess.target.options.llvm_abiname.as_ref() {
300299
"o32" if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32,
301300
"n32" if !is_32bit => e_flags |= elf::EF_MIPS_ABI2,
302301
"n64" if !is_32bit => {}
303-
"" if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32,
304-
"" => sess.dcx().fatal("LLVM ABI must be specified for 64-bit MIPS targets"),
305-
s if is_32bit => {
306-
sess.dcx().fatal(format!("invalid LLVM ABI `{}` for 32-bit MIPS target", s))
307-
}
308-
s => sess.dcx().fatal(format!("invalid LLVM ABI `{}` for 64-bit MIPS target", s)),
302+
// The rest is invalid (which is already ensured by the target spec check).
303+
s => bug!("invalid LLVM ABI `{}` for MIPS target", s),
309304
};
310305

311306
if sess.target.options.relocation_model != RelocModel::Static {

compiler/rustc_index/src/bit_set.rs

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -509,14 +509,20 @@ enum Chunk {
509509
/// to store the length, which would make this type larger. These excess
510510
/// words are always zero, as are any excess bits in the final in-use word.
511511
///
512-
/// The `ChunkSize` field is the count of 1s set in the chunk, and
513-
/// must satisfy `0 < count < chunk_domain_size`.
514-
///
515512
/// The words are within an `Rc` because it's surprisingly common to
516513
/// duplicate an entire chunk, e.g. in `ChunkedBitSet::clone_from()`, or
517514
/// when a `Mixed` chunk is union'd into a `Zeros` chunk. When we do need
518515
/// to modify a chunk we use `Rc::make_mut`.
519-
Mixed(ChunkSize, Rc<[Word; CHUNK_WORDS]>),
516+
Mixed {
517+
/// Count of set bits (1s) in this chunk's words.
518+
///
519+
/// Invariant: `0 < ones_count < chunk_domain_size`.
520+
///
521+
/// Tracking this separately allows individual insert/remove calls to
522+
/// know that the chunk has become all-zeroes or all-ones, in O(1) time.
523+
ones_count: ChunkSize,
524+
words: Rc<[Word; CHUNK_WORDS]>,
525+
},
520526
}
521527

522528
// This type is used a lot. Make sure it doesn't unintentionally get bigger.
@@ -613,7 +619,7 @@ impl<T: Idx> ChunkedBitSet<T> {
613619
match &chunk {
614620
Zeros => false,
615621
Ones => true,
616-
Mixed(_, words) => {
622+
Mixed { ones_count: _, words } => {
617623
let (word_index, mask) = chunk_word_index_and_mask(elem);
618624
(words[word_index] & mask) != 0
619625
}
@@ -644,19 +650,19 @@ impl<T: Idx> ChunkedBitSet<T> {
644650

645651
let (word_index, mask) = chunk_word_index_and_mask(elem);
646652
words_ref[word_index] |= mask;
647-
*chunk = Mixed(1, words);
653+
*chunk = Mixed { ones_count: 1, words };
648654
} else {
649655
*chunk = Ones;
650656
}
651657
true
652658
}
653659
Ones => false,
654-
Mixed(ref mut count, ref mut words) => {
660+
Mixed { ref mut ones_count, ref mut words } => {
655661
// We skip all the work if the bit is already set.
656662
let (word_index, mask) = chunk_word_index_and_mask(elem);
657663
if (words[word_index] & mask) == 0 {
658-
*count += 1;
659-
if *count < chunk_domain_size {
664+
*ones_count += 1;
665+
if *ones_count < chunk_domain_size {
660666
let words = Rc::make_mut(words);
661667
words[word_index] |= mask;
662668
} else {
@@ -702,18 +708,18 @@ impl<T: Idx> ChunkedBitSet<T> {
702708
);
703709
let (word_index, mask) = chunk_word_index_and_mask(elem);
704710
words_ref[word_index] &= !mask;
705-
*chunk = Mixed(chunk_domain_size - 1, words);
711+
*chunk = Mixed { ones_count: chunk_domain_size - 1, words };
706712
} else {
707713
*chunk = Zeros;
708714
}
709715
true
710716
}
711-
Mixed(ref mut count, ref mut words) => {
717+
Mixed { ref mut ones_count, ref mut words } => {
712718
// We skip all the work if the bit is already clear.
713719
let (word_index, mask) = chunk_word_index_and_mask(elem);
714720
if (words[word_index] & mask) != 0 {
715-
*count -= 1;
716-
if *count > 0 {
721+
*ones_count -= 1;
722+
if *ones_count > 0 {
717723
let words = Rc::make_mut(words);
718724
words[word_index] &= !mask;
719725
} else {
@@ -732,7 +738,7 @@ impl<T: Idx> ChunkedBitSet<T> {
732738
match self.chunks.get(chunk_index) {
733739
Some(Zeros) => ChunkIter::Zeros,
734740
Some(Ones) => ChunkIter::Ones(0..chunk_domain_size as usize),
735-
Some(Mixed(_, words)) => {
741+
Some(Mixed { ones_count: _, words }) => {
736742
let num_words = num_words(chunk_domain_size as usize);
737743
ChunkIter::Mixed(BitIter::new(&words[0..num_words]))
738744
}
@@ -765,14 +771,14 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
765771

766772
match (&mut self_chunk, &other_chunk) {
767773
(_, Zeros) | (Ones, _) => {}
768-
(Zeros, _) | (Mixed(..), Ones) => {
774+
(Zeros, _) | (Mixed { .. }, Ones) => {
769775
// `other_chunk` fully overwrites `self_chunk`
770776
*self_chunk = other_chunk.clone();
771777
changed = true;
772778
}
773779
(
774-
Mixed(self_chunk_count, self_chunk_words),
775-
Mixed(_other_chunk_count, other_chunk_words),
780+
Mixed { ones_count: self_chunk_ones, words: self_chunk_words },
781+
Mixed { ones_count: _, words: other_chunk_words },
776782
) => {
777783
// First check if the operation would change
778784
// `self_chunk.words`. If not, we can avoid allocating some
@@ -807,8 +813,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
807813
op,
808814
);
809815
debug_assert!(has_changed);
810-
*self_chunk_count = count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
811-
if *self_chunk_count == chunk_domain_size {
816+
*self_chunk_ones = count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
817+
if *self_chunk_ones == chunk_domain_size {
812818
*self_chunk = Ones;
813819
}
814820
changed = true;
@@ -839,11 +845,11 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
839845

840846
match (&mut self_chunk, &other_chunk) {
841847
(Zeros, _) | (_, Zeros) => {}
842-
(Ones | Mixed(..), Ones) => {
848+
(Ones | Mixed { .. }, Ones) => {
843849
changed = true;
844850
*self_chunk = Zeros;
845851
}
846-
(Ones, Mixed(other_chunk_count, other_chunk_words)) => {
852+
(Ones, Mixed { ones_count: other_chunk_ones, words: other_chunk_words }) => {
847853
changed = true;
848854
let num_words = num_words(chunk_domain_size as usize);
849855
debug_assert!(num_words > 0 && num_words <= CHUNK_WORDS);
@@ -854,16 +860,17 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
854860
*word = !*word & tail_mask;
855861
tail_mask = Word::MAX;
856862
}
857-
let self_chunk_count = chunk_domain_size - *other_chunk_count;
863+
let self_chunk_ones = chunk_domain_size - *other_chunk_ones;
858864
debug_assert_eq!(
859-
self_chunk_count,
865+
self_chunk_ones,
860866
count_ones(&self_chunk_words[0..num_words]) as ChunkSize
861867
);
862-
*self_chunk = Mixed(self_chunk_count, Rc::new(self_chunk_words));
868+
*self_chunk =
869+
Mixed { ones_count: self_chunk_ones, words: Rc::new(self_chunk_words) };
863870
}
864871
(
865-
Mixed(self_chunk_count, self_chunk_words),
866-
Mixed(_other_chunk_count, other_chunk_words),
872+
Mixed { ones_count: self_chunk_ones, words: self_chunk_words },
873+
Mixed { ones_count: _, words: other_chunk_words },
867874
) => {
868875
// See `ChunkedBitSet::union` for details on what is happening here.
869876
let num_words = num_words(chunk_domain_size as usize);
@@ -883,8 +890,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
883890
op,
884891
);
885892
debug_assert!(has_changed);
886-
*self_chunk_count = count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
887-
if *self_chunk_count == 0 {
893+
*self_chunk_ones = count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
894+
if *self_chunk_ones == 0 {
888895
*self_chunk = Zeros;
889896
}
890897
changed = true;
@@ -915,13 +922,13 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
915922

916923
match (&mut self_chunk, &other_chunk) {
917924
(Zeros, _) | (_, Ones) => {}
918-
(Ones, Zeros | Mixed(..)) | (Mixed(..), Zeros) => {
925+
(Ones, Zeros | Mixed { .. }) | (Mixed { .. }, Zeros) => {
919926
changed = true;
920927
*self_chunk = other_chunk.clone();
921928
}
922929
(
923-
Mixed(self_chunk_count, self_chunk_words),
924-
Mixed(_other_chunk_count, other_chunk_words),
930+
Mixed { ones_count: self_chunk_ones, words: self_chunk_words },
931+
Mixed { ones_count: _, words: other_chunk_words },
925932
) => {
926933
// See `ChunkedBitSet::union` for details on what is happening here.
927934
let num_words = num_words(chunk_domain_size as usize);
@@ -941,8 +948,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
941948
op,
942949
);
943950
debug_assert!(has_changed);
944-
*self_chunk_count = count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
945-
if *self_chunk_count == 0 {
951+
*self_chunk_ones = count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
952+
if *self_chunk_ones == 0 {
946953
*self_chunk = Zeros;
947954
}
948955
changed = true;
@@ -1023,11 +1030,11 @@ impl Chunk {
10231030
assert!(chunk_domain_size as usize <= CHUNK_BITS);
10241031
match *self {
10251032
Zeros | Ones => {}
1026-
Mixed(count, ref words) => {
1027-
assert!(0 < count && count < chunk_domain_size);
1033+
Mixed { ones_count, ref words } => {
1034+
assert!(0 < ones_count && ones_count < chunk_domain_size);
10281035

10291036
// Check the number of set bits matches `count`.
1030-
assert_eq!(count_ones(words.as_slice()) as ChunkSize, count);
1037+
assert_eq!(count_ones(words.as_slice()) as ChunkSize, ones_count);
10311038

10321039
// Check the not-in-use words are all zeroed.
10331040
let num_words = num_words(chunk_domain_size as usize);
@@ -1043,7 +1050,7 @@ impl Chunk {
10431050
match *self {
10441051
Zeros => 0,
10451052
Ones => chunk_domain_size as usize,
1046-
Mixed(count, _) => count as usize,
1053+
Mixed { ones_count, words: _ } => usize::from(ones_count),
10471054
}
10481055
}
10491056
}

compiler/rustc_index/src/bit_set/tests.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,16 @@ fn chunked_bitset() {
162162
assert!(!b100.contains(20) && b100.contains(30) && !b100.contains(99) && b100.contains(50));
163163
assert_eq!(
164164
b100.chunks(),
165-
vec![Mixed(
166-
97,
165+
vec![Mixed {
166+
ones_count: 97,
167167
#[rustfmt::skip]
168-
Rc::new([
168+
words: Rc::new([
169169
0b11111111_11111111_11111110_11111111_11111111_11101111_11111111_11111111,
170170
0b00000000_00000000_00000000_00000111_11111111_11111111_11111111_11111111,
171171
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
172172
0, 0, 0, 0, 0,
173173
])
174-
)],
174+
}],
175175
);
176176
b100.assert_valid();
177177
let mut num_removed = 0;
@@ -228,14 +228,14 @@ fn chunked_bitset() {
228228
b4096.chunks(),
229229
#[rustfmt::skip]
230230
vec![
231-
Mixed(1, Rc::new([
231+
Mixed { ones_count: 1, words:Rc::new([
232232
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
233233
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
234-
])),
235-
Mixed(1, Rc::new([
234+
])},
235+
Mixed { ones_count: 1, words: Rc::new([
236236
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
237237
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x8000_0000_0000_0000
238-
])),
238+
])},
239239
],
240240
);
241241
assert_eq!(b4096.count(), 2);
@@ -265,14 +265,14 @@ fn chunked_bitset() {
265265
#[rustfmt::skip]
266266
vec![
267267
Zeros,
268-
Mixed(1, Rc::new([
268+
Mixed { ones_count: 1, words: Rc::new([
269269
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0100_0000_0000_0000, 0,
270270
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
271-
])),
272-
Mixed(1, Rc::new([
271+
])},
272+
Mixed { ones_count: 1, words: Rc::new([
273273
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0100, 0,
274274
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
275-
])),
275+
])},
276276
Zeros,
277277
Zeros,
278278
],

compiler/rustc_middle/src/queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ use crate::ty::{
120120
self, CrateInherentImpls, GenericArg, GenericArgsRef, LitToConstInput, PseudoCanonicalInput,
121121
SizedTraitKind, Ty, TyCtxt, TyCtxtFeed,
122122
};
123-
use crate::{dep_graph, mir, thir};
123+
use crate::{mir, thir};
124124

125125
// Each of these queries corresponds to a function pointer field in the
126126
// `Providers` struct for requesting a value of that type, and a method

compiler/rustc_middle/src/query/inner.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
55

66
use crate::dep_graph;
7-
use crate::dep_graph::{DepKind, DepNodeKey};
7+
use crate::dep_graph::DepNodeKey;
88
use crate::query::erase::{self, Erasable, Erased};
99
use crate::query::plumbing::QueryVTable;
1010
use crate::query::{EnsureMode, QueryCache, QueryMode};
@@ -98,26 +98,26 @@ where
9898
}
9999
}
100100

101-
/// Common implementation of query feeding, used by `define_feedable!`.
101+
/// "Feeds" a feedable query by adding a given key/value pair to its in-memory cache.
102+
/// Called by macro-generated methods of [`rustc_middle::ty::TyCtxtFeed`].
102103
pub(crate) fn query_feed<'tcx, C>(
103104
tcx: TyCtxt<'tcx>,
104-
dep_kind: DepKind,
105-
query_vtable: &QueryVTable<'tcx, C>,
105+
query: &'tcx QueryVTable<'tcx, C>,
106106
key: C::Key,
107107
value: C::Value,
108108
) where
109109
C: QueryCache,
110110
C::Key: DepNodeKey<'tcx>,
111111
{
112-
let format_value = query_vtable.format_value;
112+
let format_value = query.format_value;
113113

114114
// Check whether the in-memory cache already has a value for this key.
115-
match try_get_cached(tcx, &query_vtable.cache, key) {
115+
match try_get_cached(tcx, &query.cache, key) {
116116
Some(old) => {
117117
// The query already has a cached value for this key.
118118
// That's OK if both values are the same, i.e. they have the same hash,
119119
// so now we check their hashes.
120-
if let Some(hash_value_fn) = query_vtable.hash_value_fn {
120+
if let Some(hash_value_fn) = query.hash_value_fn {
121121
let (old_hash, value_hash) = tcx.with_stable_hashing_context(|ref mut hcx| {
122122
(hash_value_fn(hcx, &old), hash_value_fn(hcx, &value))
123123
});
@@ -126,7 +126,7 @@ pub(crate) fn query_feed<'tcx, C>(
126126
// results is tainted by errors. In this case, delay a bug to
127127
// ensure compilation is doomed, and keep the `old` value.
128128
tcx.dcx().delayed_bug(format!(
129-
"Trying to feed an already recorded value for query {dep_kind:?} key={key:?}:\n\
129+
"Trying to feed an already recorded value for query {query:?} key={key:?}:\n\
130130
old value: {old}\nnew value: {value}",
131131
old = format_value(&old),
132132
value = format_value(&value),
@@ -137,7 +137,7 @@ pub(crate) fn query_feed<'tcx, C>(
137137
// If feeding the same value multiple times needs to be supported,
138138
// the query should not be marked `no_hash`.
139139
bug!(
140-
"Trying to feed an already recorded value for query {dep_kind:?} key={key:?}:\n\
140+
"Trying to feed an already recorded value for query {query:?} key={key:?}:\n\
141141
old value: {old}\nnew value: {value}",
142142
old = format_value(&old),
143143
value = format_value(&value),
@@ -147,15 +147,15 @@ pub(crate) fn query_feed<'tcx, C>(
147147
None => {
148148
// There is no cached value for this key, so feed the query by
149149
// adding the provided value to the cache.
150-
let dep_node = dep_graph::DepNode::construct(tcx, dep_kind, &key);
150+
let dep_node = dep_graph::DepNode::construct(tcx, query.dep_kind, &key);
151151
let dep_node_index = tcx.dep_graph.with_feed_task(
152152
dep_node,
153153
tcx,
154154
&value,
155-
query_vtable.hash_value_fn,
156-
query_vtable.format_value,
155+
query.hash_value_fn,
156+
query.format_value,
157157
);
158-
query_vtable.cache.complete(key, value, dep_node_index);
158+
query.cache.complete(key, value, dep_node_index);
159159
}
160160
}
161161
}

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,6 @@ macro_rules! define_callbacks {
493493
let erased_value = $name::provided_to_erased(self.tcx, value);
494494
$crate::query::inner::query_feed(
495495
self.tcx,
496-
dep_graph::DepKind::$name,
497496
&self.tcx.query_system.query_vtables.$name,
498497
key,
499498
erased_value,

0 commit comments

Comments
 (0)