magma icon indicating copy to clipboard operation
magma copied to clipboard

Wiring doesn't check for type match, only length match

Open jameshegarty opened this issue 5 years ago • 8 comments

Ports with bit type, uint type, and sint type can be wired to each other, as long as the length matches. Don't we want to check that they type itself matches, and require an explicit cast?

jameshegarty avatar Oct 14 '19 22:10 jameshegarty

Currently,

Wiring is structural. So, if two types have the same structure, then they can be connected.

If you want to override the behavior or wiring, you can overload the operator on the class to be stricter.

Operators depend on the type. For example, they can add checks the types.

Open to suggestions.

phanrahan avatar Oct 15 '19 00:10 phanrahan

It seem like right now, if you have a signed add module, you can send unsigned inputs to it and it will wire it without an error. IMO I would prefer it to give an error in this case unless you do an explicit cast. A lot of problems of Verilog come up because it doesn't do typechecking like this. Thoughts anybody?

jameshegarty avatar Oct 15 '19 00:10 jameshegarty

Except wiring is not structural, because I can't wire Bit to Bits[1].

hofstee avatar Oct 15 '19 02:10 hofstee

Wiring a scalar to an array is not normally considered structural.

phanrahan avatar Oct 15 '19 03:10 phanrahan

I agree that the add should do type checking. Let me look at the code.

phanrahan avatar Oct 15 '19 16:10 phanrahan

That'd be cool, I'd be happy to help too once I clear my plate of some other stuff :)

jameshegarty avatar Oct 15 '19 16:10 jameshegarty

Let's move this discussion to hwtypes. And get @leonardt and @cdonovick involved.

phanrahan avatar Oct 15 '19 17:10 phanrahan

I think this discussion would fit well under https://github.com/leonardt/hwtypes/issues/98 Although we can also open a new issue.

cdonovick avatar Oct 15 '19 17:10 cdonovick