Skip to content

Add DynamicGroup for runtime-defined option groups#5229

Open
uenoku wants to merge 4 commits intochipsalliance:mainfrom
uenoku:dev/hidetou/dynamic-choice-2
Open

Add DynamicGroup for runtime-defined option groups#5229
uenoku wants to merge 4 commits intochipsalliance:mainfrom
uenoku:dev/hidetou/dynamic-choice-2

Conversation

@uenoku
Copy link
Contributor

@uenoku uenoku commented Mar 11, 2026

Introduces a new DynamicGroup class that allows option groups and cases
to be defined with runtime parameters instead of requiring compile-time
singleton objects.

This enables more flexible option group definitions, particularly useful
for programmatically generated hardware where option groups cannot be
defined as static objects.

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you add appropriate documentation in docs/src?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • Feature (or new API)

Desired Merge Strategy

  • Squash: The PR will be squashed and merged (choose this if you have no preference).

Release Notes

Introduces a new DynamicGroup class that allows option groups
to be defined with runtime parameters instead

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels? (Select the most appropriate one based on the "Type of Improvement")
  • Did you mark the proper milestone (Bug fix: 3.6.x, 5.x, or 6.x depending on impact, API modification or big change: 7.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you do one of the following when ready to merge:
    • Squash: You/ the contributor Enable auto-merge (squash) and clean up the commit message.
    • Merge: Ensure that contributor has cleaned up their commit history, then merge with Create a merge commit.

@uenoku uenoku added the Feature New feature, will be included in release notes label Mar 11, 2026
@uenoku uenoku changed the title Add DynamicGroup for ModuleChoice Add DynamicGroup for runtime-defined option groups Mar 11, 2026
Copy link
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High-level: is there a way to do this which doesn't make everything string-based?

* @example {{{ val platform = new DynamicGroup("Platform", Seq("FPGA", "ASIC")) }}}
*/
class DynamicGroup(val groupName: String, caseNames: Seq[String])(implicit _sourceInfo: SourceInfo) {
import chisel3.internal.Builder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this is fine to include up top.

/** Dynamic option group that accepts a name and case names as runtime parameters.
* @example {{{ val platform = new DynamicGroup("Platform", Seq("FPGA", "ASIC")) }}}
*/
class DynamicGroup(val groupName: String, caseNames: Seq[String])(implicit _sourceInfo: SourceInfo) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love it due to the complexity, but this should probably implement the val naming with a suggestName method like other things in Chisel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I want to disallow that level of dynamic behavior. The group name is essentially user/designer facing API even when they are generated dynamically.

@uenoku
Copy link
Contributor Author

uenoku commented Mar 11, 2026

High-level: is there a way to do this which doesn't make everything string-based?

I can provide following level of trait based interface, though I didn't like it because of the amount of boilerplate.

trait PlatformType {
  def FPGA: Case
  def ASIC: Case
}
val platform = DynamicGroup[PlatformType]("Platform", Seq("FPGA", "ASIC")) { group =>
  new PlatformType {
    def FPGA = group("FPGA")
    def ASIC = group("ASIC")
  }
}
platform.FPGA

Ideally I wanted to do following but I thought scala3 reflection would be necessary to do this.

trait PlatformType {
  def FPGA: Case
  def ASIC: Case
}
val platform = DynamicGroup[PlatformType]("Platform")
platform.FPGA

@uenoku uenoku marked this pull request as ready for review March 13, 2026 08:14
@jackkoenig
Copy link
Contributor

We could make this work:

trait PlatformType extends DynamicGroup {
  object FPGA extends Case
  object ASIC extends Case
}
val platform = DynamicGroup[PlatformType]("Platform")
// or
val Platform = DynamicGroup(new PlatformType {})

Or something like that without Scala reflection

@uenoku uenoku marked this pull request as draft March 13, 2026 22:30
@uenoku
Copy link
Contributor Author

uenoku commented Mar 13, 2026

62ae69d implements trait based API that uses macro. I disclose that I needed quite a bit help from AI for writing DynamicGroupIntf.scala and it might be sloppy, so it might be better to start with a previous commit that's much more simpler. Though I believe that macro correctly implements API we generally want.

@uenoku uenoku marked this pull request as ready for review March 13, 2026 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature, will be included in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants