Skip to content

Commit

Permalink
Merge pull request #1059 from square/joel.kotlin-2.0.21
Browse files Browse the repository at this point in the history
Upgrade to Kotlin 2.0.21
  • Loading branch information
JoelWilcox authored Dec 4, 2024
2 parents 19fe656 + b9b7bdf commit 285f2bb
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 106 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
kotlin-version: [ 1.9.24 ]
kotlin-version: [ 2.0.21 ]

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Expand All @@ -36,7 +36,7 @@ jobs:
strategy:
fail-fast: false
matrix:
kotlin-version: [ 1.9.24 ]
kotlin-version: [ 2.0.21 ]

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Expand Down Expand Up @@ -162,8 +162,8 @@ jobs:
# solution.
fail-fast: false
matrix:
kotlin-version: [ 1.9.24 ]
agp-version: [ 7.1.1, 7.2.0, 7.3.1 ]
kotlin-version: [ 2.0.21 ]
agp-version: [ 7.2.0, 7.3.1 ]

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Expand Down Expand Up @@ -194,7 +194,7 @@ jobs:
# solution.
fail-fast: false
matrix:
kotlin-version: [ 1.9.24 ]
kotlin-version: [ 2.0.21 ]

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Expand Down
2 changes: 1 addition & 1 deletion annotations-optional/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
javax.inject:javax.inject:1
org.jetbrains.kotlin:kotlin-stdlib:1.9.24
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains:annotations:13.0
2 changes: 1 addition & 1 deletion annotations/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
org.jetbrains.kotlin:kotlin-stdlib:1.9.24
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains:annotations:13.0
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ abstract class BasePlugin : Plugin<Project> {
}

freeCompilerArgs.addAll(extension.kotlinCompilerArgs.get())
// We do not yet support K2, and KAPT + Kotlin 2.0 generates a warning about falling back to
// language version 1.9. Because we treat all warnings as errors, we need to suppress this
// specific warning to not fail the build. Related YT ticket:
// https://youtrack.jetbrains.com/issue/KT-68400/K2-w-Kapt-currently-doesnt-support-language-version-2.0.-Falling-back-to-1.9.
freeCompilerArgs.add("-Xsuppress-version-warnings")

fun isTestSourceSet(): Boolean {
val regex = """(?:gradle|Unit|[aA]ndroid)Test""".toRegex()
Expand Down
13 changes: 7 additions & 6 deletions compiler-api/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
org.jetbrains.intellij.deps:trove4j:1.0.20200330
org.jetbrains.kotlin:kotlin-bom:1.9.24
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.9.24
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.9.24
org.jetbrains.kotlin:kotlin-reflect:1.9.24
org.jetbrains.kotlin:kotlin-script-runtime:1.9.24
org.jetbrains.kotlin:kotlin-stdlib:1.9.24
org.jetbrains.kotlin:kotlin-bom:2.0.21
org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-reflect:2.0.21
org.jetbrains.kotlin:kotlin-script-runtime:2.0.21
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4
org.jetbrains:annotations:13.0
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
Expand Down Expand Up @@ -114,6 +115,7 @@ public class AnvilCompilationException(
message: String,
cause: Throwable? = null,
): AnvilCompilationException {
@OptIn(UnsafeDuringIrConstructionAPI::class)
return AnvilCompilationException(
message = message,
cause = cause,
Expand Down
20 changes: 11 additions & 9 deletions compiler-utils/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
com.google.dagger:dagger:2.51.1
com.squareup:kotlinpoet-jvm:1.16.0
com.squareup:kotlinpoet:1.16.0
com.google.dagger:dagger:2.52
com.squareup:kotlinpoet-jvm:1.18.1
com.squareup:kotlinpoet:1.18.1
jakarta.inject:jakarta.inject-api:2.0.1
javax.inject:javax.inject:1
org.jetbrains.intellij.deps:trove4j:1.0.20200330
org.jetbrains.kotlin:kotlin-bom:1.9.24
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.9.24
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.9.24
org.jetbrains.kotlin:kotlin-reflect:1.9.24
org.jetbrains.kotlin:kotlin-script-runtime:1.9.24
org.jetbrains.kotlin:kotlin-stdlib:1.9.24
org.jetbrains.kotlin:kotlin-bom:2.0.21
org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-reflect:2.0.21
org.jetbrains.kotlin:kotlin-script-runtime:2.0.21
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4
org.jetbrains:annotations:13.0
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.PluginOption
import com.tschuchort.compiletesting.SourceFile
import com.tschuchort.compiletesting.addPreviousResultToClasspath
import com.tschuchort.compiletesting.kspArgs
import com.tschuchort.compiletesting.kspProcessorOptions
import com.tschuchort.compiletesting.kspWithCompilation
import com.tschuchort.compiletesting.symbolProcessorProviders
import dagger.internal.codegen.ComponentProcessor
import dagger.internal.codegen.KspComponentProcessor
import org.intellij.lang.annotations.Language
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.LanguageVersion
import java.io.File
import java.io.OutputStream
import java.nio.file.Files
Expand All @@ -46,7 +47,7 @@ public class AnvilCompilation internal constructor(
disableComponentMerging: Boolean = false,
enableExperimentalAnvilApis: Boolean = true,
trackSourceFiles: Boolean = true,
mode: AnvilCompilationMode = Embedded(emptyList()),
mode: AnvilCompilationMode = Embedded(),
enableAnvil: Boolean = true,
): AnvilCompilation = apply {
checkNotCompiled()
Expand Down Expand Up @@ -153,10 +154,11 @@ public class AnvilCompilation internal constructor(
}
// Run KSP embedded directly within this kotlinc invocation
kspWithCompilation = true
kspArgs["will-have-dagger-factories"] = generateDaggerFactories.toString()
kspArgs["generate-dagger-factories"] = generateDaggerFactories.toString()
kspArgs["generate-dagger-factories-only"] = generateDaggerFactoriesOnly.toString()
kspArgs["disable-component-merging"] = disableComponentMerging.toString()
kspProcessorOptions["will-have-dagger-factories"] = generateDaggerFactories.toString()
kspProcessorOptions["generate-dagger-factories"] = generateDaggerFactories.toString()
kspProcessorOptions["generate-dagger-factories-only"] =
generateDaggerFactoriesOnly.toString()
kspProcessorOptions["disable-component-merging"] = disableComponentMerging.toString()
}
}

Expand Down Expand Up @@ -306,19 +308,20 @@ public fun compileAnvil(
enableExperimentalAnvilApis: Boolean = true,
trackSourceFiles: Boolean = true,
previousCompilationResult: JvmCompilationResult? = null,
mode: AnvilCompilationMode = Embedded(emptyList()),
mode: AnvilCompilationMode = Embedded(),
moduleName: String? = null,
jvmTarget: JvmTarget? = null,
kotlinLanguageVersion: String? = null,
kotlinLanguageVersion: String = LanguageVersion.KOTLIN_1_9.versionString,
expectExitCode: KotlinCompilation.ExitCode? = null,
block: JvmCompilationResult.() -> Unit = { },
): JvmCompilationResult {
return AnvilCompilation()
.apply {
kotlinCompilation.apply {
languageVersion = kotlinLanguageVersion
apiVersion = kotlinLanguageVersion
this.allWarningsAsErrors = allWarningsAsErrors
this.messageOutputStream = messageOutputStream
this.languageVersion = kotlinLanguageVersion
if (workingDir != null) {
this.workingDir = workingDir
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.squareup.anvil.compiler.api.CodeGenerator
public sealed class AnvilCompilationMode(public val analysisBackend: AnalysisBackend) {
public data class Embedded(
val codeGenerators: List<CodeGenerator> = emptyList(),
val useDagger: Boolean = false,
) : AnvilCompilationMode(EMBEDDED)
public data class Ksp(
val symbolProcessorProviders: List<SymbolProcessorProvider> = emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import dagger.Component
import dagger.Module
import dagger.Provides
import dagger.Subcomponent
import org.jetbrains.kotlin.analysis.utils.collections.mapToSet
import org.jetbrains.kotlin.utils.mapToSetOrEmpty
import kotlin.reflect.KClass

@ExperimentalAnvilApi
Expand All @@ -29,7 +29,7 @@ public fun Class<*>.moduleFactoryClass(

val providesMethods = methodsOrCompanionMethods
.filter { it.isAnnotationPresent(Provides::class.java) }
.mapToSet { it.name }
.mapToSetOrEmpty { it.name }

assertWithMessage("No @Provides methods found in $this")
.that(providesMethods)
Expand Down
22 changes: 12 additions & 10 deletions compiler/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
com.google.dagger:dagger:2.51.1
com.squareup:kotlinpoet-jvm:1.16.0
com.squareup:kotlinpoet-ksp:1.16.0
com.squareup:kotlinpoet:1.16.0
com.google.dagger:dagger:2.52
com.squareup:kotlinpoet-jvm:1.18.1
com.squareup:kotlinpoet-ksp:1.18.1
com.squareup:kotlinpoet:1.18.1
jakarta.inject:jakarta.inject-api:2.0.1
javax.annotation:jsr250-api:1.0
javax.inject:javax.inject:1
org.jetbrains.intellij.deps:trove4j:1.0.20200330
org.jetbrains.kotlin:kotlin-bom:1.9.24
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.9.24
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.9.24
org.jetbrains.kotlin:kotlin-reflect:1.9.24
org.jetbrains.kotlin:kotlin-script-runtime:1.9.24
org.jetbrains.kotlin:kotlin-stdlib:1.9.24
org.jetbrains.kotlin:kotlin-bom:2.0.21
org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-reflect:2.0.21
org.jetbrains.kotlin:kotlin-script-runtime:2.0.21
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4
org.jetbrains:annotations:13.0
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrVararg
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.types.classFqName
import org.jetbrains.kotlin.ir.types.classOrFail
import org.jetbrains.kotlin.ir.types.classOrNull
Expand All @@ -49,6 +50,7 @@ import java.io.File
* as super types to Dagger components annotated with `@MergeComponent` or `@MergeSubcomponent`.
* This also supports arbitrary interface merging on interfaces annotated with `@MergeInterfaces`.
*/
@OptIn(org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI::class)
internal class IrContributionMerger(
private val classScanner: ClassScanner,
private val moduleDescriptorFactory: RealAnvilModuleDescriptor.Factory,
Expand Down Expand Up @@ -160,6 +162,7 @@ internal class IrContributionMerger(
irMergesFile.writeText(mergedText)
}

@OptIn(UnsafeDuringIrConstructionAPI::class)
private fun IrBuilderWithScope.addMergedModules(
annotations: List<AnnotationReferenceIr>,
moduleFragment: IrModuleFragment,
Expand Down Expand Up @@ -378,6 +381,7 @@ internal class IrContributionMerger(
contributedModules: Sequence<IrClass>,
annotations: List<AnnotationReferenceIr>,
): IrConstructorCall {
@OptIn(UnsafeDuringIrConstructionAPI::class)
return irCallConstructor(
callee = pluginContext
.referenceConstructors(daggerAnnotationFqName.classIdBestGuess())
Expand Down Expand Up @@ -628,6 +632,7 @@ internal class IrContributionMerger(

// Since we are modifying the state of the code here, this does not need to be reflected in
// the associated [ClassReferenceIr] which is more of an initial snapshot.
@OptIn(UnsafeDuringIrConstructionAPI::class)
clazz.owner.superTypes += toAdd

// Return the list of added supertypes
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/main/java/com/squareup/anvil/compiler/IrUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithName
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.classifierOrNull
import org.jetbrains.kotlin.ir.types.typeOrNull
Expand Down Expand Up @@ -38,6 +39,7 @@ internal fun IrClass.requireClassId(): ClassId {
)
}

@OptIn(UnsafeDuringIrConstructionAPI::class)
internal fun IrClassSymbol.requireClassId(): ClassId = owner.requireClassId()

internal val IrExpression.kclassUnwrapped: IrClassifierSymbol
Expand All @@ -53,6 +55,7 @@ internal val IrDeclarationWithName.fqName: FqName
element = this,
)

@OptIn(UnsafeDuringIrConstructionAPI::class)
internal val IrClassSymbol.fqName: FqName get() = owner.fqName

// If we're evaluating an anonymous inner class, it cannot merge anything and will cause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.expressions.IrConst
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrVararg
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import kotlin.LazyThreadSafetyMode.NONE

internal class AnnotationArgumentReferenceIr(
Expand All @@ -25,6 +26,7 @@ internal class AnnotationArgumentReferenceIr(

// We currently special-case for Classes, but this is the spot we'll need to update if we need to
// support primitives later on.
@OptIn(UnsafeDuringIrConstructionAPI::class)
private fun findValue(): Any {
(argumentExpression as? IrConst<*>)?.let {
return it.value as Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.squareup.anvil.compiler.api.AnvilCompilationException
import com.squareup.anvil.compiler.internal.reference.AnnotationReference
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.util.getArgumentsWithIr
import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.name.FqName
Expand Down Expand Up @@ -83,6 +84,7 @@ internal class AnnotationReferenceIr(
}
}

@OptIn(UnsafeDuringIrConstructionAPI::class)
internal fun IrConstructorCall.toAnnotationReference(
context: IrPluginContext,
declaringClass: ClassReferenceIr?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import org.jetbrains.kotlin.backend.common.lower.parents
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.util.isInterface
import org.jetbrains.kotlin.ir.util.packageFqName
import org.jetbrains.kotlin.ir.util.parents
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import kotlin.LazyThreadSafetyMode.NONE

@OptIn(UnsafeDuringIrConstructionAPI::class)
internal class ClassReferenceIr(
val clazz: IrClassSymbol,
val context: IrPluginContext,
Expand All @@ -31,6 +34,7 @@ internal class ClassReferenceIr(
get() = fqName.shortName().asString()

val enclosingClassesWithSelf: List<ClassReferenceIr> by lazy {
@OptIn(UnsafeDuringIrConstructionAPI::class)
clazz.owner.parents
.filterIsInstance<IrClass>()
.map { it.symbol.toClassReference(context) }
Expand Down
2 changes: 1 addition & 1 deletion gradle-plugin/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
org.jetbrains.kotlin:kotlin-stdlib:1.9.24
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains:annotations:13.0
Loading

0 comments on commit 285f2bb

Please sign in to comment.