Improve AdtDef
interning.
This commit makes `AdtDef` use `Interned`. Much the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`.
This commit is contained in:
parent
5f4e067719
commit
ca5525d564
169 changed files with 702 additions and 687 deletions
|
@ -676,7 +676,7 @@ fn fundamental_ty_inner_tys<'tcx>(
|
|||
match types.next() {
|
||||
None => {
|
||||
tcx.sess.span_err(
|
||||
tcx.def_span(def.did),
|
||||
tcx.def_span(def.did()),
|
||||
"`#[fundamental]` requires at least one type parameter",
|
||||
);
|
||||
|
||||
|
@ -729,7 +729,7 @@ fn ty_is_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> bool {
|
|||
InCrate::Remote => true,
|
||||
},
|
||||
|
||||
ty::Adt(def, _) => def_id_is_local(def.did, in_crate),
|
||||
ty::Adt(def, _) => def_id_is_local(def.did(), in_crate),
|
||||
ty::Foreign(did) => def_id_is_local(did, in_crate),
|
||||
ty::Opaque(..) => {
|
||||
// This merits some explanation.
|
||||
|
|
|
@ -813,7 +813,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
| ty::Foreign(did)
|
||||
| ty::FnDef(did, _)
|
||||
| ty::Generator(did, ..) => Some(did),
|
||||
ty::Adt(def, _) => Some(def.did),
|
||||
ty::Adt(def, _) => Some(def.did()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
@ -1467,7 +1467,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
|||
ty::Bool => Some(0),
|
||||
ty::Char => Some(1),
|
||||
ty::Str => Some(2),
|
||||
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::String, def.did) => Some(2),
|
||||
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::String, def.did()) => Some(2),
|
||||
ty::Int(..)
|
||||
| ty::Uint(..)
|
||||
| ty::Float(..)
|
||||
|
|
|
@ -172,7 +172,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
if let Some(def) = self_ty.ty_adt_def() {
|
||||
// We also want to be able to select self's original
|
||||
// signature with no type arguments resolved
|
||||
flags.push((sym::_Self, Some(self.tcx.type_of(def.did).to_string())));
|
||||
flags.push((sym::_Self, Some(self.tcx.type_of(def.did()).to_string())));
|
||||
}
|
||||
|
||||
for param in generics.params.iter() {
|
||||
|
@ -190,12 +190,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
if let Some(def) = param_ty.ty_adt_def() {
|
||||
// We also want to be able to select the parameter's
|
||||
// original signature with no type arguments resolved
|
||||
flags.push((name, Some(self.tcx.type_of(def.did).to_string())));
|
||||
flags.push((name, Some(self.tcx.type_of(def.did()).to_string())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(true) = self_ty.ty_adt_def().map(|def| def.did.is_local()) {
|
||||
if let Some(true) = self_ty.ty_adt_def().map(|def| def.did().is_local()) {
|
||||
flags.push((sym::crate_local, None));
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
if let Some(def) = aty.ty_adt_def() {
|
||||
// We also want to be able to select the array's type's original
|
||||
// signature with no type arguments resolved
|
||||
let type_string = self.tcx.type_of(def.did).to_string();
|
||||
let type_string = self.tcx.type_of(def.did()).to_string();
|
||||
flags.push((sym::_Self, Some(format!("[{}]", type_string))));
|
||||
|
||||
let len =
|
||||
|
|
|
@ -2129,7 +2129,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
if !is_upvar_tys_infer_tuple {
|
||||
let msg = format!("required because it appears within the type `{}`", ty);
|
||||
match ty.kind() {
|
||||
ty::Adt(def, _) => match self.tcx.opt_item_name(def.did) {
|
||||
ty::Adt(def, _) => match self.tcx.opt_item_name(def.did()) {
|
||||
Some(ident) => err.span_note(ident.span, &msg),
|
||||
None => err.note(&msg),
|
||||
},
|
||||
|
|
|
@ -43,7 +43,7 @@ pub fn can_type_implement_copy<'tcx>(
|
|||
};
|
||||
|
||||
let mut infringing = Vec::new();
|
||||
for variant in &adt.variants {
|
||||
for variant in adt.variants() {
|
||||
for field in &variant.fields {
|
||||
let ty = field.ty(tcx, substs);
|
||||
if ty.references_error() {
|
||||
|
@ -56,7 +56,7 @@ pub fn can_type_implement_copy<'tcx>(
|
|||
// If it does not, then this field probably doesn't normalize
|
||||
// to begin with, and point to the bad field's span instead.
|
||||
let cause = if field
|
||||
.ty(tcx, traits::InternalSubsts::identity_for_item(tcx, adt.did))
|
||||
.ty(tcx, traits::InternalSubsts::identity_for_item(tcx, adt.did()))
|
||||
.has_param_types_or_consts()
|
||||
{
|
||||
cause.clone()
|
||||
|
|
|
@ -112,7 +112,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
|
|||
}
|
||||
|
||||
ty::Adt(def, _) => {
|
||||
if Some(def.did) == tcx.lang_items().manually_drop() {
|
||||
if Some(def.did()) == tcx.lang_items().manually_drop() {
|
||||
// `ManuallyDrop` never has a dtor.
|
||||
true
|
||||
} else {
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::ops::ControlFlow;
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum NonStructuralMatchTy<'tcx> {
|
||||
Adt(&'tcx AdtDef),
|
||||
Adt(AdtDef<'tcx>),
|
||||
Param,
|
||||
Dynamic,
|
||||
Foreign,
|
||||
|
@ -208,14 +208,14 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
|
|||
}
|
||||
};
|
||||
|
||||
if !self.seen.insert(adt_def.did) {
|
||||
if !self.seen.insert(adt_def.did()) {
|
||||
debug!("Search already seen adt_def: {:?}", adt_def);
|
||||
return ControlFlow::CONTINUE;
|
||||
}
|
||||
|
||||
if !self.type_marked_structural(ty) {
|
||||
debug!("Search found ty: {:?}", ty);
|
||||
return ControlFlow::Break(NonStructuralMatchTy::Adt(&adt_def));
|
||||
return ControlFlow::Break(NonStructuralMatchTy::Adt(adt_def));
|
||||
}
|
||||
|
||||
// structural-match does not care about the
|
||||
|
|
|
@ -540,7 +540,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
|
||||
ty::Adt(def, substs) => {
|
||||
// WfNominalType
|
||||
let obligations = self.nominal_obligations(def.did, substs);
|
||||
let obligations = self.nominal_obligations(def.did(), substs);
|
||||
self.out.extend(obligations);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue