Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report Builder errors even when exception is thrown #3341

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions core/src/main/scala/chisel3/internal/Builder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import logger.LazyLogging
import scala.collection.mutable
import scala.annotation.tailrec
import java.io.File
import scala.util.control.NonFatal

private[chisel3] class Namespace(keywords: Set[String], separator: Char = '_') {
// This HashMap is compressed, not every name in the namespace is present here.
Expand Down Expand Up @@ -827,10 +828,20 @@ private[chisel3] object Builder extends LazyLogging {
ViewParent: Unit // Must initialize the singleton in a Builder context or weird things can happen
// in tiny designs/testcases that never access anything in chisel3.internal
logger.info("Elaborating design...")
val mod = f
if (forceModName) { // This avoids definition name index skipping with D/I
mod.forceName(mod.name, globalNamespace)
}
val mod =
try {
val m = f
if (forceModName) { // This avoids definition name index skipping with D/I
m.forceName(m.name, globalNamespace)
}
m
} catch {
case NonFatal(e) =>
// Make sure to report any aggregated errors in case the Exception is due to a tainted return value
// Note that errors.checkpoint may throw an Exception which will suppress e
jackkoenig marked this conversation as resolved.
Show resolved Hide resolved
errors.checkpoint(logger)
throw e
}
errors.checkpoint(logger)
logger.info("Done elaborating.")

Expand Down
14 changes: 14 additions & 0 deletions src/test/scala/circtTests/stage/ChiselStageSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,20 @@ class ChiselStageSpec extends AnyFunSpec with Matchers with chiselTests.Utils {
val version = chisel3.BuildInfo.firtoolVersion.getOrElse("<unknown>")
e.getMessage should include(s"firtool version $version")
}

it("should properly report Builder.errors even if there is a later Exception") {
val (log, _) = grabLog {
intercept[java.lang.Exception] {
import chisel3._
ChiselStage.emitCHIRRTL(new Module {
val in = IO(Input(UInt(8.W)))
val y = in >> -1
require(false) // This should not suppress reporting the negative shift
})
}
}
log should include("Negative shift amounts are illegal (got -1)")
}
}

describe("ChiselStage custom transform support") {
Expand Down