Description
Type of issue: Bug Report
Please provide the steps to reproduce the problem:
Here's a scala-cli template which will recreate the error:
//> using scala "2.13.12"
//> using lib "org.chipsalliance::chisel::6.0.0-RC1"
//> using plugin "org.chipsalliance:::chisel-plugin::6.0.0-RC1"
//> using options "-unchecked", "-deprecation", "-language:reflectiveCalls", "-feature", "-Xcheckinit", "-Xfatal-warnings", "-Ywarn-dead-code", "-Ywarn-unused", "-Ymacro-annotations"
import chisel3._
import chisel3.experimental.hierarchy.{Definition, Instance, instantiable, public}
import circt.stage.ChiselStage
@instantiable
class AddOne(val width: Int) extends Module {
@public val width = width
@public val in = IO(Input(UInt(width.W)))
@public val out = IO(Output(UInt(width.W)))
out := in + 1.U
}
@instantiable
class AddTwo(addOneDef: Definition[AddOne]) extends Module {
val i0 = Instance(addOneDef)
val i1 = Instance(addOneDef)
@public val in = IO(Input(UInt(addOneDef.width.W)))
@public val out = IO(Output(UInt(addOneDef.width.W)))
i0.in := in
i1.in := i0.out
out := i1.out
}
class Foo extends Module {
val addOneDef = Definition(new AddOne(4))
val addTwoDef = Definition(new AddTwo(addOneDef))
val in = IO(Input(UInt(addOneDef.width.W)))
val out = IO(Output(UInt(addOneDef.width.W)))
val addTwo = Instance(addTwoDef)
addTwo.in := in
out := addTwo.out
}
object Main extends App {
println(
ChiselStage.emitSystemVerilog(
gen = new Foo,
firtoolOpts = Array("-disable-all-randomization", "-strip-debug-info")
)
)
}
What is the current behavior?
Executing this yields the following exception:
Exception in thread "main" chisel3.package$ChiselException: Imported Definition information not found - possibly forgot to add ImportDefinition annotation?
at ... ()
at AddTwo.$anonfun$i0$1(chisel-template.scala:20)
at chisel3.internal.plugin.package$.autoNameRecursively(package.scala:33)
at AddTwo.<init>(chisel-template.scala:20)
at Foo.$anonfun$addTwoDef$1(chisel-template.scala:31)
at chisel3.Module$.do_apply(Module.scala:62)
at chisel3.experimental.hierarchy.core.Definition$.$anonfun$do_apply$1(Definition.scala:108)
at chisel3.internal.Builder$.$anonfun$build$1(Builder.scala:970)
at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
at chisel3.internal.Builder$.build(Builder.scala:964)
at chisel3.experimental.hierarchy.core.Definition$.do_apply(Definition.scala:108)
at Foo.<init>(chisel-template.scala:31)
at Main$.$anonfun$new$7(chisel-template.scala:45)
at ... ()
at ... (Stack trace trimmed to user code only. Rerun with --full-stacktrace to see the full stack trace)
Program exited with return code 1.
Line 20 of chisel-template.scala
refers to the val i0 = Instance(addOneDef)
statement, so the first time an Instance
is created inside of the AddTwo
Definition
.
What is the expected behavior?
The D/I API should work with nested Instance
s.
Please tell us about your environment:
- version: 6.0 RC-1
- OS: macOS 14.2.1
Other Information
Changing from Instance(addOneDef)
to Instantiate(new AddOne(4))
makes the error go away, but both the Definition
and Instantiate
APIs have their uses, so I figure supporting nested Instance
s still makes sense.