-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Try to move constant terms to one side for arithmetic generics (#…
…6008) # Description ## Problem\* Resolves #6006 ## Summary\* Previously we were failing for constraints like `a + 3 = b + 1` when we could instead move the constant terms to one side: `a + 2 = b` then solve with `b := a + 2`. ## 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
4 changed files
with
86 additions
and
3 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/arithmetic_generics_move_constant_terms/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_move_constant_terms" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.33.0" | ||
|
||
[dependencies] |
26 changes: 26 additions & 0 deletions
26
test_programs/compile_success_empty/arithmetic_generics_move_constant_terms/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,26 @@ | ||
trait FromCallData<let N: u32, let M: u32> { | ||
fn from_calldata(calldata: [Field; N]) -> (Self, [Field; M]); | ||
} | ||
|
||
struct Point { x: Field, y: Field } | ||
|
||
impl <let N: u32> FromCallData<N, N - 1> for Field { | ||
fn from_calldata(calldata: [Field; N]) -> (Self, [Field; (N - 1)]) { | ||
let slice = calldata.as_slice(); | ||
let (value, slice) = slice.pop_front(); | ||
(value, slice.as_array()) | ||
} | ||
} | ||
|
||
impl <let N: u32> FromCallData<N, N - 2> for Point { | ||
fn from_calldata(calldata: [Field; N]) -> (Self, [Field; (N - 2)]) { | ||
let (x, calldata) = FromCallData::from_calldata(calldata); | ||
let (y, calldata) = FromCallData::from_calldata(calldata); | ||
(Self { x, y }, calldata) | ||
} | ||
} | ||
|
||
fn main() { | ||
let calldata = [1, 2]; | ||
let _: (Point, _) = FromCallData::from_calldata(calldata); | ||
} |