Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 16 pull requests #138255

Closed
wants to merge 47 commits into from
Closed
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8f6b184
Turn order dependent trait objects future incompat warning into a har…
oli-obk Feb 13, 2025
cc39e5f
Apply dllimport in ThinLTO
Zoxc Mar 20, 2024
8edf528
tidy: add check to verify paths in triagebot.toml
klensy Mar 2, 2025
aa72de9
fix triagebot.toml
klensy Mar 2, 2025
36efaf8
normalize away `-Wlinker-messages` wrappers from `rust-lld` rmake test
lqd Mar 5, 2025
4203e9c
depend more on attr_data_structures and move find_attr! there
jdonszelmann Feb 12, 2025
38fad98
compiler: Use size_of from the prelude instead of imported
thaliaarchi Mar 5, 2025
8af0aa2
Remove `[lints.rust]` section from `rustc_type_ir`.
nnethercote Mar 6, 2025
a8eeb4b
Remove `[lints.rust]` section from `rustc_builtin_macros`.
nnethercote Mar 7, 2025
beba32c
Specify rust lints for `compiler/` crates via Cargo.
nnethercote Mar 6, 2025
9212e31
Add `unreachable_pub` to the default lints for `compiler/` crates.
nnethercote Mar 6, 2025
8a3e033
Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.
nnethercote Mar 6, 2025
c76946a
add exclude to config.toml
Shourya742 Feb 16, 2025
86ca102
add test for exclude feature
Shourya742 Feb 16, 2025
c7af90d
Add change info to change tracker
Shourya742 Feb 16, 2025
46c387b
make test platform agnostic
Shourya742 Mar 4, 2025
f83af2a
bootstrap: Fix stack printing when a step cycle is detected
Zalathar Mar 8, 2025
9917173
Remove most manual LayoutData creations and move them to `rustc_abi`
moulins Feb 28, 2025
e69491a
Move SIMD layout logic to `rustc_abi`
moulins Mar 7, 2025
f79f3d3
Use `rustc_abi` code for SIMD layout in rust-analyzer
moulins Mar 7, 2025
b8a2170
Refactor coroutine layout logic to precompute all sublayouts
moulins Mar 7, 2025
5712d2e
add a test for pointer casts involving un/re/wrapping trait objects
WaffleLapkin Jan 16, 2025
b62d58f
check that `UnsizeCoerce` may hold before trying unsizing coercion
WaffleLapkin Jan 16, 2025
80157a5
bless tests
WaffleLapkin Jan 17, 2025
08530d3
Move coroutine layout logic to `rustc_abi`
moulins Mar 7, 2025
2cff733
Reduce verbosity of GCC build log
Kobzol Mar 8, 2025
9278a3e
Don't link against advapi32, except on win7.
smmalis37 Mar 8, 2025
50ea503
Stabilize `const_vec_string_slice`
Kixunil Feb 20, 2025
31e22c6
re-add gnu lib and tweak comment
smmalis37 Mar 8, 2025
088b125
crashes: couple more tests
matthiaskrgr Mar 7, 2025
20ed8fb
Revert "Don't test new error messages with the stage 0 compiler"
tshepang Mar 8, 2025
1c56691
Rollup merge of #122790 - Zoxc:dllimp-rev, r=ChrisDenton
jieyouxu Mar 9, 2025
0b728ee
Rollup merge of #136127 - WaffleLapkin:dyn_ptr_unwrap_cast, r=compile…
jieyouxu Mar 9, 2025
39ce41d
Rollup merge of #136968 - oli-obk:bye-bye, r=compiler-errors
jieyouxu Mar 9, 2025
94a477a
Rollup merge of #137147 - Shourya742:2025-02-16-support-exclude-in-co…
jieyouxu Mar 9, 2025
897f93f
Rollup merge of #137319 - Kixunil:stabilize-const-vec-string-slice, r…
jieyouxu Mar 9, 2025
1a07640
Rollup merge of #137885 - klensy:tidy-triagebot, r=jieyouxu
jieyouxu Mar 9, 2025
7e0e8d7
Rollup merge of #138040 - thaliaarchi:use-prelude-size-of.compiler, r…
jieyouxu Mar 9, 2025
d0694be
Rollup merge of #138052 - lqd:lld-linker-messages, r=jieyouxu
jieyouxu Mar 9, 2025
f87b2bc
Rollup merge of #138084 - nnethercote:workspace-lints, r=jieyouxu
jieyouxu Mar 9, 2025
2d44ec9
Rollup merge of #138158 - moulins:move-layout-to-rustc_abi, r=working…
jieyouxu Mar 9, 2025
20eef60
Rollup merge of #138160 - jdonszelmann:move-find-attr2, r=oli-obk
jieyouxu Mar 9, 2025
3b40a1f
Rollup merge of #138192 - matthiaskrgr:crashes_mar, r=jieyouxu
jieyouxu Mar 9, 2025
190ba2c
Rollup merge of #138216 - Zalathar:any-debug, r=onur-ozkan
jieyouxu Mar 9, 2025
aa0e160
Rollup merge of #138232 - Kobzol:gcc-reduce-verbosity, r=GuillaumeGomez
jieyouxu Mar 9, 2025
fc33066
Rollup merge of #138233 - smmalis37:no-advapi32, r=ChrisDenton
jieyouxu Mar 9, 2025
07f2520
Rollup merge of #138242 - tshepang:that-stage0-has-arrived, r=jieyouxu
jieyouxu Mar 9, 2025
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
7 changes: 5 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
@@ -3297,6 +3297,7 @@ dependencies = [
"rustc_hir",
"rustc_lexer",
"rustc_macros",
"rustc_middle",
"rustc_serialize",
"rustc_session",
"rustc_span",
@@ -3752,7 +3753,7 @@ dependencies = [
"rustc_abi",
"rustc_ast",
"rustc_ast_pretty",
"rustc_attr_parsing",
"rustc_attr_data_structures",
"rustc_hir",
"rustc_span",
]
@@ -4020,7 +4021,8 @@ dependencies = [
"rustc_apfloat",
"rustc_arena",
"rustc_ast",
"rustc_attr_parsing",
"rustc_ast_ir",
"rustc_attr_data_structures",
"rustc_data_structures",
"rustc_error_messages",
"rustc_errors",
@@ -5271,6 +5273,7 @@ dependencies = [
"serde",
"similar",
"termcolor",
"toml 0.7.8",
"walkdir",
]

14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -63,6 +63,20 @@ exclude = [
"src/tools/x",
]

# These lints are applied to many crates in the workspace. In practice, this is
# all crates under `compiler/`.
#
# NOTE: rustc-specific lints (e.g. `rustc::internal`) aren't supported by
# Cargo. (Support for them is possibly blocked by #44690 (attributes for
# tools).) Those lints are instead specified for `compiler/` crates in
# `src/bootstrap/src/core/builder/cargo.rs`.
[workspace.lints.rust]
# FIXME(edition_2024): Change this to `-Wrust_2024_idioms` when all of the
# individual lints are satisfied.
keyword_idents_2024 = "warn"
unreachable_pub = "warn"
unsafe_op_in_unsafe_fn = "warn"

[profile.release.package.rustc-rayon-core]
# The rustc fork of Rayon has deadlock detection code which intermittently
# causes overflows in the CI (see https://github.com/rust-lang/rust/issues/90227)
3 changes: 3 additions & 0 deletions compiler/rustc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -32,3 +32,6 @@ llvm = ['rustc_driver_impl/llvm']
max_level_info = ['rustc_driver_impl/max_level_info']
rustc_randomized_layouts = ['rustc_driver_impl/rustc_randomized_layouts']
# tidy-alphabetical-end

[lints]
workspace = true
3 changes: 3 additions & 0 deletions compiler/rustc_abi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -31,3 +31,6 @@ nightly = [
]
randomize = ["dep:rand", "dep:rand_xoshiro", "nightly"]
# tidy-alphabetical-end

[lints]
workspace = true
192 changes: 133 additions & 59 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ use std::{cmp, iter};

use rustc_hashes::Hash64;
use rustc_index::Idx;
use rustc_index::bit_set::BitMatrix;
use tracing::debug;

use crate::{
@@ -12,6 +13,9 @@ use crate::{
Variants, WrappingRange,
};

mod coroutine;
mod simple;

#[cfg(feature = "nightly")]
mod ty;

@@ -60,31 +64,44 @@ pub enum LayoutCalculatorError<F> {

/// The fields or variants have irreconcilable reprs
ReprConflict,

/// The length of an SIMD type is zero
ZeroLengthSimdType,

/// The length of an SIMD type exceeds the maximum number of lanes
OversizedSimdType { max_lanes: u64 },

/// An element type of an SIMD type isn't a primitive
NonPrimitiveSimdType(F),
}

impl<F> LayoutCalculatorError<F> {
pub fn without_payload(&self) -> LayoutCalculatorError<()> {
match self {
LayoutCalculatorError::UnexpectedUnsized(_) => {
LayoutCalculatorError::UnexpectedUnsized(())
}
LayoutCalculatorError::SizeOverflow => LayoutCalculatorError::SizeOverflow,
LayoutCalculatorError::EmptyUnion => LayoutCalculatorError::EmptyUnion,
LayoutCalculatorError::ReprConflict => LayoutCalculatorError::ReprConflict,
use LayoutCalculatorError::*;
match *self {
UnexpectedUnsized(_) => UnexpectedUnsized(()),
SizeOverflow => SizeOverflow,
EmptyUnion => EmptyUnion,
ReprConflict => ReprConflict,
ZeroLengthSimdType => ZeroLengthSimdType,
OversizedSimdType { max_lanes } => OversizedSimdType { max_lanes },
NonPrimitiveSimdType(_) => NonPrimitiveSimdType(()),
}
}

/// Format an untranslated diagnostic for this type
///
/// Intended for use by rust-analyzer, as neither it nor `rustc_abi` depend on fluent infra.
pub fn fallback_fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use LayoutCalculatorError::*;
f.write_str(match self {
LayoutCalculatorError::UnexpectedUnsized(_) => {
"an unsized type was found where a sized type was expected"
UnexpectedUnsized(_) => "an unsized type was found where a sized type was expected",
SizeOverflow => "size overflow",
EmptyUnion => "type is a union with no fields",
ReprConflict => "type has an invalid repr",
ZeroLengthSimdType | OversizedSimdType { .. } | NonPrimitiveSimdType(_) => {
"invalid simd type definition"
}
LayoutCalculatorError::SizeOverflow => "size overflow",
LayoutCalculatorError::EmptyUnion => "type is a union with no fields",
LayoutCalculatorError::ReprConflict => "type has an invalid repr",
})
}
}
@@ -102,41 +119,115 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
Self { cx }
}

pub fn scalar_pair<FieldIdx: Idx, VariantIdx: Idx>(
pub fn array_like<FieldIdx: Idx, VariantIdx: Idx, F>(
&self,
a: Scalar,
b: Scalar,
) -> LayoutData<FieldIdx, VariantIdx> {
let dl = self.cx.data_layout();
let b_align = b.align(dl);
let align = a.align(dl).max(b_align).max(dl.aggregate_align);
let b_offset = a.size(dl).align_to(b_align.abi);
let size = (b_offset + b.size(dl)).align_to(align.abi);
element: &LayoutData<FieldIdx, VariantIdx>,
count_if_sized: Option<u64>, // None for slices
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F> {
let count = count_if_sized.unwrap_or(0);
let size =
element.size.checked_mul(count, &self.cx).ok_or(LayoutCalculatorError::SizeOverflow)?;

// HACK(nox): We iter on `b` and then `a` because `max_by_key`
// returns the last maximum.
let largest_niche = Niche::from_scalar(dl, b_offset, b)
.into_iter()
.chain(Niche::from_scalar(dl, Size::ZERO, a))
.max_by_key(|niche| niche.available(dl));
Ok(LayoutData {
variants: Variants::Single { index: VariantIdx::new(0) },
fields: FieldsShape::Array { stride: element.size, count },
backend_repr: BackendRepr::Memory { sized: count_if_sized.is_some() },
largest_niche: element.largest_niche.filter(|_| count != 0),
uninhabited: element.uninhabited && count != 0,
align: element.align,
size,
max_repr_align: None,
unadjusted_abi_align: element.align.abi,
randomization_seed: element.randomization_seed.wrapping_add(Hash64::new(count)),
})
}

let combined_seed = a.size(&self.cx).bytes().wrapping_add(b.size(&self.cx).bytes());
pub fn simd_type<
FieldIdx: Idx,
VariantIdx: Idx,
F: AsRef<LayoutData<FieldIdx, VariantIdx>> + fmt::Debug,
>(
&self,
element: F,
count: u64,
repr_packed: bool,
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F> {
let elt = element.as_ref();
if count == 0 {
return Err(LayoutCalculatorError::ZeroLengthSimdType);
} else if count > crate::MAX_SIMD_LANES {
return Err(LayoutCalculatorError::OversizedSimdType {
max_lanes: crate::MAX_SIMD_LANES,
});
}

LayoutData {
let BackendRepr::Scalar(e_repr) = elt.backend_repr else {
return Err(LayoutCalculatorError::NonPrimitiveSimdType(element));
};

// Compute the size and alignment of the vector
let dl = self.cx.data_layout();
let size =
elt.size.checked_mul(count, dl).ok_or_else(|| LayoutCalculatorError::SizeOverflow)?;
let (repr, align) = if repr_packed && !count.is_power_of_two() {
// Non-power-of-two vectors have padding up to the next power-of-two.
// If we're a packed repr, remove the padding while keeping the alignment as close
// to a vector as possible.
(
BackendRepr::Memory { sized: true },
AbiAndPrefAlign {
abi: Align::max_aligned_factor(size),
pref: dl.llvmlike_vector_align(size).pref,
},
)
} else {
(BackendRepr::SimdVector { element: e_repr, count }, dl.llvmlike_vector_align(size))
};
let size = size.align_to(align.abi);

Ok(LayoutData {
variants: Variants::Single { index: VariantIdx::new(0) },
fields: FieldsShape::Arbitrary {
offsets: [Size::ZERO, b_offset].into(),
memory_index: [0, 1].into(),
offsets: [Size::ZERO].into(),
memory_index: [0].into(),
},
backend_repr: BackendRepr::ScalarPair(a, b),
largest_niche,
backend_repr: repr,
largest_niche: elt.largest_niche,
uninhabited: false,
align,
size,
align,
max_repr_align: None,
unadjusted_abi_align: align.abi,
randomization_seed: Hash64::new(combined_seed),
}
unadjusted_abi_align: elt.align.abi,
randomization_seed: elt.randomization_seed.wrapping_add(Hash64::new(count)),
})
}

/// Compute the layout for a coroutine.
///
/// This uses dedicated code instead of [`Self::layout_of_struct_or_enum`], as coroutine
/// fields may be shared between multiple variants (see the [`coroutine`] module for details).
pub fn coroutine<
'a,
F: Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + fmt::Debug + Copy,
VariantIdx: Idx,
FieldIdx: Idx,
LocalIdx: Idx,
>(
&self,
local_layouts: &IndexSlice<LocalIdx, F>,
prefix_layouts: IndexVec<FieldIdx, F>,
variant_fields: &IndexSlice<VariantIdx, IndexVec<FieldIdx, LocalIdx>>,
storage_conflicts: &BitMatrix<LocalIdx, LocalIdx>,
tag_to_layout: impl Fn(Scalar) -> F,
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F> {
coroutine::layout(
self,
local_layouts,
prefix_layouts,
variant_fields,
storage_conflicts,
tag_to_layout,
)
}

pub fn univariant<
@@ -214,25 +305,6 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
layout
}

pub fn layout_of_never_type<FieldIdx: Idx, VariantIdx: Idx>(
&self,
) -> LayoutData<FieldIdx, VariantIdx> {
let dl = self.cx.data_layout();
// This is also used for uninhabited enums, so we use `Variants::Empty`.
LayoutData {
variants: Variants::Empty,
fields: FieldsShape::Primitive,
backend_repr: BackendRepr::Memory { sized: true },
largest_niche: None,
uninhabited: true,
align: dl.i8_align,
size: Size::ZERO,
max_repr_align: None,
unadjusted_abi_align: dl.i8_align.abi,
randomization_seed: Hash64::ZERO,
}
}

pub fn layout_of_struct_or_enum<
'a,
FieldIdx: Idx,
@@ -260,7 +332,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
Some(present_first) => present_first,
// Uninhabited because it has no variants, or only absent ones.
None if is_enum => {
return Ok(self.layout_of_never_type());
return Ok(LayoutData::never_type(&self.cx));
}
// If it's a struct, still compute a layout so that we can still compute the
// field offsets.
@@ -949,7 +1021,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
// Common prim might be uninit.
Scalar::Union { value: prim }
};
let pair = self.scalar_pair::<FieldIdx, VariantIdx>(tag, prim_scalar);
let pair =
LayoutData::<FieldIdx, VariantIdx>::scalar_pair(&self.cx, tag, prim_scalar);
let pair_offsets = match pair.fields {
FieldsShape::Arbitrary { ref offsets, ref memory_index } => {
assert_eq!(memory_index.raw, [0, 1]);
@@ -1341,7 +1414,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
} else {
((j, b), (i, a))
};
let pair = self.scalar_pair::<FieldIdx, VariantIdx>(a, b);
let pair =
LayoutData::<FieldIdx, VariantIdx>::scalar_pair(&self.cx, a, b);
let pair_offsets = match pair.fields {
FieldsShape::Arbitrary { ref offsets, ref memory_index } => {
assert_eq!(memory_index.raw, [0, 1]);
Loading