Skip to content

Commit 2933f68

Browse files
committed
Auto merge of #130816 - matthiaskrgr:rollup-jy25phv, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #130549 (Add RISC-V vxworks targets) - #130595 (Initial std library support for NuttX) - #130734 (Fix: ices on virtual-function-elimination about principal trait) - #130787 (Ban combination of GCE and new solver) - #130809 (Update llvm triple for OpenHarmony targets) - #130810 (Don't trap into the debugger on panics under Linux) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4c62024 + 9d134cc commit 2933f68

Some content is hidden

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

50 files changed

+420
-175
lines changed

Diff for: compiler/rustc_ast_passes/src/feature_gate.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use rustc_ast::{NodeId, PatKind, attr, token};
44
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP, BuiltinAttribute, Features, GateIssue};
55
use rustc_session::Session;
66
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
7-
use rustc_span::Span;
87
use rustc_span::source_map::Spanned;
98
use rustc_span::symbol::sym;
9+
use rustc_span::{Span, Symbol};
1010
use rustc_target::spec::abi;
1111
use thin_vec::ThinVec;
1212

@@ -483,6 +483,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
483483
pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
484484
maybe_stage_features(sess, features, krate);
485485
check_incompatible_features(sess, features);
486+
check_new_solver_banned_features(sess, features);
487+
486488
let mut visitor = PostExpansionVisitor { sess, features };
487489

488490
let spans = sess.psess.gated_spans.spans.borrow();
@@ -662,3 +664,22 @@ fn check_incompatible_features(sess: &Session, features: &Features) {
662664
}
663665
}
664666
}
667+
668+
fn check_new_solver_banned_features(sess: &Session, features: &Features) {
669+
if !sess.opts.unstable_opts.next_solver.is_some_and(|n| n.globally) {
670+
return;
671+
}
672+
673+
// Ban GCE with the new solver, because it does not implement GCE correctly.
674+
if let Some(&(_, gce_span, _)) = features
675+
.declared_lang_features
676+
.iter()
677+
.find(|&&(feat, _, _)| feat == sym::generic_const_exprs)
678+
{
679+
sess.dcx().emit_err(errors::IncompatibleFeatures {
680+
spans: vec![gce_span],
681+
f1: Symbol::intern("-Znext-solver=globally"),
682+
f2: sym::generic_const_exprs,
683+
});
684+
}
685+
}

Diff for: compiler/rustc_codegen_ssa/src/base.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use crate::back::write::{
3737
submit_codegened_module_to_llvm, submit_post_lto_module_to_llvm, submit_pre_lto_module_to_llvm,
3838
};
3939
use crate::common::{self, IntPredicate, RealPredicate, TypeKind};
40+
use crate::meth::load_vtable;
4041
use crate::mir::operand::OperandValue;
4142
use crate::mir::place::PlaceRef;
4243
use crate::traits::*;
@@ -135,14 +136,8 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
135136

136137
if let Some(entry_idx) = vptr_entry_idx {
137138
let ptr_size = bx.data_layout().pointer_size;
138-
let ptr_align = bx.data_layout().pointer_align.abi;
139139
let vtable_byte_offset = u64::try_from(entry_idx).unwrap() * ptr_size.bytes();
140-
let gep = bx.inbounds_ptradd(old_info, bx.const_usize(vtable_byte_offset));
141-
let new_vptr = bx.load(bx.type_ptr(), gep, ptr_align);
142-
bx.nonnull_metadata(new_vptr);
143-
// VTable loads are invariant.
144-
bx.set_invariant_load(new_vptr);
145-
new_vptr
140+
load_vtable(bx, old_info, bx.type_ptr(), vtable_byte_offset, source, true)
146141
} else {
147142
old_info
148143
}

Diff for: compiler/rustc_codegen_ssa/src/meth.rs

+39-28
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,9 @@ impl<'a, 'tcx> VirtualIndex {
2828

2929
let llty = bx.fn_ptr_backend_type(fn_abi);
3030
let ptr_size = bx.data_layout().pointer_size;
31-
let ptr_align = bx.data_layout().pointer_align.abi;
3231
let vtable_byte_offset = self.0 * ptr_size.bytes();
3332

34-
if bx.cx().sess().opts.unstable_opts.virtual_function_elimination
35-
&& bx.cx().sess().lto() == Lto::Fat
36-
{
37-
let typeid = bx
38-
.typeid_metadata(typeid_for_trait_ref(bx.tcx(), expect_dyn_trait_in_self(ty)))
39-
.unwrap();
40-
let func = bx.type_checked_load(llvtable, vtable_byte_offset, typeid);
41-
func
42-
} else {
43-
let gep = bx.inbounds_ptradd(llvtable, bx.const_usize(vtable_byte_offset));
44-
let ptr = bx.load(llty, gep, ptr_align);
45-
// VTable loads are invariant.
46-
bx.set_invariant_load(ptr);
47-
if nonnull {
48-
bx.nonnull_metadata(ptr);
49-
}
50-
ptr
51-
}
33+
load_vtable(bx, llvtable, llty, vtable_byte_offset, ty, nonnull)
5234
}
5335

5436
pub(crate) fn get_optional_fn<Bx: BuilderMethods<'a, 'tcx>>(
@@ -75,31 +57,27 @@ impl<'a, 'tcx> VirtualIndex {
7557
self,
7658
bx: &mut Bx,
7759
llvtable: Bx::Value,
60+
ty: Ty<'tcx>,
7861
) -> Bx::Value {
7962
// Load the data pointer from the object.
8063
debug!("get_int({:?}, {:?})", llvtable, self);
8164

8265
let llty = bx.type_isize();
8366
let ptr_size = bx.data_layout().pointer_size;
84-
let ptr_align = bx.data_layout().pointer_align.abi;
8567
let vtable_byte_offset = self.0 * ptr_size.bytes();
8668

87-
let gep = bx.inbounds_ptradd(llvtable, bx.const_usize(vtable_byte_offset));
88-
let ptr = bx.load(llty, gep, ptr_align);
89-
// VTable loads are invariant.
90-
bx.set_invariant_load(ptr);
91-
ptr
69+
load_vtable(bx, llvtable, llty, vtable_byte_offset, ty, false)
9270
}
9371
}
9472

9573
/// This takes a valid `self` receiver type and extracts the principal trait
96-
/// ref of the type.
97-
fn expect_dyn_trait_in_self(ty: Ty<'_>) -> ty::PolyExistentialTraitRef<'_> {
74+
/// ref of the type. Return `None` if there is no principal trait.
75+
fn dyn_trait_in_self(ty: Ty<'_>) -> Option<ty::PolyExistentialTraitRef<'_>> {
9876
for arg in ty.peel_refs().walk() {
9977
if let GenericArgKind::Type(ty) = arg.unpack()
10078
&& let ty::Dynamic(data, _, _) = ty.kind()
10179
{
102-
return data.principal().expect("expected principal trait object");
80+
return data.principal();
10381
}
10482
}
10583

@@ -138,3 +116,36 @@ pub(crate) fn get_vtable<'tcx, Cx: CodegenMethods<'tcx>>(
138116
cx.vtables().borrow_mut().insert((ty, trait_ref), vtable);
139117
vtable
140118
}
119+
120+
/// Call this function whenever you need to load a vtable.
121+
pub(crate) fn load_vtable<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
122+
bx: &mut Bx,
123+
llvtable: Bx::Value,
124+
llty: Bx::Type,
125+
vtable_byte_offset: u64,
126+
ty: Ty<'tcx>,
127+
nonnull: bool,
128+
) -> Bx::Value {
129+
let ptr_align = bx.data_layout().pointer_align.abi;
130+
131+
if bx.cx().sess().opts.unstable_opts.virtual_function_elimination
132+
&& bx.cx().sess().lto() == Lto::Fat
133+
{
134+
if let Some(trait_ref) = dyn_trait_in_self(ty) {
135+
let typeid = bx.typeid_metadata(typeid_for_trait_ref(bx.tcx(), trait_ref)).unwrap();
136+
let func = bx.type_checked_load(llvtable, vtable_byte_offset, typeid);
137+
return func;
138+
} else if nonnull {
139+
bug!("load nonnull value from a vtable without a principal trait")
140+
}
141+
}
142+
143+
let gep = bx.inbounds_ptradd(llvtable, bx.const_usize(vtable_byte_offset));
144+
let ptr = bx.load(llty, gep, ptr_align);
145+
// VTable loads are invariant.
146+
bx.set_invariant_load(ptr);
147+
if nonnull {
148+
bx.nonnull_metadata(ptr);
149+
}
150+
ptr
151+
}

Diff for: compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
126126
sym::vtable_align => ty::COMMON_VTABLE_ENTRIES_ALIGN,
127127
_ => bug!(),
128128
};
129-
let value = meth::VirtualIndex::from_index(idx).get_usize(bx, vtable);
129+
let value = meth::VirtualIndex::from_index(idx).get_usize(bx, vtable, callee_ty);
130130
match name {
131131
// Size is always <= isize::MAX.
132132
sym::vtable_size => {

Diff for: compiler/rustc_codegen_ssa/src/size_of_val.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
2828
// Load size/align from vtable.
2929
let vtable = info.unwrap();
3030
let size = meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_SIZE)
31-
.get_usize(bx, vtable);
31+
.get_usize(bx, vtable, t);
3232
let align = meth::VirtualIndex::from_index(ty::COMMON_VTABLE_ENTRIES_ALIGN)
33-
.get_usize(bx, vtable);
33+
.get_usize(bx, vtable, t);
3434

3535
// Size is always <= isize::MAX.
3636
let size_bound = bx.data_layout().ptr_sized_integer().signed_max() as u128;

Diff for: compiler/rustc_target/src/spec/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,8 @@ supported_targets! {
18401840
("powerpc-wrs-vxworks", powerpc_wrs_vxworks),
18411841
("powerpc-wrs-vxworks-spe", powerpc_wrs_vxworks_spe),
18421842
("powerpc64-wrs-vxworks", powerpc64_wrs_vxworks),
1843+
("riscv32-wrs-vxworks", riscv32_wrs_vxworks),
1844+
("riscv64-wrs-vxworks", riscv64_wrs_vxworks),
18431845

18441846
("aarch64-kmc-solid_asp3", aarch64_kmc_solid_asp3),
18451847
("armv7a-kmc-solid_asp3-eabi", armv7a_kmc_solid_asp3_eabi),

Diff for: compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_ohos.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ pub(crate) fn target() -> Target {
55
base.max_atomic_width = Some(128);
66

77
Target {
8-
// LLVM 15 doesn't support OpenHarmony yet, use a linux target instead.
9-
llvm_target: "aarch64-unknown-linux-musl".into(),
8+
llvm_target: "aarch64-unknown-linux-ohos".into(),
109
metadata: crate::spec::TargetMetadata {
1110
description: Some("ARM64 OpenHarmony".into()),
1211
tier: Some(2),

Diff for: compiler/rustc_target/src/spec/targets/aarch64_wrs_vxworks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) fn target() -> Target {
77
description: None,
88
tier: Some(3),
99
host_tools: Some(false),
10-
std: None, // ?
10+
std: Some(true),
1111
},
1212
pointer_width: 64,
1313
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),

Diff for: compiler/rustc_target/src/spec/targets/armv7_unknown_linux_ohos.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ pub(crate) fn target() -> Target {
77
// Most of these settings are copied from the armv7_unknown_linux_musleabi
88
// target.
99
Target {
10-
// LLVM 15 doesn't support OpenHarmony yet, use a linux target instead.
11-
llvm_target: "armv7-unknown-linux-gnueabi".into(),
10+
llvm_target: "armv7-unknown-linux-ohos".into(),
1211
metadata: crate::spec::TargetMetadata {
1312
description: Some("Armv7-A OpenHarmony".into()),
1413
tier: Some(2),

Diff for: compiler/rustc_target/src/spec/targets/i686_wrs_vxworks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn target() -> Target {
1313
description: None,
1414
tier: Some(3),
1515
host_tools: Some(false),
16-
std: None, // ?
16+
std: Some(true),
1717
},
1818
pointer_width: 32,
1919
data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\

Diff for: compiler/rustc_target/src/spec/targets/loongarch64_unknown_linux_ohos.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use crate::spec::{Target, TargetOptions, base};
22

33
pub(crate) fn target() -> Target {
44
Target {
5-
// LLVM 15 doesn't support OpenHarmony yet, use a linux target instead.
6-
llvm_target: "loongarch64-unknown-linux-musl".into(),
5+
llvm_target: "loongarch64-unknown-linux-ohos".into(),
76
metadata: crate::spec::TargetMetadata {
87
description: Some("LoongArch64 OpenHarmony".into()),
98
tier: Some(3),

Diff for: compiler/rustc_target/src/spec/targets/powerpc64_wrs_vxworks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) fn target() -> Target {
1414
description: None,
1515
tier: Some(3),
1616
host_tools: Some(false),
17-
std: None, // ?
17+
std: Some(true),
1818
},
1919
pointer_width: 64,
2020
data_layout: "E-m:e-Fi64-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),

Diff for: compiler/rustc_target/src/spec/targets/powerpc_wrs_vxworks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn target() -> Target {
1313
description: None,
1414
tier: Some(3),
1515
host_tools: Some(false),
16-
std: None, // ?
16+
std: Some(true),
1717
},
1818
pointer_width: 32,
1919
data_layout: "E-m:e-p:32:32-Fn32-i64:64-n32".into(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::spec::{StackProbeType, Target, TargetOptions, base};
2+
3+
pub(crate) fn target() -> Target {
4+
Target {
5+
llvm_target: "riscv32".into(),
6+
metadata: crate::spec::TargetMetadata {
7+
description: None,
8+
tier: Some(3),
9+
host_tools: Some(false),
10+
std: Some(true),
11+
},
12+
pointer_width: 32,
13+
data_layout: "e-m:e-p:32:32-i64:64-n32-S128".into(),
14+
arch: "riscv32".into(),
15+
options: TargetOptions {
16+
cpu: "generic-rv32".into(),
17+
llvm_abiname: "ilp32d".into(),
18+
max_atomic_width: Some(32),
19+
features: "+m,+a,+f,+d,+c".into(),
20+
stack_probes: StackProbeType::Inline,
21+
..base::vxworks::opts()
22+
},
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::spec::{StackProbeType, Target, TargetOptions, base};
2+
3+
pub(crate) fn target() -> Target {
4+
Target {
5+
llvm_target: "riscv64".into(),
6+
metadata: crate::spec::TargetMetadata {
7+
description: None,
8+
tier: Some(3),
9+
host_tools: Some(false),
10+
std: Some(true),
11+
},
12+
pointer_width: 64,
13+
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128".into(),
14+
arch: "riscv64".into(),
15+
options: TargetOptions {
16+
cpu: "generic-rv64".into(),
17+
llvm_abiname: "lp64d".into(),
18+
max_atomic_width: Some(64),
19+
features: "+m,+a,+f,+d,+c".into(),
20+
stack_probes: StackProbeType::Inline,
21+
..base::vxworks::opts()
22+
},
23+
}
24+
}

Diff for: compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_ohos.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ pub(crate) fn target() -> Target {
1515
base.supports_xray = true;
1616

1717
Target {
18-
// LLVM 15 doesn't support OpenHarmony yet, use a linux target instead.
19-
llvm_target: "x86_64-unknown-linux-musl".into(),
18+
llvm_target: "x86_64-unknown-linux-ohos".into(),
2019
metadata: crate::spec::TargetMetadata {
2120
description: Some("x86_64 OpenHarmony".into()),
2221
tier: Some(2),

Diff for: compiler/rustc_target/src/spec/targets/x86_64_wrs_vxworks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(crate) fn target() -> Target {
1515
description: None,
1616
tier: Some(3),
1717
host_tools: Some(false),
18-
std: None, // ?
18+
std: Some(true),
1919
},
2020
pointer_width: 64,
2121
data_layout:

Diff for: library/panic_unwind/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ cfg_if::cfg_if! {
4848
target_os = "psp",
4949
target_os = "xous",
5050
target_os = "solid_asp3",
51-
all(target_family = "unix", not(any(target_os = "espidf", target_os = "rtems"))),
51+
all(target_family = "unix", not(any(target_os = "espidf", target_os = "rtems", target_os = "nuttx"))),
5252
all(target_vendor = "fortanix", target_env = "sgx"),
5353
target_family = "wasm",
5454
))] {

Diff for: library/std/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fn main() {
5454
|| target_os == "teeos"
5555
|| target_os == "zkvm"
5656
|| target_os == "rtems"
57+
|| target_os == "nuttx"
5758

5859
// See src/bootstrap/src/core/build_steps/synthetic_targets.rs
5960
|| env::var("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET").is_ok()

Diff for: library/std/src/os/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ pub mod macos;
139139
pub mod netbsd;
140140
#[cfg(target_os = "nto")]
141141
pub mod nto;
142+
#[cfg(target_os = "nuttx")]
143+
pub mod nuttx;
142144
#[cfg(target_os = "openbsd")]
143145
pub mod openbsd;
144146
#[cfg(target_os = "redox")]

0 commit comments

Comments
 (0)