Skip to content

Refactor duplicate expect() calls in SPIR-V binary emitter #1

Description

@Apocky

Summary

cssl-cgen-gpu-spirv/src/binary_emit.rs has 7 near-identical .expect() calls:

let parsed = dr::load_words(&words).expect("rspirv must parse emitted binary");

These appear at lines ~394, 409, 442, 475, 499, 519, 539 — one per SPIR-V test case. They all do the same thing (round-trip the emitted binary through rspirv's parser) but give no context about which operation failed.

What to do

  1. Extract a helper function:
    fn roundtrip(words: &[u32], ctx: &str) -> dr::Module {
        dr::load_words(words).unwrap_or_else(|e| panic!("rspirv parse failed in {ctx}: {e}"))
    }
  2. Replace all 7 call sites with roundtrip(&words, "sphere_sdf_forward") etc.

Why this is a good first issue

  • Self-contained change in a single file
  • No type system or IR knowledge needed
  • Teaches the SPIR-V codegen crate layout
  • Improves debuggability when a future backend change breaks round-trip

Files

  • compiler-rs/crates/cssl-cgen-gpu-spirv/src/binary_emit.rs

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions