Bring regexx.c/regexx.h's own file-header comments up to date

Both still described the v1 implementation as a single backtracking
engine with no mention of the Pike VM at all, stale since the engine
was added several commits ago; regexx.c's went further and never
mentioned it even in passing. Updated both to describe the actual
dual-engine dispatch, the Pike VM's allocation-free thread model and
literal prefilter (concept.md 7.10), and corrected the reentrancy note
from a blanket "do not call from more than one thread" to the actual,
narrower guarantee this session's PikeEngine design specifically
preserved: re_compile and the module level cache still need external
synchronization across threads, but Pattern_-prefixed calls on an
already-compiled Pattern do not, because nothing mutates a compiled
Pattern and PikeEngine is always scoped to one top-level call, never
cached on the Pattern itself.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EjuMk8kY9SDus1wWe2K9xY
This commit is contained in:
2026-09-14 18:55:15 +00:00
co-authored by Claude Sonnet 5
parent e4fc067aa6
commit 7461824de6
2 changed files with 48 additions and 30 deletions
+33 -17
View File
@@ -2,29 +2,45 @@
*
* See concept.md for the full design rationale. This file is the v1
* implementation: it covers the public API and pattern syntax listed in
* README.md "Implementation status" in full, executed by a single
* recursive backtracking engine (concept.md Section 7.3) over a fully
* materialized copy of the input. It does not yet implement the
* streaming, bounded-memory regular engine of concept.md Section 7.2;
* that remains future work, tracked in README.md.
* README.md "Implementation status" in full, executed by one of two
* engines over a fully materialized copy of the input, chosen
* automatically per compiled pattern (concept.md Section 7.2/7.7):
*
* That backtracking engine is memoized (run_memo) and, for quantifiers
* over a single character/class/./ (OP_REPEAT1), backed by precomputed
* run-length and skip-ahead tables (compute_maxrun,
* compute_next_prevmatch), so that Pattern_search/finditer/split/sub
* run in linear rather than quadratic time for the common,
* backreference-free case; see README.md "Implementation status" for
* the measured numbers, the precise remaining limitations, and
* citations to the published techniques this matches.
* - A Pike VM (Section 6b, "6b. Pike VM" below), a Thompson-NFA
* simulation with no backtracking at all, for any pattern with no
* backreference, lookahead, lookbehind, or atomic group. No
* per-thread heap allocation (a flat table indexed directly by
* instruction, concept.md 7.10) and a Boyer-Moore-Horspool literal
* prefilter for a pattern beginning with a mandatory literal string.
* - A recursive backtracking engine (Section 6, concept.md 7.3) for
* everything else, memoized (run_memo) and, for quantifiers over a
* single character/class/./ (OP_REPEAT1), backed by precomputed
* run-length and skip-ahead tables (compute_maxrun,
* compute_next_prevmatch), so that Pattern_search/finditer/split/sub
* run in linear rather than quadratic time for the common,
* backreference-free case there too.
*
* Neither engine yet implements the streaming, bounded-memory regular
* engine of concept.md Section 7.2 (both still materialize the whole
* input); that remains future work, tracked in README.md. See
* README.md "Implementation status" and "The Pike VM" for the measured
* numbers on both engines, the precise remaining limitations, and
* citations to the published techniques and production engines
* (RE2, rust-lang/regex) this matches.
*
* Naming convention (concept.md Section 9.0): every identifier with a
* direct Python `re` counterpart uses that counterpart's exact spelling.
*
* Not reentrant: re_compile() uses one process-wide parser scratch pool
* Reentrancy: re_compile() uses one process-wide parser scratch pool
* and the module level functions share one process-wide pattern cache
* (concept.md 13.6); do not call regexx functions from more than one
* thread without external synchronization.
*/
* (concept.md 13.6); do not call re_compile() or any re_-prefixed
* module level function from more than one thread without external
* synchronization. Pattern_-prefixed functions on an already-compiled
* Pattern no thread is concurrently modifying need no such
* synchronization (nothing here mutates a compiled Pattern, including
* matching on the Pike VM: its per-search working state, PikeEngine,
* is always local to one top level call, never cached on the Pattern
* itself, specifically so this guarantee holds, concept.md 7.10). */
#define _DEFAULT_SOURCE
#include "regexx.h"
#include <stdlib.h>
+15 -13
View File
@@ -9,19 +9,21 @@
* described below, executed by one of two engines over a fully
* materialized copy of the input, chosen automatically per compiled
* pattern (concept.md Section 7.2/7.7): a Pike VM (a Thompson-NFA
* simulation, genuinely linear time, no backtracking at all) for any
* pattern with no backreference, lookaround, or atomic group; a
* recursive backtracking engine (concept.md Section 7.3), augmented
* with memoization and precomputed skip-ahead tables (regexx.c:
* run_memo, compute_maxrun, compute_next_prevmatch) that make the
* search-family functions (Pattern_search/finditer/split/sub) run in
* linear time for the common, backreference-free case there too,
* otherwise. Neither engine yet implements the streaming, bounded-
* memory version of Section 7.2; see README.md "Implementation status"
* and "The Pike VM" for the complete, itemized, measured account of
* what v1 does and does not cover, including a real, documented
* performance trade-off between the two engines that is not yet
* resolved (concept.md 7.8).
* simulation, genuinely linear time, no backtracking at all, no
* per-thread heap allocation, and a Boyer-Moore-Horspool literal
* prefilter, concept.md 7.10) for any pattern with no backreference,
* lookaround, or atomic group; a recursive backtracking engine
* (concept.md Section 7.3), augmented with memoization and precomputed
* skip-ahead tables (regexx.c: run_memo, compute_maxrun,
* compute_next_prevmatch) that make the search-family functions
* (Pattern_search/finditer/split/sub) run in linear time for the
* common, backreference-free case there too, otherwise. Neither engine
* yet implements the streaming, bounded-memory version of Section 7.2;
* see README.md "Implementation status" and "The Pike VM" for the
* complete, itemized, measured account of what v1 does and does not
* cover, including the remaining, narrower performance trade-off
* between the two engines on patterns the Pike VM's prefilter cannot
* help (concept.md 7.9/7.10).
*/
#ifndef REGEXX_H
#define REGEXX_H