mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Move ToChalk -> mapping
This commit is contained in:
parent
743faa21e7
commit
5ca481bbdc
10 changed files with 76 additions and 37 deletions
|
@ -1,4 +1,5 @@
|
||||||
//! Conversion code from/to Chalk.
|
//! The implementation of `RustIrDatabase` for Chalk, which provides information
|
||||||
|
//! about the code that Chalk needs.
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
@ -13,7 +14,21 @@ use hir_def::{
|
||||||
};
|
};
|
||||||
use hir_expand::name::name;
|
use hir_expand::name::name;
|
||||||
|
|
||||||
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};
|
use crate::{
|
||||||
|
db::HirDatabase,
|
||||||
|
display::HirDisplay,
|
||||||
|
from_assoc_type_id, make_only_type_binders,
|
||||||
|
mapping::{
|
||||||
|
convert_where_clauses, from_chalk, generic_predicate_to_inline_bound, ToChalk,
|
||||||
|
TypeAliasAsValue,
|
||||||
|
},
|
||||||
|
method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS},
|
||||||
|
to_assoc_type_id, to_chalk_trait_id,
|
||||||
|
traits::ChalkContext,
|
||||||
|
utils::generics,
|
||||||
|
AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, Interner, ProjectionTy,
|
||||||
|
Substitution, TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause,
|
||||||
|
};
|
||||||
|
|
||||||
pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>;
|
pub(crate) type AssociatedTyDatum = chalk_solve::rust_ir::AssociatedTyDatum<Interner>;
|
||||||
pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>;
|
pub(crate) type TraitDatum = chalk_solve::rust_ir::TraitDatum<Interner>;
|
||||||
|
@ -31,19 +46,6 @@ pub(crate) type AssociatedTyValue = chalk_solve::rust_ir::AssociatedTyValue<Inte
|
||||||
pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>;
|
pub(crate) type FnDefDatum = chalk_solve::rust_ir::FnDefDatum<Interner>;
|
||||||
pub(crate) type Variances = chalk_ir::Variances<Interner>;
|
pub(crate) type Variances = chalk_ir::Variances<Interner>;
|
||||||
|
|
||||||
pub(crate) trait ToChalk {
|
|
||||||
type Chalk;
|
|
||||||
fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk;
|
|
||||||
fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn from_chalk<T, ChalkT>(db: &dyn HirDatabase, chalk: ChalkT) -> T
|
|
||||||
where
|
|
||||||
T: ToChalk<Chalk = ChalkT>,
|
|
||||||
{
|
|
||||||
T::from_chalk(db, chalk)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
||||||
fn associated_ty_data(&self, id: AssocTypeId) -> Arc<AssociatedTyDatum> {
|
fn associated_ty_data(&self, id: AssocTypeId) -> Arc<AssociatedTyDatum> {
|
||||||
self.db.associated_ty_data(id)
|
self.db.associated_ty_data(id)
|
||||||
|
|
|
@ -9,7 +9,12 @@ use hir_def::{
|
||||||
};
|
};
|
||||||
use la_arena::ArenaMap;
|
use la_arena::ArenaMap;
|
||||||
|
|
||||||
use crate::{Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, Interner, PolyFnSig, QuantifiedWhereClause, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, chalk_db, method_resolution::{InherentImpls, TraitImpls}};
|
use crate::{
|
||||||
|
chalk_db,
|
||||||
|
method_resolution::{InherentImpls, TraitImpls},
|
||||||
|
Binders, CallableDefId, FnDefId, ImplTraitId, InferenceResult, Interner, PolyFnSig,
|
||||||
|
QuantifiedWhereClause, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId,
|
||||||
|
};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
|
|
||||||
#[salsa::query_group(HirDatabaseStorage)]
|
#[salsa::query_group(HirDatabaseStorage)]
|
||||||
|
@ -93,10 +98,15 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
||||||
fn associated_ty_data(&self, id: chalk_db::AssocTypeId) -> Arc<chalk_db::AssociatedTyDatum>;
|
fn associated_ty_data(&self, id: chalk_db::AssocTypeId) -> Arc<chalk_db::AssociatedTyDatum>;
|
||||||
|
|
||||||
#[salsa::invoke(chalk_db::trait_datum_query)]
|
#[salsa::invoke(chalk_db::trait_datum_query)]
|
||||||
fn trait_datum(&self, krate: CrateId, trait_id: chalk_db::TraitId) -> Arc<chalk_db::TraitDatum>;
|
fn trait_datum(&self, krate: CrateId, trait_id: chalk_db::TraitId)
|
||||||
|
-> Arc<chalk_db::TraitDatum>;
|
||||||
|
|
||||||
#[salsa::invoke(chalk_db::struct_datum_query)]
|
#[salsa::invoke(chalk_db::struct_datum_query)]
|
||||||
fn struct_datum(&self, krate: CrateId, struct_id: chalk_db::AdtId) -> Arc<chalk_db::StructDatum>;
|
fn struct_datum(
|
||||||
|
&self,
|
||||||
|
krate: CrateId,
|
||||||
|
struct_id: chalk_db::AdtId,
|
||||||
|
) -> Arc<chalk_db::StructDatum>;
|
||||||
|
|
||||||
#[salsa::invoke(chalk_db::impl_datum_query)]
|
#[salsa::invoke(chalk_db::impl_datum_query)]
|
||||||
fn impl_datum(&self, krate: CrateId, impl_id: chalk_db::ImplId) -> Arc<chalk_db::ImplDatum>;
|
fn impl_datum(&self, krate: CrateId, impl_id: chalk_db::ImplId) -> Arc<chalk_db::ImplDatum>;
|
||||||
|
|
|
@ -20,11 +20,11 @@ use hir_expand::name::Name;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
const_from_placeholder_idx, db::HirDatabase, from_assoc_type_id, from_foreign_def_id,
|
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,
|
from_placeholder_idx, lt_from_placeholder_idx, mapping::from_chalk, primitive, subst_prefix,
|
||||||
chalk_db::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId,
|
to_assoc_type_id, utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, CallableSig, Const,
|
||||||
CallableSig, Const, ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime,
|
ConstValue, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, LifetimeData,
|
||||||
LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt,
|
LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, ProjectionTyExt, QuantifiedWhereClause,
|
||||||
QuantifiedWhereClause, Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause,
|
Scalar, TraitRef, TraitRefExt, Ty, TyExt, TyKind, WhereClause,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct HirFormatter<'a> {
|
pub struct HirFormatter<'a> {
|
||||||
|
|
|
@ -17,11 +17,11 @@ use syntax::ast::RangeOp;
|
||||||
use crate::{
|
use crate::{
|
||||||
autoderef, dummy_usize_const,
|
autoderef, dummy_usize_const,
|
||||||
lower::lower_to_chalk_mutability,
|
lower::lower_to_chalk_mutability,
|
||||||
|
mapping::from_chalk,
|
||||||
method_resolution, op,
|
method_resolution, op,
|
||||||
primitive::{self, UintTy},
|
primitive::{self, UintTy},
|
||||||
static_lifetime, to_chalk_trait_id,
|
static_lifetime, to_chalk_trait_id,
|
||||||
traits::FnTrait,
|
traits::FnTrait,
|
||||||
chalk_db::from_chalk,
|
|
||||||
utils::{generics, Generics},
|
utils::{generics, Generics},
|
||||||
AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner,
|
AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner,
|
||||||
ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyExt, TyKind,
|
ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyExt, TyKind,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Implementation of the Chalk `Interner` trait, which allows customizing the
|
//! Implementation of the Chalk `Interner` trait, which allows customizing the
|
||||||
//! representation of the various objects Chalk deals with (types, goals etc.).
|
//! representation of the various objects Chalk deals with (types, goals etc.).
|
||||||
|
|
||||||
use crate::{GenericArg, tls, chalk_db};
|
use crate::{chalk_db, tls, GenericArg};
|
||||||
use base_db::salsa::InternId;
|
use base_db::salsa::InternId;
|
||||||
use chalk_ir::{Goal, GoalData};
|
use chalk_ir::{Goal, GoalData};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
|
@ -60,15 +60,24 @@ impl chalk_ir::interner::Interner for Interner {
|
||||||
type Identifier = TypeAliasId;
|
type Identifier = TypeAliasId;
|
||||||
type FnAbi = ();
|
type FnAbi = ();
|
||||||
|
|
||||||
fn debug_adt_id(type_kind_id: chalk_db::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)))
|
tls::with_current_program(|prog| Some(prog?.debug_struct_id(type_kind_id, fmt)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_trait_id(type_kind_id: chalk_db::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)))
|
tls::with_current_program(|prog| Some(prog?.debug_trait_id(type_kind_id, fmt)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_assoc_type_id(id: chalk_db::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)))
|
tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,13 +51,13 @@ pub use autoderef::autoderef;
|
||||||
pub use builder::TyBuilder;
|
pub use builder::TyBuilder;
|
||||||
pub use chalk_ext::*;
|
pub use chalk_ext::*;
|
||||||
pub use infer::{could_unify, InferenceResult};
|
pub use infer::{could_unify, InferenceResult};
|
||||||
|
pub use interner::Interner;
|
||||||
pub use lower::{
|
pub use lower::{
|
||||||
associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
|
associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
|
||||||
TyDefId, TyLoweringContext, ValueTyDefId,
|
TyDefId, TyLoweringContext, ValueTyDefId,
|
||||||
};
|
};
|
||||||
pub use traits::TraitEnvironment;
|
pub use traits::TraitEnvironment;
|
||||||
pub use walk::TypeWalk;
|
pub use walk::TypeWalk;
|
||||||
pub use interner::Interner;
|
|
||||||
|
|
||||||
pub use chalk_ir::{
|
pub use chalk_ir::{
|
||||||
cast::Cast, AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind,
|
cast::Cast, AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind,
|
||||||
|
|
|
@ -27,14 +27,14 @@ use stdx::impl_from;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
dummy_usize_const, static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
|
dummy_usize_const,
|
||||||
chalk_db::ToChalk,
|
mapping::ToChalk,
|
||||||
Interner,
|
static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
|
||||||
utils::{
|
utils::{
|
||||||
all_super_trait_refs, associated_type_by_name_including_super_traits, generics, Generics,
|
all_super_trait_refs, associated_type_by_name_including_super_traits, generics, Generics,
|
||||||
},
|
},
|
||||||
AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig,
|
AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig,
|
||||||
FnSubst, ImplTraitId, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause,
|
FnSubst, ImplTraitId, Interner, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause,
|
||||||
QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution,
|
QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution,
|
||||||
TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, TyKind, WhereClause,
|
TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, TyKind, WhereClause,
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,13 +3,29 @@
|
||||||
//! Chalk (in both directions); plus some helper functions for more specialized
|
//! Chalk (in both directions); plus some helper functions for more specialized
|
||||||
//! conversions.
|
//! conversions.
|
||||||
|
|
||||||
use chalk_ir::{DebruijnIndex, cast::Cast, fold::Shift};
|
use chalk_ir::{cast::Cast, fold::Shift, DebruijnIndex};
|
||||||
use chalk_solve::rust_ir;
|
use chalk_solve::rust_ir;
|
||||||
|
|
||||||
use base_db::salsa::InternKey;
|
use base_db::salsa::InternKey;
|
||||||
use hir_def::{GenericDefId, TypeAliasId};
|
use hir_def::{GenericDefId, TypeAliasId};
|
||||||
|
|
||||||
use crate::{AliasEq, AliasTy, CallableDefId, FnDefId, Interner, ProjectionTyExt, QuantifiedWhereClause, Substitution, Ty, WhereClause, chalk_db::{self, ToChalk}, db::HirDatabase};
|
use crate::{
|
||||||
|
chalk_db, db::HirDatabase, AliasEq, AliasTy, CallableDefId, FnDefId, Interner, ProjectionTyExt,
|
||||||
|
QuantifiedWhereClause, Substitution, Ty, WhereClause,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub(crate) trait ToChalk {
|
||||||
|
type Chalk;
|
||||||
|
fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk;
|
||||||
|
fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn from_chalk<T, ChalkT>(db: &dyn HirDatabase, chalk: ChalkT) -> T
|
||||||
|
where
|
||||||
|
T: ToChalk<Chalk = ChalkT>,
|
||||||
|
{
|
||||||
|
T::from_chalk(db, chalk)
|
||||||
|
}
|
||||||
|
|
||||||
impl ToChalk for hir_def::TraitId {
|
impl ToChalk for hir_def::TraitId {
|
||||||
type Chalk = chalk_db::TraitId;
|
type Chalk = chalk_db::TraitId;
|
||||||
|
|
|
@ -4,7 +4,9 @@ use std::fmt;
|
||||||
use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication};
|
use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplication};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use crate::{db::HirDatabase, from_assoc_type_id, CallableDefId, chalk_db::{from_chalk, self}, Interner};
|
use crate::{
|
||||||
|
chalk_db, db::HirDatabase, from_assoc_type_id, mapping::from_chalk, CallableDefId, Interner,
|
||||||
|
};
|
||||||
use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId};
|
use hir_def::{AdtId, AssocContainerId, Lookup, TypeAliasId};
|
||||||
|
|
||||||
pub(crate) use unsafe_tls::{set_current_program, with_current_program};
|
pub(crate) use unsafe_tls::{set_current_program, with_current_program};
|
||||||
|
|
|
@ -9,7 +9,7 @@ use stdx::panic_context;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase, AliasEq, AliasTy, Canonical, DomainGoal, Guidance, HirDisplay, InEnvironment,
|
db::HirDatabase, AliasEq, AliasTy, Canonical, DomainGoal, Guidance, HirDisplay, InEnvironment,
|
||||||
Solution, TraitRefExt, Ty, TyKind, WhereClause, Interner,
|
Interner, Solution, TraitRefExt, Ty, TyKind, WhereClause,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This controls how much 'time' we give the Chalk solver before giving up.
|
/// This controls how much 'time' we give the Chalk solver before giving up.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue