Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions compiler/rustc_codegen_ssa/src/back/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,13 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
_ => elf::EF_MIPS_ARCH_64R2,
};

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

if sess.target.options.relocation_model != RelocModel::Static {
Expand Down
81 changes: 44 additions & 37 deletions compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,20 @@ enum Chunk {
/// to store the length, which would make this type larger. These excess
/// words are always zero, as are any excess bits in the final in-use word.
///
/// The `ChunkSize` field is the count of 1s set in the chunk, and
/// must satisfy `0 < count < chunk_domain_size`.
///
/// The words are within an `Rc` because it's surprisingly common to
/// duplicate an entire chunk, e.g. in `ChunkedBitSet::clone_from()`, or
/// when a `Mixed` chunk is union'd into a `Zeros` chunk. When we do need
/// to modify a chunk we use `Rc::make_mut`.
Mixed(ChunkSize, Rc<[Word; CHUNK_WORDS]>),
Mixed {
/// Count of set bits (1s) in this chunk's words.
///
/// Invariant: `0 < ones_count < chunk_domain_size`.
///
/// Tracking this separately allows individual insert/remove calls to
/// know that the chunk has become all-zeroes or all-ones, in O(1) time.
ones_count: ChunkSize,
words: Rc<[Word; CHUNK_WORDS]>,
},
}

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

let (word_index, mask) = chunk_word_index_and_mask(elem);
words_ref[word_index] |= mask;
*chunk = Mixed(1, words);
*chunk = Mixed { ones_count: 1, words };
} else {
*chunk = Ones;
}
true
}
Ones => false,
Mixed(ref mut count, ref mut words) => {
Mixed { ref mut ones_count, ref mut words } => {
// We skip all the work if the bit is already set.
let (word_index, mask) = chunk_word_index_and_mask(elem);
if (words[word_index] & mask) == 0 {
*count += 1;
if *count < chunk_domain_size {
*ones_count += 1;
if *ones_count < chunk_domain_size {
let words = Rc::make_mut(words);
words[word_index] |= mask;
} else {
Expand Down Expand Up @@ -702,18 +708,18 @@ impl<T: Idx> ChunkedBitSet<T> {
);
let (word_index, mask) = chunk_word_index_and_mask(elem);
words_ref[word_index] &= !mask;
*chunk = Mixed(chunk_domain_size - 1, words);
*chunk = Mixed { ones_count: chunk_domain_size - 1, words };
} else {
*chunk = Zeros;
}
true
}
Mixed(ref mut count, ref mut words) => {
Mixed { ref mut ones_count, ref mut words } => {
// We skip all the work if the bit is already clear.
let (word_index, mask) = chunk_word_index_and_mask(elem);
if (words[word_index] & mask) != 0 {
*count -= 1;
if *count > 0 {
*ones_count -= 1;
if *ones_count > 0 {
let words = Rc::make_mut(words);
words[word_index] &= !mask;
} else {
Expand All @@ -732,7 +738,7 @@ impl<T: Idx> ChunkedBitSet<T> {
match self.chunks.get(chunk_index) {
Some(Zeros) => ChunkIter::Zeros,
Some(Ones) => ChunkIter::Ones(0..chunk_domain_size as usize),
Some(Mixed(_, words)) => {
Some(Mixed { ones_count: _, words }) => {
let num_words = num_words(chunk_domain_size as usize);
ChunkIter::Mixed(BitIter::new(&words[0..num_words]))
}
Expand Down Expand Up @@ -765,14 +771,14 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {

match (&mut self_chunk, &other_chunk) {
(_, Zeros) | (Ones, _) => {}
(Zeros, _) | (Mixed(..), Ones) => {
(Zeros, _) | (Mixed { .. }, Ones) => {
// `other_chunk` fully overwrites `self_chunk`
*self_chunk = other_chunk.clone();
changed = true;
}
(
Mixed(self_chunk_count, self_chunk_words),
Mixed(_other_chunk_count, other_chunk_words),
Mixed { ones_count: self_chunk_ones, words: self_chunk_words },
Mixed { ones_count: _, words: other_chunk_words },
) => {
// First check if the operation would change
// `self_chunk.words`. If not, we can avoid allocating some
Expand Down Expand Up @@ -807,8 +813,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
op,
);
debug_assert!(has_changed);
*self_chunk_count = count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
if *self_chunk_count == chunk_domain_size {
*self_chunk_ones = count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
if *self_chunk_ones == chunk_domain_size {
*self_chunk = Ones;
}
changed = true;
Expand Down Expand Up @@ -839,11 +845,11 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {

match (&mut self_chunk, &other_chunk) {
(Zeros, _) | (_, Zeros) => {}
(Ones | Mixed(..), Ones) => {
(Ones | Mixed { .. }, Ones) => {
changed = true;
*self_chunk = Zeros;
}
(Ones, Mixed(other_chunk_count, other_chunk_words)) => {
(Ones, Mixed { ones_count: other_chunk_ones, words: other_chunk_words }) => {
changed = true;
let num_words = num_words(chunk_domain_size as usize);
debug_assert!(num_words > 0 && num_words <= CHUNK_WORDS);
Expand All @@ -854,16 +860,17 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
*word = !*word & tail_mask;
tail_mask = Word::MAX;
}
let self_chunk_count = chunk_domain_size - *other_chunk_count;
let self_chunk_ones = chunk_domain_size - *other_chunk_ones;
debug_assert_eq!(
self_chunk_count,
self_chunk_ones,
count_ones(&self_chunk_words[0..num_words]) as ChunkSize
);
*self_chunk = Mixed(self_chunk_count, Rc::new(self_chunk_words));
*self_chunk =
Mixed { ones_count: self_chunk_ones, words: Rc::new(self_chunk_words) };
}
(
Mixed(self_chunk_count, self_chunk_words),
Mixed(_other_chunk_count, other_chunk_words),
Mixed { ones_count: self_chunk_ones, words: self_chunk_words },
Mixed { ones_count: _, words: other_chunk_words },
) => {
// See `ChunkedBitSet::union` for details on what is happening here.
let num_words = num_words(chunk_domain_size as usize);
Expand All @@ -883,8 +890,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
op,
);
debug_assert!(has_changed);
*self_chunk_count = count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
if *self_chunk_count == 0 {
*self_chunk_ones = count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
if *self_chunk_ones == 0 {
*self_chunk = Zeros;
}
changed = true;
Expand Down Expand Up @@ -915,13 +922,13 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {

match (&mut self_chunk, &other_chunk) {
(Zeros, _) | (_, Ones) => {}
(Ones, Zeros | Mixed(..)) | (Mixed(..), Zeros) => {
(Ones, Zeros | Mixed { .. }) | (Mixed { .. }, Zeros) => {
changed = true;
*self_chunk = other_chunk.clone();
}
(
Mixed(self_chunk_count, self_chunk_words),
Mixed(_other_chunk_count, other_chunk_words),
Mixed { ones_count: self_chunk_ones, words: self_chunk_words },
Mixed { ones_count: _, words: other_chunk_words },
) => {
// See `ChunkedBitSet::union` for details on what is happening here.
let num_words = num_words(chunk_domain_size as usize);
Expand All @@ -941,8 +948,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
op,
);
debug_assert!(has_changed);
*self_chunk_count = count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
if *self_chunk_count == 0 {
*self_chunk_ones = count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
if *self_chunk_ones == 0 {
*self_chunk = Zeros;
}
changed = true;
Expand Down Expand Up @@ -1023,11 +1030,11 @@ impl Chunk {
assert!(chunk_domain_size as usize <= CHUNK_BITS);
match *self {
Zeros | Ones => {}
Mixed(count, ref words) => {
assert!(0 < count && count < chunk_domain_size);
Mixed { ones_count, ref words } => {
assert!(0 < ones_count && ones_count < chunk_domain_size);

// Check the number of set bits matches `count`.
assert_eq!(count_ones(words.as_slice()) as ChunkSize, count);
assert_eq!(count_ones(words.as_slice()) as ChunkSize, ones_count);

// Check the not-in-use words are all zeroed.
let num_words = num_words(chunk_domain_size as usize);
Expand All @@ -1043,7 +1050,7 @@ impl Chunk {
match *self {
Zeros => 0,
Ones => chunk_domain_size as usize,
Mixed(count, _) => count as usize,
Mixed { ones_count, words: _ } => usize::from(ones_count),
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_index/src/bit_set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,16 @@ fn chunked_bitset() {
assert!(!b100.contains(20) && b100.contains(30) && !b100.contains(99) && b100.contains(50));
assert_eq!(
b100.chunks(),
vec![Mixed(
97,
vec![Mixed {
ones_count: 97,
#[rustfmt::skip]
Rc::new([
words: Rc::new([
0b11111111_11111111_11111110_11111111_11111111_11101111_11111111_11111111,
0b00000000_00000000_00000000_00000111_11111111_11111111_11111111_11111111,
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,
0, 0, 0, 0, 0,
])
)],
}],
);
b100.assert_valid();
let mut num_removed = 0;
Expand Down Expand Up @@ -228,14 +228,14 @@ fn chunked_bitset() {
b4096.chunks(),
#[rustfmt::skip]
vec![
Mixed(1, Rc::new([
Mixed { ones_count: 1, words:Rc::new([
1, 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, 0, 0, 0, 0, 0, 0
])),
Mixed(1, Rc::new([
])},
Mixed { ones_count: 1, words: Rc::new([
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, 0, 0, 0, 0, 0, 0, 0x8000_0000_0000_0000
])),
])},
],
);
assert_eq!(b4096.count(), 2);
Expand Down Expand Up @@ -265,14 +265,14 @@ fn chunked_bitset() {
#[rustfmt::skip]
vec![
Zeros,
Mixed(1, Rc::new([
Mixed { ones_count: 1, words: Rc::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0100_0000_0000_0000, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
])),
Mixed(1, Rc::new([
])},
Mixed { ones_count: 1, words: Rc::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0100, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
])),
])},
Zeros,
Zeros,
],
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ use crate::ty::{
self, CrateInherentImpls, GenericArg, GenericArgsRef, LitToConstInput, PseudoCanonicalInput,
SizedTraitKind, Ty, TyCtxt, TyCtxtFeed,
};
use crate::{dep_graph, mir, thir};
use crate::{mir, thir};

// Each of these queries corresponds to a function pointer field in the
// `Providers` struct for requesting a value of that type, and a method
Expand Down
26 changes: 13 additions & 13 deletions compiler/rustc_middle/src/query/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};

use crate::dep_graph;
use crate::dep_graph::{DepKind, DepNodeKey};
use crate::dep_graph::DepNodeKey;
use crate::query::erase::{self, Erasable, Erased};
use crate::query::plumbing::QueryVTable;
use crate::query::{EnsureMode, QueryCache, QueryMode};
Expand Down Expand Up @@ -98,26 +98,26 @@ where
}
}

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

// Check whether the in-memory cache already has a value for this key.
match try_get_cached(tcx, &query_vtable.cache, key) {
match try_get_cached(tcx, &query.cache, key) {
Some(old) => {
// The query already has a cached value for this key.
// That's OK if both values are the same, i.e. they have the same hash,
// so now we check their hashes.
if let Some(hash_value_fn) = query_vtable.hash_value_fn {
if let Some(hash_value_fn) = query.hash_value_fn {
let (old_hash, value_hash) = tcx.with_stable_hashing_context(|ref mut hcx| {
(hash_value_fn(hcx, &old), hash_value_fn(hcx, &value))
});
Expand All @@ -126,7 +126,7 @@ pub(crate) fn query_feed<'tcx, C>(
// results is tainted by errors. In this case, delay a bug to
// ensure compilation is doomed, and keep the `old` value.
tcx.dcx().delayed_bug(format!(
"Trying to feed an already recorded value for query {dep_kind:?} key={key:?}:\n\
"Trying to feed an already recorded value for query {query:?} key={key:?}:\n\
old value: {old}\nnew value: {value}",
old = format_value(&old),
value = format_value(&value),
Expand All @@ -137,7 +137,7 @@ pub(crate) fn query_feed<'tcx, C>(
// If feeding the same value multiple times needs to be supported,
// the query should not be marked `no_hash`.
bug!(
"Trying to feed an already recorded value for query {dep_kind:?} key={key:?}:\n\
"Trying to feed an already recorded value for query {query:?} key={key:?}:\n\
old value: {old}\nnew value: {value}",
old = format_value(&old),
value = format_value(&value),
Expand All @@ -147,15 +147,15 @@ pub(crate) fn query_feed<'tcx, C>(
None => {
// There is no cached value for this key, so feed the query by
// adding the provided value to the cache.
let dep_node = dep_graph::DepNode::construct(tcx, dep_kind, &key);
let dep_node = dep_graph::DepNode::construct(tcx, query.dep_kind, &key);
let dep_node_index = tcx.dep_graph.with_feed_task(
dep_node,
tcx,
&value,
query_vtable.hash_value_fn,
query_vtable.format_value,
query.hash_value_fn,
query.format_value,
);
query_vtable.cache.complete(key, value, dep_node_index);
query.cache.complete(key, value, dep_node_index);
}
}
}
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ macro_rules! define_callbacks {
let erased_value = $name::provided_to_erased(self.tcx, value);
$crate::query::inner::query_feed(
self.tcx,
dep_graph::DepKind::$name,
&self.tcx.query_system.query_vtables.$name,
key,
erased_value,
Expand Down
Loading
Loading