Skip to content

Commit ac7bce9

Browse files
committed
Auto merge of #166114 - JonathanBrouwer:rollup-50FRx7M, r=JonathanBrouwer
Rollup of 24 pull requests Successful merges: - #164370 (Compact the previous dependency-node reverse index) - #164544 (Add an optional `llvm = ` argument to rustc_intrinsic.) - #165007 (std: Combine `is_mips64_feature_detected` into `is_mips_feature_detected` and enable on MIPS release 6) - #165090 (Check type alignment is <= type size in data layout parser) - #165524 (Cleanup, Get emitting metadata out of codegen) - #165875 (Combine the spans of generic arguments without dropping `->`) - #166074 (rustc: avoid path dependent queries in source presence checks) - #160291 (Add new target: `i686-unknown-none`) - #161708 (hir_typeck: Propagate async closure output into its body) - #162575 (keep the `use<..>` bound in the `refining_impl_trait` suggestion) - #163516 (Update std_detect support for AArch64 Darwin) - #163808 (Add `wasm64-unknown-emscripten` tier 3 target) - #163828 (Change all arm-none targets to skip frame pointers in leaf functions.) - #163966 (Keep deref suggestions from inserting a second pair of brackets) - #164483 (compiler: Add `{x86_64,aarch64}-unknown-serenity` targets) - #164690 (lint: keep type-changing casts in `raw_borrows_via_references`) - #164910 (Add regression tests for #164253) - #164975 (Add wide pointer visualizer for LLDB) - #165652 (Add regression test for GCA associated const with a pattern type field) - #165893 (Prune un/under used methods of `ast::Attribute`) - #166057 ([PAC] Disable rust-tail-cc for pauthtest) - #166071 (illumos dist should enable ThinLTO and codegen-units=1) - #166093 (Move doc attribute and doc comment target checking to attribute parsing) - #166098 (Actually test ABI for C ZSTs and fix Rust ZST ABI for SPARC) Failed merges: - #165267 ([Debuginfo] Emit artificial nested typedef representing generic params on MSVC)
2 parents 6f379f9 + 7996926 commit ac7bce9

210 files changed

Lines changed: 4450 additions & 1216 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.

‎Cargo.lock‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,6 +3924,7 @@ dependencies = [
39243924
name = "rustc_crate_store"
39253925
version = "0.0.0"
39263926
dependencies = [
3927+
"bitflags",
39273928
"rustc_abi",
39283929
"rustc_attr_ir",
39293930
"rustc_data_structures",
@@ -4868,6 +4869,7 @@ dependencies = [
48684869
"rustc_data_structures",
48694870
"rustc_hashes",
48704871
"rustc_index",
4872+
"rustc_lexer",
48714873
"rustc_macros",
48724874
"rustc_serialize",
48734875
"scoped-tls",

‎compiler/rustc_abi/src/callconv/reg.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ impl Reg {
7676
let dl = cx.data_layout();
7777
match self.kind {
7878
RegKind::Integer => match self.size.bits() {
79-
1 => dl.i1_align,
80-
2..=8 => dl.i8_align,
79+
1..=8 => Align::ONE,
8180
9..=16 => dl.i16_align,
8281
17..=32 => dl.i32_align,
8382
33..=64 => dl.i64_align,

‎compiler/rustc_abi/src/layout.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
365365
Some(present_first) => present_first,
366366
// Uninhabited because it has no variants, or only absent ones.
367367
None if is_enum => {
368-
return Ok(LayoutData::never_type(&self.cx));
368+
return Ok(LayoutData::never_type());
369369
}
370370
// If it's a struct, still compute a layout so that we can still compute the
371371
// field offsets.
@@ -412,7 +412,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
412412
F: Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + fmt::Debug + Copy,
413413
{
414414
let dl = self.cx.data_layout();
415-
let mut align = if repr.pack.is_some() { dl.i8_align } else { dl.aggregate_align };
415+
let mut align = if repr.pack.is_some() { Align::ONE } else { dl.aggregate_align };
416416
let mut max_repr_align = repr.align;
417417

418418
// If all the non-ZST fields have the same repr and union repr optimizations aren't
@@ -601,7 +601,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
601601
{
602602
let dl = self.cx.data_layout();
603603
let pack = repr.pack;
604-
let mut align = if pack.is_some() { dl.i8_align } else { dl.aggregate_align };
604+
let mut align = if pack.is_some() { Align::ONE } else { dl.aggregate_align };
605605
let mut max_repr_align = repr.align;
606606
let mut in_memory_order: IndexVec<u32, FieldIdx> = fields.indices().collect();
607607
let optimize_field_order = !repr.inhibit_struct_field_reordering();

‎compiler/rustc_abi/src/layout/simple.rs‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use rustc_hashes::Hash64;
44
use rustc_index::{Idx, IndexVec};
55

66
use crate::{
7-
BackendRepr, FieldsShape, HasDataLayout, LayoutData, Niche, Primitive, Scalar, Size, Variants,
7+
Align, BackendRepr, FieldsShape, HasDataLayout, LayoutData, Niche, Primitive, Scalar, Size,
8+
Variants,
89
};
910

1011
/// "Simple" layout constructors that cannot fail.
1112
impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
12-
pub fn unit<C: HasDataLayout>(cx: &C, sized: bool) -> Self {
13-
let dl = cx.data_layout();
13+
pub fn unit(sized: bool) -> Self {
1414
LayoutData {
1515
variants: Variants::Single { index: VariantIdx::new(0) },
1616
fields: FieldsShape::Arbitrary {
@@ -20,28 +20,27 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
2020
backend_repr: BackendRepr::Memory { sized },
2121
largest_niche: None,
2222
uninhabited: false,
23-
align: dl.i8_align,
23+
align: Align::ONE,
2424
size: Size::ZERO,
2525
max_repr_align: None,
26-
unadjusted_abi_align: dl.i8_align,
26+
unadjusted_abi_align: Align::ONE,
2727
repr_c: false,
2828
randomization_seed: Hash64::new(0),
2929
}
3030
}
3131

32-
pub fn never_type<C: HasDataLayout>(cx: &C) -> Self {
33-
let dl = cx.data_layout();
32+
pub fn never_type() -> Self {
3433
// This is also used for uninhabited enums, so we use `Variants::Empty`.
3534
LayoutData {
3635
variants: Variants::Empty,
3736
fields: FieldsShape::Primitive,
3837
backend_repr: BackendRepr::Memory { sized: true },
3938
largest_niche: None,
4039
uninhabited: true,
41-
align: dl.i8_align,
40+
align: Align::ONE,
4241
size: Size::ZERO,
4342
max_repr_align: None,
44-
unadjusted_abi_align: dl.i8_align,
43+
unadjusted_abi_align: Align::ONE,
4544
repr_c: false,
4645
randomization_seed: Hash64::ZERO,
4746
}
@@ -128,8 +127,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
128127
///
129128
/// Uninhabited variants get pruned as part of the layout calculation,
130129
/// so this can be used after the fact to reconstitute a layout.
131-
pub fn uninhabited_variant<C: HasDataLayout>(cx: &C, index: VariantIdx, fields: usize) -> Self {
132-
let dl = cx.data_layout();
130+
pub fn uninhabited_variant(index: VariantIdx, fields: usize) -> Self {
133131
LayoutData {
134132
variants: Variants::Single { index },
135133
fields: match NonZero::new(fields) {
@@ -142,10 +140,10 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
142140
backend_repr: BackendRepr::Memory { sized: true },
143141
largest_niche: None,
144142
uninhabited: true,
145-
align: dl.i8_align,
143+
align: Align::ONE,
146144
size: Size::ZERO,
147145
max_repr_align: None,
148-
unadjusted_abi_align: dl.i8_align,
146+
unadjusted_abi_align: Align::ONE,
149147
repr_c: false,
150148
// Variant layouts never flow back into actual layout computations,
151149
// so dummy values are fine here.

‎compiler/rustc_abi/src/lib.rs‎

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,6 @@ pub struct PointerSpec {
318318
#[derive(Debug, PartialEq, Eq)]
319319
pub struct TargetDataLayout {
320320
pub endian: Endian,
321-
pub i1_align: Align,
322-
pub i8_align: Align,
323321
pub i16_align: Align,
324322
pub i32_align: Align,
325323
pub i64_align: Align,
@@ -359,8 +357,6 @@ impl Default for TargetDataLayout {
359357
let align = |bits| Align::from_bits(bits).unwrap();
360358
TargetDataLayout {
361359
endian: Endian::Big,
362-
i1_align: align(8),
363-
i8_align: align(8),
364360
i16_align: align(16),
365361
i32_align: align(32),
366362
i64_align: align(32),
@@ -394,6 +390,7 @@ pub enum TargetDataLayoutError<'a> {
394390
InvalidBits { kind: &'a str, bit: &'a str, cause: &'a str, err: ParseIntError },
395391
MissingAlignment { cause: &'a str },
396392
InvalidAlignment { cause: &'a str, err: AlignFromBytesError },
393+
AlignmentTooLargeForType { cause: &'a str, align: Align },
397394
InconsistentTargetArchitecture { dl: &'a str, target: &'a str },
398395
InconsistentTargetPointerWidth { pointer_size: u64, target: u16 },
399396
InvalidBitsSize { err: String },
@@ -426,6 +423,9 @@ impl Diagnostic<'_> for TargetDataLayoutError<'_> {
426423
.with_arg("cause", cause)
427424
.with_arg("err", err.to_string())
428425
}
426+
TargetDataLayoutError::AlignmentTooLargeForType { cause, align } => {
427+
Diag::new(dcx, level, msg!("alignment of `{$align}` bytes in \"data-layout\" is too large for `{$cause}`")).with_arg("align", align.bytes()).with_arg("cause", cause)
428+
}
429429
TargetDataLayoutError::InconsistentTargetArchitecture { dl, target } => {
430430
Diag::new(dcx, level, msg!("inconsistent target specification: \"data-layout\" claims architecture is {$dl}-endian, while \"target-endian\" is `{$target}`"))
431431
.with_arg("dl", dl).with_arg("target", target)
@@ -477,22 +477,28 @@ impl TargetDataLayout {
477477
|s: &'a str, cause: &'a str| parse_bits(s, "size", cause).map(Size::from_bits);
478478

479479
// Parse an alignment string.
480-
let parse_align_str = |s: &'a str, cause: &'a str| {
480+
let parse_align_str = |s: &'a str, cause: &'a str, size_bits: u64| {
481481
let align_from_bits = |bits| {
482482
Align::from_bits(bits)
483483
.map_err(|err| TargetDataLayoutError::InvalidAlignment { cause, err })
484484
};
485-
let abi = parse_bits(s, "alignment", cause)?;
486-
Ok(align_from_bits(abi)?)
485+
let align_bits = parse_bits(s, "alignment", cause)?;
486+
let align = align_from_bits(align_bits)?;
487+
let max_align_bytes = size_bits.div_ceil(8).next_power_of_two();
488+
if align.bytes() > max_align_bytes {
489+
Err(TargetDataLayoutError::AlignmentTooLargeForType { cause, align })
490+
} else {
491+
Ok(align)
492+
}
487493
};
488494

489495
// Parse an alignment sequence, possibly in the form `<align>[:<preferred_alignment>]`,
490496
// ignoring the secondary alignment specifications.
491-
let parse_align_seq = |s: &[&'a str], cause: &'a str| {
497+
let parse_align_seq = |s: &[&'a str], cause: &'a str, size_bits: u64| {
492498
if s.is_empty() {
493499
return Err(TargetDataLayoutError::MissingAlignment { cause });
494500
}
495-
parse_align_str(s[0], cause)
501+
parse_align_str(s[0], cause, size_bits)
496502
};
497503

498504
let mut dl = TargetDataLayout::default();
@@ -508,12 +514,12 @@ impl TargetDataLayout {
508514
[p] if p.starts_with('P') => {
509515
dl.instruction_address_space = parse_address_space(&p[1..], "P")?
510516
}
511-
["a", a @ ..] => dl.aggregate_align = parse_align_seq(a, "a")?,
512-
["f16", a @ ..] => dl.f16_align = parse_align_seq(a, "f16")?,
513-
["f32", a @ ..] => dl.f32_align = parse_align_seq(a, "f32")?,
514-
["f64", a @ ..] => dl.f64_align = parse_align_seq(a, "f64")?,
515-
["f80", a @ ..] => dl.x87_f80_align = parse_align_seq(a, "f80")?,
516-
["f128", a @ ..] => dl.f128_align = parse_align_seq(a, "f128")?,
517+
["a", a @ ..] => dl.aggregate_align = parse_align_seq(a, "a", u64::MAX)?,
518+
["f16", a @ ..] => dl.f16_align = parse_align_seq(a, "f16", 16)?,
519+
["f32", a @ ..] => dl.f32_align = parse_align_seq(a, "f32", 32)?,
520+
["f64", a @ ..] => dl.f64_align = parse_align_seq(a, "f64", 64)?,
521+
["f80", a @ ..] => dl.x87_f80_align = parse_align_seq(a, "f80", 80)?,
522+
["f128", a @ ..] => dl.f128_align = parse_align_seq(a, "f128", 128)?,
517523
[p, s, a @ ..] if p.starts_with("p") => {
518524
let mut p = p.strip_prefix('p').unwrap();
519525
let mut _is_fat = false;
@@ -541,7 +547,7 @@ impl TargetDataLayout {
541547
};
542548

543549
let pointer_size = parse_size(s, "p-")?;
544-
let pointer_align = parse_align_seq(a, "p-")?;
550+
let pointer_align = parse_align_seq(a, "p-", pointer_size.bits())?;
545551
let info = PointerSpec {
546552
pointer_offset: pointer_size,
547553
pointer_size,
@@ -585,9 +591,10 @@ impl TargetDataLayout {
585591
AddressSpace::ZERO
586592
};
587593

594+
let pointer_size = parse_size(s, "p-")?;
588595
let info = PointerSpec {
589-
pointer_size: parse_size(s, "p-")?,
590-
pointer_align: parse_align_str(a, "p-")?,
596+
pointer_size,
597+
pointer_align: parse_align_str(a, "p-", pointer_size.bits())?,
591598
pointer_offset: parse_size(i, "p-")?,
592599
_is_fat,
593600
};
@@ -609,10 +616,10 @@ impl TargetDataLayout {
609616
parse_size(&s[1..], "i")?; // For the user error.
610617
continue;
611618
};
612-
let a = parse_align_seq(a, s)?;
619+
let a = parse_align_seq(a, s, bits)?;
613620
match bits {
614-
1 => dl.i1_align = a,
615-
8 => dl.i8_align = a,
621+
// i1 and i8 always have an alignment of 1 byte - this has already been
622+
// checked by `parse_align_seq` above.
616623
16 => dl.i16_align = a,
617624
32 => dl.i32_align = a,
618625
64 => dl.i64_align = a,
@@ -627,7 +634,7 @@ impl TargetDataLayout {
627634
}
628635
[s, a @ ..] if s.starts_with('v') => {
629636
let v_size = parse_size(&s[1..], "v")?;
630-
let a = parse_align_seq(a, s)?;
637+
let a = parse_align_seq(a, s, v_size.bits())?;
631638
if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) {
632639
v.1 = a;
633640
continue;
@@ -1280,7 +1287,7 @@ impl Integer {
12801287
let dl = cx.data_layout();
12811288

12821289
match self {
1283-
I8 => dl.i8_align,
1290+
I8 => Align::ONE,
12841291
I16 => dl.i16_align,
12851292
I32 => dl.i32_align,
12861293
I64 => dl.i64_align,

‎compiler/rustc_ast/src/ast.rs‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl From<ParenthesizedArgs> for Box<GenericArgs> {
354354
pub struct ParenthesizedArgs {
355355
/// ```text
356356
/// Foo(A, B) -> C
357-
/// ^^^^^^^^^^^^^^
357+
/// ^^^^^^^^^^^
358358
/// ```
359359
pub span: Span,
360360

@@ -3556,17 +3556,6 @@ impl GeneratedAttr {
35563556
}
35573557
}
35583558

3559-
pub fn is_word(&self) -> bool {
3560-
match self {
3561-
GeneratedAttr::AutomaticallyDerived => true,
3562-
GeneratedAttr::RustcConstUnstableDerived => false,
3563-
GeneratedAttr::Inline => true,
3564-
GeneratedAttr::DocHidden => false,
3565-
GeneratedAttr::CoverageOff => false,
3566-
GeneratedAttr::RustcTestMarker(_) => false,
3567-
GeneratedAttr::RustcTrivialFieldReads => false,
3568-
}
3569-
}
35703559
pub fn value_str(&self) -> Option<Symbol> {
35713560
match self {
35723561
GeneratedAttr::AutomaticallyDerived => None,

‎compiler/rustc_ast/src/attr/mod.rs‎

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::sync::atomic::{AtomicU32, Ordering};
88

99
use rustc_index::bit_set::GrowableBitSet;
1010
use rustc_span::{Ident, Span, Symbol, sym};
11-
use smallvec::{SmallVec, smallvec};
1211
use thin_vec::{ThinVec, thin_vec};
1312

1413
use crate::ast::{
@@ -135,15 +134,6 @@ impl Attribute {
135134
}
136135
}
137136

138-
pub fn meta_kind(&self) -> Option<MetaItemKind> {
139-
match &self.kind {
140-
AttrKind::Normal(normal) => normal.item.meta_kind(),
141-
AttrKind::Synthetic(..) => unreachable!(),
142-
AttrKind::DocComment(..) => None,
143-
AttrKind::Generated(..) => None,
144-
}
145-
}
146-
147137
pub fn append_token_trees_to(&self, res: &mut Vec<TokenTree>) {
148138
match &self.kind {
149139
AttrKind::Normal(normal) => normal
@@ -202,15 +192,6 @@ impl Attribute {
202192
AttrKind::Synthetic(..) | AttrKind::DocComment(..) | AttrKind::Generated(..) => None,
203193
}
204194
}
205-
206-
pub fn path_span(&self) -> Option<Span> {
207-
match &self.kind {
208-
AttrKind::Normal(attr) => Some(attr.item.path.span),
209-
AttrKind::Synthetic(..) => unreachable!(),
210-
AttrKind::DocComment(_, _) => None,
211-
AttrKind::Generated(generated) => generated.path_span(),
212-
}
213-
}
214195
}
215196

216197
impl AttrItem {
@@ -282,6 +263,11 @@ impl AttrItem {
282263
pub fn meta_kind(&self) -> Option<MetaItemKind> {
283264
MetaItemKind::from_attr_args(&self.args)
284265
}
266+
267+
/// Returns whether the attribute is a path, without any arguments.
268+
pub fn is_word(&self) -> bool {
269+
matches!(self.args, AttrArgs::Empty)
270+
}
285271
}
286272

287273
impl MetaItem {
@@ -891,30 +877,6 @@ impl Attribute {
891877
names.iter().any(|&name| self.has_name(name))
892878
}
893879

894-
/// Returns whether the attribute is a path, without any arguments.
895-
pub fn is_word(&self) -> bool {
896-
match &self.kind {
897-
AttrKind::Normal(normal) => matches!(normal.item.args, AttrArgs::Empty),
898-
AttrKind::Synthetic(..) => unreachable!(),
899-
AttrKind::DocComment(..) => false,
900-
AttrKind::Generated(generated) => generated.is_word(),
901-
}
902-
}
903-
904-
pub fn path(&self) -> SmallVec<[Symbol; 1]> {
905-
use SyntheticAttr::*;
906-
match &self.kind {
907-
AttrKind::Normal(normal) => {
908-
normal.item.path.segments.iter().map(|i| i.ident.name).collect()
909-
}
910-
AttrKind::Synthetic(CfgTrace(_)) => smallvec![sym::cfg],
911-
AttrKind::Synthetic(CfgAttrTrace(_)) => smallvec![sym::cfg_attr],
912-
AttrKind::Synthetic(TestEntrypoint) => smallvec![],
913-
AttrKind::DocComment(_, _) => smallvec![sym::doc],
914-
AttrKind::Generated(generated) => generated.path().iter().copied().collect(),
915-
}
916-
}
917-
918880
/// Returns the documentation if this is a doc comment or a sugared doc comment.
919881
/// * `///doc` returns `Some("doc")`.
920882
/// * `#[doc = "doc"]` returns `Some("doc")`.

‎compiler/rustc_ast_lowering/src/item.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
13261326
// create a fake body so that the entire rest of the compiler doesn't have to deal with
13271327
// this as a special case.
13281328
return self.lower_fn_body(decl, contract, |this| {
1329-
if find_attr!(attrs, RustcIntrinsic) || this.tcx.is_sdylib_interface_build() {
1329+
if find_attr!(attrs, RustcIntrinsic { .. }) || this.tcx.is_sdylib_interface_build()
1330+
{
13301331
let span = this.lower_span(span);
13311332
let empty_block = hir::Block {
13321333
hir_id: this.next_id(),

‎compiler/rustc_ast_lowering/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13111311
args: Default::default(),
13121312
constraints: &[],
13131313
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1314-
span: data.span,
1314+
span: constraint.ident.span.to(data.span),
13151315
}
13161316
} else {
13171317
let guar = self.emit_bad_parenthesized_trait_in_assoc_ty(data);

0 commit comments

Comments
 (0)