-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description ## Problem\* Resolves #4784 for users who haven't discovered the secret `--arithmetic-generics` flag ## Summary\* Enables the `--arithmetic-generics` flag by default and provides documentation for arithmetic generics. ## Additional Context I'm open to discussion on whether we should test this more before releasing but since the additional type checks and overflow checks that were originally blocking it are implemented I figured I'd make this PR. ## Documentation\* Check one: - [ ] No documentation needed. - [x] 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
Showing
15 changed files
with
122 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
test_programs/compile_failure/arithmetic_generics_intermediate_underflow/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "arithmetic_generics_intermediate_underflow" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.33.0" | ||
|
||
[dependencies] |
32 changes: 32 additions & 0 deletions
32
test_programs/compile_failure/arithmetic_generics_intermediate_underflow/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// docs:start:intermediate-underflow-example | ||
fn main() { | ||
// From main it looks like there's nothing sketchy going on | ||
seems_fine([]); | ||
} | ||
|
||
// Since `seems_fine` says it can receive and return any length N | ||
fn seems_fine<let N: u32>(array: [Field; N]) -> [Field; N] { | ||
// But inside `seems_fine` we pop from the array which | ||
// requires the length to be greater than zero. | ||
|
||
// error: Could not determine array length `(0 - 1)` | ||
push_zero(pop(array)) | ||
} | ||
|
||
fn pop<let N: u32>(array: [Field; N]) -> [Field; N - 1] { | ||
let mut result: [Field; N - 1] = std::mem::zeroed(); | ||
for i in 0..N { | ||
result[i] = array[i]; | ||
} | ||
result | ||
} | ||
|
||
fn push_zero<let N: u32>(array: [Field; N]) -> [Field; N + 1] { | ||
let mut result: [Field; N + 1] = std::mem::zeroed(); | ||
for i in 0..N { | ||
result[i] = array[i]; | ||
} | ||
// index N is already zeroed | ||
result | ||
} | ||
// docs:end:intermediate-underflow-example |
7 changes: 7 additions & 0 deletions
7
test_programs/compile_failure/arithmetic_generics_underflow/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "arithmetic_generics_underflow" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.33.0" | ||
|
||
[dependencies] |
14 changes: 14 additions & 0 deletions
14
test_programs/compile_failure/arithmetic_generics_underflow/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// docs:start:underflow-example | ||
fn pop<let N: u32>(array: [Field; N]) -> [Field; N - 1] { | ||
let mut result: [Field; N - 1] = std::mem::zeroed(); | ||
for i in 0..N { | ||
result[i] = array[i]; | ||
} | ||
result | ||
} | ||
|
||
fn main() { | ||
// error: Could not determine array length `(0 - 1)` | ||
pop([]); | ||
} | ||
// docs:end:underflow-example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters