Merge #5497
5497: Store macro invocation parameters as text instead of tt r=jonas-schievink a=lnicola We don't want to expand macros on every source change because it can be arbitrarily slow, but the token trees can be rather large. So instead we can cache the invocation parameters (as text). Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
8a49f93793
@ -11,7 +11,7 @@
|
||||
};
|
||||
pub use hir_expand::db::{
|
||||
AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery,
|
||||
MacroArgQuery, MacroDefQuery, MacroExpandQuery, ParseMacroQuery,
|
||||
MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroQuery,
|
||||
};
|
||||
pub use hir_ty::db::{
|
||||
AssociatedTyDataQuery, AssociatedTyValueQuery, CallableItemSignatureQuery, FieldTypesQuery,
|
||||
|
@ -6,7 +6,7 @@
|
||||
use ra_db::{salsa, SourceDatabase};
|
||||
use ra_parser::FragmentKind;
|
||||
use ra_prof::profile;
|
||||
use ra_syntax::{algo::diff, AstNode, Parse, SyntaxKind::*, SyntaxNode};
|
||||
use ra_syntax::{algo::diff, AstNode, GreenNode, Parse, SyntaxKind::*, SyntaxNode};
|
||||
|
||||
use crate::{
|
||||
ast_id_map::AstIdMap, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallLoc, EagerMacroId,
|
||||
@ -72,6 +72,8 @@ pub trait AstDatabase: SourceDatabase {
|
||||
|
||||
#[salsa::interned]
|
||||
fn intern_macro(&self, macro_call: MacroCallLoc) -> LazyMacroId;
|
||||
fn macro_arg_text(&self, id: MacroCallId) -> Option<GreenNode>;
|
||||
#[salsa::transparent]
|
||||
fn macro_arg(&self, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>>;
|
||||
fn macro_def(&self, id: MacroDefId) -> Option<Arc<(TokenExpander, mbe::TokenMap)>>;
|
||||
fn parse_macro(&self, macro_file: MacroFile)
|
||||
@ -148,10 +150,7 @@ pub(crate) fn macro_def(
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn macro_arg(
|
||||
db: &dyn AstDatabase,
|
||||
id: MacroCallId,
|
||||
) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
|
||||
pub(crate) fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> {
|
||||
let id = match id {
|
||||
MacroCallId::LazyMacro(id) => id,
|
||||
MacroCallId::EagerMacro(_id) => {
|
||||
@ -161,7 +160,15 @@ pub(crate) fn macro_arg(
|
||||
};
|
||||
let loc = db.lookup_intern_macro(id);
|
||||
let arg = loc.kind.arg(db)?;
|
||||
let (tt, tmap) = mbe::syntax_node_to_token_tree(&arg)?;
|
||||
Some(arg.green().clone())
|
||||
}
|
||||
|
||||
pub(crate) fn macro_arg(
|
||||
db: &dyn AstDatabase,
|
||||
id: MacroCallId,
|
||||
) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
|
||||
let arg = db.macro_arg_text(id)?;
|
||||
let (tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg))?;
|
||||
Some(Arc::new((tt, tmap)))
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ pub fn collect_garbage(&mut self) {
|
||||
|
||||
// Macros do take significant space, but less then the syntax trees
|
||||
// self.query(hir::db::MacroDefQuery).sweep(sweep);
|
||||
// self.query(hir::db::MacroArgQuery).sweep(sweep);
|
||||
// self.query(hir::db::MacroArgTextQuery).sweep(sweep);
|
||||
// self.query(hir::db::MacroExpandQuery).sweep(sweep);
|
||||
|
||||
hir::db::AstIdMapQuery.in_db(self).sweep(sweep);
|
||||
@ -199,7 +199,7 @@ macro_rules! sweep_each_query {
|
||||
|
||||
// AstDatabase
|
||||
hir::db::AstIdMapQuery
|
||||
hir::db::MacroArgQuery
|
||||
hir::db::MacroArgTextQuery
|
||||
hir::db::MacroDefQuery
|
||||
hir::db::ParseMacroQuery
|
||||
hir::db::MacroExpandQuery
|
||||
|
@ -42,8 +42,6 @@ macro_rules! eprintln {
|
||||
use ra_text_edit::Indel;
|
||||
use stdx::format_to;
|
||||
|
||||
use crate::syntax_node::GreenNode;
|
||||
|
||||
pub use crate::{
|
||||
algo::InsertPosition,
|
||||
ast::{AstNode, AstToken},
|
||||
@ -51,7 +49,7 @@ macro_rules! eprintln {
|
||||
ptr::{AstPtr, SyntaxNodePtr},
|
||||
syntax_error::SyntaxError,
|
||||
syntax_node::{
|
||||
Direction, NodeOrToken, SyntaxElement, SyntaxElementChildren, SyntaxNode,
|
||||
Direction, GreenNode, NodeOrToken, SyntaxElement, SyntaxElementChildren, SyntaxNode,
|
||||
SyntaxNodeChildren, SyntaxToken, SyntaxTreeBuilder,
|
||||
},
|
||||
};
|
||||
|
@ -10,7 +10,9 @@
|
||||
|
||||
use crate::{Parse, SmolStr, SyntaxError, SyntaxKind, TextSize};
|
||||
|
||||
pub(crate) use rowan::{GreenNode, GreenToken};
|
||||
pub use rowan::GreenNode;
|
||||
|
||||
pub(crate) use rowan::GreenToken;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum RustLanguage {}
|
||||
|
Loading…
Reference in New Issue
Block a user