-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add remaining slice methods to the interpreter (#5422)
# Description ## Problem\* ## Summary\* Adds the remaining builtin slice methods to the interpreter. Also adds `is_unconstrained` which always returns true. This way `comptime` can also take advantage of any `if is_unconstrained()` optimizations (like `break`) used in unconstrained code in called functions. ## 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.
- Loading branch information
Showing
5 changed files
with
170 additions
and
16 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
7 changes: 7 additions & 0 deletions
7
test_programs/compile_success_empty/comptime_slice_methods/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 = "comptime_slice_methods" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.31.0" | ||
|
||
[dependencies] |
27 changes: 27 additions & 0 deletions
27
test_programs/compile_success_empty/comptime_slice_methods/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,27 @@ | ||
fn main() { | ||
comptime | ||
{ | ||
// Comptime scopes are counted as unconstrained | ||
assert(std::runtime::is_unconstrained()); | ||
|
||
let slice = &[2]; | ||
let slice = slice.push_back(3); | ||
let slice = slice.push_front(1); | ||
assert_eq(slice, &[1, 2, 3]); | ||
|
||
let slice = slice.insert(1, 10); | ||
assert_eq(slice, &[1, 10, 2, 3]); | ||
|
||
let (slice, ten) = slice.remove(1); | ||
assert_eq(slice, &[1, 2, 3]); | ||
assert_eq(ten, 10); | ||
|
||
let (one, slice) = slice.pop_front(); | ||
assert_eq(slice, &[2, 3]); | ||
assert_eq(one, 1); | ||
|
||
let (slice, three) = slice.pop_back(); | ||
assert_eq(slice, &[2]); | ||
assert_eq(three, 3); | ||
} | ||
} |
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