aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-10-30 10:10:38 +0000
committerAleksey Kladov <[email protected]>2019-10-30 10:11:38 +0000
commitc9cd6aa370667783292de3bc580e0503a409e453 (patch)
tree4662b1c76bed5e830c1dae9ee5dbf47520f41e1e /crates/ra_hir
parenta136cc0653d2b4133fb6387009cfdbaf3e2cf275 (diff)
Move ids to hir_def crate
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model.rs16
-rw-r--r--crates/ra_hir/src/code_model/src.rs20
-rw-r--r--crates/ra_hir/src/db.rs28
-rw-r--r--crates/ra_hir/src/from_source.rs2
-rw-r--r--crates/ra_hir/src/ids.rs167
-rw-r--r--crates/ra_hir/src/impl_block.rs2
-rw-r--r--crates/ra_hir/src/nameres/collector.rs2
-rw-r--r--crates/ra_hir/src/source_binder.rs2
-rw-r--r--crates/ra_hir/src/traits.rs2
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs34
10 files changed, 26 insertions, 249 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 3f1c36941..1a790b2f3 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -343,7 +343,7 @@ pub struct Struct {
343 343
344impl Struct { 344impl Struct {
345 pub fn module(self, db: &impl DefDatabase) -> Module { 345 pub fn module(self, db: &impl DefDatabase) -> Module {
346 self.id.module(db) 346 Module { id: self.id.module(db) }
347 } 347 }
348 348
349 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 349 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
@@ -405,7 +405,7 @@ impl Union {
405 } 405 }
406 406
407 pub fn module(self, db: &impl HirDatabase) -> Module { 407 pub fn module(self, db: &impl HirDatabase) -> Module {
408 self.id.module(db) 408 Module { id: self.id.module(db) }
409 } 409 }
410 410
411 pub fn ty(self, db: &impl HirDatabase) -> Ty { 411 pub fn ty(self, db: &impl HirDatabase) -> Ty {
@@ -431,7 +431,7 @@ pub struct Enum {
431 431
432impl Enum { 432impl Enum {
433 pub fn module(self, db: &impl DefDatabase) -> Module { 433 pub fn module(self, db: &impl DefDatabase) -> Module {
434 self.id.module(db) 434 Module { id: self.id.module(db) }
435 } 435 }
436 436
437 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 437 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
@@ -697,7 +697,7 @@ impl FnData {
697 697
698impl Function { 698impl Function {
699 pub fn module(self, db: &impl DefDatabase) -> Module { 699 pub fn module(self, db: &impl DefDatabase) -> Module {
700 self.id.module(db) 700 Module { id: self.id.module(db) }
701 } 701 }
702 702
703 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 703 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
@@ -775,7 +775,7 @@ pub struct Const {
775 775
776impl Const { 776impl Const {
777 pub fn module(self, db: &impl DefDatabase) -> Module { 777 pub fn module(self, db: &impl DefDatabase) -> Module {
778 self.id.module(db) 778 Module { id: self.id.module(db) }
779 } 779 }
780 780
781 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 781 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
@@ -872,7 +872,7 @@ pub struct Static {
872 872
873impl Static { 873impl Static {
874 pub fn module(self, db: &impl DefDatabase) -> Module { 874 pub fn module(self, db: &impl DefDatabase) -> Module {
875 self.id.module(db) 875 Module { id: self.id.module(db) }
876 } 876 }
877 877
878 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 878 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
@@ -901,7 +901,7 @@ pub struct Trait {
901 901
902impl Trait { 902impl Trait {
903 pub fn module(self, db: &impl DefDatabase) -> Module { 903 pub fn module(self, db: &impl DefDatabase) -> Module {
904 self.id.module(db) 904 Module { id: self.id.module(db) }
905 } 905 }
906 906
907 pub fn name(self, db: &impl DefDatabase) -> Option<Name> { 907 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
@@ -1003,7 +1003,7 @@ pub struct TypeAlias {
1003 1003
1004impl TypeAlias { 1004impl TypeAlias {
1005 pub fn module(self, db: &impl DefDatabase) -> Module { 1005 pub fn module(self, db: &impl DefDatabase) -> Module {
1006 self.id.module(db) 1006 Module { id: self.id.module(db) }
1007 } 1007 }
1008 1008
1009 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 1009 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index 8b33f25f7..5c7f61eef 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -1,9 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use ra_syntax::{ 3use ra_syntax::ast::{self, AstNode};
4 ast::{self, AstNode},
5 SyntaxNode,
6};
7 4
8use crate::{ 5use crate::{
9 db::{AstDatabase, DefDatabase, HirDatabase}, 6 db::{AstDatabase, DefDatabase, HirDatabase},
@@ -12,26 +9,13 @@ use crate::{
12 ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, 9 ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
13}; 10};
14 11
15#[derive(Debug, PartialEq, Eq, Clone, Copy)] 12pub use hir_def::Source;
16pub struct Source<T> {
17 pub file_id: HirFileId,
18 pub ast: T,
19}
20 13
21pub trait HasSource { 14pub trait HasSource {
22 type Ast; 15 type Ast;
23 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<Self::Ast>; 16 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<Self::Ast>;
24} 17}
25 18
26impl<T> Source<T> {
27 pub(crate) fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> {
28 Source { file_id: self.file_id, ast: f(self.ast) }
29 }
30 pub(crate) fn file_syntax(&self, db: &impl AstDatabase) -> SyntaxNode {
31 db.parse_or_expand(self.file_id).expect("source created from invalid file")
32 }
33}
34
35/// NB: Module is !HasSource, because it has two source nodes at the same time: 19/// NB: Module is !HasSource, because it has two source nodes at the same time:
36/// definition and declaration. 20/// definition and declaration.
37impl Module { 21impl Module {
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index da8ae6ef4..8f6cb2da7 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -2,8 +2,8 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use ra_db::{salsa, SourceDatabase}; 5use ra_db::salsa;
6use ra_syntax::{ast, SmolStr}; 6use ra_syntax::SmolStr;
7 7
8use crate::{ 8use crate::{
9 adt::{EnumData, StructData}, 9 adt::{EnumData, StructData},
@@ -23,34 +23,12 @@ use crate::{
23 Static, Struct, StructField, Trait, TypeAlias, 23 Static, Struct, StructField, Trait, TypeAlias,
24}; 24};
25 25
26pub use hir_def::db::{InternDatabase, InternDatabaseStorage};
26pub use hir_expand::db::{ 27pub use hir_expand::db::{
27 AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, 28 AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
28 ParseMacroQuery, 29 ParseMacroQuery,
29}; 30};
30 31
31/// We store all interned things in the single QueryGroup.
32///
33/// This is done mainly to allow both "volatile" `AstDatabase` and "stable"
34/// `DefDatabase` to access macros, without adding hard dependencies between the
35/// two.
36#[salsa::query_group(InternDatabaseStorage)]
37pub trait InternDatabase: SourceDatabase {
38 #[salsa::interned]
39 fn intern_function(&self, loc: ids::ItemLoc<ast::FnDef>) -> ids::FunctionId;
40 #[salsa::interned]
41 fn intern_struct(&self, loc: ids::ItemLoc<ast::StructDef>) -> ids::StructId;
42 #[salsa::interned]
43 fn intern_enum(&self, loc: ids::ItemLoc<ast::EnumDef>) -> ids::EnumId;
44 #[salsa::interned]
45 fn intern_const(&self, loc: ids::ItemLoc<ast::ConstDef>) -> ids::ConstId;
46 #[salsa::interned]
47 fn intern_static(&self, loc: ids::ItemLoc<ast::StaticDef>) -> ids::StaticId;
48 #[salsa::interned]
49 fn intern_trait(&self, loc: ids::ItemLoc<ast::TraitDef>) -> ids::TraitId;
50 #[salsa::interned]
51 fn intern_type_alias(&self, loc: ids::ItemLoc<ast::TypeAliasDef>) -> ids::TypeAliasId;
52}
53
54// This database uses `AstDatabase` internally, 32// This database uses `AstDatabase` internally,
55#[salsa::query_group(DefDatabaseStorage)] 33#[salsa::query_group(DefDatabaseStorage)]
56#[salsa::requires(AstDatabase)] 34#[salsa::requires(AstDatabase)]
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index 291f2a14a..93713bb14 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -208,6 +208,6 @@ where
208 let module_src = 208 let module_src =
209 crate::ModuleSource::from_child_node(db, src.file_id.original_file(db), &src.ast.syntax()); 209 crate::ModuleSource::from_child_node(db, src.file_id.original_file(db), &src.ast.syntax());
210 let module = Module::from_definition(db, Source { file_id: src.file_id, ast: module_src })?; 210 let module = Module::from_definition(db, Source { file_id: src.file_id, ast: module_src })?;
211 let ctx = LocationCtx::new(db, module, src.file_id); 211 let ctx = LocationCtx::new(db, module.id, src.file_id);
212 Some(DEF::from_ast(ctx, &src.ast)) 212 Some(DEF::from_ast(ctx, &src.ast))
213} 213}
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index dea288eb7..fe083c0c6 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -5,16 +5,12 @@
5//! This module defines a bunch of ids we are using. The most important ones are 5//! This module defines a bunch of ids we are using. The most important ones are
6//! probably `HirFileId` and `DefId`. 6//! probably `HirFileId` and `DefId`.
7 7
8use std::hash::{Hash, Hasher};
9
10use ra_db::salsa; 8use ra_db::salsa;
11use ra_syntax::{ast, AstNode};
12 9
13use crate::{ 10pub use hir_def::{
14 db::{AstDatabase, InternDatabase}, 11 AstItemDef, ConstId, EnumId, FunctionId, ItemLoc, LocationCtx, StaticId, StructId, TraitId,
15 AstId, FileAstId, Module, Source, 12 TypeAliasId,
16}; 13};
17
18pub use hir_expand::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, MacroFileKind}; 14pub use hir_expand::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, MacroFileKind};
19 15
20macro_rules! impl_intern_key { 16macro_rules! impl_intern_key {
@@ -30,163 +26,6 @@ macro_rules! impl_intern_key {
30 }; 26 };
31} 27}
32 28
33#[derive(Debug)]
34pub struct ItemLoc<N: AstNode> {
35 pub(crate) module: Module,
36 ast_id: AstId<N>,
37}
38
39impl<N: AstNode> PartialEq for ItemLoc<N> {
40 fn eq(&self, other: &Self) -> bool {
41 self.module == other.module && self.ast_id == other.ast_id
42 }
43}
44impl<N: AstNode> Eq for ItemLoc<N> {}
45impl<N: AstNode> Hash for ItemLoc<N> {
46 fn hash<H: Hasher>(&self, hasher: &mut H) {
47 self.module.hash(hasher);
48 self.ast_id.hash(hasher);
49 }
50}
51
52impl<N: AstNode> Clone for ItemLoc<N> {
53 fn clone(&self) -> ItemLoc<N> {
54 ItemLoc { module: self.module, ast_id: self.ast_id }
55 }
56}
57
58#[derive(Clone, Copy)]
59pub(crate) struct LocationCtx<DB> {
60 db: DB,
61 module: Module,
62 file_id: HirFileId,
63}
64
65impl<'a, DB> LocationCtx<&'a DB> {
66 pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> {
67 LocationCtx { db, module, file_id }
68 }
69}
70
71impl<'a, DB: AstDatabase + InternDatabase> LocationCtx<&'a DB> {
72 pub(crate) fn to_def<N, DEF>(self, ast: &N) -> DEF
73 where
74 N: AstNode,
75 DEF: AstItemDef<N>,
76 {
77 DEF::from_ast(self, ast)
78 }
79}
80
81pub(crate) trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
82 fn intern(db: &impl InternDatabase, loc: ItemLoc<N>) -> Self;
83 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<N>;
84
85 fn from_ast(ctx: LocationCtx<&(impl AstDatabase + InternDatabase)>, ast: &N) -> Self {
86 let items = ctx.db.ast_id_map(ctx.file_id);
87 let item_id = items.ast_id(ast);
88 Self::from_ast_id(ctx, item_id)
89 }
90 fn from_ast_id(ctx: LocationCtx<&impl InternDatabase>, ast_id: FileAstId<N>) -> Self {
91 let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) };
92 Self::intern(ctx.db, loc)
93 }
94 fn source(self, db: &(impl AstDatabase + InternDatabase)) -> Source<N> {
95 let loc = self.lookup_intern(db);
96 let ast = loc.ast_id.to_node(db);
97 Source { file_id: loc.ast_id.file_id(), ast }
98 }
99 fn module(self, db: &impl InternDatabase) -> Module {
100 let loc = self.lookup_intern(db);
101 loc.module
102 }
103}
104
105#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
106pub struct FunctionId(salsa::InternId);
107impl_intern_key!(FunctionId);
108
109impl AstItemDef<ast::FnDef> for FunctionId {
110 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::FnDef>) -> Self {
111 db.intern_function(loc)
112 }
113 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::FnDef> {
114 db.lookup_intern_function(self)
115 }
116}
117
118#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
119pub struct StructId(salsa::InternId);
120impl_intern_key!(StructId);
121impl AstItemDef<ast::StructDef> for StructId {
122 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StructDef>) -> Self {
123 db.intern_struct(loc)
124 }
125 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StructDef> {
126 db.lookup_intern_struct(self)
127 }
128}
129
130#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
131pub struct EnumId(salsa::InternId);
132impl_intern_key!(EnumId);
133impl AstItemDef<ast::EnumDef> for EnumId {
134 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::EnumDef>) -> Self {
135 db.intern_enum(loc)
136 }
137 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::EnumDef> {
138 db.lookup_intern_enum(self)
139 }
140}
141
142#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
143pub struct ConstId(salsa::InternId);
144impl_intern_key!(ConstId);
145impl AstItemDef<ast::ConstDef> for ConstId {
146 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::ConstDef>) -> Self {
147 db.intern_const(loc)
148 }
149 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::ConstDef> {
150 db.lookup_intern_const(self)
151 }
152}
153
154#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
155pub struct StaticId(salsa::InternId);
156impl_intern_key!(StaticId);
157impl AstItemDef<ast::StaticDef> for StaticId {
158 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StaticDef>) -> Self {
159 db.intern_static(loc)
160 }
161 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StaticDef> {
162 db.lookup_intern_static(self)
163 }
164}
165
166#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
167pub struct TraitId(salsa::InternId);
168impl_intern_key!(TraitId);
169impl AstItemDef<ast::TraitDef> for TraitId {
170 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::TraitDef>) -> Self {
171 db.intern_trait(loc)
172 }
173 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::TraitDef> {
174 db.lookup_intern_trait(self)
175 }
176}
177
178#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
179pub struct TypeAliasId(salsa::InternId);
180impl_intern_key!(TypeAliasId);
181impl AstItemDef<ast::TypeAliasDef> for TypeAliasId {
182 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::TypeAliasDef>) -> Self {
183 db.intern_type_alias(loc)
184 }
185 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::TypeAliasDef> {
186 db.lookup_intern_type_alias(self)
187 }
188}
189
190/// This exists just for Chalk, because Chalk just has a single `StructId` where 29/// This exists just for Chalk, because Chalk just has a single `StructId` where
191/// we have different kinds of ADTs, primitive types and special type 30/// we have different kinds of ADTs, primitive types and special type
192/// constructors like tuples and function pointers. 31/// constructors like tuples and function pointers.
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index fde47c264..06f21fc33 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -129,7 +129,7 @@ impl ImplData {
129 ) -> Self { 129 ) -> Self {
130 let target_trait = node.target_trait().map(TypeRef::from_ast); 130 let target_trait = node.target_trait().map(TypeRef::from_ast);
131 let target_type = TypeRef::from_ast_opt(node.target_type()); 131 let target_type = TypeRef::from_ast_opt(node.target_type());
132 let ctx = LocationCtx::new(db, module, file_id); 132 let ctx = LocationCtx::new(db, module.id, file_id);
133 let negative = node.is_negative(); 133 let negative = node.is_negative();
134 let items = if let Some(item_list) = node.item_list() { 134 let items = if let Some(item_list) = node.item_list() {
135 item_list 135 item_list
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index dd5f9d4ba..a94a0554c 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -641,7 +641,7 @@ where
641 641
642 fn define_def(&mut self, def: &raw::DefData) { 642 fn define_def(&mut self, def: &raw::DefData) {
643 let module = Module::new(self.def_collector.def_map.krate, self.module_id); 643 let module = Module::new(self.def_collector.def_map.krate, self.module_id);
644 let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); 644 let ctx = LocationCtx::new(self.def_collector.db, module.id, self.file_id);
645 645
646 macro_rules! def { 646 macro_rules! def {
647 ($kind:ident, $ast_id:ident) => { 647 ($kind:ident, $ast_id:ident) => {
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index a907d6a9f..730c33226 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -64,7 +64,7 @@ fn def_with_body_from_child_node(
64) -> Option<DefWithBody> { 64) -> Option<DefWithBody> {
65 let src = crate::ModuleSource::from_child_node(db, file_id, node); 65 let src = crate::ModuleSource::from_child_node(db, file_id, node);
66 let module = Module::from_definition(db, crate::Source { file_id: file_id.into(), ast: src })?; 66 let module = Module::from_definition(db, crate::Source { file_id: file_id.into(), ast: src })?;
67 let ctx = LocationCtx::new(db, module, file_id.into()); 67 let ctx = LocationCtx::new(db, module.id, file_id.into());
68 68
69 node.ancestors().find_map(|node| { 69 node.ancestors().find_map(|node| {
70 if let Some(def) = ast::FnDef::cast(node.clone()) { 70 if let Some(def) = ast::FnDef::cast(node.clone()) {
diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs
index e39511518..22f188049 100644
--- a/crates/ra_hir/src/traits.rs
+++ b/crates/ra_hir/src/traits.rs
@@ -27,7 +27,7 @@ impl TraitData {
27 let src = tr.source(db); 27 let src = tr.source(db);
28 let name = src.ast.name().map(|n| n.as_name()); 28 let name = src.ast.name().map(|n| n.as_name());
29 let module = tr.module(db); 29 let module = tr.module(db);
30 let ctx = LocationCtx::new(db, module, src.file_id); 30 let ctx = LocationCtx::new(db, module.id, src.file_id);
31 let auto = src.ast.is_auto(); 31 let auto = src.ast.is_auto();
32 let items = if let Some(item_list) = src.ast.item_list() { 32 let items = if let Some(item_list) = src.ast.item_list() {
33 item_list 33 item_list
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index aec484feb..ab66515be 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -162,11 +162,11 @@ impl ToChalk for Trait {
162 type Chalk = chalk_ir::TraitId; 162 type Chalk = chalk_ir::TraitId;
163 163
164 fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TraitId { 164 fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TraitId {
165 self.id.into() 165 chalk_ir::TraitId(id_to_chalk(self.id))
166 } 166 }
167 167
168 fn from_chalk(_db: &impl HirDatabase, trait_id: chalk_ir::TraitId) -> Trait { 168 fn from_chalk(_db: &impl HirDatabase, trait_id: chalk_ir::TraitId) -> Trait {
169 Trait { id: trait_id.into() } 169 Trait { id: id_from_chalk(trait_id.0) }
170 } 170 }
171} 171}
172 172
@@ -198,11 +198,11 @@ impl ToChalk for TypeAlias {
198 type Chalk = chalk_ir::TypeId; 198 type Chalk = chalk_ir::TypeId;
199 199
200 fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TypeId { 200 fn to_chalk(self, _db: &impl HirDatabase) -> chalk_ir::TypeId {
201 self.id.into() 201 chalk_ir::TypeId(id_to_chalk(self.id))
202 } 202 }
203 203
204 fn from_chalk(_db: &impl HirDatabase, impl_id: chalk_ir::TypeId) -> TypeAlias { 204 fn from_chalk(_db: &impl HirDatabase, type_alias_id: chalk_ir::TypeId) -> TypeAlias {
205 TypeAlias { id: impl_id.into() } 205 TypeAlias { id: id_from_chalk(type_alias_id.0) }
206 } 206 }
207} 207}
208 208
@@ -775,30 +775,6 @@ fn id_to_chalk<T: InternKey>(salsa_id: T) -> chalk_ir::RawId {
775 chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() } 775 chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() }
776} 776}
777 777
778impl From<chalk_ir::TraitId> for crate::ids::TraitId {
779 fn from(trait_id: chalk_ir::TraitId) -> Self {
780 id_from_chalk(trait_id.0)
781 }
782}
783
784impl From<crate::ids::TraitId> for chalk_ir::TraitId {
785 fn from(trait_id: crate::ids::TraitId) -> Self {
786 chalk_ir::TraitId(id_to_chalk(trait_id))
787 }
788}
789
790impl From<chalk_ir::TypeId> for crate::ids::TypeAliasId {
791 fn from(type_id: chalk_ir::TypeId) -> Self {
792 id_from_chalk(type_id.0)
793 }
794}
795
796impl From<crate::ids::TypeAliasId> for chalk_ir::TypeId {
797 fn from(type_id: crate::ids::TypeAliasId) -> Self {
798 chalk_ir::TypeId(id_to_chalk(type_id))
799 }
800}
801
802impl From<chalk_ir::StructId> for crate::ids::TypeCtorId { 778impl From<chalk_ir::StructId> for crate::ids::TypeCtorId {
803 fn from(struct_id: chalk_ir::StructId) -> Self { 779 fn from(struct_id: chalk_ir::StructId) -> Self {
804 id_from_chalk(struct_id.0) 780 id_from_chalk(struct_id.0)