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

Emit clear error for index into zero-sized Arrays #171

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JulianKnodt
Copy link

Previously GEP on zero-sized arrays, would fail. This change fixes arrays to instead emit runtime arrays. I do not know if this will lead to any runtime cost, but it fixes all the compile errors.

I did try out [(); 0].map(|()| 1), and found that that does not compile.

Fixes #151

@LegNeato
Copy link
Collaborator

LegNeato commented Dec 8, 2024

Awesome, thanks for the PR! 🍻 I'm not super familiar with this code but the change looks reasonable to me. I'll wait for some other maintainers to look at it before reviewing 🤙

Looks like you need to run cargo fmt to pass CI.

@JulianKnodt
Copy link
Author

Somehow this passes locally but not on CI 🤣, I'll have to test a bit more

@JulianKnodt JulianKnodt changed the title Fix zero-sized Array GEPs Emit clear for index into zero-sized Arrays Dec 11, 2024
@JulianKnodt
Copy link
Author

JulianKnodt commented Dec 11, 2024

I've changed my expectation, previously it was erroring for accessing zero sized arrays, but it was hidden behind a deny that is on by default. Instead, I think we should always panic, but with a clear error message. I'm unsure what the behavior would be if that expression were allowed to be compiled.

@JulianKnodt JulianKnodt changed the title Emit clear for index into zero-sized Arrays Emit clear error for index into zero-sized Arrays Dec 11, 2024
@LegNeato
Copy link
Collaborator

Can we make the error messages match rustc? For example:

error[E0080]: evaluation of constant value failed
 --> src/main.rs:2:18
  |
2 | const VAL: u32 = ARR[0];
  |                  ^^^^^^ index out of bounds: the length is 0 but the index is 0

For more information about this error, try `rustc --explain E0080`.

Previously GEP on zero-sized arrays, would fail. This change fixes arrays to instead emit
runtime arrays. I do not know if this will lead to any runtime cost, but it fixes all the
compile errors.
@JulianKnodt
Copy link
Author

I can, I do worry that since it's not the actual error it may be more confusing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GEP not implemented for type struct [_; 0]
2 participants