Unnamed repository; edit this file 'description' to name the repository.
Turn macro_expand from query to normal function
Lukas Wirth 2023-11-28
parent b98597f · commit 7a8c4c0
-rw-r--r--crates/base-db/src/span.rs12
-rw-r--r--crates/hir-def/src/macro_expansion_tests/proc_macros.rs1
-rw-r--r--crates/hir-expand/src/db.rs5
-rw-r--r--crates/hir-expand/src/files.rs1
-rw-r--r--crates/hir-expand/src/fixup.rs4
-rw-r--r--crates/hir-expand/src/span.rs2
-rw-r--r--crates/hir/src/db.rs4
-rw-r--r--crates/ide-completion/src/tests/proc_macros.rs2
-rw-r--r--crates/ide-db/src/apply_change.rs2
-rw-r--r--crates/ide-db/src/lib.rs7
-rw-r--r--crates/proc-macro-api/src/msg/flat.rs8
-rw-r--r--crates/proc-macro-srv/src/lib.rs3
12 files changed, 15 insertions, 36 deletions
diff --git a/crates/base-db/src/span.rs b/crates/base-db/src/span.rs
index d2b40ecdd2..420c669641 100644
--- a/crates/base-db/src/span.rs
+++ b/crates/base-db/src/span.rs
@@ -1,4 +1,4 @@
-/// File and span related types.
+//! File and span related types.
// FIXME: This should probably be moved into its own crate.
use std::fmt;
@@ -26,19 +26,15 @@ impl fmt::Display for SyntaxContextId {
impl SyntaxContext for SyntaxContextId {
const DUMMY: Self = Self::ROOT;
- // veykril(HACK): salsa doesn't allow us fetching the id of the current input to be allocated so
- // we need a special value that behaves as the current context.
}
// inherent trait impls please tyvm
impl SyntaxContextId {
- // TODO: This is very much UB, salsa exposes no way to create an InternId in a const context
- // currently (which kind of makes sense but we need it here!)
pub const ROOT: Self = SyntaxContextId(unsafe { InternId::new_unchecked(0) });
- // TODO: This is very much UB, salsa exposes no way to create an InternId in a const context
- // currently (which kind of makes sense but we need it here!)
+ // veykril(HACK): salsa doesn't allow us fetching the id of the current input to be allocated so
+ // we need a special value that behaves as the current context.
pub const SELF_REF: Self =
SyntaxContextId(unsafe { InternId::new_unchecked(InternId::MAX - 1) });
- /// Used syntax fixups
+ // Used for syntax fixups
pub const FAKE: Self = SyntaxContextId(unsafe { InternId::new_unchecked(InternId::MAX - 2) });
pub fn is_root(self) -> bool {
diff --git a/crates/hir-def/src/macro_expansion_tests/proc_macros.rs b/crates/hir-def/src/macro_expansion_tests/proc_macros.rs
index 548f22499b..060b8aa8c1 100644
--- a/crates/hir-def/src/macro_expansion_tests/proc_macros.rs
+++ b/crates/hir-def/src/macro_expansion_tests/proc_macros.rs
@@ -74,7 +74,6 @@ fn foo() {
}
#[test]
-#[ignore] // TODO
fn attribute_macro_syntax_completion_2() {
// common case of dot completion while typing
check(
diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs
index 1d55aaf170..00a7b0cb3f 100644
--- a/crates/hir-expand/src/db.rs
+++ b/crates/hir-expand/src/db.rs
@@ -146,9 +146,6 @@ pub trait ExpandDatabase: SourceDatabase {
id: AstId<ast::Macro>,
) -> Arc<DeclarativeMacroExpander>;
- /// Expand macro call to a token tree.
- // This query is LRU cached
- fn macro_expand(&self, macro_call: MacroCallId) -> ExpandResult<Arc<tt::Subtree>>;
#[salsa::invoke(crate::builtin_fn_macro::include_arg_to_tt)]
fn include_expand(
&self,
@@ -315,7 +312,7 @@ fn parse_macro_expansion(
macro_file: MacroFileId,
) -> ExpandResult<(Parse<SyntaxNode>, Arc<ExpansionSpanMap>)> {
let _p = profile::span("parse_macro_expansion");
- let mbe::ValueResult { value: tt, err } = db.macro_expand(macro_file.macro_call_id);
+ let mbe::ValueResult { value: tt, err } = macro_expand(db, macro_file.macro_call_id);
let expand_to = macro_expand_to(db, macro_file.macro_call_id);
diff --git a/crates/hir-expand/src/files.rs b/crates/hir-expand/src/files.rs
index 57a7fa5ec3..36eb2dbb27 100644
--- a/crates/hir-expand/src/files.rs
+++ b/crates/hir-expand/src/files.rs
@@ -1,3 +1,4 @@
+//! Things to wrap other things in file ids.
use std::iter;
use base_db::{
diff --git a/crates/hir-expand/src/fixup.rs b/crates/hir-expand/src/fixup.rs
index 326ff1dec4..8fa7d57629 100644
--- a/crates/hir-expand/src/fixup.rs
+++ b/crates/hir-expand/src/fixup.rs
@@ -52,7 +52,7 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
while let Some(event) = preorder.next() {
let syntax::WalkEvent::Enter(node) = event else { continue };
- /* TODO
+ /*
if can_handle_error(&node) && has_error_to_handle(&node) {
// the node contains an error node, we have to completely replace it by something valid
let (original_tree, new_tmap, new_next_id) =
@@ -295,7 +295,7 @@ pub(crate) fn reverse_fixups(tt: &mut Subtree, undo_info: &SyntaxFixupUndoInfo)
tt::TokenTree::Leaf(leaf) => leaf.span().ctx != SyntaxContextId::FAKE,
tt::TokenTree::Subtree(st) => st.delimiter.open.ctx != SyntaxContextId::FAKE,
})
- // .flat_map(|tt| match tt { TODO
+ // .flat_map(|tt| match tt {
// tt::TokenTree::Subtree(mut tt) => {
// reverse_fixups(&mut tt, undo_info);
// SmallVec::from_const([tt.into()])
diff --git a/crates/hir-expand/src/span.rs b/crates/hir-expand/src/span.rs
index c2399259fa..1703923d11 100644
--- a/crates/hir-expand/src/span.rs
+++ b/crates/hir-expand/src/span.rs
@@ -1,3 +1,5 @@
+//! Spanmaps allow turning absolute ranges into relative ranges for incrementality purposes as well
+//! as associating spans with text ranges in a particular file.
use base_db::{
span::{ErasedFileAstId, SpanAnchor, SpanData, SyntaxContextId, ROOT_ERASED_FILE_AST_ID},
FileId,
diff --git a/crates/hir/src/db.rs b/crates/hir/src/db.rs
index b9112dee31..ff6f987aa1 100644
--- a/crates/hir/src/db.rs
+++ b/crates/hir/src/db.rs
@@ -23,7 +23,7 @@ pub use hir_def::db::{
};
pub use hir_expand::db::{
AstIdMapQuery, DeclMacroExpanderQuery, ExpandDatabase, ExpandDatabaseStorage,
- ExpandProcMacroQuery, IncludeExpandQuery, InternMacroCallQuery, MacroArgQuery,
- MacroExpandQuery, ParseMacroExpansionErrorQuery, ParseMacroExpansionQuery, RealSpanMapQuery,
+ ExpandProcMacroQuery, IncludeExpandQuery, InternMacroCallQuery, InternSyntaxContextQuery,
+ MacroArgQuery, ParseMacroExpansionErrorQuery, ParseMacroExpansionQuery, RealSpanMapQuery,
};
pub use hir_ty::db::*;
diff --git a/crates/ide-completion/src/tests/proc_macros.rs b/crates/ide-completion/src/tests/proc_macros.rs
index e55d1f315f..2d6234e310 100644
--- a/crates/ide-completion/src/tests/proc_macros.rs
+++ b/crates/ide-completion/src/tests/proc_macros.rs
@@ -9,7 +9,6 @@ fn check(ra_fixture: &str, expect: Expect) {
}
#[test]
-#[ignore] // todo
fn complete_dot_in_attr() {
check(
r#"
@@ -41,7 +40,6 @@ fn main() {
}
#[test]
-#[ignore] // TODO
fn complete_dot_in_attr2() {
check(
r#"
diff --git a/crates/ide-db/src/apply_change.rs b/crates/ide-db/src/apply_change.rs
index 2efe3ee1ed..67e686dad1 100644
--- a/crates/ide-db/src/apply_change.rs
+++ b/crates/ide-db/src/apply_change.rs
@@ -101,8 +101,8 @@ impl RootDatabase {
hir::db::ExpandProcMacroQuery
hir::db::IncludeExpandQuery
hir::db::InternMacroCallQuery
+ hir::db::InternSyntaxContextQuery
hir::db::MacroArgQuery
- hir::db::MacroExpandQuery
hir::db::ParseMacroExpansionQuery
hir::db::RealSpanMapQuery
diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs
index 38c9a3538f..cbd51e6781 100644
--- a/crates/ide-db/src/lib.rs
+++ b/crates/ide-db/src/lib.rs
@@ -157,7 +157,6 @@ impl RootDatabase {
base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
// macro expansions are usually rather small, so we can afford to keep more of them alive
hir::db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(4 * lru_capacity);
- hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(4 * lru_capacity);
}
pub fn update_lru_capacities(&mut self, lru_capacities: &FxHashMap<Box<str>, usize>) {
@@ -175,12 +174,6 @@ impl RootDatabase {
.copied()
.unwrap_or(4 * base_db::DEFAULT_PARSE_LRU_CAP),
);
- hir_db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(
- lru_capacities
- .get(stringify!(MacroExpandQuery))
- .copied()
- .unwrap_or(4 * base_db::DEFAULT_PARSE_LRU_CAP),
- );
macro_rules! update_lru_capacity_per_query {
($( $module:ident :: $query:ident )*) => {$(
diff --git a/crates/proc-macro-api/src/msg/flat.rs b/crates/proc-macro-api/src/msg/flat.rs
index baf8bbad4b..43840fa333 100644
--- a/crates/proc-macro-api/src/msg/flat.rs
+++ b/crates/proc-macro-api/src/msg/flat.rs
@@ -43,7 +43,7 @@ use serde::{Deserialize, Serialize};
use crate::msg::ENCODE_CLOSE_SPAN_VERSION;
-pub type SpanDataIndexMap = IndexSet<SpanData>;
+type SpanDataIndexMap = IndexSet<SpanData>;
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct TokenId(pub u32);
@@ -54,12 +54,6 @@ impl std::fmt::Debug for TokenId {
}
}
-impl TokenId {
- pub const DEF_SITE: Self = TokenId(0);
- pub const CALL_SITE: Self = TokenId(0);
- pub const MIXED_SITE: Self = TokenId(0);
-}
-
impl tt::Span for TokenId {
const DUMMY: Self = TokenId(!0);
diff --git a/crates/proc-macro-srv/src/lib.rs b/crates/proc-macro-srv/src/lib.rs
index 32a07a8477..dd327681c4 100644
--- a/crates/proc-macro-srv/src/lib.rs
+++ b/crates/proc-macro-srv/src/lib.rs
@@ -31,9 +31,8 @@ use std::{
time::SystemTime,
};
-use ::tt::Span;
use proc_macro_api::{
- msg::{self, ExpnGlobals, TokenId, CURRENT_API_VERSION, HAS_GLOBAL_SPANS},
+ msg::{self, ExpnGlobals, TokenId, CURRENT_API_VERSION},
ProcMacroKind,
};