Repository navigation
Compiler and tokenizer fixes from the manticore-fmt rewrite - #380
Merged
Merged
Conversation
… 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
…izer on __McTok. Fixes #342
…ad sprintf()/printf(); the raw NaN-boxed word was read as a string pointer. Fixes #356
… leaks the literal (#357)
…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
…ormats the pack as Array
…omment before the name; class enum extends/implements)
…a backslash name (use\C) instead of one T_NAME_QUALIFIED
…g an int-keyed local array lookup answers 0
…s boxed words through a typed parameter
…to the same literal
…t_error() is stale
…t index was built in the loop's window Fixes #364
…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
…compares unequal to its own values
…s when the function later array_splices it
…valid UTF-8 answers 0 instead of false
… <<< 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
…epr is read back raw (#376)
…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
…mespace\f() fails to parse (#378)
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)//and#comments end at a lone CR; prelude tokenizer gated accordingly (ownflow verifier rejects a loop-carried local assigned from an untyped array element and from new #338, token_get_all does not end a//comment at a lone CR the way Zend does #342)(binary)cast lexed asT_STRING_CAST(token_get_all() does not lex the (binary) cast as T_STRING_CAST #358)enumlexed as Zend does (comments betweenenumand name)\Nameis one qualified name (a reserved word followed by \Name is one qualified name to Zend (echo\A\f() is a call), but the compiler lexes it as the keyword #368, also in the compiler's ownLexer)a as protected;keeps its member modifierb'x',b"x",b<<<Ekeep the binary flag; a<<<that opens no heredoc lexes as<<<(token_get_all() splits the binary flag off b'x', b"x" and B<<<E into a T_STRING instead of one token #371)Runtime / stdlib
preg_*return false / null and setpreg_last_error()on a match error or bad pattern; pattern parsing siblings (missing delimiter, leading whitespace, bad modifier,J/n) (preg_* with /u on invalid UTF-8 returns 0 / the subject instead of false / null, and preg_last_error() is stale. #367, preg_match / preg_replace with /u on an invalid UTF-8 subject answer 0 / the subject with no error instead of false / null + PREG_BAD_UTF8_ERROR #372)strpos/striposunbox a mixed needle;sprintfspread packs get an owner and fixed-args-before-spread (A program that passes a string-offset char to strpos() and also calls array_splice() on the array segfaults. #356, sprintf() over a spread array literal holding a mixed (cell) value leaks the literal array. #357, sprintf() with a fixed argument before a spread formats the spread pack itself as "Array". #360)Compiler passes
enumas T_STRING when a comment (not only whitespace) sits between it and the name #361/token_get_all() lexesenumas T_ENUM inclass enum extends B/class enum implements C; Zend gives T_STRING #362)a as protected;as T_STRING instead of T_PROTECTED #343)@vararray local with a cell element builds a cell buffer (An int list passed to an int[] parameter reads wrong values when the same function later array_splices it (reduced from manticore-fmt). #370); locals whose whole-array stores disagree on element repr get a cell element (partial, see below)Not fixed (XFAIL repros included)
namespace\f()/namespace\Cinside an expression fail to parse.Testing
tests/aot/xfail.sh: 80 XFAIL, 0 XPASS.bin/buildclean (both passes, CELLGUARD violations=0).tools/difftest.sh, Linux gate. The shape widening (an int list vivified in a returned tuple, destructured and passed to an array<string, int[]> parameter, reads its ints as boxed words #365) may touch clone/perf behaviour — worth watching on the gates.