Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/lib.rs')
-rw-r--r--crates/hir-ty/src/lib.rs133
1 files changed, 75 insertions, 58 deletions
diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs
index e787fd9b1e..2b0dc931ea 100644
--- a/crates/hir-ty/src/lib.rs
+++ b/crates/hir-ty/src/lib.rs
@@ -21,6 +21,24 @@ extern crate rustc_pattern_analysis;
#[cfg(not(feature = "in-rust-tree"))]
extern crate ra_ap_rustc_pattern_analysis as rustc_pattern_analysis;
+#[cfg(feature = "in-rust-tree")]
+extern crate rustc_ast_ir;
+
+#[cfg(not(feature = "in-rust-tree"))]
+extern crate ra_ap_rustc_ast_ir as rustc_ast_ir;
+
+#[cfg(feature = "in-rust-tree")]
+extern crate rustc_type_ir;
+
+#[cfg(not(feature = "in-rust-tree"))]
+extern crate ra_ap_rustc_type_ir as rustc_type_ir;
+
+#[cfg(feature = "in-rust-tree")]
+extern crate rustc_next_trait_solver;
+
+#[cfg(not(feature = "in-rust-tree"))]
+extern crate ra_ap_rustc_next_trait_solver as rustc_next_trait_solver;
+
mod builder;
mod chalk_db;
mod chalk_ext;
@@ -29,13 +47,16 @@ mod infer;
mod inhabitedness;
mod interner;
mod lower;
+mod lower_nextsolver;
mod mapping;
+pub mod next_solver;
mod target_feature;
mod tls;
mod utils;
pub mod autoderef;
pub mod consteval;
+pub mod consteval_nextsolver;
pub mod db;
pub mod diagnostics;
pub mod display;
@@ -57,7 +78,7 @@ mod variance;
use std::hash::Hash;
use chalk_ir::{
- NoSolution,
+ NoSolution, VariableKinds,
fold::{Shift, TypeFoldable},
interner::HasInterner,
};
@@ -121,9 +142,9 @@ pub type ClosureId = chalk_ir::ClosureId<Interner>;
pub type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
pub type PlaceholderIndex = chalk_ir::PlaceholderIndex;
-pub type VariableKind = chalk_ir::VariableKind<Interner>;
-pub type VariableKinds = chalk_ir::VariableKinds<Interner>;
pub type CanonicalVarKinds = chalk_ir::CanonicalVarKinds<Interner>;
+
+pub(crate) type VariableKind = chalk_ir::VariableKind<Interner>;
/// Represents generic parameters and an item bound by them. When the item has parent, the binders
/// also contain the generic parameters for its parent. See chalk's documentation for details.
///
@@ -145,52 +166,45 @@ pub type GenericArgData = chalk_ir::GenericArgData<Interner>;
pub type Ty = chalk_ir::Ty<Interner>;
pub type TyKind = chalk_ir::TyKind<Interner>;
pub type TypeFlags = chalk_ir::TypeFlags;
-pub type DynTy = chalk_ir::DynTy<Interner>;
+pub(crate) type DynTy = chalk_ir::DynTy<Interner>;
pub type FnPointer = chalk_ir::FnPointer<Interner>;
-// pub type FnSubst = chalk_ir::FnSubst<Interner>; // a re-export so we don't lose the tuple constructor
-pub use chalk_ir::FnSubst;
-pub type ProjectionTy = chalk_ir::ProjectionTy<Interner>;
+pub(crate) use chalk_ir::FnSubst; // a re-export so we don't lose the tuple constructor
+
pub type AliasTy = chalk_ir::AliasTy<Interner>;
-pub type OpaqueTy = chalk_ir::OpaqueTy<Interner>;
-pub type InferenceVar = chalk_ir::InferenceVar;
-pub type Lifetime = chalk_ir::Lifetime<Interner>;
-pub type LifetimeData = chalk_ir::LifetimeData<Interner>;
-pub type LifetimeOutlives = chalk_ir::LifetimeOutlives<Interner>;
+pub type ProjectionTy = chalk_ir::ProjectionTy<Interner>;
+pub(crate) type OpaqueTy = chalk_ir::OpaqueTy<Interner>;
+pub(crate) type InferenceVar = chalk_ir::InferenceVar;
+
+pub(crate) type Lifetime = chalk_ir::Lifetime<Interner>;
+pub(crate) type LifetimeData = chalk_ir::LifetimeData<Interner>;
+pub(crate) type LifetimeOutlives = chalk_ir::LifetimeOutlives<Interner>;
-pub type Const = chalk_ir::Const<Interner>;
-pub type ConstData = chalk_ir::ConstData<Interner>;
pub type ConstValue = chalk_ir::ConstValue<Interner>;
-pub type ConcreteConst = chalk_ir::ConcreteConst<Interner>;
-pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
+pub type Const = chalk_ir::Const<Interner>;
+pub(crate) type ConstData = chalk_ir::ConstData<Interner>;
+pub(crate) type ConcreteConst = chalk_ir::ConcreteConst<Interner>;
+
pub type TraitRef = chalk_ir::TraitRef<Interner>;
pub type QuantifiedWhereClause = Binders<WhereClause>;
-pub type QuantifiedWhereClauses = chalk_ir::QuantifiedWhereClauses<Interner>;
pub type Canonical<T> = chalk_ir::Canonical<T>;
-pub type FnSig = chalk_ir::FnSig<Interner>;
+pub(crate) type ChalkTraitId = chalk_ir::TraitId<Interner>;
+pub(crate) type QuantifiedWhereClauses = chalk_ir::QuantifiedWhereClauses<Interner>;
+
+pub(crate) type FnSig = chalk_ir::FnSig<Interner>;
pub type InEnvironment<T> = chalk_ir::InEnvironment<T>;
-pub type Environment = chalk_ir::Environment<Interner>;
-pub type DomainGoal = chalk_ir::DomainGoal<Interner>;
-pub type Goal = chalk_ir::Goal<Interner>;
pub type AliasEq = chalk_ir::AliasEq<Interner>;
-pub type Solution = chalk_solve::Solution<Interner>;
-pub type Constraint = chalk_ir::Constraint<Interner>;
-pub type Constraints = chalk_ir::Constraints<Interner>;
-pub type ConstrainedSubst = chalk_ir::ConstrainedSubst<Interner>;
-pub type Guidance = chalk_solve::Guidance<Interner>;
pub type WhereClause = chalk_ir::WhereClause<Interner>;
-pub type CanonicalVarKind = chalk_ir::CanonicalVarKind<Interner>;
-pub type GoalData = chalk_ir::GoalData<Interner>;
-pub type Goals = chalk_ir::Goals<Interner>;
-pub type ProgramClauseData = chalk_ir::ProgramClauseData<Interner>;
-pub type ProgramClause = chalk_ir::ProgramClause<Interner>;
-pub type ProgramClauses = chalk_ir::ProgramClauses<Interner>;
-pub type TyData = chalk_ir::TyData<Interner>;
-pub type Variances = chalk_ir::Variances<Interner>;
+pub(crate) type DomainGoal = chalk_ir::DomainGoal<Interner>;
+pub(crate) type Goal = chalk_ir::Goal<Interner>;
+
+pub(crate) type CanonicalVarKind = chalk_ir::CanonicalVarKind<Interner>;
+pub(crate) type GoalData = chalk_ir::GoalData<Interner>;
+pub(crate) type ProgramClause = chalk_ir::ProgramClause<Interner>;
/// A constant can have reference to other things. Memory map job is holding
/// the necessary bits of memory of the const eval session to keep the constant
@@ -311,30 +325,11 @@ where
Binders::empty(Interner, value.shifted_in_from(Interner, DebruijnIndex::ONE))
}
-pub(crate) fn make_type_and_const_binders<T: HasInterner<Interner = Interner>>(
- which_is_const: impl Iterator<Item = Option<Ty>>,
- value: T,
-) -> Binders<T> {
- Binders::new(
- VariableKinds::from_iter(
- Interner,
- which_is_const.map(|x| {
- if let Some(ty) = x {
- chalk_ir::VariableKind::Const(ty)
- } else {
- chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General)
- }
- }),
- ),
- value,
- )
-}
-
pub(crate) fn make_single_type_binders<T: HasInterner<Interner = Interner>>(
value: T,
) -> Binders<T> {
Binders::new(
- VariableKinds::from_iter(
+ chalk_ir::VariableKinds::from_iter(
Interner,
std::iter::once(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General)),
),
@@ -353,7 +348,7 @@ pub(crate) fn make_binders<T: HasInterner<Interner = Interner>>(
pub(crate) fn variable_kinds_from_iter(
db: &dyn HirDatabase,
iter: impl Iterator<Item = hir_def::GenericParamId>,
-) -> VariableKinds {
+) -> VariableKinds<Interner> {
VariableKinds::from_iter(
Interner,
iter.map(|x| match x {
@@ -918,7 +913,7 @@ pub fn callable_sig_from_fn_trait(
let obligation =
InEnvironment { goal: trait_ref.clone().cast(Interner), environment: trait_env.clone() };
let canonical = table.canonicalize(obligation.clone());
- if db.trait_solve(krate, block, canonical.cast(Interner)).is_some() {
+ if !db.trait_solve(krate, block, canonical.cast(Interner)).no_solution() {
table.register_obligation(obligation.goal);
let return_ty = table.normalize_projection_ty(projection);
for fn_x in [FnTrait::Fn, FnTrait::FnMut, FnTrait::FnOnce] {
@@ -929,7 +924,7 @@ pub fn callable_sig_from_fn_trait(
environment: trait_env.clone(),
};
let canonical = table.canonicalize(obligation.clone());
- if db.trait_solve(krate, block, canonical.cast(Interner)).is_some() {
+ if !db.trait_solve(krate, block, canonical.cast(Interner)).no_solution() {
let ret_ty = table.resolve_completely(return_ty);
let args_ty = table.resolve_completely(args_ty);
let params = args_ty
@@ -985,7 +980,7 @@ impl TypeVisitor<Interner> for PlaceholderCollector<'_> {
outer_binder: DebruijnIndex,
) -> std::ops::ControlFlow<Self::BreakTy> {
let has_placeholder_bits = TypeFlags::HAS_TY_PLACEHOLDER | TypeFlags::HAS_CT_PLACEHOLDER;
- let TyData { kind, flags } = ty.data(Interner);
+ let chalk_ir::TyData { kind, flags } = ty.data(Interner);
if let TyKind::Placeholder(idx) = kind {
self.collect(*idx);
@@ -1045,3 +1040,25 @@ pub(crate) enum DeclOrigin {
pub(crate) struct DeclContext {
pub(crate) origin: DeclOrigin,
}
+
+pub fn setup_tracing() -> Option<tracing::subscriber::DefaultGuard> {
+ use std::env;
+ use std::sync::LazyLock;
+ use tracing_subscriber::{Registry, layer::SubscriberExt};
+ use tracing_tree::HierarchicalLayer;
+
+ static ENABLE: LazyLock<bool> = LazyLock::new(|| env::var("CHALK_DEBUG").is_ok());
+ if !*ENABLE {
+ return None;
+ }
+
+ let filter: tracing_subscriber::filter::Targets =
+ env::var("CHALK_DEBUG").ok().and_then(|it| it.parse().ok()).unwrap_or_default();
+ let layer = HierarchicalLayer::default()
+ .with_indent_lines(true)
+ .with_ansi(false)
+ .with_indent_amount(2)
+ .with_writer(std::io::stderr);
+ let subscriber = Registry::default().with(filter).with(layer);
+ Some(tracing::subscriber::set_default(subscriber))
+}