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

Add checked versions of 'resize', 'truncateB', and 'fromIntegral' #1491

Merged
merged 2 commits into from
Sep 1, 2020

Conversation

martijnbastiaan
Copy link
Member

Depending on the type 'resize', 'truncateB', and 'fromIntegral' either
yield an XException or silently perform wrap-around if its argument does
not fit in the resulting type's bounds. The added functions check the
bound condition and fail with an error call if the condition is
violated. They do not affect HDL generation.

Useful in cases where runtime behavior should ensure that and out of
bound or wrap around should not occur and users want their code to fail
hard if this invariant is ever violated.

@martijnbastiaan martijnbastiaan force-pushed the resize-checked branch 2 times, most recently from d750fc4 to ffcd5fb Compare August 28, 2020 07:55
@martijnbastiaan
Copy link
Member Author

@christiaanb Concerning the offline chat: I do agree that parsing is better than validating, but:

  • The resize / truncateB functions are already here and "unsafe".
  • Unless we add type level information to Bounded (or another class) we can't write type safe conversion functions
  • This would have, if used, made my debug run over at our client a matter of minutes instead of hours.

In short, I'm very much for adding this to clash-prelude

Depending on the type 'resize', 'truncateB', and 'fromIntegral' either
yield an XException or silently perform wrap-around if its argument does
not fit in the resulting type's bounds. The added functions check the
bound condition and fail with an error call if the condition is
violated. They do not affect HDL generation.

Useful in cases where runtime behavior should ensure that and out of
bound or wrap around should not occur and users want their code to fail
hard if this invariant is ever violated.
@martijnbastiaan martijnbastiaan merged commit 7e45191 into master Sep 1, 2020
@martijnbastiaan martijnbastiaan deleted the resize-checked branch September 1, 2020 09:50
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.

None yet

3 participants