Skip to content

Commit ba5f041

Browse files
committed
Shrink the size of ClosureTypeInfo to fit into 64 bytes again
1 parent 2f2350e commit ba5f041

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ macro_rules! define_callbacks {
338338

339339
pub type Storage<'tcx> = <$($K)* as keys::Key>::Cache<Erase<$V>>;
340340

341-
// Ensure that keys grow no larger than 72 bytes
341+
// Ensure that keys grow no larger than 72 bytes by accident.
342+
// Increase this limit if necessary, but do try to keep the size low if possible
342343
#[cfg(all(any(target_arch = "x86_64", target_arch="aarch64"), target_pointer_width = "64"))]
343344
const _: () = {
344345
if mem::size_of::<Key<'static>>() > 72 {
@@ -352,10 +353,11 @@ macro_rules! define_callbacks {
352353
}
353354
};
354355

355-
// Ensure that values grow no larger than 72 bytes
356+
// Ensure that values grow no larger than 64 bytes by accident.
357+
// Increase this limit if necessary, but do try to keep the size low if possible
356358
#[cfg(all(any(target_arch = "x86_64", target_arch="aarch64"), target_pointer_width = "64"))]
357359
const _: () = {
358-
if mem::size_of::<Value<'static>>() > 72 {
360+
if mem::size_of::<Value<'static>>() > 64 {
359361
panic!("{}", concat!(
360362
"the query `",
361363
stringify!($name),

compiler/rustc_middle/src/ty/closure.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl UpvarId {
4545

4646
/// Information describing the capture of an upvar. This is computed
4747
/// during `typeck`, specifically by `regionck`.
48-
#[derive(PartialEq, Clone, Debug, Copy, TyEncodable, TyDecodable, HashStable)]
48+
#[derive(Eq, PartialEq, Clone, Debug, Copy, TyEncodable, TyDecodable, HashStable, Hash)]
4949
#[derive(TypeFoldable, TypeVisitable)]
5050
pub enum UpvarCapture {
5151
/// Upvar is captured by value. This is always true when the
@@ -73,7 +73,7 @@ pub type RootVariableMinCaptureList<'tcx> = FxIndexMap<hir::HirId, MinCaptureLis
7373
pub type MinCaptureList<'tcx> = Vec<CapturedPlace<'tcx>>;
7474

7575
/// A composite describing a `Place` that is captured by a closure.
76-
#[derive(PartialEq, Clone, Debug, TyEncodable, TyDecodable, HashStable)]
76+
#[derive(Eq, PartialEq, Clone, Debug, TyEncodable, TyDecodable, HashStable, Hash)]
7777
#[derive(TypeFoldable, TypeVisitable)]
7878
pub struct CapturedPlace<'tcx> {
7979
/// Name and span where the binding happens.
@@ -192,7 +192,7 @@ impl<'tcx> CapturedPlace<'tcx> {
192192
#[derive(Copy, Clone, Debug, HashStable)]
193193
pub struct ClosureTypeInfo<'tcx> {
194194
user_provided_sig: ty::CanonicalPolyFnSig<'tcx>,
195-
captures: &'tcx [&'tcx ty::CapturedPlace<'tcx>],
195+
captures: &'tcx ty::List<&'tcx ty::CapturedPlace<'tcx>>,
196196
kind_origin: Option<&'tcx (Span, HirPlace<'tcx>)>,
197197
}
198198

@@ -201,7 +201,7 @@ fn closure_typeinfo<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> ClosureTypeInfo
201201
let typeck_results = tcx.typeck(def);
202202
let user_provided_sig = typeck_results.user_provided_sigs[&def];
203203
let captures = typeck_results.closure_min_captures_flattened(def);
204-
let captures = tcx.arena.alloc_from_iter(captures);
204+
let captures = tcx.mk_captures_from_iter(captures);
205205
let hir_id = tcx.local_def_id_to_hir_id(def);
206206
let kind_origin = typeck_results.closure_kind_origins().get(hir_id);
207207
ClosureTypeInfo { user_provided_sig, captures, kind_origin }
@@ -253,7 +253,7 @@ pub fn is_ancestor_or_same_capture(
253253
/// Part of `MinCaptureInformationMap`; describes the capture kind (&, &mut, move)
254254
/// for a particular capture as well as identifying the part of the source code
255255
/// that triggered this capture to occur.
256-
#[derive(PartialEq, Clone, Debug, Copy, TyEncodable, TyDecodable, HashStable)]
256+
#[derive(Eq, PartialEq, Clone, Debug, Copy, TyEncodable, TyDecodable, HashStable, Hash)]
257257
#[derive(TypeFoldable, TypeVisitable)]
258258
pub struct CaptureInfo {
259259
/// Expr Id pointing to use that resulted in selecting the current capture kind
@@ -332,7 +332,7 @@ pub fn place_to_string_for_capture<'tcx>(tcx: TyCtxt<'tcx>, place: &HirPlace<'tc
332332
curr_string
333333
}
334334

335-
#[derive(Clone, PartialEq, Debug, TyEncodable, TyDecodable, Copy, HashStable)]
335+
#[derive(Eq, Clone, PartialEq, Debug, TyEncodable, TyDecodable, Copy, HashStable, Hash)]
336336
#[derive(TypeFoldable, TypeVisitable)]
337337
pub enum BorrowKind {
338338
/// Data must be immutable and is aliasable.

compiler/rustc_middle/src/ty/context.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ pub struct CtxtInterners<'tcx> {
166166
predefined_opaques_in_body: InternedSet<'tcx, PredefinedOpaquesData<'tcx>>,
167167
fields: InternedSet<'tcx, List<FieldIdx>>,
168168
local_def_ids: InternedSet<'tcx, List<LocalDefId>>,
169+
captures: InternedSet<'tcx, List<&'tcx ty::CapturedPlace<'tcx>>>,
169170
offset_of: InternedSet<'tcx, List<(VariantIdx, FieldIdx)>>,
170171
}
171172

@@ -193,6 +194,7 @@ impl<'tcx> CtxtInterners<'tcx> {
193194
predefined_opaques_in_body: Default::default(),
194195
fields: Default::default(),
195196
local_def_ids: Default::default(),
197+
captures: Default::default(),
196198
offset_of: Default::default(),
197199
}
198200
}
@@ -1906,6 +1908,7 @@ slice_interners!(
19061908
bound_variable_kinds: pub mk_bound_variable_kinds(ty::BoundVariableKind),
19071909
fields: pub mk_fields(FieldIdx),
19081910
local_def_ids: intern_local_def_ids(LocalDefId),
1911+
captures: intern_captures(&'tcx ty::CapturedPlace<'tcx>),
19091912
offset_of: pub mk_offset_of((VariantIdx, FieldIdx)),
19101913
);
19111914

@@ -2227,6 +2230,17 @@ impl<'tcx> TyCtxt<'tcx> {
22272230
T::collect_and_apply(iter, |xs| self.mk_local_def_ids(xs))
22282231
}
22292232

2233+
pub fn mk_captures_from_iter<I, T>(self, iter: I) -> T::Output
2234+
where
2235+
I: Iterator<Item = T>,
2236+
T: CollectAndApply<
2237+
&'tcx ty::CapturedPlace<'tcx>,
2238+
&'tcx List<&'tcx ty::CapturedPlace<'tcx>>,
2239+
>,
2240+
{
2241+
T::collect_and_apply(iter, |xs| self.intern_captures(xs))
2242+
}
2243+
22302244
pub fn mk_const_list_from_iter<I, T>(self, iter: I) -> T::Output
22312245
where
22322246
I: Iterator<Item = T>,

0 commit comments

Comments
 (0)