Merge SimplifiedTypeGen<D> into SimplifiedType.

`SimplifiedTypeGen<DefId>` is the only instantiation used, so we don't
need the generic parameter.
This commit is contained in:
Nicholas Nethercote 2022-12-15 15:13:19 +11:00
parent 2a5aabdfc2
commit 5258b655a2
5 changed files with 15 additions and 25 deletions

View File

@ -6,28 +6,18 @@ use std::fmt::Debug;
use std::hash::Hash; use std::hash::Hash;
use std::iter; use std::iter;
use self::SimplifiedTypeGen::*; use self::SimplifiedType::*;
pub type SimplifiedType = SimplifiedTypeGen<DefId>; /// See `simplify_type`.
/// See `simplify_type`
///
/// Note that we keep this type generic over the type of identifier it uses
/// because we sometimes need to use SimplifiedTypeGen values as stable sorting
/// keys (in which case we use a DefPathHash as id-type) but in the general case
/// the non-stable but fast to construct DefId-version is the better choice.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
pub enum SimplifiedTypeGen<D> pub enum SimplifiedType {
where
D: Copy + Debug + Eq,
{
BoolSimplifiedType, BoolSimplifiedType,
CharSimplifiedType, CharSimplifiedType,
IntSimplifiedType(ty::IntTy), IntSimplifiedType(ty::IntTy),
UintSimplifiedType(ty::UintTy), UintSimplifiedType(ty::UintTy),
FloatSimplifiedType(ty::FloatTy), FloatSimplifiedType(ty::FloatTy),
AdtSimplifiedType(D), AdtSimplifiedType(DefId),
ForeignSimplifiedType(D), ForeignSimplifiedType(DefId),
StrSimplifiedType, StrSimplifiedType,
ArraySimplifiedType, ArraySimplifiedType,
SliceSimplifiedType, SliceSimplifiedType,
@ -38,9 +28,9 @@ where
/// A trait object, all of whose components are markers /// A trait object, all of whose components are markers
/// (e.g., `dyn Send + Sync`). /// (e.g., `dyn Send + Sync`).
MarkerTraitObjectSimplifiedType, MarkerTraitObjectSimplifiedType,
TraitSimplifiedType(D), TraitSimplifiedType(DefId),
ClosureSimplifiedType(D), ClosureSimplifiedType(DefId),
GeneratorSimplifiedType(D), GeneratorSimplifiedType(DefId),
GeneratorWitnessSimplifiedType(usize), GeneratorWitnessSimplifiedType(usize),
FunctionSimplifiedType(usize), FunctionSimplifiedType(usize),
PlaceholderSimplifiedType, PlaceholderSimplifiedType,
@ -142,8 +132,8 @@ pub fn simplify_type<'tcx>(
} }
} }
impl<D: Copy + Debug + Eq> SimplifiedTypeGen<D> { impl SimplifiedType {
pub fn def(self) -> Option<D> { pub fn def(self) -> Option<DefId> {
match self { match self {
AdtSimplifiedType(d) AdtSimplifiedType(d)
| ForeignSimplifiedType(d) | ForeignSimplifiedType(d)

View File

@ -1,5 +1,5 @@
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::{DefId, DefIndex}; use rustc_hir::def_id::DefIndex;
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::vec::{Idx, IndexVec};
use crate::middle::exported_symbols::ExportedSymbol; use crate::middle::exported_symbols::ExportedSymbol;
@ -67,7 +67,7 @@ trivially_parameterized_over_tcx! {
ty::TraitDef, ty::TraitDef,
ty::Visibility<DefIndex>, ty::Visibility<DefIndex>,
ty::adjustment::CoerceUnsizedInfo, ty::adjustment::CoerceUnsizedInfo,
ty::fast_reject::SimplifiedTypeGen<DefId>, ty::fast_reject::SimplifiedType,
rustc_ast::Attribute, rustc_ast::Attribute,
rustc_ast::DelimArgs, rustc_ast::DelimArgs,
rustc_attr::ConstStability, rustc_attr::ConstStability,

View File

@ -325,7 +325,7 @@ pub(crate) fn build_impls(
// * https://github.com/rust-lang/rust/pull/99917 — where the feature got used // * https://github.com/rust-lang/rust/pull/99917 — where the feature got used
// * https://github.com/rust-lang/rust/issues/53487 — overall tracking issue for Error // * https://github.com/rust-lang/rust/issues/53487 — overall tracking issue for Error
if tcx.has_attr(did, sym::rustc_has_incoherent_inherent_impls) { if tcx.has_attr(did, sym::rustc_has_incoherent_inherent_impls) {
use rustc_middle::ty::fast_reject::SimplifiedTypeGen::*; use rustc_middle::ty::fast_reject::SimplifiedType::*;
let type_ = let type_ =
if tcx.is_trait(did) { TraitSimplifiedType(did) } else { AdtSimplifiedType(did) }; if tcx.is_trait(did) { TraitSimplifiedType(did) } else { AdtSimplifiedType(did) };
for &did in tcx.incoherent_impls(type_) { for &did in tcx.incoherent_impls(type_) {

View File

@ -1870,7 +1870,7 @@ impl PrimitiveType {
} }
pub(crate) fn simplified_types() -> &'static SimplifiedTypes { pub(crate) fn simplified_types() -> &'static SimplifiedTypes {
use ty::fast_reject::SimplifiedTypeGen::*; use ty::fast_reject::SimplifiedType::*;
use ty::{FloatTy, IntTy, UintTy}; use ty::{FloatTy, IntTy, UintTy};
use PrimitiveType::*; use PrimitiveType::*;
static CELL: OnceCell<SimplifiedTypes> = OnceCell::new(); static CELL: OnceCell<SimplifiedTypes> = OnceCell::new();

View File

@ -97,7 +97,7 @@ use rustc_middle::hir::place::PlaceBase;
use rustc_middle::ty as rustc_ty; use rustc_middle::ty as rustc_ty;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
use rustc_middle::ty::binding::BindingMode; use rustc_middle::ty::binding::BindingMode;
use rustc_middle::ty::fast_reject::SimplifiedTypeGen::{ use rustc_middle::ty::fast_reject::SimplifiedType::{
ArraySimplifiedType, BoolSimplifiedType, CharSimplifiedType, FloatSimplifiedType, IntSimplifiedType, ArraySimplifiedType, BoolSimplifiedType, CharSimplifiedType, FloatSimplifiedType, IntSimplifiedType,
PtrSimplifiedType, SliceSimplifiedType, StrSimplifiedType, UintSimplifiedType, PtrSimplifiedType, SliceSimplifiedType, StrSimplifiedType, UintSimplifiedType,
}; };