Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
12 changes: 1 addition & 11 deletions compiler/rustc_hir/src/attrs/pretty_printing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ pub trait PrintAttribute {
fn print_attribute(&self, p: &mut Printer);
}

impl PrintAttribute for u128 {
fn should_render(&self) -> bool {
true
}

fn print_attribute(&self, p: &mut Printer) {
p.word(self.to_string())
}
}

impl<T: PrintAttribute> PrintAttribute for &T {
fn should_render(&self) -> bool {
T::should_render(self)
Expand Down Expand Up @@ -148,7 +138,7 @@ macro_rules! print_tup {

print_tup!(A B C D E F G H);
print_skip!(Span, (), ErrorGuaranteed);
print_disp!(u16, bool, NonZero<u32>, Limit);
print_disp!(u16, u128, bool, NonZero<u32>, Limit);
print_debug!(
Symbol,
Ident,
Expand Down
100 changes: 18 additions & 82 deletions compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl<T: Idx> DenseBitSet<T> {

/// Count the number of set bits in the set.
pub fn count(&self) -> usize {
self.words.iter().map(|e| e.count_ones() as usize).sum()
count_ones(&self.words)
}

/// Returns `true` if `self` contains `elem`.
Expand Down Expand Up @@ -786,7 +786,7 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {

match (&mut self_chunk, &other_chunk) {
(_, Zeros) | (Ones, _) => {}
(Zeros, Ones) | (Mixed(..), Ones) | (Zeros, Mixed(..)) => {
(Zeros, _) | (Mixed(..), Ones) => {
// `other_chunk` fully overwrites `self_chunk`
*self_chunk = other_chunk.clone();
changed = true;
Expand Down Expand Up @@ -814,10 +814,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
op,
);
debug_assert!(has_changed);
*self_chunk_count = self_chunk_words[0..num_words]
.iter()
.map(|w| w.count_ones() as ChunkSize)
.sum();
*self_chunk_count =
count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
if *self_chunk_count == chunk_domain_size {
*self_chunk = Ones;
}
Expand Down Expand Up @@ -850,7 +848,7 @@ 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;
}
Expand All @@ -868,10 +866,7 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
let self_chunk_count = chunk_domain_size - *other_chunk_count;
debug_assert_eq!(
self_chunk_count,
self_chunk_words[0..num_words]
.iter()
.map(|w| w.count_ones() as ChunkSize)
.sum()
count_ones(&self_chunk_words[0..num_words]) as ChunkSize
);
*self_chunk = Mixed(self_chunk_count, Rc::new(self_chunk_words));
}
Expand All @@ -894,10 +889,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
op,
);
debug_assert!(has_changed);
*self_chunk_count = self_chunk_words[0..num_words]
.iter()
.map(|w| w.count_ones() as ChunkSize)
.sum();
*self_chunk_count =
count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
if *self_chunk_count == 0 {
*self_chunk = Zeros;
}
Expand Down Expand Up @@ -953,10 +946,8 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
op,
);
debug_assert!(has_changed);
*self_chunk_count = self_chunk_words[0..num_words]
.iter()
.map(|w| w.count_ones() as ChunkSize)
.sum();
*self_chunk_count =
count_ones(&self_chunk_words[0..num_words]) as ChunkSize;
if *self_chunk_count == 0 {
*self_chunk = Zeros;
}
Expand All @@ -970,48 +961,6 @@ impl<T: Idx> BitRelations<ChunkedBitSet<T>> for ChunkedBitSet<T> {
}
}

impl<T: Idx> BitRelations<ChunkedBitSet<T>> for DenseBitSet<T> {
fn union(&mut self, other: &ChunkedBitSet<T>) -> bool {
sequential_update(|elem| self.insert(elem), other.iter())
}

fn subtract(&mut self, _other: &ChunkedBitSet<T>) -> bool {
unimplemented!("implement if/when necessary");
}

fn intersect(&mut self, other: &ChunkedBitSet<T>) -> bool {
assert_eq!(self.domain_size(), other.domain_size);
let mut changed = false;
for (i, chunk) in other.chunks.iter().enumerate() {
let mut words = &mut self.words[i * CHUNK_WORDS..];
if words.len() > CHUNK_WORDS {
words = &mut words[..CHUNK_WORDS];
}
match chunk {
Zeros => {
for word in words {
if *word != 0 {
changed = true;
*word = 0;
}
}
}
Ones => (),
Mixed(_, data) => {
for (i, word) in words.iter_mut().enumerate() {
let new_val = *word & data[i];
if new_val != *word {
changed = true;
*word = new_val;
}
}
}
}
}
changed
}
}

impl<T> Clone for ChunkedBitSet<T> {
fn clone(&self) -> Self {
ChunkedBitSet {
Expand Down Expand Up @@ -1085,21 +1034,12 @@ impl Chunk {
assert!(0 < count && count < chunk_domain_size);

// Check the number of set bits matches `count`.
assert_eq!(
words.iter().map(|w| w.count_ones() as ChunkSize).sum::<ChunkSize>(),
count
);
assert_eq!(count_ones(words.as_slice()) as ChunkSize, count);

// Check the not-in-use words are all zeroed.
let num_words = num_words(chunk_domain_size as usize);
if num_words < CHUNK_WORDS {
assert_eq!(
words[num_words..]
.iter()
.map(|w| w.count_ones() as ChunkSize)
.sum::<ChunkSize>(),
0
);
assert_eq!(count_ones(&words[num_words..]) as ChunkSize, 0);
}
}
}
Expand All @@ -1122,15 +1062,6 @@ enum ChunkIter<'a> {
Finished,
}

// Applies a function to mutate a bitset, and returns true if any
// of the applications return true
fn sequential_update<T: Idx>(
mut self_update: impl FnMut(T) -> bool,
it: impl Iterator<Item = T>,
) -> bool {
it.fold(false, |changed, elem| self_update(elem) | changed)
}

impl<T: Idx> fmt::Debug for ChunkedBitSet<T> {
fn fmt(&self, w: &mut fmt::Formatter<'_>) -> fmt::Result {
w.debug_list().entries(self.iter()).finish()
Expand Down Expand Up @@ -1590,7 +1521,7 @@ impl<R: Idx, C: Idx> BitMatrix<R, C> {
/// Returns the number of elements in `row`.
pub fn count(&self, row: R) -> usize {
let (start, end) = self.range(row);
self.words[start..end].iter().map(|e| e.count_ones() as usize).sum()
count_ones(&self.words[start..end])
}
}

Expand Down Expand Up @@ -1801,6 +1732,11 @@ fn max_bit(word: Word) -> usize {
WORD_BITS - 1 - word.leading_zeros() as usize
}

#[inline]
fn count_ones(words: &[Word]) -> usize {
words.iter().map(|word| word.count_ones() as usize).sum()
}

/// Integral type used to represent the bit set.
pub trait FiniteBitSetTy:
BitAnd<Output = Self>
Expand Down
28 changes: 0 additions & 28 deletions compiler/rustc_index/src/bit_set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,34 +306,6 @@ fn with_elements_chunked(elements: &[usize], domain_size: usize) -> ChunkedBitSe
s
}

fn with_elements_standard(elements: &[usize], domain_size: usize) -> DenseBitSet<usize> {
let mut s = DenseBitSet::new_empty(domain_size);
for &e in elements {
assert!(s.insert(e));
}
s
}

#[test]
fn chunked_bitset_into_bitset_operations() {
let a = vec![1, 5, 7, 11, 15, 2000, 3000];
let b = vec![3, 4, 11, 3000, 4000];
let aub = vec![1, 3, 4, 5, 7, 11, 15, 2000, 3000, 4000];
let aib = vec![11, 3000];

let b = with_elements_chunked(&b, 9876);

let mut union = with_elements_standard(&a, 9876);
assert!(union.union(&b));
assert!(!union.union(&b));
assert!(union.iter().eq(aub.iter().copied()));

let mut intersection = with_elements_standard(&a, 9876);
assert!(intersection.intersect(&b));
assert!(!intersection.intersect(&b));
assert!(intersection.iter().eq(aib.iter().copied()));
}

#[test]
fn chunked_bitset_iter() {
fn check_iter(bit: &ChunkedBitSet<usize>, vec: &Vec<usize>) {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_lint/src/shadowed_into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ impl<'tcx> LateLintPass<'tcx> for ShadowedIntoIter {
&& let hir::ExprKind::Call(path, [_]) = &arg.kind
&& let hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::IntoIterIntoIter, ..)) =
&path.kind
&& !receiver_arg.span.from_expansion()
&& !expr.span.from_expansion()
{
Some(ShadowedIntoIterDiagSub::RemoveIntoIter {
span: receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()),
Expand Down
4 changes: 2 additions & 2 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ dependencies = [

[[package]]
name = "libc"
version = "0.2.175"
version = "0.2.177"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
7 changes: 6 additions & 1 deletion library/core/src/mem/manually_drop.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::marker::Destruct;
use crate::ops::{Deref, DerefMut, DerefPure};
use crate::ptr;

Expand Down Expand Up @@ -249,7 +250,11 @@ impl<T: ?Sized> ManuallyDrop<T> {
/// [pinned]: crate::pin
#[stable(feature = "manually_drop", since = "1.20.0")]
#[inline]
pub unsafe fn drop(slot: &mut ManuallyDrop<T>) {
#[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")]
pub const unsafe fn drop(slot: &mut ManuallyDrop<T>)
where
T: [const] Destruct,
{
// SAFETY: we are dropping the value pointed to by a mutable reference
// which is guaranteed to be valid for writes.
// It is up to the caller to make sure that `slot` isn't dropped again.
Expand Down
13 changes: 11 additions & 2 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::any::type_name;
use crate::marker::Destruct;
use crate::mem::ManuallyDrop;
use crate::{fmt, intrinsics, ptr, slice};

Expand Down Expand Up @@ -714,7 +715,11 @@ impl<T> MaybeUninit<T> {
///
/// [`assume_init`]: MaybeUninit::assume_init
#[stable(feature = "maybe_uninit_extra", since = "1.60.0")]
pub unsafe fn assume_init_drop(&mut self) {
#[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")]
pub const unsafe fn assume_init_drop(&mut self)
where
T: [const] Destruct,
{
// SAFETY: the caller must guarantee that `self` is initialized and
// satisfies all invariants of `T`.
// Dropping the value in place is safe if that is the case.
Expand Down Expand Up @@ -1390,7 +1395,11 @@ impl<T> [MaybeUninit<T>] {
/// behaviour.
#[unstable(feature = "maybe_uninit_slice", issue = "63569")]
#[inline(always)]
pub unsafe fn assume_init_drop(&mut self) {
#[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")]
pub const unsafe fn assume_init_drop(&mut self)
where
T: [const] Destruct,
{
if !self.is_empty() {
// SAFETY: the caller must guarantee that every element of `self`
// is initialized and satisfies all invariants of `T`.
Expand Down
5 changes: 2 additions & 3 deletions library/core/src/num/bignum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ macro_rules! impl_full_ops {
fn full_mul_add(self, other: $ty, other2: $ty, carry: $ty) -> ($ty, $ty) {
// This cannot overflow;
// the output is between `0` and `2^nbits * (2^nbits - 1)`.
let v = (self as $bigty) * (other as $bigty) + (other2 as $bigty) +
(carry as $bigty);
((v >> <$ty>::BITS) as $ty, v as $ty)
let (lo, hi) = self.carrying_mul_add(other, other2, carry);
(hi, lo)
}

fn full_div_rem(self, other: $ty, borrow: $ty) -> ($ty, $ty) {
Expand Down
8 changes: 6 additions & 2 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@

use crate::cmp::Ordering;
use crate::intrinsics::const_eval_select;
use crate::marker::{FnPtr, PointeeSized};
use crate::marker::{Destruct, FnPtr, PointeeSized};
use crate::mem::{self, MaybeUninit, SizedTypeProperties};
use crate::num::NonZero;
use crate::{fmt, hash, intrinsics, ub_checks};
Expand Down Expand Up @@ -801,7 +801,11 @@ pub const unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
#[lang = "drop_in_place"]
#[allow(unconditional_recursion)]
#[rustc_diagnostic_item = "ptr_drop_in_place"]
pub unsafe fn drop_in_place<T: PointeeSized>(to_drop: *mut T) {
#[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")]
pub const unsafe fn drop_in_place<T: PointeeSized>(to_drop: *mut T)
where
T: [const] Destruct,
{
// Code here does not matter - this is replaced by the
// real drop glue by the compiler.

Expand Down
8 changes: 6 additions & 2 deletions library/core/src/ptr/mut_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use crate::cmp::Ordering::{Equal, Greater, Less};
use crate::intrinsics::const_eval_select;
use crate::marker::PointeeSized;
use crate::marker::{Destruct, PointeeSized};
use crate::mem::{self, SizedTypeProperties};
use crate::slice::{self, SliceIndex};

Expand Down Expand Up @@ -1390,8 +1390,12 @@ impl<T: PointeeSized> *mut T {
///
/// [`ptr::drop_in_place`]: crate::ptr::drop_in_place()
#[stable(feature = "pointer_methods", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")]
#[inline(always)]
pub unsafe fn drop_in_place(self) {
pub const unsafe fn drop_in_place(self)
where
T: [const] Destruct,
{
// SAFETY: the caller must uphold the safety contract for `drop_in_place`.
unsafe { drop_in_place(self) }
}
Expand Down
8 changes: 6 additions & 2 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::cmp::Ordering;
use crate::marker::{PointeeSized, Unsize};
use crate::marker::{Destruct, PointeeSized, Unsize};
use crate::mem::{MaybeUninit, SizedTypeProperties};
use crate::num::NonZero;
use crate::ops::{CoerceUnsized, DispatchFromDyn};
Expand Down Expand Up @@ -1118,7 +1118,11 @@ impl<T: PointeeSized> NonNull<T> {
/// [`ptr::drop_in_place`]: crate::ptr::drop_in_place()
#[inline(always)]
#[stable(feature = "non_null_convenience", since = "1.80.0")]
pub unsafe fn drop_in_place(self) {
#[rustc_const_unstable(feature = "const_drop_in_place", issue = "109342")]
pub const unsafe fn drop_in_place(self)
where
T: [const] Destruct,
{
// SAFETY: the caller must uphold the safety contract for `drop_in_place`.
unsafe { ptr::drop_in_place(self.as_ptr()) }
}
Expand Down
Loading
Loading