From b9c0c2abb79769852119dc9a595e63ee74eeba03 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 20 Apr 2019 12:34:36 +0200 Subject: Chalk integration - add proper canonicalization logic - add conversions from/to Chalk IR --- crates/ra_hir/src/db.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir/src/db.rs') diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 398e00c42..b2c4fccf2 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use ra_syntax::{SyntaxNode, TreeArc, SourceFile, SmolStr, ast}; use ra_db::{SourceDatabase, salsa}; @@ -8,16 +8,16 @@ use crate::{ Function, FnSignature, ExprScopes, TypeAlias, Struct, Enum, StructField, Const, ConstSignature, Static, - DefWithBody, + DefWithBody, Trait, + ids, nameres::{Namespace, ImportSourceMap, RawItems, CrateDefMap}, - ty::{InferenceResult, Ty, method_resolution::CrateImplBlocks, TypableDef, CallableDef, FnSig}, + ty::{InferenceResult, Ty, method_resolution::CrateImplBlocks, TypableDef, CallableDef, FnSig, TypeCtor}, adt::{StructData, EnumData}, - impl_block::{ModuleImplBlocks, ImplSourceMap}, + impl_block::{ModuleImplBlocks, ImplSourceMap, ImplBlock}, generics::{GenericParams, GenericDef}, type_ref::TypeRef, - traits::TraitData, Trait, ty::TraitRef, + traits::TraitData, lang_item::{LangItems, LangItemTarget}, - ids }; #[salsa::query_group(DefDatabaseStorage)] @@ -39,6 +39,12 @@ pub trait DefDatabase: SourceDatabase { #[salsa::interned] fn intern_type_alias(&self, loc: ids::ItemLoc) -> ids::TypeAliasId; + // Interned IDs for Chalk integration + #[salsa::interned] + fn intern_type_ctor(&self, type_ctor: TypeCtor) -> ids::TypeCtorId; + #[salsa::interned] + fn intern_impl_block(&self, impl_block: ImplBlock) -> ids::GlobalImplId; + #[salsa::invoke(crate::ids::macro_def_query)] fn macro_def(&self, macro_id: MacroDefId) -> Option>; @@ -144,8 +150,12 @@ pub trait HirDatabase: DefDatabase { #[salsa::invoke(crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query)] fn impls_in_crate(&self, krate: Crate) -> Arc; - #[salsa::invoke(crate::ty::traits::implements)] - fn implements(&self, trait_ref: TraitRef) -> Option; + #[salsa::invoke(crate::ty::traits::impls_for_trait)] + fn impls_for_trait(&self, krate: Crate, trait_: Trait) -> Arc<[ImplBlock]>; + + #[salsa::invoke(crate::ty::traits::solver)] + #[salsa::volatile] + fn chalk_solver(&self, krate: Crate) -> Arc>; } #[test] -- cgit v1.2.3 From ef77d8375130d12678d4b2316cc1708c90349dad Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 1 May 2019 17:13:33 +0200 Subject: Document the peculiarity of the solver query a bit Also remove the only remaining mention of chalk outside of the ty::traits module. --- crates/ra_hir/src/db.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src/db.rs') diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index b2c4fccf2..8aaf0375a 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -153,9 +153,14 @@ pub trait HirDatabase: DefDatabase { #[salsa::invoke(crate::ty::traits::impls_for_trait)] fn impls_for_trait(&self, krate: Crate, trait_: Trait) -> Arc<[ImplBlock]>; + /// This provides the Chalk trait solver instance. Because Chalk always + /// works from a specific crate, this query is keyed on the crate; and + /// because Chalk does its own internal caching, the solver is wrapped in a + /// Mutex and the query is marked volatile, to make sure the cached state is + /// thrown away when input facts change. #[salsa::invoke(crate::ty::traits::solver)] #[salsa::volatile] - fn chalk_solver(&self, krate: Crate) -> Arc>; + fn solver(&self, krate: Crate) -> Arc>; } #[test] -- cgit v1.2.3