Skip to content

Commit 38b6058

Browse files
committed
Remove all support for wasm's legacy ABI
1 parent cb08599 commit 38b6058

File tree

11 files changed

+25
-168
lines changed

11 files changed

+25
-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::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;
@@ -2342,12 +2342,6 @@ impl<'tcx> HasTargetSpec for Builder<'_, '_, 'tcx> {
23422342
}
23432343
}
23442344

2345-
impl<'tcx> HasWasmCAbiOpt for Builder<'_, '_, 'tcx> {
2346-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
2347-
self.cx.wasm_c_abi_opt()
2348-
}
2349-
}
2350-
23512345
impl<'tcx> HasX86AbiOpt for Builder<'_, '_, 'tcx> {
23522346
fn x86_abi_opt(&self) -> X86Abi {
23532347
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_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
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

+7-38
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_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::{BinaryFormat, WasmCAbi};
10+
use rustc_target::spec::BinaryFormat;
1211

1312
use crate::common;
1413
use crate::traits::{AsmCodegenMethods, BuilderMethods, GlobalAsmOperandRef, MiscCodegenMethods};
@@ -268,12 +267,7 @@ fn prefix_and_suffix<'tcx>(
268267
writeln!(begin, "{}", arch_prefix).unwrap();
269268
}
270269
writeln!(begin, "{asm_name}:").unwrap();
271-
writeln!(
272-
begin,
273-
".functype {asm_name} {}",
274-
wasm_functype(tcx, fn_abi, instance.def_id())
275-
)
276-
.unwrap();
270+
writeln!(begin, ".functype {asm_name} {}", wasm_functype(tcx, fn_abi)).unwrap();
277271

278272
writeln!(end).unwrap();
279273
// .size is ignored for function symbols, so we can skip it
@@ -287,7 +281,7 @@ fn prefix_and_suffix<'tcx>(
287281
/// The webassembly type signature for the given function.
288282
///
289283
/// Used by the `.functype` directive on wasm targets.
290-
fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id: DefId) -> String {
284+
fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> String {
291285
let mut signature = String::with_capacity(64);
292286

293287
let ptr_type = match tcx.data_layout.pointer_size.bits() {
@@ -296,17 +290,6 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id
296290
other => bug!("wasm pointer size cannot be {other} bits"),
297291
};
298292

299-
// FIXME: remove this once the wasm32-unknown-unknown ABI is fixed
300-
// please also add `wasm32-unknown-unknown` back in `tests/assembly/wasm32-naked-fn.rs`
301-
// basically the commit introducing this comment should be reverted
302-
if let PassMode::Pair { .. } = fn_abi.ret.mode {
303-
let _ = WasmCAbi::Legacy;
304-
span_bug!(
305-
tcx.def_span(def_id),
306-
"cannot return a pair (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
307-
);
308-
}
309-
310293
let hidden_return = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });
311294

312295
signature.push('(');
@@ -320,7 +303,7 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id
320303

321304
let mut it = fn_abi.args.iter().peekable();
322305
while let Some(arg_abi) = it.next() {
323-
wasm_type(tcx, &mut signature, arg_abi, ptr_type, def_id);
306+
wasm_type(&mut signature, arg_abi, ptr_type);
324307
if it.peek().is_some() {
325308
signature.push_str(", ");
326309
}
@@ -329,35 +312,21 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id
329312
signature.push_str(") -> (");
330313

331314
if !hidden_return {
332-
wasm_type(tcx, &mut signature, &fn_abi.ret, ptr_type, def_id);
315+
wasm_type(&mut signature, &fn_abi.ret, ptr_type);
333316
}
334317

335318
signature.push(')');
336319

337320
signature
338321
}
339322

340-
fn wasm_type<'tcx>(
341-
tcx: TyCtxt<'tcx>,
342-
signature: &mut String,
343-
arg_abi: &ArgAbi<'_, Ty<'tcx>>,
344-
ptr_type: &'static str,
345-
def_id: DefId,
346-
) {
323+
fn wasm_type<'tcx>(signature: &mut String, arg_abi: &ArgAbi<'_, Ty<'tcx>>, ptr_type: &'static str) {
347324
match arg_abi.mode {
348325
PassMode::Ignore => { /* do nothing */ }
349326
PassMode::Direct(_) => {
350327
let direct_type = match arg_abi.layout.backend_repr {
351328
BackendRepr::Scalar(scalar) => wasm_primitive(scalar.primitive(), ptr_type),
352329
BackendRepr::Vector { .. } => "v128",
353-
BackendRepr::Memory { .. } => {
354-
// FIXME: remove this branch once the wasm32-unknown-unknown ABI is fixed
355-
let _ = WasmCAbi::Legacy;
356-
span_bug!(
357-
tcx.def_span(def_id),
358-
"cannot use memory args (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
359-
);
360-
}
361330
other => unreachable!("unexpected BackendRepr: {:?}", other),
362331
};
363332

compiler/rustc_interface/src/tests.rs

+1-2
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};
@@ -877,7 +877,6 @@ fn test_unstable_options_tracking_hash() {
877877
tracked!(verify_llvm_ir, true);
878878
tracked!(virtual_function_elimination, true);
879879
tracked!(wasi_exec_model, Some(WasiExecModel::Reactor));
880-
tracked!(wasm_c_abi, WasmCAbi::Spec);
881880
// tidy-alphabetical-end
882881

883882
macro_rules! tracked_no_crate_hash {

compiler/rustc_middle/src/ty/layout.rs

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

@@ -573,12 +571,6 @@ impl<'tcx> HasTargetSpec for TyCtxt<'tcx> {
573571
}
574572
}
575573

576-
impl<'tcx> HasWasmCAbiOpt for TyCtxt<'tcx> {
577-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
578-
self.sess.opts.unstable_opts.wasm_c_abi
579-
}
580-
}
581-
582574
impl<'tcx> HasX86AbiOpt for TyCtxt<'tcx> {
583575
fn x86_abi_opt(&self) -> X86Abi {
584576
X86Abi {
@@ -633,12 +625,6 @@ impl<'tcx> HasTargetSpec for LayoutCx<'tcx> {
633625
}
634626
}
635627

636-
impl<'tcx> HasWasmCAbiOpt for LayoutCx<'tcx> {
637-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
638-
self.calc.cx.wasm_c_abi_opt()
639-
}
640-
}
641-
642628
impl<'tcx> HasX86AbiOpt for LayoutCx<'tcx> {
643629
fn x86_abi_opt(&self) -> X86Abi {
644630
self.calc.cx.x86_abi_opt()

compiler/rustc_session/src/config.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2936,7 +2936,7 @@ pub(crate) mod dep_tracking {
29362936
use rustc_target::spec::{
29372937
CodeModel, FramePointer, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel,
29382938
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, TargetTuple,
2939-
TlsModel, WasmCAbi,
2939+
TlsModel,
29402940
};
29412941

29422942
use super::{
@@ -3047,7 +3047,6 @@ pub(crate) mod dep_tracking {
30473047
Polonius,
30483048
InliningThreshold,
30493049
FunctionReturn,
3050-
WasmCAbi,
30513050
Align,
30523051
);
30533052

compiler/rustc_session/src/options.rs

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

2222
use crate::config::*;
@@ -790,7 +790,6 @@ mod desc {
790790
"either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
791791
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`)";
792792
pub(crate) const parse_function_return: &str = "`keep` or `thunk-extern`";
793-
pub(crate) const parse_wasm_c_abi: &str = "`legacy` or `spec`";
794793
pub(crate) const parse_mir_include_spans: &str =
795794
"either a boolean (`yes`, `no`, `on`, `off`, etc), or `nll` (default: `nll`)";
796795
pub(crate) const parse_align: &str = "a number that is a power of 2 between 1 and 2^29";
@@ -1883,15 +1882,6 @@ pub mod parse {
18831882
true
18841883
}
18851884

1886-
pub(crate) fn parse_wasm_c_abi(slot: &mut WasmCAbi, v: Option<&str>) -> bool {
1887-
match v {
1888-
Some("spec") => *slot = WasmCAbi::Spec,
1889-
Some("legacy") => *slot = WasmCAbi::Legacy,
1890-
_ => return false,
1891-
}
1892-
true
1893-
}
1894-
18951885
pub(crate) fn parse_mir_include_spans(slot: &mut MirIncludeSpans, v: Option<&str>) -> bool {
18961886
*slot = match v {
18971887
Some("on" | "yes" | "y" | "true") | None => MirIncludeSpans::On,
@@ -2599,8 +2589,6 @@ written to standard error output)"),
25992589
Requires `-Clto[=[fat,yes]]`"),
26002590
wasi_exec_model: Option<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED],
26012591
"whether to build a wasi command or reactor"),
2602-
wasm_c_abi: WasmCAbi = (WasmCAbi::Legacy, parse_wasm_c_abi, [TRACKED],
2603-
"use spec-compliant C ABI for `wasm32-unknown-unknown` (default: legacy)"),
26042592
write_long_types_to_disk: bool = (true, parse_bool, [UNTRACKED],
26052593
"whether long type names should be written to files instead of being printed in errors"),
26062594
// tidy-alphabetical-end

compiler/rustc_target/src/callconv/mod.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_abi::{
77
};
88
use rustc_macros::HashStable_Generic;
99

10-
use crate::spec::{HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, RustcAbi, WasmCAbi};
10+
use crate::spec::{HasTargetSpec, HasX86AbiOpt, RustcAbi};
1111

1212
mod aarch64;
1313
mod amdgpu;
@@ -626,7 +626,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
626626
pub fn adjust_for_foreign_abi<C>(&mut self, cx: &C, abi: ExternAbi)
627627
where
628628
Ty: TyAbiInterface<'a, C> + Copy,
629-
C: HasDataLayout + HasTargetSpec + HasWasmCAbiOpt + HasX86AbiOpt,
629+
C: HasDataLayout + HasTargetSpec + HasX86AbiOpt,
630630
{
631631
if abi == ExternAbi::X86Interrupt {
632632
if let Some(arg) = self.args.first_mut() {
@@ -699,14 +699,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
699699
"hexagon" => hexagon::compute_abi_info(self),
700700
"xtensa" => xtensa::compute_abi_info(cx, self),
701701
"riscv32" | "riscv64" => riscv::compute_abi_info(cx, self),
702-
"wasm32" => {
703-
if spec.os == "unknown" && cx.wasm_c_abi_opt() == WasmCAbi::Legacy {
704-
wasm::compute_wasm_abi_info(self)
705-
} else {
706-
wasm::compute_c_abi_info(cx, self)
707-
}
708-
}
709-
"wasm64" => wasm::compute_c_abi_info(cx, self),
702+
"wasm32" | "wasm64" => wasm::compute_abi_info(cx, self),
710703
"bpf" => bpf::compute_abi_info(self),
711704
arch => panic!("no lowering implemented for {arch}"),
712705
}

compiler/rustc_target/src/callconv/wasm.rs

+1-41
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ where
5656
}
5757

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

compiler/rustc_target/src/spec/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -2228,19 +2228,6 @@ impl HasTargetSpec for Target {
22282228
}
22292229
}
22302230

2231-
/// Which C ABI to use for `wasm32-unknown-unknown`.
2232-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
2233-
pub enum WasmCAbi {
2234-
/// Spec-compliant C ABI.
2235-
Spec,
2236-
/// Legacy ABI. Which is non-spec-compliant.
2237-
Legacy,
2238-
}
2239-
2240-
pub trait HasWasmCAbiOpt {
2241-
fn wasm_c_abi_opt(&self) -> WasmCAbi;
2242-
}
2243-
22442231
/// x86 (32-bit) abi options.
22452232
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
22462233
pub struct X86Abi {

0 commit comments

Comments
 (0)