Skip to content

Commit

Permalink
Auto merge of rust-lang#136684 - matthiaskrgr:rollup-mlpzre5, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#135973 (fix tail call checks wrt `#[track_caller]`)
 - rust-lang#136191 (compiler: replace few consts arrays with statics to remove const dupes)
 - rust-lang#136565 (compiler: Clean up weird `rustc_abi` reexports)
 - rust-lang#136582 (Revert "CI: build FreeBSD artifacts on FreeBSD 13.4")
 - rust-lang#136627 (MIR validation: add comment explaining the limitations of CfgChecker)
 - rust-lang#136634 (Stabilise `Cursor::{get_mut, set_position}` in `const` scenarios.)
 - rust-lang#136643 (ping me for attribute-related changes)
 - rust-lang#136644 (Add `rustc_hir_pretty::item_to_string` function)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 7, 2025
2 parents 5ff18d0 + 0047263 commit 64e06c0
Show file tree
Hide file tree
Showing 46 changed files with 369 additions and 259 deletions.
77 changes: 7 additions & 70 deletions compiler/rustc_abi/src/callconv.rs
Original file line number Diff line number Diff line change
@@ -1,73 +1,10 @@
mod abi {
pub(crate) use crate::Primitive::*;
pub(crate) use crate::Variants;
}

#[cfg(feature = "nightly")]
use rustc_macros::HashStable_Generic;

use crate::{Align, HasDataLayout, Size};
#[cfg(feature = "nightly")]
use crate::{BackendRepr, FieldsShape, TyAbiInterface, TyAndLayout};
use crate::{Primitive, Size, Variants};

#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum RegKind {
Integer,
Float,
Vector,
}

#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct Reg {
pub kind: RegKind,
pub size: Size,
}

macro_rules! reg_ctor {
($name:ident, $kind:ident, $bits:expr) => {
pub fn $name() -> Reg {
Reg { kind: RegKind::$kind, size: Size::from_bits($bits) }
}
};
}

impl Reg {
reg_ctor!(i8, Integer, 8);
reg_ctor!(i16, Integer, 16);
reg_ctor!(i32, Integer, 32);
reg_ctor!(i64, Integer, 64);
reg_ctor!(i128, Integer, 128);

reg_ctor!(f32, Float, 32);
reg_ctor!(f64, Float, 64);
}
mod reg;

impl Reg {
pub fn align<C: HasDataLayout>(&self, cx: &C) -> Align {
let dl = cx.data_layout();
match self.kind {
RegKind::Integer => match self.size.bits() {
1 => dl.i1_align.abi,
2..=8 => dl.i8_align.abi,
9..=16 => dl.i16_align.abi,
17..=32 => dl.i32_align.abi,
33..=64 => dl.i64_align.abi,
65..=128 => dl.i128_align.abi,
_ => panic!("unsupported integer: {self:?}"),
},
RegKind::Float => match self.size.bits() {
16 => dl.f16_align.abi,
32 => dl.f32_align.abi,
64 => dl.f64_align.abi,
128 => dl.f128_align.abi,
_ => panic!("unsupported float: {self:?}"),
},
RegKind::Vector => dl.vector_align(self.size).abi,
}
}
}
pub use reg::{Reg, RegKind};

/// Return value from the `homogeneous_aggregate` test function.
#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -134,8 +71,8 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
// The primitive for this algorithm.
BackendRepr::Scalar(scalar) => {
let kind = match scalar.primitive() {
abi::Int(..) | abi::Pointer(_) => RegKind::Integer,
abi::Float(_) => RegKind::Float,
Primitive::Int(..) | Primitive::Pointer(_) => RegKind::Integer,
Primitive::Float(_) => RegKind::Float,
};
Ok(HomogeneousAggregate::Homogeneous(Reg { kind, size: self.size }))
}
Expand Down Expand Up @@ -206,8 +143,8 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
let (mut result, mut total) = from_fields_at(*self, Size::ZERO)?;

match &self.variants {
abi::Variants::Single { .. } | abi::Variants::Empty => {}
abi::Variants::Multiple { variants, .. } => {
Variants::Single { .. } | Variants::Empty => {}
Variants::Multiple { variants, .. } => {
// Treat enum variants like union members.
// HACK(eddyb) pretend the `enum` field (discriminant)
// is at the start of every variant (otherwise the gap
Expand Down
63 changes: 63 additions & 0 deletions compiler/rustc_abi/src/callconv/reg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#[cfg(feature = "nightly")]
use rustc_macros::HashStable_Generic;

use crate::{Align, HasDataLayout, Size};

#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum RegKind {
Integer,
Float,
Vector,
}

#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct Reg {
pub kind: RegKind,
pub size: Size,
}

macro_rules! reg_ctor {
($name:ident, $kind:ident, $bits:expr) => {
pub fn $name() -> Reg {
Reg { kind: RegKind::$kind, size: Size::from_bits($bits) }
}
};
}

impl Reg {
reg_ctor!(i8, Integer, 8);
reg_ctor!(i16, Integer, 16);
reg_ctor!(i32, Integer, 32);
reg_ctor!(i64, Integer, 64);
reg_ctor!(i128, Integer, 128);

reg_ctor!(f32, Float, 32);
reg_ctor!(f64, Float, 64);
}

impl Reg {
pub fn align<C: HasDataLayout>(&self, cx: &C) -> Align {
let dl = cx.data_layout();
match self.kind {
RegKind::Integer => match self.size.bits() {
1 => dl.i1_align.abi,
2..=8 => dl.i8_align.abi,
9..=16 => dl.i16_align.abi,
17..=32 => dl.i32_align.abi,
33..=64 => dl.i64_align.abi,
65..=128 => dl.i128_align.abi,
_ => panic!("unsupported integer: {self:?}"),
},
RegKind::Float => match self.size.bits() {
16 => dl.f16_align.abi,
32 => dl.f32_align.abi,
64 => dl.f64_align.abi,
128 => dl.f128_align.abi,
_ => panic!("unsupported float: {self:?}"),
},
RegKind::Vector => dl.vector_align(self.size).abi,
}
}
}
File renamed without changes.
12 changes: 8 additions & 4 deletions compiler/rustc_abi/src/layout/ty.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use std::fmt;
use std::ops::Deref;

use Float::*;
use Primitive::*;
use rustc_data_structures::intern::Interned;
use rustc_macros::HashStable_Generic;

use crate::{
AbiAndPrefAlign, Align, BackendRepr, FieldsShape, Float, HasDataLayout, LayoutData, Niche,
PointeeInfo, Primitive, Scalar, Size, TargetDataLayout, Variants,
};

// Explicitly import `Float` to avoid ambiguity with `Primitive::Float`.
use crate::{Float, *};

rustc_index::newtype_index! {
/// The *source-order* index of a field in a variant.
Expand Down Expand Up @@ -197,7 +199,9 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
C: HasDataLayout,
{
match self.backend_repr {
BackendRepr::Scalar(scalar) => matches!(scalar.primitive(), Float(F32 | F64)),
BackendRepr::Scalar(scalar) => {
matches!(scalar.primitive(), Primitive::Float(Float::F32 | Float::F64))
}
BackendRepr::Memory { .. } => {
if self.fields.count() == 1 && self.fields.offset(0).bytes() == 0 {
self.field(cx, 0).is_single_fp_element(cx)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ macro_rules! declare_features {
$(#[doc = $doc:tt])* (accepted, $feature:ident, $ver:expr, $issue:expr),
)+) => {
/// Formerly unstable features that have now been accepted (stabilized).
pub const ACCEPTED_LANG_FEATURES: &[Feature] = &[
pub static ACCEPTED_LANG_FEATURES: &[Feature] = &[
$(Feature {
name: sym::$feature,
since: $ver,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub struct BuiltinAttribute {

/// Attributes that have a special meaning to rustc or rustdoc.
#[rustfmt::skip]
pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// ==========================================================================
// Stable attributes:
// ==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ macro_rules! declare_features {
$(#[doc = $doc:tt])* (removed, $feature:ident, $ver:expr, $issue:expr, $reason:expr),
)+) => {
/// Formerly unstable features that have now been removed.
pub const REMOVED_LANG_FEATURES: &[RemovedFeature] = &[
pub static REMOVED_LANG_FEATURES: &[RemovedFeature] = &[
$(RemovedFeature {
feature: Feature {
name: sym::$feature,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ macro_rules! declare_features {
)+) => {
/// Unstable language features that are being implemented or being
/// considered for acceptance (stabilization) or removal.
pub const UNSTABLE_LANG_FEATURES: &[Feature] = &[
pub static UNSTABLE_LANG_FEATURES: &[Feature] = &[
$(Feature {
name: sym::$feature,
since: $ver,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ pub fn expr_to_string(ann: &dyn PpAnn, pat: &hir::Expr<'_>) -> String {
to_string(ann, |s| s.print_expr(pat))
}

pub fn item_to_string(ann: &dyn PpAnn, pat: &hir::Item<'_>) -> String {
to_string(ann, |s| s.print_item(pat))
}

impl<'a> State<'a> {
fn bclose_maybe_open(&mut self, span: rustc_span::Span, close_box: bool) {
self.maybe_print_comment(span.hi());
Expand Down
51 changes: 28 additions & 23 deletions compiler/rustc_mir_build/src/check_tail_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,24 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
}

{
// `#[track_caller]` affects the ABI of a function (by adding a location argument),
// so a `track_caller` can only tail call other `track_caller` functions.
//
// The issue is however that we can't know if a function is `track_caller` or not at
// this point (THIR can be polymorphic, we may have an unresolved trait function).
// We could only allow functions that we *can* resolve and *are* `track_caller`,
// but that would turn changing `track_caller`-ness into a breaking change,
// which is probably undesirable.
//
// Also note that we don't check callee's `track_caller`-ness at all, mostly for the
// reasons above, but also because we can always tailcall the shim we'd generate for
// coercing the function to an `fn()` pointer. (although in that case the tailcall is
// basically useless -- the shim calls the actual function, so tailcalling the shim is
// equivalent to calling the function)
let caller_needs_location = self.needs_location(self.caller_ty);
let callee_needs_location = self.needs_location(ty);

if caller_needs_location != callee_needs_location {
self.report_track_caller_mismatch(expr.span, caller_needs_location);
if caller_needs_location {
self.report_track_caller_caller(expr.span);
}
}

Expand All @@ -150,7 +163,9 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
}

/// Returns true if function of type `ty` needs location argument
/// (i.e. if a function is marked as `#[track_caller]`)
/// (i.e. if a function is marked as `#[track_caller]`).
///
/// Panics if the function's instance can't be immediately resolved.
fn needs_location(&self, ty: Ty<'tcx>) -> bool {
if let &ty::FnDef(did, substs) = ty.kind() {
let instance =
Expand Down Expand Up @@ -293,25 +308,15 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
self.found_errors = Err(err);
}

fn report_track_caller_mismatch(&mut self, sp: Span, caller_needs_location: bool) {
let err = match caller_needs_location {
true => self
.tcx
.dcx()
.struct_span_err(
sp,
"a function marked with `#[track_caller]` cannot tail-call one that is not",
)
.emit(),
false => self
.tcx
.dcx()
.struct_span_err(
sp,
"a function mot marked with `#[track_caller]` cannot tail-call one that is",
)
.emit(),
};
fn report_track_caller_caller(&mut self, sp: Span) {
let err = self
.tcx
.dcx()
.struct_span_err(
sp,
"a function marked with `#[track_caller]` cannot perform a tail-call",
)
.emit();

self.found_errors = Err(err);
}
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_mir_transform/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
}
}

/// This checker covers basic properties of the control-flow graph, (dis)allowed statements and terminators.
/// Everything checked here must be stable under substitution of generic parameters. In other words,
/// this is about the *structure* of the MIR, not the *contents*.
///
/// Everything that depends on types, or otherwise can be affected by generic parameters,
/// must be checked in `TypeChecker`.
struct CfgChecker<'a, 'tcx> {
when: &'a str,
body: &'a Body<'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/lexer/unicode_chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::errors::TokenSubstitution;
use crate::token::{self, Delimiter};

#[rustfmt::skip] // for line breaks
pub(super) const UNICODE_ARRAY: &[(char, &str, &str)] = &[
pub(super) static UNICODE_ARRAY: &[(char, &str, &str)] = &[
('
', "Line Separator", " "),
('
', "Paragraph Separator", " "),
(' ', "Ogham Space mark", " "),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/asm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::fmt;
use std::str::FromStr;

use rustc_abi::Size;
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
use rustc_span::Symbol;

use crate::abi::Size;
use crate::spec::{RelocModel, Target};

pub struct ModifierInfo {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_target/src/callconv/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::iter;

use rustc_abi::{BackendRepr, Primitive};
use rustc_abi::{BackendRepr, HasDataLayout, Primitive, TyAbiInterface};

use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform};
use crate::abi::{HasDataLayout, TyAbiInterface};
use crate::spec::{HasTargetSpec, Target};

/// Indicates the variant of the AArch64 ABI we are compiling for.
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_target/src/callconv/amdgpu.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustc_abi::{HasDataLayout, TyAbiInterface};

use crate::abi::call::{ArgAbi, FnAbi};
use crate::abi::{HasDataLayout, TyAbiInterface};

fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>)
where
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_target/src/callconv/arm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rustc_abi::{HasDataLayout, TyAbiInterface};

use crate::abi::call::{ArgAbi, Conv, FnAbi, Reg, RegKind, Uniform};
use crate::abi::{HasDataLayout, TyAbiInterface};
use crate::spec::HasTargetSpec;

fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) -> Option<Uniform>
Expand Down
Loading

0 comments on commit 64e06c0

Please sign in to comment.