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: Implement traits - parser support #2094 #2230

Merged
merged 3 commits into from
Aug 10, 2023

Conversation

yordanmadzhunkov
Copy link
Contributor

@yordanmadzhunkov yordanmadzhunkov commented Aug 9, 2023

Description

Parser support for traits

  • The functions within trait definitions can now have a body ( Expand trait definition in AST to include body )
  • Parsing support for trait-associated constants (using the let keyword for now to avoid introducing a new keyword such as const).
  • Traits can have a where clause
  • The where clause is only allowed on generic definitions
  • The parsing of where clauses with multiple constraints has been fixed
  • More parsing tests for functions using traits and trait definitions.
  • Parser tests now pass by ignore warnings

Problem*

After the first prototype of traits implementation we agreed to split into small PRs and merge them one by one in master branch.
This is the first from many to follow. Enjoy

Resolves

Summary*

After this PR the parser with parse ( with traits are experimental warnings ) the following code

trait Empty {}

trait TraitWithDefaultBody { fn foo(self) {}; }

trait TraitAcceptingMutableRef { fn foo(&mut self); }

trait TraitWithTypeBoundOperation { fn identity() -> Self; }

trait TraitWithAssociatedType { type Element; fn item(self, index: Field) -> Self::Element; }

trait TraitWithAssociatedConstant { let Size: Field; }

trait TraitWithAssociatedConstantWithDefaultValue { let Size: Field = 10; }

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.

PR Checklist*

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

* Add several parsing traits test
* Expand trait definition in AST to include body
* Add diagnostic error when where clause is not appled on generic type
@yordanmadzhunkov
Copy link
Contributor Author

@jfecher

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.

Looks mostly good, but lets revert the changed error check for no longer disallowing patterns in trait parameters. To match rust we should always disallow them.

crates/noirc_frontend/src/parser/parser.rs Outdated Show resolved Hide resolved
crates/noirc_frontend/src/parser/parser.rs Show resolved Hide resolved
crates/noirc_frontend/src/parser/parser.rs Outdated Show resolved Hide resolved
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.

Looks good. My bad for holding this up 👍

crates/noirc_frontend/src/parser/parser.rs Show resolved Hide resolved
@jfecher jfecher enabled auto-merge August 10, 2023 13:19
@jfecher jfecher added this pull request to the merge queue Aug 10, 2023
Merged via the queue into noir-lang:master with commit 589f173 Aug 10, 2023
TomAFrench added a commit that referenced this pull request Aug 10, 2023
* master: (80 commits)
  fix: properly capture lvalues in closure environments (#2120) (#2257)
  fix: Optimize contracts built by `nargo info` (#2259)
  chore: impl Display for DebugType (#2258)
  chore: update `noir_wasm` build process to match `acvm_js` (#2067)
  feat: Implement traits - parser support #2094 (#2230)
  chore: Refactor DefCollector duplicate errors (#2231)
  chore: Address clippy warnings (#2246)
  feat: Support `contract` package type in `nargo info` command (#2249)
  feat: Add slice append (#2241)
  chore: Bump `async-lsp` to v0.0.5 (#2186)
  chore: Move the remaining `nargo_cli` lib funcs into `nargo` crate (#2225)
  chore: Add test for eddsa (#2237)
  chore: Split `Nargo.toml` operations into separate package (#2224)
  fix(stdlib): correct `tecurve::contains` formula (#1821)
  feat: Remove `comptime` and warn upon usage (#2178)
  fix: Remove last vestige of array of structs to struct of arrays conversion (#2217)
  fix: Add foreign impl error (#2216)
  feat(nargo)!: Replace `--contracts` flag with `contract` package type (#2204)
  feat: Optimize `x < 0` for unsigned `x` to false (#2206)
  fix: Initialize numeric generics' type to a polymorphic integer when used in an expression (#2179)
  ...
TomAFrench added a commit that referenced this pull request Aug 11, 2023
* master: (29 commits)
  feat(nargo): Add support for contracts in `nargo check` (#2267)
  chore(ci): Name wasm job more clearly (#2269)
  chore(ci): Create cache key with consideration to target (#2273)
  chore(ci): Run publish workflow against PRs (#2268)
  chore: Merge in contents of `build-nargo` repository (#2211)
  fix(lsp): Improve dependency resolution in context of `Nargo.toml` (#2226)
  chore: Remove unnecessary duplication in how we test Noir compiler (#2248)
  fix: properly capture lvalues in closure environments (#2120) (#2257)
  fix: Optimize contracts built by `nargo info` (#2259)
  chore: impl Display for DebugType (#2258)
  chore: update `noir_wasm` build process to match `acvm_js` (#2067)
  feat: Implement traits - parser support #2094 (#2230)
  chore: Refactor DefCollector duplicate errors (#2231)
  chore: Address clippy warnings (#2246)
  feat: Support `contract` package type in `nargo info` command (#2249)
  feat: Add slice append (#2241)
  chore: Bump `async-lsp` to v0.0.5 (#2186)
  chore: Move the remaining `nargo_cli` lib funcs into `nargo` crate (#2225)
  chore: Add test for eddsa (#2237)
  chore: Split `Nargo.toml` operations into separate package (#2224)
  ...
TomAFrench added a commit that referenced this pull request Aug 11, 2023
* master:
  feat(nargo): Add support for contracts in `nargo check` (#2267)
  chore(ci): Name wasm job more clearly (#2269)
  chore(ci): Create cache key with consideration to target (#2273)
  chore(ci): Run publish workflow against PRs (#2268)
  chore: Merge in contents of `build-nargo` repository (#2211)
  fix(lsp): Improve dependency resolution in context of `Nargo.toml` (#2226)
  chore: Remove unnecessary duplication in how we test Noir compiler (#2248)
  fix: properly capture lvalues in closure environments (#2120) (#2257)
  fix: Optimize contracts built by `nargo info` (#2259)
  chore: impl Display for DebugType (#2258)
  chore: update `noir_wasm` build process to match `acvm_js` (#2067)
  feat: Implement traits - parser support #2094 (#2230)
  chore: Refactor DefCollector duplicate errors (#2231)
  chore: Address clippy warnings (#2246)
  feat: Support `contract` package type in `nargo info` command (#2249)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants