Skip to content

Commit 814e319

Browse files
Merge #6804
6804: Bump the macro token limit r=jonas-schievink a=jonas-schievink Should fix #6504 Not entirely sure what the previous limit was based on, but it looks like it does get hit in practice. Co-authored-by: Jonas Schievink <[email protected]>
2 parents 6095deb + 829d9d3 commit 814e319

File tree

1 file changed

+9
-3
lines changed
  • crates/hir_expand/src

1 file changed

+9
-3
lines changed

crates/hir_expand/src/db.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ use crate::{
1313
MacroFile, ProcMacroExpander,
1414
};
1515

16+
/// Total limit on the number of tokens produced by any macro invocation.
17+
///
18+
/// If an invocation produces more tokens than this limit, it will not be stored in the database and
19+
/// an error will be emitted.
20+
const TOKEN_LIMIT: usize = 524288;
21+
1622
#[derive(Debug, Clone, Eq, PartialEq)]
1723
pub enum TokenExpander {
1824
MacroRules(mbe::MacroRules),
@@ -227,10 +233,10 @@ fn macro_expand_with_arg(
227233
let ExpandResult { value: tt, err } = macro_rules.0.expand(db, lazy_id, &macro_arg.0);
228234
// Set a hard limit for the expanded tt
229235
let count = tt.count();
230-
if count > 262144 {
236+
if count > TOKEN_LIMIT {
231237
return ExpandResult::str_err(format!(
232-
"Total tokens count exceed limit : count = {}",
233-
count
238+
"macro invocation exceeds token limit: produced {} tokens, limit is {}",
239+
count, TOKEN_LIMIT,
234240
));
235241
}
236242

0 commit comments

Comments
 (0)