forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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#126531 - slanterns:error_provider, r=workingjubilee Add codegen test for `Request::provide_*` Codegen before & after rust-lang#126242: https://gist.github.com/slanterns/3789ee36f59ed834e1a6bd4677b68ed4. Also adjust an outdated comment since `tag_id` is no longer attached to `TaggedOption` via `Erased`, but stored next to it in `Tagged` under the new implementation. My first time writing FileCheck xD. Correct me if there is anything that should be amended. r? libs
- Loading branch information
Showing
2 changed files
with
51 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Codegen test for #126242 | ||
|
||
//@ compile-flags: -O | ||
#![crate_type = "lib"] | ||
#![feature(error_generic_member_access)] | ||
use std::error::Request; | ||
use std::fmt; | ||
|
||
#[derive(Debug)] | ||
struct MyBacktrace1 {} | ||
|
||
#[derive(Debug)] | ||
struct MyBacktrace2 {} | ||
|
||
#[derive(Debug)] | ||
struct MyBacktrace3 {} | ||
|
||
#[derive(Debug)] | ||
struct MyError { | ||
backtrace1: MyBacktrace1, | ||
backtrace2: MyBacktrace2, | ||
backtrace3: MyBacktrace3, | ||
other: MyBacktrace3, | ||
} | ||
|
||
impl fmt::Display for MyError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "Example Error") | ||
} | ||
} | ||
|
||
impl std::error::Error for MyError { | ||
// CHECK-LABEL: @provide | ||
#[no_mangle] | ||
fn provide<'a>(&'a self, request: &mut Request<'a>) { | ||
// LLVM should be able to optimize multiple .provide_* calls into a switch table | ||
// and eliminate redundant ones, rather than compare one-by-one. | ||
|
||
// CHECK-NEXT: start: | ||
// CHECK-NEXT: %[[SCRUTINEE:[^ ]+]] = load i64, ptr | ||
// CHECK-NEXT: switch i64 %[[SCRUTINEE]], label %{{.*}} [ | ||
// CHECK-COUNT-3: i64 {{.*}}, label %{{.*}} | ||
// CHECK-NEXT: ] | ||
request | ||
.provide_ref::<MyBacktrace1>(&self.backtrace1) | ||
.provide_ref::<MyBacktrace3>(&self.other) | ||
.provide_ref::<MyBacktrace2>(&self.backtrace2) | ||
.provide_ref::<MyBacktrace3>(&self.backtrace3); | ||
} | ||
} |