Skip to content

Commit 80e1112

Browse files
authored
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.
2 parents d02ed0a + 1ccb1de commit 80e1112

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
@@ -252,6 +252,36 @@ macro_rules! define_callbacks {
252252
)*
253253
}
254254

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

0 commit comments

Comments
 (0)