Auto merge of #17221 - Veykril:lazier-validation, r=Veykril

internal: Lazier macro parse tree validation
This commit is contained in:
bors 2024-05-13 15:16:46 +00:00
commit b98690ba74
14 changed files with 151 additions and 140 deletions

View file

@ -132,7 +132,7 @@ pub trait ExpandDatabase: SourceDatabase {
fn parse_macro_expansion_error(
&self,
macro_call: MacroCallId,
) -> ExpandResult<Box<[SyntaxError]>>;
) -> Option<Arc<ExpandResult<Arc<[SyntaxError]>>>>;
}
/// This expands the given macro call, but with different arguments. This is
@ -357,9 +357,14 @@ fn parse_macro_expansion(
fn parse_macro_expansion_error(
db: &dyn ExpandDatabase,
macro_call_id: MacroCallId,
) -> ExpandResult<Box<[SyntaxError]>> {
db.parse_macro_expansion(MacroFileId { macro_call_id })
.map(|it| it.0.errors().into_boxed_slice())
) -> Option<Arc<ExpandResult<Arc<[SyntaxError]>>>> {
let e: ExpandResult<Arc<[SyntaxError]>> =
db.parse_macro_expansion(MacroFileId { macro_call_id }).map(|it| Arc::from(it.0.errors()));
if e.value.is_empty() && e.err.is_none() {
None
} else {
Some(Arc::new(e))
}
}
pub(crate) fn parse_with_map(

View file

@ -132,13 +132,13 @@ pub enum ExpandError {
MacroDefinition,
Mbe(mbe::ExpandError),
RecursionOverflow,
Other(Box<Box<str>>),
ProcMacroPanic(Box<Box<str>>),
Other(Arc<Box<str>>),
ProcMacroPanic(Arc<Box<str>>),
}
impl ExpandError {
pub fn other(msg: impl Into<Box<str>>) -> Self {
ExpandError::Other(Box::new(msg.into()))
ExpandError::Other(Arc::new(msg.into()))
}
}

View file

@ -8,6 +8,7 @@ use rustc_hash::FxHashMap;
use span::Span;
use stdx::never;
use syntax::SmolStr;
use triomphe::Arc;
use crate::{db::ExpandDatabase, tt, ExpandError, ExpandResult};
@ -157,7 +158,7 @@ impl CustomProcMacroExpander {
ProcMacroExpansionError::System(text)
| ProcMacroExpansionError::Panic(text) => ExpandResult::new(
tt::Subtree::empty(tt::DelimSpan { open: call_site, close: call_site }),
ExpandError::ProcMacroPanic(Box::new(text.into_boxed_str())),
ExpandError::ProcMacroPanic(Arc::new(text.into_boxed_str())),
),
},
}