Skip to content

arkham: handle the comesfrom statement tag - #95

Closed
Redict wants to merge 1 commit into
nim-lang:masterfrom
Redict:fix-comesfrom-stmt
Closed

arkham: handle the comesfrom statement tag#95
Redict wants to merge 1 commit into
nim-lang:masterfrom
Redict:fix-comesfrom-stmt

Conversation

@Redict

@Redict Redict commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

nimony is gaining (comesfrom SYM S*) in nim-lang/nimony#2240 - a transparent wrapper marking statements produced by expanding SYM (a template today), so the debug backend can emit them as a DWARF inlined frame. It opens no scope and carries no semantics of its own.

Without this, every native test aborts:

arkham x64n: genStmt2 comesfrom [AssertionDefect]
0 / 67 native tests successful

Needs to land with (or before) that PR, since the tag reaches arkham as soon as it does.

The one thing to know

The wrapper's first child is the origin symbol, not a statement. Four passes walk statement children generically, and each has to step over it:

  • codegen_x64 genStmt2 / asmStmt, codegen_a64 genStmt2 - emit the body like stmts. Deliberately no enterScope, unlike ScopeS: the locals an expansion declares belong to the enclosing scope.
  • analyser - its generic analyseChildren fallback would analyse the leading symbol as a symbol use, recording a read of the expanded routine at this position.
  • register_allocator - same, and it would carry that phantom read into the live ranges.

The two analysis passes are the ones worth a second look. They accept the tag through a permissive else: without complaint, so a miss there is quiet - it shows up much later as a wrong allocation rather than an assertion. The same shape caused four separate regressions on the nimony side, each found by breakage in a different suite.

(pragmax pragmas body) already has this shape, which is why several passes here special-case it too.

Testing

arkham builds against the nimony branch that introduces the tag, and no genStmt2 comesfrom assertion remains. I could not run the native suite to completion - it targets Linux ELF and I am on Windows, where it fails earlier on ExitProcess. CI on the nimony PR is the real check.

nimony is gaining `(comesfrom SYM S*)` in nim-lang/nimony#2240: a transparent
wrapper marking statements produced by expanding SYM (a template today), so
the debug backend can emit them as a DWARF inlined frame. It opens no scope
and has no semantics of its own.

Without this every native test aborts with

    arkham x64n: genStmt2 comesfrom [AssertionDefect]

The wrapper's first child is the origin SYMBOL, not a statement, so the four
passes that walk statement children generically each step over it before
treating the rest as `stmts`:

- codegen_x64 genStmt2 / asmStmt, codegen_a64 genStmt2: emit the body, no
  `enterScope` (unlike `ScopeS` - the locals an expansion declares belong to
  the enclosing scope).
- analyser: the generic `analyseChildren` path would analyse the leading
  symbol as a symbol *use* and record a read of the expanded routine here.
- register_allocator: same, and it would carry that phantom read into the
  live ranges.

Each branch sits behind `when declared(ComesfromS)` so arkham compiles both
against a nimony that has the tag and one that does not. Without the guard the
two repos deadlock: this PR cannot build until #2240 merges, and #2240's
linux-amd64 job cannot pass until this one does. The guards can be dropped
once #2240 is in.
@Redict
Redict force-pushed the fix-comesfrom-stmt branch from 5467c74 to 38bc037 Compare August 4, 2026 13:40
@Redict

Redict commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

CI was red because this and nim-lang/nimony#2240 were waiting on each other. Both repos check out the other's master with no ref:, so:

  • this PR could not compile: analyser.nim(403, 8) Error: undeclared identifier: 'ComesfromS', since the tag only exists on the nimony PR branch
  • #2240's linux-amd64 could not pass: arkham master has no branch for the tag, so hastur native hit genStmt2 comesfrom [AssertionDefect]

Neither could go first. Now each branch sits behind when declared(ComesfromS), so arkham compiles against a nimony with the tag and one without.

Verified both ways against a clean checkout:

nimony arkham build
master (no tag) exit 0
#2240 branch (tag present) exit 0

Also checked the guard is really live rather than silently compiling out, since a when that is always false would look identical here: against the #2240 branch it resolves and reports ComesfromS = 349.

The whens should come out once #2240 merges. I left a note saying so at each of the five sites.

One thing worth flagging separately: tests/tester.nim fails on Windows on pristine master, before any of my changes, with [Error] Unknown type: Outer.0.mod_a in tests/module_chain.nif. Same failure with my commit stashed, so it is unrelated to this PR, but it means the Windows job is passing for a reason I could not reproduce locally.

@Araq Araq closed this Aug 5, 2026
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.

2 participants