Skip to content

Commit b7ee721

Browse files
committed
Fix layer.enable applying to all later modules
Fix a bug where use of the `layer.enable` API would incorrect cause a propagation of layers being enabled to all subsequent modules. This was due to a bug in how the state save/restore logic worked. Fixes #4839. Signed-off-by: Schuyler Eldridge <[email protected]>
1 parent 8c87bb3 commit b7ee721

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

core/src/main/scala/chisel3/internal/Builder.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,8 @@ private[chisel3] object Builder extends LazyLogging {
12271227
Builder.setPrefix(state.prefix)
12281228
Builder.currentClock = state.clock
12291229
Builder.currentReset = state.reset
1230-
Builder.enabledLayers = enabledLayers
1230+
Builder.enabledLayers.clear()
1231+
Builder.enabledLayers ++= state.enabledLayers
12311232
}
12321233

12331234
/** Run the `thunk` with the context provided by `state`. Save the [[Builder]]

src/test/scala-2/chiselTests/LayerSpec.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,23 @@ class LayerSpec extends AnyFlatSpec with Matchers with FileCheck {
216216

217217
}
218218

219+
they should ", when enabled, not propagate to child modules" in {
220+
221+
class Bar extends RawModule
222+
223+
class Foo extends RawModule {
224+
layer.enable(A)
225+
val bar = Module(new Bar)
226+
}
227+
228+
ChiselStage.emitCHIRRTL(new Foo).fileCheck() {
229+
"""|CHECK: module Bar :
230+
|CHECK: module Foo enablelayer A :
231+
|""".stripMargin
232+
}
233+
234+
}
235+
219236
they should "work correctly with Definition/Instance" in {
220237

221238
@instantiable

0 commit comments

Comments
 (0)