Rollup merge of #144717 - nnethercote:mv-rustc_middle-parameterized, r=compiler-errors
Move `rustc_middle::parameterized` It doesn't need to be in `rustc_middle`. r? `@compiler-errors`
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use rustc_data_structures::owned_slice::OwnedSlice;
|
||||
use rustc_hir::def_path_hash_map::{Config as HashMapConfig, DefPathHashMap};
|
||||
use rustc_middle::parameterized_over_tcx;
|
||||
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||
use rustc_span::def_id::{DefIndex, DefPathHash};
|
||||
|
||||
@@ -11,10 +10,6 @@ pub(crate) enum DefPathHashMapRef<'tcx> {
|
||||
BorrowedFromTcx(&'tcx DefPathHashMap),
|
||||
}
|
||||
|
||||
parameterized_over_tcx! {
|
||||
DefPathHashMapRef,
|
||||
}
|
||||
|
||||
impl DefPathHashMapRef<'_> {
|
||||
#[inline]
|
||||
pub(crate) fn def_path_hash_to_def_index(&self, def_path_hash: &DefPathHash) -> DefIndex {
|
||||
|
||||
@@ -6,6 +6,7 @@ use decoder::{DecodeContext, Metadata};
|
||||
use def_path_hash_map::DefPathHashMapRef;
|
||||
use encoder::EncodeContext;
|
||||
pub use encoder::{EncodedMetadata, encode_metadata, rendered_const};
|
||||
pub(crate) use parameterized::ParameterizedOverTcx;
|
||||
use rustc_abi::{FieldIdx, ReprOptions, VariantIdx};
|
||||
use rustc_attr_data_structures::StrippedCfgItem;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
@@ -26,12 +27,10 @@ use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
|
||||
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
|
||||
use rustc_middle::middle::lib_features::FeatureStability;
|
||||
use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::ty::fast_reject::SimplifiedType;
|
||||
use rustc_middle::ty::{
|
||||
self, DeducedParamAttrs, ParameterizedOverTcx, Ty, TyCtxt, UnusedGenericParams,
|
||||
};
|
||||
use rustc_middle::ty::{self, DeducedParamAttrs, Ty, TyCtxt, UnusedGenericParams};
|
||||
use rustc_middle::util::Providers;
|
||||
use rustc_middle::{mir, trivially_parameterized_over_tcx};
|
||||
use rustc_serialize::opaque::FileEncoder;
|
||||
use rustc_session::config::{SymbolManglingVersion, TargetModifier};
|
||||
use rustc_session::cstore::{CrateDepKind, ForeignModule, LinkagePreference, NativeLib};
|
||||
@@ -47,6 +46,7 @@ use crate::creader::CrateMetadataRef;
|
||||
mod decoder;
|
||||
mod def_path_hash_map;
|
||||
mod encoder;
|
||||
mod parameterized;
|
||||
mod table;
|
||||
|
||||
pub(crate) fn rustc_version(cfg_version: &'static str) -> String {
|
||||
@@ -86,10 +86,6 @@ struct LazyValue<T> {
|
||||
_marker: PhantomData<fn() -> T>,
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for LazyValue<T> {
|
||||
type Value<'tcx> = LazyValue<T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<T> LazyValue<T> {
|
||||
fn from_position(position: NonZero<usize>) -> LazyValue<T> {
|
||||
LazyValue { position, _marker: PhantomData }
|
||||
@@ -112,10 +108,6 @@ struct LazyArray<T> {
|
||||
_marker: PhantomData<fn() -> T>,
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for LazyArray<T> {
|
||||
type Value<'tcx> = LazyArray<T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<T> Default for LazyArray<T> {
|
||||
fn default() -> LazyArray<T> {
|
||||
LazyArray::from_position_and_num_elems(NonZero::new(1).unwrap(), 0)
|
||||
@@ -143,10 +135,6 @@ struct LazyTable<I, T> {
|
||||
_marker: PhantomData<fn(I) -> T>,
|
||||
}
|
||||
|
||||
impl<I: 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for LazyTable<I, T> {
|
||||
type Value<'tcx> = LazyTable<I, T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<I, T> LazyTable<I, T> {
|
||||
fn from_position_and_encoded_size(
|
||||
position: NonZero<usize>,
|
||||
@@ -594,14 +582,3 @@ pub fn provide(providers: &mut Providers) {
|
||||
encoder::provide(providers);
|
||||
decoder::provide(providers);
|
||||
}
|
||||
|
||||
trivially_parameterized_over_tcx! {
|
||||
VariantData,
|
||||
RawDefId,
|
||||
TraitImpls,
|
||||
IncoherentImpls,
|
||||
CrateHeader,
|
||||
CrateRoot,
|
||||
CrateDep,
|
||||
AttrFlags,
|
||||
}
|
||||
|
||||
166
compiler/rustc_metadata/src/rmeta/parameterized.rs
Normal file
166
compiler/rustc_metadata/src/rmeta/parameterized.rs
Normal file
@@ -0,0 +1,166 @@
|
||||
use std::hash::Hash;
|
||||
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_hir::def_id::DefIndex;
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
use rustc_middle::ty::{Binder, EarlyBinder};
|
||||
use rustc_span::Symbol;
|
||||
|
||||
use crate::rmeta::{LazyArray, LazyTable, LazyValue};
|
||||
|
||||
pub(crate) trait ParameterizedOverTcx: 'static {
|
||||
type Value<'tcx>;
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for Option<T> {
|
||||
type Value<'tcx> = Option<T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<A: ParameterizedOverTcx, B: ParameterizedOverTcx> ParameterizedOverTcx for (A, B) {
|
||||
type Value<'tcx> = (A::Value<'tcx>, B::Value<'tcx>);
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for Vec<T> {
|
||||
type Value<'tcx> = Vec<T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<I: Idx + 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for IndexVec<I, T> {
|
||||
type Value<'tcx> = IndexVec<I, T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<I: Hash + Eq + 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for UnordMap<I, T> {
|
||||
type Value<'tcx> = UnordMap<I, T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for Binder<'static, T> {
|
||||
type Value<'tcx> = Binder<'tcx, T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for EarlyBinder<'static, T> {
|
||||
type Value<'tcx> = EarlyBinder<'tcx, T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for LazyValue<T> {
|
||||
type Value<'tcx> = LazyValue<T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for LazyArray<T> {
|
||||
type Value<'tcx> = LazyArray<T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<I: 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for LazyTable<I, T> {
|
||||
type Value<'tcx> = LazyTable<I, T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
macro_rules! trivially_parameterized_over_tcx {
|
||||
($($ty:ty),+ $(,)?) => {
|
||||
$(
|
||||
impl ParameterizedOverTcx for $ty {
|
||||
#[allow(unused_lifetimes)]
|
||||
type Value<'tcx> = $ty;
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
trivially_parameterized_over_tcx! {
|
||||
bool,
|
||||
u64,
|
||||
usize,
|
||||
std::string::String,
|
||||
// tidy-alphabetical-start
|
||||
crate::rmeta::AttrFlags,
|
||||
crate::rmeta::CrateDep,
|
||||
crate::rmeta::CrateHeader,
|
||||
crate::rmeta::CrateRoot,
|
||||
crate::rmeta::IncoherentImpls,
|
||||
crate::rmeta::RawDefId,
|
||||
crate::rmeta::TraitImpls,
|
||||
crate::rmeta::VariantData,
|
||||
rustc_abi::ReprOptions,
|
||||
rustc_ast::DelimArgs,
|
||||
rustc_attr_data_structures::ConstStability,
|
||||
rustc_attr_data_structures::DefaultBodyStability,
|
||||
rustc_attr_data_structures::Deprecation,
|
||||
rustc_attr_data_structures::Stability,
|
||||
rustc_attr_data_structures::StrippedCfgItem<rustc_hir::def_id::DefIndex>,
|
||||
rustc_hir::Attribute,
|
||||
rustc_hir::Constness,
|
||||
rustc_hir::CoroutineKind,
|
||||
rustc_hir::Defaultness,
|
||||
rustc_hir::LangItem,
|
||||
rustc_hir::OpaqueTyOrigin<rustc_hir::def_id::DefId>,
|
||||
rustc_hir::PreciseCapturingArgKind<Symbol, Symbol>,
|
||||
rustc_hir::Safety,
|
||||
rustc_hir::def::DefKind,
|
||||
rustc_hir::def::DocLinkResMap,
|
||||
rustc_hir::def_id::DefId,
|
||||
rustc_hir::def_id::DefIndex,
|
||||
rustc_hir::definitions::DefKey,
|
||||
rustc_index::bit_set::DenseBitSet<u32>,
|
||||
rustc_middle::metadata::ModChild,
|
||||
rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs,
|
||||
rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile,
|
||||
rustc_middle::middle::exported_symbols::SymbolExportInfo,
|
||||
rustc_middle::middle::lib_features::FeatureStability,
|
||||
rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault,
|
||||
rustc_middle::mir::ConstQualifs,
|
||||
rustc_middle::ty::AnonConstKind,
|
||||
rustc_middle::ty::AssocItemContainer,
|
||||
rustc_middle::ty::AsyncDestructor,
|
||||
rustc_middle::ty::Asyncness,
|
||||
rustc_middle::ty::DeducedParamAttrs,
|
||||
rustc_middle::ty::Destructor,
|
||||
rustc_middle::ty::Generics,
|
||||
rustc_middle::ty::ImplTraitInTraitData,
|
||||
rustc_middle::ty::IntrinsicDef,
|
||||
rustc_middle::ty::TraitDef,
|
||||
rustc_middle::ty::Variance,
|
||||
rustc_middle::ty::Visibility<DefIndex>,
|
||||
rustc_middle::ty::adjustment::CoerceUnsizedInfo,
|
||||
rustc_middle::ty::fast_reject::SimplifiedType,
|
||||
rustc_session::config::TargetModifier,
|
||||
rustc_session::cstore::ForeignModule,
|
||||
rustc_session::cstore::LinkagePreference,
|
||||
rustc_session::cstore::NativeLib,
|
||||
rustc_span::ExpnData,
|
||||
rustc_span::ExpnHash,
|
||||
rustc_span::ExpnId,
|
||||
rustc_span::Ident,
|
||||
rustc_span::SourceFile,
|
||||
rustc_span::Span,
|
||||
rustc_span::Symbol,
|
||||
rustc_span::hygiene::SyntaxContextKey,
|
||||
// tidy-alphabetical-end
|
||||
}
|
||||
|
||||
// HACK(compiler-errors): This macro rule can only take a fake path,
|
||||
// not a real, due to parsing ambiguity reasons.
|
||||
macro_rules! parameterized_over_tcx {
|
||||
($($( $fake_path:ident )::+ ),+ $(,)?) => {
|
||||
$(
|
||||
impl ParameterizedOverTcx for $( $fake_path )::+ <'static> {
|
||||
type Value<'tcx> = $( $fake_path )::+ <'tcx>;
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
parameterized_over_tcx! {
|
||||
// tidy-alphabetical-start
|
||||
crate::rmeta::DefPathHashMapRef,
|
||||
rustc_middle::middle::exported_symbols::ExportedSymbol,
|
||||
rustc_middle::mir::Body,
|
||||
rustc_middle::mir::CoroutineLayout,
|
||||
rustc_middle::mir::interpret::ConstAllocation,
|
||||
rustc_middle::ty::Clause,
|
||||
rustc_middle::ty::ClauseKind,
|
||||
rustc_middle::ty::Const,
|
||||
rustc_middle::ty::ConstConditions,
|
||||
rustc_middle::ty::FnSig,
|
||||
rustc_middle::ty::GenericPredicates,
|
||||
rustc_middle::ty::ImplTraitHeader,
|
||||
rustc_middle::ty::TraitRef,
|
||||
rustc_middle::ty::Ty,
|
||||
// tidy-alphabetical-end
|
||||
}
|
||||
@@ -85,7 +85,6 @@ pub use self::fold::*;
|
||||
pub use self::instance::{Instance, InstanceKind, ReifyReason, ShortInstance, UnusedGenericParams};
|
||||
pub use self::list::{List, ListWithCachedTypeInfo};
|
||||
pub use self::opaque_types::OpaqueTypeKey;
|
||||
pub use self::parameterized::ParameterizedOverTcx;
|
||||
pub use self::pattern::{Pattern, PatternKind};
|
||||
pub use self::predicate::{
|
||||
AliasTerm, ArgOutlivesPredicate, Clause, ClauseKind, CoercePredicate, ExistentialPredicate,
|
||||
@@ -158,7 +157,6 @@ mod instance;
|
||||
mod intrinsic;
|
||||
mod list;
|
||||
mod opaque_types;
|
||||
mod parameterized;
|
||||
mod predicate;
|
||||
mod region;
|
||||
mod rvalue_scopes;
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
use std::hash::Hash;
|
||||
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_hir::def_id::DefIndex;
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
use rustc_span::Symbol;
|
||||
|
||||
use crate::ty;
|
||||
|
||||
pub trait ParameterizedOverTcx: 'static {
|
||||
type Value<'tcx>;
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for &'static [T] {
|
||||
type Value<'tcx> = &'tcx [T::Value<'tcx>];
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for Option<T> {
|
||||
type Value<'tcx> = Option<T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<A: ParameterizedOverTcx, B: ParameterizedOverTcx> ParameterizedOverTcx for (A, B) {
|
||||
type Value<'tcx> = (A::Value<'tcx>, B::Value<'tcx>);
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for Vec<T> {
|
||||
type Value<'tcx> = Vec<T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<I: Idx + 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for IndexVec<I, T> {
|
||||
type Value<'tcx> = IndexVec<I, T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<I: Hash + Eq + 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for UnordMap<I, T> {
|
||||
type Value<'tcx> = UnordMap<I, T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for ty::Binder<'static, T> {
|
||||
type Value<'tcx> = ty::Binder<'tcx, T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for ty::EarlyBinder<'static, T> {
|
||||
type Value<'tcx> = ty::EarlyBinder<'tcx, T::Value<'tcx>>;
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! trivially_parameterized_over_tcx {
|
||||
($($ty:ty),+ $(,)?) => {
|
||||
$(
|
||||
impl $crate::ty::ParameterizedOverTcx for $ty {
|
||||
#[allow(unused_lifetimes)]
|
||||
type Value<'tcx> = $ty;
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
trivially_parameterized_over_tcx! {
|
||||
usize,
|
||||
(),
|
||||
u32,
|
||||
u64,
|
||||
bool,
|
||||
std::string::String,
|
||||
crate::metadata::ModChild,
|
||||
crate::middle::codegen_fn_attrs::CodegenFnAttrs,
|
||||
crate::middle::debugger_visualizer::DebuggerVisualizerFile,
|
||||
crate::middle::exported_symbols::SymbolExportInfo,
|
||||
crate::middle::lib_features::FeatureStability,
|
||||
crate::middle::resolve_bound_vars::ObjectLifetimeDefault,
|
||||
crate::mir::ConstQualifs,
|
||||
ty::AsyncDestructor,
|
||||
ty::AssocItemContainer,
|
||||
ty::Asyncness,
|
||||
ty::AnonConstKind,
|
||||
ty::DeducedParamAttrs,
|
||||
ty::Destructor,
|
||||
ty::Generics,
|
||||
ty::ImplPolarity,
|
||||
ty::ImplTraitInTraitData,
|
||||
ty::ReprOptions,
|
||||
ty::TraitDef,
|
||||
ty::UnusedGenericParams,
|
||||
ty::Visibility<DefIndex>,
|
||||
ty::adjustment::CoerceUnsizedInfo,
|
||||
ty::fast_reject::SimplifiedType,
|
||||
ty::IntrinsicDef,
|
||||
rustc_ast::Attribute,
|
||||
rustc_ast::DelimArgs,
|
||||
rustc_attr_data_structures::StrippedCfgItem<rustc_hir::def_id::DefIndex>,
|
||||
rustc_attr_data_structures::ConstStability,
|
||||
rustc_attr_data_structures::DefaultBodyStability,
|
||||
rustc_attr_data_structures::Deprecation,
|
||||
rustc_attr_data_structures::Stability,
|
||||
rustc_hir::Constness,
|
||||
rustc_hir::Defaultness,
|
||||
rustc_hir::Safety,
|
||||
rustc_hir::CoroutineKind,
|
||||
rustc_hir::IsAsync,
|
||||
rustc_hir::LangItem,
|
||||
rustc_hir::def::DefKind,
|
||||
rustc_hir::def::DocLinkResMap,
|
||||
rustc_hir::def_id::DefId,
|
||||
rustc_hir::def_id::DefIndex,
|
||||
rustc_hir::definitions::DefKey,
|
||||
rustc_hir::OpaqueTyOrigin<rustc_hir::def_id::DefId>,
|
||||
rustc_hir::PreciseCapturingArgKind<Symbol, Symbol>,
|
||||
rustc_index::bit_set::DenseBitSet<u32>,
|
||||
rustc_index::bit_set::FiniteBitSet<u32>,
|
||||
rustc_session::cstore::ForeignModule,
|
||||
rustc_session::cstore::LinkagePreference,
|
||||
rustc_session::cstore::NativeLib,
|
||||
rustc_session::config::TargetModifier,
|
||||
rustc_span::ExpnData,
|
||||
rustc_span::ExpnHash,
|
||||
rustc_span::ExpnId,
|
||||
rustc_span::SourceFile,
|
||||
rustc_span::Span,
|
||||
rustc_span::Symbol,
|
||||
rustc_span::def_id::DefPathHash,
|
||||
rustc_span::hygiene::SyntaxContextKey,
|
||||
rustc_span::Ident,
|
||||
rustc_type_ir::Variance,
|
||||
rustc_hir::Attribute,
|
||||
}
|
||||
|
||||
// HACK(compiler-errors): This macro rule can only take a fake path,
|
||||
// not a real, due to parsing ambiguity reasons.
|
||||
#[macro_export]
|
||||
macro_rules! parameterized_over_tcx {
|
||||
($($($fake_path:ident)::+),+ $(,)?) => {
|
||||
$(
|
||||
impl $crate::ty::ParameterizedOverTcx for $($fake_path)::+<'static> {
|
||||
type Value<'tcx> = $($fake_path)::+<'tcx>;
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
parameterized_over_tcx! {
|
||||
crate::middle::exported_symbols::ExportedSymbol,
|
||||
crate::mir::Body,
|
||||
crate::mir::CoroutineLayout,
|
||||
crate::mir::interpret::ConstAllocation,
|
||||
ty::Ty,
|
||||
ty::FnSig,
|
||||
ty::GenericPredicates,
|
||||
ty::ConstConditions,
|
||||
ty::TraitRef,
|
||||
ty::Const,
|
||||
ty::Predicate,
|
||||
ty::Clause,
|
||||
ty::ClauseKind,
|
||||
ty::ImplTraitHeader,
|
||||
}
|
||||
Reference in New Issue
Block a user