[libc-commits] [libc] [libc][regex] Make ExprPool concat and star iterative (PR #244953)
Jeff Bailey via libc-commits
libc-commits at lists.llvm.org
Mon Nov 23 09:57:16 PST 2026
================
@@ -356,81 +385,128 @@ ErrorOr<ExprId> ExprPool::make_concat(ExprId l, ExprId r) {
return (l == EMPTY_STR_ID) ? r : l;
}
// (A · B) · C = A · (B · C) (Right-associative canonical form)
- const Expr le = get(l);
- if (le.kind == ExprKind::Concat) {
- ErrorOr<ExprId> tail = make_concat(le.bin.right, r);
- if (!tail.has_value())
- return tail;
- return make_concat(le.bin.left, *tail);
+ Expr ce = get(l);
+ if (ce.kind != ExprKind::Concat)
+ return intern_concat_node(l, r);
+
+ // Flatten the right-associated left spine iteratively so long concatenations
+ // never recurse on the call stack: (A · (B · C)) · D -> [A, B], C, D.
+ ReverseExprIdStack lefts;
----------------
kaladron wrote:
No, for two reasons:
1) ExprPool is retained in RegexInternal for the entire lifetime of a compiled regex_t. The BlockStore is 88 B, which would more than double sizeof(ExprPool) (72 B today).
2) Even after make_alt is converted in the next PR, functions like make_alt, coalesce_repeat_pair, and make_concat call one another while holding live stacks, so they cannot share a single stack.
https://github.com/llvm/llvm-project/pull/244953
More information about the libc-commits
mailing list