Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add assert_eq keyword #2137

Merged
merged 59 commits into from
Aug 28, 2023
Merged

feat: Add assert_eq keyword #2137

merged 59 commits into from
Aug 28, 2023

Conversation

TomAFrench
Copy link
Member

@TomAFrench TomAFrench commented Aug 3, 2023

Description

Problem*

Resolves #2031
Resolves #1431

Summary*

This PR is an exploration of adding the built-in function assert_eq(lhs, rhs) which constains lhs == rhs. This is more efficient than assert(lhs == rhs) as laid out in #2031. It also allows proper usage of #1431 and can be modified in future to address #1995

There are a couple of blockers for this

  • assert() is still implemented as a keyword rather than another builtin function.
  • Instruction::Constrain should be replaced with a call to Intrinsic::AssertEq
  • assert_eq() needs to be explicitly imported from the stdlib before it can be used.

Documentation

  • This PR requires documentation updates when merged.

    • I will submit a noir-lang/docs PR.
    • I will request for and support Dev Rel's help in documenting this PR.

Additional Context

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@jfecher
Copy link
Contributor

jfecher commented Aug 3, 2023

assert_eq() needs to be explicitly imported from the stdlib before it can be used.

Why not make assert_eq a keyword as well?

@TomAFrench
Copy link
Member Author

I'm going off the conversation here where consensus seemed to change these to functions.

@TomAFrench TomAFrench force-pushed the assert-eq-builtin branch 3 times, most recently from 7ed59f0 to 0f5392f Compare August 11, 2023 06:14
@TomAFrench
Copy link
Member Author

TomAFrench commented Aug 16, 2023

This seems to be working now but a mutable reference to a closure which is performing acir-gen as it's being passed down recursively is pretty gross.

Failing constraints behind a if statement are still being applied Fixed now.

@TomAFrench TomAFrench changed the base branch from master to update-artifacts August 20, 2023 02:44
@TomAFrench TomAFrench force-pushed the assert-eq-builtin branch 2 times, most recently from 8a50ca6 to 3e50b54 Compare August 20, 2023 03:33
@TomAFrench TomAFrench changed the title feat: add assert_eq builtin function [do not merge] feat: Add assert_eq builtin function Aug 20, 2023
Base automatically changed from update-artifacts to master August 21, 2023 09:31
@TomAFrench
Copy link
Member Author

@jfecher I think this is at the point were we can start doing a proper review. I've got a separate branch which replaces Instruction::Constrain with a call to Intrinsic::AssertEq so lmk if you want that rolled into this PR.

@jfecher
Copy link
Contributor

jfecher commented Aug 21, 2023

@TomAFrench Since it seems like it's going to be a little while before we have an actual Prelude I'm fine with adding assert_eq as a keyword for now and demoting it to a function later once we have a prelude. Otherwise this PR will be blocked for a little while longer.

@TomAFrench
Copy link
Member Author

We could remove the assert_eq keyword after these changes now that assert(x == y) is equivalent and just have this PR affect SSA. I'm inclined to leave it in however.

jfecher
jfecher previously approved these changes Aug 28, 2023
Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jfecher jfecher enabled auto-merge August 28, 2023 16:37
@jfecher jfecher added this pull request to the merge queue Aug 28, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 28, 2023
@TomAFrench TomAFrench added this pull request to the merge queue Aug 28, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Aug 28, 2023
* master:
  feat(ssa): Reuse existing results for duplicated instructions with no side-effects (#2460)
  fix: Closure lvalue capture bugfix (#2457)
  feat: Syntax for environment types now works with generics (#2383)
  fix(parser): fixes for the parsing of 'where' clauses (#2430)
  fix: Run `wasm` nodejs tests with no fails (#2387)
* master:
  fix(ssa): Do not optimize for allocates in constant folding (#2466)
@kevaundray kevaundray added this pull request to the merge queue Aug 28, 2023
Copy link
Contributor

@kevaundray kevaundray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-approving in Jake's stead

Merged via the queue into master with commit b467a2d Aug 28, 2023
16 checks passed
@kevaundray kevaundray deleted the assert-eq-builtin branch August 28, 2023 23:02
TomAFrench added a commit that referenced this pull request Aug 30, 2023
* master: (42 commits)
  fix(ssa): Handle right shift with constants (#2481)
  chore(noir): Release 0.10.4 (#2354)
  fix: Divide by zero should fail to satisfy constraints for `Field` and ints (#2475)
  fix(ssa): Remove padding from ToRadix call with constant inputs (#2479)
  fix: Implement handling of array aliasing in the mem2reg optimization pass (#2463)
  chore: resolve `Instruction` inputs fully before checking against cache (#2472)
  chore: Move independent `run_test` function into nargo core (#2468)
  feat: Standard library functions can now be called with closure args  (#2471)
  feat(frontend): aztec syntactic sugar (feature flagged) (#2403)
  chore(ci): enforce compliance with `cargo fmt` (#2467)
  chore(ci): Allow releases to have additional feature flags (#2405)
  feat: Add `assert_eq` keyword (#2137)
  fix(ssa): Do not optimize for allocates in constant folding (#2466)
  feat(ssa): Reuse existing results for duplicated instructions with no side-effects (#2460)
  fix: Closure lvalue capture bugfix (#2457)
  feat: Syntax for environment types now works with generics (#2383)
  fix(parser): fixes for the parsing of 'where' clauses (#2430)
  fix: Run `wasm` nodejs tests with no fails (#2387)
  chore: Run `cargo fmt` (#2455)
  chore: Perform formatting changes to integration tests (#2448)
  ...
TomAFrench added a commit that referenced this pull request Aug 30, 2023
* master: (42 commits)
  fix(ssa): Handle right shift with constants (#2481)
  chore(noir): Release 0.10.4 (#2354)
  fix: Divide by zero should fail to satisfy constraints for `Field` and ints (#2475)
  fix(ssa): Remove padding from ToRadix call with constant inputs (#2479)
  fix: Implement handling of array aliasing in the mem2reg optimization pass (#2463)
  chore: resolve `Instruction` inputs fully before checking against cache (#2472)
  chore: Move independent `run_test` function into nargo core (#2468)
  feat: Standard library functions can now be called with closure args  (#2471)
  feat(frontend): aztec syntactic sugar (feature flagged) (#2403)
  chore(ci): enforce compliance with `cargo fmt` (#2467)
  chore(ci): Allow releases to have additional feature flags (#2405)
  feat: Add `assert_eq` keyword (#2137)
  fix(ssa): Do not optimize for allocates in constant folding (#2466)
  feat(ssa): Reuse existing results for duplicated instructions with no side-effects (#2460)
  fix: Closure lvalue capture bugfix (#2457)
  feat: Syntax for environment types now works with generics (#2383)
  fix(parser): fixes for the parsing of 'where' clauses (#2430)
  fix: Run `wasm` nodejs tests with no fails (#2387)
  chore: Run `cargo fmt` (#2455)
  chore: Perform formatting changes to integration tests (#2448)
  ...
@Savio-Sou
Copy link
Collaborator

Savio-Sou commented Sep 14, 2023

Just to confirm: should this be documented (i.e. meant to be used by Noir devs)?

UPDATE: From my understanding this was baked into assert(... == ...) (instead of adding a new assert_eq keyword), hence no documentation changes are needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
4 participants