mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Reorganize hir_ty modules
Chalk isn't really a 'traits' thing anymore, so it doesn't make sense to have all the Chalk-related stuff in submodules of `traits`.
This commit is contained in:
parent
99ed68a109
commit
743faa21e7
@ -13,25 +13,23 @@ use hir_def::{
|
||||
};
|
||||
use hir_expand::name::name;
|
||||
|
||||
use super::ChalkContext;
|
||||
use crate::{
|
||||
db::HirDatabase,
|
||||
display::HirDisplay,
|
||||
from_assoc_type_id, make_only_type_binders,
|
||||
method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS},
|
||||
to_assoc_type_id, to_chalk_trait_id,
|
||||
utils::generics,
|
||||
AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, ProjectionTy, Substitution,
|
||||
TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause,
|
||||
};
|
||||
use mapping::{convert_where_clauses, generic_predicate_to_inline_bound, TypeAliasAsValue};
|
||||
use crate::{AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, Interner, ProjectionTy, Substitution, TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause, traits::ChalkContext, db::HirDatabase, display::HirDisplay, from_assoc_type_id, make_only_type_binders, mapping::{convert_where_clauses, generic_predicate_to_inline_bound, TypeAliasAsValue}, method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, to_assoc_type_id, to_chalk_trait_id, utils::generics};
|
||||
|
||||
pub use self::interner::Interner;
|
||||
pub(crate) use self::interner::*;
|
||||
pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>;
|
||||
pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>;
|
||||
pub(crate) type StructDatum = chalk_solve::rust_ir::AdtDatum<Interner>;
|
||||
pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>;
|
||||
pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>;
|
||||
|
||||
pub(super) mod tls;
|
||||
mod interner;
|
||||
mod mapping;
|
||||
pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
|
||||
pub(crate) type TraitId = chalk_ir::TraitId<Interner>;
|
||||
pub(crate) type AdtId = chalk_ir::AdtId<Interner>;
|
||||
pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
|
||||
pub(crate) type ImplId = chalk_ir::ImplId<Interner>;
|
||||
pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>;
|
||||
pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>;
|
||||
pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>;
|
||||
pub(crate) type Variances = chalk_ir::Variances<Interner>;
|
||||
|
||||
pub(crate) trait ToChalk {
|
||||
type Chalk;
|
@ -9,12 +9,7 @@ use hir_def::{
|
||||
};
|
||||
use la_arena::ArenaMap;
|
||||
|
||||
use crate::{
|
||||
method_resolution::{InherentImpls, TraitImpls},
|
||||
traits::chalk,
|
||||
Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, PolyFnSig,
|
||||
QuantifiedWhereClause, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId,
|
||||
};
|
||||
use crate::{Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, Interner, PolyFnSig, QuantifiedWhereClause, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, chalk_db, method_resolution::{InherentImpls, TraitImpls}};
|
||||
use hir_expand::name::Name;
|
||||
|
||||
#[salsa::query_group(HirDatabaseStorage)]
|
||||
@ -94,33 +89,33 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
||||
#[salsa::interned]
|
||||
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
|
||||
|
||||
#[salsa::invoke(chalk::associated_ty_data_query)]
|
||||
fn associated_ty_data(&self, id: chalk::AssocTypeId) -> Arc<chalk::AssociatedTyDatum>;
|
||||
#[salsa::invoke(chalk_db::associated_ty_data_query)]
|
||||
fn associated_ty_data(&self, id: chalk_db::AssocTypeId) -> Arc<chalk_db::AssociatedTyDatum>;
|
||||
|
||||
#[salsa::invoke(chalk::trait_datum_query)]
|
||||
fn trait_datum(&self, krate: CrateId, trait_id: chalk::TraitId) -> Arc<chalk::TraitDatum>;
|
||||
#[salsa::invoke(chalk_db::trait_datum_query)]
|
||||
fn trait_datum(&self, krate: CrateId, trait_id: chalk_db::TraitId) -> Arc<chalk_db::TraitDatum>;
|
||||
|
||||
#[salsa::invoke(chalk::struct_datum_query)]
|
||||
fn struct_datum(&self, krate: CrateId, struct_id: chalk::AdtId) -> Arc<chalk::StructDatum>;
|
||||
#[salsa::invoke(chalk_db::struct_datum_query)]
|
||||
fn struct_datum(&self, krate: CrateId, struct_id: chalk_db::AdtId) -> Arc<chalk_db::StructDatum>;
|
||||
|
||||
#[salsa::invoke(crate::traits::chalk::impl_datum_query)]
|
||||
fn impl_datum(&self, krate: CrateId, impl_id: chalk::ImplId) -> Arc<chalk::ImplDatum>;
|
||||
#[salsa::invoke(chalk_db::impl_datum_query)]
|
||||
fn impl_datum(&self, krate: CrateId, impl_id: chalk_db::ImplId) -> Arc<chalk_db::ImplDatum>;
|
||||
|
||||
#[salsa::invoke(crate::traits::chalk::fn_def_datum_query)]
|
||||
fn fn_def_datum(&self, krate: CrateId, fn_def_id: FnDefId) -> Arc<chalk::FnDefDatum>;
|
||||
#[salsa::invoke(chalk_db::fn_def_datum_query)]
|
||||
fn fn_def_datum(&self, krate: CrateId, fn_def_id: FnDefId) -> Arc<chalk_db::FnDefDatum>;
|
||||
|
||||
#[salsa::invoke(crate::traits::chalk::fn_def_variance_query)]
|
||||
fn fn_def_variance(&self, krate: CrateId, fn_def_id: FnDefId) -> chalk::Variances;
|
||||
#[salsa::invoke(chalk_db::fn_def_variance_query)]
|
||||
fn fn_def_variance(&self, krate: CrateId, fn_def_id: FnDefId) -> chalk_db::Variances;
|
||||
|
||||
#[salsa::invoke(crate::traits::chalk::adt_variance_query)]
|
||||
fn adt_variance(&self, krate: CrateId, adt_id: chalk::AdtId) -> chalk::Variances;
|
||||
#[salsa::invoke(chalk_db::adt_variance_query)]
|
||||
fn adt_variance(&self, krate: CrateId, adt_id: chalk_db::AdtId) -> chalk_db::Variances;
|
||||
|
||||
#[salsa::invoke(crate::traits::chalk::associated_ty_value_query)]
|
||||
#[salsa::invoke(chalk_db::associated_ty_value_query)]
|
||||
fn associated_ty_value(
|
||||
&self,
|
||||
krate: CrateId,
|
||||
id: chalk::AssociatedTyValueId,
|
||||
) -> Arc<chalk::AssociatedTyValue>;
|
||||
id: chalk_db::AssociatedTyValueId,
|
||||
) -> Arc<chalk_db::AssociatedTyValue>;
|
||||
|
||||
#[salsa::invoke(crate::traits::trait_solve_query)]
|
||||
fn trait_solve(
|
||||
@ -129,12 +124,12 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
||||
goal: crate::Canonical<crate::InEnvironment<crate::DomainGoal>>,
|
||||
) -> Option<crate::Solution>;
|
||||
|
||||
#[salsa::invoke(crate::traits::chalk::program_clauses_for_chalk_env_query)]
|
||||
#[salsa::invoke(chalk_db::program_clauses_for_chalk_env_query)]
|
||||
fn program_clauses_for_chalk_env(
|
||||
&self,
|
||||
krate: CrateId,
|
||||
env: chalk_ir::Environment<chalk::Interner>,
|
||||
) -> chalk_ir::ProgramClauses<chalk::Interner>;
|
||||
env: chalk_ir::Environment<Interner>,
|
||||
) -> chalk_ir::ProgramClauses<Interner>;
|
||||
}
|
||||
|
||||
fn infer_wait(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> {
|
||||
|
@ -21,7 +21,7 @@ use hir_expand::name::Name;
|
||||
use crate::{
|
||||
const_from_placeholder_idx, db::HirDatabase, from_assoc_type_id, from_foreign_def_id,
|
||||
from_placeholder_idx, lt_from_placeholder_idx, primitive, subst_prefix, to_assoc_type_id,
|
||||
traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId,
|
||||
chalk_db::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId,
|
||||
CallableSig, Const, ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime,
|
||||
LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt,
|
||||
QuantifiedWhereClause, Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause,
|
||||
|
@ -20,7 +20,8 @@ use crate::{
|
||||
method_resolution, op,
|
||||
primitive::{self, UintTy},
|
||||
static_lifetime, to_chalk_trait_id,
|
||||
traits::{chalk::from_chalk, FnTrait},
|
||||
traits::FnTrait,
|
||||
chalk_db::from_chalk,
|
||||
utils::{generics, Generics},
|
||||
AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner,
|
||||
ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyExt, TyKind,
|
||||
|
@ -1,8 +1,7 @@
|
||||
//! Implementation of the Chalk `Interner` trait, which allows customizing the
|
||||
//! representation of the various objects Chalk deals with (types, goals etc.).
|
||||
|
||||
use super::tls;
|
||||
use crate::GenericArg;
|
||||
use crate::{GenericArg, tls, chalk_db};
|
||||
use base_db::salsa::InternId;
|
||||
use chalk_ir::{Goal, GoalData};
|
||||
use hir_def::{
|
||||
@ -15,21 +14,6 @@ use std::{fmt, sync::Arc};
|
||||
#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
|
||||
pub struct Interner;
|
||||
|
||||
pub(crate) type AssocTypeId = chalk_ir::AssocTypeId<Interner>;
|
||||
pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>;
|
||||
pub(crate) type TraitId = chalk_ir::TraitId<Interner>;
|
||||
pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>;
|
||||
pub(crate) type AdtId = chalk_ir::AdtId<Interner>;
|
||||
pub(crate) type StructDatum = chalk_solve::rust_ir::AdtDatum<Interner>;
|
||||
pub(crate) type ImplId = chalk_ir::ImplId<Interner>;
|
||||
pub(crate) type ImplDatum = chalk_solve::rust_ir::ImplDatum<Interner>;
|
||||
pub(crate) type AssociatedTyValueId = chalk_solve::rust_ir::AssociatedTyValueId<Interner>;
|
||||
pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Interner>;
|
||||
pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>;
|
||||
pub(crate) type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
|
||||
pub(crate) type OpaqueTyDatum = chalk_solve::rust_ir::OpaqueTyDatum<Interner>;
|
||||
pub(crate) type Variances = chalk_ir::Variances<Interner>;
|
||||
|
||||
#[derive(PartialEq, Eq, Hash, Debug)]
|
||||
pub struct InternedWrapper<T>(T);
|
||||
|
||||
@ -76,15 +60,15 @@ impl chalk_ir::interner::Interner for Interner {
|
||||
type Identifier = TypeAliasId;
|
||||
type FnAbi = ();
|
||||
|
||||
fn debug_adt_id(type_kind_id: AdtId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
|
||||
fn debug_adt_id(type_kind_id: chalk_db::AdtId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
|
||||
tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt)))
|
||||
}
|
||||
|
||||
fn debug_trait_id(type_kind_id: TraitId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
|
||||
fn debug_trait_id(type_kind_id: chalk_db::TraitId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
|
||||
tls::with_current_program(|prog| Some(prog?.debug_trait_id(type_kind_id, fmt)))
|
||||
}
|
||||
|
||||
fn debug_assoc_type_id(id: AssocTypeId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
|
||||
fn debug_assoc_type_id(id: chalk_db::AssocTypeId, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
|
||||
tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt)))
|
||||
}
|
||||
|
@ -18,6 +18,10 @@ mod chalk_cast;
|
||||
mod chalk_ext;
|
||||
mod builder;
|
||||
mod walk;
|
||||
mod tls;
|
||||
mod interner;
|
||||
mod mapping;
|
||||
mod chalk_db;
|
||||
|
||||
pub mod display;
|
||||
pub mod db;
|
||||
@ -51,8 +55,9 @@ pub use lower::{
|
||||
associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
|
||||
TyDefId, TyLoweringContext, ValueTyDefId,
|
||||
};
|
||||
pub use traits::{chalk::Interner, TraitEnvironment};
|
||||
pub use traits::TraitEnvironment;
|
||||
pub use walk::TypeWalk;
|
||||
pub use interner::Interner;
|
||||
|
||||
pub use chalk_ir::{
|
||||
cast::Cast, AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind,
|
||||
|
@ -28,7 +28,8 @@ use stdx::impl_from;
|
||||
use crate::{
|
||||
db::HirDatabase,
|
||||
dummy_usize_const, static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
|
||||
traits::chalk::{Interner, ToChalk},
|
||||
chalk_db::ToChalk,
|
||||
Interner,
|
||||
utils::{
|
||||
all_super_trait_refs, associated_type_by_name_including_super_traits, generics, Generics,
|
||||
},
|
||||
|
@ -3,40 +3,34 @@
|
||||
//! Chalk (in both directions); plus some helper functions for more specialized
|
||||
//! conversions.
|
||||
|
||||
use chalk_ir::cast::Cast;
|
||||
use chalk_ir::{DebruijnIndex, cast::Cast, fold::Shift};
|
||||
use chalk_solve::rust_ir;
|
||||
|
||||
use base_db::salsa::InternKey;
|
||||
use hir_def::{GenericDefId, TypeAliasId};
|
||||
|
||||
use crate::{
|
||||
db::HirDatabase, AliasTy, CallableDefId, ProjectionTyExt, QuantifiedWhereClause, Substitution,
|
||||
Ty, WhereClause,
|
||||
};
|
||||
|
||||
use super::interner::*;
|
||||
use super::*;
|
||||
use crate::{AliasEq, AliasTy, CallableDefId, FnDefId, Interner, ProjectionTyExt, QuantifiedWhereClause, Substitution, Ty, WhereClause, chalk_db::{self, ToChalk}, db::HirDatabase};
|
||||
|
||||
impl ToChalk for hir_def::TraitId {
|
||||
type Chalk = TraitId;
|
||||
type Chalk = chalk_db::TraitId;
|
||||
|
||||
fn to_chalk(self, _db: &dyn HirDatabase) -> TraitId {
|
||||
fn to_chalk(self, _db: &dyn HirDatabase) -> chalk_db::TraitId {
|
||||
chalk_ir::TraitId(self.as_intern_id())
|
||||
}
|
||||
|
||||
fn from_chalk(_db: &dyn HirDatabase, trait_id: TraitId) -> hir_def::TraitId {
|
||||
fn from_chalk(_db: &dyn HirDatabase, trait_id: chalk_db::TraitId) -> hir_def::TraitId {
|
||||
InternKey::from_intern_id(trait_id.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToChalk for hir_def::ImplId {
|
||||
type Chalk = ImplId;
|
||||
type Chalk = chalk_db::ImplId;
|
||||
|
||||
fn to_chalk(self, _db: &dyn HirDatabase) -> ImplId {
|
||||
fn to_chalk(self, _db: &dyn HirDatabase) -> chalk_db::ImplId {
|
||||
chalk_ir::ImplId(self.as_intern_id())
|
||||
}
|
||||
|
||||
fn from_chalk(_db: &dyn HirDatabase, impl_id: ImplId) -> hir_def::ImplId {
|
||||
fn from_chalk(_db: &dyn HirDatabase, impl_id: chalk_db::ImplId) -> hir_def::ImplId {
|
||||
InternKey::from_intern_id(impl_id.0)
|
||||
}
|
||||
}
|
||||
@ -56,15 +50,15 @@ impl ToChalk for CallableDefId {
|
||||
pub(crate) struct TypeAliasAsValue(pub(crate) TypeAliasId);
|
||||
|
||||
impl ToChalk for TypeAliasAsValue {
|
||||
type Chalk = AssociatedTyValueId;
|
||||
type Chalk = chalk_db::AssociatedTyValueId;
|
||||
|
||||
fn to_chalk(self, _db: &dyn HirDatabase) -> AssociatedTyValueId {
|
||||
fn to_chalk(self, _db: &dyn HirDatabase) -> chalk_db::AssociatedTyValueId {
|
||||
rust_ir::AssociatedTyValueId(self.0.as_intern_id())
|
||||
}
|
||||
|
||||
fn from_chalk(
|
||||
_db: &dyn HirDatabase,
|
||||
assoc_ty_value_id: AssociatedTyValueId,
|
||||
assoc_ty_value_id: chalk_db::AssociatedTyValueId,
|
||||
) -> TypeAliasAsValue {
|
||||
TypeAliasAsValue(TypeAliasId::from_intern_id(assoc_ty_value_id.0))
|
||||
}
|
@ -4,8 +4,7 @@ use std::fmt;
|
||||
use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication};
|
||||
use itertools::Itertools;
|
||||
|
||||
use super::{from_chalk, Interner};
|
||||
use crate::{db::HirDatabase, from_assoc_type_id, CallableDefId};
|
||||
use crate::{db::HirDatabase, from_assoc_type_id, CallableDefId, chalk_db::{from_chalk, self}, Interner};
|
||||
use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId};
|
||||
|
||||
pub(crate) use unsafe_tls::{set_current_program, with_current_program};
|
||||
@ -15,7 +14,7 @@ pub(crate) struct DebugContext<'a>(&'a dyn HirDatabase);
|
||||
impl DebugContext<'_> {
|
||||
pub(crate) fn debug_struct_id(
|
||||
&self,
|
||||
id: super::AdtId,
|
||||
id: chalk_db::AdtId,
|
||||
f: &mut fmt::Formatter<'_>,
|
||||
) -> Result<(), fmt::Error> {
|
||||
let name = match id.0 {
|
||||
@ -28,7 +27,7 @@ impl DebugContext<'_> {
|
||||
|
||||
pub(crate) fn debug_trait_id(
|
||||
&self,
|
||||
id: super::TraitId,
|
||||
id: chalk_db::TraitId,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Result<(), fmt::Error> {
|
||||
let trait_: hir_def::TraitId = from_chalk(self.0, id);
|
||||
@ -38,7 +37,7 @@ impl DebugContext<'_> {
|
||||
|
||||
pub(crate) fn debug_assoc_type_id(
|
||||
&self,
|
||||
id: super::AssocTypeId,
|
||||
id: chalk_db::AssocTypeId,
|
||||
fmt: &mut fmt::Formatter<'_>,
|
||||
) -> Result<(), fmt::Error> {
|
||||
let type_alias: TypeAliasId = from_assoc_type_id(id);
|
@ -9,20 +9,16 @@ use stdx::panic_context;
|
||||
|
||||
use crate::{
|
||||
db::HirDatabase, AliasEq, AliasTy, Canonical, DomainGoal, Guidance, HirDisplay, InEnvironment,
|
||||
Solution, TraitRefExt, Ty, TyKind, WhereClause,
|
||||
Solution, TraitRefExt, Ty, TyKind, WhereClause, Interner,
|
||||
};
|
||||
|
||||
use self::chalk::Interner;
|
||||
|
||||
pub(crate) mod chalk;
|
||||
|
||||
/// This controls how much 'time' we give the Chalk solver before giving up.
|
||||
const CHALK_SOLVER_FUEL: i32 = 100;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
struct ChalkContext<'a> {
|
||||
db: &'a dyn HirDatabase,
|
||||
krate: CrateId,
|
||||
pub(crate) struct ChalkContext<'a> {
|
||||
pub(crate) db: &'a dyn HirDatabase,
|
||||
pub(crate) krate: CrateId,
|
||||
}
|
||||
|
||||
fn create_chalk_solver() -> chalk_recursive::RecursiveSolver<Interner> {
|
||||
@ -148,7 +144,7 @@ fn solve(
|
||||
// don't set the TLS for Chalk unless Chalk debugging is active, to make
|
||||
// extra sure we only use it for debugging
|
||||
let solution =
|
||||
if is_chalk_debug() { chalk::tls::set_current_program(db, solve) } else { solve() };
|
||||
if is_chalk_debug() { crate::tls::set_current_program(db, solve) } else { solve() };
|
||||
|
||||
solution
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user