use saddle::__private::{AcceptedIngress, DatabaseRequest, entry_consumer_layouts_for};
use saddle::{BusinessConfig, Result};
use std::future::{Future, pending};
use std::sync::atomic::{AtomicUsize, Ordering};
static CALLS: AtomicUsize = AtomicUsize::new(0);
#[repr(align(64))]
struct Deployment<const N: usize>([u8; N]);
fn dispatch<const CAPTURE: usize, const BODY: usize>(
_ingress: AcceptedIngress,
deployment: Deployment<CAPTURE>,
_business: BusinessConfig<()>,
_request: DatabaseRequest,
) -> impl Future<Output = Result<Vec<u8>>> + Send {
CALLS.fetch_add(1, Ordering::SeqCst);
async move {
let body = [0u8; BODY];
pending::<()>().await;
std::hint::black_box((&deployment.0, &body));
Ok(Vec::new())
}
}
fn main() {
let small = entry_consumer_layouts_for(&dispatch::<1, 1>).unwrap();
let capture = entry_consumer_layouts_for(&dispatch::<65536, 1>).unwrap();
let body = entry_consumer_layouts_for(&dispatch::<1, 65536>).unwrap();
assert_eq!(
CALLS.load(Ordering::SeqCst),
0,
"layout never invokes dispatch"
);
assert!(capture.normal_environment.size() > small.normal_environment.size());
assert!(capture.normal_factory.size() > small.normal_factory.size());
assert!(capture.normal_body.size() > small.normal_body.size());
assert!(body.normal_body.size() > small.normal_body.size());
assert_eq!(body.normal_factory, small.normal_factory);
assert!(small.normal_environment.align() >= 64);
assert!(small.normal_body.align() >= 64);
assert_eq!(small.owner_cell.allocation, body.owner_cell.allocation);
assert_eq!(small.rejection_body, body.rejection_body);
assert!(small.owner_cell.allocation.size() > small.owner_cell.payload.size());
for (name, layout) in [("small", small), ("capture", capture), ("body", body)] {
println!("{name}: {layout:#?}");
}
println!(
"PASS production consumer type layouts before factory/body/request allocation; reservation/account settlement NOT_ENABLED"
);
}