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 16e660d

Browse files
committedDec 6, 2024
Remove all support for wasm's legacy ABI
1 parent c0b76a2 commit 16e660d

File tree

10 files changed

+18
-130
lines changed

10 files changed

+18
-130
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;
@@ -2331,12 +2331,6 @@ impl<'tcx> HasTargetSpec for Builder<'_, '_, 'tcx> {
23312331
}
23322332
}
23332333

2334-
impl<'tcx> HasWasmCAbiOpt for Builder<'_, '_, 'tcx> {
2335-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
2336-
self.cx.wasm_c_abi_opt()
2337-
}
2338-
}
2339-
23402334
impl<'tcx> HasX86AbiOpt for Builder<'_, '_, 'tcx> {
23412335
fn x86_abi_opt(&self) -> X86Abi {
23422336
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_interface/src/tests.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_span::symbol::sym;
2727
use rustc_span::{FileName, SourceFileHashAlgorithm};
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};
@@ -866,7 +866,6 @@ fn test_unstable_options_tracking_hash() {
866866
tracked!(verify_llvm_ir, true);
867867
tracked!(virtual_function_elimination, true);
868868
tracked!(wasi_exec_model, Some(WasiExecModel::Reactor));
869-
tracked!(wasm_c_abi, WasmCAbi::Spec);
870869
// tidy-alphabetical-end
871870

872871
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_session::config::OptLevel;
1919
use rustc_span::symbol::{Symbol, sym};
2020
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
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

@@ -544,12 +542,6 @@ impl<'tcx> HasTargetSpec for TyCtxt<'tcx> {
544542
}
545543
}
546544

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

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

‎compiler/rustc_session/src/config.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2893,7 +2893,7 @@ pub(crate) mod dep_tracking {
28932893
use rustc_target::spec::{
28942894
CodeModel, FramePointer, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel,
28952895
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, TargetTuple,
2896-
TlsModel, WasmCAbi,
2896+
TlsModel,
28972897
};
28982898

28992899
use super::{
@@ -3002,7 +3002,6 @@ pub(crate) mod dep_tracking {
30023002
Polonius,
30033003
InliningThreshold,
30043004
FunctionReturn,
3005-
WasmCAbi,
30063005
);
30073006

30083007
impl<T1, T2> DepTrackingHash for (T1, T2)

‎compiler/rustc_session/src/options.rs

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

2020
use crate::config::*;
@@ -450,7 +450,6 @@ mod desc {
450450
"either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
451451
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`)";
452452
pub(crate) const parse_function_return: &str = "`keep` or `thunk-extern`";
453-
pub(crate) const parse_wasm_c_abi: &str = "`legacy` or `spec`";
454453
pub(crate) const parse_mir_include_spans: &str =
455454
"either a boolean (`yes`, `no`, `on`, `off`, etc), or `nll` (default: `nll`)";
456455
}
@@ -1502,15 +1501,6 @@ pub mod parse {
15021501
true
15031502
}
15041503

1505-
pub(crate) fn parse_wasm_c_abi(slot: &mut WasmCAbi, v: Option<&str>) -> bool {
1506-
match v {
1507-
Some("spec") => *slot = WasmCAbi::Spec,
1508-
Some("legacy") => *slot = WasmCAbi::Legacy,
1509-
_ => return false,
1510-
}
1511-
true
1512-
}
1513-
15141504
pub(crate) fn parse_mir_include_spans(slot: &mut MirIncludeSpans, v: Option<&str>) -> bool {
15151505
*slot = match v {
15161506
Some("on" | "yes" | "y" | "true") | None => MirIncludeSpans::On,
@@ -2181,8 +2171,6 @@ written to standard error output)"),
21812171
Requires `-Clto[=[fat,yes]]`"),
21822172
wasi_exec_model: Option<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED],
21832173
"whether to build a wasi command or reactor"),
2184-
wasm_c_abi: WasmCAbi = (WasmCAbi::Legacy, parse_wasm_c_abi, [TRACKED],
2185-
"use spec-compliant C ABI for `wasm32-unknown-unknown` (default: legacy)"),
21862174
write_long_types_to_disk: bool = (true, parse_bool, [UNTRACKED],
21872175
"whether long type names should be written to files instead of being printed in errors"),
21882176
// tidy-alphabetical-end

‎compiler/rustc_target/src/callconv/mod.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::abi::{
1010
TyAndLayout,
1111
};
1212
use crate::spec::abi::Abi as SpecAbi;
13-
use crate::spec::{self, HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, WasmCAbi};
13+
use crate::spec::{self, HasTargetSpec, HasX86AbiOpt};
1414

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

‎compiler/rustc_target/src/callconv/wasm.rs

+1-41
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ where
4545
}
4646

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

‎compiler/rustc_target/src/spec/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -2098,19 +2098,6 @@ impl HasTargetSpec for Target {
20982098
}
20992099
}
21002100

2101-
/// Which C ABI to use for `wasm32-unknown-unknown`.
2102-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
2103-
pub enum WasmCAbi {
2104-
/// Spec-compliant C ABI.
2105-
Spec,
2106-
/// Legacy ABI. Which is non-spec-compliant.
2107-
Legacy,
2108-
}
2109-
2110-
pub trait HasWasmCAbiOpt {
2111-
fn wasm_c_abi_opt(&self) -> WasmCAbi;
2112-
}
2113-
21142101
/// x86 (32-bit) abi options.
21152102
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
21162103
pub struct X86Abi {

‎compiler/rustc_ty_utils/src/abi.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -470,28 +470,18 @@ fn fn_abi_sanity_check<'tcx>(
470470
// For an unsized type we'd only pass the sized prefix, so there is no universe
471471
// in which we ever want to allow this.
472472
assert!(sized, "`PassMode::Direct` for unsized type in ABI: {:#?}", fn_abi);
473+
473474
// This really shouldn't happen even for sized aggregates, since
474475
// `immediate_llvm_type` will use `layout.fields` to turn this Rust type into an
475476
// LLVM type. This means all sorts of Rust type details leak into the ABI.
476-
// However wasm sadly *does* currently use this mode for it's "C" ABI so we
477-
// have to allow it -- but we absolutely shouldn't let any more targets do
478-
// that. (Also see <https://github.com/rust-lang/rust/issues/115666>.)
479-
//
480-
// The unadjusted ABI also uses Direct for all args and is ill-specified,
477+
// The unadjusted ABI however uses Direct for all args. It is ill-specified,
481478
// but unfortunately we need it for calling certain LLVM intrinsics.
482-
483-
match spec_abi {
484-
ExternAbi::Unadjusted => {}
485-
ExternAbi::C { unwind: _ }
486-
if matches!(&*tcx.sess.target.arch, "wasm32" | "wasm64") => {}
487-
_ => {
488-
panic!(
489-
"`PassMode::Direct` for aggregates only allowed for \"unadjusted\" functions and on wasm\n\
490-
Problematic type: {:#?}",
491-
arg.layout,
492-
);
493-
}
494-
}
479+
assert!(
480+
matches!(spec_abi, ExternAbi::Unadjusted),
481+
"`PassMode::Direct` for aggregates only allowed for \"unadjusted\"\n\
482+
Problematic type: {:#?}",
483+
arg.layout,
484+
);
495485
}
496486
}
497487
}

0 commit comments

Comments
 (0)
Failed to load comments.