From 6cce48838b230ed429cb8e69d207993ebff00dd7 Mon Sep 17 00:00:00 2001 From: Slanterns Date: Sun, 16 Jun 2024 06:31:37 +0800 Subject: [PATCH 1/3] update comment --- library/core/src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/error.rs b/library/core/src/error.rs index 042a8c9925f..150e4f3f318 100644 --- a/library/core/src/error.rs +++ b/library/core/src/error.rs @@ -928,7 +928,7 @@ impl<'a, I: MaybeSizedType<'a>> Type<'a> for Ref { /// 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); From 240478383bfa73e165bb677e6d5ecafe48523f45 Mon Sep 17 00:00:00 2001 From: Slanterns Date: Sun, 16 Jun 2024 07:43:08 +0800 Subject: [PATCH 2/3] add codegen test for `Error::provide` --- tests/codegen/error-provide.rs | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/codegen/error-provide.rs diff --git a/tests/codegen/error-provide.rs b/tests/codegen/error-provide.rs new file mode 100644 index 00000000000..e80905eee11 --- /dev/null +++ b/tests/codegen/error-provide.rs @@ -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 %{{.*}} [ + // CHECK-COUNT-3: i64 {{.*}}, label %{{.*}} + // CHECK-NEXT: ] + request + .provide_ref::(&self.backtrace1) + .provide_ref::(&self.other) + .provide_ref::(&self.backtrace2) + .provide_ref::(&self.backtrace3); + } +} From 51d95464169751604a3cf70b1c8c524450258427 Mon Sep 17 00:00:00 2001 From: Slanterns Date: Sun, 16 Jun 2024 15:56:13 +0800 Subject: [PATCH 3/3] Apply suggestion. Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com> --- tests/codegen/error-provide.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/codegen/error-provide.rs b/tests/codegen/error-provide.rs index e80905eee11..68dd383e5cc 100644 --- a/tests/codegen/error-provide.rs +++ b/tests/codegen/error-provide.rs @@ -36,7 +36,9 @@ 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 %{{.*}} [ + // CHECK-NEXT: start: + // CHECK-NEXT: %[[SCRUTINEE:[^ ]+]] = load i64, ptr + // CHECK-NEXT: switch i64 %[[SCRUTINEE]], label %{{.*}} [ // CHECK-COUNT-3: i64 {{.*}}, label %{{.*}} // CHECK-NEXT: ] request