Skip to content

Commit 7402a39

Browse files
committed
Auto merge of #76244 - vandenheuvel:remove__paramenv__def_id, r=nikomatsakis
Removing the `def_id` field from hot `ParamEnv` to make it smaller This PR addresses #74865.
2 parents a055c5a + 7dad29d commit 7402a39

File tree

35 files changed

+288
-337
lines changed

35 files changed

+288
-337
lines changed

compiler/rustc_infer/src/infer/outlives/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ pub fn explicit_outlives_bounds<'tcx>(
2626
| ty::PredicateAtom::ClosureKind(..)
2727
| ty::PredicateAtom::TypeOutlives(..)
2828
| ty::PredicateAtom::ConstEvaluatable(..)
29-
| ty::PredicateAtom::ConstEquate(..) => None,
29+
| ty::PredicateAtom::ConstEquate(..)
30+
| ty::PredicateAtom::TypeWellFormedFromEnv(..) => None,
3031
ty::PredicateAtom::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
3132
Some(OutlivesBound::RegionSubRegion(r_b, r_a))
3233
}

compiler/rustc_infer/src/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
5757

5858
// `PredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
5959
#[cfg(target_arch = "x86_64")]
60-
static_assert_size!(PredicateObligation<'_>, 40);
60+
static_assert_size!(PredicateObligation<'_>, 32);
6161

6262
pub type Obligations<'tcx, O> = Vec<Obligation<'tcx, O>>;
6363
pub type PredicateObligations<'tcx> = Vec<PredicateObligation<'tcx>>;

compiler/rustc_infer/src/traits/util.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ impl Elaborator<'tcx> {
236236
.map(|predicate| predicate_obligation(predicate, None)),
237237
);
238238
}
239+
ty::PredicateAtom::TypeWellFormedFromEnv(..) => {
240+
// Nothing to elaborate
241+
}
239242
}
240243
}
241244
}

compiler/rustc_lint/src/builtin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,8 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
12281228
ClosureKind(..) |
12291229
Subtype(..) |
12301230
ConstEvaluatable(..) |
1231-
ConstEquate(..) => continue,
1231+
ConstEquate(..) |
1232+
TypeWellFormedFromEnv(..) => continue,
12321233
};
12331234
if predicate.is_global() {
12341235
cx.struct_span_lint(TRIVIAL_BOUNDS, span, |lint| {

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ rustc_queries! {
13991399
}
14001400

14011401
query evaluate_goal(
1402-
goal: traits::ChalkCanonicalGoal<'tcx>
1402+
goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
14031403
) -> Result<
14041404
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
14051405
NoSolution

compiler/rustc_middle/src/traits/chalk.rs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66
//! interned Chalk types.
77
88
use rustc_middle::mir::interpret::ConstValue;
9-
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
10-
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
9+
use rustc_middle::ty::{self, AdtDef, TyCtxt};
1110

1211
use rustc_hir::def_id::DefId;
1312
use rustc_target::spec::abi::Abi;
1413

15-
use smallvec::SmallVec;
16-
1714
use std::cmp::Ordering;
1815
use std::fmt;
1916
use std::hash::{Hash, Hasher};
@@ -376,31 +373,10 @@ impl<'tcx> chalk_ir::interner::HasInterner for RustInterner<'tcx> {
376373
type Interner = Self;
377374
}
378375

379-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
380-
pub enum ChalkEnvironmentClause<'tcx> {
381-
/// A normal rust `ty::Predicate` in the environment.
382-
Predicate(ty::Predicate<'tcx>),
383-
/// A special clause in the environment that gets lowered to
384-
/// `chalk_ir::FromEnv::Ty`.
385-
TypeFromEnv(Ty<'tcx>),
386-
}
387-
388-
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ChalkEnvironmentClause<'tcx>> {
389-
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
390-
let v = self.iter().map(|t| t.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
391-
folder.tcx().intern_chalk_environment_clause_list(&v)
392-
}
393-
394-
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
395-
self.iter().any(|t| t.visit_with(visitor))
396-
}
397-
}
398-
/// We have to elaborate the environment of a chalk goal *before*
399-
/// canonicalization. This type wraps the predicate and the elaborated
400-
/// environment.
376+
/// A chalk environment and goal.
401377
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
402378
pub struct ChalkEnvironmentAndGoal<'tcx> {
403-
pub environment: &'tcx ty::List<ChalkEnvironmentClause<'tcx>>,
379+
pub environment: &'tcx ty::List<ty::Predicate<'tcx>>,
404380
pub goal: ty::Predicate<'tcx>,
405381
}
406382

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ use std::rc::Rc;
2626

2727
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
2828

29-
pub type ChalkCanonicalGoal<'tcx> = Canonical<'tcx, ChalkEnvironmentAndGoal<'tcx>>;
29+
pub type CanonicalChalkEnvironmentAndGoal<'tcx> = Canonical<'tcx, ChalkEnvironmentAndGoal<'tcx>>;
3030

3131
pub use self::ImplSource::*;
3232
pub use self::ObligationCauseCode::*;
3333

34-
pub use self::chalk::{
35-
ChalkEnvironmentAndGoal, ChalkEnvironmentClause, RustInterner as ChalkRustInterner,
36-
};
34+
pub use self::chalk::{ChalkEnvironmentAndGoal, RustInterner as ChalkRustInterner};
3735

3836
/// Depending on the stage of compilation, we want projection to be
3937
/// more or less conservative.

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ pub struct CtxtInterners<'tcx> {
9191
projs: InternedSet<'tcx, List<ProjectionKind>>,
9292
place_elems: InternedSet<'tcx, List<PlaceElem<'tcx>>>,
9393
const_: InternedSet<'tcx, Const<'tcx>>,
94-
95-
chalk_environment_clause_list: InternedSet<'tcx, List<traits::ChalkEnvironmentClause<'tcx>>>,
9694
}
9795

9896
impl<'tcx> CtxtInterners<'tcx> {
@@ -110,7 +108,6 @@ impl<'tcx> CtxtInterners<'tcx> {
110108
projs: Default::default(),
111109
place_elems: Default::default(),
112110
const_: Default::default(),
113-
chalk_environment_clause_list: Default::default(),
114111
}
115112
}
116113

@@ -2041,7 +2038,7 @@ direct_interners! {
20412038
}
20422039

20432040
macro_rules! slice_interners {
2044-
($($field:ident: $method:ident($ty:ty)),+) => (
2041+
($($field:ident: $method:ident($ty:ty)),+ $(,)?) => (
20452042
$(impl<'tcx> TyCtxt<'tcx> {
20462043
pub fn $method(self, v: &[$ty]) -> &'tcx List<$ty> {
20472044
self.interners.$field.intern_ref(v, || {
@@ -2060,8 +2057,6 @@ slice_interners!(
20602057
predicates: _intern_predicates(Predicate<'tcx>),
20612058
projs: _intern_projs(ProjectionKind),
20622059
place_elems: _intern_place_elems(PlaceElem<'tcx>),
2063-
chalk_environment_clause_list:
2064-
_intern_chalk_environment_clause_list(traits::ChalkEnvironmentClause<'tcx>)
20652060
);
20662061

20672062
impl<'tcx> TyCtxt<'tcx> {
@@ -2460,13 +2455,6 @@ impl<'tcx> TyCtxt<'tcx> {
24602455
if ts.is_empty() { List::empty() } else { self._intern_canonical_var_infos(ts) }
24612456
}
24622457

2463-
pub fn intern_chalk_environment_clause_list(
2464-
self,
2465-
ts: &[traits::ChalkEnvironmentClause<'tcx>],
2466-
) -> &'tcx List<traits::ChalkEnvironmentClause<'tcx>> {
2467-
if ts.is_empty() { List::empty() } else { self._intern_chalk_environment_clause_list(ts) }
2468-
}
2469-
24702458
pub fn mk_fn_sig<I>(
24712459
self,
24722460
inputs: I,
@@ -2524,18 +2512,6 @@ impl<'tcx> TyCtxt<'tcx> {
25242512
self.mk_substs(iter::once(self_ty.into()).chain(rest.iter().cloned()))
25252513
}
25262514

2527-
pub fn mk_chalk_environment_clause_list<
2528-
I: InternAs<
2529-
[traits::ChalkEnvironmentClause<'tcx>],
2530-
&'tcx List<traits::ChalkEnvironmentClause<'tcx>>,
2531-
>,
2532-
>(
2533-
self,
2534-
iter: I,
2535-
) -> I::Output {
2536-
iter.intern_with(|xs| self.intern_chalk_environment_clause_list(xs))
2537-
}
2538-
25392515
/// Walks upwards from `id` to find a node which might change lint levels with attributes.
25402516
/// It stops at `bound` and just returns it if reached.
25412517
pub fn maybe_lint_level_root_bounded(self, mut id: HirId, bound: HirId) -> HirId {

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ impl FlagComputation {
249249
self.add_const(expected);
250250
self.add_const(found);
251251
}
252+
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
253+
self.add_ty(ty);
254+
}
252255
}
253256
}
254257

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,11 @@ pub enum PredicateAtom<'tcx> {
11551155

11561156
/// Constants must be equal. The first component is the const that is expected.
11571157
ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>),
1158+
1159+
/// Represents a type found in the environment that we can use for implied bounds.
1160+
///
1161+
/// Only used for Chalk.
1162+
TypeWellFormedFromEnv(Ty<'tcx>),
11581163
}
11591164

11601165
impl<'tcx> PredicateAtom<'tcx> {
@@ -1450,7 +1455,8 @@ impl<'tcx> Predicate<'tcx> {
14501455
| PredicateAtom::ClosureKind(..)
14511456
| PredicateAtom::TypeOutlives(..)
14521457
| PredicateAtom::ConstEvaluatable(..)
1453-
| PredicateAtom::ConstEquate(..) => None,
1458+
| PredicateAtom::ConstEquate(..)
1459+
| PredicateAtom::TypeWellFormedFromEnv(..) => None,
14541460
}
14551461
}
14561462

@@ -1465,7 +1471,8 @@ impl<'tcx> Predicate<'tcx> {
14651471
| PredicateAtom::ObjectSafe(..)
14661472
| PredicateAtom::ClosureKind(..)
14671473
| PredicateAtom::ConstEvaluatable(..)
1468-
| PredicateAtom::ConstEquate(..) => None,
1474+
| PredicateAtom::ConstEquate(..)
1475+
| PredicateAtom::TypeWellFormedFromEnv(..) => None,
14691476
}
14701477
}
14711478
}
@@ -1738,11 +1745,6 @@ pub struct ParamEnv<'tcx> {
17381745
///
17391746
/// Note: This is packed, use the reveal() method to access it.
17401747
packed: CopyTaggedPtr<&'tcx List<Predicate<'tcx>>, traits::Reveal, true>,
1741-
1742-
/// If this `ParamEnv` comes from a call to `tcx.param_env(def_id)`,
1743-
/// register that `def_id` (useful for transitioning to the chalk trait
1744-
/// solver).
1745-
pub def_id: Option<DefId>,
17461748
}
17471749

17481750
unsafe impl rustc_data_structures::tagged_ptr::Tag for traits::Reveal {
@@ -1767,7 +1769,6 @@ impl<'tcx> fmt::Debug for ParamEnv<'tcx> {
17671769
f.debug_struct("ParamEnv")
17681770
.field("caller_bounds", &self.caller_bounds())
17691771
.field("reveal", &self.reveal())
1770-
.field("def_id", &self.def_id)
17711772
.finish()
17721773
}
17731774
}
@@ -1776,23 +1777,16 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ParamEnv<'tcx> {
17761777
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
17771778
self.caller_bounds().hash_stable(hcx, hasher);
17781779
self.reveal().hash_stable(hcx, hasher);
1779-
self.def_id.hash_stable(hcx, hasher);
17801780
}
17811781
}
17821782

17831783
impl<'tcx> TypeFoldable<'tcx> for ParamEnv<'tcx> {
17841784
fn super_fold_with<F: ty::fold::TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
1785-
ParamEnv::new(
1786-
self.caller_bounds().fold_with(folder),
1787-
self.reveal().fold_with(folder),
1788-
self.def_id.fold_with(folder),
1789-
)
1785+
ParamEnv::new(self.caller_bounds().fold_with(folder), self.reveal().fold_with(folder))
17901786
}
17911787

17921788
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
1793-
self.caller_bounds().visit_with(visitor)
1794-
|| self.reveal().visit_with(visitor)
1795-
|| self.def_id.visit_with(visitor)
1789+
self.caller_bounds().visit_with(visitor) || self.reveal().visit_with(visitor)
17961790
}
17971791
}
17981792

@@ -1803,7 +1797,7 @@ impl<'tcx> ParamEnv<'tcx> {
18031797
/// type-checking.
18041798
#[inline]
18051799
pub fn empty() -> Self {
1806-
Self::new(List::empty(), Reveal::UserFacing, None)
1800+
Self::new(List::empty(), Reveal::UserFacing)
18071801
}
18081802

18091803
#[inline]
@@ -1825,17 +1819,13 @@ impl<'tcx> ParamEnv<'tcx> {
18251819
/// or invoke `param_env.with_reveal_all()`.
18261820
#[inline]
18271821
pub fn reveal_all() -> Self {
1828-
Self::new(List::empty(), Reveal::All, None)
1822+
Self::new(List::empty(), Reveal::All)
18291823
}
18301824

18311825
/// Construct a trait environment with the given set of predicates.
18321826
#[inline]
1833-
pub fn new(
1834-
caller_bounds: &'tcx List<Predicate<'tcx>>,
1835-
reveal: Reveal,
1836-
def_id: Option<DefId>,
1837-
) -> Self {
1838-
ty::ParamEnv { packed: CopyTaggedPtr::new(caller_bounds, reveal), def_id }
1827+
pub fn new(caller_bounds: &'tcx List<Predicate<'tcx>>, reveal: Reveal) -> Self {
1828+
ty::ParamEnv { packed: CopyTaggedPtr::new(caller_bounds, reveal) }
18391829
}
18401830

18411831
pub fn with_user_facing(mut self) -> Self {
@@ -1857,12 +1847,12 @@ impl<'tcx> ParamEnv<'tcx> {
18571847
return self;
18581848
}
18591849

1860-
ParamEnv::new(tcx.normalize_opaque_types(self.caller_bounds()), Reveal::All, self.def_id)
1850+
ParamEnv::new(tcx.normalize_opaque_types(self.caller_bounds()), Reveal::All)
18611851
}
18621852

18631853
/// Returns this same environment but with no caller bounds.
18641854
pub fn without_caller_bounds(self) -> Self {
1865-
Self::new(List::empty(), self.reveal(), self.def_id)
1855+
Self::new(List::empty(), self.reveal())
18661856
}
18671857

18681858
/// Creates a suitable environment in which to perform trait

0 commit comments

Comments
 (0)