diff --git a/src/arkham/analyser.nim b/src/arkham/analyser.nim index 69186d6..1ec8e95 100644 --- a/src/arkham/analyser.nim +++ b/src/arkham/analyser.nim @@ -523,6 +523,19 @@ proc analyse(c: var Context; n: var Cursor) = if frame.sawCall: c.loopStack[^1].sawCall = true for pnm in frame.usedParams: c.loopStack[^1].usedParams.incl pnm else: + when declared(ComesfromS): + if n.stmtKind == ComesfromS: + # `(comesfrom SYM S*)`: debug-info marker, walks like `stmts` but + # opens no scope frame. The leading child is the origin SYMBOL, not a + # statement, so `analyseChildren` would analyse it as a symbol *use* + # and record a read of the expanded routine at this position. + # + # Guarded so arkham still compiles against a nimony that predates the + # tag (nim-lang/nimony#2240); drop the `when` once that has merged. + n.into: + skip n # the origin symbol + while n.hasMore: analyse(c, n) + return analyseChildren(c, n) # if/case/ret/... : recurse else: inc n diff --git a/src/arkham/codegen_a64.nim b/src/arkham/codegen_a64.nim index 5f1af73..84489f1 100644 --- a/src/arkham/codegen_a64.nim +++ b/src/arkham/codegen_a64.nim @@ -4702,7 +4702,22 @@ proc genStmt2(g: var CodeGen; c: Cursor) = g.ovfReg2 = rB g.ovfBridges = @[rA, rB] while cc.hasMore: skip cc - else: raiseAssert "arkham a64n: genStmt2 " & $c.stmtKind + else: + when declared(ComesfromS): + if c.stmtKind == ComesfromS: + # `(comesfrom SYM S*)` — statements produced by expanding SYM (a + # template today). Debug-info only: no scope and no code of its own, so + # it behaves as `stmts` once the leading origin SYMBOL is stepped over. + # That first child is an operand, not a statement. + # + # Guarded so arkham still compiles against a nimony that predates the + # tag (nim-lang/nimony#2240); drop the `when` once that has merged. + var cc = c + cc.into: + skip cc # the origin symbol + while cc.hasMore: (g.genStmt2(cc); skip cc) + return + raiseAssert "arkham a64n: genStmt2 " & $c.stmtKind # ── proc emission / driver (pure-emit path) ────────────────────────────────── diff --git a/src/arkham/codegen_x64.nim b/src/arkham/codegen_x64.nim index 3f18fb9..9517b1e 100644 --- a/src/arkham/codegen_x64.nim +++ b/src/arkham/codegen_x64.nim @@ -4590,7 +4590,25 @@ proc genStmt2(g: var CodeGen; c: Cursor) = g.genStore2(opCur, memLoc(lhsCur, ScalarSlot)) g.noFoldPos = -1 while cc.hasMore: skip cc - else: raiseAssert "arkham x64n: genStmt2 " & $c.stmtKind + else: + when declared(ComesfromS): + if c.stmtKind == ComesfromS: + # `(comesfrom SYM S*)` — statements produced by expanding SYM (a + # template today). Debug-info only: no scope and no code of its own, so + # it behaves as `stmts` once the leading origin SYMBOL is stepped over. + # That first child is an operand, not a statement. + # + # Guarded so arkham still compiles against a nimony that predates the + # tag (nim-lang/nimony#2240); drop the `when` once that has merged. + var cc = c + cc.into: + skip cc # the origin symbol + while cc.hasMore: + var nx = cc; skip nx + g.tailStmt = myTail and not nx.hasMore + g.genStmt2(cc); skip cc + return + raiseAssert "arkham x64n: genStmt2 " & $c.stmtKind # ── fused value core: unconverted-proc stubs (die as each case lands) ──────── proc emitBin2(g: var CodeGen; c: Cursor; dest: var Location) = @@ -6838,6 +6856,19 @@ proc asmStmt(g: var CodeGen; c: Cursor) = g.retLabelUsed2 = true g.emJmp(g.retLabel2) else: + when declared(ComesfromS): + if c.stmtKind == ComesfromS: + # See `genStmt2`: transparent debug-info marker, first child is an + # operand. Guarded so arkham still compiles against a nimony that + # predates the tag (nim-lang/nimony#2240). + var cc = c + cc.into: + skip cc # the origin symbol + while cc.hasMore: + var nx = cc; skip nx + g.tailStmt = myTail and not nx.hasMore + g.asmStmt(cc); skip cc + return lengError c, "`" & $c.stmtKind & "` is not allowed in an `.assembler` proc", g.asmInfo proc genAsmProc(g: var CodeGen; info: ProcInfo) = diff --git a/src/arkham/register_allocator.nim b/src/arkham/register_allocator.nim index 6f38d1e..cb45c4e 100644 --- a/src/arkham/register_allocator.nim +++ b/src/arkham/register_allocator.nim @@ -527,6 +527,20 @@ proc walk(b: var Builder; n: var Cursor) = n.into: while n.hasMore: walk(b, n) else: + when declared(ComesfromS): + if n.stmtKind == ComesfromS: + # `(comesfrom SYM S*)`: debug-info marker, walks like `stmts`. The + # leading child is the origin SYMBOL, not a statement, so the generic + # recursion below would count it as a use of the expanded routine here. + # + # Guarded so arkham still compiles against a nimony that predates the + # tag (nim-lang/nimony#2240); drop the `when` once that has merged. + n.into: + skip n # the origin symbol + while n.hasMore: + walk(b, n) + flushFree(b, b.posOf(n)) + return if n.kind == TagLit: n.into: while n.hasMore: walk(b, n) # recurse (var decls may nest)