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

Panic if an allocation would exceed isize::MAX bytes #3299

Closed
rtfeldman opened this issue Jun 22, 2022 · 1 comment
Closed

Panic if an allocation would exceed isize::MAX bytes #3299

rtfeldman opened this issue Jun 22, 2022 · 1 comment
Labels
builtins Relates to roc builtins like Bool, List, Str ... enhancement New feature or request

Comments

@rtfeldman
Copy link
Contributor

rtfeldman commented Jun 22, 2022

Our pointers can only index up to isize::MAX into an array because they do signed pointer arithmetic.

This means a List, Str, Dict, or Set must never exceed isize::MAX bytes of capacity, and should panic if they are about to, as the alternative would be undefined behavior. Notes:

  • This is bytes, not elements.
  • We should do this "overflow" check on all operations that can increase capacity, e.g. append, prepend, concat, reserve, withCapacity, etc.
  • We should also give a compile-time error if a list literal or string literal would be too big.
@rtfeldman rtfeldman added enhancement New feature or request builtins Relates to roc builtins like Bool, List, Str ... labels Jun 22, 2022
@rtfeldman rtfeldman changed the title Error if an allocation would exceed isize::MAX bytes Panic if an allocation would exceed isize::MAX bytes Jun 22, 2022
@rtfeldman
Copy link
Contributor Author

Closing in favor of #3299

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builtins Relates to roc builtins like Bool, List, Str ... enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant