chipsalliance / chipsalliance/chisel

Naming Prefix Preserved Across Failing Tests

Open
#4,941 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Scala
Stars
4.8k
Forks
658
Avg merge
18h 59m
Merged PRs (30d)
14

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:

``` scala
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"
```

Contributor guide

Open the contributing guide

Research direction

Start by running the provided mill command for chiselTests.ModulePrefixSpec and inspect the "Failed earlier tests" case in ModulePrefixSpec. Trace how ChiselStage.elaborate handles a failed module construction and how the naming prefix is retained. Done means the second module is emitted as B_Foo rather than A_B_Foo and the focused test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.