Repository navigation
Run section 9's constructors and init on the engine - #110
Conversation
Problem: Section 9 is the fourth most-hit gap to v1. A subclass cannot feed its parent: `: super(row)` is four generic parse errors, and a subclass constructor without it compiles and never runs the parent's constructor. Named constructors are refused. The spec's own guard clause, `if (!tenant.active) throw new InactiveTenant(tenant);`, is refused as a statement without braces. `lazy`, a computed parameter and a second constructor get generic parse errors or PHP's duplicate-method message. Solution: The note records every rule of section 9 with its observed state and its mechanism, the public names the Slice adds, and the PR order: three mago-sharp PRs and one php-sharp PR. Its Rulings section holds the interim refusals for the four open questions, so the Slice refuses instead of guessing until the Architect answers them. docs/architecture/slices/ └── 09-constructors.md <- added: section 9's design, rulings and PR order
Problem: The section 9 design note said the Slice adds no parse error variant and uses "the existing generic error with a message". No such error exists: the generic parse error prints "Parse error encountered during parsing", and every PHP# parse error with its own message has its own variant. team-lead approved two variants, and PR 1 adds ModifierKind::Lazy to the HIR, which the tree did not list. Solution: The public names tree lists ParseError::ComputedParameterInSharp (PR 1), ParseError::ConstructorInitializerInSharp (PR 2) and ModifierKind::Lazy, and the "Not added" line names both variants and their precedent. docs/architecture/slices/ └── 09-constructors.md <- the two parse error variants and ModifierKind::Lazy
Problem: The note gave the computed-parameter and `lazy` errors as "A constructor parameter cannot be …". The parser and check_slice raise both on every PHP# parameter, method and lambda parameters included, so the text was false where it fired. The note also did not say that `lazy` stays a name before `(`, `)`, `,` or `=`. Solution: - The computed-parameter error reads "A parameter cannot be a computed property: a computed property has no incoming value to receive.", at the `=>`, team-lead's ruling on #155's review. - The `lazy` error reads "A parameter cannot be `lazy`: …", as PR 1 builds it. A parameter with only `lazy` is no promoted property, and `(lazy) => lazy` keeps compiling. docs/architecture/slices/ └── 09-constructors.md <- the two parameter errors, under "`lazy`, computed properties and `static`"
Problem: decision 3 put the name of `new Artifact.fromJson(…)` on an `Instantiation.constructor` field the parser fills. The parser cannot fill it: `new Order.Paid(…)` (a nested event, section 15) and `new Artifact.fromJson(…)` (a named constructor) read the same, and only the class's declaration, possibly in another file, tells them apart. Solution: both parse as a plain `Instantiation` of the dotted name, the binder resolves it to `App\X\Y`, and the analyzer's `new` path creates the type `App\X\Y` when one exists and calls the named constructor `Y` of `X` otherwise, recording that static method as the call target. The bridge, the effects check and the Lean translation read the record. The PR that lands second adds the clash error with its test. docs/architecture/slices/09-constructors.md ├── Decisions, 3 <- the dotted parse and the analyzer's decision ├── Rulings <- team-lead's replacement of the field, the clash error ├── 9.1 mechanism <- parser, names, analyzer and bridge bullets ├── public names tree <- ConstructorName and Node::ConstructorName dropped, │ the dotted parse, Types::named_constructor added └── PR 3 <- the dotted `new` parse instead of ConstructorName
Problem: fe209c4 moved decision 3's choice behind `new X.Y(…)` to the analyzer, so that `new Order.Paid(…)` could create a nested type. The Architect ruled that nothing nests, and section 23 makes `.` in code always member access, so the parser can tell `new Artifact.fromJson(…)` calls a named constructor. Solution: decision 3 is back to the parser's `Instantiation.constructor` field, with section 23 as its reason. The analyzer's type-first decision, the clash error and `Types::named_constructor` leave the note. docs/architecture/slices/09-constructors.md ├── Decisions, 3 <- `Instantiation.constructor`, and the section 23 reason ├── Rulings <- the replacement and the clash error removed ├── 9.1 mechanism <- parser, names, analyzer and bridge bullets as before ├── public names tree <- ConstructorName and Node::ConstructorName back └── PR 3 <- ConstructorName back
Problem: the note listed `init` among the accessors section 9 leaves "not supported yet", so a named constructor could not set the `init` properties section 9.1 names, and the note did not say where the object initializer and `with` set them. Solution: PR 5 builds `init` whole, with C#'s write rule and the `protected(set)` lowering, and states the plain PHP subclass boundary. The object initializer (section 16) and `with` (section 10) set `init` properties in their own Slices. docs/architecture/slices/09-constructors.md <- 9.1: the `init` write rule, the get-only help, sections 16 and 10 <- public names: PropertyHookList::setter, MetadataFlags::INIT <- PRs: PR 5, `init` <- refused list: `init` leaves it
Problem: the engine ran no test of section 9. `: super(…)`, named constructors and `init` compiled in mago-sharp, but nothing showed the engine running them, a plain PHP caller using them, or reflection seeing them. The pinned Mago commit predated all three, so the section 9.1 spec examples still sat in sharp/baseline/spec. The constructors note still held the open questions the Architect has since ruled on. Solution: pin Mago to master c3a2b5a, which holds `: super(…)`, named constructors and `init`. constructors.phpt runs each section 9 rule from PHP and checks what reflection shows. The four section 9.1 examples pass and leave the baseline, as do five examples from other sections that the new pin fixes. The note records the Architect's rulings: `: super(…)` always written, a get-only property set once, braces always, and `this` refused in `: super(…)`. docs/architecture/slices/09-constructors.md the rulings replace the open questions; decisions 2, 6 and 7, the lowering and the PR 4 line match them ext/sharp/sharp_unit.h SHARP_MAGO_COMMIT moves to c3a2b5a sharp/baseline/spec §9.1 constructor-call-this, named-constructors, set-once and super-call pass; so do §12 collection-read-methods and index-rules, and §15 extern-event, extern-event-effects and standalone-event Zend/tests/sharp/ ├── Constructors.sharp SalesReport, Artifact with fromJson, the braced guard clause, Label with an `init` property ├── Constructors.inc the plain PHP subclasses LegacyArtifact and LegacyLabel ├── constructors.phpt every row, run from plain PHP, plus reflection of Artifact └── harness/Report.inc the plain PHP base class SalesReport extends
Problem: in Zend/tests/sharp a capitalized Name.inc is the opcode twin of Name.sharp, which opcodes.phpt compares. Constructors.inc is not a twin: it holds the plain PHP subclasses constructors.phpt uses. Its name claimed a role it doesn't have. Solution: rename it constructors.inc, as property_override.inc names the plain PHP side of its test. Zend/tests/sharp/ ├── constructors.inc renamed from Constructors.inc └── constructors.phpt requires constructors.inc docs/architecture/slices/09-constructors.md the names tree and the PR 4 line use the new name
|
Review verdict: CHANGES NEEDED Head
I built the engine ( Changes needed1.
|
Problem
Two rows of constructors.phpt passed whatever the code did. `Artifact` didn't
override `describe()`, so `super.describe()` in `Artifact.fromJson` printed the
same string as `this.describe()`, and a named constructor that dispatched
`super.m()` as `$this->m()` still passed. The `LegacyArtifact` row checked only
`get_class(new LegacyArtifact(…))`, which is `LegacyArtifact` for any
constructor that returns, so it passed when `Artifact`'s `: super(…)` passed the
wrong argument.
Solution
`Entity.describe` is virtual and `Artifact` overrides it, so `super.describe()`
must reach `Entity`'s. The `LegacyArtifact` row also reads `->manifest->name`
and `->name`, which `Artifact`'s main constructor and its `: super(…)` set.
Under `this.describe()`, the `fromJson` row prints "artifact tea". Under
`: super("")`, the `LegacyArtifact` row prints "".
Zend/tests/sharp/
├── Constructors.sharp Entity.describe is virtual, Artifact overrides it
└── constructors.phpt the LegacyArtifact row reads what the constructors set; line numbers follow
…tors # Conflicts: # ext/sharp/sharp_unit.h # sharp/baseline/spec~HEAD
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 ```
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.
Completes: §9.1
Problem
The engine ran no test of section 9. mago-sharp compiles
: super(…), named constructors (#161) andinit(#169). Nothing showed the engine running them, a plain PHP caller using them, or reflection seeing them.php-sharp still pinned Mago 625c278, which predates all three. So the four section 9.1 spec examples stayed in
sharp/baseline/spec. The constructors note still listed open questions that the Architect has since ruled on.Solution
Mago now lives in
sharp/mago/, and #114 pulled it to mago-sharp 3cc39cc, which holds: super(…), named constructors andinit. This branch merges master, so it runs on that Mago and needs no pin of its own.constructors.phptruns each row from plain PHP, three rounds so the JIT compiles each one, and passes in all four opcache modes:new SalesReport(1)runs the plain PHPReport's constructor through: super(id).Artifact::load()writesnew Artifact.fromJson(json)in PHP#, and plain PHP callsArtifact::fromJson($json). Both create equal objects, andsuper.describe()inside the named constructor runs on the new object ("entity tea").Artifactoverridesdescribe(), so asuper.m()dispatched as$this->m()prints"artifact tea"and fails the row.LegacyArtifact::fromJson('x')returns aDemo\Artifact.new LegacyArtifact(…)returns aDemo\LegacyArtifactwhosemanifest->nameandnameare whatArtifact's main constructor and its: super(…)set, so: super("")fails the row.Gate's constructor throwsInactiveTenantfor an inactive tenant and passes an active one.Label.shouting('hi')overwrites theinitpropertytextthat the main constructor set, andHIis read back.getConstructor()as__construct, with the promoted$manifestand a readonlymanifestproperty.getMethod('fromJson')is public, static and not a constructor, takesstring $json, returnsDemo\Artifactand carries theDemo\Retryattribute.A constructor without
: super(…)has no engine row. The checker refuses it withmissing-super-call, which mago-sharp's tests prove.The
initboundaryinitlowers toprotected(set). On the engine:$label->text = 'b'throwsError: Cannot modify protected(set) property Demo\Label::$text from global scope.LegacyLabel::rename('b')setstexttob, because PHP has no set visibility that ends when the object is created. This is the known boundary. The checker refuses the same write in a PHP# subclass.Guard 1
#114 already moved the four §9.1 examples,
constructor-call-this,named-constructors,set-onceandsuper-call, out ofsharp/baseline/spec/, with the Mago that runs them. So this pull request changes no list entry:sharp/bin/spec --base origin/masterreports "0 entries join sharp/baseline/spec, 0 leave it."sharp/bin/spec --completeson this body reports "§9.1: all 4 checked examples pass."Completes:names §9.1 only.§9 parameter-membersstill fails, because its example writesvia Tracked, andviawaits on section 6.4.sharp/bin/spec --completeswithCompletes: §9prints§9 still has 1 entries in sharp/baseline/spec: parameter-members.The note
The note's open questions become the "Rulings" section, with the Architect's answers:
: super(…)is always written.{ get; init; }.thisin: super(…)is refused (ruling 12).Decisions 2, 6 and 7, the named-constructor lowering (now a closure bound with
Closure::call), the PHP a plain caller sees, and the PR 1 and PR 4 lines change to match.Files
Verification
sharp/bin/test --opcache --repeat --passes Zend/tests/sharp/constructors.phptpasses in every mode, all 16 optimizer passes and both JITs included.sharp/bin/test --opcache --repeat --census --differential --spec: 173 of 173 tests pass in each mode, the census and differential pass, and the spec results equalsharp/baseline/spec.sharp/bin/test --passes: 173 of 173 under each optimizer pass alone and both JITs.sharp/bin/test --census --differential --specon macOS: 174 of 174 tests pass, the census and differential pass, 17 of 17 self-test examples, and the spec run matchessharp/baseline/spec/.