@@ -173,8 +173,8 @@ private[chisel3] class DynamicContext() {
173
173
var currentClockAndReset : Option [ClockAndReset ] = None
174
174
val errors = new ErrorLog
175
175
val namingStack = new internal.naming.NamingStack
176
- // Record the Bundle instance, class name, and reverse stack trace position of open Bundles
177
- val bundleStack : ArrayBuffer [(Bundle , String , Int )] = ArrayBuffer ()
176
+ // Record the Bundle instance, class name, method name, and reverse stack trace position of open Bundles
177
+ val bundleStack : ArrayBuffer [(Bundle , String , String , Int )] = ArrayBuffer ()
178
178
}
179
179
180
180
private [chisel3] object Builder {
@@ -247,24 +247,29 @@ private[chisel3] object Builder {
247
247
// Returns the current stack of open Bundles
248
248
// Note: elt will NOT have finished construction, its elements cannot be accessed
249
249
def updateBundleStack (elt : Bundle ): Seq [Bundle ] = {
250
- val stackClasses = Thread .currentThread().getStackTrace()
251
- .map(_.getClassName)
250
+ val stackElts = Thread .currentThread().getStackTrace()
252
251
.reverse // so stack frame numbers are deterministic across calls
252
+ .dropRight(2 ) // discard Thread.getStackTrace and updateBundleStack
253
+
254
+ // Determine where we are in the Bundle stack
255
+ val eltClassName = elt.getClass.getName
256
+ val eltStackPos = stackElts.map(_.getClassName).lastIndexOf(eltClassName)
253
257
254
258
// Prune the existing Bundle stack of closed Bundles
255
- val pruneLength = dynamicContext.bundleStack.reverse.prefixLength { case (_, cname, pos) =>
256
- pos >= stackClasses.size || stackClasses(pos) != cname
259
+ // If we know where we are in the stack, discard frames above that
260
+ val stackEltsTop = if (eltStackPos >= 0 ) eltStackPos else stackElts.size
261
+ val pruneLength = dynamicContext.bundleStack.reverse.prefixLength { case (_, cname, mname, pos) =>
262
+ pos >= stackEltsTop || stackElts(pos).getClassName != cname || stackElts(pos).getMethodName != mname
257
263
}
258
264
dynamicContext.bundleStack.trimEnd(pruneLength)
259
265
260
266
// Return the stack state before adding the most recent bundle
261
267
val lastStack = dynamicContext.bundleStack.map(_._1).toSeq
262
268
263
269
// Append the current Bundle to the stack, if it's on the stack trace
264
- val eltClassName = elt.getClass.getName
265
- val eltStackPos = stackClasses.lastIndexOf(eltClassName)
266
270
if (eltStackPos >= 0 ) {
267
- dynamicContext.bundleStack.append((elt, eltClassName, eltStackPos))
271
+ val stackElt = stackElts(eltStackPos)
272
+ dynamicContext.bundleStack.append((elt, eltClassName, stackElt.getMethodName, eltStackPos))
268
273
}
269
274
// Otherwise discard the stack frame, this shouldn't fail noisily
270
275
0 commit comments