Skip to content

Commit 5cb86fe

Browse files
committed
don't store OriginalQueryValues::universe_map
ParamEnv is canonicalized in *queries input* rather than query response. In such case we don't "preserve universes" of canonical variable. This means that `universe_map` always has the default value, which is wasteful to store in the cache.
1 parent d54bfb0 commit 5cb86fe

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ impl<'tcx> InferCtxt<'tcx> {
150150
{
151151
let (param_env, value) = value.into_parts();
152152
let base = self.tcx.canonical_param_env_cache.get_or_insert(
153+
self.tcx,
153154
param_env,
154155
query_state,
155156
|query_state| {

compiler/rustc_middle/src/infer/canonical.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -300,29 +300,36 @@ pub struct CanonicalParamEnvCache<'tcx> {
300300
map: Lock<
301301
FxHashMap<
302302
ty::ParamEnv<'tcx>,
303-
(Canonical<'tcx, ty::ParamEnv<'tcx>>, OriginalQueryValues<'tcx>),
303+
(Canonical<'tcx, ty::ParamEnv<'tcx>>, &'tcx [GenericArg<'tcx>]),
304304
>,
305305
>,
306306
}
307307

308308
impl<'tcx> CanonicalParamEnvCache<'tcx> {
309309
pub fn get_or_insert(
310310
&self,
311+
tcx: TyCtxt<'tcx>,
311312
key: ty::ParamEnv<'tcx>,
312313
state: &mut OriginalQueryValues<'tcx>,
313314
canonicalize_op: impl FnOnce(
314315
&mut OriginalQueryValues<'tcx>,
315316
) -> Canonical<'tcx, ty::ParamEnv<'tcx>>,
316317
) -> Canonical<'tcx, ty::ParamEnv<'tcx>> {
318+
assert_eq!(state.var_values.len(), 0);
319+
assert_eq!(state.universe_map.len(), 1);
320+
debug_assert_eq!(&*state.universe_map, &[ty::UniverseIndex::ROOT]);
321+
317322
match self.map.borrow().entry(key) {
318323
Entry::Occupied(e) => {
319-
let (canonical, state_cached) = e.get();
320-
state.clone_from(state_cached);
324+
let (canonical, var_values) = e.get();
325+
state.var_values.extend_from_slice(var_values);
321326
canonical.clone()
322327
}
323328
Entry::Vacant(e) => {
324329
let canonical = canonicalize_op(state);
325-
e.insert((canonical.clone(), state.clone()));
330+
let OriginalQueryValues { var_values, universe_map } = state;
331+
assert_eq!(universe_map.len(), 1);
332+
e.insert((canonical.clone(), tcx.arena.alloc_slice(var_values)));
326333
canonical
327334
}
328335
}

0 commit comments

Comments
 (0)