1
Fork 0

Auto merge of #99181 - lcnr:arenaGTrc, r=wesleywiser

`arena > Rc` for query results

The `Rc`s have to live for the whole duration as their count cannot go below 1 while stored as part of the query results.

By storing them in an arena we should save a bit of memory because we don't have as many independent allocations and also don't have to clone the `Rc` anymore.
This commit is contained in:
bors 2022-07-18 05:50:54 +00:00
commit 880416180b
7 changed files with 16 additions and 14 deletions

View file

@ -9,7 +9,6 @@ use rustc_infer::traits::TraitEngineExt as _;
use rustc_span::source_map::DUMMY_SP;
use std::fmt;
use std::rc::Rc;
pub struct CustomTypeOp<F, G> {
closure: F,
@ -109,7 +108,7 @@ pub fn scrape_region_constraints<'tcx, Op: super::TypeOp<'tcx, Output = R>, R>(
Ok((
TypeOpOutput {
output: value,
constraints: Some(Rc::new(region_constraints)),
constraints: Some(infcx.tcx.arena.alloc(region_constraints)),
error_info: None,
},
region_constraint_data,

View file

@ -10,7 +10,6 @@ use rustc_infer::traits::PredicateObligations;
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
use std::fmt;
use std::rc::Rc;
pub mod ascribe_user_type;
pub mod custom;
@ -41,7 +40,7 @@ pub struct TypeOpOutput<'tcx, Op: TypeOp<'tcx>> {
/// The output from the type op.
pub output: Op::Output,
/// Any region constraints from performing the type op.
pub constraints: Option<Rc<QueryRegionConstraints<'tcx>>>,
pub constraints: Option<&'tcx QueryRegionConstraints<'tcx>>,
/// Used for error reporting to be able to rerun the query
pub error_info: Option<Op::ErrorInfo>,
}
@ -156,11 +155,14 @@ where
}
}
// Promote the final query-region-constraints into a
// (optional) ref-counted vector:
let region_constraints =
if region_constraints.is_empty() { None } else { Some(Rc::new(region_constraints)) };
Ok(TypeOpOutput { output, constraints: region_constraints, error_info })
Ok(TypeOpOutput {
output,
constraints: if region_constraints.is_empty() {
None
} else {
Some(infcx.tcx.arena.alloc(region_constraints))
},
error_info,
})
}
}