Skip to content

Commit a8e1186

Browse files
committed
Auto merge of rust-lang#132435 - workingjubilee:rollup-3mgogw9, r=workingjubilee
Rollup of 9 pull requests Successful merges: - rust-lang#131168 (Fix `target_os` for `mipsel-sony-psx`) - rust-lang#132209 (Fix validation when lowering `?` trait bounds) - rust-lang#132294 (Bump Fuchsia) - rust-lang#132357 (Improve missing_abi lint) - rust-lang#132385 (compiler: Move `rustc_target::spec::abi::Abi` to `rustc_abi::ExternAbi`) - rust-lang#132403 (continue `TypingMode` refactor) - rust-lang#132417 (macOS: Document the difference between Clang's `-darwin` and `-macosx` targets) - rust-lang#132421 (Remove `""` case from RISC-V `llvm_abiname` match statement) - rust-lang#132422 (llvm: Match new LLVM 128-bit integer alignment on sparc) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 24254ef + acd839d commit a8e1186

File tree

75 files changed

+364
-220
lines changed

Some content is hidden

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

75 files changed

+364
-220
lines changed

Cargo.lock

+5-3
Original file line numberDiff line numberDiff line change
@@ -3204,9 +3204,11 @@ dependencies = [
32043204
"rand",
32053205
"rand_xoshiro",
32063206
"rustc_data_structures",
3207+
"rustc_feature",
32073208
"rustc_index",
32083209
"rustc_macros",
32093210
"rustc_serialize",
3211+
"rustc_span",
32103212
"tracing",
32113213
]
32123214

@@ -3749,11 +3751,11 @@ dependencies = [
37493751
name = "rustc_hir_pretty"
37503752
version = "0.0.0"
37513753
dependencies = [
3754+
"rustc_abi",
37523755
"rustc_ast",
37533756
"rustc_ast_pretty",
37543757
"rustc_hir",
37553758
"rustc_span",
3756-
"rustc_target",
37573759
]
37583760

37593761
[[package]]
@@ -3938,14 +3940,14 @@ dependencies = [
39383940
name = "rustc_lint_defs"
39393941
version = "0.0.0"
39403942
dependencies = [
3943+
"rustc_abi",
39413944
"rustc_ast",
39423945
"rustc_data_structures",
39433946
"rustc_error_messages",
39443947
"rustc_hir",
39453948
"rustc_macros",
39463949
"rustc_serialize",
39473950
"rustc_span",
3948-
"rustc_target",
39493951
"serde",
39503952
]
39513953

@@ -4054,6 +4056,7 @@ version = "0.0.0"
40544056
dependencies = [
40554057
"either",
40564058
"itertools",
4059+
"rustc_abi",
40574060
"rustc_apfloat",
40584061
"rustc_arena",
40594062
"rustc_ast",
@@ -4069,7 +4072,6 @@ dependencies = [
40694072
"rustc_pattern_analysis",
40704073
"rustc_session",
40714074
"rustc_span",
4072-
"rustc_target",
40734075
"rustc_trait_selection",
40744076
"tracing",
40754077
]

compiler/rustc_abi/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ bitflags = "2.4.1"
99
rand = { version = "0.8.4", default-features = false, optional = true }
1010
rand_xoshiro = { version = "0.6.0", optional = true }
1111
rustc_data_structures = { path = "../rustc_data_structures", optional = true }
12+
rustc_feature = { path = "../rustc_feature", optional = true }
1213
rustc_index = { path = "../rustc_index", default-features = false }
1314
rustc_macros = { path = "../rustc_macros", optional = true }
1415
rustc_serialize = { path = "../rustc_serialize", optional = true }
16+
rustc_span = { path = "../rustc_span", optional = true }
1517
tracing = "0.1"
1618
# tidy-alphabetical-end
1719

@@ -22,8 +24,10 @@ default = ["nightly", "randomize"]
2224
# without depending on rustc_data_structures, rustc_macros and rustc_serialize
2325
nightly = [
2426
"dep:rustc_data_structures",
27+
"dep:rustc_feature",
2528
"dep:rustc_macros",
2629
"dep:rustc_serialize",
30+
"dep:rustc_span",
2731
"rustc_index/nightly",
2832
]
2933
randomize = ["dep:rand", "dep:rand_xoshiro", "nightly"]

compiler/rustc_target/src/spec/abi/mod.rs renamed to compiler/rustc_abi/src/extern_abi/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ use rustc_span::{Span, Symbol};
77
#[cfg(test)]
88
mod tests;
99

10+
use ExternAbi as Abi;
11+
1012
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Debug)]
1113
#[derive(HashStable_Generic, Encodable, Decodable)]
12-
pub enum Abi {
14+
pub enum ExternAbi {
1315
// Some of the ABIs come first because every time we add a new ABI, we have to re-bless all the
1416
// hashing tests. These are used in many places, so giving them stable values reduces test
1517
// churn. The specific values are meaningless.

compiler/rustc_abi/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// tidy-alphabetical-start
22
#![cfg_attr(feature = "nightly", allow(internal_features))]
33
#![cfg_attr(feature = "nightly", doc(rust_logo))]
4+
#![cfg_attr(feature = "nightly", feature(assert_matches))]
45
#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
56
#![cfg_attr(feature = "nightly", feature(rustdoc_internals))]
67
#![cfg_attr(feature = "nightly", feature(step_trait))]
@@ -28,8 +29,15 @@ mod layout;
2829
#[cfg(test)]
2930
mod tests;
3031

32+
#[cfg(feature = "nightly")]
33+
mod extern_abi;
34+
3135
pub use callconv::{Heterogeneous, HomogeneousAggregate, Reg, RegKind};
3236
#[cfg(feature = "nightly")]
37+
pub use extern_abi::{
38+
AbiDisabled, AbiUnsupported, ExternAbi, all_names, enabled_names, is_enabled, is_stable, lookup,
39+
};
40+
#[cfg(feature = "nightly")]
3341
pub use layout::{FIRST_VARIANT, FieldIdx, Layout, TyAbiInterface, TyAndLayout, VariantIdx};
3442
pub use layout::{LayoutCalculator, LayoutCalculatorError};
3543

compiler/rustc_ast/src/ast.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2810,6 +2810,8 @@ pub struct ModSpans {
28102810
/// E.g., `extern { .. }` or `extern "C" { .. }`.
28112811
#[derive(Clone, Encodable, Decodable, Debug)]
28122812
pub struct ForeignMod {
2813+
/// Span of the `extern` keyword.
2814+
pub extern_span: Span,
28132815
/// `unsafe` keyword accepted syntactically for macro DSLs, but not
28142816
/// semantically by Rust.
28152817
pub safety: Safety,

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ pub fn walk_ty<T: MutVisitor>(vis: &mut T, ty: &mut P<Ty>) {
525525
}
526526

527527
fn walk_foreign_mod<T: MutVisitor>(vis: &mut T, foreign_mod: &mut ForeignMod) {
528-
let ForeignMod { safety, abi: _, items } = foreign_mod;
528+
let ForeignMod { extern_span: _, safety, abi: _, items } = foreign_mod;
529529
visit_safety(vis, safety);
530530
items.flat_map_in_place(|item| vis.flat_map_foreign_item(item));
531531
}

compiler/rustc_ast/src/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl WalkItemKind for ItemKind {
366366
}
367367
ModKind::Unloaded => {}
368368
},
369-
ItemKind::ForeignMod(ForeignMod { safety: _, abi: _, items }) => {
369+
ItemKind::ForeignMod(ForeignMod { extern_span: _, safety: _, abi: _, items }) => {
370370
walk_list!(visitor, visit_foreign_item, items);
371371
}
372372
ItemKind::GlobalAsm(asm) => try_visit!(visitor.visit_inline_asm(asm)),

compiler/rustc_ast_passes/src/ast_validation.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,8 @@ impl<'a> AstValidator<'a> {
677677
Self::check_decl_no_pat(&bfty.decl, |span, _, _| {
678678
self.dcx().emit_err(errors::PatternFnPointer { span });
679679
});
680-
if let Extern::Implicit(_) = bfty.ext {
681-
let sig_span = self.sess.source_map().next_point(ty.span.shrink_to_lo());
682-
self.maybe_lint_missing_abi(sig_span, ty.id);
680+
if let Extern::Implicit(extern_span) = bfty.ext {
681+
self.maybe_lint_missing_abi(extern_span, ty.id);
683682
}
684683
}
685684
TyKind::TraitObject(bounds, ..) => {
@@ -953,7 +952,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
953952
walk_list!(self, visit_attribute, &item.attrs);
954953
return; // Avoid visiting again.
955954
}
956-
ItemKind::ForeignMod(ForeignMod { abi, safety, .. }) => {
955+
ItemKind::ForeignMod(ForeignMod { extern_span, abi, safety, .. }) => {
957956
self.with_in_extern_mod(*safety, |this| {
958957
let old_item = mem::replace(&mut this.extern_mod, Some(item.span));
959958
this.visibility_not_permitted(
@@ -977,7 +976,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
977976
}
978977

979978
if abi.is_none() {
980-
this.maybe_lint_missing_abi(item.span, item.id);
979+
this.maybe_lint_missing_abi(*extern_span, item.id);
981980
}
982981
visit::walk_item(this, item);
983982
this.extern_mod = old_item;
@@ -1350,13 +1349,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13501349
if let FnKind::Fn(
13511350
_,
13521351
_,
1353-
FnSig { span: sig_span, header: FnHeader { ext: Extern::Implicit(_), .. }, .. },
1352+
FnSig { header: FnHeader { ext: Extern::Implicit(extern_span), .. }, .. },
13541353
_,
13551354
_,
13561355
_,
13571356
) = fk
13581357
{
1359-
self.maybe_lint_missing_abi(*sig_span, id);
1358+
self.maybe_lint_missing_abi(*extern_span, id);
13601359
}
13611360

13621361
// Functions without bodies cannot have patterns.

compiler/rustc_codegen_llvm/src/context.rs

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ pub(crate) unsafe fn create_module<'ll>(
148148
target_data_layout =
149149
target_data_layout.replace("-p270:32:32-p271:32:32-p272:64:64", "");
150150
}
151+
if sess.target.arch.starts_with("sparc") {
152+
// LLVM 20 updates the sparc layout to correctly align 128 bit integers to 128 bit.
153+
// See https://github.com/llvm/llvm-project/pull/106951
154+
target_data_layout = target_data_layout.replace("-i128:128", "");
155+
}
151156
}
152157

153158
// Ensure the data-layout values hardcoded remain the defaults.

compiler/rustc_codegen_ssa/src/back/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
322322
// Set the appropriate flag based on ABI
323323
// This needs to match LLVM `RISCVELFStreamer.cpp`
324324
match &*sess.target.llvm_abiname {
325-
"" | "ilp32" | "lp64" => (),
325+
"ilp32" | "lp64" => (),
326326
"ilp32f" | "lp64f" => e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE,
327327
"ilp32d" | "lp64d" => e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE,
328328
// Note that the `lp64e` is still unstable as it's not (yet) part of the ELF psABI.

compiler/rustc_const_eval/src/check_consts/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::mir::visit::Visitor;
1616
use rustc_middle::mir::*;
1717
use rustc_middle::span_bug;
1818
use rustc_middle::ty::adjustment::PointerCoercion;
19-
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TypeVisitableExt, TypingMode};
19+
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TypeVisitableExt};
2020
use rustc_mir_dataflow::Analysis;
2121
use rustc_mir_dataflow::impls::MaybeStorageLive;
2222
use rustc_mir_dataflow::storage::always_storage_live_locals;
@@ -589,7 +589,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
589589
// Typeck only does a "non-const" check since it operates on HIR and cannot distinguish
590590
// which path expressions are getting called on and which path expressions are only used
591591
// as function pointers. This is required for correctness.
592-
let infcx = tcx.infer_ctxt().build(TypingMode::from_param_env(param_env));
592+
let infcx = tcx.infer_ctxt().build(body.typing_mode(tcx));
593593
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
594594

595595
let predicates = tcx.predicates_of(callee).instantiate(tcx, fn_args);

compiler/rustc_const_eval/src/check_consts/mod.rs

-7
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,7 @@ impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
3232
pub fn new(tcx: TyCtxt<'tcx>, body: &'mir mir::Body<'tcx>) -> Self {
3333
let def_id = body.source.def_id().expect_local();
3434
let param_env = tcx.param_env(def_id);
35-
Self::new_with_param_env(tcx, body, param_env)
36-
}
3735

38-
pub fn new_with_param_env(
39-
tcx: TyCtxt<'tcx>,
40-
body: &'mir mir::Body<'tcx>,
41-
param_env: ty::ParamEnv<'tcx>,
42-
) -> Self {
4336
let const_kind = tcx.hir().body_const_context(body.source.def_id().expect_local());
4437
ConstCx { body, tcx, param_env, const_kind }
4538
}

compiler/rustc_const_eval/src/check_consts/ops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::mir::CallSource;
1212
use rustc_middle::span_bug;
1313
use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths};
1414
use rustc_middle::ty::{
15-
self, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef, Param, TraitRef, Ty, TypingMode,
15+
self, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef, Param, TraitRef, Ty,
1616
suggest_constraining_type_param,
1717
};
1818
use rustc_middle::util::{CallDesugaringKind, CallKind, call_kind};
@@ -116,7 +116,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
116116
let obligation =
117117
Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref);
118118

119-
let infcx = tcx.infer_ctxt().build(TypingMode::from_param_env(param_env));
119+
let infcx = tcx.infer_ctxt().build(body.typing_mode(tcx));
120120
let mut selcx = SelectionContext::new(&infcx);
121121
let implsrc = selcx.select(&obligation);
122122

compiler/rustc_const_eval/src/interpret/eval_context.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_errors::DiagCtxtHandle;
33
use rustc_hir::def_id::DefId;
44
use rustc_infer::infer::TyCtxtInferExt;
55
use rustc_infer::infer::at::ToTrace;
6-
use rustc_infer::traits::ObligationCause;
6+
use rustc_infer::traits::{ObligationCause, Reveal};
77
use rustc_middle::mir::interpret::{ErrorHandled, InvalidMetaKind, ReportedErrorInfo};
88
use rustc_middle::query::TyCtxtAt;
99
use rustc_middle::ty::layout::{
@@ -116,6 +116,7 @@ impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
116116
/// This test should be symmetric, as it is primarily about layout compatibility.
117117
pub(super) fn mir_assign_valid_types<'tcx>(
118118
tcx: TyCtxt<'tcx>,
119+
typing_mode: TypingMode<'tcx>,
119120
param_env: ParamEnv<'tcx>,
120121
src: TyAndLayout<'tcx>,
121122
dest: TyAndLayout<'tcx>,
@@ -124,7 +125,7 @@ pub(super) fn mir_assign_valid_types<'tcx>(
124125
// all normal lifetimes are erased, higher-ranked types with their
125126
// late-bound lifetimes are still around and can lead to type
126127
// differences.
127-
if util::relate_types(tcx, param_env, Variance::Covariant, src.ty, dest.ty) {
128+
if util::relate_types(tcx, typing_mode, param_env, Variance::Covariant, src.ty, dest.ty) {
128129
// Make sure the layout is equal, too -- just to be safe. Miri really
129130
// needs layout equality. For performance reason we skip this check when
130131
// the types are equal. Equal types *can* have different layouts when
@@ -144,6 +145,7 @@ pub(super) fn mir_assign_valid_types<'tcx>(
144145
#[cfg_attr(not(debug_assertions), inline(always))]
145146
pub(super) fn from_known_layout<'tcx>(
146147
tcx: TyCtxtAt<'tcx>,
148+
typing_mode: TypingMode<'tcx>,
147149
param_env: ParamEnv<'tcx>,
148150
known_layout: Option<TyAndLayout<'tcx>>,
149151
compute: impl FnOnce() -> InterpResult<'tcx, TyAndLayout<'tcx>>,
@@ -153,7 +155,13 @@ pub(super) fn from_known_layout<'tcx>(
153155
Some(known_layout) => {
154156
if cfg!(debug_assertions) {
155157
let check_layout = compute()?;
156-
if !mir_assign_valid_types(tcx.tcx, param_env, check_layout, known_layout) {
158+
if !mir_assign_valid_types(
159+
tcx.tcx,
160+
typing_mode,
161+
param_env,
162+
check_layout,
163+
known_layout,
164+
) {
157165
span_bug!(
158166
tcx.span,
159167
"expected type differs from actual type.\nexpected: {}\nactual: {}",
@@ -203,6 +211,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
203211
}
204212
}
205213

214+
pub fn typing_mode(&self) -> TypingMode<'tcx> {
215+
debug_assert_eq!(self.param_env.reveal(), Reveal::All);
216+
TypingMode::PostAnalysis
217+
}
218+
206219
/// Returns the span of the currently executed statement/terminator.
207220
/// This is the span typically used for error reporting.
208221
#[inline(always)]
@@ -327,7 +340,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
327340
return true;
328341
}
329342
// Slow path: spin up an inference context to check if these traits are sufficiently equal.
330-
let infcx = self.tcx.infer_ctxt().build(TypingMode::from_param_env(self.param_env));
343+
let infcx = self.tcx.infer_ctxt().build(self.typing_mode());
331344
let ocx = ObligationCtxt::new(&infcx);
332345
let cause = ObligationCause::dummy_with_span(self.cur_span());
333346
// equate the two trait refs after normalization

compiler/rustc_const_eval/src/interpret/operand.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
773773
)?;
774774
if !mir_assign_valid_types(
775775
*self.tcx,
776+
self.typing_mode(),
776777
self.param_env,
777778
self.layout_of(normalized_place_ty)?,
778779
op.layout,
@@ -832,7 +833,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
832833
})
833834
};
834835
let layout =
835-
from_known_layout(self.tcx, self.param_env, layout, || self.layout_of(ty).into())?;
836+
from_known_layout(self.tcx, self.typing_mode(), self.param_env, layout, || {
837+
self.layout_of(ty).into()
838+
})?;
836839
let imm = match val_val {
837840
mir::ConstValue::Indirect { alloc_id, offset } => {
838841
// This is const data, no mutation allowed.

compiler/rustc_const_eval/src/interpret/place.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ where
540540
)?;
541541
if !mir_assign_valid_types(
542542
*self.tcx,
543+
self.typing_mode(),
543544
self.param_env,
544545
self.layout_of(normalized_place_ty)?,
545546
place.layout,
@@ -870,8 +871,13 @@ where
870871
) -> InterpResult<'tcx> {
871872
// We do NOT compare the types for equality, because well-typed code can
872873
// actually "transmute" `&mut T` to `&T` in an assignment without a cast.
873-
let layout_compat =
874-
mir_assign_valid_types(*self.tcx, self.param_env, src.layout(), dest.layout());
874+
let layout_compat = mir_assign_valid_types(
875+
*self.tcx,
876+
self.typing_mode(),
877+
self.param_env,
878+
src.layout(),
879+
dest.layout(),
880+
);
875881
if !allow_transmute && !layout_compat {
876882
span_bug!(
877883
self.cur_span(),

compiler/rustc_const_eval/src/interpret/stack.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,13 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
596596
return interp_ok(layout);
597597
}
598598

599-
let layout = from_known_layout(self.tcx, self.param_env, layout, || {
600-
let local_ty = frame.body.local_decls[local].ty;
601-
let local_ty =
602-
self.instantiate_from_frame_and_normalize_erasing_regions(frame, local_ty)?;
603-
self.layout_of(local_ty).into()
604-
})?;
599+
let layout =
600+
from_known_layout(self.tcx, self.typing_mode(), self.param_env, layout, || {
601+
let local_ty = frame.body.local_decls[local].ty;
602+
let local_ty =
603+
self.instantiate_from_frame_and_normalize_erasing_regions(frame, local_ty)?;
604+
self.layout_of(local_ty).into()
605+
})?;
605606

606607
// Layouts of locals are requested a lot, so we cache them.
607608
state.layout.set(Some(layout));

0 commit comments

Comments
 (0)