Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e08a91b

Browse files
committedMay 21, 2025
Remove all support for wasm's legacy ABI
1 parent c43786c commit e08a91b

File tree

16 files changed

+28
-305
lines changed

16 files changed

+28
-305
lines changed
 

‎compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_middle::ty::{self, 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;
@@ -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()

‎compiler/rustc_codegen_gcc/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;
@@ -516,12 +514,6 @@ impl<'gcc, 'tcx> HasTargetSpec for CodegenCx<'gcc, 'tcx> {
516514
}
517515
}
518516

519-
impl<'gcc, 'tcx> HasWasmCAbiOpt for CodegenCx<'gcc, 'tcx> {
520-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
521-
self.tcx.sess.opts.unstable_opts.wasm_c_abi
522-
}
523-
}
524-
525517
impl<'gcc, 'tcx> HasX86AbiOpt for CodegenCx<'gcc, 'tcx> {
526518
fn x86_abi_opt(&self) -> X86Abi {
527519
X86Abi {

‎compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use rustc_abi::{BackendRepr, Float, Integer, Primitive, RegKind};
22
use rustc_attr_data_structures::InstructionSetAttr;
3-
use rustc_hir::def_id::DefId;
43
use rustc_middle::mir::mono::{Linkage, MonoItemData, Visibility};
54
use rustc_middle::mir::{InlineAsmOperand, START_BLOCK};
65
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
76
use rustc_middle::ty::{Instance, Ty, TyCtxt, TypeVisitableExt};
8-
use rustc_middle::{bug, span_bug, ty};
7+
use rustc_middle::{bug, ty};
98
use rustc_span::sym;
109
use rustc_target::callconv::{ArgAbi, FnAbi, PassMode};
11-
use rustc_target::spec::{BinaryFormat, WasmCAbi};
10+
use rustc_target::spec::BinaryFormat;
1211

1312
use crate::common;
1413
use crate::mir::AsmCodegenMethods;
@@ -287,12 +286,7 @@ fn prefix_and_suffix<'tcx>(
287286
writeln!(begin, "{}", arch_prefix).unwrap();
288287
}
289288
writeln!(begin, "{asm_name}:").unwrap();
290-
writeln!(
291-
begin,
292-
".functype {asm_name} {}",
293-
wasm_functype(tcx, fn_abi, instance.def_id())
294-
)
295-
.unwrap();
289+
writeln!(begin, ".functype {asm_name} {}", wasm_functype(tcx, fn_abi)).unwrap();
296290

297291
writeln!(end).unwrap();
298292
// .size is ignored for function symbols, so we can skip it
@@ -333,7 +327,7 @@ fn prefix_and_suffix<'tcx>(
333327
/// The webassembly type signature for the given function.
334328
///
335329
/// Used by the `.functype` directive on wasm targets.
336-
fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id: DefId) -> String {
330+
fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> String {
337331
let mut signature = String::with_capacity(64);
338332

339333
let ptr_type = match tcx.data_layout.pointer_size.bits() {
@@ -342,17 +336,6 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id
342336
other => bug!("wasm pointer size cannot be {other} bits"),
343337
};
344338

345-
// FIXME: remove this once the wasm32-unknown-unknown ABI is fixed
346-
// please also add `wasm32-unknown-unknown` back in `tests/assembly/wasm32-naked-fn.rs`
347-
// basically the commit introducing this comment should be reverted
348-
if let PassMode::Pair { .. } = fn_abi.ret.mode {
349-
let _ = WasmCAbi::Legacy { with_lint: true };
350-
span_bug!(
351-
tcx.def_span(def_id),
352-
"cannot return a pair (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
353-
);
354-
}
355-
356339
let hidden_return = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });
357340

358341
signature.push('(');
@@ -366,7 +349,7 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id
366349

367350
let mut it = fn_abi.args.iter().peekable();
368351
while let Some(arg_abi) = it.next() {
369-
wasm_type(tcx, &mut signature, arg_abi, ptr_type, def_id);
352+
wasm_type(&mut signature, arg_abi, ptr_type);
370353
if it.peek().is_some() {
371354
signature.push_str(", ");
372355
}
@@ -375,35 +358,21 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id
375358
signature.push_str(") -> (");
376359

377360
if !hidden_return {
378-
wasm_type(tcx, &mut signature, &fn_abi.ret, ptr_type, def_id);
361+
wasm_type(&mut signature, &fn_abi.ret, ptr_type);
379362
}
380363

381364
signature.push(')');
382365

383366
signature
384367
}
385368

386-
fn wasm_type<'tcx>(
387-
tcx: TyCtxt<'tcx>,
388-
signature: &mut String,
389-
arg_abi: &ArgAbi<'_, Ty<'tcx>>,
390-
ptr_type: &'static str,
391-
def_id: DefId,
392-
) {
369+
fn wasm_type<'tcx>(signature: &mut String, arg_abi: &ArgAbi<'_, Ty<'tcx>>, ptr_type: &'static str) {
393370
match arg_abi.mode {
394371
PassMode::Ignore => { /* do nothing */ }
395372
PassMode::Direct(_) => {
396373
let direct_type = match arg_abi.layout.backend_repr {
397374
BackendRepr::Scalar(scalar) => wasm_primitive(scalar.primitive(), ptr_type),
398375
BackendRepr::SimdVector { .. } => "v128",
399-
BackendRepr::Memory { .. } => {
400-
// FIXME: remove this branch once the wasm32-unknown-unknown ABI is fixed
401-
let _ = WasmCAbi::Legacy { with_lint: true };
402-
span_bug!(
403-
tcx.def_span(def_id),
404-
"cannot use memory args (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
405-
);
406-
}
407376
other => unreachable!("unexpected BackendRepr: {:?}", other),
408377
};
409378

‎compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_span::source_map::{RealFileLoader, SourceMapInputs};
2727
use rustc_span::{FileName, SourceFileHashAlgorithm, sym};
2828
use rustc_target::spec::{
2929
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
30-
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel, WasmCAbi,
30+
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel,
3131
};
3232

3333
use crate::interface::{initialize_checked_jobserver, parse_cfg};
@@ -881,7 +881,6 @@ fn test_unstable_options_tracking_hash() {
881881
tracked!(verify_llvm_ir, true);
882882
tracked!(virtual_function_elimination, true);
883883
tracked!(wasi_exec_model, Some(WasiExecModel::Reactor));
884-
tracked!(wasm_c_abi, WasmCAbi::Spec);
885884
// tidy-alphabetical-end
886885

887886
macro_rules! tracked_no_crate_hash {

‎compiler/rustc_lint/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ fn register_builtins(store: &mut LintStore) {
615615
"converted into hard error, \
616616
see <https://github.com/rust-lang/rust/issues/116558> for more information",
617617
);
618+
store.register_removed("wasm_c_abi", "the wasm C ABI has been fixed");
618619
}
619620

620621
fn register_internals(store: &mut LintStore) {

‎compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ declare_lint_pass! {
142142
UNUSED_VARIABLES,
143143
USELESS_DEPRECATED,
144144
WARNINGS,
145-
WASM_C_ABI,
146145
// tidy-alphabetical-end
147146
]
148147
}
@@ -5024,46 +5023,3 @@ declare_lint! {
50245023
};
50255024
crate_level_only
50265025
}
5027-
5028-
declare_lint! {
5029-
/// The `wasm_c_abi` lint detects usage of the `extern "C"` ABI of wasm that is affected
5030-
/// by a planned ABI change that has the goal of aligning Rust with the standard C ABI
5031-
/// of this target.
5032-
///
5033-
/// ### Example
5034-
///
5035-
/// ```rust,ignore (needs wasm32-unknown-unknown)
5036-
/// #[repr(C)]
5037-
/// struct MyType(i32, i32);
5038-
///
5039-
/// extern "C" my_fun(x: MyType) {}
5040-
/// ```
5041-
///
5042-
/// This will produce:
5043-
///
5044-
/// ```text
5045-
/// error: this function function definition is affected by the wasm ABI transition: it passes an argument of non-scalar type `MyType`
5046-
/// --> $DIR/wasm_c_abi_transition.rs:17:1
5047-
/// |
5048-
/// | pub extern "C" fn my_fun(_x: MyType) {}
5049-
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5050-
/// |
5051-
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
5052-
/// = note: for more information, see issue #138762 <https://github.com/rust-lang/rust/issues/138762>
5053-
/// = help: the "C" ABI Rust uses on wasm32-unknown-unknown will change to align with the standard "C" ABI for this target
5054-
/// ```
5055-
///
5056-
/// ### Explanation
5057-
///
5058-
/// Rust has historically implemented a non-spec-compliant C ABI on wasm32-unknown-unknown. This
5059-
/// has caused incompatibilities with other compilers and Wasm targets. In a future version
5060-
/// of Rust, this will be fixed, and therefore code relying on the non-spec-compliant C ABI will
5061-
/// stop functioning.
5062-
pub WASM_C_ABI,
5063-
Warn,
5064-
"detects code relying on rustc's non-spec-compliant wasm C ABI",
5065-
@future_incompatible = FutureIncompatibleInfo {
5066-
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
5067-
reference: "issue #138762 <https://github.com/rust-lang/rust/issues/138762>",
5068-
};
5069-
}

‎compiler/rustc_middle/src/ty/layout.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ use rustc_macros::{HashStable, TyDecodable, TyEncodable, extension};
1616
use rustc_session::config::OptLevel;
1717
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1818
use rustc_target::callconv::FnAbi;
19-
use rustc_target::spec::{
20-
HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, PanicStrategy, Target, WasmCAbi, X86Abi,
21-
};
19+
use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, PanicStrategy, Target, X86Abi};
2220
use tracing::debug;
2321
use {rustc_abi as abi, rustc_hir as hir};
2422

@@ -565,12 +563,6 @@ impl<'tcx> HasTargetSpec for TyCtxt<'tcx> {
565563
}
566564
}
567565

568-
impl<'tcx> HasWasmCAbiOpt for TyCtxt<'tcx> {
569-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
570-
self.sess.opts.unstable_opts.wasm_c_abi
571-
}
572-
}
573-
574566
impl<'tcx> HasX86AbiOpt for TyCtxt<'tcx> {
575567
fn x86_abi_opt(&self) -> X86Abi {
576568
X86Abi {
@@ -625,12 +617,6 @@ impl<'tcx> HasTargetSpec for LayoutCx<'tcx> {
625617
}
626618
}
627619

628-
impl<'tcx> HasWasmCAbiOpt for LayoutCx<'tcx> {
629-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
630-
self.calc.cx.wasm_c_abi_opt()
631-
}
632-
}
633-
634620
impl<'tcx> HasX86AbiOpt for LayoutCx<'tcx> {
635621
fn x86_abi_opt(&self) -> X86Abi {
636622
self.calc.cx.x86_abi_opt()

‎compiler/rustc_monomorphize/messages.ftl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,4 @@ monomorphize_start_not_found = using `fn main` requires the standard library
6060
6161
monomorphize_symbol_already_defined = symbol `{$symbol}` is already defined
6262
63-
monomorphize_wasm_c_abi_transition =
64-
this function {$is_call ->
65-
[true] call
66-
*[false] definition
67-
} involves an argument of type `{$ty}` which is affected by the wasm ABI transition
68-
.help = the "C" ABI Rust uses on wasm32-unknown-unknown will change to align with the standard "C" ABI for this target
69-
7063
monomorphize_written_to_path = the full type name has been written to '{$path}'

‎compiler/rustc_monomorphize/src/errors.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,3 @@ pub(crate) struct AbiRequiredTargetFeature<'a> {
100100
/// Whether this is a problem at a call site or at a declaration.
101101
pub is_call: bool,
102102
}
103-
104-
#[derive(LintDiagnostic)]
105-
#[diag(monomorphize_wasm_c_abi_transition)]
106-
#[help]
107-
pub(crate) struct WasmCAbiTransition<'a> {
108-
pub ty: Ty<'a>,
109-
/// Whether this is a problem at a call site or at a declaration.
110-
pub is_call: bool,
111-
}

‎compiler/rustc_monomorphize/src/mono_checks/abi_check.rs

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
use rustc_abi::{BackendRepr, RegKind};
44
use rustc_hir::{CRATE_HIR_ID, HirId};
55
use rustc_middle::mir::{self, Location, traversal};
6-
use rustc_middle::ty::layout::LayoutCx;
7-
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt, TypingEnv};
8-
use rustc_session::lint::builtin::WASM_C_ABI;
6+
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt};
97
use rustc_span::def_id::DefId;
108
use rustc_span::{DUMMY_SP, Span, Symbol, sym};
11-
use rustc_target::callconv::{ArgAbi, Conv, FnAbi, PassMode};
12-
use rustc_target::spec::{HasWasmCAbiOpt, WasmCAbi};
9+
use rustc_target::callconv::{Conv, FnAbi, PassMode};
1310

1411
use crate::errors;
1512

@@ -83,72 +80,6 @@ fn do_check_simd_vector_abi<'tcx>(
8380
}
8481
}
8582

86-
/// Determines whether the given argument is passed the same way on the old and new wasm ABIs.
87-
fn wasm_abi_safe<'tcx>(tcx: TyCtxt<'tcx>, arg: &ArgAbi<'tcx, Ty<'tcx>>) -> bool {
88-
if matches!(arg.layout.backend_repr, BackendRepr::Scalar(_)) {
89-
return true;
90-
}
91-
92-
// Both the old and the new ABIs treat vector types like `v128` the same
93-
// way.
94-
if uses_vector_registers(&arg.mode, &arg.layout.backend_repr) {
95-
return true;
96-
}
97-
98-
// This matches `unwrap_trivial_aggregate` in the wasm ABI logic.
99-
if arg.layout.is_aggregate() {
100-
let cx = LayoutCx::new(tcx, TypingEnv::fully_monomorphized());
101-
if let Some(unit) = arg.layout.homogeneous_aggregate(&cx).ok().and_then(|ha| ha.unit()) {
102-
let size = arg.layout.size;
103-
// Ensure there's just a single `unit` element in `arg`.
104-
if unit.size == size {
105-
return true;
106-
}
107-
}
108-
}
109-
110-
// Zero-sized types are dropped in both ABIs, so they're safe
111-
if arg.layout.is_zst() {
112-
return true;
113-
}
114-
115-
false
116-
}
117-
118-
/// Warns against usage of `extern "C"` on wasm32-unknown-unknown that is affected by the
119-
/// ABI transition.
120-
fn do_check_wasm_abi<'tcx>(
121-
tcx: TyCtxt<'tcx>,
122-
abi: &FnAbi<'tcx, Ty<'tcx>>,
123-
is_call: bool,
124-
loc: impl Fn() -> (Span, HirId),
125-
) {
126-
// Only proceed for `extern "C" fn` on wasm32-unknown-unknown (same check as what `adjust_for_foreign_abi` uses to call `compute_wasm_abi_info`),
127-
// and only proceed if `wasm_c_abi_opt` indicates we should emit the lint.
128-
if !(tcx.sess.target.arch == "wasm32"
129-
&& tcx.sess.target.os == "unknown"
130-
&& tcx.wasm_c_abi_opt() == WasmCAbi::Legacy { with_lint: true }
131-
&& abi.conv == Conv::C)
132-
{
133-
return;
134-
}
135-
// Warn against all types whose ABI will change. Return values are not affected by this change.
136-
for arg_abi in abi.args.iter() {
137-
if wasm_abi_safe(tcx, arg_abi) {
138-
continue;
139-
}
140-
let (span, hir_id) = loc();
141-
tcx.emit_node_span_lint(
142-
WASM_C_ABI,
143-
hir_id,
144-
span,
145-
errors::WasmCAbiTransition { ty: arg_abi.layout.ty, is_call },
146-
);
147-
// Let's only warn once per function.
148-
break;
149-
}
150-
}
151-
15283
/// Checks that the ABI of a given instance of a function does not contain vector-passed arguments
15384
/// or return values for which the corresponding target feature is not enabled.
15485
fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
@@ -167,7 +98,6 @@ fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
16798
)
16899
};
169100
do_check_simd_vector_abi(tcx, abi, instance.def_id(), /*is_call*/ false, loc);
170-
do_check_wasm_abi(tcx, abi, /*is_call*/ false, loc);
171101
}
172102

173103
/// Checks that a call expression does not try to pass a vector-passed argument which requires a
@@ -205,7 +135,6 @@ fn check_call_site_abi<'tcx>(
205135
return;
206136
};
207137
do_check_simd_vector_abi(tcx, callee_abi, caller.def_id(), /*is_call*/ true, loc);
208-
do_check_wasm_abi(tcx, callee_abi, /*is_call*/ true, loc);
209138
}
210139

211140
fn check_callees_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, body: &mir::Body<'tcx>) {

0 commit comments

Comments
 (0)
Please sign in to comment.