Repository navigation
feat: a .sharp file declares one type, named like the file, and a Position.current() default gives the caller's position - #152
Merged
Merged
Conversation
Section 27 holds on master except four gaps: one type per file is silently accepted, a Position.current() default is refused, preloading a Composer project crashes the engine in readModule, and <?php in a .sharp file gets a generic parse error. The note lists every rule line with its state on master, the mechanism that builds it, the code it reuses, and the files it changes. team-lead approved decisions 1 to 10. docs/architecture/slices/ └── 27-files.md new: section 27's rules, states, decisions and files
…ition.current() default gives the caller's position Spec section 27, PHP# files: - The checker refuses a second type in a .sharp file, "A `.sharp` file declares one type: move `X` to `X.sharp`.", and a type named unlike its file, case included, as in Java. An extern file and a module file hold no type. - `<?php` in a .sharp file is one parse error that names the fix. - As a parameter's default, `Position.current()` gives a PHP# call's own position: MetadataFlags::CALLER_POSITION marks the parameter, and Lowering::sharp_arguments passes `caller: new \Sharp\Position(…)` for each one a call leaves out. A call through a function value and a plain PHP caller get the position of the declaration. A default that reads one part of the position is an error. - The Composer plugin's class map lists a file only when it declares a type named like it. - \Sharp\Internal\testModule takes one class name. - Every test source declares one type per file. The engine fixtures are one folder each, loaded through fixture() in Zend/tests/sharp/harness/fixture.inc. - The spec's one-body-per-method and sub-interface-defaults examples write one block per file, and the section 27 baseline entries are gone.
Master's fixture changes go into the split files, one type per file:
Inheritance/Ranked.sharp, TypeArgumentsCalls/{Wrapped,Tally,Tallies,Fragile,Runs}.sharp,
the Structs fixture becomes the Structs folder, and #149's Orchard files move into
Orchard/. CALLER_POSITION moves to bit 62 beside master's RUNTIME_INITIAL_VALUE.
Master's new test sources split per type.
…o files of their own Section 27's one-type rule refused their one-file source. analyze_files_with_fixture analyzes several files as one project, and analyze_with_fixture is its one-file form.
…nd the file rules name their fixes - A named constructor, `: this(…)` and an extension call pass the caller's position, through one lookup, Types::sharp_method, which replaces sharp_constructor. A call that spreads a list passes it unless the list may fill the Position parameter. - Any parameter default computed from Position.current() is "Take the whole position". - The type named like its file is the file's own, and "or the type" is offered only for a name a type can take. - `<?`, `<?=` and `?>` are named PHP syntax errors, a leading byte order mark is skipped, and `partial` before a type says a class lives in one file. - The class map reads a type line that starts with attributes, and never an extern line. - The one-type check and the declaration check read the file's statements in one walk.
…'s position A bridge test runs Types::spread_can_fill for a List<string> spread and a List<Any> one. Only a List spreads into a call and a PHP# parameter has a type, so the function keeps no branch for either.
… checker and the bridge Each of the three kept its own copy of the Position.current() test, so they could disagree on which default takes the caller's position. ResolvedNames::is_current_position, beside static_call_class, replaces all three.
#145's NamesImports.sharp becomes the NamesImports folder, one type per file, which names_imports.inc requires for the request and for preloading. hir's comment names both new parse errors.
heyJordanParker
added a commit
that referenced
this pull request
Oct 16, 2026
Problem - #152, PHP# files, landed, and #136 conflicted with master in four files. - Both sides took bit 62 of MetadataFlags: #152's CALLER_POSITION and this branch's TAKES_ON_EFFECTS. Solution - codex/src/metadata/flags.rs keeps both flags. TAKES_ON_EFFECTS moves to bit 63, the last free bit, and the accessor and the flag test list cover both. - ext/sharp/sharp.c's container globals comment keeps #152's one class per test file and this branch's per-fiber scopes. - ext/sharp/sharp_arginfo.h is regenerated from the merged stub. Against master it adds runScoped and drops Container::scope, as before. - hir/src/lower/error/mod.rs names both `partial` before a type and a function parameter a method names in `uses`. - Every .sharp file this branch adds already declares one type, so no fixture splits. ext/sharp ├── sharp.c container globals comment └── sharp_arginfo.h regenerated sharp/mago/crates ├── codex/src/metadata/flags.rs TAKES_ON_EFFECTS at bit 63 └── hir/src/lower/error/mod.rs both comments
heyJordanParker
added a commit
that referenced
this pull request
Oct 16, 2026
Both sides keep their behaviour, with one mechanism where both built one: - Default names: master generates every class-like directly in Sharp into sharp_classes.rs, so the effect classes and ProcessResult come from it, and this branch's standard exceptions join that list. NAMED_EFFECTS, which #145 moved into mago_names, goes, as decision 1 deleted it: each effect is a class now. - `Error` always names Sharp.Error (spec section 31), so sharp/bin/builtins no longer declares PHP's engine Error, which PHP# code never names. - The bridge tests' library takes the effect classes on master's two-pass name resolution. Two master tests no longer pass ENVIRONMENT, which every analyzer test project holds through EFFECT_CLASSES. - The yield test loads its Import fixture folder and the effect classes. - Messages keep this branch's wording: echo names Console, a refused law says "A law cannot reason about…", an undeclared call names the class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completes: §27
A PHP# developer finds every type by its namespace and its file, and a
Position.current()default tells a method who called it. Section 27's two failing examples,one-type-per-fileandposition, now pass, and every rule line of the section holds in the checker, the bridge, the engine and the Composer plugin.docs/architecture/slices/27-files.mdlists each line with its state and mechanism.A
.sharpfile declares one type, named like the file.sharpfile declares one type: moveStoreHelpertoStoreHelper.sharp."Bill.sharpdeclaresInvoice: rename the fileInvoice.sharp, or the typeBill."Second.sharpholdingFirstthenSecond,Firstmoves.{name}" shows only when the file's name can name a type, sostore-helper.sharp,Order.Extra.sharpandinvoice.sharpget "rename the fileInvoice.sharp." alone.partialbefore a type is a compile error: "PHP# has no partial classes: a class lives in one file."externdeclaration file and aModule.sharpfile hold no type, so any name is theirs.[Attribute] public class Marker, and never on anexternline. Before, it listedSharp\Modulefor the standard library'sModule.sharp, a class for every misnamed file, nothing forMarker, andApp\Failedfor aFailed.sharpholdingextern event Failed;.\Sharp\Internal\testModuletakes one class name, since a test file's module now covers the one class its file declares.PHP tags in a
.sharpfile are named parse errors<?phpis PHP syntax: a.sharpfile has no opening tag, so delete it."<?gets the same,<?=gets "a.sharpfile has no tags, and writes output withglobal.printf", and?>gets "a.sharpfile has no closing tag, so delete it". The file parses on, so its other errors still show.List<?int>still gets "?before a type is PHP syntax", andList<int?>still parses.A
Position.current()default gives the caller's positionAs C++20's
std::source_location::current()and Swift's#filedefaults do.MetadataFlags::CALLER_POSITIONmarks the parameter, and each direct PHP# call that leaves it out passescaller: new \Sharp\Position(__FILE__, 12, 9, 'App.Reports.run'), the start of the call: a static or instance call,new, a named constructor,: this(…),: super(…), a generic call, an interface's default body and an extension call.Types::sharp_method(class, method)finds the callee of each, and replacessharp_constructor.Any default computed from
Position.current(), asPosition.current().line + 1, gets "Take the whole position". A plain PHP caller gets the position where the parameter is declared, which is what the default lowers to.Tests follow the rule
Every test source declares one type per file, with no exemption. The engine fixtures are one folder each, loaded through
fixture()inZend/tests/sharp/harness/fixture.inc, which maps each file by itsnamespaceline and its name, as the Composer plugin does. #143'sResults.sharpis theResults/folder. The spec'sone-body-per-methodandsub-interface-defaultswrite one block per file, and the two section 27 baseline entries are gone.Verification
sharp/bin/specgivesChecked 202 examples, ignored 1, and 9 fail, the 9 of master's baseline that this PR leaves, and exits 0.one-type-per-file,positionandfile-headerpass.sharp/bin/spec --self-testgives23 of 23 self-test examples give the problems they expect.a_sharp_file_declares_one_type,a_sharp_file_is_named_like_its_typeanda_sharp_file_without_a_type_takes_any_nameincrates/semantics/tests/sharp.rs.partial:an_opening_tag_is_a_php_syntax_error,every_php_tag_is_a_php_syntax_error,a_byte_order_mark_is_skippedanda_partial_type_is_an_errorincrates/syntax/tests/sharp.rs.position_current_as_a_parameter_default_is_the_callers_positionanda_default_computed_from_position_current_is_an_errorin semantics, the two position tests incrates/sharp-bridge/tests/lower.rs, andposition_caller.phpt, whose 14 rows cover each call form above.library_autoload.phptprints the class map the plugin writes, and loadsApp\Stamp, whose type line starts with an attribute.sharp/bin/test --opcache Zend/tests/sharppasses 300 of 300 in each of its 3 modes on macOS.position_caller.phpt,position_caller_preload.phpt,results.phpt,results_preload.phptand the library autoload tests pass in all 22 modes.position_callerpasses 200 runs andresults100 runs underUSE_ZEND_ALLOC=0 MallocScribble=1, each with and without preloading.cargo clippy --workspace --all-targets -D warningsandcargo fmt --checkare clean..sharpfile, and the analyzer's tests pass unchanged.