chipsalliance / chipsalliance/chisel
AutocloneType Stripping Hardware type?
- Dominant language
- Scala
- Stars
- 4.8k
- Forks
- 658
- Avg merge
- 18h 59m
- Merged PRs (30d)
- 14
Description
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.
```scala
//> 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.(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)
```
Contributor guide
Research direction
Start by running the inline Scala reproducer with scala-cli and inspect the cloneType behavior shown in Bar.scala. Trace how AutocloneType handles the parameter passed to Bar, then verify that the cloned bundle preserves a usable hardware value and that Foo no longer raises ExpectedHardwareException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100