Skip to content

Commit

Permalink
address pr review comments
Browse files Browse the repository at this point in the history
 ### Add debug assertion to check `AbiDatas` ordering

    This makes a small alteration to `Abi::index`, so that we include a
    debug assertion to check that the index we are returning corresponds
    with the same abi in our data array.

    This will help prevent ordering bugs in the future, which can
    manifest in rather strange errors.

 ### Using exhaustive ABI matches

    This slightly modifies the changes from our previous commits,
    favoring exhaustive matches in place of `_ => ...` fall-through
    arms.

    This should help with maintenance in the future, when additional
    ABI's are added, or when existing ABI's are modified.

 ### List all `-unwind` ABI's in unstable book

    This updates the `c-unwind` page in the unstable book to list _all_
    of the other ABI strings that are introduced by this feature gate.

    Now, all of the ABI's specified by RFC 2945 are shown.

Co-authored-by: Amanieu d'Antras <[email protected]>
Co-authored-by: Niko Matsakis <[email protected]>
  • Loading branch information
3 people committed Mar 9, 2021
1 parent baf227e commit 05bf037
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
20 changes: 19 additions & 1 deletion compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2595,7 +2595,25 @@ fn fn_can_unwind(
C { unwind } | Stdcall { unwind } | System { unwind } | Thiscall { unwind } => {
unwind
}
_ => false,
Cdecl
| Fastcall
| Vectorcall
| Aapcs
| Win64
| SysV64
| PtxKernel
| Msp430Interrupt
| X86Interrupt
| AmdGpuKernel
| EfiApi
| AvrInterrupt
| AvrNonBlockingInterrupt
| CCmseNonSecureCall
| RustIntrinsic
| PlatformIntrinsic
| Unadjusted => false,
// In the `if` above, we checked for functions with the Rust calling convention.
Rust | RustCall => unreachable!(),
}
}
}
Expand Down
18 changes: 17 additions & 1 deletion compiler/rustc_mir_build/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,23 @@ fn should_abort_on_panic(tcx: TyCtxt<'_>, fn_def_id: LocalDefId, abi: Abi) -> bo
// Rust and `rust-call` functions are allowed to unwind, and should not abort.
Rust | RustCall => false,
// Other ABI's should abort.
_ => true,
Cdecl
| Fastcall
| Vectorcall
| Aapcs
| Win64
| SysV64
| PtxKernel
| Msp430Interrupt
| X86Interrupt
| AmdGpuKernel
| EfiApi
| AvrInterrupt
| AvrNonBlockingInterrupt
| CCmseNonSecureCall
| RustIntrinsic
| PlatformIntrinsic
| Unadjusted => true,
}
}
}
Expand Down
15 changes: 13 additions & 2 deletions compiler/rustc_target/src/spec/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl Abi {
// N.B., this ordering MUST match the AbiDatas array above.
// (This is ensured by the test indices_are_correct().)
use Abi::*;
match self {
let i = match self {
// Cross-platform ABIs
Rust => 0,
C { unwind: false } => 1,
Expand Down Expand Up @@ -138,7 +138,18 @@ impl Abi {
RustCall => 24,
PlatformIntrinsic => 25,
Unadjusted => 26,
}
};
debug_assert!(
AbiDatas
.iter()
.enumerate()
.find(|(_, AbiData { abi, .. })| *abi == self)
.map(|(index, _)| index)
.expect("abi variant has associated data")
== i,
"Abi index did not match `AbiDatas` ordering"
);
i
}

#[inline]
Expand Down
3 changes: 2 additions & 1 deletion src/doc/unstable-book/src/language-features/c-unwind.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ The tracking issue for this feature is: [#74990]

------------------------

Introduces a new ABI string, "C-unwind", to enable unwinding from other
Introduces four new ABI strings: "C-unwind", "stdcall-unwind",
"thiscall-unwind", and "system-unwind". These enable unwinding from other
languages (such as C++) into Rust frames and from Rust into other languages.

See [RFC 2945] for more information.
Expand Down

0 comments on commit 05bf037

Please sign in to comment.