Skip to content

fix: a compile after a warm pass types every class the pass skipped - #126

Merged
heyJordanParker merged 3 commits into
masterfrom
fix/warm-compile-panic
Oct 14, 2026
Merged

heyJordanParker merged 3 commits into
masterfrom
fix/warm-compile-panic

Conversation

@heyJordanParker

@heyJordanParker heyJordanParker commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Problem

A compile after a warm pass panics in the bridge when the service analyzes with diff, which is how mago analyze --watch analyzes. A body-only edit is enough, such as return 1; to return 2; or => cents; to => cents + 1;:

thread '<unnamed>' panicked at crates/sharp-bridge/src/lower/types.rs:93:13:
internal error: entered unreachable code: the analysis types every expression of a file the checker accepted, not Span { …, start: Position { offset: 127 }, end: Position { offset: 158 } }

On master only a warm compile hits it: mago compile analyzes cold without diff, and mago analyze --watch never compiles. The warm compile tests and the coming daemon do hit it. The same stale state also hides an unchanged file's issues and types from analyze_file and analyze_file_with_artifacts, the one-file analysis an editor runs, for PHP too.

Root cause

A body-only pass marks every unchanged class safe (CodebaseMetadata::safe_symbols), and populate_codebase_inner stores the marks in the codebase the service keeps after the pass. compile's lower_all then analyzes each .sharp file again, one at a time, with the service's settings. Under diff the analyzer skips every class still marked safe, so it records no type for any expression in it. The span above is money.amount() + Rate.percent() in the unchanged app/Order.sharp, the first expression the bridge asked a type for.

Solution

The marks steer only the pass that set them. run_analyzer_selective will clear them once its analysis ran:

         if !after_analysis {
             snapshots.clear();
         }
 
+        // The safe marks tell this pass which code its skipped files' cached results stand for. An analysis of one file
+        // after it, as the compile step runs, analyzes and types the whole file.
+        codebase.safe_symbols.clear();
+        codebase.safe_symbol_members.clear();
+
         Ok(SelectiveAnalysisOutput {

The same stale marks broke a second path. When the before-analysis hooks return references that differ from the last pass, run_analyzer_selective analyzes every file again, the ones it meant to skip too. Their classes were still marked safe, so under diff their cached issues were replaced with none. run_analyzer_selective will clear the marks before that full re-analysis:

         let effective_skip_files = if references_changed { HashSet::default() } else { skip_files.clone() };
+        // Changed references analyze every file again, the ones the pass meant to skip too, so no class stays safe.
+        if references_changed {
+            codebase.safe_symbols.clear();
+            codebase.safe_symbol_members.clear();
+        }

The next warm pass sets its own marks before it reads any. The body-only path builds them from the class list, and the other path clears them first. A full analysis already leaves none, because populate_codebase writes empty sets.

sharp/mago/composer/tests/Sdk/Fixtures/
└── analyzer-server-worker.php
    └── ServerProofPlugin::beforeAnalysis                                   <- adds a reference while PROOF_REFERENCE is declared
sharp/mago/tests/
└── server_engine.rs
    ├── server_with                                                         <- new: the proof server under given analyzer settings
    └── a_warm_pass_whose_before_analysis_references_changed_reports_what_a_fresh_pass_reports   <- new, diff on
sharp/mago/crates/orchestrator/src/service/
├── incremental_analysis.rs
│   ├── run_analyzer_selective                                              <- clears the safe marks when the references changed, and once its analysis ran
│   └── tests
│       └── test_watch_one_file_analysis_after_a_body_change_in_an_unrelated_file   <- new: PHP, analyze_file after a warm diff pass
└── incremental_analysis/
    └── compile.rs
        └── tests
            └── a_compile_after_each_edit_matches_a_clean_compile          <- new: every edits() row, diff false and true

Changed PHP result

analyze_file on an unchanged PHP file after a warm diff pass now reports that file's issues. Before, the analyzer skipped its classes. With Child extends Base returning float over Base::run(): string and a private unused() method, after a body edit to an unrelated file:

master: []
fix:    incompatible-return-type: Return type `float` of `Child::run()` is incompatible with parent return type `string` of `Base::run()`
        unused-method: Method `unused()` is never used.

Those are the issues a full analysis reports. mago analyze --watch output does not change, because the pass's own issues come from the analysis that ran before the marks are cleared.

Verification

  • a_compile_after_each_edit_matches_a_clean_compile on master panics with the message above. With the fix it passes, and every edits() row's warm compile equals the clean compile byte for byte after the header, with and without diff.
  • test_watch_one_file_analysis_after_a_body_change_in_an_unrelated_file fails without the fix (Only after the full analysis: [unused-method…, incompatible-return-type…]) and passes with it.
  • a_warm_pass_whose_before_analysis_references_changed_reports_what_a_fresh_pass_reports fails without the second fix (left: {}, right: {"invalid-return-statement": ["Invalid return type for function Broken::value: …"]}) and passes with it. --test server_engine: 12 passed. --test scoped_check, which shares the worker: 5 passed. Both ran with MAGO_REQUIRE_PHP_SDK_TESTS=1.
  • cargo test -p mago-orchestrator --lib: 146 passed. cargo test -p mago-server: 2 passed. cargo clippy -p mago-orchestrator --tests -- -D warnings: clean.
  • A release mago from this head: mago compile on a two-file probe writes the same .sharpc bytes as master's, except the header's checker build ID and the key that hashes it. mago analyze --watch across two body edits prints the same lines as master.

heyJordanParker and others added 3 commits October 14, 2026 01:36
A compile after a body-only edit panicked in the bridge with "the analysis types every expression of a file the checker accepted", when the service analyzes with `diff`, as `mago analyze --watch` does. The body-only pass marks every unchanged class safe, and the populator stores those marks in the codebase the service keeps. The compile step analyzes each file again, one at a time, with the same settings, so the analyzer skipped every class still marked safe and typed none of its expressions. The first one the bridge asked for was `money.amount() + Rate.percent()` in an unchanged file.

The marks steer only the pass that set them. `run_analyzer_selective` now clears them once its analysis ran, so a one-file analysis after a warm pass covers the whole file. That also gives `analyze_file` and `analyze_file_with_artifacts` an unchanged file's issues and types again, for PHP too.

Co-Authored-By: Claude <[email protected]>
…e's issues

When the before-analysis hooks return references that differ from the last pass, `run_analyzer_selective` analyzes every file again, the ones the pass meant to skip too. Their classes were still marked safe, so under `diff`, as `mago analyze --watch` analyzes, the analyzer skipped them and their cached issues were replaced with none. An unchanged `Broken` lost its `invalid-return-statement`.

It is the same cause as the warm compile: safe marks that outlive what they describe. `run_analyzer_selective` now clears them before it analyzes every file again.

The server proof worker's before-analysis hook adds a reference while `PROOF_REFERENCE` is declared, so a test can change the hooks' references between two requests.

Co-Authored-By: Claude <[email protected]>
@heyJordanParker
heyJordanParker merged commit 76d220c into master Oct 14, 2026
19 checks passed
heyJordanParker added a commit that referenced this pull request Oct 14, 2026
…eside structs and Map and Set objects

Problem

master gained spec section 32's modules and container, section 26's
extensions, and the warm-compile fix. Both sides changed the same bridge,
scanner, checker and flag code, so 13 files conflicted, and four places
compiled apart but not together.

Solution

Each side's behaviour stays, through one mechanism where both had one:

- A parameter's `Map` or `Set` crosses through `collection_parameters`,
  which now takes any parameters, so master's extension members cross a
  `Map` as well as a `Set`. master's `set_parameters`, `set_parameter` and
  `set_from` go: `collection_parameters`, `collection_hint` and `crossed`
  do their job.
- `attributes` takes the one group the lowering adds last: a property's
  `#[\Sharp\Crossing]` or master's parameter `#[\Sharp\Internal\Service]`,
  each from its own builder over a shared `attribute_group`.
- The test hooks of a test module's file go on a class in `class`, since
  `class_members` serves a struct too and the module names only classes.
- `STRUCT` and `REQUIRED` move to flag bits 51 and 52, after master's
  extension flags.
- The bridge's `constructor_parameters` for `new` becomes `new_parameters`,
  beside master's `constructor_parameters` for the container.
- master's extension call drops the key argument our side deleted with the
  key text, and `Key` joins the default class names master moved to
  `shadowable_default_classes`.
- Two of master's test-module tests assert their rule rather than "no
  method" and "no return anywhere", which every class's generated `parse`
  and `tryParse` broke.
- `Stamp.sharp` calls `value.trim()`, as section 26 now requires.
  `struct-equality` passes, a struct's `==` calling the new `trim()`, and
  leaves the spec baseline.
- `sharp_arginfo.h` is regenerated from the merged stub.

php-sharp
├── ext/sharp/sharp_arginfo.h               <- regenerated from the merged sharp.stub.php
├── Zend/tests/sharp/Stamp.sharp            <- value.trim()
├── sharp/baseline/spec/§19/struct-equality <- deleted: the example passes
├── docs/architecture/slices/10-structs.md  <- names collection_parameters and crossed
└── sharp/mago/
    ├── scripts/regen-analyzer-issue-codes.php
    │                                       <- both sides' issue codes
    └── crates/
        ├── codex/src/metadata/flags.rs     <- STRUCT 1 << 51, REQUIRED 1 << 52
        ├── codex/src/scanner/              <- register_struct and walk_struct beside modules'
        │                                      bindings; the names binding enum by its module path
        ├── names/src/lib.rs, internal/walker.rs
        │                                   <- Sharp\Key a default class name
        ├── semantics/src/internal/checker/sharp.rs
        │                                   <- check_struct_declaration beside check_extension
        ├── syntax/src/parser/internal/class_like/method.rs
        │                                   <- both doc lines
        └── sharp-bridge/
            ├── src/lower.rs                <- collection_parameters for every parameter list;
            │                                  attributes, crossing_attribute, service_attribute,
            │                                  attribute_group; test hooks in class
            ├── src/lower/inline.rs         <- form refuses a Map or Set parameter
            ├── src/lower/types.rs          <- new_parameters
            └── tests/lower.rs              <- both sides' tests; two test-module asserts narrowed
heyJordanParker added a commit that referenced this pull request Oct 14, 2026
…compile fix (#126)

Problem

Master moved `Sharp\Environment` out of C into the standard library as a
`foreign` class, and added `foreign` classes, `uses` on methods without a
body, and the rule that no static holds a `foreign` object. Generics changed
the same parser, binder, checker, bridge and extension files. Joined, four
things broke:

- `Method` grew by both sides' arena fields, and clippy's
  large_enum_variant refused `ClassLikeMember`.
- A method value of a plain PHP `@template` method, as `List.wrap`, kept its
  unfixed `T`. Generics hold an unfixed type parameter to itself, so
  `Shelf.make(List.wrap)` into a `Function<List<Any?>(Any?)>` was refused.
- Two generics fixtures implement a pure interface method with `sprintf`,
  which has no `extern`, so the effects check refused them.
- The opcodes test pinned its `Generics` difference against the old `link`
  body.

Solution

- Keep both sides in every conflict. `ext/sharp/sharp.c` keeps the type
  texts and takes master's native `Environment.commandLine`, and
  `sharp_arginfo.h` is regenerated from the merged stub. sharp/bin/native
  writes the same `sharp_native.h` and `native.php`.
- A method's `on` clause moves into the arena, as `type_parameters` and
  `uses` already sit there, so `Method` fits clippy's limit again.
- `fix_type_arguments` infers a plain PHP method value's `@template` types
  from the function type it goes into, as it does a PHP# method's. A plain
  PHP method's type arguments never reach the engine, so it records none and
  refuses none, and the value stays PHP's first-class callable.
- The fixtures build their strings with template strings, in the `.sharp`
  and its `.inc` twin alike, and the opcodes test pins the three `.php`
  lines the old `link` body hid.
- A new analyzer test holds the join of the two features: a value whose type
  parameter has a `foreign` bound, and a generic class's `foreign` type
  argument, are refused in a static, and a bound that is no `foreign` class
  is not.

ext/sharp/
  sharp.c                      type texts kept, Environment from master
  sharp_arginfo.h              regenerated from the merged stub
sharp/mago/crates/
  syntax/src/cst/cst/class_like/method.rs     `on` lives in the arena
  syntax/src/parser/internal/class_like/method.rs   allocates it
  syntax/src/parser/internal/statement.rs     internal or foreign, one return path
  names/src/binding.rs         both imports, `on` read as it is
  analyzer/src/resolver/property.rs           plain PHP method values infer
  analyzer/src/statement/class_like/listener.rs     `on` read as it is
  analyzer/src/expression/call/method_call.rs       both imports
  semantics/src/internal/checker/sharp.rs     an enum's `ClassLike` has both fields
  sharp-bridge/src/lower.rs    static_type_text kept, master's class_flags doc
  orchestrator/src/service/incremental_analysis/compile.rs   both tests kept whole
  analyzer/tests/sharp.rs      foreign behind a type parameter or argument
  syntax/tests/sharp.rs        `on` read as it is
Zend/tests/sharp/
  Generics.sharp, Generics.inc, TypeArguments.sharp   template strings
  opcodes.phpt                 three pinned `.php` lines
heyJordanParker added a commit that referenced this pull request Oct 14, 2026
Brings #110, #113, #115, #118, #121 and #126. Both sides keep their
behaviour:

- #115 wraps `trim` with the extension `string.trim()` through
  `[Replaces]`, which this branch retires for the checker's table. The
  table gains `trim -> Sharp.Text.Text.trim`, and the table's member
  form renders an extension member on the call's first argument, as
  #115's wrapper did: `name.trim()`, `name.trim(…)`, `name.trim`, and the
  class's import only where the file lacks the extension by default.
  `Sharp\Replaces` leaves the default class names. #115's tests move to
  the table row.
- Every PHP# source master adds calls plain PHP through `global.`: the
  library's Environment and Text extension, Accessors.sharp,
  Constructors.sharp, the test fixtures, and the slice notes.
- The import check keeps #115's reference to an imported class, so its
  extensions reach the file.
- Issue codes hold both sides': bare-function-call and function-import
  beside the effect and module codes.
- §29 pure-interface joins sharp/baseline/spec again: this branch's
  example writes through `Files`, which ships with the effect classes.
@heyJordanParker
heyJordanParker deleted the fix/warm-compile-panic branch November 3, 2026 22:08
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