Skip to content

Commit cfe4e5e

Browse files
authored
Cleanup warnings final (#3021)
* In BoringUtils replace deprecated SyncVar with BuilderContextCache * Handle potential in-exhaustive match error * Changes lines to linesIterator to fix deprecation warning * Change build.sbt to make fatal warnings error come after suppressed warnings
1 parent 3c14563 commit cfe4e5e

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

build.sbt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ lazy val commonSettings = Seq(
3535
}
3636
)
3737

38+
lazy val fatalWarningsSettings = Seq(
39+
scalacOptions ++= {
40+
CrossVersion.partialVersion(scalaVersion.value) match {
41+
case Some((2, n)) if n >= 13 => "-Werror" :: Nil
42+
case _ => Nil
43+
}
44+
}
45+
)
46+
3847
lazy val warningSuppression = Seq(
3948
scalacOptions += "-Wconf:" + Seq(
4049
"msg=APIs in chisel3.internal:s",
@@ -181,6 +190,7 @@ lazy val core = (project in file("core"))
181190
.settings(publishSettings: _*)
182191
.settings(mimaPreviousArtifacts := Set())
183192
.settings(warningSuppression: _*)
193+
.settings(fatalWarningsSettings: _*)
184194
.settings(
185195
name := "chisel3-core",
186196
libraryDependencies ++= Seq(
@@ -212,6 +222,7 @@ lazy val chisel = (project in file("."))
212222
.dependsOn(core)
213223
.aggregate(macros, core, plugin)
214224
.settings(warningSuppression: _*)
225+
.settings(fatalWarningsSettings: _*)
215226
.settings(
216227
mimaPreviousArtifacts := Set(),
217228
Test / scalacOptions ++= Seq("-language:reflectiveCalls"),
@@ -263,6 +274,8 @@ lazy val integrationTests = (project in file("integration-tests"))
263274
.dependsOn(chisel)
264275
.dependsOn(standardLibrary)
265276
.settings(commonSettings: _*)
277+
.settings(warningSuppression: _*)
278+
.settings(fatalWarningsSettings: _*)
266279
.settings(chiselSettings: _*)
267280
.settings(usePluginSettings: _*)
268281
.settings(

src/main/scala/chisel3/util/experimental/BoringUtils.scala

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package chisel3.util.experimental
44

55
import chisel3._
66
import chisel3.experimental.{annotate, ChiselAnnotation, RunFirrtlTransform}
7-
import chisel3.internal.{NamedComponent, Namespace}
7+
import chisel3.internal.{Builder, BuilderContextCache, NamedComponent, Namespace}
88
import firrtl.transforms.{DontTouchAnnotation, NoDedupAnnotation}
99
import firrtl.passes.wiring.{SinkAnnotation, SourceAnnotation, WiringTransform}
1010
import firrtl.annotations.{ComponentName, ModuleName}
@@ -98,19 +98,15 @@ class BoringUtilsException(message: String) extends Exception(message)
9898
*/
9999
object BoringUtils {
100100
/* A global namespace for boring ids */
101-
private val namespace: SyncVar[Namespace] = new SyncVar
102-
namespace.put(Namespace.empty)
101+
private[chisel3] case object CacheKey extends BuilderContextCache.Key[Namespace]
102+
private def boringNamespace = Builder.contextCache.getOrElseUpdate(CacheKey, Namespace.empty)
103103

104104
/* Get a new name (value) from the namespace */
105105
private def newName(value: String): String = {
106-
val ns = namespace.take()
107-
val valuex = ns.name(value)
108-
namespace.put(ns)
109-
valuex
106+
boringNamespace.name(value)
110107
}
111-
112108
/* True if the requested name (value) exists in the namespace */
113-
private def checkName(value: String): Boolean = namespace.get.contains(value)
109+
private def checkName(value: String): Boolean = boringNamespace.contains(value)
114110

115111
/** Add a named source cross module reference
116112
* @param component source circuit component
@@ -199,5 +195,4 @@ object BoringUtils {
199195
sinks.foreach(addSink(_, genName, true, true))
200196
genName
201197
}
202-
203198
}

src/main/scala/circt/stage/phases/CIRCT.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import firrtl.options.phases.WriteOutputAnnotations
2424
import firrtl.options.Viewer.view
2525
import firrtl.stage.{FirrtlOptions, RunFirrtlTransformAnnotation}
2626
import _root_.logger.LogLevel
27+
import chisel3.InternalErrorException
2728

2829
import java.io.File
2930

@@ -45,7 +46,7 @@ private object Helpers {
4546
*/
4647
def extractAnnotationFile(string: String, filename: String): AnnotationSeq = {
4748
var inAnno = false
48-
val filtered: String = string.lines.filter {
49+
val filtered: String = string.linesIterator.filter {
4950
case line if line.startsWith("// ----- 8< ----- FILE") && line.contains(filename) =>
5051
inAnno = true
5152
false
@@ -282,6 +283,8 @@ class CIRCT extends Phase {
282283
throw new Exception(
283284
"No 'circtOptions.target' specified. This should be impossible if dependencies are satisfied!"
284285
)
286+
case unknown =>
287+
throw new InternalErrorException(s"Match Error: Unknon CIRCTTarget: $unknown")
285288
})
286289
}
287290

0 commit comments

Comments
 (0)