summaryrefslogtreecommitdiff
path: root/core/src/main/scala/chisel3/Aggregate.scala
diff options
context:
space:
mode:
authormergify[bot]2022-10-17 22:50:55 +0000
committerGitHub2022-10-17 22:50:55 +0000
commit1957f5ef5c43439144cf779a343707872ca92d6a (patch)
treea13298b8b9fbe0d2130800e25e2faf75e5891487 /core/src/main/scala/chisel3/Aggregate.scala
parent1e9f4e99167d1bc132a1a1a04e6987c2161c4d0e (diff)
Add opt-in AutoCloneType for Records (backport #2781) (#2785)
* Add opt-in AutoCloneType for Records (#2781) There is a new trait, chisel3.experimental.AutoCloneType that is mixed in to Bundle and can optionally be mixed in to user-defined Records. The compiler plugin prints a deprecation warning on any user-defined implementation of cloneType, telling the user to mix in AutoCloneType before upgrading to 3.6. (cherry picked from commit a234fd48ac8f5942c38fef5797292014e407b586) # Conflicts: # core/src/main/scala/chisel3/Aggregate.scala # plugin/src/main/scala/chisel3/internal/plugin/BundleComponent.scala * Resolve backport conflicts * Do not make MixedVec extend AutoCloneType It is a binary incompatible change that can wait for 3.6. * Waive MiMa false positives Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'core/src/main/scala/chisel3/Aggregate.scala')
-rw-r--r--core/src/main/scala/chisel3/Aggregate.scala32
1 files changed, 22 insertions, 10 deletions
diff --git a/core/src/main/scala/chisel3/Aggregate.scala b/core/src/main/scala/chisel3/Aggregate.scala
index 042e78b1..aacf0b1c 100644
--- a/core/src/main/scala/chisel3/Aggregate.scala
+++ b/core/src/main/scala/chisel3/Aggregate.scala
@@ -1158,6 +1158,16 @@ abstract class Record(private[chisel3] implicit val compileOptions: CompileOptio
* Results in "`\$className(elt0.name -> elt0.value, ...)`"
*/
def toPrintable: Printable = toPrintableHelper(elements.toList)
+
+ /** Implementation of cloneType that is [optionally for Record] overridden by the compiler plugin
+ *
+ * @note This should _never_ be overridden or called in user-code
+ */
+ protected def _cloneTypeImpl: Record = {
+ throwException(
+ s"Internal Error! This should have been implemented by the chisel3-plugin. Please file an issue against chisel3"
+ )
+ }
}
/**
@@ -1182,6 +1192,15 @@ package experimental {
class BundleLiteralException(message: String) extends ChiselException(message)
class VecLiteralException(message: String) extends ChiselException(message)
+ /** Indicates that the compiler plugin should generate [[cloneType]] for this type
+ *
+ * All user-defined [[Record]]s should mix this trait in as it will be required for upgrading to Chisel 3.6.
+ */
+ trait AutoCloneType { self: Record =>
+
+ override def cloneType: this.type = _cloneTypeImpl.asInstanceOf[this.type]
+
+ }
}
/** Base class for data types defined as a bundle of other data types.
@@ -1217,7 +1236,7 @@ package experimental {
* }
* }}}
*/
-abstract class Bundle(implicit compileOptions: CompileOptions) extends Record {
+abstract class Bundle(implicit compileOptions: CompileOptions) extends Record with experimental.AutoCloneType {
assert(
_usingPlugin,
"The Chisel compiler plugin is now required for compiling Chisel code. " +
@@ -1385,15 +1404,8 @@ abstract class Bundle(implicit compileOptions: CompileOptions) extends Record {
clone
}
- /** Implementation of cloneType using runtime reflection. This should _never_ be overridden or called in user-code
- *
- * @note This is overridden by the compiler plugin (this implementation is never called)
- */
- protected def _cloneTypeImpl: Bundle = {
- throwException(
- s"Internal Error! This should have been implemented by the chisel3-plugin. Please file an issue against chisel3"
- )
- }
+ // This is overriden for binary compatibility reasons in 3.5
+ override protected def _cloneTypeImpl: Bundle = super._cloneTypeImpl.asInstanceOf[Bundle]
/** Default "pretty-print" implementation
* Analogous to printing a Map