-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add support for parsing of constants #63
Conversation
c5772d7
to
82ca60f
Compare
8bc6d31
to
801dd1d
Compare
I'm in favor of this. It is kind of consistent with Rust. But also, I don't feel strongly about this.
What would be an example of using special characters here? If it is prefixing every constant reference with a special character, I don't think we need it (especially if we use capital letters for constant names). |
Agreed. I meant that as an option if we don't go with using CAPITALS. But agreed that this doesn't seem like a good solution. I have gone with using a generic enum type in this PR while building the AST (for eg |
I think there's a general question here about whether we should be using column-major or row-major form. I know Miden is column-major, but Winterfell isn't always, and many other projects may not be. Row-major is more common in general, and we are aiming for AirScript to have more general utility than just for Miden. @bobbinth curious about your thoughts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work @tohrnii! I've left several comments inline, mostly about ways to use more shared abstractions and reduce near-duplications.
One other comment, though - the tests are mostly for the perfect case, which makes them great as examples and sanity checks, but doesn't give us the level of confidence in the code that I think we'd like to have. Can you add more edge cases for all of them? I added examples in one case, but the other test modules should be updated too
VecElem(Identifier, usize), | ||
MatrixElem(Identifier, usize, usize), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should avoid hard-coding the order of the indices. Instead, maybe we should make new shared atomic types like "VectorAccess" and "MatrixAccess" which can be used both here and in the boundary constraints.
Something like:
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone)]
pub struct VectorAccess {
name: Identifier,
idx: u64,
}
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone)]
pub struct MatrixAccess {
name: Identifier,
col_idx: u64,
row_idx: u64,
}
Also, if we're naming these like this then maybe we should change the name of "Var" to "Elem". It will be more consistent with these names, and they're no longer just variables now that they include named constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh, I'm not 100% convinced by the naming here, since a vector access may not be an element - it might be another vector. Do you have other ideas for this instead of VecElem
and MatrixElem
? Lookup, access, index, ... (I'm not in love with anything I've come up with)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "access" is the best of these, but I agree that it is not satisfying.
BoundaryExpr::PubInput(Identifier("a".to_string()), 0), | ||
BoundaryExpr::VecElem(Identifier("a".to_string()), 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the name of this test should be updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with adding a public_inputs
section instead and kept the name same.
I think we should probably do this. It's the convention for Python too, which means it's the convention for both languages we're referencing syntactically. (This actually makes me wonder if we should really have a separate source section for these. Maybe they should just be declared at the top of the file uppercase, like the convention in Python and Rust. Having the lowercase source section "constants:" followed by the uppercase constants feels weird.)
No, I don't think we should have special characters for accessing constant values. |
@grjte I agree with your point however since currently all of our code is organized into sections, I think it might also look a little weird to only have constants declared outside a section. Maybe we should only do this if we are planning to have some other part of the code outside of the current source section structure as well. What do you think? |
Thank you @grjte for the review. Made suggested changes. I've also added enforcing the use of capitalized names for constants in this PR. The error message and corresponding error enum variant name can be improved though but I can't think of a better one. |
3a6e4ac
to
837de82
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tohrnii! This is a partial review of everything except the tests. I'll review the test changes separately.
71f68e1
to
ad2da0e
Compare
@grjte I've changed |
Hmm yeah, I probably would revert for uniformity personally. Matrix is hard to abbreviate well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tohrnii! Just a few small final things inline
3c3c46d
to
ea68dcc
Compare
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you! I left only a question on testing.
} | ||
|
||
#[test] | ||
fn constants_access_inside_boundary_expr() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have some failing tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I added a few tests with comments that should fail at the parser or IR level. I don't think there's anything specific to constants that would fail at the lexer level (please let me know if you think there are failure cases to add here). There are a lot of redundant tests for lexer and we should refactor these in the future and probably remove most of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! There's one final thing that should be adjusted, but I'm approving so I don't block things. Please make that adjustment before merging. Thanks for all your work on this!
parser/src/ast/mod.rs
Outdated
|
||
/// Returns the name of the matrix. | ||
pub fn name(&self) -> &str { | ||
&self.name.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also be &self.name.name()
now that we have it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, I thought I changed both instances. Fixed.
Partly addressing #60.
This PR adds support for constants to the parser. This doesn't yet produce valid IR for constants. That will be handled in
#67.
Questions: