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:
commit
56cd04af5c
27 changed files with 208 additions and 182 deletions
|
@ -9,7 +9,6 @@ use crate::hir::def::DefKind;
|
|||
use crate::hir::def_id::DefId;
|
||||
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::Namespace;
|
||||
|
@ -59,7 +58,7 @@ struct ProbeContext<'a, 'tcx> {
|
|||
/// This is the OriginalQueryValues for the steps queries
|
||||
/// that are answered in steps.
|
||||
orig_steps_var_values: OriginalQueryValues<'tcx>,
|
||||
steps: Lrc<Vec<CandidateStep<'tcx>>>,
|
||||
steps: &'tcx [CandidateStep<'tcx>],
|
||||
|
||||
inherent_candidates: Vec<Candidate<'tcx>>,
|
||||
extension_candidates: Vec<Candidate<'tcx>>,
|
||||
|
@ -364,7 +363,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
param_env_and_self_ty, self_ty
|
||||
);
|
||||
MethodAutoderefStepsResult {
|
||||
steps: Lrc::new(vec![CandidateStep {
|
||||
steps: infcx.tcx.arena.alloc_from_iter([CandidateStep {
|
||||
self_ty: self.make_query_response_ignoring_pending_obligations(
|
||||
canonical_inference_vars,
|
||||
self_ty,
|
||||
|
@ -533,8 +532,8 @@ fn method_autoderef_steps<'tcx>(
|
|||
debug!("method_autoderef_steps: steps={:?} opt_bad_ty={:?}", steps, opt_bad_ty);
|
||||
|
||||
MethodAutoderefStepsResult {
|
||||
steps: Lrc::new(steps),
|
||||
opt_bad_ty: opt_bad_ty.map(Lrc::new),
|
||||
steps: tcx.arena.alloc_from_iter(steps),
|
||||
opt_bad_ty: opt_bad_ty.map(|ty| &*tcx.arena.alloc(ty)),
|
||||
reached_recursion_limit: autoderef.reached_recursion_limit(),
|
||||
}
|
||||
})
|
||||
|
@ -548,7 +547,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||
method_name: Option<Ident>,
|
||||
return_type: Option<Ty<'tcx>>,
|
||||
orig_steps_var_values: OriginalQueryValues<'tcx>,
|
||||
steps: Lrc<Vec<CandidateStep<'tcx>>>,
|
||||
steps: &'tcx [CandidateStep<'tcx>],
|
||||
is_suggestion: IsSuggestion,
|
||||
scope_expr_id: hir::HirId,
|
||||
) -> ProbeContext<'a, 'tcx> {
|
||||
|
@ -605,8 +604,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn assemble_inherent_candidates(&mut self) {
|
||||
let steps = Lrc::clone(&self.steps);
|
||||
for step in steps.iter() {
|
||||
for step in self.steps.iter() {
|
||||
self.assemble_probe(&step.self_ty);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1696,7 +1696,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
kind: ty::GenericParamDefKind::Lifetime,
|
||||
}));
|
||||
|
||||
let object_lifetime_defaults = tcx.object_lifetime_defaults(hir_id);
|
||||
let object_lifetime_defaults = tcx.object_lifetime_defaults(hir_id.owner);
|
||||
|
||||
// Now create the real type and const parameters.
|
||||
let type_start = own_start - has_self as u32 + params.len() as u32;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue