Skip to content

Commit 8804161

Browse files
committed
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.
2 parents 2fa64d0 + 0fc5296 commit 8804161

File tree

7 files changed

+16
-14
lines changed

7 files changed

+16
-14
lines changed

compiler/rustc_borrowck/src/type_check/canonical.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
3939

4040
let TypeOpOutput { output, constraints, error_info } = op.fully_perform(self.infcx)?;
4141

42-
if let Some(data) = &constraints {
42+
if let Some(data) = constraints {
4343
self.push_region_constraints(locations, category, data);
4444
}
4545

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
335335
/// the same time, compute and add any implied bounds that come
336336
/// from this local.
337337
#[instrument(level = "debug", skip(self))]
338-
fn add_implied_bounds(&mut self, ty: Ty<'tcx>) -> Option<Rc<QueryRegionConstraints<'tcx>>> {
338+
fn add_implied_bounds(&mut self, ty: Ty<'tcx>) -> Option<&'tcx QueryRegionConstraints<'tcx>> {
339339
let TypeOpOutput { output: bounds, constraints, .. } = self
340340
.param_env
341341
.and(type_op::implied_outlives_bounds::ImpliedOutlivesBounds { ty })

compiler/rustc_borrowck/src/type_check/input_output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
225225

226226
debug!("{:?} normalized to {:?}", t, norm_ty);
227227

228-
for data in constraints.into_iter().collect::<Vec<_>>() {
228+
for data in constraints {
229229
ConstraintConversion::new(
230230
self.infcx,
231231
&self.borrowck_context.universal_regions,

compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
9898

9999
struct DropData<'tcx> {
100100
dropck_result: DropckOutlivesResult<'tcx>,
101-
region_constraint_data: Option<Rc<QueryRegionConstraints<'tcx>>>,
101+
region_constraint_data: Option<&'tcx QueryRegionConstraints<'tcx>>,
102102
}
103103

104104
struct LivenessResults<'me, 'typeck, 'flow, 'tcx> {

compiler/rustc_middle/src/arena.rs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ macro_rules! arena_types {
5555
[] dtorck_constraint: rustc_middle::traits::query::DropckConstraint<'tcx>,
5656
[] candidate_step: rustc_middle::traits::query::CandidateStep<'tcx>,
5757
[] autoderef_bad_ty: rustc_middle::traits::query::MethodAutoderefBadTy<'tcx>,
58+
[] query_region_constraints: rustc_middle::infer::canonical::QueryRegionConstraints<'tcx>,
5859
[] type_op_subtype:
5960
rustc_middle::infer::canonical::Canonical<'tcx,
6061
rustc_middle::infer::canonical::QueryResponse<'tcx, ()>

compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_infer::traits::TraitEngineExt as _;
99
use rustc_span::source_map::DUMMY_SP;
1010

1111
use std::fmt;
12-
use std::rc::Rc;
1312

1413
pub struct CustomTypeOp<F, G> {
1514
closure: F,
@@ -109,7 +108,7 @@ pub fn scrape_region_constraints<'tcx, Op: super::TypeOp<'tcx, Output = R>, R>(
109108
Ok((
110109
TypeOpOutput {
111110
output: value,
112-
constraints: Some(Rc::new(region_constraints)),
111+
constraints: Some(infcx.tcx.arena.alloc(region_constraints)),
113112
error_info: None,
114113
},
115114
region_constraint_data,

compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc_infer::traits::PredicateObligations;
1010
use rustc_middle::ty::fold::TypeFoldable;
1111
use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
1212
use std::fmt;
13-
use std::rc::Rc;
1413

1514
pub mod ascribe_user_type;
1615
pub mod custom;
@@ -41,7 +40,7 @@ pub struct TypeOpOutput<'tcx, Op: TypeOp<'tcx>> {
4140
/// The output from the type op.
4241
pub output: Op::Output,
4342
/// Any region constraints from performing the type op.
44-
pub constraints: Option<Rc<QueryRegionConstraints<'tcx>>>,
43+
pub constraints: Option<&'tcx QueryRegionConstraints<'tcx>>,
4544
/// Used for error reporting to be able to rerun the query
4645
pub error_info: Option<Op::ErrorInfo>,
4746
}
@@ -156,11 +155,14 @@ where
156155
}
157156
}
158157

159-
// Promote the final query-region-constraints into a
160-
// (optional) ref-counted vector:
161-
let region_constraints =
162-
if region_constraints.is_empty() { None } else { Some(Rc::new(region_constraints)) };
163-
164-
Ok(TypeOpOutput { output, constraints: region_constraints, error_info })
158+
Ok(TypeOpOutput {
159+
output,
160+
constraints: if region_constraints.is_empty() {
161+
None
162+
} else {
163+
Some(infcx.tcx.arena.alloc(region_constraints))
164+
},
165+
error_info,
166+
})
165167
}
166168
}

0 commit comments

Comments
 (0)