-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Use KSP2 #350
base: main
Are you sure you want to change the base?
Use KSP2 #350
Conversation
kotlin-inject-compiler/ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/Util.kt
Outdated
Show resolved
Hide resolved
ba8f1eb
to
bbcc6b9
Compare
c2775ad
to
d5e308f
Compare
9f0d6ec
to
ede41bd
Compare
kotlin-inject-compiler/ksp/src/main/kotlin/me/tatarka/inject/compiler/ksp/Util.kt
Outdated
Show resolved
Hide resolved
kotlin-inject-compiler/test/src/main/kotlin/me/tatarka/inject/ProjectCompiler.kt
Outdated
Show resolved
Hide resolved
bb53268
to
009a7e7
Compare
kotlin-inject-compiler/test/src/main/kotlin/me/tatarka/inject/ProjectCompiler.kt
Outdated
Show resolved
Hide resolved
kotlin-inject-compiler/test/src/main/kotlin/me/tatarka/inject/ProjectCompiler.kt
Outdated
Show resolved
Hide resolved
761cad1
to
f52527a
Compare
8fb90a7
to
82ddb23
Compare
@evant I updated all dependencies to latest versions, but looks like google/ksp#1854 is still an issue, as well as some issues with I probably won't have much time to dedicate to this for the next few months, in case there's anyone who'd like to pick it up. |
The exception
whereas the corresponding element of
Please avoid caching and using the elements across rounds. |
Yup, I started working on that. Not sure if I'm doing something wrong because I'm getting other errors but at least the |
@evant I believe the latest commit fixes the There is still an issue with typealiases (probably related to google/ksp#1921). Most of the |
@@ -1495,7 +1495,7 @@ class FailureTest { | |||
""".trimIndent() | |||
).compile() | |||
}.output().all { | |||
contains("e: [ksp] Cannot find an @Inject constructor or provider for: Foo") | |||
contains("Cannot find an @Inject constructor or provider for: Foo") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evant The e: [ksp]
prefix wasn't present anymore; it was a toString
representation of DiagnosticMessage
The workaround for #447 isn't user friendly. |
Agreed, I'm updating the issue you filed on KSP. |
you can invalidate the cache by changing the cache_key at kotlin-inject/.circleci/config.yml Line 62 in 7f7dcd9
kotlin-inject/.circleci/config.yml Line 82 in 7f7dcd9
btw thanks @eygraber for keeping up with this |
It looks like this happens when running tests after assemble. I'll dig in further. |
data class KmpComponentCreateFunctionInfo( | ||
val name: String, | ||
val annotations: List<AnnotationSpec>, | ||
val visibility: KModifier, | ||
val receiverParameterType: TypeName?, | ||
val parameters: List<Pair<String, TypeName>>, | ||
val parametersTemplate: String, | ||
val parameterNames: List<String>, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copying everything out of the ast to preserve it between rounds seems really not ideal to me, and I worry about how it'd interact with symbols that are only resolvable in future rounds. Not going to block the pr on this since I haven't looked into enough to come up with a better way, but I'll try to investigate that when I get a chance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. The fastest way I could think of to do this was to defer all functions found with resolver.getSymbolsWithAnnotation
and then call resolver.getSymbolsWithAnnotation
in finish
and generate everything there.
Not sure if that's frowned upon in KSP, so I'm also working on a solution that generates a file per function so that nothing needs to be cached. The difficulty there is naming the generated file because it's easy to end up with multiple files named the same.
@@ -24,36 +43,37 @@ class KmpComponentCreateGenerator( | |||
addFunction( | |||
FunSpec | |||
.builder(kmpComponentCreateFunction.name) | |||
.addOriginatingElement(kmpComponentCreateFunction) | |||
// .addOriginatingElement(kmpComponentCreateFunction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mean to leave commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mistake 😅
fun AstType.isPair(): Boolean = packageName == "kotlin" && simpleName == "Pair" | ||
fun AstType.isFunctionOrTypeAliasOfFunction() = isFunction() || isTypeAlias() && resolvedType().isFunction() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does resolvedType().isFunction()
need to be recursive to handle a type alias to a type alias?
CI is blocked by google/ksp#2230. Alternatively we can update the script to run Outstanding questions are:
|
I've seen enough issues that I think it would be good to have overlap supporting both for a bit. What breaks here with ksp1? I don't know if it'll easy to detect which one you are using but we could add an additional option to enable it for now |
Actually it looks like it |
Got some inspiration from https://github.com/amzn/kotlin-inject-anvil/blob/main/compiler-utils/src/testFixtures/kotlin/software/amazon/lastmile/kotlin/inject/anvil/Compilation.kt and figured it out 😄 The only unit tests failing now are the ones that check for a specific error format that changed from KSP1 to KSP2, so I'm thinking that it is fine. |
Updated the unit and integration tests to run with both KSP1 and KSP2. |
looks like it's already fixed! I'm ok with throwing a clean on ci for now until that's released though |
Updated, hopefully that's all that's needed. |
- Avoids issues until google/ksp#2231 is released
No description provided.