Skip to content

fix(env): a program's and a module's frame is a tree; pin x-lang v0.46.0 - #228

Merged
jonruttan merged 1 commit into
mainfrom
fix/module-frame-is-a-tree
Nov 5, 2026
Merged

jonruttan merged 1 commit into
mainfrom
fix/module-frame-is-a-tree

Conversation

@jonruttan

Copy link
Copy Markdown
Owner

specs @ x-lang main went red on main on 2026-11-04: nearly every case got Error: first: () has no first.

Cause. x-lang#1154 (c718db01, shipped in v0.46.0) moved the engine to x-engine-c v0.2.26. That engine keeps a tree behind an environment whose spine the language made with pair, and law 10 in docs/engine-laws.md was rewritten to say so. A program's environment and a module's are made that way here ((pair () genv)). The runtime walked those frames as lists of cells, so a lookup ran off a tree node into first of (). And python-module-new handed pair a list of cells, which the engine then read as a tree.

Bisected locally with an x-python worktree on x-lang main (d64c3da6, the commit CI built):

  • main: 08-lists fails 8 of 19
  • #1157 (f2a1706e) reverted: still fails 8 of 19
  • #1157 and #1154 reverted (engine v0.2.25): passes 19 of 19

x-lang changed the law on purpose and released it, so the fix is here.

Change.

  • %py-env-tree? tells the two kinds apart the way law 10 does: the root, or pair?.
  • %py-env-cell and %py-env-rows now take the environment and walk either a tree or a list. A cell found in a tree is the live one, so a global or nonlocal assignment through it still rebinds the name.
  • A module the runtime writes starts empty and its names are bound with def.
  • lang.xon and the CI matrix move to v0.46.0.

Small known cost: a module's rows (%py-mod-rows) now come out in the frame's tree order, not the order they were bound. No spec depends on that order.

Verification (specs.sh on v0.46.0):

  • New tests/specs/C0-env-frames.spec.md: 3 of 3 fail with main's runtime-flow.x, and 3 of 3 pass with this change.
  • The other 127 spec files all pass.

🤖 Generated with Claude Code

x-lang v0.46.0 (x-lang#1154, x-engine-c v0.2.26) keeps a tree behind an
environment whose spine the language made with pair, as a program's and a
module's are here, where it kept a list of cells; law 10 says so.  The
runtime walked those frames as lists, so a lookup ran off a node into
`first: () has no first`, and python-module-new handed pair a list of cells
the engine then read as a tree.

%py-env-tree? tells the two apart as law 10 does (the root, or pair?), and
%py-env-cell and %py-env-rows take the environment and walk either.  A
cell found in a tree is the live one, so an assignment through it still
rebinds the name.  A module the runtime writes is made empty and bound with
def.

Spec: tests/specs/C0-env-frames.spec.md reads and rebinds a program's and a module's
frame; on v0.46.0 its three cases fail before this change and pass after.
The other 127 spec files pass on v0.46.0 too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonruttan
jonruttan merged commit 27cb5d7 into main Nov 5, 2026
12 checks passed
@jonruttan
jonruttan deleted the fix/module-frame-is-a-tree branch November 10, 2026 00:03
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