Conversation
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
|
I think if we used SmartBits to coerce integers, we could solve this issue: #855 too by just converting them to SmartBits and having the mux primitive manage the required extension to match the value the mux output is wired too. But, @rsetaluri, this would require SmartBits to work with the mux primitive. We could build this in since mux is a primitive, but I wonder if there's a more general pattern we might consider to allow circuits/generators to support/extend SmartBits? |
|
Bump @rsetaluri I'd like to use this as a starting point for fixing #969. Basically, I'd like to add the rule that we shouldn't truncate during conversion between python integers to magma values. I think this decorator would be a good place to do it and we should have all the operators reuse that logic rather than adding it to them individually. |
|
Actually scratch that, we can lower the priority but this would be a good change to get in since it's pretty straightforward and does avoid a circular import. I was able to resolve #969 inside the Array constructor logic which actually seems like a good place for it. |
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
intcoercion can't really happen up front like thissince 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