Skip to content

Commit

Permalink
Monomorphize a bit of error handling in declare_class!
Browse files Browse the repository at this point in the history
Mostly to make the assembly tests more stable
  • Loading branch information
madsmtm committed Dec 3, 2023
1 parent 6d351f2 commit 2d188cb
Show file tree
Hide file tree
Showing 3 changed files with 340 additions and 416 deletions.
16 changes: 14 additions & 2 deletions crates/objc2/src/__macro_helpers/declared_ivars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,14 @@ pub(crate) fn register_with_ivars<T: DeclaredClass>(
let cls = builder.register();

let ivars_offset = if T::HAS_IVARS {
// Monomorphized error handling
// Intentionally not #[track_caller], we expect this error to never occur
fn get_ivar_failed() -> ! {
unreachable!("failed retrieving instance variable on newly declared class")
}

cls.instance_variable(&ivar_name)
.expect("failed retrieving instance variable on newly declared class")
.unwrap_or_else(|| get_ivar_failed())
.offset()
} else {
// Fallback to an offset of zero.
Expand All @@ -293,8 +299,14 @@ pub(crate) fn register_with_ivars<T: DeclaredClass>(
};

let drop_flag_offset = if T::HAS_DROP_FLAG {
// Monomorphized error handling
// Intentionally not #[track_caller], we expect this error to never occur
fn get_drop_flag_failed() -> ! {
unreachable!("failed retrieving drop flag instance variable on newly declared class")
}

cls.instance_variable(&drop_flag_name)
.expect("failed retrieving drop flag instance variable on newly declared class")
.unwrap_or_else(|| get_drop_flag_failed())
.offset()
} else {
// Fall back to an offset of zero.
Expand Down
Loading

0 comments on commit 2d188cb

Please sign in to comment.