Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutocloneType Stripping Hardware type? #3289

Open
seldridge opened this issue May 18, 2023 · 1 comment
Open

AutocloneType Stripping Hardware type? #3289

seldridge opened this issue May 18, 2023 · 1 comment
Labels

Comments

@seldridge
Copy link
Member

Autoclonetype converts all hardware types to Chisel types. This can create a situation where the user wrote a Bundle in such a way that they need to have the hardware type preserved. If they rely on this, this can cause a runtime crash.

Consider the following example. Here, I have a tieoff() method in a Bundle named Bar. I chose to parameterize this with the value to tieoff the bundle with. However, if I clone that Bundle, the method no longer works. the tieoff value is now a bare Chisel type.

//> using scala "2.13.10"
//> using repository "https://s01.oss.sonatype.org/content/repositories/snapshots"
//> using lib "org.chipsalliance::chisel::5.0.0-RC1+38-7b0abd90-SNAPSHOT"
//> using plugin "org.chipsalliance:::chisel-plugin::5.0.0-RC1+38-7b0abd90-SNAPSHOT"
//> using options "-Ymacro-annotations"

import chisel3._
import circt.stage.ChiselStage

class Bar(default: Bool) extends Bundle {
  val a = Output(Bool())
  def tieoff() = {
    println("default is a: " + default)
    a := default
  }
}

class Foo extends Module {
  val io = IO(new Bar(true.B))
  val io2 = IO(io.cloneType)
  io.tieoff()
  io2.tieoff()
}

object Main extends App {
  println(ChiselStage.emitCHIRRTL(new Foo))
}

The above errors with:

# scala-cli Bar.scala
Compiling project (Scala 2.13.10, JVM)
Compiled project (Scala 2.13.10, JVM)
default is a: Bool(true)
default is a: Bool
Exception in thread "main" chisel3.package$ExpectedHardwareException: data to be connected 'Bool' must be hardware, not a bare Chisel type. Perhaps you forgot to wrap it in Wire(_) or IO(_)?
        at ... ()
        at Bar.tieoff(Bar.scala:14)
        at Foo.<init>(Bar.scala:22)
        at Main$.$anonfun$new$1(Bar.scala:26)
        at ... ()
        at ... (Stack trace trimmed to user code only. Rerun with --full-stacktrace to see the full stack trace)
@seldridge seldridge added the bug label May 18, 2023
@jackkoenig
Copy link
Contributor

This happens so that we can support Bundles like

class Foo[T <: Data](gen: T) extends Bundle {
  val foo = gen
}
// or
case class Bar[T <: Data](bar: T) extends Bundle

We could probably change autoclonetype to insert a chiselTypeClone(...) (the equivalent of Aligned(...) or the old Field(...) proposal) around val foo = gen and around the implicit val bar = _bar in the case class. Then we would no longer need to clone the constructor arguments which would be more sound and fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants