-
Notifications
You must be signed in to change notification settings - Fork 242
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
Basic strings #622
Basic strings #622
Conversation
…rings currently mock array functionality
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. I take it it is currently blocked until #620 is merged
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, just some minor cleanup with removing unneeded comments then we can merge
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.
LGTM
Related issue(s)
Resolves #383
The issue linked is to add log statements. Although not directly related, strings are being added to ultimately enable logging.
Description
This PR adds a basic string implementation. To correctly resolve string size we follow the same resolution strategy as arrays and under the hood we utilize Rust's String type and convert to a list of
u8
integers.Summary of changes
I added a
String
type to various type enums such asInputValue
,UnresolvedType
,Type
in the HIR,Literal
in the monomorphisation AST, etc. Strings are allowed to be passed into the ABI and compared against each other.However, in this current implementation strings do not fully mock the functionality of arrays. This means we cannot replace individual elements of arrays, but a mutable string is possible by replacing the entire string value.
I debated whether or not to implement a string type directly or rather create a char type and then enable arrays to handle this char type. This felt like it would be a little bit more complex as we would then have to extend arrays to support string literals, and char literals would have to be added as well. To start, I went with a separate string type as it seems highly unlikely that many people are going to be doing string manipulation in Noir and the main goal of adding strings was to enable logging which will just require string literals. I could make this change right now, or I could open an issue for later to add chars and enable formatting/manipulation of strings.
Dependency additions / changes
(If applicable.)
Test additions / changes
I added a basic test checking whether or not we can pass string data to the ABI and compare it against string literals inside of Noir.
Checklist
cargo fmt
with default settings.Additional context
(If applicable.)