Skip to content

Commit 767c1e7

Browse files
authored
Rollup merge of rust-lang#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.
2 parents 47c3a48 + 1ccb1de commit 767c1e7

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

compiler/rustc_middle/src/ty/query.rs

+30
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,36 @@ macro_rules! define_callbacks {
250250
)*
251251
}
252252

253+
$(
254+
// Ensure that keys grow no larger than 64 bytes
255+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
256+
const _: () = {
257+
if mem::size_of::<query_keys::$name<'static>>() > 64 {
258+
panic!("{}", concat!(
259+
"the query `",
260+
stringify!($name),
261+
"` has a key type `",
262+
stringify!($($K)*),
263+
"` that is too large"
264+
));
265+
}
266+
};
267+
268+
// Ensure that values grow no larger than 64 bytes
269+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
270+
const _: () = {
271+
if mem::size_of::<query_values::$name<'static>>() > 64 {
272+
panic!("{}", concat!(
273+
"the query `",
274+
stringify!($name),
275+
"` has a value type `",
276+
stringify!($V),
277+
"` that is too large"
278+
));
279+
}
280+
};
281+
)*
282+
253283
pub struct QueryArenas<'tcx> {
254284
$($(#[$attr])* pub $name: query_if_arena!([$($modifiers)*]
255285
(WorkerLocal<TypedArena<<$V as Deref>::Target>>)

0 commit comments

Comments
 (0)