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

Support KSP in BindsMethodValidator #831

Merged
merged 5 commits into from
Apr 3, 2024

Conversation

IlyaGulya
Copy link
Contributor

@IlyaGulya IlyaGulya commented Dec 26, 2023

Part of the issue #751

@CLAassistant
Copy link

CLAassistant commented Dec 26, 2023

CLA assistant check
All committers have signed the CLA.

@IlyaGulya
Copy link
Contributor Author

@ZacSweers
This one is almost done.
There's three tests that are failing because they require dagger compilation:



As far as I can see, dagger compilation with ksp is not yet supported in tests (according to

// TODO Dagger is not supported with KSP in Anvil's tests yet
).
Do I need to do something with these three tests?

@IlyaGulya
Copy link
Contributor Author

Oh, I forgot to write a test for this issue: #750
Will do that tomorrow 🙁

@ZacSweers
Copy link
Collaborator

For those three tests, what you wanna do is enable the KSP validator on the first compilation and then just use the regular dagger processing on the subsequent compilation. Hoping that could work?

Sidenote - there are some related changes I've made in #830 to support Dagger's new behavior in 2.48, but you're welcome to cherry-pick those into this PR since they sorta go together and I can update my PR after this is in

@ZacSweers
Copy link
Collaborator

eh actually the more I think about it, the more I think it'll be smoother for me to just update that PR and get this one through first. I can manage any conflicts. Just know that it's there :)

@IlyaGulya
Copy link
Contributor Author

eh actually the more I think about it, the more I think it'll be smoother for me to just update that PR and get this one through first. I can manage any conflicts. Just know that it's there :)

Ok, now I will fix those three tests and add a test for #750, after that I will wait for your PR to be merged 🙂

@IlyaGulya
Copy link
Contributor Author

@ZacSweers regarding the #750 - I've added test which is correctly passes in KSP mode.
However, I've spent about 4 hours already trying to fix it in Embedded mode and I think it will require another 4-8 hours to get any success =)
Will Embedded mode be replaced by KSP mode or it will stay and I should fix this behavior?

@IlyaGulya
Copy link
Contributor Author

Nevermind, I've fixed #750 🙁

@IlyaGulya IlyaGulya force-pushed the feature/ksp/binds-method-validator branch from dc8c9d7 to 8f0cdf6 Compare December 27, 2023 17:56
@ZacSweers
Copy link
Collaborator

if it's not too difficult, do you think it's possible to split out the fix for #750 to a separate PR first? Might make this easier to review

@IlyaGulya
Copy link
Contributor Author

if it's not too difficult, do you think it's possible to split out the fix for #750 to a separate PR first? Might make this easier to review

Sure!

@IlyaGulya IlyaGulya force-pushed the feature/ksp/binds-method-validator branch from 8f0cdf6 to e153081 Compare December 31, 2023 14:02
@IlyaGulya
Copy link
Contributor Author

@ZacSweers I've extracted #750 fix to #833

@IlyaGulya IlyaGulya force-pushed the feature/ksp/binds-method-validator branch from e153081 to d37d6ca Compare December 31, 2023 14:06
@IlyaGulya IlyaGulya force-pushed the feature/ksp/binds-method-validator branch from d37d6ca to 52e0a97 Compare January 18, 2024 09:12
@IlyaGulya IlyaGulya force-pushed the feature/ksp/binds-method-validator branch from 52e0a97 to 593833a Compare January 27, 2024 06:50
@ZacSweers
Copy link
Collaborator

Let's start reviewing this once #833 is in and this branch is updated. Suspect there will be a decent amount of overlap :)

@ZacSweers
Copy link
Collaborator

@IlyaGulya ping me when you've pulled latest main and we can start review here!

@IlyaGulya IlyaGulya force-pushed the feature/ksp/binds-method-validator branch 3 times, most recently from fbc6d57 to f087463 Compare February 18, 2024 13:18
@IlyaGulya
Copy link
Contributor Author

@ZacSweers done!
I've also removed the receiver parameter validation because extension functions are no longer supported.

Copy link
Collaborator

@ZacSweers ZacSweers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

@@ -352,17 +353,43 @@ class BindsMethodValidatorTest(
}
}

@Test
fun `binding inside interface is valid`() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

private fun compile(
@Language("kotlin") vararg sources: String,
previousCompilationResult: JvmCompilationResult? = null,
enableDagger: Boolean = useDagger,
forceEmbeddedMode: Boolean = false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a small comment explaining why we need this for posterity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to explain it in a comment.
I've added this flag to fix tests according to your suggestion: #831 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a simple comment like "Used to enable the dagger compiler even in KSP mode, which is necessary for some multi-round tests"


clazz to constructors[0]
}
}

private fun requireSingleInjectConstructor(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

.resolveSuperTypesExcludingAny()
.toList()

if (returnType !in parameterSuperTypes) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use KSP's built-in assignability check? KSType.isAssignableFrom(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I did not know about this api. Will fix that =)

)
}

internal inline fun <reified T> Resolver.getAnnotatedSymbols(): Sequence<KSAnnotated> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires all these classes to be on the KSP classpath. This could cause unexpected errors if this processor is run on a source set that doesn't contain them, and we should gracefully degrade in this case. This is why we usually use the fqcn. No need to fix here as we depend directly on these annotations in the compiler artifact anyway, but just a note

private fun compile(
@Language("kotlin") vararg sources: String,
previousCompilationResult: JvmCompilationResult? = null,
enableDagger: Boolean = useDagger,
forceEmbeddedMode: Boolean = false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a simple comment like "Used to enable the dagger compiler even in KSP mode, which is necessary for some multi-round tests"

@ZacSweers
Copy link
Collaborator

Haven't forgotten about this, we just had to revert the embedded impl temporarily due to issues :/. Will revisit once that one is in again, unless you want to rebase this one

@IlyaGulya
Copy link
Contributor Author

@ZacSweers you mean this revert? 5a04d60
I haven't got time to fix that issue yet, unfortunately.
But I can rebase this PR if it will help, for sure 🙂

@IlyaGulya IlyaGulya force-pushed the feature/ksp/binds-method-validator branch from c4d1f71 to d062920 Compare March 26, 2024 12:19
@IlyaGulya
Copy link
Contributor Author

@ZacSweers done 🙂

Copy link
Collaborator

@ZacSweers ZacSweers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking so long on this, appreciate your patience!

@ZacSweers ZacSweers enabled auto-merge (squash) April 3, 2024 17:17
@ZacSweers ZacSweers merged commit e5919f2 into square:main Apr 3, 2024
17 checks passed
@IlyaGulya IlyaGulya deleted the feature/ksp/binds-method-validator branch April 4, 2024 03:32
@gildor gildor mentioned this pull request Apr 8, 2024
15 tasks
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

Successfully merging this pull request may close these issues.

3 participants