Turn macro_expand from query to normal function

This commit is contained in:
Lukas Wirth 2023-11-28 16:50:05 +01:00
parent b98597f06d
commit 7a8c4c001b
12 changed files with 15 additions and 36 deletions

View File

@ -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 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
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 {

View File

@ -74,7 +74,6 @@ fn foo() {
}
#[test]
#[ignore] // TODO
fn attribute_macro_syntax_completion_2() {
// common case of dot completion while typing
check(

View File

@ -146,9 +146,6 @@ fn decl_macro_expander(
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);

View File

@ -1,3 +1,4 @@
//! Things to wrap other things in file ids.
use std::iter;
use base_db::{

View File

@ -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()])

View File

@ -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,

View File

@ -23,7 +23,7 @@
};
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::*;

View File

@ -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#"

View File

@ -101,8 +101,8 @@ macro_rules! purge_each_query {
hir::db::ExpandProcMacroQuery
hir::db::IncludeExpandQuery
hir::db::InternMacroCallQuery
hir::db::InternSyntaxContextQuery
hir::db::MacroArgQuery
hir::db::MacroExpandQuery
hir::db::ParseMacroExpansionQuery
hir::db::RealSpanMapQuery

View File

@ -157,7 +157,6 @@ pub fn update_parse_query_lru_capacity(&mut self, lru_capacity: Option<usize>) {
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 @@ pub fn update_lru_capacities(&mut self, lru_capacities: &FxHashMap<Box<str>, usi
.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 )*) => {$(

View File

@ -43,7 +43,7 @@
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 @@ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
}
}
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);

View File

@ -31,9 +31,8 @@
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,
};