Repository: rust-lang/rust
File: compiler/rustc_middle/src/query/plumbing.rs (Rust)

Code before:
                    tcx: TyCtxt<'tcx>,
                    provided_value: ProvidedValue<'tcx>,
                ) -> Erased<Value<'tcx>> {
                    // For queries with the `arena_cache` modifier, store the
                    // provided value in an arena and get a reference to it.
                    let value: Value<'tcx> = if_arena_cache!(
                        [$($modifiers)*]
                        {
                            <Value<'tcx> as $crate::query::arena_cached::ArenaCached>::
                                alloc_in_arena
                            (
                                tcx,
                                &tcx.query_system.arenas.$name,
                                provided_value,
                            )
                        }
                        {
                            // Otherwise, the provided value is the value (and `tcx` is unused).
                            let _ = tcx;
                            provided_value
                        }
                    );
                    erase::erase_val(value)
                }

                pub type QueryCache<'tcx> =
                    <Key<'tcx> as $crate::query::QueryKey>::Cache<Erased<Value<'tcx>>>;

                // Ensure that keys grow no larger than 88 bytes by accident.
                // Increase this limit if necessary, but do try to keep the size low if possible
                #[cfg(target_pointer_width = "64")]
                const _: () = {
                    if size_of::<Key<'static>>() > 88 {
                        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 by accident.
                // Increase this limit if necessary, but do try to keep the size low if possible
                #[cfg(target_pointer_width = "64")]
                #[cfg(not(feature = "rustc_randomized_layouts"))]
                const _: () = {
                    if size_of::<Value<'static>>() > 64 {
                        panic!("{}", concat!(
                            "the query `",

Review comment (performance):
I definitely agree with renaming `Storage`.

Because this is macro-heavy code, I place a very high priority on having distinct names for things, both to make searching easier and less noisy, and to make it easier to keep things distinct in my mind without IDE-hover assistance.

For that reason I would prefer something unique, even if it's less elegant. Thankfully we only need to see it in a few places.

Perhaps `QueryCacheImpl`? I don't love it, but it's unique, and feels suitably connected to the `QueryCache` trait without actually colliding.

Code after:
                        }
                        {
                            // Otherwise, the provided value is the value (and `tcx` is unused).
                            let _ = tcx;
                            provided_value
                        }
                    );
                    erase::erase_val(value)
                }

                pub type Cache<'tcx> =
                    <Key<'tcx> as $crate::query::QueryKey>::Cache<Erased<Value<'tcx>>>;

                // Ensure that keys grow no larger than 88 bytes by accident.
                // Increase this limit if necessary, but do try to keep the size low if possible
                #[cfg(target_pointer_width = "64")]
                const _: () = {
                    if size_of::<Key<'static>>() > 88 {
                        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 by accident.
                // Increase this limit if necessary, but do try to keep the size low if possible
                #[cfg(target_pointer_width = "64")]
                #[cfg(not(feature = "rustc_randomized_layouts"))]
                const _: () = {
                    if size_of::<Value<'static>>() > 64 {
                        panic!("{}", concat!(
                            "the query `",
                            stringify!($name),
                            "` has a value type `",
                            stringify!($V),
                            "` that is too large"
                        ));
                    }
                };
            }
        )*

        /// Holds per-query arenas for queries with the `arena_cache` modifier.
        #[derive(Default)]
        pub struct QueryArenas<'tcx> {
            $(
                pub $name: if_arena_cache!(