evant
10/10/2020, 8:32 PM(Int) -> String
has the type
kotlin.Function1<Int, String>
and
suspend (Int) -> String
has the type
kotlin.coroutines.SuspendFunction1<Int, String>
would it make sense to represent these more specially as function types? Or maybe have some helpers to detect if a type is a function type, what it's args/return type is, if it's suspend etc?edrd
10/11/2020, 10:20 PMSymbolProcessor#init
like annotation processor interfaces do? Having init
and process
in the same interface forces the declaration of `var`s to reference arguments from init
for later usage in process
. IMO a better approach would be a factory/provider interface:
// ServiceLoader would load this instead
interface SymbolProcessorFactory {
// same args passed to init
fun create(codeGenerator: CodeGenerator, ...): SymbolProcessor
}
interface SymbolProcessor {
fun process(...)
fun finish()
}
Although it would be a little more work to implement, there are some pretty concise ways of doing it:
class Processor(private val codeGenerator: CodeGenerator) : SymbolProcessor {
override fun process(...) { ... }
object Factory : SymbolProcessorFactory {
override fun create(codeGenerator: CodeGenerator, ...) = Processor(codeGenerator)
}
}
This would allow full immutability.spierce7
10/16/2020, 3:20 PMspierce7
10/18/2020, 6:37 PMZac Sweers
10/23/2020, 11:10 PMfun asMemberOf(
property: KSPropertyDeclaration,
containing: KSType
): KSType
Which feels a little java-y. What about this?
fun KSPropertyDeclaration.asMemberOf(
containing: KSType,
resolver: Resolver
): KSType
galex
11/03/2020, 10:22 AMenum class Value {
Default, Value1, Value2
}
class SomeClass(val values: List<Value>) {
fun hasValue1() = values.contains(Value.Value1)
fun hasValue2() = values.contains(Value.Value2)
}
fun main() {
val someClass = SomeClass(listOf(Value.Default, Value.Value1))
someClass.hasValue2() // how to make this call compile time error?
}
As someClass
does not contain Value.Value2
in its values
property, I would like to make a call to hasValue2
a compile time error.
Is it possible to do so?Jiaxiang
11/06/2020, 11:22 PMKSNode.validate()
for more details.Ting-Yuan Huang
11/10/2020, 6:51 PMgetSymbolsWithAnnotation
will need to be rebuilt.
https://github.com/google/ksp/releases/tag/1.4.10-dev-experimental-20201110Zac Sweers
11/11/2020, 1:16 AMZac Sweers
11/21/2020, 10:37 PMZac Sweers
11/29/2020, 9:34 PMKtCallableDeclaration
type to help share with code that can call a function or property. Thoughts on matching this with a KSCallableDeclaration
?Zac Sweers
11/30/2020, 4:18 AMZac Sweers
11/30/2020, 4:21 AMZac Sweers
11/30/2020, 4:32 AMcompileKotlin
task. I imagine it maybe runs the frontend only (i.e. not the backend?), but I thought the frontend was also where the bulk of the slowdown was and being replaced with fir
. On paper it seems like this is effectively running compilation twice like kapt does in its task, which presumable would work via similar mechanismparth
12/03/2020, 5:11 PMZac Sweers
12/06/2020, 12:59 AM@KspExperimental
make sense? I've kind of always only thought of experimental annotations being necessary for stable APIs, feels like unnecessary friction in something that is still being actively developed anywayTing-Yuan Huang
12/22/2020, 5:14 AMksp.incremental=true
. Logs can be enabled by ksp.incremental.log=true
. They are disabled by default so no worries :-)
Incremental processing in KSP relies on processor's knowledge of how inputs are associated with outputs. Therefore, a new parameter is introduced to CodeGenerator.createNewFile
. There is also CodeGenerator.associate
to associate inputs and outputs, in case the relation isn't clear when creating the outputs. This is an API change that breaks existing code. Please see the API for details.
Please give it a try and share your thoughts! We need your help to improve the API.Zac Sweers
12/24/2020, 12:40 AMdependOnNewChanges
would be false?Zac Sweers
12/24/2020, 2:05 AMZac Sweers
12/24/2020, 2:10 AMyigit
12/30/2020, 5:41 PMscript used:
<https://android-review.googlesource.com/c/platform/frameworks/support/+/1531924/11/room/ksp-kapt-comparison.sh>
10 runs (clean compile test app):
total time spent in each group's tasks:
kapt : 34584 ms
ksp : 18671 ms
individual task totals:
kaptGenerateStubsDebugAndroidTestKotlin : 11751 ms
kspDebugAndroidTestKotlin : 17400 ms
kaptDebugAndroidTestKotlin : 21407 ms
kaptAndroidTestDebug : 0 ms
kapt : 0 ms
kaptAndroidTest : 41 ms
kspDebugKotlin : 1225 ms
kaptGenerateStubsDebugKotlin : 799 ms
kaptDebugKotlin : 586 ms
ksp : 46 ms
kaptDebug : 0 ms
Jiaxiang
01/08/2021, 12:49 AMsymbol-processing
to com.google.devtools.ksp
. Now you may remove the resolutionStrategy
for KSP in setting.gradle.kts
since it is no longer needed. See playground in attachment for full detail.
We also planned to enable incremental processing in next release. Here is a doc describing how to use it and also a few examples. Please give it a try!
Issues fixed:
released POM files do not list dependencies #187
[Gradle Plugin] Publish plugin marker #203
Incremental logging does not create a file first #210
PRs merged:
multi-module tests: make sure javaOut exists before passing to compiler #235
Setup depenedencies in compiler plugin’s POM #233
Report INNER modifier for class descriptors #232
Rebuild if processing options changed #229
Don’t calculate incremental info when incremental processing is disabled #227
Make kspTask depends on processors #222
Refine incremental logs #221
document for incremental processing #220
Rename dependOnNewChanges to aggregating #219
Use property descriptor impl for java properties #217
Add generated resource dir to proper sources and outputs #215
Gradle plugin publishing setup #206Zac Sweers
01/10/2021, 5:47 AM> Task :moshi-ksp:moshi-ksp:compileTestKotlin
w: Some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version of the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath
w: /Users/zsweers/.gradle/caches/modules-2/files-2.1/com.google.devtools.ksp/symbol-processing/1.4.20-dev-experimental-20210107/95a5ba4b6dd106b77cbbdc06f1491984b3c6b5/symbol-processing-1.4.20-dev-experimental-20210107.jar: Library has Kotlin runtime bundled into it
Zac Sweers
01/10/2021, 6:37 AMJavaCompile
task to run even if there are no java source files
* What went wrong:
Execution failed for task ':moshi-ksp:moshi-ksp:compileJava'.
> no source files
suresh
01/18/2021, 5:10 AMspierce7
01/21/2021, 12:09 AMmiqbaldc
01/24/2021, 4:39 AMF0X
01/26/2021, 1:17 PMtest
after making changes and having built before (it works after clearing the .gradle
cache).
I have of course added the generated sources to the source set like so
kotlin {
sourceSets {
main {
kotlin.srcDir("build/generated/ksp/main/kotlin")
}
test {
kotlin.srcDir("build/generated/ksp/test/kotlin")
}
}
}
is there anything else that can be done in order to allow access to generated sources in tests?Zac Sweers
02/10/2021, 1:28 AM1.4.30-1.0.0-alpha02
?Ting-Yuan Huang
02/10/2021, 5:06 PMTing-Yuan Huang
02/10/2021, 5:06 PMSymbolProcessor.process()
will be called multiple times until there is no newly generated file.
• SymbolProcessor.process()
now returns a List<KSAnnotated>
, which will be processed again in the next round.
The detailed behavior of multiple round processing can be found here.elihart
02/10/2021, 5:31 PMKT-42182
KAPT: Does not consider generated sources for incremental compilation.” was really important to us and it would be reassuring to know that KSP won’t regress on progress like that. Thanks!Ting-Yuan Huang
02/11/2021, 12:00 AMedrd
02/11/2021, 10:51 PMKSP is open to changes at this alpha stage so please feel free to reach out to us while seeing any bugs or areas to improve, whether they are in the implementation or API design.I'd love if the API didn't require usage of `var`s because of
init
and process
on the same interface. So this:
class Processor : SymbolProcessor {
private lateinit var codeGenerator: CodeGenerator
fun init(codeGenerator: CodeGenerator, ...) {
this.codeGenerator = codeGenerator
}
fun process(...) {}
}
would become this:
class Processor(private val codeGenerator: CodeGenerator) : SymbolProcessor {
override fun process(...) { ... }
object Provider : SymbolProcessorProvider {
override fun create(codeGenerator: CodeGenerator, ...) = Processor(codeGenerator)
}
}
as it's less code and safer. It would also allow for future optimizations like concurrent execution of multiple `SymbolProcessor`s since it would be possible to call SymbolProcessorProvider.create
, for example, for every module.Ting-Yuan Huang
02/11/2021, 10:58 PMedrd
02/22/2021, 4:38 PMmaster
.Ting-Yuan Huang
02/23/2021, 5:01 AMedrd
02/23/2021, 12:39 PMJiaxiang
03/04/2021, 7:52 AMedrd
03/05/2021, 11:40 PM