mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
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:
commit
880416180b
@ -39,7 +39,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
|
|
||||||
let TypeOpOutput { output, constraints, error_info } = op.fully_perform(self.infcx)?;
|
let TypeOpOutput { output, constraints, error_info } = op.fully_perform(self.infcx)?;
|
||||||
|
|
||||||
if let Some(data) = &constraints {
|
if let Some(data) = constraints {
|
||||||
self.push_region_constraints(locations, category, data);
|
self.push_region_constraints(locations, category, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
|
|||||||
/// the same time, compute and add any implied bounds that come
|
/// the same time, compute and add any implied bounds that come
|
||||||
/// from this local.
|
/// from this local.
|
||||||
#[instrument(level = "debug", skip(self))]
|
#[instrument(level = "debug", skip(self))]
|
||||||
fn add_implied_bounds(&mut self, ty: Ty<'tcx>) -> Option<Rc<QueryRegionConstraints<'tcx>>> {
|
fn add_implied_bounds(&mut self, ty: Ty<'tcx>) -> Option<&'tcx QueryRegionConstraints<'tcx>> {
|
||||||
let TypeOpOutput { output: bounds, constraints, .. } = self
|
let TypeOpOutput { output: bounds, constraints, .. } = self
|
||||||
.param_env
|
.param_env
|
||||||
.and(type_op::implied_outlives_bounds::ImpliedOutlivesBounds { ty })
|
.and(type_op::implied_outlives_bounds::ImpliedOutlivesBounds { ty })
|
||||||
|
@ -225,7 +225,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
|
|
||||||
debug!("{:?} normalized to {:?}", t, norm_ty);
|
debug!("{:?} normalized to {:?}", t, norm_ty);
|
||||||
|
|
||||||
for data in constraints.into_iter().collect::<Vec<_>>() {
|
for data in constraints {
|
||||||
ConstraintConversion::new(
|
ConstraintConversion::new(
|
||||||
self.infcx,
|
self.infcx,
|
||||||
&self.borrowck_context.universal_regions,
|
&self.borrowck_context.universal_regions,
|
||||||
|
@ -98,7 +98,7 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
|
|||||||
|
|
||||||
struct DropData<'tcx> {
|
struct DropData<'tcx> {
|
||||||
dropck_result: DropckOutlivesResult<'tcx>,
|
dropck_result: DropckOutlivesResult<'tcx>,
|
||||||
region_constraint_data: Option<Rc<QueryRegionConstraints<'tcx>>>,
|
region_constraint_data: Option<&'tcx QueryRegionConstraints<'tcx>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LivenessResults<'me, 'typeck, 'flow, 'tcx> {
|
struct LivenessResults<'me, 'typeck, 'flow, 'tcx> {
|
||||||
|
@ -55,6 +55,7 @@ macro_rules! arena_types {
|
|||||||
[] dtorck_constraint: rustc_middle::traits::query::DropckConstraint<'tcx>,
|
[] dtorck_constraint: rustc_middle::traits::query::DropckConstraint<'tcx>,
|
||||||
[] candidate_step: rustc_middle::traits::query::CandidateStep<'tcx>,
|
[] candidate_step: rustc_middle::traits::query::CandidateStep<'tcx>,
|
||||||
[] autoderef_bad_ty: rustc_middle::traits::query::MethodAutoderefBadTy<'tcx>,
|
[] autoderef_bad_ty: rustc_middle::traits::query::MethodAutoderefBadTy<'tcx>,
|
||||||
|
[] query_region_constraints: rustc_middle::infer::canonical::QueryRegionConstraints<'tcx>,
|
||||||
[] type_op_subtype:
|
[] type_op_subtype:
|
||||||
rustc_middle::infer::canonical::Canonical<'tcx,
|
rustc_middle::infer::canonical::Canonical<'tcx,
|
||||||
rustc_middle::infer::canonical::QueryResponse<'tcx, ()>
|
rustc_middle::infer::canonical::QueryResponse<'tcx, ()>
|
||||||
|
@ -9,7 +9,6 @@ use rustc_infer::traits::TraitEngineExt as _;
|
|||||||
use rustc_span::source_map::DUMMY_SP;
|
use rustc_span::source_map::DUMMY_SP;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
pub struct CustomTypeOp<F, G> {
|
pub struct CustomTypeOp<F, G> {
|
||||||
closure: F,
|
closure: F,
|
||||||
@ -109,7 +108,7 @@ pub fn scrape_region_constraints<'tcx, Op: super::TypeOp<'tcx, Output = R>, R>(
|
|||||||
Ok((
|
Ok((
|
||||||
TypeOpOutput {
|
TypeOpOutput {
|
||||||
output: value,
|
output: value,
|
||||||
constraints: Some(Rc::new(region_constraints)),
|
constraints: Some(infcx.tcx.arena.alloc(region_constraints)),
|
||||||
error_info: None,
|
error_info: None,
|
||||||
},
|
},
|
||||||
region_constraint_data,
|
region_constraint_data,
|
||||||
|
@ -10,7 +10,6 @@ use rustc_infer::traits::PredicateObligations;
|
|||||||
use rustc_middle::ty::fold::TypeFoldable;
|
use rustc_middle::ty::fold::TypeFoldable;
|
||||||
use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
|
use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
pub mod ascribe_user_type;
|
pub mod ascribe_user_type;
|
||||||
pub mod custom;
|
pub mod custom;
|
||||||
@ -41,7 +40,7 @@ pub struct TypeOpOutput<'tcx, Op: TypeOp<'tcx>> {
|
|||||||
/// The output from the type op.
|
/// The output from the type op.
|
||||||
pub output: Op::Output,
|
pub output: Op::Output,
|
||||||
/// Any region constraints from performing the type op.
|
/// 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
|
/// Used for error reporting to be able to rerun the query
|
||||||
pub error_info: Option<Op::ErrorInfo>,
|
pub error_info: Option<Op::ErrorInfo>,
|
||||||
}
|
}
|
||||||
@ -156,11 +155,14 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Promote the final query-region-constraints into a
|
Ok(TypeOpOutput {
|
||||||
// (optional) ref-counted vector:
|
output,
|
||||||
let region_constraints =
|
constraints: if region_constraints.is_empty() {
|
||||||
if region_constraints.is_empty() { None } else { Some(Rc::new(region_constraints)) };
|
None
|
||||||
|
} else {
|
||||||
Ok(TypeOpOutput { output, constraints: region_constraints, error_info })
|
Some(infcx.tcx.arena.alloc(region_constraints))
|
||||||
|
},
|
||||||
|
error_info,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user