mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Merge #6630
6630: followup to "hir_expand: propagate expansion errors" r=jonas-schievink a=jonas-schievink https://github.com/rust-analyzer/rust-analyzer/pull/6625 bors r+ 🤖 Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
5478aaebfe
6 changed files with 19 additions and 29 deletions
|
@ -11,7 +11,7 @@ pub use hir_def::db::{
|
|||
};
|
||||
pub use hir_expand::db::{
|
||||
AstDatabase, AstDatabaseStorage, AstIdMapQuery, InternEagerExpansionQuery, InternMacroQuery,
|
||||
MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroQuery,
|
||||
MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroExpansionQuery,
|
||||
};
|
||||
pub use hir_ty::db::*;
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ pub trait AstDatabase: SourceDatabase {
|
|||
#[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(
|
||||
fn parse_macro_expansion(
|
||||
&self,
|
||||
macro_file: MacroFile,
|
||||
) -> MacroResult<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)>;
|
||||
|
@ -138,16 +138,13 @@ pub fn expand_hypothetical(
|
|||
Some((node.syntax_node(), token))
|
||||
}
|
||||
|
||||
pub(crate) fn ast_id_map(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
|
||||
fn ast_id_map(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
|
||||
let map =
|
||||
db.parse_or_expand(file_id).map_or_else(AstIdMap::default, |it| AstIdMap::from_source(&it));
|
||||
Arc::new(map)
|
||||
}
|
||||
|
||||
pub(crate) fn macro_def(
|
||||
db: &dyn AstDatabase,
|
||||
id: MacroDefId,
|
||||
) -> Option<Arc<(TokenExpander, mbe::TokenMap)>> {
|
||||
fn macro_def(db: &dyn AstDatabase, id: MacroDefId) -> Option<Arc<(TokenExpander, mbe::TokenMap)>> {
|
||||
match id.kind {
|
||||
MacroDefKind::Declarative => {
|
||||
let macro_call = id.ast_id?.to_node(db);
|
||||
|
@ -178,7 +175,7 @@ pub(crate) fn macro_def(
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> {
|
||||
fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> {
|
||||
let id = match id {
|
||||
MacroCallId::LazyMacro(id) => id,
|
||||
MacroCallId::EagerMacro(_id) => {
|
||||
|
@ -191,16 +188,13 @@ pub(crate) fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<Gr
|
|||
Some(arg.green().clone())
|
||||
}
|
||||
|
||||
pub(crate) fn macro_arg(
|
||||
db: &dyn AstDatabase,
|
||||
id: MacroCallId,
|
||||
) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
|
||||
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)))
|
||||
}
|
||||
|
||||
pub(crate) fn macro_expand(db: &dyn AstDatabase, id: MacroCallId) -> MacroResult<Arc<tt::Subtree>> {
|
||||
fn macro_expand(db: &dyn AstDatabase, id: MacroCallId) -> MacroResult<Arc<tt::Subtree>> {
|
||||
macro_expand_with_arg(db, id, None)
|
||||
}
|
||||
|
||||
|
@ -258,7 +252,7 @@ fn macro_expand_with_arg(
|
|||
MacroResult { value: Some(Arc::new(tt)), error: err.map(|e| format!("{:?}", e)) }
|
||||
}
|
||||
|
||||
pub(crate) fn expand_proc_macro(
|
||||
fn expand_proc_macro(
|
||||
db: &dyn AstDatabase,
|
||||
id: MacroCallId,
|
||||
) -> Result<tt::Subtree, mbe::ExpandError> {
|
||||
|
@ -285,23 +279,23 @@ pub(crate) fn expand_proc_macro(
|
|||
expander.expand(db, lazy_id, ¯o_arg.0)
|
||||
}
|
||||
|
||||
pub(crate) fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> {
|
||||
fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNode> {
|
||||
match file_id.0 {
|
||||
HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()),
|
||||
HirFileIdRepr::MacroFile(macro_file) => {
|
||||
db.parse_macro(macro_file).map(|(it, _)| it.syntax_node()).value
|
||||
db.parse_macro_expansion(macro_file).map(|(it, _)| it.syntax_node()).value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn parse_macro(
|
||||
fn parse_macro_expansion(
|
||||
db: &dyn AstDatabase,
|
||||
macro_file: MacroFile,
|
||||
) -> MacroResult<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)> {
|
||||
parse_macro_with_arg(db, macro_file, None)
|
||||
}
|
||||
|
||||
pub fn parse_macro_with_arg(
|
||||
fn parse_macro_with_arg(
|
||||
db: &dyn AstDatabase,
|
||||
macro_file: MacroFile,
|
||||
arg: Option<Arc<(tt::Subtree, mbe::TokenMap)>>,
|
||||
|
@ -359,11 +353,7 @@ pub fn parse_macro_with_arg(
|
|||
|
||||
match result.error {
|
||||
Some(error) => {
|
||||
// FIXME:
|
||||
// In future, we should propagate the actual error with recovery information
|
||||
// instead of ignore the error here.
|
||||
|
||||
// Safe check for recurisve identity macro
|
||||
// Safety check for recursive identity macro.
|
||||
let node = parse.syntax_node();
|
||||
let file: HirFileId = macro_file.into();
|
||||
let call_node = match file.call_node(db) {
|
||||
|
@ -374,7 +364,7 @@ pub fn parse_macro_with_arg(
|
|||
};
|
||||
|
||||
if !diff(&node, &call_node.value).is_empty() {
|
||||
MacroResult { value: Some((parse, Arc::new(rev_token_map))), error: None }
|
||||
MacroResult { value: Some((parse, Arc::new(rev_token_map))), error: Some(error) }
|
||||
} else {
|
||||
return MacroResult::error(error);
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ impl HirFileId {
|
|||
let def_tt = loc.def.ast_id?.to_node(db).token_tree()?;
|
||||
|
||||
let macro_def = db.macro_def(loc.def)?;
|
||||
let (parse, exp_map) = db.parse_macro(macro_file).value?;
|
||||
let (parse, exp_map) = db.parse_macro_expansion(macro_file).value?;
|
||||
let macro_arg = db.macro_arg(macro_file.macro_call_id)?;
|
||||
|
||||
Some(ExpansionInfo {
|
||||
|
|
|
@ -19,7 +19,7 @@ fn syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
|
|||
ide_db::base_db::ParseQuery.in_db(db).entries::<SyntaxTreeStats>()
|
||||
}
|
||||
fn macro_syntax_tree_stats(db: &RootDatabase) -> SyntaxTreeStats {
|
||||
hir::db::ParseMacroQuery.in_db(db).entries::<SyntaxTreeStats>()
|
||||
hir::db::ParseMacroExpansionQuery.in_db(db).entries::<SyntaxTreeStats>()
|
||||
}
|
||||
|
||||
// Feature: Status
|
||||
|
|
|
@ -76,7 +76,7 @@ impl RootDatabase {
|
|||
let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
|
||||
|
||||
base_db::ParseQuery.in_db(self).sweep(sweep);
|
||||
hir::db::ParseMacroQuery.in_db(self).sweep(sweep);
|
||||
hir::db::ParseMacroExpansionQuery.in_db(self).sweep(sweep);
|
||||
|
||||
// Macros do take significant space, but less then the syntax trees
|
||||
// self.query(hir::db::MacroDefQuery).sweep(sweep);
|
||||
|
@ -143,7 +143,7 @@ impl RootDatabase {
|
|||
hir::db::AstIdMapQuery
|
||||
hir::db::MacroArgTextQuery
|
||||
hir::db::MacroDefQuery
|
||||
hir::db::ParseMacroQuery
|
||||
hir::db::ParseMacroExpansionQuery
|
||||
hir::db::MacroExpandQuery
|
||||
|
||||
// DefDatabase
|
||||
|
|
|
@ -113,7 +113,7 @@ impl RootDatabase {
|
|||
pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) {
|
||||
let lru_capacity = lru_capacity.unwrap_or(base_db::DEFAULT_LRU_CAP);
|
||||
base_db::ParseQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
|
||||
hir::db::ParseMacroQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
|
||||
hir::db::ParseMacroExpansionQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
|
||||
hir::db::MacroExpandQuery.in_db_mut(self).set_lru_capacity(lru_capacity);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue