-
Notifications
You must be signed in to change notification settings - Fork 648
Description
These days I did some code review on Elements operators.
The original idea was trying to solve the the Intellij highlight issue.
But I encountered some strange designs which need to be recorded and discussed later.
Question 1: What is Bits?
I think Bits corresponds to these data structure in BlueSpec, SMT
However when I take a look at operator at Bits, there are some strange functions.
tail(n: Int) -> UInt
head(n: Int) -> UInt
apply(x: BigInt, y: BigInt) -> UInt
pad(that: Int) -> this.type
##(that: Bits) -> UInt
- Firstly, return type of
tail,head,apply(x: BigInt, y: BigInt),##(that: Bits)are certainly wrong.
They should returnsBits, rather than aUInt. - Secondly, what is
pad(that: Int) -> this.type?
this.typeis defined here
I don't know why it returnsthis.type, it's kind of dependent type thinking?
Question 2: UInt are used too much?
Basically, I think there exists a customary abuse to UInt: using UInt as Bits. I think if a user need a UInt, they are using +, -, *, / and other numerical related operators. But these operator only exists in UInt, while not exists in Bits:
&(that: UInt) -> UInt
|(that: UInt) -> UInt
^(that: UInt) -> UInt
orR -> Bool
andR -> Bool
xorR -> Bool
bitSet(off: UInt, dat: Bool) -> UInt
=/=(that: UInt) -> Bool
===(that: UInt) -> Bool
All of these operator are not related to number, while they should belong to Bits, and even the return type should be Bits:
what's the purpose of (a: UInt | b: UInt) + c: UInt? It's kind of strange to merge the usage between Bit Vector and UInt.
So, as the result, I think we may need to fix this to provide a more safe and concrete types to users.
Solution
- Change the wrong return type in Bits.
- Add missing operators to Bits.