Skip to content

Commit

Permalink
Auto merge of rust-lang#133568 - GuillaumeGomez:rollup-js22ovb, r=Gui…
Browse files Browse the repository at this point in the history
…llaumeGomez

Rollup of 7 pull requests

Successful merges:

 - rust-lang#133358 (Don't type error if we fail to coerce `Pin<T>` because it doesnt contain a ref)
 - rust-lang#133422 (Fix clobber_abi in RV32E and RV64E inline assembly)
 - rust-lang#133452 (Support predicate registers (clobber-only) in Hexagon inline assembly)
 - rust-lang#133463 (Fix handling of x18 in AArch64 inline assembly on ohos/trusty or with -Zfixed-x18)
 - rust-lang#133487 (fix confusing diagnostic for reserved `##`)
 - rust-lang#133557 (Small doc fixes in `rustc_codegen_ssa`)
 - rust-lang#133560 (Trim extra space in 'repeated `mut`' diagnostic)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Nov 28, 2024
2 parents c1cfab2 + 22c5bb0 commit 9b4d7c6
Show file tree
Hide file tree
Showing 50 changed files with 438 additions and 186 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let mut clobber_abis = FxIndexMap::default();
if let Some(asm_arch) = asm_arch {
for (abi_name, abi_span) in &asm.clobber_abis {
match asm::InlineAsmClobberAbi::parse(asm_arch, &self.tcx.sess.target, *abi_name) {
match asm::InlineAsmClobberAbi::parse(
asm_arch,
&self.tcx.sess.target,
&self.tcx.sess.unstable_target_features,
*abi_name,
) {
Ok(abi) => {
// If the abi was already in the list, emit an error
match clobber_abis.get(&abi) {
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_codegen_cranelift/src/inline_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,14 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
let mut new_slot = |x| new_slot_fn(&mut slot_size, x);

// Allocate stack slots for saving clobbered registers
let abi_clobber = InlineAsmClobberAbi::parse(self.arch, &self.tcx.sess.target, sym::C)
.unwrap()
.clobbered_regs();
let abi_clobber = InlineAsmClobberAbi::parse(
self.arch,
&self.tcx.sess.target,
&self.tcx.sess.unstable_target_features,
sym::C,
)
.unwrap()
.clobbered_regs();
for (i, reg) in self.registers.iter().enumerate().filter_map(|(i, r)| r.map(|r| (i, r))) {
let mut need_save = true;
// If the register overlaps with a register clobbered by function call, then
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_codegen_gcc/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ fn reg_to_gcc(reg: InlineAsmRegOrRegClass) -> ConstraintOrRegister {
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r",
InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w",
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => "r",
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
unreachable!("clobber-only")
}
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => "r",
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => "f",
InlineAsmRegClass::M68k(M68kInlineAsmRegClass::reg) => "r",
Expand Down Expand Up @@ -720,6 +723,9 @@ fn dummy_output_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, reg: InlineAsmRegCl
cx.type_vector(cx.type_i64(), 2)
}
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::reg) => cx.type_i32(),
InlineAsmRegClass::Hexagon(HexagonInlineAsmRegClass::preg) => {
unreachable!("clobber-only")
}
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::reg) => cx.type_i32(),
InlineAsmRegClass::LoongArch(LoongArchInlineAsmRegClass::freg) => cx.type_f32(),
InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg) => cx.type_i32(),
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_llvm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'_>>) ->
| Arm(ArmInlineAsmRegClass::qreg_low4) => "x",
Arm(ArmInlineAsmRegClass::dreg) | Arm(ArmInlineAsmRegClass::qreg) => "w",
Hexagon(HexagonInlineAsmRegClass::reg) => "r",
Hexagon(HexagonInlineAsmRegClass::preg) => unreachable!("clobber-only"),
LoongArch(LoongArchInlineAsmRegClass::reg) => "r",
LoongArch(LoongArchInlineAsmRegClass::freg) => "f",
Mips(MipsInlineAsmRegClass::reg) => "r",
Expand Down Expand Up @@ -813,6 +814,7 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &'
| Arm(ArmInlineAsmRegClass::qreg_low8)
| Arm(ArmInlineAsmRegClass::qreg_low4) => cx.type_vector(cx.type_i64(), 2),
Hexagon(HexagonInlineAsmRegClass::reg) => cx.type_i32(),
Hexagon(HexagonInlineAsmRegClass::preg) => unreachable!("clobber-only"),
LoongArch(LoongArchInlineAsmRegClass::reg) => cx.type_i32(),
LoongArch(LoongArchInlineAsmRegClass::freg) => cx.type_f32(),
Mips(MipsInlineAsmRegClass::reg) => cx.type_i32(),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/traits/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ pub trait CodegenBackend {
need_metadata_module: bool,
) -> Box<dyn Any>;

/// This is called on the returned `Box<dyn Any>` from `codegen_backend`
/// This is called on the returned `Box<dyn Any>` from [`codegen_crate`](Self::codegen_crate)
///
/// # Panics
///
/// Panics when the passed `Box<dyn Any>` was not returned by `codegen_backend`.
/// Panics when the passed `Box<dyn Any>` was not returned by [`codegen_crate`](Self::codegen_crate).
fn join_codegen(
&self,
ongoing_codegen: Box<dyn Any>,
sess: &Session,
outputs: &OutputFilenames,
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>);

/// This is called on the returned `CodegenResults` from `join_codegen`
/// This is called on the returned [`CodegenResults`] from [`join_codegen`](Self::join_codegen).
fn link(
&self,
sess: &Session,
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
}
}

// Examine the supertype and consider auto-borrowing.
// Examine the supertype and consider type-specific coercions, such
// as auto-borrowing, coercing pointer mutability, a `dyn*` coercion,
// or pin-ergonomics.
match *b.kind() {
ty::RawPtr(_, b_mutbl) => {
return self.coerce_unsafe_ptr(a, b, b_mutbl);
Expand All @@ -230,7 +232,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
if self.tcx.features().pin_ergonomics()
&& self.tcx.is_lang_item(pin.did(), hir::LangItem::Pin) =>
{
return self.coerce_pin(a, b);
let pin_coerce = self.commit_if_ok(|_| self.coerce_pin_ref(a, b));
if pin_coerce.is_ok() {
return pin_coerce;
}
}
_ => {}
}
Expand Down Expand Up @@ -797,7 +802,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
/// - `Pin<Box<T>>` as `Pin<&T>`
/// - `Pin<Box<T>>` as `Pin<&mut T>`
#[instrument(skip(self), level = "trace")]
fn coerce_pin(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
fn coerce_pin_ref(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'tcx> {
// We need to make sure the two types are compatible for coercion.
// Then we will build a ReborrowPin adjustment and return that as an InferOk.

Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,9 @@ lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
lint_requested_level = requested on the command line with `{$level} {$lint_name}`
lint_reserved_multihash = reserved token in Rust 2024
.suggestion = insert whitespace here to avoid this being parsed as a forbidden token in Rust 2024
lint_reserved_prefix = prefix `{$prefix}` is unknown
.label = unknown prefix
.suggestion = insert whitespace here to avoid this being parsed as a prefix in Rust 2021
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_lint/src/context/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
lints::RawPrefix { label: label_span, suggestion: label_span.shrink_to_hi() }
.decorate_lint(diag);
}
BuiltinLintDiag::ReservedString(suggestion) => {
lints::ReservedString { suggestion }.decorate_lint(diag);
BuiltinLintDiag::ReservedString { is_string, suggestion } => {
if is_string {
lints::ReservedString { suggestion }.decorate_lint(diag);
} else {
lints::ReservedMultihash { suggestion }.decorate_lint(diag);
}
}
BuiltinLintDiag::UnusedBuiltinAttribute { attr_name, macro_name, invoc_span } => {
lints::UnusedBuiltinAttribute { invoc_span, attr_name, macro_name }.decorate_lint(diag);
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3059,3 +3059,10 @@ pub(crate) struct ReservedString {
#[suggestion(code = " ", applicability = "machine-applicable")]
pub suggestion: Span,
}

#[derive(LintDiagnostic)]
#[diag(lint_reserved_multihash)]
pub(crate) struct ReservedMultihash {
#[suggestion(code = " ", applicability = "machine-applicable")]
pub suggestion: Span,
}
7 changes: 5 additions & 2 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,11 @@ pub enum BuiltinLintDiag {
ReservedPrefix(Span, String),
/// `'r#` in edition < 2021.
RawPrefix(Span),
/// `##` or `#"` is edition < 2024.
ReservedString(Span),
/// `##` or `#"` in edition < 2024.
ReservedString {
is_string: bool,
suggestion: Span,
},
TrailingMacro(bool, Ident),
BreakWithLabelAndLoop(Span),
UnicodeTextFlow(Span, String),
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,10 @@ parse_require_colon_after_labeled_expression = labeled expression must be follow
.label = the label
.suggestion = add `:` after the label
parse_reserved_multihash = reserved multi-hash token is forbidden
.note = sequences of two or more # are reserved for future use since Rust 2024
.suggestion_whitespace = consider inserting whitespace here
parse_reserved_string = invalid string literal
.note = unprefixed guarded string literals are reserved for future use since Rust 2024
.suggestion_whitespace = consider inserting whitespace here
Expand Down
12 changes: 11 additions & 1 deletion compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2151,6 +2151,15 @@ pub(crate) enum UnknownPrefixSugg {
},
}

#[derive(Diagnostic)]
#[diag(parse_reserved_multihash)]
#[note]
pub(crate) struct ReservedMultihash {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub sugg: Option<GuardedStringSugg>,
}
#[derive(Diagnostic)]
#[diag(parse_reserved_string)]
#[note]
Expand Down Expand Up @@ -2611,8 +2620,9 @@ pub(crate) enum InvalidMutInPattern {
#[diag(parse_repeated_mut_in_pattern)]
pub(crate) struct RepeatedMutInPattern {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
pub span: Span,
#[suggestion(code = "", applicability = "machine-applicable", style = "verbose")]
pub suggestion: Span,
}

#[derive(Diagnostic)]
Expand Down
16 changes: 10 additions & 6 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {

let mut cursor = Cursor::new(str_before);

let (span, unterminated) = match cursor.guarded_double_quoted_string() {
let (is_string, span, unterminated) = match cursor.guarded_double_quoted_string() {
Some(rustc_lexer::GuardedStr { n_hashes, terminated, token_len }) => {
let end = start + BytePos(token_len);
let span = self.mk_sp(start, end);
Expand All @@ -829,13 +829,13 @@ impl<'psess, 'src> Lexer<'psess, 'src> {

let unterminated = if terminated { None } else { Some(str_start) };

(span, unterminated)
(true, span, unterminated)
}
_ => {
None => {
// We should only get here in the `##+` case.
debug_assert_eq!(self.str_from_to(start, start + BytePos(2)), "##");

(span, None)
(false, span, None)
}
};
if edition2024 {
Expand All @@ -857,7 +857,11 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
};

// In Edition 2024 and later, emit a hard error.
let err = self.dcx().emit_err(errors::ReservedString { span, sugg });
let err = if is_string {
self.dcx().emit_err(errors::ReservedString { span, sugg })
} else {
self.dcx().emit_err(errors::ReservedMultihash { span, sugg })
};

token::Literal(token::Lit {
kind: token::Err(err),
Expand All @@ -870,7 +874,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
RUST_2024_GUARDED_STRING_INCOMPATIBLE_SYNTAX,
span,
ast::CRATE_NODE_ID,
BuiltinLintDiag::ReservedString(space_span),
BuiltinLintDiag::ReservedString { is_string, suggestion: space_span },
);

// For backwards compatibility, roll back to after just the first `#`
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,9 @@ impl<'a> Parser<'a> {
return;
}

self.dcx().emit_err(RepeatedMutInPattern { span: lo.to(self.prev_token.span) });
let span = lo.to(self.prev_token.span);
let suggestion = span.with_hi(self.token.span.lo());
self.dcx().emit_err(RepeatedMutInPattern { span, suggestion });
}

/// Parse macro invocation
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,7 @@ symbols! {
repr_simd,
repr_transparent,
require,
reserve_x18: "reserve-x18",
residual,
result,
result_ffi_guarantees,
Expand Down
18 changes: 13 additions & 5 deletions compiler/rustc_target/src/asm/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;

use rustc_data_structures::fx::FxIndexSet;
use rustc_span::Symbol;
use rustc_span::{Symbol, sym};

use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
use crate::spec::{RelocModel, Target};
Expand Down Expand Up @@ -71,18 +71,26 @@ impl AArch64InlineAsmRegClass {
}
}

pub(crate) fn target_reserves_x18(target: &Target) -> bool {
target.os == "android" || target.os == "fuchsia" || target.is_like_osx || target.is_like_windows
pub(crate) fn target_reserves_x18(target: &Target, target_features: &FxIndexSet<Symbol>) -> bool {
// See isX18ReservedByDefault in LLVM for targets reserve x18 by default:
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/TargetParser/AArch64TargetParser.cpp#L102-L105
// Note that +reserve-x18 is currently not set for the above targets.
target.os == "android"
|| target.os == "fuchsia"
|| target.env == "ohos"
|| target.is_like_osx
|| target.is_like_windows
|| target_features.contains(&sym::reserve_x18)
}

fn reserved_x18(
_arch: InlineAsmArch,
_reloc_model: RelocModel,
_target_features: &FxIndexSet<Symbol>,
target_features: &FxIndexSet<Symbol>,
target: &Target,
_is_clobber: bool,
) -> Result<(), &'static str> {
if target_reserves_x18(target) {
if target_reserves_x18(target, target_features) {
Err("x18 is a reserved register on this target")
} else {
Ok(())
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_target/src/asm/hexagon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::{InlineAsmArch, InlineAsmType, ModifierInfo};
def_reg_class! {
Hexagon HexagonInlineAsmRegClass {
reg,
preg,
}
}

Expand Down Expand Up @@ -37,6 +38,7 @@ impl HexagonInlineAsmRegClass {
) -> &'static [(InlineAsmType, Option<Symbol>)] {
match self {
Self::reg => types! { _: I8, I16, I32, F32; },
Self::preg => &[],
}
}
}
Expand Down Expand Up @@ -71,6 +73,10 @@ def_regs! {
r26: reg = ["r26"],
r27: reg = ["r27"],
r28: reg = ["r28"],
p0: preg = ["p0"],
p1: preg = ["p1"],
p2: preg = ["p2"],
p3: preg = ["p3"],
#error = ["r19"] =>
"r19 is used internally by LLVM and cannot be used as an operand for inline asm",
#error = ["r29", "sp"] =>
Expand Down
Loading

0 comments on commit 9b4d7c6

Please sign in to comment.