Auto merge of #93511 - cjgillot:query-copy, r=oli-obk

Ensure that queries only return Copy types.

This should pervent the perf footgun of returning a result with an expensive `Clone` impl (like a `Vec` of a hash map).

I went for the stupid solution of allocating on an arena everything that was not `Copy`. Some query results could be made Copy easily, but I did not really investigate.
This commit is contained in:
bors 2022-02-10 09:37:07 +00:00
commit 56cd04af5c
27 changed files with 208 additions and 182 deletions

View file

@ -22,7 +22,7 @@ use rustc_middle::ty::{self, TyCtxt};
pub fn codegen_fulfill_obligation<'tcx>(
tcx: TyCtxt<'tcx>,
(param_env, trait_ref): (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>),
) -> Result<ImplSource<'tcx, ()>, ErrorReported> {
) -> Result<&'tcx ImplSource<'tcx, ()>, ErrorReported> {
// Remove any references to regions; this helps improve caching.
let trait_ref = tcx.erase_regions(trait_ref);
// We expect the input to be fully normalized.
@ -96,7 +96,7 @@ pub fn codegen_fulfill_obligation<'tcx>(
drop(infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types());
debug!("Cache miss: {:?} => {:?}", trait_ref, impl_source);
Ok(impl_source)
Ok(&*tcx.arena.alloc(impl_source))
})
}

View file

@ -262,7 +262,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
.tcx
.diagnostic_hir_wf_check((tcx.erase_regions(obligation.predicate), *wf_loc))
{
obligation.cause = cause;
obligation.cause = cause.clone();
span = obligation.cause.span;
}
}