chipsalliance / chipsalliance/chisel

Recursive RegNext Breaks Naming

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

Description

I preface this by I think this is low priority and relatively rare to see.

Consider the following circuit that describe a register that increments by one, from a reset value of zero, forever:

```scala
class NonRecursiveRegister extends Module {
val a = RegInit(0.U(8.W))
a := a + 1.U
}
```

Now consider this circuit rewritten using a `RegNext`:

```scala
class RecursiveRegister extends Module {
val a: UInt = RegNext(aNext, 0.U(8.W))
val aNext = a + 1.U
}
```

This then crashes without a great error:

```
java.lang.NullPointerException: Cannot invoke "chisel3.Data.cloneTypeFull()" because "" is null
at ... ()
at Playground$RecursiveRegister$$anonfun$3$$anonfun$apply$2.apply(main.scala:15)
at Playground$RecursiveRegister$$anonfun$3$$anonfun$apply$2.apply(main.scala:15)
at chisel3.internal.prefix$.apply(prefix.scala:48)
at Playground$RecursiveRegister$$anonfun$3.apply(main.scala:15)
at Playground$RecursiveRegister$$anonfun$3.apply(main.scala)
at chisel3.internal.plugin.package$.autoNameRecursively(package.scala:33)
at Playground$RecursiveRegister.(main.scala:15)
at Playground$$anonfun$5.apply(main.scala:19)
at Playground$$anonfun$5.apply(main.scala:19)
at ... ()
```

I can recognize disallowing this with a better error message. However, this seems like something that should be capable of being expressed. I assume that it just needs a tweak to name prefixing to detect when this is happening. It can then either bail (generate a bad name) or, hopefully, generate a good name.

Scastie link: https://scastie.scala-lang.org/seldridge/K8KGN2kORfqPudn2dk2qJA/46

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.