Skip to content

WordPress groundwork: parser, declaration hoisting, include semantics, injective symbol names - #631

Merged
blacktrs merged 21 commits into
mainfrom
wordpress
Nov 10, 2026
Merged

blacktrs merged 21 commits into
mainfrom
wordpress

Conversation

@blacktrs

@blacktrs blacktrs commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #622, Fixes #623, Fixes #624, Fixes #625

Why

First step toward compiling WordPress (7.1.4) into a native binary. Building the core front end (index.php → wp-settings.php → wp-includes, wp-content) hit a series of gaps in the parser, lowering, type inference and include semantics. This PR closes the ones that block the build and the early request path, each with its own AOT case.

Where WordPress stands with this PR

  • wp.bin builds (≈5 min with -j 0, 232 MB); manifest: src: ["."], entry index.php, wp-admin and SimplePie excluded for now.
  • With the sample wp-config.php (no database) the binary prints the "Error establishing a database connection" page byte-identical to php.
  • Against a real MySQL it boots through plugins and default-filters.php and stops in create_initial_taxonomies() — the next item, not in this PR.

What changes

Parser

  • var $x is a property modifier (it was parsed as a type named var).
  • The alternative switch (…): … endswitch; syntax.

Declarations and lowering

  • \true / \false / \null fold in declaration guards like the bare literals (A class declared under if (\false) fails to lower, while if (false) compiles: "unsupported statement kind Class". #625).
  • A function/class declared under a runtime if, or inside a function body, is hoisted to the top level (one declaration per name; two behind an unfoldable guard is a clear compile error).
  • version_compare(PHP_VERSION, …) folds at compile time.
  • $GLOBALS[$name] with a computed name (read / write / isset / unset) through a generated by-name table.
  • $obj::$prop = v / $cls::$prop = v.
  • compact($names) with runtime names.
  • A local assigned nowhere in its function reads NULL instead of failing MIR.verify.
  • A polyfill of a built-in type whose file leaves early on class_exists() is dropped (sodium_compat's SplFixedArray).
  • A docblock @param callable no longer narrows the parameter to a closure (it took add_filter()'s string callbacks for env pointers).

Include semantics (what WordPress expects from php)

  • A lazy include unit keeps its define() calls: they run when the file is required, not at startup (xmlrpc.php's define('XMLRPC_REQUEST', true) made wp_die() answer in XML).
  • function_exists() of a function declared in a not-yet-required file answers false; files of function declarations alone become lazy units for that.
  • A foreach loop variable that is a global writes through the global's cell.

References, types, ownership

  • A reference to a static stored in a global array ($l10n[$domain] = &$noop): the static's slot is a cell; a global filled only by unshaped element stores is an array of cells, not int.
  • A reference to a $GLOBALS-viewed global can be stored.
  • Ownership flow leaves a name unowned (leaks, never double-frees) when compensation cannot converge or a scope reader (compact/extract) meets a representation mismatch, instead of failing the build.

Symbols

  • One owner for symbol names (Compile\SymbolName): \ mangles to ., synthesized helper names use an injective escape. A\B_C and A_B\C no longer collide (sodium_compat ships both spellings of several classes). Sig uses the same function.
  • The nested-array release flavor is capped at the three levels the runtime emits.

Stdlib

  • extension_loaded() answers true for every linked extension (hash, date, spl, curl, zlib, …); WordPress refuses to boot without hash.
  • INI_* constants, DateTimeZone group constants, date_create_immutable_from_format().

Bugs filed on the way (repro in tests/aot/repro, XFAIL)

Not in this PR

  • ext/xml (0/22) — needed by SimplePie and XML-RPC.
  • Two declarations of one class behind a runtime condition (wp-admin/includes/class-ftp.php) — needed to bring wp-admin back into the build.
  • HTTP serving with fresh per-request state; wp-config.php from environment variables.

Testing

  • New AOT cases for every fix (each red on the previous compiler), plus fixtures in tests/libs/lazy_units (tools/liblazyunits_smoke.sh).
  • Targeted groups green locally on macOS arm64: static, ref_, global, superglobal, foreach, reflect, namespace, attribute, callable, lib, datetime, extension_loaded; tests/parser/run.sh green.
  • Not run: full AOT suite, difftest, fixpoint, Linux gate. The riskiest changes for the full suite are the mangle change (\ → .) and declaration-only files becoming lazy units.

…n_compare(PHP_VERSION, ...), lower $GLOBALS[$name] with a computed name
…stead of failing when compensation cannot settle it or a scope reader meets a mismatch
…e globals table from global bindings, not the $GLOBALS view
… LLVM symbols and for synthesized helper names; Sig uses it
…(hash, date, spl, filter, iconv, random, reflection, sockets, curl, simplexml, libxml, zlib, pdo)
…s a cell (null boxed), and a global filled only by unshaped element stores is an array of cells, not int
…cell; repro for an unassigned global reading 0 (#630)
@blacktrs
blacktrs merged commit dbb6fdd into main Nov 10, 2026
55 checks passed
@blacktrs
blacktrs deleted the wordpress branch November 10, 2026 15:01
blacktrs added a commit that referenced this pull request Nov 12, 2026
…lution (#655)

* Parser: parenthesized break/continue level, instanceof Name::$prop, ranges start at a receiver's '('

break(1); / continue((2)); parse as php does; `$x instanceof self::$prop` (and `[...]` subscripts) names the class by a static property's value, sharing new's new_variable parser. In ranges mode a postfix or binary node on a parenthesised operand starts at the '('.

Fixes #618
Fixes #619
Fixes #505

* #[\Override] accepts a method implementing an abstract method of a used trait

php counts an abstract method of a trait the class uses (directly or via trait-uses-trait) as overridden; a concrete trait method still is not.

Fixes #617

* static::$p = v in a parent that does not declare $p lowers to php's run-time Error

The parent-scope body is reached only by a direct call, where php throws "Access to undeclared static property C::$p"; the subclass-scope bodies keep their slots. The read of the same name said "Undefined constant C::$p"; both now share one helper with php's wording.

Fixes #620

* Declaration guards fold class constants of declared classes

`if (Logger::API >= 3) { trait Compat … } else { trait Compat … }` (sentry's Monolog compat traits) folds like a global constant guard.

Fixes #621

* build: refuse "stdlib": false on an application that does not embed the runtime source

The codegen calls runtime helpers (__mc_dtoa_core, …) directly, so such an app failed in clang with an undefined IR value. The option exists for the compiler, which compiles src/Runtime itself.

Fixes #506

* xfail: drop the #407 repro (closed: not reproducible in AOT), link the #606 repro to its issue

* DateTime::createFromFormat: Z offsets, escaped literals, microseconds, and the parsed or given zone

P/O/p read 'Z' as UTC; an escaped format char must match the input. The object keeps the microseconds, takes the zone written in the string (or +00:00 for an epoch) and otherwise reads the fields as wall-clock time in $timezone or the default zone — it used to treat them as UTC and force +00:00. One helper serves DateTime and DateTimeImmutable.

Fixes #572

* Builtin name sets back in sync: runtime function_exists, get_defined_functions, analyzer prelude

Analyze\Builtins (which seeds the runtime function_exists table and get_defined_functions) missed 61 dispatch names, so a runtime-name function_exists('stripos') / ('gc_enable') answered false. The emitter-inline list gains the 8 names whose literal answer leaned on a stdlib body. The analyzer now indexes the 16 intl prelude files. calibrate.sh no longer reads "runtime\\libc\\strlen" or $name === $target as dispatch names and skips the *_off.php driver stand-ins.

Fixes #646

* xfail: class_alias() name unusable for new/instanceof/static calls (#653)

* Library .sig exports class constants again

releaseAllClassMetadata (front-end memory trim) emptied every ClassDecl's consts before the export fold and the .sig writer read them, so an app importing a library class saw "Undefined constant Acme\\Point::NAME". Exported types (Module::typeDecls, library builds only) keep their metadata. libclass_smoke.sh looked for the pre-#631 method symbol spelling.

Fixes #632

* Convert an int to float where the declared type admits float but not int

Weak-mode php turns an int landing in a ?float / float|string slot into a float; such a slot is a cell and kept the int tag. Params convert in a callee-side prologue (direct, dynamic, default, by-ref, ?float variadic), returns through the declared hint (functions, methods, closures, arrow fns, get hooks), instance and static property stores, and a float variadic pack built from int args.

Fixes #553
Fixes #554
Fixes #490

* Bind call arguments like php across spread, variadic, static and callable paths

- Spread arrays: the positional run is the int-keyed prefix (__mir_array_pos_prefix);
  a string key naming no parameter goes to the variadic under its key, or throws
  "Unknown named parameter" / "Cannot use positional argument after named argument";
  mixed-key literals count as keyed. The fixed+variadic split moves from lowering
  (positional array_slice) to the emitter, and a spread no longer refines the
  callee's params from the pack's array type.
- func_get_args() sees spread arguments: argc and overflow come from the pack at run time.
- ArgumentCountError names Class::method, not Class::::method.
- $obj() on a variadic __invoke packs its arguments.
- A variadic arm of an erased receiver packs the written arguments when lowering
  could not name the method.
- A static method reached through an object ($o->m(...), [$o, 'm'], erased receiver)
  gets no $this; ResolveMethodFcc forwards every param of a static target.
- A function-name string in a `callable` slot stays tagged, so the invoke resolves
  it by name instead of jumping to it as a closure.

Fixes #571
Fixes #573
Fixes #574
Fixes #583
Fixes #593
Fixes #595
Fixes #596
Fixes #650

* Fold case in runtime class-name lookup, name the missing class in constant(), mark internal return types tentative in reflection

Fixes #603
Fixes #604
Fixes #563

* Resolve runtime class names through the registry: get_parent_class, is_a, enum interfaces, Generator; type errors for array props and string args

get_parent_class answers for runtime names and built-in classes, is_a folds case,
UnitEnum/BackedEnum match enum cases, get_class names a Generator in a mixed slot,
ReflectionMethod::invoke of __construct runs on the given object, a scalar stored
into an array property and an array/object passed to a stdlib string parameter by
runtime name throw TypeError.

Fixes #332
Fixes #578
Fixes #579
Fixes #584
Fixes #588
Fixes #570

* Throw when a plain read of an unset typed property goes through an erased receiver

Fixes #594

* Array-property type check no longer leaks every stored value

The #579 check wrapped the value in a __mir_assert_array_prop call that retained it and was listed as owned, so every store into an `array` property leaked one reference (mysqli stmt_procedural LEAK on CI). Classed as a borrow it freed the argument temp before the store retained it. The check now goes through a temp local (is_scalar / is_null -> TypeError, else the local), the shape the int->float coercion uses, and the builtin is gone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment