Skip to content

Commit e4f26d6

Browse files
committed
Turn macro_expand from query to normal function
1 parent b98597f commit e4f26d6

File tree

10 files changed

+13
-27
lines changed

10 files changed

+13
-27
lines changed

crates/base-db/src/span.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// File and span related types.
1+
//! File and span related types.
22
// FIXME: This should probably be moved into its own crate.
33
use std::fmt;
44

@@ -26,19 +26,15 @@ impl fmt::Display for SyntaxContextId {
2626

2727
impl SyntaxContext for SyntaxContextId {
2828
const DUMMY: Self = Self::ROOT;
29-
// veykril(HACK): salsa doesn't allow us fetching the id of the current input to be allocated so
30-
// we need a special value that behaves as the current context.
3129
}
3230
// inherent trait impls please tyvm
3331
impl SyntaxContextId {
34-
// TODO: This is very much UB, salsa exposes no way to create an InternId in a const context
35-
// currently (which kind of makes sense but we need it here!)
3632
pub const ROOT: Self = SyntaxContextId(unsafe { InternId::new_unchecked(0) });
37-
// TODO: This is very much UB, salsa exposes no way to create an InternId in a const context
38-
// currently (which kind of makes sense but we need it here!)
33+
// veykril(HACK): salsa doesn't allow us fetching the id of the current input to be allocated so
34+
// we need a special value that behaves as the current context.
3935
pub const SELF_REF: Self =
4036
SyntaxContextId(unsafe { InternId::new_unchecked(InternId::MAX - 1) });
41-
/// Used syntax fixups
37+
// Used for syntax fixups
4238
pub const FAKE: Self = SyntaxContextId(unsafe { InternId::new_unchecked(InternId::MAX - 2) });
4339

4440
pub fn is_root(self) -> bool {

crates/hir-def/src/macro_expansion_tests/proc_macros.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ fn foo() {
7474
}
7575

7676
#[test]
77-
#[ignore] // TODO
7877
fn attribute_macro_syntax_completion_2() {
7978
// common case of dot completion while typing
8079
check(

crates/hir-expand/src/db.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ pub trait ExpandDatabase: SourceDatabase {
146146
id: AstId<ast::Macro>,
147147
) -> Arc<DeclarativeMacroExpander>;
148148

149-
/// Expand macro call to a token tree.
150-
// This query is LRU cached
151-
fn macro_expand(&self, macro_call: MacroCallId) -> ExpandResult<Arc<tt::Subtree>>;
152149
#[salsa::invoke(crate::builtin_fn_macro::include_arg_to_tt)]
153150
fn include_expand(
154151
&self,
@@ -315,7 +312,7 @@ fn parse_macro_expansion(
315312
macro_file: MacroFileId,
316313
) -> ExpandResult<(Parse<SyntaxNode>, Arc<ExpansionSpanMap>)> {
317314
let _p = profile::span("parse_macro_expansion");
318-
let mbe::ValueResult { value: tt, err } = db.macro_expand(macro_file.macro_call_id);
315+
let mbe::ValueResult { value: tt, err } = macro_expand(db, macro_file.macro_call_id);
319316

320317
let expand_to = macro_expand_to(db, macro_file.macro_call_id);
321318

crates/hir-expand/src/files.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Things to wrap other things in file ids.
12
use std::iter;
23

34
use base_db::{

crates/hir-expand/src/fixup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
5252
while let Some(event) = preorder.next() {
5353
let syntax::WalkEvent::Enter(node) = event else { continue };
5454

55-
/* TODO
55+
/*
5656
if can_handle_error(&node) && has_error_to_handle(&node) {
5757
// the node contains an error node, we have to completely replace it by something valid
5858
let (original_tree, new_tmap, new_next_id) =
@@ -295,7 +295,7 @@ pub(crate) fn reverse_fixups(tt: &mut Subtree, undo_info: &SyntaxFixupUndoInfo)
295295
tt::TokenTree::Leaf(leaf) => leaf.span().ctx != SyntaxContextId::FAKE,
296296
tt::TokenTree::Subtree(st) => st.delimiter.open.ctx != SyntaxContextId::FAKE,
297297
})
298-
// .flat_map(|tt| match tt { TODO
298+
// .flat_map(|tt| match tt {
299299
// tt::TokenTree::Subtree(mut tt) => {
300300
// reverse_fixups(&mut tt, undo_info);
301301
// SmallVec::from_const([tt.into()])

crates/hir-expand/src/span.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Spanmaps allow turning absolute ranges into relative ranges for incrementality purposes as well
2+
//! as associating spans with text ranges in a particular file.
13
use base_db::{
24
span::{ErasedFileAstId, SpanAnchor, SpanData, SyntaxContextId, ROOT_ERASED_FILE_AST_ID},
35
FileId,

crates/hir/src/db.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub use hir_def::db::{
2323
};
2424
pub use hir_expand::db::{
2525
AstIdMapQuery, DeclMacroExpanderQuery, ExpandDatabase, ExpandDatabaseStorage,
26-
ExpandProcMacroQuery, IncludeExpandQuery, InternMacroCallQuery, MacroArgQuery,
27-
MacroExpandQuery, ParseMacroExpansionErrorQuery, ParseMacroExpansionQuery, RealSpanMapQuery,
26+
ExpandProcMacroQuery, IncludeExpandQuery, InternMacroCallQuery, InternSyntaxContextQuery,
27+
MacroArgQuery, ParseMacroExpansionErrorQuery, ParseMacroExpansionQuery, RealSpanMapQuery,
2828
};
2929
pub use hir_ty::db::*;

crates/ide-completion/src/tests/proc_macros.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ fn check(ra_fixture: &str, expect: Expect) {
99
}
1010

1111
#[test]
12-
#[ignore] // todo
1312
fn complete_dot_in_attr() {
1413
check(
1514
r#"
@@ -41,7 +40,6 @@ fn main() {
4140
}
4241

4342
#[test]
44-
#[ignore] // TODO
4543
fn complete_dot_in_attr2() {
4644
check(
4745
r#"

crates/ide-db/src/apply_change.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ impl RootDatabase {
101101
hir::db::ExpandProcMacroQuery
102102
hir::db::IncludeExpandQuery
103103
hir::db::InternMacroCallQuery
104+
hir::db::InternSyntaxContextQuery
104105
hir::db::MacroArgQuery
105-
hir::db::MacroExpandQuery
106106
hir::db::ParseMacroExpansionQuery
107107
hir::db::RealSpanMapQuery
108108

crates/ide-db/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ impl RootDatabase {
157157
base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
158158
// macro expansions are usually rather small, so we can afford to keep more of them alive
159159
hir::db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(4 * lru_capacity);
160-
hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(4 * lru_capacity);
161160
}
162161

163162
pub fn update_lru_capacities(&mut self, lru_capacities: &FxHashMap<Box<str>, usize>) {
@@ -175,12 +174,6 @@ impl RootDatabase {
175174
.copied()
176175
.unwrap_or(4 * base_db::DEFAULT_PARSE_LRU_CAP),
177176
);
178-
hir_db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(
179-
lru_capacities
180-
.get(stringify!(MacroExpandQuery))
181-
.copied()
182-
.unwrap_or(4 * base_db::DEFAULT_PARSE_LRU_CAP),
183-
);
184177

185178
macro_rules! update_lru_capacity_per_query {
186179
($( $module:ident :: $query:ident )*) => {$(

0 commit comments

Comments
 (0)