chipsalliance / chipsalliance/chisel
Aspects Don't Run If Added Via annotate
- Dominant language
- Scala
- Stars
- 4.8k
- Forks
- 658
- Avg merge
- 18h 59m
- Merged PRs (30d)
- 14
Description
Chisel's `MaybeAspectPhase` relies on looking for aspect annotations to know which to run. However, Chisel only creates annotations in its `Convert` phase. This means that aspects added via the `annotate` method will be silently dropped.
The `Convert` phase should be broken up into two phases:
1. Generates annotations phase
2. Conversion of Chisel circuit to FIRRTL circuit
This is tricky to untangle deterministically as aspects consume annotations, but also may generate annotations. The current solution is nicely restrictive in that you can't get into a loop. However, it would also be acceptable if a phase was added that disallowed generation of aspects (so at least the user knows what's going on).
```scala
import chisel3._
import chisel3.aop.injecting.InjectingAspect
import chisel3.experimental.{
annotate,
ChiselAnnotation
}
import chisel3.stage.ChiselStage
class Foo extends MultiIOModule {
Some(
new ChiselAnnotation {
override def toFirrtl = new FooAspect
}
).foreach(annotate(_))
}
class FooAspect extends InjectingAspect(
{dut: Foo => Seq(dut)},
{dut: Foo => println("hello") } /* "hello" won't print because FooAspect doesn't run! */
)
ChiselStage.emitChirrtl(new Foo)
```
https://scastie.scala-lang.org/oTrhcwdOQpC3ZvEBeqEXng
**Type of issue**: bug report
**Impact**: unknown
**Development Phase**: request
**Please tell us about your environment:**
- Chisel 3.4.0
**What is the use case for changing the behavior?**
Either a new error for something that is silently not done now or better functionality for users writing aspects.
Contributor guide
Research direction
Start by tracing the ChiselStage phase pipeline, especially MaybeAspectPhase and Convert, and reproduce the provided annotate example. Determine how annotations generated during conversion interact with aspects, then verify that the example's FooAspect runs or that an explicit error reports the unsupported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100