Skip to content

Commit fe54768

Browse files
authored
Support concatenating properties of Seq subtypes (#4907)
1 parent d4acb2e commit fe54768

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

core/src/main/scala/chisel3/properties/Property.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,9 @@ object PropertySequenceOps {
454454
import PropertyExpressionHelpers._
455455

456456
// Type class instances for Property sequence operations.
457-
implicit def seqOps[U]: PropertySequenceOps[Property[Seq[U]]] =
458-
new PropertySequenceOps[Property[Seq[U]]] {
459-
def concat(lhs: Property[Seq[U]], rhs: Property[Seq[U]])(implicit sourceInfo: SourceInfo) =
457+
implicit def seqOps[U, S[U] <: Seq[U]]: PropertySequenceOps[Property[S[U]]] =
458+
new PropertySequenceOps[Property[S[U]]] {
459+
def concat(lhs: Property[S[U]], rhs: Property[S[U]])(implicit sourceInfo: SourceInfo) =
460460
binOp(sourceInfo, fir.ListConcatOp, lhs, rhs)
461461
}
462462
}

src/test/scala-2/chiselTests/properties/PropertySpec.scala

+36
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,42 @@ class PropertySpec extends AnyFlatSpec with Matchers with FileCheck {
360360
)
361361
}
362362

363+
it should "support concatenation of Property[Seq[Int]]" in {
364+
ChiselStage.emitCHIRRTL {
365+
new RawModule {
366+
val seqProp1 = IO(Input(Property[Seq[Int]]()))
367+
val seqProp2 = IO(Input(Property[Seq[Int]]()))
368+
val seqProp3 = IO(Output(Property[Seq[Int]]()))
369+
seqProp3 := seqProp1 ++ seqProp2
370+
}
371+
}.fileCheck()(
372+
"""|CHECK: input seqProp1 : List<Integer>
373+
|CHECK: input seqProp2 : List<Integer>
374+
|CHECK: output seqProp3 : List<Integer>
375+
|CHECK: wire _seqProp3_propExpr : List<Integer>
376+
|CHECK: propassign _seqProp3_propExpr, list_concat(seqProp1, seqProp2)
377+
|""".stripMargin
378+
)
379+
}
380+
381+
it should "support concatenation of Property[List[Int]]" in {
382+
ChiselStage.emitCHIRRTL {
383+
new RawModule {
384+
val listProp1 = IO(Input(Property[List[Int]]()))
385+
val listProp2 = IO(Input(Property[List[Int]]()))
386+
val listProp3 = IO(Output(Property[List[Int]]()))
387+
listProp3 := listProp1 ++ listProp2
388+
}
389+
}.fileCheck()(
390+
"""|CHECK: input listProp1 : List<Integer>
391+
|CHECK: input listProp2 : List<Integer>
392+
|CHECK: output listProp3 : List<Integer>
393+
|CHECK: wire _listProp3_propExpr : List<Integer>
394+
|CHECK: propassign _listProp3_propExpr, list_concat(listProp1, listProp2)
395+
|""".stripMargin
396+
)
397+
}
398+
363399
it should "not support types with nested Property[_]" in {
364400
assertTypeError("Property[Property[Property[Int]]]()")
365401
assertTypeError("Property[Property[Seq[Property[Int]]]]()")

0 commit comments

Comments
 (0)