Skip to content
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

Merged
merged 2 commits into from
Apr 26, 2022

Conversation

NoelTautges
Copy link
Contributor

@NoelTautges NoelTautges commented Apr 25, 2022

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.

@jimblandy jimblandy added the area: doc Documentation for crate items, public or private label Apr 25, 2022
@jimblandy jimblandy self-requested a review April 25, 2022 16:18
Copy link
Member

@jimblandy jimblandy left a 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.
Copy link
Member

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.

Copy link
Contributor Author

@NoelTautges NoelTautges Apr 25, 2022

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.

Copy link
Member

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.

Copy link
Member

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.)

src/lib.rs Show resolved Hide resolved
Will I ever learn to run `cargo fmt`  before pushing? The answer is probably yes, after this repeated embarrassment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: doc Documentation for crate items, public or private
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants