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

Stale symbol crash #17294

Closed
soronpo opened this issue Apr 17, 2023 · 6 comments · Fixed by #18077
Closed

Stale symbol crash #17294

soronpo opened this issue Apr 17, 2023 · 6 comments · Fixed by #18077
Assignees
Milestone

Comments

@soronpo
Copy link
Contributor

soronpo commented Apr 17, 2023

Could be related somehow to #17152, but this also occurs for older compiler versions and this minimization is far simpler.
It may be that this should just yield a cyclic dependency error instead of a crash. I'm not sure what the cross-file macro dependency limitations are.

Compiler version

v3.2.2
Also tested on the latest nightly: scala-3.3.1-RC1-bin-20230416-2f4cc4c-NIGHTLY

Minimized code

DFVal.scala

package crash

def bits[T](t: T)(using w: Width[T]): w.Out = ???

Width.scala

package crash

import scala.quoted.*

trait Width[T]:
  type Out
object Width:
  transparent inline given [T]: Width[T] = ${ getWidthMacro[T] }
  def getWidthMacro[T](using Quotes, Type[T]): Expr[Width[T]] =
    '{ new Width[T] {} }
end Width

val x = bits(1)

Output (click arrow to expand)

[error] dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; type Out#4554 in trait Width, defined in Period(1..63, run = 2), is referred to in run Period(2..2, run = 3)
[error] dotty.tools.dotc.core.Denotations$SingleDenotation.staleSymbolError(Denotations.scala:948)
[error] dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:752)
[error] dotty.tools.dotc.core.Denotations$SingleDenotation.toNewRun$1(Denotations.scala:799)
[error] dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:870)
[error] dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:120)
[error] dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:114)
[error] dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:107)
[error] dotty.tools.dotc.core.Symbols$.toDenot(Symbols.scala:494)
[error] dotty.tools.dotc.core.Types$NamedType.derivedSelect(Types.scala:2657)
[error] dotty.tools.dotc.core.Substituters$.subst(Substituters.scala:18)
[error] dotty.tools.dotc.core.Types$Type.subst(Types.scala:1798)
[error] dotty.tools.dotc.core.Types$LambdaType.newLikeThis$$anonfun$2(Types.scala:3679)
[error] dotty.tools.dotc.core.Types$MethodType.<init>(Types.scala:3934)
[error] dotty.tools.dotc.core.Types$CachedMethodType.<init>(Types.scala:3953)
[error] dotty.tools.dotc.core.Types$MethodTypeCompanion.apply(Types.scala:4045)
[error] dotty.tools.dotc.core.Types$MethodTypeCompanion.apply(Types.scala:4044)
[error] dotty.tools.dotc.core.Types$LambdaType.newLikeThis(Types.scala:3679)
[error] dotty.tools.dotc.core.Types$LambdaType.newLikeThis$(Types.scala:3606)
[error] dotty.tools.dotc.core.Types$MethodOrPoly.newLikeThis(Types.scala:3692)
[error] dotty.tools.dotc.core.Types$LambdaType.derivedLambdaType(Types.scala:3669)
[error] dotty.tools.dotc.core.Types$LambdaType.derivedLambdaType$(Types.scala:3606)
[error] dotty.tools.dotc.core.Types$MethodOrPoly.derivedLambdaType(Types.scala:3692)
[error] dotty.tools.dotc.core.Types$TypeMap.derivedLambdaType(Types.scala:5655)
[error] dotty.tools.dotc.core.Types$TypeMap.mapOverLambda(Types.scala:5674)
[error] dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:5701)
[error] dotty.tools.dotc.core.Substituters$.substParams(Substituters.scala:163)
[error] dotty.tools.dotc.core.Substituters$SubstParamsMap.apply(Substituters.scala:201)
[error] dotty.tools.dotc.core.Types$TypeMap.mapOverLambda(Types.scala:5674)
[error] dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:5701)
[error] dotty.tools.dotc.core.Substituters$.substParams(Substituters.scala:163)
[error] dotty.tools.dotc.core.Types$Type.substParams(Types.scala:1818)
[error] dotty.tools.dotc.core.Types$LambdaType.instantiate(Types.scala:3645)
[error] dotty.tools.dotc.core.Types$LambdaType.instantiate$(Types.scala:3606)
[error] dotty.tools.dotc.core.Types$MethodOrPoly.instantiate(Types.scala:3692)
[error] dotty.tools.dotc.typer.TypeAssigner.assignType(TypeAssigner.scala:360)
[error] dotty.tools.dotc.typer.TypeAssigner.assignType$(TypeAssigner.scala:16)
[error] dotty.tools.dotc.typer.Typer.assignType(Typer.scala:116)
[error] dotty.tools.dotc.ast.tpd$.TypeApply(tpd.scala:58)
[error] dotty.tools.dotc.ast.tpd$TreeOps$.appliedToTypeTrees$extension(tpd.scala:979)
[error] dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:4171)
[error] dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3503)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3126)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3130)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3242)
[error] dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:941)
[error] dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1101)
[error] dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:352)
[error] dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:116)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2991)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3054)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3126)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3130)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3242)
[error] dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1645)
[error] dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1635)
[error] dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1645)
[error] dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1898)
[error] dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:250)
[error] dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:1898)
[error] dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1906)
[error] dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1924)
[error] dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1925)
[error] dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:1936)
[error] dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1683)
[error] dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1690)
[error] dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:787)
[error] dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:926)
[error] dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:814)
[error] dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
[error] dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
[error] dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
[error] dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
[error] dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2932)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2957)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3053)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3126)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3130)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3152)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3198)
[error] dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2612)
[error] dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2979)
[error] dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2983)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3053)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3126)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3130)
[error] dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3152)
[error] dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3198)
[error] dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2755)
[error] dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3024)
[error] dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3054)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3126)
[error] dotty.tools.dotc.typer.Typer.typed(Typer.scala:3130)
[error] dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3242)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:44)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:54)
[error] scala.Function0.apply$mcV$sp(Function0.scala:42)
[error] dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:437)
[error] dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:54)
[error] dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:88)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.immutable.List.foreach(List.scala:333)
[error] dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:88)
[error] dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321)
[error] dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
[error] dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
[error] dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:279)
[error] dotty.tools.dotc.Run.compileUnits(Run.scala:200)
[error] dotty.tools.dotc.Driver.finish(Driver.scala:58)
[error] dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
[error] dotty.tools.xsbt.CompilerBridgeDriver.run(CompilerBridgeDriver.java:88)
[error] dotty.tools.xsbt.CompilerBridge.run(CompilerBridge.java:22)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:179)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:177)
[error] sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:463)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:418)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:405)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:171)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2363)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$2(Defaults.scala:2313)
[error] sbt.internal.server.BspCompileTask$.$anonfun$compute$1(BspCompileTask.scala:30)
[error] sbt.internal.io.Retry$.apply(Retry.scala:46)
[error] sbt.internal.io.Retry$.apply(Retry.scala:28)
[error] sbt.internal.io.Retry$.apply(Retry.scala:23)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:30)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:2311)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] sbt.Execute.work(Execute.scala:291)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[error] java.base/java.lang.Thread.run(Thread.java:829)
[error]
[error] stack trace is suppressed; run last core / Compile / compileIncremental for the full output
[error] (core / Compile / compileIncremental) dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; type Out#4554 in trait Width, defined in Period(1..63, run = 2), is referred to in run Period(2..2, run = 3)
@soronpo soronpo added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 17, 2023
@soronpo soronpo changed the title State symbol crash Stale symbol crash Apr 17, 2023
@jchyb jchyb added area:typer area:metaprogramming:quotes Issues related to quotes and splices and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 18, 2023
@ftucky
Copy link

ftucky commented Apr 26, 2023

Hello,
I encounter the same symptom:
dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; method definition$lzyINIT2#52624 in class Generator, defined in Period(76..93, run = 2), is referred to in run Period(92..92, run = 3)

dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; method definition$lzyINIT2#52624 in class Generator, defined in Period(76..93, run = 2), is referred to in run Period(92..92, run = 3) | => root / Compile / compileIncremental 1s at dotty.tools.dotc.core.Denotations$SingleDenotation.staleSymbolError(Denotations.scala:948) at dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:752) at dotty.tools.dotc.core.Denotations$SingleDenotation.toNewRun$1(Denotations.scala:799) at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:870) at dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:120) at dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:114) at dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:107) at dotty.tools.dotc.core.Symbols$Symbol.name(Symbols.scala:260) at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeMemberNames$$anonfun$2(SymDenotations.scala:2328)

Observations

No metaprogramming

Code is difficult to minimize, however metaprogramming or quotes do not seem to be involved.

Apparent workaround

The faulty symbol definition$lzyINIT2#52624 is associated to a declaration

object definition extends Definition: 
  ...

Changing the line for the declaration below acts as a work-around.

val definition = new Definition:
  ...

Caching Issue

Running the sbt build a second time succeeds after the crash.

sbt:> clean 
sbt:> compile /// Crashes
sbt:> compile /// with no source change. NO CRASH. (and correct behavior!)

Hope this helps.

@jchyb jchyb self-assigned this Jun 15, 2023
odersky added a commit that referenced this issue Jun 30, 2023
#18077)

Closes #17152
Closes #17294

In general the issues stemmed from the fact that after suspending runs
due to the found macros, when typing Ident of the called method, symbols
from the previous run are found there. Some of them either are able to
have their validity updated while returning the denotation (which those
path dependent types are unable to do, since their owners now have
updated decls, which do not include the stale symbol), or do not need
denotation as part of a code path they rely on.

The fixes simply check if the to-be-used symbol has a valid runID, and
if not then recomputes it.

The first commit fixes the minimizations from above GitHub issues. Both
minimizations by design have to result in cyclic macro errors (which
they now do), so they were placed in `neg-macros` tests.

By some experimentation, I ended up with another, slightly different
stale symbol crash, with the stale symbol trying to create a denotation
in different place (in `withPrefix`), requiring an additional fix there,
included in the second commit. This minimization, unlike the previous
ones, does compile successfully, without cyclic macro errors, which
shows the issue was not exclusive to those.
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
@Pyromuffin
Copy link

Pyromuffin commented Jun 15, 2024

Still seeing this on 3.4.2

My repro is very complicated involving macros unfortunately, but I am seeing the same symptoms as #17294 (comment): it happens with a top level object and goes away when either making it a top level val or on the second compile.

@joan38
Copy link
Contributor

joan38 commented Nov 22, 2024

Hey,
I'm having the same issue on 3.5.2.

Here is the code of the macro:

import scala.quoted.*

/**
 * Scala 3 macro which finds all objects that inherit from a given type T as a compile-time / static metaprogramming operation.
 *
 * Example usage:
 *   import com.netflix.measures.library.macros.ObjectInheritanceFinder.findAllInheritingObjects
 *   val measureParsers: Set[MeasureParser] = findAllInheritingObjects[MeasureParser]
 */
object ObjectInheritanceFinder {
  inline def findAllInheritingObjects[T]: Set[T] = ${ findAllInheritingObjectsImpl[T] }

  private def findAllInheritingObjectsImpl[T: Type](using Quotes): Expr[Set[T]] = {
    // Context-sensitive reflection import is tied to specific instance of Quotes that's created for each specific macro invocation
    import quotes.reflect._

    // Get the TypeRepr of the type parameter T to be used for inheritance checks
    val baseType = TypeRepr.of[T]

    /**
     * Check if the symbol is an object and a subtype of baseType.
     *
     * @param sym The symbol to check.
     * @return True if the symbol is an object and a subtype of baseType, otherwise false.
     */
    def isObjectInheritingFromBaseType(sym: Symbol): Boolean =
      // All symbols are terms or types, and some types throw when checking sym.flags.is, so this check is necessary before it is called
      sym.isTerm &&
        // flags.is(Flags.Module) is equivalent to checking if the symbol is an object
        sym.flags.is(Flags.Module) &&
        // termRef <:< baseType is equivalent to checking if the symbol is a subtype of baseType
        sym.termRef <:< baseType

    /**
     * Recursively traverse a package and its subpackages to find objects that are subtypes of baseType.
     *
     * We convert to a Set because there are no guarantees that the same object won't be referenced in multiple packages.
     *
     * @param pkg The package symbol to start the search from.
     * @return A sequence of fully qualified names representing the inheriting objects.
     */
    def findAllInheritingObjectsInPackage(pkg: Symbol): Set[String] =
      pkg.declarations.flatMap {
        case sym if sym.isPackageDef                    => findAllInheritingObjectsInPackage(sym) // Recurse
        case sym if isObjectInheritingFromBaseType(sym) => Some(sym.fullName)                     // Include
        case _                                          => None                                   // Skip
      }.toSet

    // Root package symbol
    val packageSymbol: Symbol = Symbol.requiredPackage("com.netflix.measures.library")

    // Find all objects that inherit from T starting from the root package
    val inheritingObjects: Set[Expr[T]] = findAllInheritingObjectsInPackage(packageSymbol)
      // Map fully qualified names to Expr[T]
      .map(x => Ref(Symbol.requiredModule(x)).asExprOf[T])

    // Convert Set[Expr[T]] to Expr[Set[T]]
    '{ Set(${ Expr.ofSeq(inheritingObjects.toSeq) }*) }
  }
}

Anything wrong with it?

@joan38
Copy link
Contributor

joan38 commented Nov 23, 2024

If I add sym.isValDef before sym.flags.is(Flags.Module) then it works:

    def isObjectInheritingFromBaseType(sym: Symbol): Boolean =
      // All symbols are terms or types, and some types throw when checking sym.flags.is, so this check is necessary before it is called
      sym.isTerm &&
        // Check if the symbol is the object instance (as opposed to the type definition)
        sym.isValDef &&
        // Check if the symbol is an object
        sym.flags.is(Flags.Module) &&
        // Check if the symbol is a subtype of baseType
        sym.termRef <:< baseType

@jchyb
Copy link
Contributor

jchyb commented Dec 2, 2024

Hi @joan38. Usually with stale symbol crashes the actual macro implementation tends to not matter as much as the place where that macro is called. When we compile multiple files at once and one of them is found to call a simultaneously compiled macro method, we have to pause compilation of that file, finish compilation of the macro implementation, and return to compiling the previous file. This back and forth can cause stale symbol issues. For this reason I am not able to help You without a proper minimization, with the macro call included. The stack trace might help too - stale symbol crashes can have distinct causes and fixes, so I might be able to see this way if this is something that was being fixed before

@joan38
Copy link
Contributor

joan38 commented Dec 2, 2024

That explains why it was flaky and now works. Thanks for explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants