Skip to content

§28: the engine refuses a file whose law or structure rule the checker refuses - #113

Merged
heyJordanParker merged 13 commits into
masterfrom
feat/slice-verification
Oct 13, 2026
Merged

heyJordanParker merged 13 commits into
masterfrom
feat/slice-verification

Conversation

@heyJordanParker

@heyJordanParker heyJordanParker commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Problem

The engine runs only what mago compile accepts. php-sharp pinned Mago at 625c278, from before section 28's laws and structure rules reached mago compile. A project on that pin never had its laws or structure rules checked. No engine test showed a refused law or a broken structure rule stopping a file from running.

Solution

Mago now lives in sharp/mago/, and #114 pulled it to mago-sharp 3cc39cc. That Mago checks laws and structure rules, and installs Lean itself when lake isn't on the PATH. This branch merges master, so it runs on that Mago and needs no pin of its own. Two engine tests run mago compile through sharp.compile_command, as the engine does for a user:

  • laws.phpt: Money runs while Lean proves addKeepsCurrency. Once Money.lean holds sorry, the engine refuses Money.sharp:
    CompileError: app/Shared/Money.sharp has 1 error:
    line 8: Law addKeepsCurrency is not proven: app/Shared/Money.lean line 4 is a gap (sorry). Write the proof there, or change the law.
    
  • structure_rules.phpt: once app/Shared/Module.lean gains .neverImports App.Tenant.Store, the engine refuses Ledger.sharp on its import line and still runs Receipts.sharp:
    CompileError: app/Shared/Ledger.sharp has 1 error:
    line 3: This import of App.Tenant.Store.Receipts breaks the structure rule sharedNeverReachesTenant in app/Shared/Module.lean.
    ran
    

The MACOS job has no lake on its PATH. With PATH=/usr/bin:/bin and an empty XDG_CACHE_HOME, both tests pass in 39 seconds while Mago installs elan and Lean into its cache. CI caches neither, because restoring 3 GB is no faster than the download. LINUX keeps the image's elan. Removing it changes sharp/docker/, a guarded folder, so it lands in a pull request of its own.

The spec examples, the list and the self-test are master's. #114 already moved the examples this Mago passes out of sharp/baseline/spec/, §28's three among them, and changed the self-test's refusal example. So this pull request changes no list entry.

Verification

On macOS, with master's engine and the mago built from master's sharp/mago/, run-tests.php on laws.phpt and structure_rules.phpt passes 2 of 2.

Files

Zend/tests/sharp/
├── laws.phpt                                 <- new: a proven law runs, a gap refuses
└── structure_rules.phpt                      <- new: a broken rule refuses the file at its import line
docs/architecture/slices/28-verification.md   <- new: the section 28 Slice note, its PRs and its decisions

Problem:
Spec section 28 promises module laws and structure rules that gate running,
and master builds neither. `module { law … }` in `Module.sharp` is 13 parse
errors, and `mago compile` never reads a `Module.lean`, so code that breaks a
structure rule compiles and runs. The builders of the Slice need one approved
design to build its 5 PRs against.

Solution:
The note records every rule of sections 28 and 28.1 with its observed state
and its mechanism, the parts of `spike/lean-structure` and
`upstream/feat/language-server` it reuses, how Lean reaches a user's machine,
the public names it adds, and the 5 PRs in order. team-lead's rulings sit
under its decisions: decision 7's spec line waits for Jordan, a broken module
law refuses `Module.sharp`, the empty `.sharpc` facts section stays for now,
and a `Module.lean` that Lean rejects refuses every `.sharp` file of its
namespace, naming Lean's first error.

docs/architecture/slices/
└── 28-verification.md  <- added: the approved design of slice 28, with its rulings
Problem

Decision 5's platform line said that on Alpine missing-lean names the platform
and the install command. elan-init.sh refuses musl hosts, and Lean has no musl
build, so that command fails there. The static musl binary of Mago also runs on
glibc Linux, where Lean works, so a message about the host would be false too.

Solution

The line now says what mago-sharp #167 ships: with no lake on the PATH, the
musl build's missing-lean says this musl build of Mago can't install Lean,
because Lean has no musl build, and to put a lake on the PATH or use Mago's
glibc Linux build. A source build for any other target with no pinned elan
names its OS and architecture and never claims Lean has no build for it.

Files

docs/architecture/slices/
└── 28-verification.md   <- "Lean on a user's machine", the Platforms line
Problem

The Platforms line said the musl build's missing-lean tells the user to put a
lake on the PATH or use Mago's glibc Linux build. On Alpine neither works:
Mago's glibc build and Lean's glibc build do not start, and elan-init.sh
refuses the host.

Solution

The line now quotes what mago-sharp #167 ships: the musl text keeps the two
sentences true on every host and states the glibc remedy as a fact about glibc
Linux, and any other build without a pinned elan names its OS and architecture
and gives no advice.

Files

docs/architecture/slices/
└── 28-verification.md   <- "Lean on a user's machine", the Platforms line
…n issue

Problem: the §28 note drew the structure-rule API with String namespaces, quoted names in its
examples, and a ruling that a rejected Module.lean reports only Lean's first error. mago-sharp's
structure-rule-names PR changes all three: a rule names a namespace by its bare full name, Lean
resolves it against a generated Sharp.Namespace constant, and each Lean error is its own issue.

Solution: the note records Jordan's round 4 ruling, draws the rule API with Sharp.Namespace and
under, writes every example rule with bare names, and adds the public names that carry it:
Sharp.Namespace and elabNamespaceName in Facts.lean, the generated module Code from package.rs,
Lean::check(translations, namespaces), compile's namespaces, and .sharp/.lean/Code.lean in the
user's project. The ruling on a rejected Module.lean now reads "each Lean error is its own issue,
at its line and column".

docs/architecture/slices/28-verification.md
    <- Rulings: each Lean error is its own issue; namespaces are bare names
    <- Public names: Sharp.Namespace, under, elabNamespaceName, package.rs namespaces(),
       Lean::check(translations, namespaces), compile(stamp, rules, check), .sharp/.lean/Code.lean
    <- rule API diff, spec change and broken-rule walk-through use bare names
…espace's constructor private

Problem: mago-sharp #171's second round changes three things the §28 note describes. A rule can name a namespace
of plain PHP, in the project or `vendor/`. A `Namespace` built from a string compiled and never fired. A `@[rule]`
added to a Lean file no `.sharp` file reaches was not checked until something else went stale.

Solution: the note's rulings record team-lead's reversal of "namespaces taken from every PHP# class", the private
constructor with `namespace_decl`, the rules check that runs again when a Lean file it builds changes, and Lean's
whole message on a rejected `Module.lean`. The public names, the rule API diff and the flow follow.

docs/architecture/slices/28-verification.md   <- rulings; Facts.lean, package.rs, lean.rs and compile.rs names;
                                                 Code.lean as namespace_decl lines; checked-rules; the flow
Problem: the note said no public function turns a String into a Namespace, but Rule.breaks is public, and unsafeCast,
an axiom cast or an elaborator naming the private constructor made one too. It also showed Code as one namespace_decl
per namespace, which mago-sharp #171 replaced with one command.

Solution: a ruling records that the runner refuses a rule reaching Sharp.Namespace.mk, Sharp.Rule.breaks, an unsafe
constant, implemented_by or extern, sorry, or a non-standard axiom, as one broken-rule issue on every file the rule's
Module.lean judges. The public names, the API diff and the flow show the walk and the single namespace_decl command.

docs/architecture/slices/28-verification.md   <- Rulings: the kernel-checked ruling; Public names: Runner.lean,
                                                 rules.rs, runner.rs, package.rs, Code.lean; the namespace_decl
                                                 diff; Rule.breaks is refused; the flow's runner step
Problem: the note said the walk stops at Lean's, the runtime library's and Code's modules, and said nothing of which
PSR-4 folders link into the package. mago-sharp #171 round 4 found the two disagreed: a Code\Evil\ folder linked and
its Lean files were trusted.

Solution: a ruling records the one list of roots Lean and Mago own (Init, Lean, Std, Lake, Code, Sharp), which the
runner trusts and no PSR-4 folder links, and the true message a Lean file in such a folder gets. The public names gain
ownedRoots, OWNED_ROOTS and Unbuilt.

docs/architecture/slices/28-verification.md   <- Rulings: the kernel-checked ruling's walk, the owned-roots ruling;
                                                 Public names: Runner.lean, rules.rs, package.rs
…er refuses

Problem: the engine runs only what `mago compile` accepts, but php-sharp pinned Mago at 625c278, from before section
28's laws and structure rules reached `mago compile`. Nothing in the engine's tests showed a refused law or a broken
structure rule stopping a file from running, and a project on the pinned Mago never had its laws or rules checked.

Solution: pin Mago at b9ffc3c, which checks laws and structure rules and installs Lean
itself when `lake` isn't on the PATH. Two engine tests run `mago compile` through `sharp.compile_command`:

- laws.phpt: `Money` runs while Lean proves `addKeepsCurrency`. Once `Money.lean` holds `sorry`, the engine refuses
  `Money.sharp` with "line 8: Law addKeepsCurrency is not proven: app/Shared/Money.lean line 4 is a gap (sorry)."
- structure_rules.phpt: once `app/Shared/Module.lean` gains `.neverImports App.Tenant.Store`, the engine refuses
  `Ledger.sharp` on its import line, naming the rule, and still runs `Receipts.sharp`.

With no `lake` on the PATH and an empty Mago cache, as on the MACOS job, both pass in 39 seconds while Mago installs
elan and Lean. The pin also passes nine spec examples, which leave sharp/baseline/spec: section 9.1's
constructor-call-this, named-constructors, set-once and super-call, section 12's collection-read-methods and
index-rules, and section 15's extern-event, extern-event-effects and standalone-event.

ext/sharp/sharp_unit.h                        <- SHARP_MAGO_COMMIT b9ffc3c
Zend/tests/sharp/
├── laws.phpt                                 <- new: a proven law runs, a gap refuses
└── structure_rules.phpt                      <- new: a broken rule refuses the file at its import line
sharp/baseline/spec                           <- nine examples that pass now leave the list
docs/architecture/slices/28-verification.md   <- PR 5: no Lean cache in CI, elan leaves the image in its own PR
…uses as not supported yet

Problem: the `refusal` example of sharp/spec-self-test.md shows that a "not supported yet" refusal never satisfies a
`compile error` line, with `if (true) return;`. Mago c09f4f5 accepts that guard clause, so at the pinned Mago
b9ffc3c the checker accepts the line and `sharp/bin/spec --self-test` fails:
"reported, and not expected: line 1 expects a compile error, and the checker accepts it".

Solution: the example writes `public int|string|null find() => 1;`, which the pinned Mago refuses with "This union that
holds null is not supported yet in PHP#.", the refusal section 24's nullable-unions example also meets. 17 of 17
self-test examples give the problems they expect.

sharp/spec-self-test.md   <- refusal: a null union member instead of the guard clause
…tion

# Conflicts:
#	ext/sharp/sharp_unit.h
#	sharp/baseline/spec~HEAD
#	sharp/spec-self-test.md
@heyJordanParker
heyJordanParker merged commit 5d5724a into master Oct 13, 2026
20 checks passed
heyJordanParker added a commit that referenced this pull request Oct 13, 2026
Master brings #110 (constructors) and #113 (verification). Both add
engine tests, fixtures and slice notes, and neither changes the engine
or `sharp/mago/`. Nothing conflicted. Their three new tests and
`opcodes.phpt`, which reads #110's new fixture, pass on this slice.
heyJordanParker added a commit that referenced this pull request Oct 13, 2026
Problem

Master gained #110 (constructors), #113 (the verification slice) and #115 (extensions). Four Mago files conflicted
with this branch's modules, and the bridge's extension members called `attributes` and `parameter` without the
service argument this branch added. The analyzer tests also declared `STANDARD_LIBRARY` twice.

Solution

Each conflict keeps both sides: the codebase keeps its modules and its extensions, and merges and removes each of
them. The warm path reanalyzes when modules or extensions change, and when a namespace's classes change. A compiled
file lists its namespace's class files and folder files, and its module files. The semantics checker keeps both
`unreachable!` notes. An extension member is no service the container fills, so its attributes and parameters pass
`None`.

```text
sharp/mago/crates/
├── codex/src/metadata/mod.rs                         modules and extensions, both merged and removed
├── orchestrator/src/service/incremental_analysis.rs  modules, extensions and namespace classes each reanalyze
├── orchestrator/src/service/incremental_analysis/compile.rs   namespace files and module files both inputs
├── semantics/src/internal/checker/sharp.rs           the module and extension notes both unreachable
├── sharp-bridge/src/lower.rs                         an extension member's attributes and parameters take no service
└── analyzer/tests/sharp.rs                           one STANDARD_LIBRARY
```
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 feat/slice-verification 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