Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codegen test for Request::provide_* #126531

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ pub(crate) mod tags {
/// An `Option` with a type tag `I`.
///
/// Since this struct implements `Erased`, the type can be erased to make a dynamically typed
/// option. The type can be checked dynamically using `Erased::tag_id` and since this is statically
/// option. The type can be checked dynamically using `Tagged::tag_id` and since this is statically
/// checked for the concrete type, there is some degree of type safety.
#[repr(transparent)]
pub(crate) struct TaggedOption<'a, I: tags::Type<'a>>(pub Option<I::Reified>);
Expand Down
48 changes: 48 additions & 0 deletions tests/codegen/error-provide.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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: switch i64 %{{.*}}, label %{{.*}} [
slanterns marked this conversation as resolved.
Show resolved Hide resolved
// 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);
}
}
Loading