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

Selecting instances when using D/I and Class Property types crashes #4476

Open
jackkoenig opened this issue Oct 16, 2024 · 1 comment
Open

Comments

@jackkoenig
Copy link
Contributor

Type of issue: Bug Report

Please provide the steps to reproduce the problem:

    import chisel3.experimental.hierarchy._

    implicit val mg = new chisel3.internal.MacroGenerated {}

    class MyClass extends Class {
      val id = IO(Output(Property[Int]()))
      id := Property(3)
    }

    class Child extends Module {
      val cls = Definition(new MyClass)
      // This models SRAMDescription
      val io = IO(new Bundle {
        val metadata = cls.getPropertyType
      })
    }

    class Top extends Module {
      val c = Instantiate(new Child)

      val allInstances = Select.unsafe.allCurrentInstancesIn(this).map(_._lookup { m => m.name })
      println(allInstances)
    }

    println(ChiselStage.emitCHIRRTL(new Top))

What is the current behavior?

This crashes in _.lookup

What is the expected behavior?

It should not crash. and the only instance in allInstances should be c: Child.

Please tell us about your environment:

Other Information

What is the use case for changing the behavior?

@dtzSiFive
Copy link
Member

Simplified and executable reproducer (LMK if anything important was lost in the translation, but hopefully not):

//> using repository "sonatype-s01:snapshots"
//> using scala "2.13.15"
//> using dep "org.chipsalliance::chisel:7.0.0-M2+164-a7a68e52-SNAPSHOT"
//> using plugin "org.chipsalliance:::chisel-plugin:7.0.0-M2+164-a7a68e52-SNAPSHOT"
//> using options "-unchecked", "-deprecation", "-language:reflectiveCalls", "-feature", "-Xcheckinit", "-Xfatal-warnings", "-Ywarn-dead-code", "-Ywarn-unused", "-Ymacro-annotations"

import chisel3._
import circt.stage.ChiselStage
import chisel3.experimental.hierarchy._
import chisel3.properties._

import chisel3.aop.Select

class MyClass extends Class

class Child extends Module {
  val cls = Definition(new MyClass)

  // This models SRAMDescription
  val io = IO(new Bundle {
    val metadata = cls.getPropertyType
  })
}

class Top extends Module {
  val c = Instantiate(new Child)

  val allInstances = Select.unsafe.allCurrentInstancesIn(this)
  println(allInstances)
}

object Main extends App {
  println(ChiselStage.emitCHIRRTL(new Top, Array("--full-stacktrace", "--throw-on-first-error")))
}

And to elaborate on crashes here's the stack trace:

Exception in thread "main" chisel3.package$InternalErrorException: Internal Error: Please file an issue at https://github.com/chipsalliance/chisel3/issues:Match error: module=Clone(DefinitionClone(MyClass@32b9bd12))
	at chisel3.experimental.hierarchy.core.Lookupable$.cloneModuleToContext(Lookupable.scala:285)
	at chisel3.experimental.hierarchy.core.Lookupable$$anon$1.instanceLookup(Lookupable.scala:308)
	at chisel3.experimental.hierarchy.core.Lookupable$$anon$1.instanceLookup(Lookupable.scala:297)
	at chisel3.experimental.hierarchy.core.Instance._lookup(Instance.scala:68)
	at chisel3.aop.Select$unsafe$$anonfun$currentInstancesIn$2.applyOrElse(Select.scala:648)
	at chisel3.aop.Select$unsafe$$anonfun$currentInstancesIn$2.applyOrElse(Select.scala:646)

(snipped after)

Which comes from:

case _ => throw new InternalErrorException(s"Match error: module=$module")

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

No branches or pull requests

2 participants