Skip to content

Reuse one prepared frontend program for multiple emit outputs #775

Description

@LunaStev

Problem

Each Wave artifact emitter prepares the frontend again. Emitting AST, IR, bitcode, assembly and object for one source repeats tokenization five times, whereas object-only emission tokenizes once.

Starting points: src/cli.rs, src/runner.rs.

Reproduction and measurement

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 fun main() -> i32 { return 0; } as repro.wave, then run:

target/debug/wavec build repro.wave --emit=obj --debug-wave=tokens --out-dir /tmp/wave-emit-one > /tmp/wave-emit-one.log
target/debug/wavec build repro.wave --emit=ast,ir,bc,asm,obj --debug-wave=tokens --out-dir /tmp/wave-emit-many > /tmp/wave-emit-many.log
rg -c '===== Tokens =====' /tmp/wave-emit-one.log /tmp/wave-emit-many.log

One run of each command showed 1 versus 5 token-stream dumps. Source inspection confirms each emitter calls frontend preparation again. These are invocation counts, not a measured speedup.

Results

Object-only: 1 frontend token stream. Combined five-artifact emit: 5 token streams. Output generation itself succeeds.

Scope

Share one prepared frontend result per source/target/options combination across emitters. Keep LLVM module/pass mutation concerns separate; reusing typed HIR must not accidentally share mutable backend state or cross configuration boundaries.

Difficulty: hard.

Completion criteria

  • Prepare the frontend once for a combined emit request.
  • Preserve artifacts and diagnostics compared with separate emits.
  • Keep source identities/spans and target/options isolation intact.
  • Measure preparation counts and, if claimed, compilation time with repeatable runs.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedThe issue requires extra attention or help from others.needs testingIssues that require additional testing or verification.performanceIssues related to performance or optimization.refactorIssues that require code refactoring without changing functionality.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions