aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-22 18:31:39 +0100
committerGitHub <[email protected]>2020-05-22 18:31:39 +0100
commitb38f9a5810f28563c45acb1ae8b82438649227c9 (patch)
treeea6b68dcbd47a92a5615c74723ae69dafd7d47f9 /crates/ra_hir_def/src
parentc5a22715809fa79b2c77d461c2161dbf5ebb411a (diff)
parente0f978018aad1a48390189ce54372913f324b2e3 (diff)
Merge #4570
4570: Use Chalk's built-in impls r=matklad a=flodiebold This contains two changes: - Chalk has begun adding built-in representations of primitive types; use these in our type conversion logic. There's one somewhat 'iffy' part here, namely references; we don't keep track of lifetimes, but Chalk does, so it will expect a lifetime parameter on references. If we didn't provide that, it could cause crashes in Chalk code that expects the lifetime, so I rather hackily add an (always the same) lifetime placeholder during conversion. I expect that we'll fully switch to using Chalk's types everywhere before we add lifetime support, so I think this is the best solution for now. - let Chalk know about well-known traits (from lang items), so it can apply its built-in impls. Before: ``` Total expressions: 181485 Expressions of unknown type: 2940 (1%) Expressions of partially unknown type: 2884 (1%) Type mismatches: 901 Inference: 37.821210245s, 0b allocated 0b resident Total: 53.399467609s, 0b allocated 0b resident ``` After: ``` Total expressions: 181485 Expressions of unknown type: 2923 (1%) Expressions of partially unknown type: 2879 (1%) Type mismatches: 734 Inference: 39.157752509s, 0b allocated 0b resident Total: 54.110767621s, 0b allocated 0b resident ``` (I will start splitting up `chalk.rs` in a separate PR, since it's getting pretty big...) Co-authored-by: Florian Diebold <[email protected]> Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/lang_item.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs
index d96ac8c0a..d962db3cc 100644
--- a/crates/ra_hir_def/src/lang_item.rs
+++ b/crates/ra_hir_def/src/lang_item.rs
@@ -73,8 +73,8 @@ pub struct LangItems {
73} 73}
74 74
75impl LangItems { 75impl LangItems {
76 pub fn target<'a>(&'a self, item: &str) -> Option<&'a LangItemTarget> { 76 pub fn target(&self, item: &str) -> Option<LangItemTarget> {
77 self.items.get(item) 77 self.items.get(item).copied()
78 } 78 }
79 79
80 /// Salsa query. This will look for lang items in a specific crate. 80 /// Salsa query. This will look for lang items in a specific crate.
@@ -163,9 +163,13 @@ impl LangItems {
163 ) where 163 ) where
164 T: Into<AttrDefId> + Copy, 164 T: Into<AttrDefId> + Copy,
165 { 165 {
166 let attrs = db.attrs(item.into()); 166 if let Some(lang_item_name) = lang_attr(db, item) {
167 if let Some(lang_item_name) = attrs.by_key("lang").string_value() {
168 self.items.entry(lang_item_name.clone()).or_insert_with(|| constructor(item)); 167 self.items.entry(lang_item_name.clone()).or_insert_with(|| constructor(item));
169 } 168 }
170 } 169 }
171} 170}
171
172pub fn lang_attr(db: &dyn DefDatabase, item: impl Into<AttrDefId> + Copy) -> Option<SmolStr> {
173 let attrs = db.attrs(item.into());
174 attrs.by_key("lang").string_value().cloned()
175}