Skip to content

Commit 16cddb3

Browse files
committed
Auto merge of rust-lang#2988 - rust-lang:rustup-2023-07-22, r=oli-obk
Automatic sync from rustc
2 parents c0de313 + 32198e1 commit 16cddb3

File tree

253 files changed

+3881
-1906
lines changed

Some content is hidden

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

253 files changed

+3881
-1906
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3367,7 +3367,6 @@ dependencies = [
33673367
"rustc_type_ir",
33683368
"serde_json",
33693369
"smallvec",
3370-
"snap",
33713370
"tempfile",
33723371
"thorin-dwp",
33733372
"tracing",

compiler/rustc_abi/src/lib.rs

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ bitflags! {
4949
}
5050
}
5151

52+
/// Which niches (beyond the `null` niche) are available on references.
53+
#[derive(Default, Copy, Clone, Hash, Debug, Eq, PartialEq)]
54+
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_Generic))]
55+
pub struct ReferenceNichePolicy {
56+
pub size: bool,
57+
pub align: bool,
58+
}
59+
5260
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5361
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_Generic))]
5462
pub enum IntegerType {
@@ -346,6 +354,33 @@ impl TargetDataLayout {
346354
}
347355
}
348356

357+
#[inline]
358+
pub fn target_usize_max(&self) -> u64 {
359+
self.pointer_size.unsigned_int_max().try_into().unwrap()
360+
}
361+
362+
#[inline]
363+
pub fn target_isize_min(&self) -> i64 {
364+
self.pointer_size.signed_int_min().try_into().unwrap()
365+
}
366+
367+
#[inline]
368+
pub fn target_isize_max(&self) -> i64 {
369+
self.pointer_size.signed_int_max().try_into().unwrap()
370+
}
371+
372+
/// Returns the (inclusive) range of possible addresses for an allocation with
373+
/// the given size and alignment.
374+
///
375+
/// Note that this doesn't take into account target-specific limitations.
376+
#[inline]
377+
pub fn address_range_for(&self, size: Size, align: Align) -> (u64, u64) {
378+
let end = Size::from_bytes(self.target_usize_max());
379+
let min = align.bytes();
380+
let max = (end - size).align_down_to(align).bytes();
381+
(min, max)
382+
}
383+
349384
#[inline]
350385
pub fn vector_align(&self, vec_size: Size) -> AbiAndPrefAlign {
351386
for &(size, align) in &self.vector_align {
@@ -473,6 +508,12 @@ impl Size {
473508
Size::from_bytes((self.bytes() + mask) & !mask)
474509
}
475510

511+
#[inline]
512+
pub fn align_down_to(self, align: Align) -> Size {
513+
let mask = align.bytes() - 1;
514+
Size::from_bytes(self.bytes() & !mask)
515+
}
516+
476517
#[inline]
477518
pub fn is_aligned(self, align: Align) -> bool {
478519
let mask = align.bytes() - 1;
@@ -967,6 +1008,43 @@ impl WrappingRange {
9671008
}
9681009
}
9691010

1011+
/// Returns `true` if `range` is contained in `self`.
1012+
#[inline(always)]
1013+
pub fn contains_range<I: Into<u128> + Ord>(&self, range: RangeInclusive<I>) -> bool {
1014+
if range.is_empty() {
1015+
return true;
1016+
}
1017+
1018+
let (vmin, vmax) = range.into_inner();
1019+
let (vmin, vmax) = (vmin.into(), vmax.into());
1020+
1021+
if self.start <= self.end {
1022+
self.start <= vmin && vmax <= self.end
1023+
} else {
1024+
// The last check is needed to cover the following case:
1025+
// `vmin ... start, end ... vmax`. In this special case there is no gap
1026+
// between `start` and `end` so we must return true.
1027+
self.start <= vmin || vmax <= self.end || self.start == self.end + 1
1028+
}
1029+
}
1030+
1031+
/// Returns `true` if `range` has an overlap with `self`.
1032+
#[inline(always)]
1033+
pub fn overlaps_range<I: Into<u128> + Ord>(&self, range: RangeInclusive<I>) -> bool {
1034+
if range.is_empty() {
1035+
return false;
1036+
}
1037+
1038+
let (vmin, vmax) = range.into_inner();
1039+
let (vmin, vmax) = (vmin.into(), vmax.into());
1040+
1041+
if self.start <= self.end {
1042+
self.start <= vmax && vmin <= self.end
1043+
} else {
1044+
self.start <= vmax || vmin <= self.end
1045+
}
1046+
}
1047+
9701048
/// Returns `self` with replaced `start`
9711049
#[inline(always)]
9721050
pub fn with_start(mut self, start: u128) -> Self {
@@ -984,9 +1062,15 @@ impl WrappingRange {
9841062
/// Returns `true` if `size` completely fills the range.
9851063
#[inline]
9861064
pub fn is_full_for(&self, size: Size) -> bool {
1065+
debug_assert!(self.is_in_range_for(size));
1066+
self.start == (self.end.wrapping_add(1) & size.unsigned_int_max())
1067+
}
1068+
1069+
/// Returns `true` if the range is valid for `size`.
1070+
#[inline(always)]
1071+
pub fn is_in_range_for(&self, size: Size) -> bool {
9871072
let max_value = size.unsigned_int_max();
988-
debug_assert!(self.start <= max_value && self.end <= max_value);
989-
self.start == (self.end.wrapping_add(1) & max_value)
1073+
self.start <= max_value && self.end <= max_value
9901074
}
9911075
}
9921076

@@ -1427,16 +1511,21 @@ impl Niche {
14271511

14281512
pub fn reserve<C: HasDataLayout>(&self, cx: &C, count: u128) -> Option<(u128, Scalar)> {
14291513
assert!(count > 0);
1514+
if count > self.available(cx) {
1515+
return None;
1516+
}
14301517

14311518
let Self { value, valid_range: v, .. } = *self;
1432-
let size = value.size(cx);
1433-
assert!(size.bits() <= 128);
1434-
let max_value = size.unsigned_int_max();
1519+
let max_value = value.size(cx).unsigned_int_max();
1520+
let distance_end_zero = max_value - v.end;
14351521

1436-
let niche = v.end.wrapping_add(1)..v.start;
1437-
let available = niche.end.wrapping_sub(niche.start) & max_value;
1438-
if count > available {
1439-
return None;
1522+
// Null-pointer optimization. This is guaranteed by Rust (at least for `Option<_>`),
1523+
// and offers better codegen opportunities.
1524+
if count == 1 && matches!(value, Pointer(_)) && !v.contains(0) {
1525+
// Select which bound to move to minimize the number of lost niches.
1526+
let valid_range =
1527+
if v.start - 1 > distance_end_zero { v.with_end(0) } else { v.with_start(0) };
1528+
return Some((0, Scalar::Initialized { value, valid_range }));
14401529
}
14411530

14421531
// Extend the range of valid values being reserved by moving either `v.start` or `v.end` bound.
@@ -1459,7 +1548,6 @@ impl Niche {
14591548
let end = v.end.wrapping_add(count) & max_value;
14601549
Some((start, Scalar::Initialized { value, valid_range: v.with_end(end) }))
14611550
};
1462-
let distance_end_zero = max_value - v.end;
14631551
if v.start > v.end {
14641552
// zero is unavailable because wrapping occurs
14651553
move_end(v)

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -551,17 +551,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
551551
for &(ref use_tree, id) in trees {
552552
let new_hir_id = self.local_def_id(id);
553553

554-
let mut prefix = prefix.clone();
555-
556-
// Give the segments new node-ids since they are being cloned.
557-
for seg in &mut prefix.segments {
558-
// Give the cloned segment the same resolution information
559-
// as the old one (this is needed for stability checking).
560-
let new_id = self.next_node_id();
561-
self.resolver.clone_res(seg.id, new_id);
562-
seg.id = new_id;
563-
}
564-
565554
// Each `use` import is an item and thus are owners of the
566555
// names in the path. Up to this point the nested import is
567556
// the current owner, since we want each desugared import to
@@ -570,6 +559,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
570559
self.with_hir_id_owner(id, |this| {
571560
let mut ident = *ident;
572561

562+
// `prefix` is lowered multiple times, but in different HIR owners.
563+
// So each segment gets renewed `HirId` with the same
564+
// `ItemLocalId` and the new owner. (See `lower_node_id`)
573565
let kind =
574566
this.lower_use_tree(use_tree, &prefix, id, vis_span, &mut ident, attrs);
575567
if let Some(attrs) = attrs {

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ trait ResolverAstLoweringExt {
148148
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>>;
149149
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes>;
150150
fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res<NodeId>>>;
151-
// Clones the resolution (if any) on 'source' and applies it
152-
// to 'target'. Used when desugaring a `UseTreeKind::Nested` to
153-
// multiple `UseTreeKind::Simple`s
154-
fn clone_res(&mut self, source: NodeId, target: NodeId);
155151
fn get_label_res(&self, id: NodeId) -> Option<NodeId>;
156152
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes>;
157153
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)>;
@@ -184,12 +180,6 @@ impl ResolverAstLoweringExt for ResolverAstLowering {
184180
None
185181
}
186182

187-
fn clone_res(&mut self, source: NodeId, target: NodeId) {
188-
if let Some(res) = self.partial_res_map.get(&source) {
189-
self.partial_res_map.insert(target, *res);
190-
}
191-
}
192-
193183
/// Obtains resolution for a `NodeId` with a single resolution.
194184
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
195185
self.partial_res_map.get(&id).copied()

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ impl WriteBackendMethods for GccCodegenBackend {
239239
unimplemented!();
240240
}
241241

242+
fn print_statistics(&self) {
243+
unimplemented!()
244+
}
245+
242246
unsafe fn optimize(_cgcx: &CodegenContext<Self>, _diag_handler: &Handler, module: &ModuleCodegen<Self::Module>, config: &ModuleConfig) -> Result<(), FatalError> {
243247
module.module_llvm.context.set_optimization_level(to_gcc_opt_level(config.opt_level));
244248
Ok(())

compiler/rustc_codegen_gcc/src/type_of.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
339339
return pointee;
340340
}
341341

342-
let result = Ty::ty_and_layout_pointee_info_at(*self, cx, offset);
342+
let assume_valid_ptr = true;
343+
let result = Ty::ty_and_layout_pointee_info_at(*self, cx, offset, assume_valid_ptr);
343344

344345
cx.pointee_infos.borrow_mut().insert((self.ty, offset), result);
345346
result

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use rustc_target::abi::{
3333
use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
3434
use smallvec::SmallVec;
3535

36+
use libc::c_uint;
3637
use std::cell::{Cell, RefCell};
3738
use std::ffi::CStr;
3839
use std::str;
@@ -349,6 +350,23 @@ pub unsafe fn create_module<'ll>(
349350
);
350351
}
351352

353+
// Insert `llvm.ident` metadata.
354+
//
355+
// On the wasm targets it will get hooked up to the "producer" sections
356+
// `processed-by` information.
357+
let rustc_producer =
358+
format!("rustc version {}", option_env!("CFG_VERSION").expect("CFG_VERSION"));
359+
let name_metadata = llvm::LLVMMDStringInContext(
360+
llcx,
361+
rustc_producer.as_ptr().cast(),
362+
rustc_producer.as_bytes().len() as c_uint,
363+
);
364+
llvm::LLVMAddNamedMetadataOperand(
365+
llmod,
366+
cstr!("llvm.ident").as_ptr(),
367+
llvm::LLVMMDNodeInContext(llcx, &name_metadata, 1),
368+
);
369+
352370
llmod
353371
}
354372

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -888,21 +888,6 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
888888
llvm::LLVMAddNamedMetadataOperand(debug_context.llmod, llvm_gcov_ident.as_ptr(), val);
889889
}
890890

891-
// Insert `llvm.ident` metadata on the wasm targets since that will
892-
// get hooked up to the "producer" sections `processed-by` information.
893-
if tcx.sess.target.is_like_wasm {
894-
let name_metadata = llvm::LLVMMDStringInContext(
895-
debug_context.llcontext,
896-
rustc_producer.as_ptr().cast(),
897-
rustc_producer.as_bytes().len() as c_uint,
898-
);
899-
llvm::LLVMAddNamedMetadataOperand(
900-
debug_context.llmod,
901-
cstr!("llvm.ident").as_ptr(),
902-
llvm::LLVMMDNodeInContext(debug_context.llcontext, &name_metadata, 1),
903-
);
904-
}
905-
906891
return unit_metadata;
907892
};
908893

0 commit comments

Comments
 (0)