8000 Error creating Instance inside an Instance · Issue #3708 · chipsalliance/chisel · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Error creating Instance inside an Instance #3708
Closed
@tymcauley

Description

@tymcauley

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 Instances.

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 Instances still makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0