Skip to content

Front end: every error in one pass, --check, undeclared names ranked by reachability - #634

Merged
blacktrs merged 53 commits into
mainfrom
front-end-check
Nov 11, 2026
Merged

blacktrs merged 53 commits into
mainfrom
front-end-check

Conversation

@blacktrs

@blacktrs blacktrs commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A large app build stopped at the first front-end error. The external Laravel 13 report (#614) needed 15 full builds, each ~3 min and 11–14 GB, to find a dozen unsupported constructs. Parse errors, unsupported constructs and declaration/attribute errors each aborted the build on their own.

What changes

  • The front end collects every parse error, unsupported construct, and declaration/attribute/#[TypeDef] error into one diagnostics sink. It prints them all and stops before type inference (exit 65):
    <file>:<line>: error[<code>]: <message>
    front end: N error(s), M warning(s)
    
    Codes: parse.error, lower.unsupported, decl.error, attr.error, typedef.error, lower.internal.
  • compile --check / build --check: run the front end only. A clean program exits 0 and no binary is written.
  • Lowering keeps going after an error:
    • User-facing throw sites now record the error and leave a placeholder. Internal invariant / ABI-drift checks stay fatal.
    • Each function, method and top-level statement is lowered inside a recovery boundary that resets per-function state.
    • A syntax error inside a method body reports every error in that body, with its line.
  • analyze --deep reports what it did before, plus MIR findings that a declaration error used to hide.
  • On a clean program the output is identical: no new stderr lines, and bin/build is bit-identical across two runs.

Numbers (build --check, macOS arm64)

App Wall Peak RSS Errors
symfony-console 1.4 s 198 MB 0
symfony-app 7.2 s 814 MB 0
laravel-app 32 s 3.0 GB 0
symfony-demo 33 s 2.9 GB 0

Tests

  • New tests/cli cases:
    • parse errors in two files;
    • three unsupported constructs in three files;
    • two errors in one method body;
    • recovery followed by a valid function;
    • dedup;
    • --check on a clean program;
    • --check rejected by dump-* and analyze;
    • analyze --deep finding both a declaration error and a type error.
  • New tests/aot/reject/multi_decl_errors. The reject suite passes 74/74.
  • Focused AOT runs pass: closure, foreach, typedef, generic.
  • Not run yet: full AOT suite and the Linux gate.

Known limits (follow-ups)

Closes #627


Part 2 — undeclared classes, functions, constants as front-end warnings (#489, step 2)

Problem. A reference to a class, function or constant that nothing declares compiled silently and failed only at run time. For example, symfony-app without symfony/string built green, then died on UnicodeString. new X on an unknown class was not checked anywhere.

What changes

  • References in user code to undeclared names are reported by the front end as warnings, one line per name at its first site with (N uses) counted over distinct sites:
    • undefined.class: new, static access, instanceof, catch, param/return/property type hints, extends/implements/trait use;
    • undefined.function: direct calls. A function counts as defined if it is a module function, a linked .sig extern or an emitter builtin (BUILTIN_NAMES, kept in sync with emitBuiltin by tools/check_builtin_names.sh);
    • undefined.constant: bare global constants.
  • Resolution uses the build's own tables. There is no second resolver. Polyfill-guarded declarations, guarded define, literal class_alias targets, namespace fallback and use function/use const all count as declared.
  • Warnings only. The build proceeds, the exit code is unchanged, codegen and lib/*.o are unchanged, and the runtime traps stay. Errors for reachable references come with step 3 (reachability tiers).
  • The prelude, generated code and __mir_*/__mc_* are never checked.

Found by the new check

  • src/Manticore/Main.php, namespace Manticore: two catch (Throwable $e) resolved to Manticore\Throwable and never caught anything. Fixed to \Throwable.
  • The parser treated numeric as a scalar type, so a class named Numeric in a namespace (Laravel Rule.php) stayed unqualified. Fixed; tests/parser/strict_invariance.sh reports OK on 3187 files.
  • A bare exit; lowers to Undefined constant "exit". Repro added; filed as A bare exit; (no parentheses) throws "Undefined constant exit" instead of terminating. #635.

Corpus (build --check, rc=0 everywhere; warnings class/const/fn)

App Warnings Wall
symfony-console 32 / 0 / 0 1.3 s
symfony-app 253 / 96 / 49 7.0 s
laravel-app 335 / 138 / 105 29 s
symfony-demo 400 / 162 / 161 30 s

Every class and constant warning was audited by hand against the app sources, vendor, prelude, stdlib and .sig. One false positive (Numeric) was fixed at its root; the rest name genuinely absent symbols. The compiler's own build --check reports zero warnings.

CI fix. The cli golden failed on macOS because CI=1 turns progress output on. diag() now runs commands with CI unset.

Also addresses #489 (steps 1–2 of 4; reachability tiers and the shared declaration table follow).


Part 3 — reachability tiers: reachable undeclared names fail the build (#489, step 3)

What changes

  • After lowering, a two-level Rapid-Type-Analysis pass (Compile\Mir\Reachability) walks the MIR from the program roots: __main, include units, global initialisers, emitter-invoked factories, and every exported symbol for library targets.
    • STATIC level: explicit edges only — named calls, new, resolved static and late-static calls, literal-name method calls over instantiated classes, and callable literals in callable positions.
    • DYNAMIC level: what is reachable only through runtime names — $f(), new $x, $o->$m(), $cls::m(), unserialize, reflection newInstance*.
    • Literal-only local value sets turn dynamic targets into static edges, e.g. $c = $x ? A::class : B::class; new $c.
  • Each undeclared-name finding is tiered:
    • a statically reached, unguarded, hard reference (new, static access, call, constant, extends/implements) → error, exit 65, with (reachable: a <- b <- __main);
    • a dynamic-only, soft (instanceof, catch, type hints) or guarded reference → warning. Guards cover class_exists/function_exists/extension_loaded/… in if arms, polarity-aware early exits, &&, ?:, single-return guard helpers such as isSupported(), and guard-valued locals;
    • unreachable → hidden note; --all lists them.
  • PHP-internal names that Manticore does not implement (a generated list from php) → unsupported.builtin warning, never an error.
  • Escape hatches:
    • manifest per-app allowUndefined glob patterns, which acknowledge specific missing names;
    • --allow-undefined-traps, which restores the old runtime traps entirely.
    • The example manifests carry their (true-positive) patterns, so all four example apps build with 0 errors.
  • AOT cases that deliberately test the runtime trap carry // @allow-undefined-traps, honoured by both test runners.

Also fixed

Lowering changes to watch in the full suite

  • define() names that are foldable concatenations are now folded.
  • Composer\Autoload\ClassLoader counts as compiler-owned.
  • $x::K probing no longer records class references.
  • Dead top-level code after a folded guard's return/exit is no longer lowered.
  • exit/die count as terminators.

Numbers. Reachability costs about 0.9 s of a 30 s build --check on laravel-app and symfony-demo (≈3%). The compiler's own build --check reports zero diagnostics. bin/build output is bit-identical across rebuilds.

Merged main (#631, #616). Conflicts were resolved keeping both sides.

… boundary

With a diagnostics sink, an exception escaping lowerFunction, a method
(lowerMethodFn / lazy-body materialisation), a class or a top-level statement
is recorded (lower.internal, or parse.error with the ParseError's own line for
a lazy body) and lowering moves on; the failed unit is not added to the module.
Synthesized helpers stay outside the boundary. release* still run after a
failed class.

recoverLowering resets the per-function state lowering sets and restores
without a finally: currentLowerClass, currentLowerFn, currentLowerFnHasThis,
currentTypeParams, currentTypeBounds, currentTypeSubst, currentStaticClass,
currentTypeDefClass, currentRefParamNames, currentLowerParams,
currentLowerParamHints, currentArrayCaps, constCallables, localNewClasses,
lowerInMain, bindLateThis, lowerClosureDepth, closureMagic, silenceDepth,
sawYield, sawFuncArgs, sawStaticUse, lvHoist, lvTemps, valueTemps,
stmtAssign, pendingCallInits, pendingCallPost, scopedIncludeStack,
declTableBusy. A failed method re-enters the class scope (type params,
bounds, subst, namespace) via restoreClassScope.
…pans for typedef/reify errors, all parse errors of a lazy body, guarded tolerant re-parse
COMPILER_CLASSES: Closure (emitter statics, EmitLlvmObjects/staticClassAbsent), Generator (emitter class_exists handling in EmitLlvmBuiltins), Ffi\Ptr (ptrIntrinsicClass).
@blacktrs blacktrs changed the title Front end: report every parse/lowering error in one pass, add --check Front end: every parse/lowering error in one pass, --check, undeclared-symbol warnings Nov 10, 2026
…bles, attribute bodiless method hints to their class
…factories, $x::K probe, callable arrays, static:: hierarchy, guards in switch/try and assignments
@blacktrs blacktrs changed the title Front end: every parse/lowering error in one pass, --check, undeclared-symbol warnings Front end: every error in one pass, --check, undeclared names ranked by reachability Nov 11, 2026
@blacktrs
blacktrs merged commit 02c0971 into main Nov 11, 2026
55 checks passed
@blacktrs
blacktrs deleted the front-end-check branch November 11, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant