Skip to content

Commit fb10fcf

Browse files
committed
Remove <: Data from ModuleChoice
AI-assisted-by: Claude Code (Claude Sonnet 4.6) Signed-off-by: Jack Koenig <koenig@sifive.com>
1 parent b295f09 commit fb10fcf

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/main/scala-2/chisel3/FixedIOModule.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ sealed trait FixedIOBaseModule[A] extends BaseModule {
2222

2323
protected implicit def dataProduct: DataProduct[A]
2424

25+
private[chisel3] def _lookupable: Lookupable[A] = lookupable
26+
2527
// No @public, lookups implemented manually in companion object.
2628
final val io: A = {
2729
val a = ioGenerator

src/main/scala-2/chisel3/choice/ModuleChoiceIntf.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ private[chisel3] trait ModuleChoiceObjIntf extends SourceInfoDoc { self: ModuleC
2929
*
3030
* @throws java.lang.IllegalArgumentException if the cases do not belong to the same option.
3131
*/
32-
def apply[T <: Data](
32+
def apply[T](
3333
default: => FixedIOBaseModule[T]
3434
)(choices: => Seq[(Case, () => FixedIOBaseModule[T])]): T =
3535
macro InstChoiceTransform.apply[T]
3636

3737
/** @group SourceInfoTransformMacro */
38-
def do_apply[T <: Data](
38+
def do_apply[T](
3939
default: => FixedIOBaseModule[T],
4040
choices: Seq[(Case, () => FixedIOBaseModule[T])]
4141
)(

src/main/scala-3/chisel3/FixedIOModule.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ sealed trait FixedIOBaseModule[A](using lookupable: Lookupable[A]) extends BaseM
1616
/** A generator of IO */
1717
protected def ioGenerator: A
1818

19+
private[chisel3] def _lookupable: Lookupable[A] = lookupable
20+
1921
@public final val io: A = {
2022
val dataElems = lookupable.in(ioGenerator)
2123
val names = LazyList.from(0).map(i => ('a' + i).toChar.toString)

src/main/scala-3/chisel3/choice/ModuleChoiceIntf.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
package chisel3.choice
44

5-
import chisel3.{Data, FixedIOBaseModule}
5+
import chisel3.FixedIOBaseModule
66
import chisel3.experimental.SourceInfo
77

88
private[chisel3] trait ModuleChoiceObjIntf { self: ModuleChoice.type =>
@@ -26,7 +26,7 @@ private[chisel3] trait ModuleChoiceObjIntf { self: ModuleChoice.type =>
2626
*
2727
* @throws java.lang.IllegalArgumentException if the cases do not belong to the same option.
2828
*/
29-
def apply[T <: Data](
29+
def apply[T](
3030
default: => FixedIOBaseModule[T],
3131
choices: Seq[(Case, () => FixedIOBaseModule[T])]
3232
)(

src/main/scala/chisel3/choice/ModuleChoice.scala

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,29 @@ import scala.collection.immutable.ListMap
66

77
import chisel3.{Data, FixedIOBaseModule, Module, SourceInfoDoc}
88
import chisel3.experimental.{BaseModule, SourceInfo}
9+
import chisel3.experimental.hierarchy.core.Lookupable
910
import chisel3.internal.{groupByIntoSeq, Builder}
1011
import chisel3.internal.binding.InstanceChoiceBinding
1112
import chisel3.internal.Builder.pushCommand
1213
import chisel3.internal.firrtl.ir.DefInstanceChoice
1314

1415
object ModuleChoice extends ModuleChoiceObjIntf {
1516

16-
protected def _applyImpl[T <: Data](
17+
protected def _applyImpl[T](
1718
default: => FixedIOBaseModule[T],
1819
choices: Seq[(Case, () => FixedIOBaseModule[T])]
1920
)(
2021
implicit sourceInfo: SourceInfo
2122
): T = {
2223
val instDefaultModule = Module.evaluate(default)
24+
val lk: Lookupable[T] = instDefaultModule._lookupable
25+
26+
val defaultLeaves = lk.in(instDefaultModule.io)
2327

2428
val choiceModules = choices.map { case (choice, module) =>
2529
val instModule = Module.evaluate(module())
26-
if (!instModule.io.typeEquivalent(instDefaultModule.io)) {
30+
val choiceLeaves = lk.in(instModule.io)
31+
if (!defaultLeaves.zip(choiceLeaves).forall { case (a, b) => b.typeEquivalent(a) }) {
2732
Builder.error("Error: choice module IO bundles are not type equivalent")
2833
}
2934
Builder.options += choice
@@ -46,13 +51,14 @@ object ModuleChoice extends ModuleChoiceObjIntf {
4651
}
4752
val group = groupedChoices.head.name
4853

49-
val binding = instDefaultModule.io.cloneTypeFull
50-
binding.bind(InstanceChoiceBinding(Builder.forcedUserModule, Builder.currentBlock))
54+
val bindingLeaves = defaultLeaves.map(_.cloneTypeFull)
55+
bindingLeaves.foreach(_.bind(InstanceChoiceBinding(Builder.forcedUserModule, Builder.currentBlock)))
56+
val binding = lk.out(instDefaultModule.io, bindingLeaves.iterator)
5157

5258
pushCommand(
5359
DefInstanceChoice(
5460
sourceInfo,
55-
binding,
61+
bindingLeaves.head,
5662
instDefaultModule,
5763
group,
5864
choiceModules.map { case (choice, instModule) =>

0 commit comments

Comments
 (0)