cloning is the way that types are copied allowing even wires to provide their type as input to things like ValidIO:
class ValidIO[+T <: Data](gen: T) extends Bundle {
val valid = Bool(OUTPUT)
val bits = gen.clone.asOutput
def fire(dummy: Int = 0): Bool = valid
override def clone: this.type = new ValidIO(gen).asInstanceOf[this.type]
}
usage:
new ValidIO(UInt(width = 8))
the main place where you need to provide a clone method is when a bundle class definition depends on its parameters for creation. it's pretty easy to do if you just copy and paste the template from above. the template includes the this.type return type and the coercion to this.type using asInstanceOf.