Skip to content

Commit 8c4aaf5

Browse files
committed
Revert "Convert cloneType to an extension method"
This reverts commit 0ba3c5d.
1 parent b0e233d commit 8c4aaf5

File tree

18 files changed

+50
-72
lines changed

18 files changed

+50
-72
lines changed

core/src/main/scala-2/chisel3/Bits.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends BitsImpl w
160160
* @note For [[SInt]]s only, this will do sign extension.
161161
* @group Bitwise
162162
*/
163-
final def pad(that: Int): Bits = macro SourceInfoWhiteboxTransform.thatArg
163+
final def pad(that: Int): this.type = macro SourceInfoTransform.thatArg
164164

165165
/** @group SourceInfoTransformMacro */
166-
def do_pad(that: Int)(implicit sourceInfo: SourceInfo): Bits = _padImpl(that)
166+
def do_pad(that: Int)(implicit sourceInfo: SourceInfo): this.type = _padImpl(that)
167167

168168
/** Bitwise inversion operator
169169
*
@@ -182,6 +182,8 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends BitsImpl w
182182
* $sumWidthInt
183183
* @group Bitwise
184184
*/
185+
// REVIEW TODO: redundant
186+
// REVIEW TODO: should these return this.type or Bits?
185187
final def <<(that: BigInt): Bits = macro SourceInfoWhiteboxTransform.thatArg
186188

187189
/** @group SourceInfoTransformMacro */

core/src/main/scala/chisel3/AggregateImpl.scala

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package chisel3
44

55
import chisel3.experimental.VecLiterals.AddVecLiteralConstructor
66
import chisel3.experimental.dataview.{isView, reify, reifyIdentityView, InvalidViewException}
7-
import chisel3.Data.DataExtensions
87

98
import scala.collection.immutable.{SeqMap, VectorMap}
109
import scala.collection.mutable.{HashSet, LinkedHashMap}
@@ -422,7 +421,9 @@ private[chisel3] abstract class VecImpl[T <: Data] private[chisel3] (gen: => T,
422421
*/
423422
def apply(idx: Int): T = self(idx)
424423

425-
override def _cloneType: Vec[T] = new Vec(gen.cloneTypeFull, length)
424+
override def cloneType: this.type = {
425+
new Vec(gen.cloneTypeFull, length).asInstanceOf[this.type]
426+
}
426427

427428
override def getElements: Seq[Data] = self
428429

@@ -490,7 +491,7 @@ private[chisel3] abstract class VecImpl[T <: Data] private[chisel3] (gen: => T,
490491
elementInitializers: (Int, T)*
491492
)(
492493
implicit sourceInfo: SourceInfo
493-
): Vec[T] = {
494+
): this.type = {
494495

495496
def checkLiteralConstruction(): Unit = {
496497
val dupKeys = elementInitializers.map { x => x._1 }.groupBy(x => x).flatMap {
@@ -542,7 +543,7 @@ private[chisel3] abstract class VecImpl[T <: Data] private[chisel3] (gen: => T,
542543
requireIsChiselType(this, "vec literal constructor model")
543544
checkLiteralConstruction()
544545

545-
val clone = this.cloneType
546+
val clone = cloneType
546547
val cloneFields = getRecursiveFields(clone, "(vec root)").toMap
547548

548549
// Create the Vec literal binding from litArgs of arguments
@@ -831,10 +832,8 @@ private[chisel3] trait RecordImpl extends AggregateImpl { thiz: Record =>
831832
}
832833
}
833834

834-
// Note that _cloneTypeImpl is implemented by the compiler plugin and must be a different method name because
835-
// We want to run checkClone after calling _cloneTypeImpl
836-
final override def _cloneType: Data = {
837-
val clone = _cloneTypeImpl
835+
override def cloneType: this.type = {
836+
val clone = _cloneTypeImpl.asInstanceOf[this.type]
838837
checkClone(clone)
839838
clone
840839
}
@@ -954,10 +953,10 @@ private[chisel3] trait RecordImpl extends AggregateImpl { thiz: Record =>
954953
* )
955954
* }}}
956955
*/
957-
private[chisel3] def _makeLit(elems: (Data => (Data, Data))*)(implicit sourceInfo: SourceInfo): Data = {
956+
private[chisel3] def _makeLit(elems: (this.type => (Data, Data))*)(implicit sourceInfo: SourceInfo): this.type = {
958957

959958
requireIsChiselType(this, "bundle literal constructor model")
960-
val clone = this.cloneType
959+
val clone = cloneType
961960
val cloneFields = getRecursiveFields(clone, "_").toMap
962961

963962
// Create the Bundle literal binding from litargs of arguments

core/src/main/scala/chisel3/BitsImpl.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
package chisel3
44

5-
import chisel3.Data.DataExtensions
65
import chisel3.experimental.{requireIsHardware, SourceInfo}
76
import chisel3.internal.{_resizeToWidth, throwException, BaseModule}
87
import chisel3.internal.Builder.pushOp
@@ -22,9 +21,9 @@ private[chisel3] trait BitsImpl extends Element { self: Bits =>
2221
// Arguments against: generates down to a FIRRTL UInt anyways
2322

2423
// Only used for in a few cases, hopefully to be removed
25-
private[chisel3] def cloneTypeWidth(width: Width): Bits
24+
private[chisel3] def cloneTypeWidth(width: Width): this.type
2625

27-
override def _cloneType: Data = cloneTypeWidth(this.width)
26+
def cloneType: this.type = cloneTypeWidth(this.width)
2827

2928
/** A non-ambiguous name of this `Bits` instance for use in generated Verilog names
3029
* Inserts the width directly after the typeName, e.g. UInt4, SInt1
@@ -168,7 +167,7 @@ private[chisel3] trait BitsImpl extends Element { self: Bits =>
168167
// Pad literal to that width
169168
protected def _padLit(that: Int): this.type
170169

171-
protected def _padImpl(that: Int)(implicit sourceInfo: SourceInfo): Bits = this.width match {
170+
protected def _padImpl(that: Int)(implicit sourceInfo: SourceInfo): this.type = this.width match {
172171
case KnownWidth(w) if w >= that => this
173172
case _ if this.isLit => this._padLit(that)
174173
case _ => binop(sourceInfo, cloneTypeWidth(this.width.max(Width(that))), PadOp, that)
@@ -223,7 +222,8 @@ private[chisel3] trait UIntImpl extends BitsImpl with Num[UInt] { self: UInt =>
223222
}
224223
}
225224

226-
private[chisel3] override def cloneTypeWidth(w: Width): UInt = new UInt(w)
225+
private[chisel3] override def cloneTypeWidth(w: Width): this.type =
226+
new UInt(w).asInstanceOf[this.type]
227227

228228
override protected def _padLit(that: Int): this.type = {
229229
val value = this.litValue
@@ -403,7 +403,8 @@ private[chisel3] trait SIntImpl extends BitsImpl with Num[SInt] { self: SInt =>
403403
}
404404
}
405405

406-
private[chisel3] override def cloneTypeWidth(w: Width): SInt = new SInt(w)
406+
private[chisel3] override def cloneTypeWidth(w: Width): this.type =
407+
new SInt(w).asInstanceOf[this.type]
407408

408409
override protected def _padLit(that: Int): this.type = {
409410
val value = this.litValue
@@ -528,7 +529,7 @@ private[chisel3] trait ResetTypeImpl extends Element { self: Reset =>
528529

529530
override def toString: String = stringAccessor("Reset")
530531

531-
override def _cloneType: Data = Reset()
532+
def cloneType: this.type = Reset().asInstanceOf[this.type]
532533

533534
override def litOption: Option[BigInt] = None
534535

@@ -557,7 +558,7 @@ private[chisel3] trait AsyncResetImpl extends Element { self: AsyncReset =>
557558

558559
override def toString: String = stringAccessor("AsyncReset")
559560

560-
override def _cloneType: Data = AsyncReset()
561+
def cloneType: this.type = AsyncReset().asInstanceOf[this.type]
561562

562563
override def litOption: Option[BigInt] = None
563564

@@ -598,9 +599,9 @@ private[chisel3] trait BoolImpl extends UIntImpl { self: Bool =>
598599
}
599600
}
600601

601-
private[chisel3] override def cloneTypeWidth(w: Width): Bool = {
602+
private[chisel3] override def cloneTypeWidth(w: Width): this.type = {
602603
require(!w.known || w.get == 1)
603-
new Bool()
604+
new Bool().asInstanceOf[this.type]
604605
}
605606

606607
/** Convert to a [[scala.Option]] of [[scala.Boolean]] */

core/src/main/scala/chisel3/ChiselEnumImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private[chisel3] abstract class EnumTypeImpl(private[chisel3] val factory: Chise
3030
}
3131
}
3232

33-
override def _cloneType: Data = factory()
33+
override def cloneType: this.type = factory().asInstanceOf[this.type]
3434

3535
private[chisel3] def compop(sourceInfo: SourceInfo, op: PrimOp, other: EnumType): Bool = {
3636
requireIsHardware(this, "bits operated on")

core/src/main/scala/chisel3/ClockImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ private[chisel3] trait ClockImpl extends Element {
1313

1414
override def toString: String = stringAccessor("Clock")
1515

16-
override def _cloneType: Data = Clock()
16+
def cloneType: this.type = Clock().asInstanceOf[this.type]
1717

1818
override def connect(that: Data)(implicit sourceInfo: SourceInfo): Unit =
1919
that match {

core/src/main/scala/chisel3/DataImpl.scala

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package chisel3
44

55
import chisel3.experimental.dataview.reify
66

7-
import chisel3.Data.DataExtensions
87
import chisel3.experimental.{requireIsChiselType, requireIsHardware, Analog, BaseModule}
98
import chisel3.experimental.{prefix, SourceInfo, UnlocatableSourceInfo}
109
import chisel3.experimental.dataview.{reifyIdentityView, reifySingleTarget, DataViewable}
@@ -782,12 +781,28 @@ private[chisel3] trait DataImpl extends HasId with NamedComponent { self: Data =
782781
private[chisel3] def width: Width
783782
private[chisel3] def firrtlConnect(that: Data)(implicit sourceInfo: SourceInfo): Unit
784783

785-
/** Private implementation of cloneType
784+
/** Internal API; Chisel users should look at chisel3.chiselTypeOf(...).
786785
*
787-
* _cloneType must be defined for any Chisel object extending Data.
788-
* It is implemented by Chisel itself or by the compiler plugin for user-defined types.
786+
* cloneType must be defined for any Chisel object extending Data.
787+
* It is responsible for constructing a basic copy of the object being cloned.
788+
*
789+
* @return a copy of the object.
790+
*/
791+
def cloneType: this.type
792+
793+
/** Internal API; Chisel users should look at chisel3.chiselTypeOf(...).
794+
*
795+
* Returns a copy of this data type, with hardware bindings (if any) removed.
796+
* Directionality data and probe information is still preserved.
789797
*/
790-
def _cloneType: Data
798+
private[chisel3] def cloneTypeFull: this.type = {
799+
val clone = this.cloneType // get a fresh object, without bindings
800+
// Only the top-level direction needs to be fixed up, cloneType should do the rest
801+
clone.specifiedDirection = specifiedDirection
802+
probe.setProbeModifier(clone, probeInfo)
803+
clone.isConst = isConst
804+
clone
805+
}
791806

792807
/** The "strong connect" operator.
793808
*
@@ -979,7 +994,6 @@ private[chisel3] trait ObjectDataImpl {
979994
*
980995
* @param lhs The [[Data]] hardware on the left-hand side of the equality
981996
*/
982-
// TODO fold this into DataExtensions
983997
implicit class DataEquality[T <: Data](lhs: T)(implicit sourceInfo: SourceInfo) {
984998

985999
/** Dynamic recursive equality operator for generic [[Data]]
@@ -1058,33 +1072,6 @@ private[chisel3] trait ObjectDataImpl {
10581072
}
10591073
}
10601074
}
1061-
1062-
implicit class DataExtensions[T <: Data](self: T) {
1063-
1064-
/** Internal API; Chisel users should look at chisel3.chiselTypeOf(...).
1065-
*
1066-
* cloneType must be defined for any Chisel object extending Data.
1067-
* It is responsible for constructing a basic copy of the object being cloned.
1068-
*
1069-
* @return a copy of the object.
1070-
*/
1071-
def cloneType: T = self._cloneType.asInstanceOf[T]
1072-
1073-
/** Internal API; Chisel users should look at chisel3.chiselTypeOf(...).
1074-
*
1075-
* Returns a copy of this data type, with hardware bindings (if any) removed.
1076-
* Directionality data and probe information is still preserved.
1077-
*/
1078-
private[chisel3] def cloneTypeFull: T = {
1079-
val clone = self.cloneType // get a fresh object, without bindings
1080-
// Only the top-level direction needs to be fixed up, cloneType should do the rest
1081-
clone.specifiedDirection = self.specifiedDirection
1082-
// TODO do we need to exclude probe and const from cloneTypeFull on Properties?
1083-
probe.setProbeModifier(clone, self.probeInfo)
1084-
clone.isConst = self.isConst
1085-
clone.asInstanceOf[T]
1086-
}
1087-
}
10881075
}
10891076

10901077
trait WireFactory {
@@ -1256,8 +1243,7 @@ final case object DontCare extends Element with connectable.ConnectableDocs {
12561243
private[chisel3] override val width: Width = UnknownWidth
12571244

12581245
bind(DontCareBinding(), SpecifiedDirection.Output)
1259-
1260-
override def _cloneType: Data = DontCare
1246+
override def cloneType: this.type = DontCare
12611247

12621248
override def toString: String = "DontCare()"
12631249

core/src/main/scala/chisel3/IO.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package chisel3
22

3-
import chisel3.Data.DataExtensions
43
import chisel3.internal.{throwException, Builder}
54
import chisel3.experimental.{noPrefix, requireIsChiselType, SourceInfo}
65
import chisel3.properties.{Class, Property}

core/src/main/scala/chisel3/Intrinsic.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
package chisel3
44

55
import chisel3._
6-
import chisel3.Data.DataExtensions
76
import chisel3.experimental.{requireIsChiselType, Param, SourceInfo}
87
import chisel3.internal.firrtl.ir._
98
import chisel3.internal.Builder

core/src/main/scala/chisel3/MemImpl.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import chisel3.internal.binding._
99
import chisel3.internal.Builder.pushCommand
1010
import chisel3.internal.firrtl.ir._
1111
import chisel3.experimental.{requireIsChiselType, requireIsHardware, SourceInfo, SourceLine}
12-
import chisel3.Data.DataExtensions
1312

1413
private[chisel3] trait ObjectMemImpl {
1514

core/src/main/scala/chisel3/ModuleImpl.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import chisel3.internal.plugin.autoNameRecursively
2828
import chisel3.util.simpleClassName
2929
import chisel3.experimental.{annotate, ChiselAnnotation}
3030
import chisel3.experimental.hierarchy.Hierarchy
31-
import chisel3.Data.DataExtensions
3231

3332
private[chisel3] trait ObjectModuleImpl {
3433

@@ -371,7 +370,7 @@ package internal {
371370
private[chisel3] class ClonePorts(elts: (String, Data)*) extends Record {
372371
val elements: ListMap[String, Data] = ListMap(elts.map { case (name, d) => name -> d.cloneTypeFull }: _*)
373372
def apply(field: String) = elements(field)
374-
override protected def _cloneTypeImpl: Record = (new ClonePorts(elts: _*))
373+
override def cloneType = (new ClonePorts(elts: _*)).asInstanceOf[this.type]
375374
}
376375

377376
private[chisel3] def cloneIORecord(

0 commit comments

Comments
 (0)