Skip to content

Commit 685d733

Browse files
committed
Auto merge of #158837 - jhpratt:rollup-KBtLguc, r=<try>
Rollup of 20 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1 try-job: i686-msvc-2
2 parents 3659db0 + f423b10 commit 685d733

188 files changed

Lines changed: 1353 additions & 579 deletions

File tree

Some content is hidden

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

compiler/rustc_ast/src/ast.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ impl GenericBound {
407407
}
408408
}
409409

410-
pub type GenericBounds = Vec<GenericBound>;
410+
pub type GenericBounds = ThinVec<GenericBound>;
411411

412412
/// Specifies the enforced ordering for generic parameters. In the future,
413413
/// if we wanted to relax this order, we could override `PartialEq` and
@@ -1534,7 +1534,7 @@ impl Expr {
15341534
let (Some(lhs), Some(rhs)) = (lhs.to_bound(), rhs.to_bound()) else {
15351535
return None;
15361536
};
1537-
TyKind::TraitObject(vec![lhs, rhs], TraitObjectSyntax::None)
1537+
TyKind::TraitObject(thin_vec![lhs, rhs], TraitObjectSyntax::None)
15381538
}
15391539

15401540
ExprKind::Underscore => TyKind::Infer,
@@ -1868,7 +1868,7 @@ pub enum ExprKind {
18681868
///
18691869
/// Usually not written directly in user code but
18701870
/// indirectly via the macro `core::mem::offset_of!(...)`.
1871-
OffsetOf(Box<Ty>, Vec<Ident>),
1871+
OffsetOf(Box<Ty>, ThinVec<Ident>),
18721872

18731873
/// A macro invocation; pre-expansion.
18741874
MacCall(Box<MacCall>),
@@ -4391,27 +4391,37 @@ mod size_asserts {
43914391
// tidy-alphabetical-start
43924392
static_assert_size!(AssocItem, 80);
43934393
static_assert_size!(AssocItemKind, 16);
4394+
static_assert_size!(AttrKind, 16);
43944395
static_assert_size!(Attribute, 32);
43954396
static_assert_size!(Block, 32);
43964397
static_assert_size!(Expr, 72);
43974398
static_assert_size!(ExprKind, 40);
43984399
static_assert_size!(Fn, 192);
4400+
static_assert_size!(FnDecl, 24);
4401+
static_assert_size!(FnHeader, 76);
4402+
static_assert_size!(FnSig, 96);
43994403
static_assert_size!(ForeignItem, 80);
44004404
static_assert_size!(ForeignItemKind, 16);
44014405
static_assert_size!(GenericArg, 24);
4406+
static_assert_size!(GenericArgs, 40);
44024407
static_assert_size!(GenericBound, 88);
4408+
static_assert_size!(GenericParam, 80);
44034409
static_assert_size!(Generics, 40);
44044410
static_assert_size!(Impl, 80);
44054411
static_assert_size!(Item, 152);
44064412
static_assert_size!(ItemKind, 88);
4413+
static_assert_size!(Lifetime, 16);
44074414
static_assert_size!(LitKind, 24);
44084415
static_assert_size!(Local, 96);
4416+
static_assert_size!(MetaItem, 88);
4417+
static_assert_size!(MetaItemKind, 40);
44094418
static_assert_size!(MetaItemLit, 40);
44104419
static_assert_size!(Param, 40);
44114420
static_assert_size!(Pat, 80);
44124421
static_assert_size!(PatKind, 56);
44134422
static_assert_size!(Path, 24);
44144423
static_assert_size!(PathSegment, 24);
4424+
static_assert_size!(QSelf, 24);
44154425
static_assert_size!(Stmt, 32);
44164426
static_assert_size!(StmtKind, 16);
44174427
static_assert_size!(TraitImplHeader, 72);

compiler/rustc_ast/src/visit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,8 @@ macro_rules! common_visitor_and_walkers {
386386
impl_visitable_list!(<$($lt)? $($mut)?>
387387
ThinVec<AngleBracketedArg>,
388388
ThinVec<Attribute>,
389+
ThinVec<GenericBound>,
390+
ThinVec<Ident>,
389391
ThinVec<(Ident, Option<Ident>)>,
390392
ThinVec<(NodeId, Path)>,
391393
ThinVec<PathSegment>,

compiler/rustc_attr_parsing/src/attributes/doc.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,11 @@ impl DocParser {
348348
// If it's a list, then only `any()` and `none()` are allowed and they must not
349349
// contain any item.
350350
MetaItemOrLitParser::MetaItemParser(sub_item) => {
351-
if let Some(ident) = sub_item.ident()
352-
&& [sym::any, sym::none].contains(&ident.name)
351+
let Some(ident) = sub_item.ident() else {
352+
cx.adcx().expected_identifier(sub_item.path().span());
353+
continue;
354+
};
355+
if [sym::any, sym::none].contains(&ident.name)
353356
&& let ArgParser::List(list) = sub_item.args()
354357
&& list.mixed().count() == 0
355358
{
@@ -371,9 +374,7 @@ impl DocParser {
371374
} else {
372375
cx.emit_lint(
373376
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
374-
DocAutoCfgHideShowUnexpectedItem {
375-
attr_name: sub_item.ident().unwrap().name,
376-
},
377+
DocAutoCfgHideShowUnexpectedItem { attr_name: ident.name },
377378
sub_item.span(),
378379
);
379380
}

compiler/rustc_builtin_macros/src/deriving/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) ->
167167
let ty_dyn_debug = cx.ty(
168168
span,
169169
ast::TyKind::TraitObject(
170-
vec![cx.trait_bound(path_debug, false)],
170+
thin_vec![cx.trait_bound(path_debug, false)],
171171
ast::TraitObjectSyntax::Dyn,
172172
),
173173
);

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ impl<'a> TraitDef<'a> {
617617
ident,
618618
generics: Generics::default(),
619619
after_where_clause: ast::WhereClause::default(),
620-
bounds: Vec::new(),
620+
bounds: ThinVec::new(),
621621
ty: Some(type_def.to_ty(cx, self.span, type_ident, generics)),
622622
})),
623623
tokens: None,
@@ -639,7 +639,7 @@ impl<'a> TraitDef<'a> {
639639
// Extra restrictions on the generics parameters to the
640640
// type being derived upon.
641641
let span = param.ident.span.with_ctxt(ctxt);
642-
let bounds: Vec<_> = self
642+
let bounds: ThinVec<_> = self
643643
.additional_bounds
644644
.iter()
645645
.map(|p| {
@@ -723,7 +723,7 @@ impl<'a> TraitDef<'a> {
723723
{
724724
continue;
725725
}
726-
let mut bounds: Vec<_> = self
726+
let mut bounds: ThinVec<_> = self
727727
.additional_bounds
728728
.iter()
729729
.map(|p| {

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_fs_util::{link_or_copy, path_to_c_string};
2222
use rustc_middle::ty::TyCtxt;
2323
use rustc_session::Session;
2424
use rustc_session::config::{self, Lto, OutputType, Passes, SplitDwarfKind, SwitchWithOptPath};
25-
use rustc_span::{BytePos, InnerSpan, Pos, RemapPathScopeComponents, SpanData, SyntaxContext, sym};
25+
use rustc_span::{BytePos, InnerSpan, Pos, RemapPathScopeComponents, SpanData, SyntaxContext};
2626
use rustc_target::spec::{CodeModel, FloatAbi, RelocModel, SanitizerSet, SplitDebuginfo, TlsModel};
2727
use tracing::{debug, trace};
2828

@@ -209,14 +209,8 @@ pub(crate) fn target_machine_factory(
209209

210210
let code_model = to_llvm_code_model(sess.code_model());
211211

212-
let mut singlethread = sess.target.singlethread;
213-
214-
// On the wasm target once the `atomics` feature is enabled that means that
215-
// we're no longer single-threaded, or otherwise we don't want LLVM to
216-
// lower atomic operations to single-threaded operations.
217-
if singlethread && sess.target.is_like_wasm && sess.target_features.contains(&sym::atomics) {
218-
singlethread = false;
219-
}
212+
// This is used to set cfg_has_threads, so all logic must be in this method.
213+
let singlethread = sess.target.singlethread(&sess.target_features);
220214

221215
let triple = SmallCStr::new(&versioned_llvm_target(sess));
222216
let cpu = SmallCStr::new(llvm_util::target_cpu(sess));

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_target::spec::{CfgAbi, LlvmAbi, Os, RelocModel, Target, ef_avr_arch};
2424
use tracing::debug;
2525

2626
use super::apple;
27+
use crate::errors;
2728

2829
/// The default metadata loader. This is used by cg_llvm and cg_clif.
2930
///
@@ -370,7 +371,7 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
370371
if let Some(ref cpu) = sess.opts.cg.target_cpu {
371372
ef_avr_arch(cpu)
372373
} else {
373-
bug!("AVR CPU not explicitly specified")
374+
sess.dcx().emit_fatal(errors::CpuRequired)
374375
}
375376
}
376377
Architecture::Csky => {

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6363
result_place: Option<PlaceValue<Bx::Value>>,
6464
source_info: SourceInfo,
6565
) -> IntrinsicResult<'tcx, Bx::Value> {
66+
// When `-Zforce-intrinsic-fallback` is enabled, always use the fallback body if it exists,
67+
if bx.tcx().sess.opts.unstable_opts.force_intrinsic_fallback
68+
&& let Some(def) = bx.tcx().intrinsic(instance.def_id())
69+
&& !def.must_be_overridden
70+
{
71+
return IntrinsicResult::Fallback(ty::Instance::new_raw(
72+
instance.def_id(),
73+
instance.args,
74+
));
75+
}
76+
6677
let span = source_info.span;
6778

6879
let name = bx.tcx().item_name(instance.def_id());

compiler/rustc_data_structures/src/intern.rs

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::cmp::Ordering;
21
use std::fmt::{self, Debug};
32
use std::hash::{Hash, Hasher};
43
use std::ops::Deref;
@@ -11,26 +10,40 @@ mod private {
1110
pub struct PrivateZst;
1211
}
1312

14-
/// A reference to a value that is interned, and is known to be unique.
13+
/// This type is a reference with one special behaviour: the reference pointer (i.e. the address of
14+
/// the value referred to) is used for equality and hashing, rather than the value's contents, as
15+
/// would occur with a vanilla reference. There are two cases when this is useful.
1516
///
16-
/// Note that it is possible to have a `T` and a `Interned<T>` that are (or
17-
/// refer to) equal but different values. But if you have two different
18-
/// `Interned<T>`s, they both refer to the same value, at a single location in
19-
/// memory. This means that equality and hashing can be done on the value's
20-
/// address rather than the value's contents, which can improve performance.
17+
/// - Types where uniqueness is guaranteed. This is most commonly achieved via interning -- hence
18+
/// the name `Interned` -- though it may also be possible via other means. In this case, the use
19+
/// of `Interned` is primarily a performance optimization, because pointer equality/hashing gives
20+
/// the same results as value equality/hashing, but is faster. (The use of the `Interned` type
21+
/// also provides documentation about the interned-ness.)
2122
///
22-
/// The `PrivateZst` field means you can pattern match with `Interned(v, _)`
23-
/// but you can only construct a `Interned` with `new_unchecked`, and not
24-
/// directly.
23+
/// Note that in this case it is possible to have a `T` and a `Interned<T>` that are (or refer
24+
/// to) equal but different values. But if you have two different `Interned<T>`s, they both refer
25+
/// to the same value, at a single location in memory.
26+
///
27+
/// - Types with identity, where distinct values should always be considered unequal, even if they
28+
/// have equal values. These are rare in Rust, but do occur sometimes. In this case, the use of
29+
/// `Interned` gives different behaviour, because pointer equality/hashing gives different result
30+
/// to value equality/hashing, and is also faster.
31+
///
32+
/// The `PrivateZst` field means you can pattern match with `Interned(v, _)` but you can only
33+
/// construct a `Interned` with `new_unchecked`, and not directly. This means that all creation
34+
/// points can be audited easily.
2535
#[rustc_pass_by_value]
2636
pub struct Interned<'a, T>(pub &'a T, pub private::PrivateZst);
2737

2838
impl<'a, T> Interned<'a, T> {
29-
/// Create a new `Interned` value. The value referred to *must* be interned
30-
/// and thus be unique, and it *must* remain unique in the future. This
31-
/// function has `_unchecked` in the name but is not `unsafe`, because if
32-
/// the uniqueness condition is violated condition it will cause incorrect
33-
/// behaviour but will not affect memory safety.
39+
/// Create a new `Interned` value. The value referred to *must* satisfy one of the following
40+
/// two conditions.
41+
/// - It must be unique and it must remain unique in the future.
42+
/// - It must be of a type with "identity" such that distinct values should always be
43+
/// considered unequal.
44+
///
45+
/// This function has `_unchecked` in the name but is not `unsafe`, because if neither of these
46+
/// conditions is met it will cause incorrect behaviour but will not affect memory safety.
3447
#[inline]
3548
pub const fn new_unchecked(t: &'a T) -> Self {
3649
Interned(t, private::PrivateZst)
@@ -64,41 +77,10 @@ impl<'a, T> PartialEq for Interned<'a, T> {
6477

6578
impl<'a, T> Eq for Interned<'a, T> {}
6679

67-
impl<'a, T: PartialOrd> PartialOrd for Interned<'a, T> {
68-
fn partial_cmp(&self, other: &Interned<'a, T>) -> Option<Ordering> {
69-
// Pointer equality implies equality, due to the uniqueness constraint,
70-
// but the contents must be compared otherwise.
71-
if ptr::eq(self.0, other.0) {
72-
Some(Ordering::Equal)
73-
} else {
74-
let res = self.0.partial_cmp(other.0);
75-
debug_assert_ne!(res, Some(Ordering::Equal));
76-
res
77-
}
78-
}
79-
}
80-
81-
impl<'a, T: Ord> Ord for Interned<'a, T> {
82-
fn cmp(&self, other: &Interned<'a, T>) -> Ordering {
83-
// Pointer equality implies equality, due to the uniqueness constraint,
84-
// but the contents must be compared otherwise.
85-
if ptr::eq(self.0, other.0) {
86-
Ordering::Equal
87-
} else {
88-
let res = self.0.cmp(other.0);
89-
debug_assert_ne!(res, Ordering::Equal);
90-
res
91-
}
92-
}
93-
}
94-
95-
impl<'a, T> Hash for Interned<'a, T>
96-
where
97-
T: Hash,
98-
{
80+
impl<'a, T> Hash for Interned<'a, T> {
9981
#[inline]
10082
fn hash<H: Hasher>(&self, s: &mut H) {
101-
// Pointer hashing is sufficient, due to the uniqueness constraint.
83+
// Pointer hashing is sufficient.
10284
ptr::hash(self.0, s)
10385
}
10486
}
Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::*;
22

3+
#[allow(unused)]
34
#[derive(Debug)]
45
struct S(u32);
56

@@ -11,22 +12,6 @@ impl PartialEq for S {
1112

1213
impl Eq for S {}
1314

14-
impl PartialOrd for S {
15-
fn partial_cmp(&self, other: &S) -> Option<Ordering> {
16-
// The `==` case should be handled by `Interned`.
17-
assert_ne!(self.0, other.0);
18-
self.0.partial_cmp(&other.0)
19-
}
20-
}
21-
22-
impl Ord for S {
23-
fn cmp(&self, other: &S) -> Ordering {
24-
// The `==` case should be handled by `Interned`.
25-
assert_ne!(self.0, other.0);
26-
self.0.cmp(&other.0)
27-
}
28-
}
29-
3015
#[test]
3116
fn test_uniq() {
3217
let s1 = S(1);
@@ -45,14 +30,4 @@ fn test_uniq() {
4530
assert_eq!(v1, v1);
4631
assert_eq!(v3a, v3b);
4732
assert_ne!(v1, v4); // same content but different addresses: not equal
48-
49-
assert_eq!(v1.cmp(&v2), Ordering::Less);
50-
assert_eq!(v3a.cmp(&v2), Ordering::Greater);
51-
assert_eq!(v1.cmp(&v1), Ordering::Equal); // only uses Interned::eq, not S::cmp
52-
assert_eq!(v3a.cmp(&v3b), Ordering::Equal); // only uses Interned::eq, not S::cmp
53-
54-
assert_eq!(v1.partial_cmp(&v2), Some(Ordering::Less));
55-
assert_eq!(v3a.partial_cmp(&v2), Some(Ordering::Greater));
56-
assert_eq!(v1.partial_cmp(&v1), Some(Ordering::Equal)); // only uses Interned::eq, not S::cmp
57-
assert_eq!(v3a.partial_cmp(&v3b), Some(Ordering::Equal)); // only uses Interned::eq, not S::cmp
5833
}

0 commit comments

Comments
 (0)