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

getSymbolsWithAnnotation() returns duplicate entries #1993

Open
vRallev opened this issue Jul 10, 2024 · 1 comment
Open

getSymbolsWithAnnotation() returns duplicate entries #1993

vRallev opened this issue Jul 10, 2024 · 1 comment

Comments

@vRallev
Copy link

vRallev commented Jul 10, 2024

I'm consistently seeing in multiple processors that getSymbolsWithAnnotation() returns duplicate symbols or symbols processed in previous rounds in multi round scenarios with deferred symbols. I wanted to file this issue to start the discussion.

getSymbolsWithAnnotation() says in its documentation:

Note that in multiple round processing, only symbols from deferred symbols of last round and symbols from newly generated files will be returned in this function.

But I'm seeing the following:

  • Round 1: A KSClassDeclaration can't be processed and is deferred.
  • Round 2: getSymbolsWithAnnotation() returns the deferred symbol twice in the Sequence. Ignoring one entry allows us to process the KSClassDeclaration. It's not returned as deferred symbol anymore, but other symbols are deferred.
  • Round 3: getSymbolsWithAnnotation() returns the already processed KSClassDeclaration.

This happens with KSP 1.9.24-1.0.20 but also 2.0.0-1.0.22.

We've implemented workarounds such as:

    fun Resolver.getNewSymbolsWithAnnotation(annotation: KClass<*>): Sequence<KSAnnotated> {
        val newFiles = getNewFiles().toSet()
        return getSymbolsWithAnnotation(annotation)
            .filter { it.containingFile in newFiles }
    }

To filter symbols ourselves. We also keep track of all successfully processed symbols and ignore them when getSymbolsWithAnnotation() returns them again.

I have yet to build a sample to reproduce the issue outside of our internal code, but I wanted to file this issue to start the discussion. Is there a chance that caching issues or other problems could trigger this bug?

@erfansn
Copy link

erfansn commented Oct 15, 2024

I have similar issue, when return empty list as deferred symbols next run started with previous symbols

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

No branches or pull requests

2 participants