Skip to content

Bits UInt type review #1743

@sequencer

Description

@sequencer

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 returns Bits, rather than a UInt.
  • Secondly, what is pad(that: Int) -> this.type?
    this.type is defined here
    I don't know why it returns this.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

  1. Change the wrong return type in Bits.
  2. Add missing operators to Bits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions