Rollup merge of #108690 - Zoxc:query-size-limits, r=cjgillot

Place size limits on query keys and values

This just prevents these from growing accidentally too large. I'm not sure if there's an easy way to also print the actual size too.
This commit is contained in:
Matthias Krüger 2023-03-11 15:43:14 +01:00 committed by GitHub
commit 1909d933d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -252,6 +252,36 @@ macro_rules! define_callbacks {
)*
}
$(
// Ensure that keys grow no larger than 64 bytes
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
const _: () = {
if mem::size_of::<query_keys::$name<'static>>() > 64 {
panic!("{}", concat!(
"the query `",
stringify!($name),
"` has a key type `",
stringify!($($K)*),
"` that is too large"
));
}
};
// Ensure that values grow no larger than 64 bytes
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
const _: () = {
if mem::size_of::<query_values::$name<'static>>() > 64 {
panic!("{}", concat!(
"the query `",
stringify!($name),
"` has a value type `",
stringify!($V),
"` that is too large"
));
}
};
)*
pub struct QueryArenas<'tcx> {
$($(#[$attr])* pub $name: query_if_arena!([$($modifiers)*]
(WorkerLocal<TypedArena<<$V as Deref>::Target>>)