From 75bf5b3c96ab4580576dbc4bc2177c244427db96 Mon Sep 17 00:00:00 2001 From: Schuyler Eldridge Date: Tue, 10 Dec 2024 19:53:14 -0500 Subject: [PATCH] fixup! [core] Add private Layer.layerSeq member function --- core/src/main/scala/chisel3/Layer.scala | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/core/src/main/scala/chisel3/Layer.scala b/core/src/main/scala/chisel3/Layer.scala index 6c5d1bf73b..823c2f396b 100644 --- a/core/src/main/scala/chisel3/Layer.scala +++ b/core/src/main/scala/chisel3/Layer.scala @@ -161,18 +161,17 @@ object layer { case _ => this.canWriteTo(that.parent) } - /** Return a sequence of this layer and all its parents, excluding the root layer. + /** Return a list containg this layer and all its parents, excluding the root + * layer. The deepest layer (this layer) is the first element in the list. * * @return a sequence of all layers */ - private[chisel3] def layerSeq: Seq[Layer] = { - var currentLayer: Layer = this - val layers = ArrayBuffer.empty[Layer] - while (currentLayer != Layer.Root) { - layers.addOne(currentLayer) - currentLayer = currentLayer.parent + private[chisel3] def layerSeq: List[Layer] = { + def rec(current: Layer, acc: List[Layer]): List[Layer] = current match { + case Layer.root => acc + case _ => rec(current.parent, current :: acc) } - layers.reverse.toSeq + rec(this, Nil) } }