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

Improve to_bits type checking #614

Open
Timmmm opened this issue Nov 11, 2024 · 1 comment
Open

Improve to_bits type checking #614

Timmmm opened this issue Nov 11, 2024 · 1 comment
Labels
refactor Code clean up

Comments

@Timmmm
Copy link
Collaborator

Timmmm commented Nov 11, 2024

Currently to_bits just silently accepts larger integers than will fit in the bitvector and slices off the top. That's a bit sad from a type checking point of view. Sail can perfectly happily check this at compile time:

val to_bits : forall 'l 'x, 'l >= 0 & 0 <= 'x < 2 ^ 'l . (int('l), int('x)) -> bits('l)
function to_bits (l, n) = get_slice_int(l, n, 0)

I think we should change the definition to that. There are some places where the slicing is intentional (e.g. the bit rotate functions), where we can probably introduce an explicit function:

val to_bits_truncate : forall 'l, 'l >= 0 . (int('l), int) -> bits('l)
function to_bits_truncate (l, n) = get_slice_int(l, n, 0)

And there are a lot of places where it probably isn't intentional, where we could add

val to_bits_unsafe : forall 'l, 'l >= 0 . (int('l), int) -> bits('l)
function to_bits_unsafe (l, n) = get_slice_int(l, n, 0)

with TODOs to add the appropriate assertions & types. A lot of them are in the vector extension which has very loose typing so it will take a while to fix them there.

@Timmmm Timmmm added the refactor Code clean up label Nov 11, 2024
@jordancarlin
Copy link
Collaborator

jordancarlin commented Nov 11, 2024 via email

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

No branches or pull requests

2 participants