Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cb7c75b

Browse files
committedMar 11, 2024
Shrink the size of ClosureTypeInfo to fit into 64 bytes again
1 parent e09cde6 commit cb7c75b

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed
 

‎compiler/rustc_middle/src/query/plumbing.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ macro_rules! define_callbacks {
340340
<$($K)* as keys::Key>::CacheSelector as CacheSelector<'tcx, Erase<$V>>
341341
>::Cache;
342342

343-
// Ensure that keys grow no larger than 72 bytes
343+
// Ensure that keys grow no larger than 72 bytes by accident.
344+
// Increase this limit if necessary, but do try to keep the size low if possible
344345
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
345346
const _: () = {
346347
if mem::size_of::<Key<'static>>() > 72 {
@@ -354,10 +355,11 @@ macro_rules! define_callbacks {
354355
}
355356
};
356357

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

‎compiler/rustc_middle/src/ty/closure.rs

+6-6
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

+14
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ pub struct CtxtInterners<'tcx> {
162162
predefined_opaques_in_body: InternedSet<'tcx, PredefinedOpaquesData<'tcx>>,
163163
fields: InternedSet<'tcx, List<FieldIdx>>,
164164
local_def_ids: InternedSet<'tcx, List<LocalDefId>>,
165+
captures: InternedSet<'tcx, List<&'tcx ty::CapturedPlace<'tcx>>>,
165166
offset_of: InternedSet<'tcx, List<(VariantIdx, FieldIdx)>>,
166167
}
167168

@@ -189,6 +190,7 @@ impl<'tcx> CtxtInterners<'tcx> {
189190
predefined_opaques_in_body: Default::default(),
190191
fields: Default::default(),
191192
local_def_ids: Default::default(),
193+
captures: Default::default(),
192194
offset_of: Default::default(),
193195
}
194196
}
@@ -1773,6 +1775,7 @@ slice_interners!(
17731775
bound_variable_kinds: pub mk_bound_variable_kinds(ty::BoundVariableKind),
17741776
fields: pub mk_fields(FieldIdx),
17751777
local_def_ids: intern_local_def_ids(LocalDefId),
1778+
captures: intern_captures(&'tcx ty::CapturedPlace<'tcx>),
17761779
offset_of: pub mk_offset_of((VariantIdx, FieldIdx)),
17771780
);
17781781

@@ -2023,6 +2026,17 @@ impl<'tcx> TyCtxt<'tcx> {
20232026
T::collect_and_apply(iter, |xs| self.mk_local_def_ids(xs))
20242027
}
20252028

2029+
pub fn mk_captures_from_iter<I, T>(self, iter: I) -> T::Output
2030+
where
2031+
I: Iterator<Item = T>,
2032+
T: CollectAndApply<
2033+
&'tcx ty::CapturedPlace<'tcx>,
2034+
&'tcx List<&'tcx ty::CapturedPlace<'tcx>>,
2035+
>,
2036+
{
2037+
T::collect_and_apply(iter, |xs| self.intern_captures(xs))
2038+
}
2039+
20262040
pub fn mk_const_list_from_iter<I, T>(self, iter: I) -> T::Output
20272041
where
20282042
I: Iterator<Item = T>,

0 commit comments

Comments
 (0)
Failed to load comments.