Skip to content

Commit 9677720

Browse files
committed
Remove all support for wasm's legacy ABI
1 parent 1c1c13a commit 9677720

File tree

11 files changed

+24
-168
lines changed

11 files changed

+24
-168
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

+1-7
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::abi::call::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;
@@ -2363,12 +2363,6 @@ impl<'tcx> HasTargetSpec for Builder<'_, '_, 'tcx> {
23632363
}
23642364
}
23652365

2366-
impl<'tcx> HasWasmCAbiOpt for Builder<'_, '_, 'tcx> {
2367-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
2368-
self.cx.wasm_c_abi_opt()
2369-
}
2370-
}
2371-
23722366
impl<'tcx> HasX86AbiOpt for Builder<'_, '_, 'tcx> {
23732367
fn x86_abi_opt(&self) -> X86Abi {
23742368
self.cx.x86_abi_opt()

compiler/rustc_codegen_gcc/src/context.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use rustc_session::Session;
1919
use rustc_span::source_map::respan;
2020
use rustc_span::{DUMMY_SP, Span};
2121
use rustc_target::abi::{HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx};
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
use crate::callee::get_fn;
2725
use crate::common::SignType;
@@ -536,12 +534,6 @@ impl<'gcc, 'tcx> HasTargetSpec for CodegenCx<'gcc, 'tcx> {
536534
}
537535
}
538536

539-
impl<'gcc, 'tcx> HasWasmCAbiOpt for CodegenCx<'gcc, 'tcx> {
540-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
541-
self.tcx.sess.opts.unstable_opts.wasm_c_abi
542-
}
543-
}
544-
545537
impl<'gcc, 'tcx> HasX86AbiOpt for CodegenCx<'gcc, 'tcx> {
546538
fn x86_abi_opt(&self) -> X86Abi {
547539
X86Abi {

compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

+6-38
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use rustc_abi::{BackendRepr, Float, Integer, Primitive, RegKind};
22
use rustc_attr_parsing::InstructionSetAttr;
3-
use rustc_hir::def_id::DefId;
43
use rustc_middle::mir::mono::{Linkage, MonoItem, MonoItemData, Visibility};
54
use rustc_middle::mir::{Body, InlineAsmOperand};
65
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, LayoutOf};
76
use rustc_middle::ty::{Instance, Ty, TyCtxt};
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::WasmCAbi;
1210

1311
use crate::common;
1412
use crate::traits::{AsmCodegenMethods, BuilderMethods, GlobalAsmOperandRef, MiscCodegenMethods};
@@ -287,12 +285,7 @@ fn prefix_and_suffix<'tcx>(
287285
writeln!(begin, "{}", arch_prefix).unwrap();
288286
}
289287
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();
288+
writeln!(begin, ".functype {asm_name} {}", wasm_functype(tcx, fn_abi)).unwrap();
296289

297290
writeln!(end).unwrap();
298291
// .size is ignored for function symbols, so we can skip it
@@ -306,7 +299,7 @@ fn prefix_and_suffix<'tcx>(
306299
/// The webassembly type signature for the given function.
307300
///
308301
/// Used by the `.functype` directive on wasm targets.
309-
fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id: DefId) -> String {
302+
fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> String {
310303
let mut signature = String::with_capacity(64);
311304

312305
let ptr_type = match tcx.data_layout.pointer_size.bits() {
@@ -315,17 +308,6 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id
315308
other => bug!("wasm pointer size cannot be {other} bits"),
316309
};
317310

318-
// FIXME: remove this once the wasm32-unknown-unknown ABI is fixed
319-
// please also add `wasm32-unknown-unknown` back in `tests/assembly/wasm32-naked-fn.rs`
320-
// basically the commit introducing this comment should be reverted
321-
if let PassMode::Pair { .. } = fn_abi.ret.mode {
322-
let _ = WasmCAbi::Legacy;
323-
span_bug!(
324-
tcx.def_span(def_id),
325-
"cannot return a pair (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
326-
);
327-
}
328-
329311
let hidden_return = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });
330312

331313
signature.push('(');
@@ -339,7 +321,7 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id
339321

340322
let mut it = fn_abi.args.iter().peekable();
341323
while let Some(arg_abi) = it.next() {
342-
wasm_type(tcx, &mut signature, arg_abi, ptr_type, def_id);
324+
wasm_type(&mut signature, arg_abi, ptr_type);
343325
if it.peek().is_some() {
344326
signature.push_str(", ");
345327
}
@@ -348,35 +330,21 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id
348330
signature.push_str(") -> (");
349331

350332
if !hidden_return {
351-
wasm_type(tcx, &mut signature, &fn_abi.ret, ptr_type, def_id);
333+
wasm_type(&mut signature, &fn_abi.ret, ptr_type);
352334
}
353335

354336
signature.push(')');
355337

356338
signature
357339
}
358340

359-
fn wasm_type<'tcx>(
360-
tcx: TyCtxt<'tcx>,
361-
signature: &mut String,
362-
arg_abi: &ArgAbi<'_, Ty<'tcx>>,
363-
ptr_type: &'static str,
364-
def_id: DefId,
365-
) {
341+
fn wasm_type<'tcx>(signature: &mut String, arg_abi: &ArgAbi<'_, Ty<'tcx>>, ptr_type: &'static str) {
366342
match arg_abi.mode {
367343
PassMode::Ignore => { /* do nothing */ }
368344
PassMode::Direct(_) => {
369345
let direct_type = match arg_abi.layout.backend_repr {
370346
BackendRepr::Scalar(scalar) => wasm_primitive(scalar.primitive(), ptr_type),
371347
BackendRepr::Vector { .. } => "v128",
372-
BackendRepr::Memory { .. } => {
373-
// FIXME: remove this branch once the wasm32-unknown-unknown ABI is fixed
374-
let _ = WasmCAbi::Legacy;
375-
span_bug!(
376-
tcx.def_span(def_id),
377-
"cannot use memory args (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
378-
);
379-
}
380348
other => unreachable!("unexpected BackendRepr: {:?}", other),
381349
};
382350

compiler/rustc_interface/src/tests.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_span::{FileName, SourceFileHashAlgorithm, sym};
2727
use rustc_target::abi::Align;
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};
@@ -875,7 +875,6 @@ fn test_unstable_options_tracking_hash() {
875875
tracked!(verify_llvm_ir, true);
876876
tracked!(virtual_function_elimination, true);
877877
tracked!(wasi_exec_model, Some(WasiExecModel::Reactor));
878-
tracked!(wasm_c_abi, WasmCAbi::Spec);
879878
// tidy-alphabetical-end
880879

881880
macro_rules! tracked_no_crate_hash {

compiler/rustc_middle/src/ty/layout.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use rustc_macros::{HashStable, TyDecodable, TyEncodable, extension};
1818
use rustc_session::config::OptLevel;
1919
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
2020
use rustc_target::callconv::FnAbi;
21-
use rustc_target::spec::{
22-
HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, PanicStrategy, Target, WasmCAbi, X86Abi,
23-
};
21+
use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, PanicStrategy, Target, X86Abi};
2422
use tracing::debug;
2523
use {rustc_abi as abi, rustc_hir as hir};
2624

@@ -543,12 +541,6 @@ impl<'tcx> HasTargetSpec for TyCtxt<'tcx> {
543541
}
544542
}
545543

546-
impl<'tcx> HasWasmCAbiOpt for TyCtxt<'tcx> {
547-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
548-
self.sess.opts.unstable_opts.wasm_c_abi
549-
}
550-
}
551-
552544
impl<'tcx> HasX86AbiOpt for TyCtxt<'tcx> {
553545
fn x86_abi_opt(&self) -> X86Abi {
554546
X86Abi {
@@ -603,12 +595,6 @@ impl<'tcx> HasTargetSpec for LayoutCx<'tcx> {
603595
}
604596
}
605597

606-
impl<'tcx> HasWasmCAbiOpt for LayoutCx<'tcx> {
607-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
608-
self.calc.cx.wasm_c_abi_opt()
609-
}
610-
}
611-
612598
impl<'tcx> HasX86AbiOpt for LayoutCx<'tcx> {
613599
fn x86_abi_opt(&self) -> X86Abi {
614600
self.calc.cx.x86_abi_opt()

compiler/rustc_session/src/config.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,7 @@ pub(crate) mod dep_tracking {
28982898
use rustc_target::spec::{
28992899
CodeModel, FramePointer, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel,
29002900
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, TargetTuple,
2901-
TlsModel, WasmCAbi,
2901+
TlsModel,
29022902
};
29032903

29042904
use super::{
@@ -3008,7 +3008,6 @@ pub(crate) mod dep_tracking {
30083008
Polonius,
30093009
InliningThreshold,
30103010
FunctionReturn,
3011-
WasmCAbi,
30123011
Align,
30133012
);
30143013

compiler/rustc_session/src/options.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_span::{RealFileName, SourceFileHashAlgorithm};
1515
use rustc_target::spec::{
1616
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
1717
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility,
18-
TargetTuple, TlsModel, WasmCAbi,
18+
TargetTuple, TlsModel,
1919
};
2020

2121
use crate::config::*;
@@ -480,7 +480,6 @@ mod desc {
480480
"either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
481481
pub(crate) const parse_llvm_module_flag: &str = "<key>:<type>:<value>:<behavior>. Type must currently be `u32`. Behavior should be one of (`error`, `warning`, `require`, `override`, `append`, `appendunique`, `max`, `min`)";
482482
pub(crate) const parse_function_return: &str = "`keep` or `thunk-extern`";
483-
pub(crate) const parse_wasm_c_abi: &str = "`legacy` or `spec`";
484483
pub(crate) const parse_mir_include_spans: &str =
485484
"either a boolean (`yes`, `no`, `on`, `off`, etc), or `nll` (default: `nll`)";
486485
pub(crate) const parse_align: &str = "a number that is a power of 2 between 1 and 2^29";
@@ -1544,15 +1543,6 @@ pub mod parse {
15441543
true
15451544
}
15461545

1547-
pub(crate) fn parse_wasm_c_abi(slot: &mut WasmCAbi, v: Option<&str>) -> bool {
1548-
match v {
1549-
Some("spec") => *slot = WasmCAbi::Spec,
1550-
Some("legacy") => *slot = WasmCAbi::Legacy,
1551-
_ => return false,
1552-
}
1553-
true
1554-
}
1555-
15561546
pub(crate) fn parse_mir_include_spans(slot: &mut MirIncludeSpans, v: Option<&str>) -> bool {
15571547
*slot = match v {
15581548
Some("on" | "yes" | "y" | "true") | None => MirIncludeSpans::On,
@@ -2245,8 +2235,6 @@ written to standard error output)"),
22452235
Requires `-Clto[=[fat,yes]]`"),
22462236
wasi_exec_model: Option<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED],
22472237
"whether to build a wasi command or reactor"),
2248-
wasm_c_abi: WasmCAbi = (WasmCAbi::Legacy, parse_wasm_c_abi, [TRACKED],
2249-
"use spec-compliant C ABI for `wasm32-unknown-unknown` (default: legacy)"),
22502238
write_long_types_to_disk: bool = (true, parse_bool, [UNTRACKED],
22512239
"whether long type names should be written to files instead of being printed in errors"),
22522240
// tidy-alphabetical-end

compiler/rustc_target/src/callconv/mod.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::abi::{
99
self, AddressSpace, Align, BackendRepr, HasDataLayout, Pointer, Size, TyAbiInterface,
1010
TyAndLayout,
1111
};
12-
use crate::spec::{HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, WasmCAbi};
12+
use crate::spec::{HasTargetSpec, HasX86AbiOpt};
1313

1414
mod aarch64;
1515
mod amdgpu;
@@ -639,7 +639,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
639639
) -> Result<(), AdjustForForeignAbiError>
640640
where
641641
Ty: TyAbiInterface<'a, C> + Copy,
642-
C: HasDataLayout + HasTargetSpec + HasWasmCAbiOpt + HasX86AbiOpt,
642+
C: HasDataLayout + HasTargetSpec + HasX86AbiOpt,
643643
{
644644
if abi == ExternAbi::X86Interrupt {
645645
if let Some(arg) = self.args.first_mut() {
@@ -711,14 +711,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
711711
"hexagon" => hexagon::compute_abi_info(self),
712712
"xtensa" => xtensa::compute_abi_info(cx, self),
713713
"riscv32" | "riscv64" => riscv::compute_abi_info(cx, self),
714-
"wasm32" => {
715-
if spec.os == "unknown" && cx.wasm_c_abi_opt() == WasmCAbi::Legacy {
716-
wasm::compute_wasm_abi_info(self)
717-
} else {
718-
wasm::compute_c_abi_info(cx, self)
719-
}
720-
}
721-
"wasm64" => wasm::compute_c_abi_info(cx, self),
714+
"wasm32" | "wasm64" => wasm::compute_abi_info(cx, self),
722715
"bpf" => bpf::compute_abi_info(self),
723716
arch => {
724717
return Err(AdjustForForeignAbiError::Unsupported {

compiler/rustc_target/src/callconv/wasm.rs

+1-41
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ where
5757
}
5858

5959
/// The purpose of this ABI is to match the C ABI (aka clang) exactly.
60-
pub(crate) fn compute_c_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
60+
pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
6161
where
6262
Ty: TyAbiInterface<'a, C> + Copy,
6363
C: HasDataLayout,
@@ -73,43 +73,3 @@ where
7373
classify_arg(cx, arg);
7474
}
7575
}
76-
77-
/// The purpose of this ABI is for matching the WebAssembly standard. This
78-
/// intentionally diverges from the C ABI and is specifically crafted to take
79-
/// advantage of LLVM's support of multiple returns in WebAssembly.
80-
///
81-
/// This ABI is *bad*! It uses `PassMode::Direct` for `abi::Aggregate` types, which leaks LLVM
82-
/// implementation details into the ABI. It's just hard to fix because ABIs are hard to change.
83-
/// Also see <https://github.com/rust-lang/rust/issues/115666>.
84-
pub(crate) fn compute_wasm_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
85-
if !fn_abi.ret.is_ignore() {
86-
classify_ret_wasm_abi(&mut fn_abi.ret);
87-
}
88-
89-
for arg in fn_abi.args.iter_mut() {
90-
if arg.is_ignore() {
91-
continue;
92-
}
93-
classify_arg_wasm_abi(arg);
94-
}
95-
96-
fn classify_ret_wasm_abi<Ty>(ret: &mut ArgAbi<'_, Ty>) {
97-
if !ret.layout.is_sized() {
98-
// Not touching this...
99-
return;
100-
}
101-
// FIXME: this is bad! https://github.com/rust-lang/rust/issues/115666
102-
ret.make_direct_deprecated();
103-
ret.extend_integer_width_to(32);
104-
}
105-
106-
fn classify_arg_wasm_abi<Ty>(arg: &mut ArgAbi<'_, Ty>) {
107-
if !arg.layout.is_sized() {
108-
// Not touching this...
109-
return;
110-
}
111-
// FIXME: this is bad! https://github.com/rust-lang/rust/issues/115666
112-
arg.make_direct_deprecated();
113-
arg.extend_integer_width_to(32);
114-
}
115-
}

compiler/rustc_target/src/spec/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -2137,19 +2137,6 @@ impl HasTargetSpec for Target {
21372137
}
21382138
}
21392139

2140-
/// Which C ABI to use for `wasm32-unknown-unknown`.
2141-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
2142-
pub enum WasmCAbi {
2143-
/// Spec-compliant C ABI.
2144-
Spec,
2145-
/// Legacy ABI. Which is non-spec-compliant.
2146-
Legacy,
2147-
}
2148-
2149-
pub trait HasWasmCAbiOpt {
2150-
fn wasm_c_abi_opt(&self) -> WasmCAbi;
2151-
}
2152-
21532140
/// x86 (32-bit) abi options.
21542141
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
21552142
pub struct X86Abi {

0 commit comments

Comments
 (0)