noir-ssa-tests

Write unit tests for SSA optimization passes in the Noir compiler's noirc_evaluator.

1.4k|408|Updated Aug 4, 2020
One-click install
npx skills add https://github.com/noir-lang/noir --skill noir-ssa-tests
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: noir-ssa-tests
Source: https://github.com/noir-lang/noir/tree/main/.claude/skills/noir-ssa-tests
Command: npx skills add https://github.com/noir-lang/noir --skill noir-ssa-tests

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing tests for SSA optimization passes in the Noir compiler often stops at snapshot assertions, which pin output shape but cannot catch miscompilations where the pass silently changes what the program computes. This Skill guides you to write tests that prove a pass preserves execution semantics, not just structure.

Core Features & Use Cases

  • Semantics-preserving assertions: Use assert_pass_does_not_affect_execution to interpret SSA before and after a pass and assert identical results, including failure behavior like which constraint fails.
  • Snapshot and no-op testing: Pin transformed SSA output with assert_ssa_snapshot!, or assert a pass leaves input untouched with assert_ssa_does_not_change.
  • Realistic test inputs: Generate real SSA from Noir programs via nargo compile --show-ssa-pass, build interpreter inputs with Value constructors, and handle path-sensitive bugs with one run per input.
  • Use Case: When fixing a loop-invariant-code-motion miscompilation, write a regression test that runs the interpreter on both control-flow paths, asserts the specific ConstrainEqFailed error is preserved, and snapshots the transformed SSA.

Quick Start

Ask the AI to write a regression test for an SSA pass in compiler/noirc_evaluator/src/ssa/opt/ that proves the pass preserves execution semantics and snapshots its output.

Frequently Asked Questions about noir-ssa-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a regression test for an SSA optimization pass in Noir?

Add a test in the inline mod tests at the bottom of the pass's file under compiler/noirc_evaluator/src/ssa/opt/. Parse textual SSA with Ssa::from_str, run the pass through assert_pass_does_not_affect_execution, then snapshot the result with assert_ssa_snapshot!.

Why is a snapshot test alone not enough for SSA passes?

A snapshot only pins the shape of the output SSA, so a miscompiling pass produces a stable, plausible snapshot that gets accepted. Pair snapshots with assert_pass_does_not_affect_execution, which interprets the SSA before and after the pass and asserts the results match.

How do I test that an SSA pass does not change a program?

Use assert_ssa_does_not_change(src, pass) for a one-line no-op test asserting the pass leaves the input completely alone. For comparing against an explicit expected string, use assert_normalized_ssa_equals instead.

How do I get realistic SSA input for a Noir compiler test?

Compile a real Noir program with cargo run -q -p nargo_cli -- compile --silence-warnings --force --show-ssa-pass <label> to capture actual SSA. The grammar is defined in compiler/noirc_evaluator/src/ssa/parser/, so grep existing tests when unsure about syntax.

When should I not use assert_pass_does_not_affect_execution?

Fall back to a snapshot-only test when the pass intentionally changes semantics, main calls a foreign function, the program exceeds the interpreter's step budget, or the pass only touches metadata the interpreter never observes. Document the reason in a comment.

Why does my SSA interpreter test give wrong results with cloned inputs?

A shallow clone shares an array's backing storage, so an in-place array_set in the first interpretation corrupts the second run's inputs. Use assert_pass_does_not_affect_execution, which deep-copies inputs via Value::snapshot_args for each run.