Open
Description
If an exception occurs during the elaboration of a Chisel module, the naming prefix is not cleared. This can then leak the prefix to later invocations of the same builder.
I noticed this when dealing with a long string of failing Scalatest tests within the same test suite. As this is kind of weird, I put this on a branch here: https://github.com/chipsalliance/chisel/pull/new/dev/chisel-naming-prefix-bug
Snippet from that branch below:
behavior.of("Failed earlier tests")
it should "A" in {
class Foo extends RawModule {
override def localModulePrefix = Some("A")
throw new Exception("A")
}
intercept[Exception] {
ChiselStage.elaborate(new Foo)
}
}
it should "B" in {
class Foo extends RawModule {
override def localModulePrefix = Some("B")
}
ChiselStage
.emitCHIRRTL(new Foo)
.fileCheck()("CHECK: module B_Foo")
}
This will generate a module A_B_Foo
when it should be a module B_Foo
.
To run the example on the branch:
./mill 'chisel[2.13.16].test.testOnly' chiselTests.ModulePrefixSpec -- -z "Failed earlier tests"