chisel icon indicating copy to clipboard operation
chisel copied to clipboard

Hierarchy API does not support @public on `val`s in constructors

Open debs-sifive opened this issue 3 years ago • 5 comments

Type of issue: feature request

Impact: API addition (no impact on existing code)

Development Phase: request

Other information

This is pretty easy to work around, but it might be nice to have support for this.

https://scastie.scala-lang.org/debs-sifive/zAVcJfvxTnGqhKLbTa7sUw/51

This does not work:

@instantiable
class PassThrough(@public val hello: String) extends Module {
  ...

Workaround:

@instantiable
class PassThrough(val hello: String) extends Module {
  @public val hello = hello
  ...

Please tell us about your environment: See Scastie.

What is the use case for changing the behavior? Less typing.

debs-sifive avatar Feb 02 '22 21:02 debs-sifive

I think the workaround is the documented behavior...

mwachs5 avatar Feb 02 '22 21:02 mwachs5

@mwachs5 do you know where that's documented?

debs-sifive avatar Feb 02 '22 21:02 debs-sifive

See the hierarchy cookbook, search for @public val clock

mwachs5 avatar Feb 02 '22 21:02 mwachs5

https://github.com/chipsalliance/chisel3/blob/master/docs/src/cookbooks/hierarchy.md

To mark a superclass's member as @public, use the following pattern (shown with val clock).

import chisel3._
import chisel3.experimental.hierarchy.{instantiable, public}

@instantiable
class MyModule extends Module {
  @public val clock = clock
}

mwachs5 avatar Feb 02 '22 21:02 mwachs5

Oh gotcha, yes the workaround is pretty much to do what's normal. I just think it's kind of confusing/verbose to have to make another val and @public the second one.

debs-sifive avatar Feb 02 '22 22:02 debs-sifive