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 https://github.com/rust-lang/rust/issues/74865.
This commit is contained in:
commit
7402a39447
35 changed files with 288 additions and 337 deletions
|
@ -1399,7 +1399,7 @@ rustc_queries! {
|
|||
}
|
||||
|
||||
query evaluate_goal(
|
||||
goal: traits::ChalkCanonicalGoal<'tcx>
|
||||
goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
|
||||
) -> Result<
|
||||
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>,
|
||||
NoSolution
|
||||
|
|
|
@ -6,14 +6,11 @@
|
|||
//! interned Chalk types.
|
||||
|
||||
use rustc_middle::mir::interpret::ConstValue;
|
||||
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
||||
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, AdtDef, TyCtxt};
|
||||
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
@ -376,31 +373,10 @@ impl<'tcx> chalk_ir::interner::HasInterner for RustInterner<'tcx> {
|
|||
type Interner = Self;
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
|
||||
pub enum ChalkEnvironmentClause<'tcx> {
|
||||
/// A normal rust `ty::Predicate` in the environment.
|
||||
Predicate(ty::Predicate<'tcx>),
|
||||
/// A special clause in the environment that gets lowered to
|
||||
/// `chalk_ir::FromEnv::Ty`.
|
||||
TypeFromEnv(Ty<'tcx>),
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ChalkEnvironmentClause<'tcx>> {
|
||||
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
let v = self.iter().map(|t| t.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
|
||||
folder.tcx().intern_chalk_environment_clause_list(&v)
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
||||
self.iter().any(|t| t.visit_with(visitor))
|
||||
}
|
||||
}
|
||||
/// We have to elaborate the environment of a chalk goal *before*
|
||||
/// canonicalization. This type wraps the predicate and the elaborated
|
||||
/// environment.
|
||||
/// A chalk environment and goal.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
|
||||
pub struct ChalkEnvironmentAndGoal<'tcx> {
|
||||
pub environment: &'tcx ty::List<ChalkEnvironmentClause<'tcx>>,
|
||||
pub environment: &'tcx ty::List<ty::Predicate<'tcx>>,
|
||||
pub goal: ty::Predicate<'tcx>,
|
||||
}
|
||||
|
||||
|
|
|
@ -26,14 +26,12 @@ use std::rc::Rc;
|
|||
|
||||
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
|
||||
|
||||
pub type ChalkCanonicalGoal<'tcx> = Canonical<'tcx, ChalkEnvironmentAndGoal<'tcx>>;
|
||||
pub type CanonicalChalkEnvironmentAndGoal<'tcx> = Canonical<'tcx, ChalkEnvironmentAndGoal<'tcx>>;
|
||||
|
||||
pub use self::ImplSource::*;
|
||||
pub use self::ObligationCauseCode::*;
|
||||
|
||||
pub use self::chalk::{
|
||||
ChalkEnvironmentAndGoal, ChalkEnvironmentClause, RustInterner as ChalkRustInterner,
|
||||
};
|
||||
pub use self::chalk::{ChalkEnvironmentAndGoal, RustInterner as ChalkRustInterner};
|
||||
|
||||
/// Depending on the stage of compilation, we want projection to be
|
||||
/// more or less conservative.
|
||||
|
|
|
@ -91,8 +91,6 @@ pub struct CtxtInterners<'tcx> {
|
|||
projs: InternedSet<'tcx, List<ProjectionKind>>,
|
||||
place_elems: InternedSet<'tcx, List<PlaceElem<'tcx>>>,
|
||||
const_: InternedSet<'tcx, Const<'tcx>>,
|
||||
|
||||
chalk_environment_clause_list: InternedSet<'tcx, List<traits::ChalkEnvironmentClause<'tcx>>>,
|
||||
}
|
||||
|
||||
impl<'tcx> CtxtInterners<'tcx> {
|
||||
|
@ -110,7 +108,6 @@ impl<'tcx> CtxtInterners<'tcx> {
|
|||
projs: Default::default(),
|
||||
place_elems: Default::default(),
|
||||
const_: Default::default(),
|
||||
chalk_environment_clause_list: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2041,7 +2038,7 @@ direct_interners! {
|
|||
}
|
||||
|
||||
macro_rules! slice_interners {
|
||||
($($field:ident: $method:ident($ty:ty)),+) => (
|
||||
($($field:ident: $method:ident($ty:ty)),+ $(,)?) => (
|
||||
$(impl<'tcx> TyCtxt<'tcx> {
|
||||
pub fn $method(self, v: &[$ty]) -> &'tcx List<$ty> {
|
||||
self.interners.$field.intern_ref(v, || {
|
||||
|
@ -2060,8 +2057,6 @@ slice_interners!(
|
|||
predicates: _intern_predicates(Predicate<'tcx>),
|
||||
projs: _intern_projs(ProjectionKind),
|
||||
place_elems: _intern_place_elems(PlaceElem<'tcx>),
|
||||
chalk_environment_clause_list:
|
||||
_intern_chalk_environment_clause_list(traits::ChalkEnvironmentClause<'tcx>)
|
||||
);
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
|
@ -2460,13 +2455,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
if ts.is_empty() { List::empty() } else { self._intern_canonical_var_infos(ts) }
|
||||
}
|
||||
|
||||
pub fn intern_chalk_environment_clause_list(
|
||||
self,
|
||||
ts: &[traits::ChalkEnvironmentClause<'tcx>],
|
||||
) -> &'tcx List<traits::ChalkEnvironmentClause<'tcx>> {
|
||||
if ts.is_empty() { List::empty() } else { self._intern_chalk_environment_clause_list(ts) }
|
||||
}
|
||||
|
||||
pub fn mk_fn_sig<I>(
|
||||
self,
|
||||
inputs: I,
|
||||
|
@ -2524,18 +2512,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
self.mk_substs(iter::once(self_ty.into()).chain(rest.iter().cloned()))
|
||||
}
|
||||
|
||||
pub fn mk_chalk_environment_clause_list<
|
||||
I: InternAs<
|
||||
[traits::ChalkEnvironmentClause<'tcx>],
|
||||
&'tcx List<traits::ChalkEnvironmentClause<'tcx>>,
|
||||
>,
|
||||
>(
|
||||
self,
|
||||
iter: I,
|
||||
) -> I::Output {
|
||||
iter.intern_with(|xs| self.intern_chalk_environment_clause_list(xs))
|
||||
}
|
||||
|
||||
/// Walks upwards from `id` to find a node which might change lint levels with attributes.
|
||||
/// It stops at `bound` and just returns it if reached.
|
||||
pub fn maybe_lint_level_root_bounded(self, mut id: HirId, bound: HirId) -> HirId {
|
||||
|
|
|
@ -249,6 +249,9 @@ impl FlagComputation {
|
|||
self.add_const(expected);
|
||||
self.add_const(found);
|
||||
}
|
||||
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
|
||||
self.add_ty(ty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1155,6 +1155,11 @@ pub enum PredicateAtom<'tcx> {
|
|||
|
||||
/// Constants must be equal. The first component is the const that is expected.
|
||||
ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>),
|
||||
|
||||
/// Represents a type found in the environment that we can use for implied bounds.
|
||||
///
|
||||
/// Only used for Chalk.
|
||||
TypeWellFormedFromEnv(Ty<'tcx>),
|
||||
}
|
||||
|
||||
impl<'tcx> PredicateAtom<'tcx> {
|
||||
|
@ -1450,7 +1455,8 @@ impl<'tcx> Predicate<'tcx> {
|
|||
| PredicateAtom::ClosureKind(..)
|
||||
| PredicateAtom::TypeOutlives(..)
|
||||
| PredicateAtom::ConstEvaluatable(..)
|
||||
| PredicateAtom::ConstEquate(..) => None,
|
||||
| PredicateAtom::ConstEquate(..)
|
||||
| PredicateAtom::TypeWellFormedFromEnv(..) => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1465,7 +1471,8 @@ impl<'tcx> Predicate<'tcx> {
|
|||
| PredicateAtom::ObjectSafe(..)
|
||||
| PredicateAtom::ClosureKind(..)
|
||||
| PredicateAtom::ConstEvaluatable(..)
|
||||
| PredicateAtom::ConstEquate(..) => None,
|
||||
| PredicateAtom::ConstEquate(..)
|
||||
| PredicateAtom::TypeWellFormedFromEnv(..) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1738,11 +1745,6 @@ pub struct ParamEnv<'tcx> {
|
|||
///
|
||||
/// Note: This is packed, use the reveal() method to access it.
|
||||
packed: CopyTaggedPtr<&'tcx List<Predicate<'tcx>>, traits::Reveal, true>,
|
||||
|
||||
/// If this `ParamEnv` comes from a call to `tcx.param_env(def_id)`,
|
||||
/// register that `def_id` (useful for transitioning to the chalk trait
|
||||
/// solver).
|
||||
pub def_id: Option<DefId>,
|
||||
}
|
||||
|
||||
unsafe impl rustc_data_structures::tagged_ptr::Tag for traits::Reveal {
|
||||
|
@ -1767,7 +1769,6 @@ impl<'tcx> fmt::Debug for ParamEnv<'tcx> {
|
|||
f.debug_struct("ParamEnv")
|
||||
.field("caller_bounds", &self.caller_bounds())
|
||||
.field("reveal", &self.reveal())
|
||||
.field("def_id", &self.def_id)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
@ -1776,23 +1777,16 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for ParamEnv<'tcx> {
|
|||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
|
||||
self.caller_bounds().hash_stable(hcx, hasher);
|
||||
self.reveal().hash_stable(hcx, hasher);
|
||||
self.def_id.hash_stable(hcx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TypeFoldable<'tcx> for ParamEnv<'tcx> {
|
||||
fn super_fold_with<F: ty::fold::TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
|
||||
ParamEnv::new(
|
||||
self.caller_bounds().fold_with(folder),
|
||||
self.reveal().fold_with(folder),
|
||||
self.def_id.fold_with(folder),
|
||||
)
|
||||
ParamEnv::new(self.caller_bounds().fold_with(folder), self.reveal().fold_with(folder))
|
||||
}
|
||||
|
||||
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
||||
self.caller_bounds().visit_with(visitor)
|
||||
|| self.reveal().visit_with(visitor)
|
||||
|| self.def_id.visit_with(visitor)
|
||||
self.caller_bounds().visit_with(visitor) || self.reveal().visit_with(visitor)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1803,7 +1797,7 @@ impl<'tcx> ParamEnv<'tcx> {
|
|||
/// type-checking.
|
||||
#[inline]
|
||||
pub fn empty() -> Self {
|
||||
Self::new(List::empty(), Reveal::UserFacing, None)
|
||||
Self::new(List::empty(), Reveal::UserFacing)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -1825,17 +1819,13 @@ impl<'tcx> ParamEnv<'tcx> {
|
|||
/// or invoke `param_env.with_reveal_all()`.
|
||||
#[inline]
|
||||
pub fn reveal_all() -> Self {
|
||||
Self::new(List::empty(), Reveal::All, None)
|
||||
Self::new(List::empty(), Reveal::All)
|
||||
}
|
||||
|
||||
/// Construct a trait environment with the given set of predicates.
|
||||
#[inline]
|
||||
pub fn new(
|
||||
caller_bounds: &'tcx List<Predicate<'tcx>>,
|
||||
reveal: Reveal,
|
||||
def_id: Option<DefId>,
|
||||
) -> Self {
|
||||
ty::ParamEnv { packed: CopyTaggedPtr::new(caller_bounds, reveal), def_id }
|
||||
pub fn new(caller_bounds: &'tcx List<Predicate<'tcx>>, reveal: Reveal) -> Self {
|
||||
ty::ParamEnv { packed: CopyTaggedPtr::new(caller_bounds, reveal) }
|
||||
}
|
||||
|
||||
pub fn with_user_facing(mut self) -> Self {
|
||||
|
@ -1857,12 +1847,12 @@ impl<'tcx> ParamEnv<'tcx> {
|
|||
return self;
|
||||
}
|
||||
|
||||
ParamEnv::new(tcx.normalize_opaque_types(self.caller_bounds()), Reveal::All, self.def_id)
|
||||
ParamEnv::new(tcx.normalize_opaque_types(self.caller_bounds()), Reveal::All)
|
||||
}
|
||||
|
||||
/// Returns this same environment but with no caller bounds.
|
||||
pub fn without_caller_bounds(self) -> Self {
|
||||
Self::new(List::empty(), self.reveal(), self.def_id)
|
||||
Self::new(List::empty(), self.reveal())
|
||||
}
|
||||
|
||||
/// Creates a suitable environment in which to perform trait
|
||||
|
|
|
@ -2096,6 +2096,11 @@ define_print_and_forward_display! {
|
|||
print(c2),
|
||||
write("`"))
|
||||
}
|
||||
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
|
||||
p!(write("the type `"),
|
||||
print(ty),
|
||||
write("` is found in the environment"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -260,6 +260,9 @@ impl fmt::Debug for ty::PredicateAtom<'tcx> {
|
|||
write!(f, "ConstEvaluatable({:?}, {:?})", def_id, substs)
|
||||
}
|
||||
ty::PredicateAtom::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
|
||||
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
|
||||
write!(f, "TypeWellFormedFromEnv({:?})", ty)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -536,6 +539,9 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateAtom<'a> {
|
|||
ty::PredicateAtom::ConstEquate(c1, c2) => {
|
||||
tcx.lift(&(c1, c2)).map(|(c1, c2)| ty::PredicateAtom::ConstEquate(c1, c2))
|
||||
}
|
||||
ty::PredicateAtom::TypeWellFormedFromEnv(ty) => {
|
||||
tcx.lift(&ty).map(ty::PredicateAtom::TypeWellFormedFromEnv)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -551,7 +557,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::ParamEnv<'a> {
|
|||
type Lifted = ty::ParamEnv<'tcx>;
|
||||
fn lift_to_tcx(&self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
|
||||
tcx.lift(&self.caller_bounds())
|
||||
.map(|caller_bounds| ty::ParamEnv::new(caller_bounds, self.reveal(), self.def_id))
|
||||
.map(|caller_bounds| ty::ParamEnv::new(caller_bounds, self.reveal()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue