Skip to content

Rollup of 12 pull requests #137346

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

Merged
merged 32 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5914fb7
Stabilize `num_midpoint_signed` feature
Urgau Dec 15, 2024
2445dd7
Persist target features used for codegen beyond tcx
Feb 9, 2025
831d9f3
Pass through of target features to llvm-bitcode-linker and handling them
Feb 5, 2025
35febd7
Fix `*-win7-windows-msvc` target since 26eeac1a1e9fe46ffd80dd0d3dafdd…
QianNangong Feb 19, 2025
78ddabf
Create a generic AVR target: avr-none
Patryk27 Oct 13, 2024
81ab20f
Update references to cc_detect.rs
jmqd Feb 20, 2025
c23bf48
infer linker flavor by linker name if it's sufficiently specific
usamoi Feb 3, 2025
d5128f9
avr-rjmp-offset: Explain `.target_cpu()`
Patryk27 Feb 20, 2025
18c210c
Workaround Cranelift not yet properly supporting vectors smaller than…
bjorn3 Feb 20, 2025
c2aed39
Update docs for default features of wasm targets
alexcrichton Feb 20, 2025
32a1ff1
Make x86 QNX target name consistent with other Rust targets
flba-eb Feb 20, 2025
7ba3d7b
Remove `BackendRepr::Uninhabited`, replaced with an `uninhabited: boo…
zachs18 Jan 26, 2025
c33fb5a
Update ui tests with `LayoutData { uninhabited: ... }` etc
zachs18 Jan 26, 2025
bcfde13
Update check to reflect that non-ZST uninhabited types should not be …
zachs18 Jan 28, 2025
58ebf6a
Add test that uninhabited repr(transparent) type has same function re…
zachs18 Feb 13, 2025
6493cd8
Adjust LayoutData::uninhabited doc comment.
zachs18 Feb 18, 2025
e3f5db0
fine-tune comment
RalfJung Feb 18, 2025
9535151
Improve error message when a submodule directory is missing completely
Kobzol Feb 20, 2025
d2203ad
skip submodule updating logics on tarballs
onur-ozkan Feb 20, 2025
c0bea5d
Add a notice about missing GCC sources in source tarballs
Kobzol Feb 20, 2025
9de94b4
Rollup merge of #131651 - Patryk27:avr-unknown-unknown, r=tgross35
workingjubilee Feb 20, 2025
480a72d
Rollup merge of #134340 - Urgau:stabilize-num_midpoint_signed, r=scot…
workingjubilee Feb 20, 2025
921ef32
Rollup merge of #136473 - usamoi:infer_linker_hints, r=petrochenkov
workingjubilee Feb 20, 2025
6d74563
Rollup merge of #136608 - kulst:ptx_target_features, r=bjorn3
workingjubilee Feb 20, 2025
8c9e374
Rollup merge of #136985 - zachs18:backend-repr-remove-uninhabited, r=…
workingjubilee Feb 20, 2025
f24b140
Rollup merge of #137270 - QianNangong:master, r=ChrisDenton
workingjubilee Feb 20, 2025
0d47366
Rollup merge of #137312 - jmqd:master, r=clubby789
workingjubilee Feb 20, 2025
8d5eb73
Rollup merge of #137318 - bjorn3:cg_clif_abi_workaround, r=workingjub…
workingjubilee Feb 20, 2025
3d5e773
Rollup merge of #137322 - alexcrichton:update-wasm-docs, r=jieyouxu
workingjubilee Feb 20, 2025
8aa75f5
Rollup merge of #137324 - flba-eb:rename_qnx_target_name_i586, r=work…
workingjubilee Feb 20, 2025
02ceb5f
Rollup merge of #137338 - onur-ozkan:137332, r=Kobzol
workingjubilee Feb 20, 2025
4d479f9
Rollup merge of #137340 - Kobzol:bootstrap-dir-check, r=onur-ozkan
workingjubilee Feb 20, 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
2 changes: 0 additions & 2 deletions compiler/rustc_abi/src/callconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
Ty: TyAbiInterface<'a, C> + Copy,
{
match self.backend_repr {
BackendRepr::Uninhabited => Err(Heterogeneous),

// The primitive for this algorithm.
BackendRepr::Scalar(scalar) => {
let kind = match scalar.primitive() {
Expand Down
23 changes: 12 additions & 11 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
},
backend_repr: BackendRepr::ScalarPair(a, b),
largest_niche,
uninhabited: false,
align,
size,
max_repr_align: None,
Expand Down Expand Up @@ -221,8 +222,9 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
LayoutData {
variants: Variants::Empty,
fields: FieldsShape::Primitive,
backend_repr: BackendRepr::Uninhabited,
backend_repr: BackendRepr::Memory { sized: true },
largest_niche: None,
uninhabited: true,
align: dl.i8_align,
size: Size::ZERO,
max_repr_align: None,
Expand Down Expand Up @@ -400,6 +402,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
fields: FieldsShape::Union(union_field_count),
backend_repr: abi,
largest_niche: None,
uninhabited: false,
align,
size: size.align_to(align.abi),
max_repr_align,
Expand Down Expand Up @@ -447,7 +450,6 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
Scalar::Union { .. } => {}
};
match &mut st.backend_repr {
BackendRepr::Uninhabited => {}
BackendRepr::Scalar(scalar) => hide_niches(scalar),
BackendRepr::ScalarPair(a, b) => {
hide_niches(a);
Expand Down Expand Up @@ -639,9 +641,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
let same_size = size == variant_layouts[largest_variant_index].size;
let same_align = align == variant_layouts[largest_variant_index].align;

let abi = if variant_layouts.iter().all(|v| v.is_uninhabited()) {
BackendRepr::Uninhabited
} else if same_size && same_align && others_zst {
let uninhabited = variant_layouts.iter().all(|v| v.is_uninhabited());
let abi = if same_size && same_align && others_zst {
match variant_layouts[largest_variant_index].backend_repr {
// When the total alignment and size match, we can use the
// same ABI as the scalar variant with the reserved niche.
Expand Down Expand Up @@ -683,6 +684,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
},
backend_repr: abi,
largest_niche,
uninhabited,
size,
align,
max_repr_align,
Expand Down Expand Up @@ -853,9 +855,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
};
let mut abi = BackendRepr::Memory { sized: true };

if layout_variants.iter().all(|v| v.is_uninhabited()) {
abi = BackendRepr::Uninhabited;
} else if tag.size(dl) == size {
let uninhabited = layout_variants.iter().all(|v| v.is_uninhabited());
if tag.size(dl) == size {
// Make sure we only use scalar layout when the enum is entirely its
// own tag (i.e. it has no padding nor any non-ZST variant fields).
abi = BackendRepr::Scalar(tag);
Expand Down Expand Up @@ -995,6 +996,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
memory_index: [0].into(),
},
largest_niche,
uninhabited,
backend_repr: abi,
align,
size,
Expand Down Expand Up @@ -1355,9 +1357,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
_ => {}
}
}
if fields.iter().any(|f| f.is_uninhabited()) {
abi = BackendRepr::Uninhabited;
}
let uninhabited = fields.iter().any(|f| f.is_uninhabited());

let unadjusted_abi_align = if repr.transparent() {
match layout_of_single_non_zst_field {
Expand All @@ -1378,6 +1378,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
fields: FieldsShape::Arbitrary { offsets, memory_index },
backend_repr: abi,
largest_niche,
uninhabited,
align,
size,
max_repr_align,
Expand Down
35 changes: 16 additions & 19 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,6 @@ impl AddressSpace {
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
pub enum BackendRepr {
Uninhabited,
Scalar(Scalar),
ScalarPair(Scalar, Scalar),
Vector {
Expand All @@ -1423,10 +1422,9 @@ impl BackendRepr {
#[inline]
pub fn is_unsized(&self) -> bool {
match *self {
BackendRepr::Uninhabited
| BackendRepr::Scalar(_)
| BackendRepr::ScalarPair(..)
| BackendRepr::Vector { .. } => false,
BackendRepr::Scalar(_) | BackendRepr::ScalarPair(..) | BackendRepr::Vector { .. } => {
false
}
BackendRepr::Memory { sized } => !sized,
}
}
Expand All @@ -1445,12 +1443,6 @@ impl BackendRepr {
}
}

/// Returns `true` if this is an uninhabited type
#[inline]
pub fn is_uninhabited(&self) -> bool {
matches!(*self, BackendRepr::Uninhabited)
}

/// Returns `true` if this is a scalar type
#[inline]
pub fn is_scalar(&self) -> bool {
Expand All @@ -1471,7 +1463,7 @@ impl BackendRepr {
BackendRepr::Vector { element, count } => {
cx.data_layout().vector_align(element.size(cx) * count)
}
BackendRepr::Uninhabited | BackendRepr::Memory { .. } => return None,
BackendRepr::Memory { .. } => return None,
})
}

Expand All @@ -1492,7 +1484,7 @@ impl BackendRepr {
// to make the size a multiple of align (e.g. for vectors of size 3).
(element.size(cx) * count).align_to(self.inherent_align(cx)?.abi)
}
BackendRepr::Uninhabited | BackendRepr::Memory { .. } => return None,
BackendRepr::Memory { .. } => return None,
})
}

Expand All @@ -1506,9 +1498,7 @@ impl BackendRepr {
BackendRepr::Vector { element, count } => {
BackendRepr::Vector { element: element.to_union(), count }
}
BackendRepr::Uninhabited | BackendRepr::Memory { .. } => {
BackendRepr::Memory { sized: true }
}
BackendRepr::Memory { .. } => BackendRepr::Memory { sized: true },
}
}

Expand Down Expand Up @@ -1704,6 +1694,11 @@ pub struct LayoutData<FieldIdx: Idx, VariantIdx: Idx> {
/// The leaf scalar with the largest number of invalid values
/// (i.e. outside of its `valid_range`), if it exists.
pub largest_niche: Option<Niche>,
/// Is this type known to be uninhabted?
///
/// This is separate from BackendRepr because uninhabited return types can affect ABI,
/// especially in the case of by-pointer struct returns, which allocate stack even when unused.
pub uninhabited: bool,

pub align: AbiAndPrefAlign,
pub size: Size,
Expand Down Expand Up @@ -1735,14 +1730,14 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
/// Returns `true` if this is an aggregate type (including a ScalarPair!)
pub fn is_aggregate(&self) -> bool {
match self.backend_repr {
BackendRepr::Uninhabited | BackendRepr::Scalar(_) | BackendRepr::Vector { .. } => false,
BackendRepr::Scalar(_) | BackendRepr::Vector { .. } => false,
BackendRepr::ScalarPair(..) | BackendRepr::Memory { .. } => true,
}
}

/// Returns `true` if this is an uninhabited type
pub fn is_uninhabited(&self) -> bool {
self.backend_repr.is_uninhabited()
self.uninhabited
}

pub fn scalar<C: HasDataLayout>(cx: &C, scalar: Scalar) -> Self {
Expand Down Expand Up @@ -1778,6 +1773,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
fields: FieldsShape::Primitive,
backend_repr: BackendRepr::Scalar(scalar),
largest_niche,
uninhabited: false,
size,
align,
max_repr_align: None,
Expand All @@ -1802,6 +1798,7 @@ where
backend_repr,
fields,
largest_niche,
uninhabited,
variants,
max_repr_align,
unadjusted_abi_align,
Expand All @@ -1813,6 +1810,7 @@ where
.field("abi", backend_repr)
.field("fields", fields)
.field("largest_niche", largest_niche)
.field("uninhabited", uninhabited)
.field("variants", variants)
.field("max_repr_align", max_repr_align)
.field("unadjusted_abi_align", unadjusted_abi_align)
Expand Down Expand Up @@ -1877,7 +1875,6 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
BackendRepr::Scalar(_) | BackendRepr::ScalarPair(..) | BackendRepr::Vector { .. } => {
false
}
BackendRepr::Uninhabited => self.size.bytes() == 0,
BackendRepr::Memory { sized } => sized && self.size.bytes() == 0,
}
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_cranelift/src/value_and_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,7 @@ impl<'tcx> CPlace<'tcx> {
}
CPlaceInner::Addr(_, Some(_)) => bug!("Can't write value to unsized place {:?}", self),
CPlaceInner::Addr(to_ptr, None) => {
if dst_layout.size == Size::ZERO
|| dst_layout.backend_repr == BackendRepr::Uninhabited
{
if dst_layout.size == Size::ZERO {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
let layout = self.layout_of(tp_ty).layout;
let _use_integer_compare = match layout.backend_repr() {
Scalar(_) | ScalarPair(_, _) => true,
Uninhabited | Vector { .. } => false,
Vector { .. } => false,
Memory { .. } => {
// For rusty ABIs, small aggregates are actually passed
// as `RegKind::Integer` (see `FnAbi::adjust_for_abi`),
Expand Down
13 changes: 5 additions & 8 deletions compiler/rustc_codegen_gcc/src/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn uncached_gcc_type<'gcc, 'tcx>(
false,
);
}
BackendRepr::Uninhabited | BackendRepr::Memory { .. } => {}
BackendRepr::Memory { .. } => {}
}

let name = match *layout.ty.kind() {
Expand Down Expand Up @@ -179,19 +179,16 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
fn is_gcc_immediate(&self) -> bool {
match self.backend_repr {
BackendRepr::Scalar(_) | BackendRepr::Vector { .. } => true,
BackendRepr::ScalarPair(..) | BackendRepr::Uninhabited | BackendRepr::Memory { .. } => {
false
}
BackendRepr::ScalarPair(..) | BackendRepr::Memory { .. } => false,
}
}

fn is_gcc_scalar_pair(&self) -> bool {
match self.backend_repr {
BackendRepr::ScalarPair(..) => true,
BackendRepr::Uninhabited
| BackendRepr::Scalar(_)
| BackendRepr::Vector { .. }
| BackendRepr::Memory { .. } => false,
BackendRepr::Scalar(_) | BackendRepr::Vector { .. } | BackendRepr::Memory { .. } => {
false
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
let layout = self.layout_of(tp_ty).layout;
let use_integer_compare = match layout.backend_repr() {
Scalar(_) | ScalarPair(_, _) => true,
Uninhabited | Vector { .. } => false,
Vector { .. } => false,
Memory { .. } => {
// For rusty ABIs, small aggregates are actually passed
// as `RegKind::Integer` (see `FnAbi::adjust_for_abi`),
Expand Down
13 changes: 5 additions & 8 deletions compiler/rustc_codegen_llvm/src/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn uncached_llvm_type<'a, 'tcx>(
let element = layout.scalar_llvm_type_at(cx, element);
return cx.type_vector(element, count);
}
BackendRepr::Uninhabited | BackendRepr::Memory { .. } | BackendRepr::ScalarPair(..) => {}
BackendRepr::Memory { .. } | BackendRepr::ScalarPair(..) => {}
}

let name = match layout.ty.kind() {
Expand Down Expand Up @@ -172,19 +172,16 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
fn is_llvm_immediate(&self) -> bool {
match self.backend_repr {
BackendRepr::Scalar(_) | BackendRepr::Vector { .. } => true,
BackendRepr::ScalarPair(..) | BackendRepr::Uninhabited | BackendRepr::Memory { .. } => {
false
}
BackendRepr::ScalarPair(..) | BackendRepr::Memory { .. } => false,
}
}

fn is_llvm_scalar_pair(&self) -> bool {
match self.backend_repr {
BackendRepr::ScalarPair(..) => true,
BackendRepr::Uninhabited
| BackendRepr::Scalar(_)
| BackendRepr::Vector { .. }
| BackendRepr::Memory { .. } => false,
BackendRepr::Scalar(_) | BackendRepr::Vector { .. } | BackendRepr::Memory { .. } => {
false
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,7 @@ fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor)
if let Some(args) = sess.target.pre_link_args.get(&flavor) {
cmd.verbatim_args(args.iter().map(Deref::deref));
}

cmd.verbatim_args(&sess.opts.unstable_opts.pre_link_args);
}

Expand Down Expand Up @@ -2518,6 +2519,12 @@ fn add_order_independent_options(
"--target-cpu",
&codegen_results.crate_info.target_cpu,
]);
if codegen_results.crate_info.target_features.len() > 0 {
cmd.link_arg(&format!(
"--target-feature={}",
&codegen_results.crate_info.target_features.join(",")
));
}
} else if flavor == LinkerFlavor::Ptx {
cmd.link_args(&["--fallback-arch", &codegen_results.crate_info.target_cpu]);
} else if flavor == LinkerFlavor::Bpf {
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ pub(crate) fn get_linker<'a>(
hinted_static: None,
is_ld: cc == Cc::No,
is_gnu: flavor.is_gnu(),
uses_lld: flavor.uses_lld(),
}) as Box<dyn Linker>,
LinkerFlavor::Msvc(..) => Box::new(MsvcLinker { cmd, sess }) as Box<dyn Linker>,
LinkerFlavor::EmCc => Box::new(EmLinker { cmd, sess }) as Box<dyn Linker>,
Expand Down Expand Up @@ -361,6 +362,7 @@ struct GccLinker<'a> {
// Link as ld
is_ld: bool,
is_gnu: bool,
uses_lld: bool,
}

impl<'a> GccLinker<'a> {
Expand Down Expand Up @@ -552,6 +554,7 @@ impl<'a> Linker for GccLinker<'a> {
self.link_args(&["--entry", "_initialize"]);
}
}

// VxWorks compiler driver introduced `--static-crt` flag specifically for rustc,
// it switches linking for libc and similar system libraries to static without using
// any `#[link]` attributes in the `libc` crate, see #72782 for details.
Expand All @@ -567,6 +570,15 @@ impl<'a> Linker for GccLinker<'a> {
{
self.cc_arg("--static-crt");
}

// avr-none doesn't have default ISA, users must specify which specific
// CPU (well, microcontroller) they are targetting using `-Ctarget-cpu`.
//
// Currently this makes sense only when using avr-gcc as a linker, since
// it brings a couple of hand-written important intrinsics from libgcc.
if self.sess.target.arch == "avr" && !self.uses_lld {
self.verbatim_arg(format!("-mmcu={}", self.target_cpu));
}
}

fn link_dylib_by_name(&mut self, name: &str, verbatim: bool, as_needed: bool) {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ impl CrateInfo {
let n_crates = crates.len();
let mut info = CrateInfo {
target_cpu,
target_features: tcx.global_backend_features(()).clone(),
crate_types,
exported_symbols,
linked_symbols,
Expand Down
Loading
Loading