Skip to content

Commit e12935e

Browse files
Move Scala runtime isSingleton to Java runtime (#4608)
This will help keep reflection code cross-compiling between Scala 2 and 3 cleanly
1 parent 0d73982 commit e12935e

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

firrtl/src/main/scala-2/Macros.scala

Lines changed: 0 additions & 11 deletions
This file was deleted.

firrtl/src/main/scala-3/Macros.scala

Lines changed: 0 additions & 13 deletions
This file was deleted.

firrtl/src/main/scala/firrtl/options/Phase.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import logger.LazyLogging
99
import scala.collection.mutable.LinkedHashSet
1010

1111
import scala.reflect.ClassTag
12-
import firrtl.macros.Macros
12+
import java.lang.reflect.Modifier
1313

1414
object Dependency {
1515
def apply[A <: DependencyAPI[_]: ClassTag]: Dependency[A] = {
@@ -33,7 +33,16 @@ object Dependency {
3333
}
3434
}
3535

36-
private def isSingleton(obj: AnyRef): Boolean = Macros.isSingletonImpl(obj)
36+
private def isSingleton(obj: Any): Boolean = {
37+
val clazz = obj.getClass
38+
try {
39+
// Check if the class has a static field named "MODULE$"
40+
val moduleField = clazz.getDeclaredField("MODULE$")
41+
Modifier.isStatic(moduleField.getModifiers)
42+
} catch {
43+
case _: NoSuchFieldException => false
44+
}
45+
}
3746
}
3847

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

0 commit comments

Comments
 (0)