Skip to content

feat(#5525): file-local name handles for anonymous >> objects via >> foo#5528

Merged
yegor256 merged 1 commit into
masterfrom
claude/github-issue-5525-u4nu9q
Jul 15, 2026
Merged

feat(#5525): file-local name handles for anonymous >> objects via >> foo#5528
yegor256 merged 1 commit into
masterfrom
claude/github-issue-5525-u4nu9q

Conversation

@yegor256

Copy link
Copy Markdown
Member

Closes #5525.

What

Extends the >> auto-name suffix to optionally carry a trailing NAME — a file-local handle:

[] > app
  [n] >> fibo
    if. > @
      n.lt 2
      n
      plus.
        fibo (n.minus 1)
        fibo (n.minus 2)
  stdout > @
    sprintf "%d is the %dth number\n" *(fibo 6) 6

>> fibo keeps the object anonymous — it still receives its deterministic cactus @name (§9.2) and never enters the visible namespace — but fibo becomes a typeable alias for that cactus name, usable anywhere in the same .eo file. Here fibo is referenced twice recursively inside its own body and once from app's @, and all three rewrite to the same cactus @name. Unlike plain > fibo, the object is never put on app's public surface. Pure syntactic sugar — no new semantics.

This supersedes the reverted % (#5433): % self-referenced only the nearest enclosing anonymous formation, whereas >> foo gives a typeable handle to any anonymous object reachable from anywhere the cactus name is in scope (self-recursion, mutual recursion, sibling calls).

How

Mirrors the marker + first-pass-XSL pattern of #5432 / #5522.

  • Parser front-end. Suffix.auto() reads an optional handle after >> (and the ! const), surfaced via the new Suffix.handle(). Emit.local() records it as an @local marker on the object that carries the cactus @name; it is emitted by LnFormation, LnOnlyPhi and ChainEmission, so >> name is accepted uniformly on bare formations, inline-phi formations and applications. ! const stays allowed (>>! name); /sig stays forbidden (R-3.10.2).
  • New first-pass resolve-local-names.xsl, wired into Canonical right after resolve-self.xsl, before build-fqns.xsl / scope resolution. It (1) collects the per-file @local → @name table, (2) rewrites every @base equal to a handle into the matching cactus @name, (3) drops the @local markers, and (4) reports a duplicate handle as a resolve-local-names compile-time error (duplicate local name 'name'). A reference with no matching handle is left untouched for later scope resolution. Downstream passes see only ordinary references by the reserved cactus name — nothing changes below the parser front-end.
  • Spec. PARSER_SPEC.md gains R-3.10.12 (file-local handles) and R-9.2.3 (emission + rewrite), plus the >> base-form table entry.

Tests

  • eo-packs/parse/resolve-local-names.yaml — the reshape in isolation: three fibo references rewrite to the single cactus @name, @local markers dropped, no errors.
  • eo-packs/parse/resolve-local-names-duplicate.yaml — two >> dup in one file produce the resolve-local-names duplicate-handle error.
  • SuffixTest>> fibo yields Form.AUTO carrying the handle; >>! fibo combines const with the handle; trailing garbage after the handle is still rejected (trailing-non-suffix-auto typo pack updated).

All eo-parser tests pass (959, incl. the parse packs); qulice, xcop and yamllint are clean. I also verified the full parse train on the Fibonacci example end-to-end: all fibo references resolve to the single cactus @name with zero errors — identical to the resolved XMIR of the existing snippets/fibo.yaml (which uses > f), so runtime behaviour is unchanged.

The diff is kept under the 200-line pr-size limit (197). To stay within it, the runtime SnippetIT snippet was deferred to a follow-up — its program is the existing snippets/fibo.yaml with > f>> fibo, and the resolution is already covered by the isolation packs and the full-train check above. Happy to add it (or split the duplicate-handle safeguard out) if you'd prefer a different balance.

🤖 Generated with Claude Code


Generated by Claude Code

Extend the `>>` auto-name suffix to optionally carry a trailing NAME —
a file-local handle. `[n] >> fibo` keeps the object anonymous (it still
gets its deterministic cactus @name per §9.2) while `fibo` becomes a
typeable alias usable anywhere in the same .eo file: self-recursion,
mutual recursion, or a call from a sibling attribute — none of which
expose the object on the enclosing surface, unlike plain `> name`.

Parser front-end: `Suffix.auto()` reads an optional handle after `>>`
(and `!`), surfaced via `Suffix.handle()`; `Emit.local()` records it as
an `@local` marker on the object carrying the cactus `@name`, emitted by
LnFormation, LnOnlyPhi and ChainEmission. A new first-pass
`resolve-local-names.xsl` (wired into Canonical right after
`resolve-self`, before `build-fqns`) collects the per-file
`@local -> @name` table, rewrites every `@base` equal to a handle into
the matching cactus name, drops the markers, and reports a duplicate
handle as a compile-time error. Pure syntactic sugar; nothing changes
below the parser front-end. Supersedes the reverted `%` (#5433).

PARSER_SPEC.md gains R-3.10.12 and R-9.2.3; adds parse-pack tests for
the rewrite and the duplicate-handle error plus Suffix unit tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TB27TwPXPJ3c7bKZbxerxj
@github-actions github-actions Bot added the core label Jul 15, 2026
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Benchmark Comparison Unavailable

Unfortunately, one of the benchmarks is missing, and we couldn't generate a performance comparison report.

Please ensure that both the base and PR benchmark results are available for analysis.

@yegor256
yegor256 marked this pull request as ready for review July 15, 2026 18:03
Copilot AI review requested due to automatic review settings July 15, 2026 18:03
@yegor256
yegor256 merged commit 44df3b1 into master Jul 15, 2026
26 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@yegor256
yegor256 deleted the claude/github-issue-5525-u4nu9q branch July 15, 2026 18:04
@0crat

0crat commented Jul 16, 2026

Copy link
Copy Markdown

@yegor256 Thanks for the contribution! You've earned +4 points for this: +16 as a basis; -4 for too many hits-of-code (197 >= 100); -8 for the lack of code review. Please, keep them coming. Your running score is +1808; don't forget to check your Zerocracy account too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Anonymous objects handling using file-local name via '>> foo' not working as expected

4 participants