bors be055d96c4 Auto merge of #67502 - Mark-Simulacrum:opt-catch, r=Mark-Simulacrum
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 #64224, and resolves #64222.
2020-03-13 22:43:06 +00:00
..
2019-12-22 17:42:47 -05:00
2019-12-22 17:42:47 -05:00
2020-02-11 10:22:47 +01:00
2020-02-27 14:51:22 +01:00
2020-02-26 12:43:37 +01:00
2020-03-10 10:31:03 +01:00
2020-03-06 15:19:31 +01:00
2020-03-08 11:01:12 +01:00
2019-12-22 17:42:47 -05:00
2019-12-22 17:42:47 -05:00
2020-03-10 10:31:03 +01:00
2020-03-06 15:19:31 +01:00
2020-02-23 23:59:39 -08:00