Skip to content

Commit 9743d8a

Browse files
authored
Merge pull request #20032 from lnicola/sync-from-rust
minor: Sync from downstream
2 parents a2691cb + 0d96409 commit 9743d8a

12 files changed

Lines changed: 63 additions & 113 deletions

File tree

build_system/build_sysroot/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ resolver = "2"
66

77
[dependencies]
88
core = { path = "./sysroot_src/library/core" }
9-
compiler_builtins = "0.1"
109
alloc = { path = "./sysroot_src/library/alloc" }
1110
std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtrace"] }
1211
test = { path = "./sysroot_src/library/test" }
@@ -16,6 +15,7 @@ proc_macro = { path = "./sysroot_src/library/proc_macro" }
1615
rustc-std-workspace-core = { path = "./sysroot_src/library/rustc-std-workspace-core" }
1716
rustc-std-workspace-alloc = { path = "./sysroot_src/library/rustc-std-workspace-alloc" }
1817
rustc-std-workspace-std = { path = "./sysroot_src/library/rustc-std-workspace-std" }
18+
compiler_builtins = { path = "./sysroot_src/library/compiler-builtins/compiler-builtins" }
1919

2020
# For compiler-builtins we always use a high number of codegen units.
2121
# The goal here is to place every single intrinsic into its own object

example/arbitrary_self_types_pointers_and_wrappers.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ impl<T: DispatchFromDyn<U>, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T> {}
3737

3838

3939
trait Trait {
40-
// This method isn't object-safe yet. Unsized by-value `self` is object-safe (but not callable
41-
// without unsized_locals), but wrappers around `Self` currently are not.
42-
// FIXME (mikeyhew) uncomment this when unsized rvalues object-safety is implemented
43-
// fn wrapper(self: Wrapper<Self>) -> i32;
4440
fn ptr_wrapper(self: Ptr<Wrapper<Self>>) -> i32;
4541
fn wrapper_ptr(self: Wrapper<Ptr<Self>>) -> i32;
4642
fn wrapper_ptr_wrapper(self: Wrapper<Ptr<Wrapper<Self>>>) -> i32;

example/mini_core.rs

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ unsafe extern "C" fn _Unwind_Resume() {
1919
intrinsics::unreachable();
2020
}
2121

22+
#[lang = "pointee_sized"]
23+
pub trait PointeeSized {}
24+
25+
#[lang = "meta_sized"]
26+
pub trait MetaSized: PointeeSized {}
27+
2228
#[lang = "sized"]
23-
pub trait Sized {}
29+
pub trait Sized: MetaSized {}
2430

2531
#[lang = "destruct"]
2632
pub trait Destruct {}
@@ -29,35 +35,35 @@ pub trait Destruct {}
2935
pub trait Tuple {}
3036

3137
#[lang = "unsize"]
32-
pub trait Unsize<T: ?Sized> {}
38+
pub trait Unsize<T: PointeeSized>: PointeeSized {}
3339

3440
#[lang = "coerce_unsized"]
3541
pub trait CoerceUnsized<T> {}
3642

37-
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
38-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
39-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
40-
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
43+
impl<'a, 'b: 'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a U> for &'b T {}
44+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<&'a mut U> for &'a mut T {}
45+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*const U> for *const T {}
46+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> CoerceUnsized<*mut U> for *mut T {}
4147

4248
#[lang = "dispatch_from_dyn"]
4349
pub trait DispatchFromDyn<T> {}
4450

4551
// &T -> &U
46-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
52+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a U> for &'a T {}
4753
// &mut T -> &mut U
48-
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
54+
impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a mut U> for &'a mut T {}
4955
// *const T -> *const U
50-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
56+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*const U> for *const T {}
5157
// *mut T -> *mut U
52-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
53-
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
58+
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {}
59+
impl<T: MetaSized + Unsize<U>, U: MetaSized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
5460

5561
#[lang = "legacy_receiver"]
5662
pub trait LegacyReceiver {}
5763

58-
impl<T: ?Sized> LegacyReceiver for &T {}
59-
impl<T: ?Sized> LegacyReceiver for &mut T {}
60-
impl<T: ?Sized, A: Allocator> LegacyReceiver for Box<T, A> {}
64+
impl<T: PointeeSized> LegacyReceiver for &T {}
65+
impl<T: PointeeSized> LegacyReceiver for &mut T {}
66+
impl<T: MetaSized> LegacyReceiver for Box<T> {}
6167

6268
#[lang = "receiver"]
6369
trait Receiver {}
@@ -84,9 +90,9 @@ impl Copy for i128 {}
8490
impl Copy for f32 {}
8591
impl Copy for f64 {}
8692
impl Copy for char {}
87-
impl<'a, T: ?Sized> Copy for &'a T {}
88-
impl<T: ?Sized> Copy for *const T {}
89-
impl<T: ?Sized> Copy for *mut T {}
93+
impl<'a, T: PointeeSized> Copy for &'a T {}
94+
impl<T: PointeeSized> Copy for *const T {}
95+
impl<T: PointeeSized> Copy for *mut T {}
9096

9197
#[lang = "sync"]
9298
pub unsafe trait Sync {}
@@ -102,17 +108,17 @@ unsafe impl Sync for i16 {}
102108
unsafe impl Sync for i32 {}
103109
unsafe impl Sync for isize {}
104110
unsafe impl Sync for char {}
105-
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
111+
unsafe impl<'a, T: PointeeSized> Sync for &'a T {}
106112
unsafe impl Sync for [u8; 16] {}
107113

108114
#[lang = "freeze"]
109115
unsafe auto trait Freeze {}
110116

111-
unsafe impl<T: ?Sized> Freeze for PhantomData<T> {}
112-
unsafe impl<T: ?Sized> Freeze for *const T {}
113-
unsafe impl<T: ?Sized> Freeze for *mut T {}
114-
unsafe impl<T: ?Sized> Freeze for &T {}
115-
unsafe impl<T: ?Sized> Freeze for &mut T {}
117+
unsafe impl<T: PointeeSized> Freeze for PhantomData<T> {}
118+
unsafe impl<T: PointeeSized> Freeze for *const T {}
119+
unsafe impl<T: PointeeSized> Freeze for *mut T {}
120+
unsafe impl<T: PointeeSized> Freeze for &T {}
121+
unsafe impl<T: PointeeSized> Freeze for &mut T {}
116122

117123
#[lang = "structural_peq"]
118124
pub trait StructuralPartialEq {}
@@ -456,7 +462,7 @@ pub enum Option<T> {
456462
pub use Option::*;
457463

458464
#[lang = "phantom_data"]
459-
pub struct PhantomData<T: ?Sized>;
465+
pub struct PhantomData<T: PointeeSized>;
460466

461467
#[lang = "fn_once"]
462468
#[rustc_paren_sugar]
@@ -576,18 +582,18 @@ impl Allocator for Global {}
576582
#[repr(transparent)]
577583
#[rustc_layout_scalar_valid_range_start(1)]
578584
#[rustc_nonnull_optimization_guaranteed]
579-
pub struct NonNull<T: ?Sized>(pub *const T);
585+
pub struct NonNull<T: PointeeSized>(pub *const T);
580586

581-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
582-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
587+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
588+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
583589

584-
pub struct Unique<T: ?Sized> {
590+
pub struct Unique<T: PointeeSized> {
585591
pub pointer: NonNull<T>,
586592
pub _marker: PhantomData<T>,
587593
}
588594

589-
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
590-
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
595+
impl<T: PointeeSized, U: PointeeSized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
596+
impl<T: PointeeSized, U: PointeeSized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
591597

592598
#[lang = "owned_box"]
593599
pub struct Box<T: ?Sized, A: Allocator = Global>(Unique<T>, A);
@@ -655,9 +661,9 @@ pub mod intrinsics {
655661
#[rustc_intrinsic]
656662
pub unsafe fn size_of_val<T: ?::Sized>(val: *const T) -> usize;
657663
#[rustc_intrinsic]
658-
pub fn min_align_of<T>() -> usize;
664+
pub fn align_of<T>() -> usize;
659665
#[rustc_intrinsic]
660-
pub unsafe fn min_align_of_val<T: ?::Sized>(val: *const T) -> usize;
666+
pub unsafe fn align_of_val<T: ?::Sized>(val: *const T) -> usize;
661667
#[rustc_intrinsic]
662668
pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
663669
#[rustc_intrinsic]

example/mini_core_hello_world.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn main() {
153153
let slice = &[0, 1] as &[i32];
154154
let slice_ptr = slice as *const [i32] as *const i32;
155155

156-
let align = intrinsics::min_align_of::<*const i32>();
156+
let align = intrinsics::align_of::<*const i32>();
157157
assert_eq!(slice_ptr as usize % align, 0);
158158

159159
//return;
@@ -194,8 +194,8 @@ fn main() {
194194
assert_eq!(intrinsics::size_of_val(a) as u8, 8);
195195
assert_eq!(intrinsics::size_of_val(&0u32) as u8, 4);
196196

197-
assert_eq!(intrinsics::min_align_of::<u16>() as u8, 2);
198-
assert_eq!(intrinsics::min_align_of_val(&a) as u8, intrinsics::min_align_of::<&str>() as u8);
197+
assert_eq!(intrinsics::align_of::<u16>() as u8, 2);
198+
assert_eq!(intrinsics::align_of_val(&a) as u8, intrinsics::align_of::<&str>() as u8);
199199

200200
assert!(!intrinsics::needs_drop::<u8>());
201201
assert!(!intrinsics::needs_drop::<[u8]>());

messages.ftl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ codegen_gcc_unknown_ctarget_feature_prefix =
22
unknown feature specified for `-Ctarget-feature`: `{$feature}`
33
.note = features must begin with a `+` to enable or `-` to disable it
44
5-
codegen_gcc_forbidden_ctarget_feature =
6-
target feature `{$feature}` cannot be toggled with `-Ctarget-feature`: {$reason}
7-
85
codegen_gcc_unwinding_inline_asm =
96
GCC backend does not support unwinding from inline asm
107
@@ -26,10 +23,6 @@ codegen_gcc_unknown_ctarget_feature =
2623
.possible_feature = you might have meant: `{$rust_feature}`
2724
.consider_filing_feature_request = consider filing a feature request
2825
29-
codegen_gcc_unstable_ctarget_feature =
30-
unstable feature specified for `-Ctarget-feature`: `{$feature}`
31-
.note = this feature is not stably supported; its behavior can change in the future
32-
3326
codegen_gcc_missing_features =
3427
add the missing features in a `target_feature` attribute
3528

src/abi.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,16 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
239239
pub fn conv_to_fn_attribute<'gcc>(conv: CanonAbi, arch: &str) -> Option<FnAttribute<'gcc>> {
240240
let attribute = match conv {
241241
CanonAbi::C | CanonAbi::Rust => return None,
242+
CanonAbi::RustCold => FnAttribute::Cold,
243+
// Functions with this calling convention can only be called from assembly, but it is
244+
// possible to declare an `extern "custom"` block, so the backend still needs a calling
245+
// convention for declaring foreign functions.
246+
CanonAbi::Custom => return None,
242247
CanonAbi::Arm(arm_call) => match arm_call {
243248
ArmCall::CCmseNonSecureCall => FnAttribute::ArmCmseNonsecureCall,
244249
ArmCall::CCmseNonSecureEntry => FnAttribute::ArmCmseNonsecureEntry,
245250
ArmCall::Aapcs => FnAttribute::ArmPcs("aapcs"),
246251
},
247-
CanonAbi::RustCold => FnAttribute::Cold,
248252
CanonAbi::GpuKernel => {
249253
if arch == "amdgpu" {
250254
FnAttribute::GcnAmdGpuHsaKernel

src/builder.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_middle::ty::{self, AtomicOrdering, Instance, Ty, TyCtxt};
3030
use rustc_span::Span;
3131
use rustc_span::def_id::DefId;
3232
use rustc_target::callconv::FnAbi;
33-
use rustc_target::spec::{HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, Target, WasmCAbi, X86Abi};
33+
use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, X86Abi};
3434

3535
use crate::common::{SignType, TypeReflection, type_is_pointer};
3636
use crate::context::CodegenCx;
@@ -897,7 +897,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
897897
fn checked_binop(
898898
&mut self,
899899
oop: OverflowOp,
900-
typ: Ty<'_>,
900+
typ: Ty<'tcx>,
901901
lhs: Self::Value,
902902
rhs: Self::Value,
903903
) -> (Self::Value, Self::Value) {
@@ -2394,12 +2394,6 @@ impl<'tcx> HasTargetSpec for Builder<'_, '_, 'tcx> {
23942394
}
23952395
}
23962396

2397-
impl<'tcx> HasWasmCAbiOpt for Builder<'_, '_, 'tcx> {
2398-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
2399-
self.cx.wasm_c_abi_opt()
2400-
}
2401-
}
2402-
24032397
impl<'tcx> HasX86AbiOpt for Builder<'_, '_, 'tcx> {
24042398
fn x86_abi_opt(&self) -> X86Abi {
24052399
self.cx.x86_abi_opt()

src/context.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use rustc_middle::ty::{self, ExistentialTraitRef, Instance, Ty, TyCtxt};
1919
use rustc_session::Session;
2020
use rustc_span::source_map::respan;
2121
use rustc_span::{DUMMY_SP, Span};
22-
use rustc_target::spec::{
23-
HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, Target, TlsModel, WasmCAbi, X86Abi,
24-
};
22+
use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, TlsModel, X86Abi};
2523

2624
#[cfg(feature = "master")]
2725
use crate::abi::conv_to_fn_attribute;
@@ -512,12 +510,6 @@ impl<'gcc, 'tcx> HasTargetSpec for CodegenCx<'gcc, 'tcx> {
512510
}
513511
}
514512

515-
impl<'gcc, 'tcx> HasWasmCAbiOpt for CodegenCx<'gcc, 'tcx> {
516-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
517-
self.tcx.sess.opts.unstable_opts.wasm_c_abi
518-
}
519-
}
520-
521513
impl<'gcc, 'tcx> HasX86AbiOpt for CodegenCx<'gcc, 'tcx> {
522514
fn x86_abi_opt(&self) -> X86Abi {
523515
X86Abi {

src/errors.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,6 @@ pub(crate) struct UnknownCTargetFeature<'a> {
1717
pub rust_feature: PossibleFeature<'a>,
1818
}
1919

20-
#[derive(Diagnostic)]
21-
#[diag(codegen_gcc_unstable_ctarget_feature)]
22-
#[note]
23-
pub(crate) struct UnstableCTargetFeature<'a> {
24-
pub feature: &'a str,
25-
}
26-
27-
#[derive(Diagnostic)]
28-
#[diag(codegen_gcc_forbidden_ctarget_feature)]
29-
pub(crate) struct ForbiddenCTargetFeature<'a> {
30-
pub feature: &'a str,
31-
pub enabled: &'a str,
32-
pub reason: &'a str,
33-
}
34-
3520
#[derive(Subdiagnostic)]
3621
pub(crate) enum PossibleFeature<'a> {
3722
#[help(codegen_gcc_possible_feature)]

src/gcc_util.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ use rustc_codegen_ssa::errors::TargetFeatureDisableOrEnable;
55
use rustc_data_structures::fx::FxHashMap;
66
use rustc_data_structures::unord::UnordSet;
77
use rustc_session::Session;
8+
use rustc_session::features::{StabilityExt, retpoline_features_by_flags};
89
use rustc_target::target_features::RUSTC_SPECIFIC_FEATURES;
910
use smallvec::{SmallVec, smallvec};
1011

11-
use crate::errors::{
12-
ForbiddenCTargetFeature, PossibleFeature, UnknownCTargetFeature, UnknownCTargetFeaturePrefix,
13-
UnstableCTargetFeature,
14-
};
12+
use crate::errors::{PossibleFeature, UnknownCTargetFeature, UnknownCTargetFeaturePrefix};
13+
14+
fn gcc_features_by_flags(sess: &Session) -> Vec<&str> {
15+
let mut features: Vec<&str> = Vec::new();
16+
retpoline_features_by_flags(sess, &mut features);
17+
features
18+
}
1519

1620
/// The list of GCC features computed from CLI flags (`-Ctarget-cpu`, `-Ctarget-feature`,
1721
/// `--target` and similar).
@@ -45,7 +49,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
4549

4650
// Compute implied features
4751
let mut all_rust_features = vec![];
48-
for feature in sess.opts.cg.target_feature.split(',') {
52+
for feature in sess.opts.cg.target_feature.split(',').chain(gcc_features_by_flags(sess)) {
4953
if let Some(feature) = feature.strip_prefix('+') {
5054
all_rust_features.extend(
5155
UnordSet::from(sess.target.implied_target_features(feature))
@@ -94,18 +98,7 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
9498
sess.dcx().emit_warn(unknown_feature);
9599
}
96100
Some(&(_, stability, _)) => {
97-
if let Err(reason) = stability.toggle_allowed() {
98-
sess.dcx().emit_warn(ForbiddenCTargetFeature {
99-
feature,
100-
enabled: if enable { "enabled" } else { "disabled" },
101-
reason,
102-
});
103-
} else if stability.requires_nightly().is_some() {
104-
// An unstable feature. Warn about using it. (It makes little sense
105-
// to hard-error here since we just warn about fully unknown
106-
// features above).
107-
sess.dcx().emit_warn(UnstableCTargetFeature { feature });
108-
}
101+
stability.verify_feature_enabled_by_flag(sess, enable, feature);
109102
}
110103
}
111104

0 commit comments

Comments
 (0)