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

Implicit coercion decorator for Python values #828

Open
leonardt opened this issue Sep 9, 2020 · 0 comments · May be fixed by #855
Open

Implicit coercion decorator for Python values #828

leonardt opened this issue Sep 9, 2020 · 0 comments · May be fixed by #855
Assignees

Comments

@leonardt
Copy link
Collaborator

leonardt commented Sep 9, 2020

See #815 for discussion

Summary: Provide a decorator that handles the implicit coercion of Python values (bool, int, Bit, BV, tuple) to the magma equivalent values using the conversion operators (m.bit, m.bits, m.tuple_). This should standardize the implicit coercion logic for all user facing functions such as primitives and operators. It should also simplify type inference since the primitives can then simply operator on magma types (since all python values will first be coerced to magma values).

@leonardt leonardt self-assigned this Sep 9, 2020
leonardt added a commit that referenced this issue Sep 24, 2020
Provides reuseable decorator and function to handle magma's implicit
coercion of Python values.

For now, I moved the logic from wiring and mux to a shared place to
ensure consistency.  There's probably other places to do this, but we
can do this on demand as we enounter incosistencies.

One issue is that `int` coercion can't really happen up front like this
since it is determined by the place it's used (i.e. when it's wired to a
Bits we check it can fit in the bit width).  @rsetaluri perhaps we could
use SmartBits for this? (convert it to a smartbits that's automatically
extended to wire to a regular bits, but I think right now our rules
don't allow implicit truncation, but we could define a special SmartBits
subclass that only extends.  My one concern would be whether this would
make the error a bit harder to traceback)

Fixes #828
leonardt added a commit that referenced this issue Sep 24, 2020
Provides reuseable decorator and function to handle magma's implicit
coercion of Python values.

For now, I moved the logic from wiring and mux to a shared place to
ensure consistency.  There's probably other places to do this, but we
can do this on demand as we enounter incosistencies.

One issue is that `int` coercion can't really happen up front like this
since it is determined by the place it's used (i.e. when it's wired to a
Bits we check it can fit in the bit width).  @rsetaluri perhaps we could
use SmartBits for this? (convert it to a smartbits that's automatically
extended to wire to a regular bits, but I think right now our rules
don't allow implicit truncation, but we could define a special SmartBits
subclass that only extends.  My one concern would be whether this would
make the error a bit harder to traceback)

Fixes #828
@leonardt leonardt linked a pull request Sep 24, 2020 that will close this issue
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 a pull request may close this issue.

1 participant