While working on some changes in Metro (PR context...
# compiler
j
While working on some changes in Metro (PR context: https://github.com/ZacSweers/metro/pull/576) I ran into some IC issues with generated top-level functions in IR. When seeing code like
Copy code
@Singleton
@Inject
class Foo
I generate a top-level function like
Copy code
@Singleton
fun hintForScopeSingleton(contributed: Foo) = stub(..)
in a common 'hints' package that allows me to later grab all of the generated functions and reference back to their class parameters. With an IC test, I found that with multiple back-to-back compilations where I change the scope annotation (
@Singleton
above), new hint functions would be successfully generated but the old ones would not be invalidated and some later compilations would e.g. end up with
Copy code
@Singleton
fun hintForScopeSingleton(contributed: Foo) = stub(..)

@NewerScope
fun hintForScopeNewerScope(contributed: Foo) = stub(..)
Is tracking and invalidating top-level functions like this supported? And if so, any advice on the best way to do so? There's this IC tracking function used elsewhere in Metro, but it is specific to functions that live in a class and from what I could tell the underlying compiler calls also seemed to not be compatible with a top-level function
y
It seems like
LookupTracker.record
supports that explicitly by passing in
ScopeKind.PACKAGE
and presumably the package fqname
j
Ahh good catch! Looks like passing in that combo is valid, although after trying it out I still see the same behavior where the tracked function doesn't get invalidated Also tried out a combination of tracking a lookup of the generated function from the class that needs it and a lookup of the source class from the generated function, but this didn't seem to have any effect either (outdated generated function remains)