Skip to content

Commit

Permalink
Rollup merge of rust-lang#108690 - Zoxc:query-size-limits, r=cjgillot
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JohnTitor authored Mar 8, 2023
2 parents 47c3a48 + 1ccb1de commit 767c1e7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions compiler/rustc_middle/src/ty/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,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>>)
Expand Down

0 comments on commit 767c1e7

Please sign in to comment.