Skip to content

Commit

Permalink
Move Scala runtime isSingleton to Java runtime (#4608)
Browse files Browse the repository at this point in the history
This will help keep reflection code cross-compiling between Scala 2 and
3 cleanly
  • Loading branch information
adkian-sifive authored Jan 10, 2025
1 parent 0d73982 commit e12935e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
11 changes: 0 additions & 11 deletions firrtl/src/main/scala-2/Macros.scala

This file was deleted.

13 changes: 0 additions & 13 deletions firrtl/src/main/scala-3/Macros.scala

This file was deleted.

13 changes: 11 additions & 2 deletions firrtl/src/main/scala/firrtl/options/Phase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import logger.LazyLogging
import scala.collection.mutable.LinkedHashSet

import scala.reflect.ClassTag
import firrtl.macros.Macros
import java.lang.reflect.Modifier

object Dependency {
def apply[A <: DependencyAPI[_]: ClassTag]: Dependency[A] = {
Expand All @@ -33,7 +33,16 @@ object Dependency {
}
}

private def isSingleton(obj: AnyRef): Boolean = Macros.isSingletonImpl(obj)
private def isSingleton(obj: Any): Boolean = {
val clazz = obj.getClass
try {
// Check if the class has a static field named "MODULE$"
val moduleField = clazz.getDeclaredField("MODULE$")
Modifier.isStatic(moduleField.getModifiers)
} catch {
case _: NoSuchFieldException => false
}
}
}

case class Dependency[+A <: DependencyAPI[_]](id: Either[Class[_ <: A], A with Singleton]) {
Expand Down

0 comments on commit e12935e

Please sign in to comment.