[libc-commits] [libc] [libc][regex] Make ExprPool alt spines iterative (PR #245590)

Jeff Bailey via libc-commits libc-commits at lists.llvm.org
Tue Nov 24 13:46:04 PST 2026


================
@@ -371,6 +388,40 @@ ErrorOr<ExprId> ExprPool::intern_concat_node(ExprId l, ExprId r) {
       cpp::max(le.rep_expansion, re.rep_expansion)));
 }
 
+// Interns a canonical right-associated, strictly sorted Alt(l, r) node with
+// propagated nullability and repeat metadata.
+ErrorOr<ExprId> ExprPool::intern_alt_node(ExprId l, ExprId r) {
+  const Expr le = get(l);
+  const Expr re = get(r);
+  LIBC_ASSERT(l != EMPTY_SET_ID && r != EMPTY_SET_ID);
+  LIBC_ASSERT(le.kind != ExprKind::Alt);
+  LIBC_ASSERT(l < ((re.kind == ExprKind::Alt) ? re.bin.left : r));
+  return intern(Expr::make_alt(
+      l, r, static_cast<uint8_t>(le.nullable_mask | re.nullable_mask),
+      le.has_repeat || re.has_repeat,
+      cpp::max(le.rep_expansion, re.rep_expansion)));
+}
+
+// Prepends head onto an existing Alt spine (or returns head if tail is empty).
+ErrorOr<ExprId> ExprPool::prepend_alt_node(ExprId head, ExprId tail) {
+  return (tail == EMPTY_SET_ID) ? ErrorOr<ExprId>(head)
+                                : intern_alt_node(head, tail);
+}
+
+// Folds non-tombstoned items right-to-left (LIFO) onto tail as an Alt spine.
----------------
kaladron wrote:

I've rewritten that comment and few around it to be clearer.  Thanks.

https://github.com/llvm/llvm-project/pull/245590


More information about the libc-commits mailing list