Skip to content

[ci] Two stale CIS_* layout comments in CiIR.w (DO_WHILE d2, VAR_DECL flags) #1022

Closed

Description

@eas4ai

AUDIT finding (read-only review at 450733e, verified against source).
Severity: Low (doc-only; producer/consumer agree, no behavioral impact).

Two enum comments in the CIS_* layout header disagree with the constructors
and printers:

  1. src/CiIR.w:451 — CIS_DO_WHILE = 6 // d0 = body_block, d1 = cond_expr
    omits d2, but do_while_stmt (:614-615) stores
    d2 = cond_setup, and the printer honors it on both paths
    (src/CiPrint.w:304-316 compact, :907-919 pretty, with cond_setup != 0
    guard). Fix: document d2 = cond_setup (0 if none).

  2. src/CiIR.w:456 — CIS_VAR_DECL = 11 // ...; flags in extra is wrong:
    var_decl (:618-624) packs is_mut/has_init into f and passes it as
    the flags argument to add, and the printer reads
    stmts.get_flags(id) (src/CiPrint.w:324-328, :1001-1005, :823-831).
    Flags live in the flags column, never extra. Fix: "flags in flags
    column (bit0=is_mut, bit1=has_init)".

Noted but NOT filed as defects: CiExprPool.set_type (:384-398) rebuilds
the whole types vec per call (O(n) + fresh allocation; live caller
src/CImport.w:6665) — perf-only observation, no incorrectness proven.

Activity

  1. ehartford commented on Sep 16, 2026

    @ehartford
    Contributor

    Review: reproduced

    Verdict. Both documentation claims are established against current main; the lines are unchanged since the reported revision 450733e. This is a comment-accuracy defect with no behavioral impact, as the report says, so source evidence is sufficient and no execution is needed: the producer and both printers agree with each other and disagree only with the header comment.

    Tested. main @ 5809ac1 (2026-09-14), source read; git log 450733e5..HEAD -- src/CiIR.w src/CiPrint.w shows only the byte_at/get mechanical sweep and unrelated edits, and both comment lines are byte-identical at 450733e.

    Claim 1, CIS_DO_WHILE omits d2. Confirmed.

    • Comment: src/CiIR.w:451 says d0 = body_block, d1 = cond_expr.
    • Constructor stores a third field: do_while_stmt(body, cond, cond_setup) calls self.add(CIS_DO_WHILE, body, cond, cond_setup, 0) (:614-615).
    • Both printers read it: let cond_setup = stmts.get_d2(id) at src/CiPrint.w:307 and :914.

    Claim 2, CIS_VAR_DECL "flags in extra" is wrong. Confirmed.

    • Comment: src/CiIR.w:456.
    • Constructor packs is_mut (bit 0) and has_init (bit 1) into f and passes it as the fifth argument of add (:617-624); add pushes that argument to st.flags, a column distinct from st.extra (the pool has separate add_extra/get_extra and get_flags accessors, :563-567).
    • Printers read stmts.get_flags(id) at src/CiPrint.w:328 and :1009. Nothing reads extra for a CIS_VAR_DECL.

    On the set_type note. Not a defect claim in the report and not assessed as one. For the record, CiExprPool.set_type does rebuild the whole types vector per call (src/CiIR.w:384-398); whether that matters is a profiling question, not a correctness one.

    Spec/decisions. None apply; CiIR.w is an internal IR whose layout header exists to keep AGENTS.md's "confirm AST layouts before editing" rule honest. A wrong layout comment is exactly the trap that rule warns about, which is why the fix is worth the two lines.

    Related PRs. None touch these comments.

    Recommendation. Fix, two-line doc change with no build impact. Acceptance criteria: line 451 reads d0 = body_block, d1 = cond_expr, d2 = cond_setup (0 if none); line 456 reads ...; flags column: bit0 = is_mut, bit1 = has_init and no longer mentions extra. Optional: a one-line CiIR self-check that asserts each CIS_* constructor's use of d2/flags/extra matches a table, so the header cannot drift again.

  2. ehartford commented on Oct 25, 2026

    @ehartford
    Contributor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced; both comments are unchanged. src/CiIR.w:528 says CIS_DO_WHILE = 6 // d0 = body_block, d1 = cond_expr while do_while_stmt (:696-697) stores cond_setup in d2. src/CiIR.w:533 still says "flags in extra" for CIS_VAR_DECL.

    post-release: comment-only, no behavior.

  3. added this to the post-v0.16.0 milestone on Oct 28, 2026
  4. ehartford commented on Nov 11, 2026

    @ehartford
    Contributor

    Merged to main ae20d89 (#3248): the two CIS_* layout comments in CiIR.w state d2 = cond_setup and the flags column.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions