Skip to content

Compiler and tokenizer fixes from the manticore-fmt rewrite - #380

Merged
blacktrs merged 41 commits into
mainfrom
fix/ownflow-and-tokenizer
Oct 22, 2026
Merged

blacktrs merged 41 commits into
mainfrom
fix/ownflow-and-tokenizer

Conversation

@blacktrs

Copy link
Copy Markdown
Contributor

Summary

Compiler and prelude fixes found while building manticore-fmt (a from-scratch PHP formatter compiled by Manticore, byte-identical to php-cs-fixer under Zend). Each fix is a root-cause change with a promoted regression case; open bugs keep XFAIL repros.

Fixed

Tokenizer (prelude/tokenizer.php)

Runtime / stdlib

Compiler passes

Not fixed (XFAIL repros included)

Testing

… the narrowed type

An instanceof guard narrows a local's read type without touching its slot.
inferIf recovered the slot by comparing the arm's type with the narrowed one,
so an arm that STORED a value of the narrowed type ($l = new M() under
$l instanceof M) was taken for unstored: no merge box-back was planted, a raw
object met a cell at the loop head and ownflow rejected the read past it.
Record the pre-narrowing slot per name until a store, and compare slots at
every if/else merge, nested ifs included.

Fixes #338
…ad sprintf()/printf(); the raw NaN-boxed word was read as a string pointer. Fixes #356
…nts in SpillFreshBases so every call kind releases the pack after the statement; route a spread sprintf()/printf() with a literal format to the runtime engine. Fixes #357
…omment before the name; class enum extends/implements)
…he name, and enum extends / implements is a plain name. Fixes #361, fixes #362
…a backslash name (use\C) instead of one T_NAME_QUALIFIED
…hem: an erased list in an int[] field was read raw

A shape's container field (array<string, int[]>) claimed raw elements no
matter what filled it. Returns, literal args adopting a shape param, and
Monomorphize clones now keep a container field's element claim only as
deep as the given value proves it (Type::proveShapeFields), widening to
cell below. A shape param a call site leaves unproven is a specialization
dimension, so a lone site gets its own clone.

Fixes #365
…tead of by pointer

chainsComparable() rejected a raw nested array facing a cell element unless the
raw side's inner elements were cells, so an array<string, mixed> from
json_decode() fell back to pointer identity against the same literal. The
array compare runtime now recurses into such a pair itself: the raw side by
the rest of its chain, the cell side by its buffer hint.

Fixes #366
…et_all()

Zend's lexer matches {LABEL}(\{LABEL})+ before any keyword rule, so use\C,
new\X and yield\from are one T_NAME_QUALIFIED (namespace\X: T_NAME_RELATIVE);
only a property name after -> / ?-> stays a bare label. The prelude scanner
classified the keyword first and split the name.

Fixes #363
…; is T_PROTECTED

parseReclassify turned any keyword between `as` and `;` into T_STRING, but
Zend's trait_alias grammar takes a bare member_modifier there (public,
protected, private, static, abstract, final); only a reserved non-modifier
names the alias, also after a modifier (`as final list;`).

Fixes #343
…teral [$a, ...$b]

biSprintf/biFormatRuntime took the runtime path only for a lone spread and
otherwise packed the Spread node as ONE value ("ab Array!", or a SIGSEGV);
biMinMax compared the spread's array as an operand. Both now build the
argument list with emitArgPack (fixed args boxed and appended, each spread
merged with php's key rules) and hand it to __mc_format / __mc_minmax_of.

Fixes #360
… <<< that opens no heredoc lexes as << <

Fixes #371
…r or a pattern that does not compile

A bad UTF-8 subject under /u, a bad offset or a match limit made preg_match
answer 0 and preg_replace the subject, with preg_last_error() stale. Every
preg_* now follows php: preg_match / preg_match_all / preg_split false,
preg_replace / preg_replace_callback(_array) null (an array subject drops
the failing key), preg_grep stops at the first error. Pattern parsing is
php's too: leading whitespace skipped, a missing closing delimiter, an
alphanumeric delimiter or an unknown modifier fail to compile; J and n
modifiers map to PCRE2 options.

Fixes #367
Fixes #372
array<int, array{0: int, 1: string}> built with $out[] narrowed its key to a
vec and rebuilt the element from the body (vec[cell]), dropping the fields.
$p[0] typed int before the pass and cell after it, so an int list fed from
it became vec[cell] while its int[] callee stayed bound to vec[int].

Fixes #369
…cell buffer

A by-ref callee that writes foreign elements (array_splice) puts the local in
cellElemLocals, so every $x[] = v boxed into vec[cell] while the @var int[]
init pinned the slot to vec[int]. Branch merges joined the two to
vec[unknown], one buffer held raw and boxed words, and an int[] callee read
wrong values. The declared type now yields to the cell arm for such a slot.

Fixes #370
…repr gets a cell element

$p = ints(); if (…) { $p = strs(); } merged vec[int] and vec[string] to
vec[unknown], the next $p[0] = 9 re-narrowed it to vec[int], and the string
buffer was read as ints (an address printed). The slot now takes a cell
element and every store converts its value. Decided before Monomorphize
only: a later retype hands vec[cell] to a callee already specialized for the
old element, which is why #376 (the conflict appears only after Mono) stays open.
echo\A\f() is a call to A\echo\A\f to php, not echo + \A\f(). Only
namespace\X keeps the keyword. No tree code spells a keyword before \Name.

Fixes #368
foo\f() in namespace A resolved to A\f, and \B\strlen() to strlen,
because resolveCallName stripped every unknown name to its last segment.
php falls back only for an unqualified name; CallExpr now records whether
the source was qualified.

Fixes #377
…t and the nullsafe operator in simple interpolation
memory_get_usage()/memory_get_peak_usage() answered getrusage's ru_maxrss,
which Linux carries across execve: a program started by a bigger process
(the test runner, a shell) began at that process's peak, and its own growth
stayed hidden or surfaced late as an arbitrary jump. ref_store_throw_path_flat
measured that jump, not a leak (valgrind: 192 B in use at exit for 1000 and
10000 iterations alike; exact smaps RSS flat over 400k iterations).
Linux now reads VmHWM from /proc/self/status, the address space's own peak.

Fixes #381
@blacktrs
blacktrs merged commit 33df962 into main Oct 22, 2026
13 checks passed
@blacktrs
blacktrs deleted the fix/ownflow-and-tokenizer branch October 22, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant