Skip to content

Commit 64e06c0

Browse files
committed
Auto merge of rust-lang#136684 - matthiaskrgr:rollup-mlpzre5, r=matthiaskrgr
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
2 parents 5ff18d0 + 0047263 commit 64e06c0

Some content is hidden

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

46 files changed

+369
-259
lines changed

compiler/rustc_abi/src/callconv.rs

+7-70
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,10 @@
1-
mod abi {
2-
pub(crate) use crate::Primitive::*;
3-
pub(crate) use crate::Variants;
4-
}
5-
6-
#[cfg(feature = "nightly")]
7-
use rustc_macros::HashStable_Generic;
8-
9-
use crate::{Align, HasDataLayout, Size};
101
#[cfg(feature = "nightly")]
112
use crate::{BackendRepr, FieldsShape, TyAbiInterface, TyAndLayout};
3+
use crate::{Primitive, Size, Variants};
124

13-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
14-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
15-
pub enum RegKind {
16-
Integer,
17-
Float,
18-
Vector,
19-
}
20-
21-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
22-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
23-
pub struct Reg {
24-
pub kind: RegKind,
25-
pub size: Size,
26-
}
27-
28-
macro_rules! reg_ctor {
29-
($name:ident, $kind:ident, $bits:expr) => {
30-
pub fn $name() -> Reg {
31-
Reg { kind: RegKind::$kind, size: Size::from_bits($bits) }
32-
}
33-
};
34-
}
35-
36-
impl Reg {
37-
reg_ctor!(i8, Integer, 8);
38-
reg_ctor!(i16, Integer, 16);
39-
reg_ctor!(i32, Integer, 32);
40-
reg_ctor!(i64, Integer, 64);
41-
reg_ctor!(i128, Integer, 128);
42-
43-
reg_ctor!(f32, Float, 32);
44-
reg_ctor!(f64, Float, 64);
45-
}
5+
mod reg;
466

47-
impl Reg {
48-
pub fn align<C: HasDataLayout>(&self, cx: &C) -> Align {
49-
let dl = cx.data_layout();
50-
match self.kind {
51-
RegKind::Integer => match self.size.bits() {
52-
1 => dl.i1_align.abi,
53-
2..=8 => dl.i8_align.abi,
54-
9..=16 => dl.i16_align.abi,
55-
17..=32 => dl.i32_align.abi,
56-
33..=64 => dl.i64_align.abi,
57-
65..=128 => dl.i128_align.abi,
58-
_ => panic!("unsupported integer: {self:?}"),
59-
},
60-
RegKind::Float => match self.size.bits() {
61-
16 => dl.f16_align.abi,
62-
32 => dl.f32_align.abi,
63-
64 => dl.f64_align.abi,
64-
128 => dl.f128_align.abi,
65-
_ => panic!("unsupported float: {self:?}"),
66-
},
67-
RegKind::Vector => dl.vector_align(self.size).abi,
68-
}
69-
}
70-
}
7+
pub use reg::{Reg, RegKind};
718

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

208145
match &self.variants {
209-
abi::Variants::Single { .. } | abi::Variants::Empty => {}
210-
abi::Variants::Multiple { variants, .. } => {
146+
Variants::Single { .. } | Variants::Empty => {}
147+
Variants::Multiple { variants, .. } => {
211148
// Treat enum variants like union members.
212149
// HACK(eddyb) pretend the `enum` field (discriminant)
213150
// is at the start of every variant (otherwise the gap
+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#[cfg(feature = "nightly")]
2+
use rustc_macros::HashStable_Generic;
3+
4+
use crate::{Align, HasDataLayout, Size};
5+
6+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
7+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
8+
pub enum RegKind {
9+
Integer,
10+
Float,
11+
Vector,
12+
}
13+
14+
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
15+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
16+
pub struct Reg {
17+
pub kind: RegKind,
18+
pub size: Size,
19+
}
20+
21+
macro_rules! reg_ctor {
22+
($name:ident, $kind:ident, $bits:expr) => {
23+
pub fn $name() -> Reg {
24+
Reg { kind: RegKind::$kind, size: Size::from_bits($bits) }
25+
}
26+
};
27+
}
28+
29+
impl Reg {
30+
reg_ctor!(i8, Integer, 8);
31+
reg_ctor!(i16, Integer, 16);
32+
reg_ctor!(i32, Integer, 32);
33+
reg_ctor!(i64, Integer, 64);
34+
reg_ctor!(i128, Integer, 128);
35+
36+
reg_ctor!(f32, Float, 32);
37+
reg_ctor!(f64, Float, 64);
38+
}
39+
40+
impl Reg {
41+
pub fn align<C: HasDataLayout>(&self, cx: &C) -> Align {
42+
let dl = cx.data_layout();
43+
match self.kind {
44+
RegKind::Integer => match self.size.bits() {
45+
1 => dl.i1_align.abi,
46+
2..=8 => dl.i8_align.abi,
47+
9..=16 => dl.i16_align.abi,
48+
17..=32 => dl.i32_align.abi,
49+
33..=64 => dl.i64_align.abi,
50+
65..=128 => dl.i128_align.abi,
51+
_ => panic!("unsupported integer: {self:?}"),
52+
},
53+
RegKind::Float => match self.size.bits() {
54+
16 => dl.f16_align.abi,
55+
32 => dl.f32_align.abi,
56+
64 => dl.f64_align.abi,
57+
128 => dl.f128_align.abi,
58+
_ => panic!("unsupported float: {self:?}"),
59+
},
60+
RegKind::Vector => dl.vector_align(self.size).abi,
61+
}
62+
}
63+
}
File renamed without changes.

compiler/rustc_abi/src/layout/ty.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use std::fmt;
22
use std::ops::Deref;
33

4-
use Float::*;
5-
use Primitive::*;
64
use rustc_data_structures::intern::Interned;
75
use rustc_macros::HashStable_Generic;
86

7+
use crate::{
8+
AbiAndPrefAlign, Align, BackendRepr, FieldsShape, Float, HasDataLayout, LayoutData, Niche,
9+
PointeeInfo, Primitive, Scalar, Size, TargetDataLayout, Variants,
10+
};
11+
912
// Explicitly import `Float` to avoid ambiguity with `Primitive::Float`.
10-
use crate::{Float, *};
1113

1214
rustc_index::newtype_index! {
1315
/// The *source-order* index of a field in a variant.
@@ -197,7 +199,9 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
197199
C: HasDataLayout,
198200
{
199201
match self.backend_repr {
200-
BackendRepr::Scalar(scalar) => matches!(scalar.primitive(), Float(F32 | F64)),
202+
BackendRepr::Scalar(scalar) => {
203+
matches!(scalar.primitive(), Primitive::Float(Float::F32 | Float::F64))
204+
}
201205
BackendRepr::Memory { .. } => {
202206
if self.fields.count() == 1 && self.fields.offset(0).bytes() == 0 {
203207
self.field(cx, 0).is_single_fp_element(cx)

compiler/rustc_feature/src/accepted.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ macro_rules! declare_features {
99
$(#[doc = $doc:tt])* (accepted, $feature:ident, $ver:expr, $issue:expr),
1010
)+) => {
1111
/// Formerly unstable features that have now been accepted (stabilized).
12-
pub const ACCEPTED_LANG_FEATURES: &[Feature] = &[
12+
pub static ACCEPTED_LANG_FEATURES: &[Feature] = &[
1313
$(Feature {
1414
name: sym::$feature,
1515
since: $ver,

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ pub struct BuiltinAttribute {
318318

319319
/// Attributes that have a special meaning to rustc or rustdoc.
320320
#[rustfmt::skip]
321-
pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
321+
pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
322322
// ==========================================================================
323323
// Stable attributes:
324324
// ==========================================================================

compiler/rustc_feature/src/removed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ macro_rules! declare_features {
1414
$(#[doc = $doc:tt])* (removed, $feature:ident, $ver:expr, $issue:expr, $reason:expr),
1515
)+) => {
1616
/// Formerly unstable features that have now been removed.
17-
pub const REMOVED_LANG_FEATURES: &[RemovedFeature] = &[
17+
pub static REMOVED_LANG_FEATURES: &[RemovedFeature] = &[
1818
$(RemovedFeature {
1919
feature: Feature {
2020
name: sym::$feature,

compiler/rustc_feature/src/unstable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ macro_rules! declare_features {
104104
)+) => {
105105
/// Unstable language features that are being implemented or being
106106
/// considered for acceptance (stabilization) or removal.
107-
pub const UNSTABLE_LANG_FEATURES: &[Feature] = &[
107+
pub static UNSTABLE_LANG_FEATURES: &[Feature] = &[
108108
$(Feature {
109109
name: sym::$feature,
110110
since: $ver,

compiler/rustc_hir_pretty/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ pub fn expr_to_string(ann: &dyn PpAnn, pat: &hir::Expr<'_>) -> String {
325325
to_string(ann, |s| s.print_expr(pat))
326326
}
327327

328+
pub fn item_to_string(ann: &dyn PpAnn, pat: &hir::Item<'_>) -> String {
329+
to_string(ann, |s| s.print_item(pat))
330+
}
331+
328332
impl<'a> State<'a> {
329333
fn bclose_maybe_open(&mut self, span: rustc_span::Span, close_box: bool) {
330334
self.maybe_print_comment(span.hi());

compiler/rustc_mir_build/src/check_tail_calls.rs

+28-23
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,24 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
132132
}
133133

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

138-
if caller_needs_location != callee_needs_location {
139-
self.report_track_caller_mismatch(expr.span, caller_needs_location);
151+
if caller_needs_location {
152+
self.report_track_caller_caller(expr.span);
140153
}
141154
}
142155

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

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

296-
fn report_track_caller_mismatch(&mut self, sp: Span, caller_needs_location: bool) {
297-
let err = match caller_needs_location {
298-
true => self
299-
.tcx
300-
.dcx()
301-
.struct_span_err(
302-
sp,
303-
"a function marked with `#[track_caller]` cannot tail-call one that is not",
304-
)
305-
.emit(),
306-
false => self
307-
.tcx
308-
.dcx()
309-
.struct_span_err(
310-
sp,
311-
"a function mot marked with `#[track_caller]` cannot tail-call one that is",
312-
)
313-
.emit(),
314-
};
311+
fn report_track_caller_caller(&mut self, sp: Span) {
312+
let err = self
313+
.tcx
314+
.dcx()
315+
.struct_span_err(
316+
sp,
317+
"a function marked with `#[track_caller]` cannot perform a tail-call",
318+
)
319+
.emit();
315320

316321
self.found_errors = Err(err);
317322
}

compiler/rustc_mir_transform/src/validate.rs

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ impl<'tcx> crate::MirPass<'tcx> for Validator {
9797
}
9898
}
9999

100+
/// This checker covers basic properties of the control-flow graph, (dis)allowed statements and terminators.
101+
/// Everything checked here must be stable under substitution of generic parameters. In other words,
102+
/// this is about the *structure* of the MIR, not the *contents*.
103+
///
104+
/// Everything that depends on types, or otherwise can be affected by generic parameters,
105+
/// must be checked in `TypeChecker`.
100106
struct CfgChecker<'a, 'tcx> {
101107
when: &'a str,
102108
body: &'a Body<'tcx>,

compiler/rustc_parse/src/lexer/unicode_chars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::errors::TokenSubstitution;
88
use crate::token::{self, Delimiter};
99

1010
#[rustfmt::skip] // for line breaks
11-
pub(super) const UNICODE_ARRAY: &[(char, &str, &str)] = &[
11+
pub(super) static UNICODE_ARRAY: &[(char, &str, &str)] = &[
1212
('
', "Line Separator", " "),
1313
('
', "Paragraph Separator", " "),
1414
(' ', "Ogham Space mark", " "),

compiler/rustc_target/src/asm/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::fmt;
22
use std::str::FromStr;
33

4+
use rustc_abi::Size;
45
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
56
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
67
use rustc_span::Symbol;
78

8-
use crate::abi::Size;
99
use crate::spec::{RelocModel, Target};
1010

1111
pub struct ModifierInfo {

compiler/rustc_target/src/callconv/aarch64.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::iter;
22

3-
use rustc_abi::{BackendRepr, Primitive};
3+
use rustc_abi::{BackendRepr, HasDataLayout, Primitive, TyAbiInterface};
44

55
use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind, Uniform};
6-
use crate::abi::{HasDataLayout, TyAbiInterface};
76
use crate::spec::{HasTargetSpec, Target};
87

98
/// Indicates the variant of the AArch64 ABI we are compiling for.

compiler/rustc_target/src/callconv/amdgpu.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use rustc_abi::{HasDataLayout, TyAbiInterface};
2+
13
use crate::abi::call::{ArgAbi, FnAbi};
2-
use crate::abi::{HasDataLayout, TyAbiInterface};
34

45
fn classify_ret<'a, Ty, C>(_cx: &C, ret: &mut ArgAbi<'a, Ty>)
56
where

compiler/rustc_target/src/callconv/arm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use rustc_abi::{HasDataLayout, TyAbiInterface};
2+
13
use crate::abi::call::{ArgAbi, Conv, FnAbi, Reg, RegKind, Uniform};
2-
use crate::abi::{HasDataLayout, TyAbiInterface};
34
use crate::spec::HasTargetSpec;
45

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

0 commit comments

Comments
 (0)