Skip to content

Commit

Permalink
fix: ignore calls to Intrinsic::AsWitness during brillig codegen (n…
Browse files Browse the repository at this point in the history
…oir-lang#5350)

# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

This PR addresses an issue where if a call is made to `std::as_witness`
from a brillig runtime then the compiler will panic with the unreachable
error directly below where the new match arm is added.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Jun 28, 2024
1 parent 758a905 commit 9c11fd2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ impl<'block> BrilligBlock<'block> {
1,
);
}

// `Intrinsic::AsWitness` is used to provide hints to acir-gen on optimal expression splitting.
// It is then useless in the brillig runtime and so we can ignore it
Value::Intrinsic(Intrinsic::AsWitness) => (),

_ => {
unreachable!("unsupported function call type {:?}", dfg[*func])
}
Expand Down
6 changes: 6 additions & 0 deletions test_programs/execution_success/as_witness/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "as_witness"
type = "bin"
authors = [""]

[dependencies]
1 change: 1 addition & 0 deletions test_programs/execution_success/as_witness/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a = 42
5 changes: 5 additions & 0 deletions test_programs/execution_success/as_witness/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Simple example of checking where two arrays are different
fn main(a: Field) -> pub Field {
std::as_witness(a);
a
}

0 comments on commit 9c11fd2

Please sign in to comment.