makepad/libs/relax/compiler/tests/dyn_tail_drop_align.rs
Admin b22a714840 makepad run: the Rust JIT (libs/relax) and makepad-remote
The JIT that runs makepad apps from source: lexer, front end, type checker,
lazy borrow checker (Gandalf; `--check-first` opts in), codegen, session and
warm/cold caches keyed by compiler stamp, provided crates bound late,
startup images, live patching. User-facing name is `makepad run` (binary
`makepad`, MAKEPAD_RUN_* env, ~/.makepad-run); libs/relax stays the internal
library name. `makepad check` reports rustc-style diagnostics with rustc
error codes and checks a whole workspace (`--workspace`). Runs on macOS,
Linux, Windows and Android. makepad-remote: one tool schema for apps and the
WM (app/1): grabs, captures, traces, frame profiles and tweaks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 12:26:21 +02:00

47 lines
1.3 KiB
Rust

// Dropping an unsized struct must project its tail using dynamic alignment,
// both through generated Arc drop glue and Box's drop_in_place intrinsic.
use std::sync::{
atomic::{AtomicUsize, Ordering},
Arc,
};
static DROPPED: AtomicUsize = AtomicUsize::new(0);
static DROPS: AtomicUsize = AtomicUsize::new(0);
trait Marker {}
#[repr(align(64))]
struct Aligned {
_pad: [u8; 64],
}
impl Marker for Aligned {}
impl Drop for Aligned {
fn drop(&mut self) {
DROPPED.store(self as *mut Self as usize, Ordering::SeqCst);
DROPS.fetch_add(1, Ordering::SeqCst);
}
}
struct Tail<T: ?Sized> {
_tag: u8,
value: T,
}
#[test]
fn aligned_dyn_tail() {
let value = Arc::new(Tail { _tag: 1, value: Aligned { _pad: [0; 64] } });
let expected = &value.value as *const Aligned as usize;
let erased: Arc<Tail<dyn Marker>> = value;
drop(erased);
assert_eq!(DROPPED.load(Ordering::SeqCst), expected);
assert_eq!(DROPS.load(Ordering::SeqCst), 1);
let value = Box::new(Tail { _tag: 1, value: Aligned { _pad: [0; 64] } });
let expected = &value.value as *const Aligned as usize;
let erased: Box<Tail<dyn Marker>> = value;
drop(erased);
assert_eq!(DROPPED.load(Ordering::SeqCst), expected);
assert_eq!(DROPS.load(Ordering::SeqCst), 2);
}