-
Notifications
You must be signed in to change notification settings - Fork 195
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
Clarify accepted types for Expression::AccessIndex
#1862
Conversation
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 for this!
I have one concern.
src/lib.rs
Outdated
/// Array access with a known index. | ||
/// Access the same types as [`Access`] plus [`Struct`] with a known index. | ||
/// | ||
/// [`Array`]s must have a [`Constant`] size. |
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.
Is this true? I couldn't find code in the validator that would reject dynamically-sized arrays.
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 validator sets a bound of the size of the array if its size is constant, but sets it to !0
if it's not, which somehow evaluates to -1, making the bounds check always fail. At least in theory, I haven't explicitly tested this.
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.
It makes the compile time bounds check always succeed because !0
as a u32 is u32::MAX
so no index is ever out of bounds. The code could be made easier to grok by using u32::MAX
explicitly.
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.
(Agreed that the code is not as clear as it might be.)
Will I ever learn to run `cargo fmt` before pushing? The answer is probably yes, after this repeated embarrassment
The docs for
AccessIndex
only note it can be used with arrays ("Array access with a known index.") and don't mention it can be used with structs or other types.This pull request documents the full list of types relative to those for
Expression::Access
, which already have a more extensive blurb written about them.