diff --git a/compiler/rustc_type_ir/Cargo.toml b/compiler/rustc_type_ir/Cargo.toml index 18a09067a2c..02d163531b4 100644 --- a/compiler/rustc_type_ir/Cargo.toml +++ b/compiler/rustc_type_ir/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" # tidy-alphabetical-start bitflags = "2.4.1" derivative = "2.2.0" -rustc_ast_ir = { path = "../rustc_ast_ir" } +rustc_ast_ir = { path = "../rustc_ast_ir", default-features = false } rustc_data_structures = { path = "../rustc_data_structures", optional = true } rustc_index = { path = "../rustc_index", default-features = false } rustc_macros = { path = "../rustc_macros", optional = true } diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index e50d59ba5f0..39ea61f0393 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -5,14 +5,16 @@ use std::ops::{ControlFlow, Deref}; #[cfg(feature = "nightly")] use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable}; +#[cfg(feature = "nightly")] use rustc_serialize::Decodable; use tracing::debug; +use crate::data_structures::SsoHashSet; use crate::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable}; use crate::inherent::*; use crate::lift::Lift; use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor}; -use crate::{self as ty, Interner, SsoHashSet}; +use crate::{self as ty, Interner}; /// Binder is a binder for higher-ranked lifetimes or types. It is part of the /// compiler's representation for things like `for<'a> Fn(&'a isize)` @@ -55,6 +57,7 @@ where } } +#[cfg(feature = "nightly")] macro_rules! impl_binder_encode_decode { ($($t:ty),+ $(,)?) => { $( @@ -82,6 +85,7 @@ macro_rules! impl_binder_encode_decode { } } +#[cfg(feature = "nightly")] impl_binder_encode_decode! { ty::FnSig, ty::TraitPredicate, diff --git a/compiler/rustc_type_ir/src/data_structures.rs b/compiler/rustc_type_ir/src/data_structures.rs new file mode 100644 index 00000000000..86d7b31d216 --- /dev/null +++ b/compiler/rustc_type_ir/src/data_structures.rs @@ -0,0 +1,19 @@ +#[cfg(feature = "nightly")] +mod impl_ { + pub use rustc_data_structures::fx::FxHashMap as HashMap; + pub use rustc_data_structures::fx::FxHashSet as HashSet; + pub use rustc_data_structures::sso::SsoHashMap as SsoHashMap; + pub use rustc_data_structures::sso::SsoHashSet as SsoHashSet; + pub use rustc_data_structures::sync::Lrc; +} + +#[cfg(not(feature = "nightly"))] +mod impl_ { + pub use std::collections::HashMap; + pub use std::collections::HashSet; + pub use std::collections::HashMap as SsoHashMap; + pub use std::collections::HashSet as SsoHashSet; + pub use std::sync::Arc as Lrc; +} + +pub use impl_::*; \ No newline at end of file diff --git a/compiler/rustc_type_ir/src/error.rs b/compiler/rustc_type_ir/src/error.rs index 27623ea9cac..8b59e9a6f48 100644 --- a/compiler/rustc_type_ir/src/error.rs +++ b/compiler/rustc_type_ir/src/error.rs @@ -30,7 +30,7 @@ impl ExpectedFound { Debug(bound = "") )] #[derive(TypeVisitable_Generic)] -#[rustc_pass_by_value] +#[cfg_attr(feature = "nightly", rustc_pass_by_value)] pub enum TypeError { Mismatch, ConstnessMismatch(ExpectedFound), diff --git a/compiler/rustc_type_ir/src/fold.rs b/compiler/rustc_type_ir/src/fold.rs index ee3e5ce66d0..26e365f64fa 100644 --- a/compiler/rustc_type_ir/src/fold.rs +++ b/compiler/rustc_type_ir/src/fold.rs @@ -49,9 +49,10 @@ use rustc_index::{Idx, IndexVec}; use std::mem; use tracing::debug; +use crate::data_structures::Lrc; use crate::inherent::*; use crate::visit::{TypeVisitable, TypeVisitableExt as _}; -use crate::{self as ty, Interner, Lrc}; +use crate::{self as ty, Interner}; #[cfg(feature = "nightly")] type Never = !; diff --git a/compiler/rustc_type_ir/src/generic_arg.rs b/compiler/rustc_type_ir/src/generic_arg.rs index cc8c4444657..b158f0f5eee 100644 --- a/compiler/rustc_type_ir/src/generic_arg.rs +++ b/compiler/rustc_type_ir/src/generic_arg.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "nightly")] use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable}; use crate::Interner; diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index 64d3400976a..be6deee011b 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -8,8 +8,8 @@ use std::hash::Hash; use std::ops::Deref; use rustc_ast_ir::Mutability; -use rustc_data_structures::fx::FxHashSet; +use crate::data_structures::HashSet; use crate::fold::{TypeFoldable, TypeSuperFoldable}; use crate::relate::Relate; use crate::solve::{CacheData, CanonicalInput, QueryResult, Reveal}; @@ -530,7 +530,7 @@ pub trait EvaluationCache { proof_tree: Option, additional_depth: usize, encountered_overflow: bool, - cycle_participants: FxHashSet>, + cycle_participants: HashSet>, dep_node: I::DepNodeIndex, result: QueryResult, ); diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index 130ea231bf7..9b8ca5efdda 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -7,27 +7,19 @@ #![cfg_attr(feature = "nightly", allow(internal_features))] // tidy-alphabetical-end -#[cfg(feature = "nightly")] extern crate self as rustc_type_ir; -#[cfg(feature = "nightly")] -use rustc_data_structures::sso::SsoHashSet; -#[cfg(feature = "nightly")] -use rustc_data_structures::sync::Lrc; #[cfg(feature = "nightly")] use rustc_macros::{Decodable, Encodable, HashStable_NoContext}; -#[cfg(not(feature = "nightly"))] -use std::collections::HashSet as SsoHashSet; use std::fmt; use std::hash::Hash; -#[cfg(not(feature = "nightly"))] -use std::sync::Arc as Lrc; // These modules are `pub` since they are not glob-imported. #[macro_use] pub mod visit; #[cfg(feature = "nightly")] pub mod codec; +pub mod data_structures; pub mod error; pub mod fold; pub mod inherent; diff --git a/compiler/rustc_type_ir/src/opaque_ty.rs b/compiler/rustc_type_ir/src/opaque_ty.rs index 60737066597..738350f1b34 100644 --- a/compiler/rustc_type_ir/src/opaque_ty.rs +++ b/compiler/rustc_type_ir/src/opaque_ty.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "nightly")] use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable}; use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic}; diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index 8a6ba87b60e..429bc3197d4 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -1,12 +1,13 @@ use std::iter; use rustc_ast_ir::Mutability; -use rustc_type_ir::error::{ExpectedFound, TypeError}; -use rustc_type_ir::fold::TypeFoldable; -use rustc_type_ir::inherent::*; -use rustc_type_ir::{self as ty, Interner}; use tracing::{debug, instrument}; +use crate::error::{ExpectedFound, TypeError}; +use crate::fold::TypeFoldable; +use crate::inherent::*; +use crate::{self as ty, Interner}; + pub type RelateResult = Result>; /// Extra information about why we ended up with a particular variance. diff --git a/compiler/rustc_type_ir/src/visit.rs b/compiler/rustc_type_ir/src/visit.rs index 6880c7b8cef..473a0aa250f 100644 --- a/compiler/rustc_type_ir/src/visit.rs +++ b/compiler/rustc_type_ir/src/visit.rs @@ -47,8 +47,9 @@ use rustc_index::{Idx, IndexVec}; use std::fmt; use std::ops::ControlFlow; +use crate::data_structures::Lrc; use crate::inherent::*; -use crate::{self as ty, Interner, Lrc, TypeFlags}; +use crate::{self as ty, Interner, TypeFlags}; /// This trait is implemented for every type that can be visited, /// providing the skeleton of the traversal.