Skip to content

Commit

Permalink
feat: Add comptime Interpreter (#4821)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves #4587

## Summary\*

Implements an interpreter to interpret Noir functions at compile-time.
This is intended to be used in the future for evaluation of `comptime`
items for metaprogramming, although there is currently no way to trigger
this interpreter in user code.

## 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.

---------

Co-authored-by: Maxim Vezenov <mvezenov@gmail.com>
  • Loading branch information
jfecher and vezenovm committed Apr 17, 2024
1 parent 0f9ae0a commit 5992436
Show file tree
Hide file tree
Showing 17 changed files with 1,503 additions and 31 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ tempfile = "3.6.0"
jsonrpc = { version = "0.16.0", features = ["minreq_http"] }
flate2 = "1.0.24"

im = { version = "15.1", features = ["serde"] }
tracing = "0.1.40"
tracing-web = "0.1.3"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_evaluator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fxhash.workspace = true
iter-extended.workspace = true
thiserror.workspace = true
num-bigint = "0.4"
im = { version = "15.1", features = ["serde"] }
im.workspace = true
serde.workspace = true
tracing.workspace = true
chrono = "0.4.37"
chrono = "0.4.37"
1 change: 1 addition & 0 deletions compiler/noirc_frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ iter-extended.workspace = true
chumsky.workspace = true
thiserror.workspace = true
smol_str.workspace = true
im.workspace = true
serde_json.workspace = true
serde.workspace = true
rustc-hash = "1.1.0"
Expand Down
5 changes: 5 additions & 0 deletions compiler/noirc_frontend/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ pub struct FunctionDefinition {
/// True if this function was defined with the 'unconstrained' keyword
pub is_unconstrained: bool,

/// True if this function was defined with the 'comptime' keyword
pub is_comptime: bool,

/// Indicate if this function was defined with the 'pub' keyword
pub visibility: ItemVisibility,

Expand Down Expand Up @@ -679,10 +682,12 @@ impl FunctionDefinition {
span: ident.span().merge(unresolved_type.span.unwrap()),
})
.collect();

FunctionDefinition {
name: name.clone(),
attributes: Attributes::empty(),
is_unconstrained: false,
is_comptime: false,
visibility: ItemVisibility::Private,
generics: generics.clone(),
parameters: p,
Expand Down

0 comments on commit 5992436

Please sign in to comment.