diff options
| author | Aditya Naik | 2024-05-29 16:57:13 -0700 |
|---|---|---|
| committer | Aditya Naik | 2024-05-29 16:57:13 -0700 |
| commit | 165804ee58cb18443042b9655328278434ddedf4 (patch) | |
| tree | 4e167eff9e7b3ec09d73dbd9feaa6f9964cd8a68 /src/main/scala/firrtl/options | |
| parent | 57b8a395ee8d5fdabb2deed3db7d0c644f0a7eed (diff) | |
Add Scala3 support
Diffstat (limited to 'src/main/scala/firrtl/options')
12 files changed, 31 insertions, 26 deletions
diff --git a/src/main/scala/firrtl/options/DependencyManager.scala b/src/main/scala/firrtl/options/DependencyManager.scala index ae22b4b4..32f6b3c9 100644 --- a/src/main/scala/firrtl/options/DependencyManager.scala +++ b/src/main/scala/firrtl/options/DependencyManager.scala @@ -17,7 +17,7 @@ case class DependencyManagerException(message: String, cause: Throwable = null) * @tparam A the type over which this transforms * @tparam B the type of the [[firrtl.options.TransformLike TransformLike]] */ -trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends TransformLike[A] with DependencyAPI[B] { +trait DependencyManager[A, B <: TransformLike[A] & DependencyAPI[B]] extends TransformLike[A] with DependencyAPI[B] { import DependencyManagerUtils.CharSet override def prerequisites: Seq[Dependency[B]] = currentState @@ -52,7 +52,7 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends /** Store of conversions between classes and objects. Objects that do not exist in the map will be lazily constructed. */ protected lazy val dependencyToObject: LinkedHashMap[Dependency[B], B] = { - val init = LinkedHashMap[Dependency[B], B](knownObjects.map(x => oToD(x) -> x).toSeq: _*) + val init = LinkedHashMap[Dependency[B], B](knownObjects.map(x => oToD(x) -> x).toSeq*) (_targets ++ _currentState) .filter(!init.contains(_)) .map(x => init(x) = x.getObject()) @@ -84,9 +84,9 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends ): LinkedHashMap[B, LinkedHashSet[B]] = { val (queue, edges) = { - val a: Queue[Dependency[B]] = Queue(start.toSeq: _*) + val a: Queue[Dependency[B]] = Queue(start.toSeq*) val b: LinkedHashMap[B, LinkedHashSet[B]] = - LinkedHashMap[B, LinkedHashSet[B]](start.map((dToO(_) -> LinkedHashSet[B]())).toSeq: _*) + LinkedHashMap[B, LinkedHashSet[B]](start.map((dToO(_) -> LinkedHashSet[B]())).toSeq*) (a, b) } @@ -183,7 +183,7 @@ trait DependencyManager[A, B <: TransformLike[A] with DependencyAPI[B]] extends } /** Wrap a possible [[CyclicException]] thrown by a thunk in a [[DependencyManagerException]] */ - private def cyclePossible[A](a: String, diGraph: DiGraph[_])(thunk: => A): A = try { thunk } + private def cyclePossible[A](a: String, diGraph: DiGraph[?])(thunk: => A): A = try { thunk } catch { case e: CyclicException => throw new DependencyManagerException( diff --git a/src/main/scala/firrtl/options/OptionParser.scala b/src/main/scala/firrtl/options/OptionParser.scala index 79163aea..27251b00 100644 --- a/src/main/scala/firrtl/options/OptionParser.scala +++ b/src/main/scala/firrtl/options/OptionParser.scala @@ -11,7 +11,7 @@ case object OptionsHelpException extends Exception("Usage help invoked") /** OptionParser mixin that causes the OptionParser to not call exit (call `sys.exit`) if the `--help` option is * passed */ -trait DoNotTerminateOnExit { this: OptionParser[_] => +trait DoNotTerminateOnExit { this: OptionParser[?] => override def terminate(exitState: Either[String, Unit]): Unit = () } @@ -21,7 +21,7 @@ trait DoNotTerminateOnExit { this: OptionParser[_] => * [[StageUtils.dramaticError]]. By converting this to an [[OptionsException]], a [[Stage]] can then catch the error an * convert it to an [[OptionsException]] that a [[Stage]] can get at. */ -trait ExceptOnError { this: OptionParser[_] => +trait ExceptOnError { this: OptionParser[?] => override def reportError(msg: String): Unit = throw new OptionsException(msg) } diff --git a/src/main/scala/firrtl/options/Phase.scala b/src/main/scala/firrtl/options/Phase.scala index b836c386..04538fa5 100644 --- a/src/main/scala/firrtl/options/Phase.scala +++ b/src/main/scala/firrtl/options/Phase.scala @@ -3,7 +3,7 @@ package firrtl.options import firrtl.AnnotationSeq - +import firrtl.macros.Macros import logger.LazyLogging import scala.collection.mutable.LinkedHashSet @@ -12,33 +12,33 @@ import scala.reflect import scala.reflect.ClassTag object Dependency { - def apply[A <: DependencyAPI[_]: ClassTag]: Dependency[A] = { + def apply[A <: DependencyAPI[?]: ClassTag]: Dependency[A] = { val clazz = reflect.classTag[A].runtimeClass Dependency(Left(clazz.asInstanceOf[Class[A]])) } - def apply[A <: DependencyAPI[_]](c: Class[_ <: A]): Dependency[A] = { + def apply[A <: DependencyAPI[?]](c: Class[? <: A]): Dependency[A] = { // It's forbidden to wrap the class of a singleton as a Dependency require(c.getName.last != '$') Dependency(Left(c)) } - def apply[A <: DependencyAPI[_]](o: A with Singleton): Dependency[A] = Dependency(Right(o)) + def apply[A <: DependencyAPI[?]](o: A & Singleton): Dependency[A] = Dependency(Right(o)) - def fromTransform[A <: DependencyAPI[_]](t: A): Dependency[A] = { + def fromTransform[A <: DependencyAPI[?]](t: A): Dependency[A] = { if (isSingleton(t)) { - Dependency[A](Right(t.asInstanceOf[A with Singleton])) + Dependency[A](Right(t.asInstanceOf[A & Singleton])) } else { Dependency[A](Left(t.getClass)) } } private def isSingleton(obj: AnyRef): Boolean = { - reflect.runtime.currentMirror.reflect(obj).symbol.isModuleClass + Macros.isModuleClass(obj) } } -case class Dependency[+A <: DependencyAPI[_]](id: Either[Class[_ <: A], A with Singleton]) { +case class Dependency[+A <: DependencyAPI[?]](id: Either[Class[? <: A], A & Singleton]) { def getObject(): A = id match { case Left(c) => safeConstruct(c) case Right(o) => o @@ -55,7 +55,7 @@ case class Dependency[+A <: DependencyAPI[_]](id: Either[Class[_ <: A], A with S } /** Wrap an [[IllegalAccessException]] due to attempted object construction in a [[DependencyManagerException]] */ - private def safeConstruct[A](a: Class[_ <: A]): A = try { a.newInstance } + private def safeConstruct[A](a: Class[? <: A]): A = try { a.newInstance } catch { case e: IllegalAccessException => throw new DependencyManagerException(s"Failed to construct '$a'! (Did you try to construct an object?)", e) @@ -123,7 +123,7 @@ trait IdentityLike[A] { this: TransformLike[A] => * @define seqNote @note The use of a Seq here is to preserve input order. Internally, this will be converted to a private, * ordered Set. */ -trait DependencyAPI[A <: DependencyAPI[A]] { this: TransformLike[_] => +trait DependencyAPI[A <: DependencyAPI[A]] { this: TransformLike[?] => /** All transform that must run before this transform * $seqNote diff --git a/src/main/scala/firrtl/options/Registration.scala b/src/main/scala/firrtl/options/Registration.scala index 1ebccea4..c0eead69 100644 --- a/src/main/scala/firrtl/options/Registration.scala +++ b/src/main/scala/firrtl/options/Registration.scala @@ -3,7 +3,7 @@ package firrtl.options import firrtl.{AnnotationSeq, Transform} - +import firrtl.{seqToAnnoSeq, annoSeqToSeq} import scopt.{OptionDef, OptionParser, Read} /** Contains information about a [[Shell]] command line option @@ -43,7 +43,7 @@ trait HasShellOptions { /** A sequence of options provided */ - def options: Seq[ShellOption[_]] + def options: Seq[ShellOption[?]] /** Add all shell (command line) options to an option parser * @param p an option parser diff --git a/src/main/scala/firrtl/options/Shell.scala b/src/main/scala/firrtl/options/Shell.scala index f7b9371f..89ae0f57 100644 --- a/src/main/scala/firrtl/options/Shell.scala +++ b/src/main/scala/firrtl/options/Shell.scala @@ -3,7 +3,7 @@ package firrtl.options import firrtl.AnnotationSeq - +import firrtl.{seqToAnnoSeq, annoSeqToSeq} import logger.{ClassLogLevelAnnotation, LogClassNamesAnnotation, LogFileAnnotation, LogLevelAnnotation} import scopt.OptionParser @@ -16,7 +16,7 @@ import java.util.ServiceLoader class Shell(val applicationName: String) { /** Command line argument parser (OptionParser) with modifications */ - protected val parser = new OptionParser[AnnotationSeq](applicationName) with DuplicateHandling with ExceptOnError + val parser = new OptionParser[AnnotationSeq](applicationName) with DuplicateHandling with ExceptOnError /** Contains all discovered [[RegisteredLibrary]] */ final lazy val registeredLibraries: Seq[RegisteredLibrary] = { diff --git a/src/main/scala/firrtl/options/Stage.scala b/src/main/scala/firrtl/options/Stage.scala index cefdd957..2744bc00 100644 --- a/src/main/scala/firrtl/options/Stage.scala +++ b/src/main/scala/firrtl/options/Stage.scala @@ -3,6 +3,7 @@ package firrtl.options import firrtl.AnnotationSeq +import firrtl.{seqToAnnoSeq, annoSeqToSeq} import logger.Logger diff --git a/src/main/scala/firrtl/options/StageAnnotations.scala b/src/main/scala/firrtl/options/StageAnnotations.scala index 1642e248..bc5952b6 100644 --- a/src/main/scala/firrtl/options/StageAnnotations.scala +++ b/src/main/scala/firrtl/options/StageAnnotations.scala @@ -3,6 +3,7 @@ package firrtl.options import firrtl.AnnotationSeq +import firrtl.{seqToAnnoSeq, annoSeqToSeq} import firrtl.annotations.{Annotation, NoTargetAnnotation} import firrtl.options.Viewer.view diff --git a/src/main/scala/firrtl/options/phases/AddDefaults.scala b/src/main/scala/firrtl/options/phases/AddDefaults.scala index dcd5b031..626410fd 100644 --- a/src/main/scala/firrtl/options/phases/AddDefaults.scala +++ b/src/main/scala/firrtl/options/phases/AddDefaults.scala @@ -3,6 +3,7 @@ package firrtl.options.phases import firrtl.AnnotationSeq +import firrtl.{seqToAnnoSeq, annoSeqToSeq} import firrtl.options.{Dependency, Phase, TargetDirAnnotation} /** Add default annotations for a [[Stage]] diff --git a/src/main/scala/firrtl/options/phases/Checks.scala b/src/main/scala/firrtl/options/phases/Checks.scala index 64d81fb4..4ffe0510 100644 --- a/src/main/scala/firrtl/options/phases/Checks.scala +++ b/src/main/scala/firrtl/options/phases/Checks.scala @@ -4,6 +4,7 @@ package firrtl.options.phases import firrtl.AnnotationSeq import firrtl.annotations.Annotation +import firrtl.{seqToAnnoSeq, annoSeqToSeq} import firrtl.options.{OptionsException, OutputAnnotationFileAnnotation, Phase, TargetDirAnnotation} import firrtl.options.Dependency diff --git a/src/main/scala/firrtl/options/phases/DeletedWrapper.scala b/src/main/scala/firrtl/options/phases/DeletedWrapper.scala index fe2c6d78..2b2ccf16 100644 --- a/src/main/scala/firrtl/options/phases/DeletedWrapper.scala +++ b/src/main/scala/firrtl/options/phases/DeletedWrapper.scala @@ -3,6 +3,7 @@ package firrtl.options.phases import firrtl.AnnotationSeq +import firrtl.{annoSeqToSeq, seqToAnnoSeq} import firrtl.annotations.DeletedAnnotation import firrtl.options.{Phase, Translator} @@ -25,14 +26,10 @@ class DeletedWrapper(p: Phase) extends Phase with Translator[AnnotationSeq, (Ann def aToB(a: AnnotationSeq): (AnnotationSeq, AnnotationSeq) = (a, a) def bToA(b: (AnnotationSeq, AnnotationSeq)): AnnotationSeq = { - - val (in, out) = (mutable.LinkedHashSet() ++ b._1, mutable.LinkedHashSet() ++ b._2) - - (in -- out).map { + b._1.diff(b._2).map { case DeletedAnnotation(n, a) => DeletedAnnotation(s"$n+$name", a) case a => DeletedAnnotation(name, a) }.toSeq ++ b._2 - } def internalTransform(b: (AnnotationSeq, AnnotationSeq)): (AnnotationSeq, AnnotationSeq) = (b._1, p.transform(b._2)) diff --git a/src/main/scala/firrtl/options/phases/GetIncludes.scala b/src/main/scala/firrtl/options/phases/GetIncludes.scala index d50b2c6f..05810a31 100644 --- a/src/main/scala/firrtl/options/phases/GetIncludes.scala +++ b/src/main/scala/firrtl/options/phases/GetIncludes.scala @@ -3,9 +3,11 @@ package firrtl.options.phases import firrtl.AnnotationSeq +import org.json4s.convertToJsonInput import firrtl.annotations.{AnnotationFileNotFoundException, JsonProtocol} import firrtl.options.{InputAnnotationFileAnnotation, Phase, StageUtils} import firrtl.FileUtils +import firrtl.{seqToAnnoSeq, annoSeqToSeq} import firrtl.stage.AllowUnrecognizedAnnotations import java.io.File diff --git a/src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala b/src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala index ba38bb87..4cbb0496 100644 --- a/src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala +++ b/src/main/scala/firrtl/options/phases/WriteOutputAnnotations.scala @@ -3,6 +3,8 @@ package firrtl.options.phases import firrtl.AnnotationSeq +import firrtl.{seqToAnnoSeq, annoSeqToSeq} +import firrtl.options.StageOptionsView import firrtl.annotations.{Annotation, DeletedAnnotation, JsonProtocol} import firrtl.options.{ BufferedCustomFileEmission, |
