forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#67502 - Mark-Simulacrum:opt-catch, r=alexcr…
…ichton Optimize catch_unwind to match C++ try/catch This refactors the implementation of catching unwinds to allow LLVM to inline the "try" closure directly into the happy path, avoiding indirection. This means that the catch_unwind implementation is (after this PR) zero-cost unless a panic is thrown. https://rust.godbolt.org/z/cZcUSB is an example of the current codegen in a simple case. Notably, the codegen is *exactly the same* if `-Cpanic=abort` is passed, which is clearly not great. This PR, on the other hand, generates the following assembly: ```asm # -Cpanic=unwind: push rbx mov ebx,0x2a call QWORD PTR [rip+0x1c53c] # <happy> mov eax,ebx pop rbx ret mov rdi,rax call QWORD PTR [rip+0x1c537] # cleanup function call call QWORD PTR [rip+0x1c539] # <unfortunate> mov ebx,0xd mov eax,ebx pop rbx ret # -Cpanic=abort: push rax call QWORD PTR [rip+0x20a1] # <happy> mov eax,0x2a pop rcx ret ``` Fixes rust-lang#64224, and resolves rust-lang#64222.
- Loading branch information
Showing
16 changed files
with
110 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Type definition for the payload argument of the try intrinsic. | ||
// | ||
// This must be kept in sync with the implementations of the try intrinsic. | ||
// | ||
// This file is included by both panic runtimes and libstd. It is part of the | ||
// panic runtime ABI. | ||
cfg_if::cfg_if! { | ||
if #[cfg(target_os = "emscripten")] { | ||
type TryPayload = *mut u8; | ||
} else if #[cfg(target_arch = "wasm32")] { | ||
type TryPayload = *mut u8; | ||
} else if #[cfg(target_os = "hermit")] { | ||
type TryPayload = *mut u8; | ||
} else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] { | ||
type TryPayload = *mut u8; | ||
} else if #[cfg(target_env = "msvc")] { | ||
type TryPayload = [u64; 2]; | ||
} else { | ||
type TryPayload = *mut u8; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// compile-flags: -O | ||
|
||
#![crate_type = "lib"] | ||
|
||
extern "C" { | ||
fn bar(); | ||
} | ||
|
||
// CHECK-LABEL: @foo | ||
#[no_mangle] | ||
pub unsafe fn foo() -> i32 { | ||
// CHECK: call void @bar | ||
// CHECK: ret i32 0 | ||
std::panic::catch_unwind(|| { | ||
bar(); | ||
0 | ||
}) | ||
.unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// compile-flags: -C panic=abort -O | ||
|
||
#![crate_type = "lib"] | ||
#![feature(unwind_attributes, core_intrinsics)] | ||
|
||
extern "C" { | ||
#[unwind(allow)] | ||
fn bar(data: *mut u8); | ||
} | ||
|
||
// CHECK-LABEL: @foo | ||
#[no_mangle] | ||
pub unsafe fn foo() -> i32 { | ||
// CHECK: call void @bar | ||
// CHECK: ret i32 0 | ||
std::intrinsics::r#try(|x| bar(x), 0 as *mut u8, 0 as *mut u8) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters