Skip to content

Report constant dependency cycles during semantic validation #751

Closed

Description

@LunaStev

Problem

A cycle between typed global constants passes semantic checking and only fails during backend emission with an unresolved-cycle E9002. Valid forward references already work and must remain supported.

Starting points: front/parser/src/verification.rs, llvm/src/codegen/ir.rs.

Reproduction

Tested at 6257ba3eb4b9f1ab6c247a920c6e0c4b5d699331 on Linux amd64 with LLVM 21.1.8 and a compiler built from that checkout. Build it with LLVM_SYS_211_PREFIX=/usr/lib64/llvm21 cargo build --locked --jobs 2.

Save as repro.wave:

const A: i32 = B; const B: i32 = A; fun main() -> i32 { return A; }
target/debug/wavec check repro.wave
target/debug/wavec build repro.wave -O0 --emit=ir,bin --out-dir /tmp/wave-issue-O0
/tmp/wave-issue-O0/repro
target/debug/wavec build repro.wave -O2 --emit=ir,bin --out-dir /tmp/wave-issue-O2
/tmp/wave-issue-O2/repro

check exits 0. Both builds fail with E9002: unresolved const cycle or missing symbols after 1 rounds: ["A", "B"]. Replacing B's initializer with 4 makes the forward reference build and run successfully.

Scope

Detect self and mutual constant-dependency cycles in semantic validation and report their declaration/reference locations. This can be implemented independently of arithmetic constant evaluation.

Difficulty: medium.

Completion criteria

  • Reject self cycles and multi-node cycles, including imported declarations, with source diagnostics.
  • Keep noncyclic forward references and shared dependencies valid.
  • Test both human and JSON diagnostics and agreement between check/build.

Activity

  1. added
    bug
    help wanted
    needs testing
    on Sep 25, 2026
  2. self-assigned this
    on Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bughelp wantedneeds testing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions