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(noir): added distinct keyword #1219

Merged
merged 4 commits into from
Apr 26, 2023
Merged

feat(noir): added distinct keyword #1219

merged 4 commits into from
Apr 26, 2023

Conversation

joss-aztec
Copy link
Contributor

@joss-aztec joss-aztec commented Apr 25, 2023

Related issue(s)

Resolves # 1183

Description

Summary of changes

Added distinct keyword for preventing repetitions of witness indices in the program's abi.

fn main(x : pub Field, y : pub Field) -> pub [Field; 4] {
    let a = 1;
    let b = 1;
    [x + 1, y, a, b]
}

Compiles to:

{
  //...
  "abi": {
    //...
    "param_witnesses": { "x": [1], "y": [2] },
    "return_witnesses": [3, 2, 4, 4]
  }
}
EXPR [ (1, _1) (-1, _3) 1 ]
EXPR [ (-1, _4) 1 ]

Whereas

fn main(x : pub Field, y : pub Field) -> distinct pub [Field; 4] {
    let a = 1;
    let b = 1;
    [x + 1, y, a, b]
}

compiles to:

{
  //...
  "abi": {
    //...
    "param_witnesses": { "x": [1], "y": [2] },
    //...
    "return_witnesses": [3, 4, 5, 6]
  }
}
EXPR [ (1, _1) (-1, _3) 1 ]
EXPR [ (1, _2) (-1, _4) 0 ]
EXPR [ (-1, _5) 1 ]
EXPR [ (1, _5) (-1, _6) 0 ]

Key behaviours:

  • witness 2 no longer appears in both the input and output
  • witness 3 is unchanged because it was already unique
  • the last 2 elements of the return are now also unique
  • the above changes required the addition of two extra constraints

Dependency additions / changes

Test additions / changes

Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt with default settings.
  • I have linked this PR to the issue(s) that it resolves.
  • I have reviewed the changes on GitHub, line by line.
  • I have ensured all changes are covered in the description.

Documentation needs

Additional context

crates/noirc_frontend/src/hir/resolution/errors.rs Outdated Show resolved Hide resolved
crates/noirc_frontend/src/hir/resolution/resolver.rs Outdated Show resolved Hide resolved
crates/noirc_frontend/src/parser/parser.rs Outdated Show resolved Hide resolved
crates/noirc_frontend/src/parser/parser.rs Outdated Show resolved Hide resolved
@jfecher
Copy link
Contributor

jfecher commented Apr 25, 2023

Looks like there were some typos introduced by this PR as well

- reorder keywords (distinct first)
- add test case
- fix up comments & typos
- tidy up
jfecher
jfecher previously approved these changes Apr 26, 2023
crates/noirc_frontend/src/hir/resolution/resolver.rs Outdated Show resolved Hide resolved
Co-authored-by: jfecher <jake@aztecprotocol.com>
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.

LGTM

@kevaundray kevaundray enabled auto-merge April 26, 2023 17:17
@kevaundray kevaundray added this pull request to the merge queue Apr 26, 2023
Merged via the queue into master with commit 3a65f30 Apr 26, 2023
@kevaundray kevaundray deleted the joss/distinct-keyword branch April 26, 2023 17:47
TomAFrench added a commit that referenced this pull request Apr 27, 2023
* master:
  chore: address clippy warnings (#1239)
  chore(ssa refactor): Implement function calls (#1235)
  chore(ssa refactor): Implement mutable and immutable variables (#1234)
  chore(ssa refactor): Fix recursive printing of blocks (#1230)
  feat(noir): added assert keyword (#1227)
  chore(ssa refactor): Implement ssa-gen for indexing, cast, constrain, if, unary (#1225)
  feat(noir): added `distinct` keyword (#1219)
TomAFrench added a commit that referenced this pull request Apr 29, 2023
* master: (223 commits)
  chore(noir): Release 0.5.0 (#1202)
  chore(ci): Utilize new workflow to build binaries (#1250)
  chore(ssa refactor): Fix loading from mutable parameters (#1248)
  fix(wasm): add std after dependencies (#1245)
  chore(ssa refactor): Fix no returns & duplicate main (#1243)
  chore(ssa refactor): Implement intrinsics (#1241)
  chore(ssa refactor): Implement first-class functions (#1238)
  chore: address clippy warnings (#1239)
  chore(ssa refactor): Implement function calls (#1235)
  chore(ssa refactor): Implement mutable and immutable variables (#1234)
  chore(ssa refactor): Fix recursive printing of blocks (#1230)
  feat(noir): added assert keyword (#1227)
  chore(ssa refactor): Implement ssa-gen for indexing, cast, constrain, if, unary (#1225)
  feat(noir): added `distinct` keyword (#1219)
  chore(nargo): update panic message to suggest searching for similar issues (#1224)
  chore(ssa refactor): Update how instruction result types are retrieved (#1222)
  chore(ssa refactor): Implement ssa-gen for binary, block, tuple, extract-tuple-field, and semi expressions (#1217)
  chore: add RUST_BACKTRACE environment variable to nix config (#1216)
  chore(ssa): Add intial control flow graph  (#1200)
  chore(ssa refactor): Handle codegen for literals (#1209)
  ...
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
Development

Successfully merging this pull request may close these issues.

4 participants