Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-expand/src/db.rs')
-rw-r--r--crates/hir-expand/src/db.rs46
1 files changed, 20 insertions, 26 deletions
diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs
index fa400378f3..f4e80ef9e2 100644
--- a/crates/hir-expand/src/db.rs
+++ b/crates/hir-expand/src/db.rs
@@ -28,7 +28,7 @@ use crate::{
MacroDefId, MacroDefKind, MacroFileId,
};
/// This is just to ensure the types of smart_macro_arg and macro_arg are the same
-type MacroArgResult = (Arc<tt::Subtree>, SyntaxFixupUndoInfo, Span);
+type MacroArgResult = (Arc<tt::TopSubtree>, SyntaxFixupUndoInfo, Span);
/// Total limit on the number of tokens produced by any macro invocation.
///
/// If an invocation produces more tokens than this limit, it will not be stored in the database and
@@ -123,7 +123,7 @@ pub trait ExpandDatabase: SourceDatabase {
/// proc macros, since they are not deterministic in general, and
/// non-determinism breaks salsa in a very, very, very bad way.
/// @edwin0cheng heroically debugged this once! See #4315 for details
- fn expand_proc_macro(&self, call: MacroCallId) -> ExpandResult<Arc<tt::Subtree>>;
+ fn expand_proc_macro(&self, call: MacroCallId) -> ExpandResult<Arc<tt::TopSubtree>>;
/// Retrieves the span to be used for a proc-macro expansions spans.
/// This is a firewall query as it requires parsing the file, which we don't want proc-macros to
/// directly depend on as that would cause to frequent invalidations, mainly because of the
@@ -251,7 +251,7 @@ pub fn expand_speculative(
span,
DocCommentDesugarMode::ProcMacro,
);
- tree.delimiter = tt::Delimiter::invisible_spanned(span);
+ *tree.top_subtree_delimiter_mut() = tt::Delimiter::invisible_spanned(span);
Some(tree)
}
@@ -266,7 +266,7 @@ pub fn expand_speculative(
let mut speculative_expansion = match loc.def.kind {
MacroDefKind::ProcMacro(ast, expander, _) => {
let span = db.proc_macro_span(ast);
- tt.delimiter = tt::Delimiter::invisible_spanned(span);
+ *tt.top_subtree_delimiter_mut() = tt::Delimiter::invisible_spanned(span);
expander.expand(
db,
loc.def.krate,
@@ -429,10 +429,10 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
let dummy_tt = |kind| {
(
- Arc::new(tt::Subtree {
- delimiter: tt::Delimiter { open: span, close: span, kind },
- token_trees: Box::default(),
- }),
+ Arc::new(tt::TopSubtree::from_token_trees(
+ tt::Delimiter { open: span, close: span, kind },
+ tt::TokenTreesView::new(&[]),
+ )),
SyntaxFixupUndoInfo::default(),
span,
)
@@ -479,7 +479,7 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
);
if loc.def.is_proc_macro() {
// proc macros expect their inputs without parentheses, MBEs expect it with them included
- tt.delimiter.kind = tt::DelimiterKind::Invisible;
+ tt.top_subtree_delimiter_mut().kind = tt::DelimiterKind::Invisible;
}
return (Arc::new(tt), SyntaxFixupUndoInfo::NONE, span);
}
@@ -537,7 +537,7 @@ fn macro_arg(db: &dyn ExpandDatabase, id: MacroCallId) -> MacroArgResult {
if loc.def.is_proc_macro() {
// proc macros expect their inputs without parentheses, MBEs expect it with them included
- tt.delimiter.kind = tt::DelimiterKind::Invisible;
+ tt.top_subtree_delimiter_mut().kind = tt::DelimiterKind::Invisible;
}
(Arc::new(tt), undo_info, span)
@@ -592,7 +592,7 @@ fn macro_expand(
db: &dyn ExpandDatabase,
macro_call_id: MacroCallId,
loc: MacroCallLoc,
-) -> ExpandResult<(CowArc<tt::Subtree>, MatchedArmIndex)> {
+) -> ExpandResult<(CowArc<tt::TopSubtree>, MatchedArmIndex)> {
let _p = tracing::info_span!("macro_expand").entered();
let (ExpandResult { value: (tt, matched_arm), err }, span) = match loc.def.kind {
@@ -655,12 +655,7 @@ fn macro_expand(
// Set a hard limit for the expanded tt
if let Err(value) = check_tt_count(&tt) {
return value
- .map(|()| {
- CowArc::Owned(tt::Subtree {
- delimiter: tt::Delimiter::invisible_spanned(span),
- token_trees: Box::new([]),
- })
- })
+ .map(|()| CowArc::Owned(tt::TopSubtree::empty(tt::DelimSpan::from_single(span))))
.zip_val(matched_arm);
}
}
@@ -679,7 +674,10 @@ fn proc_macro_span(db: &dyn ExpandDatabase, ast: AstId<ast::Fn>) -> Span {
span_map.span_for_range(range)
}
-fn expand_proc_macro(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<Arc<tt::Subtree>> {
+fn expand_proc_macro(
+ db: &dyn ExpandDatabase,
+ id: MacroCallId,
+) -> ExpandResult<Arc<tt::TopSubtree>> {
let loc = db.lookup_intern_macro_call(id);
let (macro_arg, undo_info, span) = db.macro_arg_considering_derives(id, &loc.kind);
@@ -709,12 +707,7 @@ fn expand_proc_macro(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<A
// Set a hard limit for the expanded tt
if let Err(value) = check_tt_count(&tt) {
- return value.map(|()| {
- Arc::new(tt::Subtree {
- delimiter: tt::Delimiter::invisible_spanned(span),
- token_trees: Box::new([]),
- })
- });
+ return value.map(|()| Arc::new(tt::TopSubtree::empty(tt::DelimSpan::from_single(span))));
}
fixup::reverse_fixups(&mut tt, &undo_info);
@@ -723,7 +716,7 @@ fn expand_proc_macro(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<A
}
fn token_tree_to_syntax_node(
- tt: &tt::Subtree,
+ tt: &tt::TopSubtree,
expand_to: ExpandTo,
edition: parser::Edition,
) -> (Parse<SyntaxNode>, ExpansionSpanMap) {
@@ -737,7 +730,8 @@ fn token_tree_to_syntax_node(
syntax_bridge::token_tree_to_syntax_node(tt, entry_point, edition)
}
-fn check_tt_count(tt: &tt::Subtree) -> Result<(), ExpandResult<()>> {
+fn check_tt_count(tt: &tt::TopSubtree) -> Result<(), ExpandResult<()>> {
+ let tt = tt.top_subtree();
let count = tt.count();
if TOKEN_LIMIT.check(count).is_err() {
Err(ExpandResult {