Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ kotlin {
androidNativeX86()
androidNativeX64()

@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
freeCompilerArgs.add("-Xcontext-parameters")
}
}
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
kotlinMininumSupported = "2.3.0"
kotlin = "2.3.20"
kotlinMininumSupported = "2.4.0-Beta2"
kotlin = "2.4.0-Beta2"
kotlinx-coroutines = "1.10.2"
buildconfig = "5.7.0"
google-autoservice = "1.1.1"
atomicfu = "0.31.0"
dokka = "2.1.0"
poko = "0.21.1"
poko = "0.22.1"
vanniktech-publish-plugin = "0.36.0"
gradle-portal-publish = "2.0.0"

Expand Down
2 changes: 0 additions & 2 deletions mokkery-core-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ plugins {
// no publishing - it's embedded into the plugin
}

kotlin.compilerOptions.freeCompilerArgs.add("-Xcontext-parameters")

kotlin.sourceSets.all {
languageSettings.apply {
optIn("org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package dev.mokkery.plugin.core.ir

import dev.mokkery.plugin.core.ir.compat.referenceClassCompat
import dev.mokkery.plugin.core.ir.compat.referenceFunctionsCompat
import dev.mokkery.plugin.core.ir.compat.referencePropertiesCompat
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrProperty
Expand All @@ -27,20 +24,25 @@ class IrFunctionById(
private val id: CallableId,
private val predicate: (IrSimpleFunctionSymbol) -> Boolean = { true }
) : IrFunctionReferencer {
override fun reference(context: IrPluginContext): IrSimpleFunction = context.referenceFunctionsCompat(id)


override fun reference(context: IrPluginContext): IrSimpleFunction = context.finderForBuiltins()
.findFunctions(id)
.find(predicate)
?.owner
?: runtimeDependencyError(id.toString())
}

class IrClassById(private val id: ClassId) : IrClassReferencer {
override fun reference(context: IrPluginContext): IrClass = context.referenceClassCompat(id)
override fun reference(context: IrPluginContext): IrClass = context.finderForBuiltins()
.findClass(id)
?.owner
?: runtimeDependencyError(id.toString())
}

class IrPropertyById(private val id: CallableId) : IrPropertyReferencer {
override fun reference(context: IrPluginContext): IrProperty = context.referencePropertiesCompat(id)
override fun reference(context: IrPluginContext): IrProperty = context.finderForBuiltins()
.findProperties(id)
.firstOrNull()
?.owner
?: runtimeDependencyError(id.toString())
Expand Down
3 changes: 0 additions & 3 deletions mokkery-core-tooling/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ plugins {
kotlin {
explicitApi()
optInMokkeryDelicateAndInternals()
compilerOptions {
freeCompilerArgs.add("-Xcontext-parameters")
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ private val buildFileContent = $$"""
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
freeCompilerArgs.add("-Xcontext-parameters")
}
}

Expand Down
2 changes: 0 additions & 2 deletions mokkery-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ plugins {
id("mokkery-publish")
}

kotlin.compilerOptions.freeCompilerArgs.add("-Xcontext-parameters")

kotlin.sourceSets.all {
languageSettings.apply {
optIn("org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import org.jetbrains.kotlin.fir.expressions.FirSpreadArgumentExpression
import org.jetbrains.kotlin.fir.expressions.FirWrappedArgumentExpression
import org.jetbrains.kotlin.fir.expressions.resolvedArgumentMapping
import org.jetbrains.kotlin.fir.expressions.unwrapExpression
import org.jetbrains.kotlin.fir.resolve.isArrayOfCall
import org.jetbrains.kotlin.fir.resolve.toClassLikeSymbol
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirArrayOfCallTransformer.Companion.isArrayOfCall
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
Expand All @@ -31,8 +31,8 @@ fun FirFunctionCall.allNonDispatchArgumentsMapping(symbol: FirFunctionSymbol<*>)
+ symbol.valueParameterSymbols.size
+ if (receiverParameterSymbol != null) 1 else 0
)
for (i in 0..<contextSymbols.size) {
map[contextSymbols[i]] = contextArguments[i]
for ((i, element) in contextSymbols.withIndex()) {
map[element] = contextArguments[i]
}
if (receiverParameterSymbol != null) {
map[receiverParameterSymbol] = extensionReceiver!!
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dev.mokkery.plugin.fir.diagnostics

import dev.mokkery.plugin.Mokkery
import dev.mokkery.plugin.fir.acceptsMatcher
import dev.mokkery.plugin.fir.compat.isNamedFunctionCompat
import dev.mokkery.plugin.fir.getMatcherAnnotation
import dev.mokkery.plugin.fir.isMatcher
import dev.mokkery.plugin.fir.isMokkeryMatcherScope
Expand All @@ -18,6 +17,7 @@ import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirFunctionChecker
import org.jetbrains.kotlin.fir.declarations.FirFunction
import org.jetbrains.kotlin.fir.declarations.FirNamedFunction
import org.jetbrains.kotlin.fir.declarations.utils.isExternal
import org.jetbrains.kotlin.fir.declarations.utils.modality
import org.jetbrains.kotlin.fir.resolve.defaultType
Expand Down Expand Up @@ -67,7 +67,7 @@ class MatchersDeclarationChecker(

context(context: CheckerContext, reporter: DiagnosticReporter)
private fun checkOrigin(declaration: FirFunction) {
if (!declaration.isNamedFunctionCompat()) {
if (declaration !is FirNamedFunction) {
reporter.reportOn(declaration.source, Diagnostics.MATCHER_MUST_BE_REGULAR_FUNCTION)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dev.mokkery.plugin.fir.diagnostics
import dev.mokkery.plugin.Mokkery.Callable
import dev.mokkery.plugin.fir.acceptsMatcher
import dev.mokkery.plugin.fir.allNonDispatchArgumentsMapping
import dev.mokkery.plugin.fir.compat.isSimpleFunctionCompat
import dev.mokkery.plugin.fir.dispatchReceiverClassLikeSymbolOrNull
import dev.mokkery.plugin.fir.extractArrayLiteralCall
import dev.mokkery.plugin.fir.isSpread
Expand Down Expand Up @@ -88,8 +87,6 @@ class MatchersUsageReporterVisitor(
private val legalizedNonMemberFunctionWithMatchers = mutableSetOf<FirFunctionCall>()

override fun visitElement(element: FirElement) {
// backward compat - cannot override removed type so it's handled here
if (element is FirFunction && element.isSimpleFunctionCompat()) return visitFunction(element)
element.acceptChildren(this)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.mokkery.plugin.ir

import dev.mokkery.plugin.ir.compat.LOCAL_FUNCTION_FOR_LAMBDA_COMPAT
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
import org.jetbrains.kotlin.backend.common.lower.irIfThen
import org.jetbrains.kotlin.backend.common.lower.irNot
Expand Down Expand Up @@ -100,7 +99,7 @@ fun IrBuilderWithScope.irLambdaOf(
this.returnType = returnType
this.isSuspend = lambdaType.isSuspendFunction()
visibility = DescriptorVisibilities.LOCAL
origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA_COMPAT
origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
}.apply {
val bodyBuilder = DeclarationIrBuilder(context, symbol, startOffset, endOffset)
params.forEachIndexed { i, it ->
Expand Down
21 changes: 5 additions & 16 deletions mokkery-plugin/src/main/kotlin/dev/mokkery/plugin/ir/IrClass.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package dev.mokkery.plugin.ir

import dev.mokkery.plugin.ir.annotations.AnnotationFilter
import dev.mokkery.plugin.ir.annotations.deepApplyAnnotationsFilter
import dev.mokkery.plugin.ir.compat.DEFAULT_PROPERTY_ACCESSOR_COMPAT
import dev.mokkery.plugin.ir.compat.DEFINED_COMPAT
import dev.mokkery.plugin.ir.compat.addBackingFieldCompat
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.descriptors.Modality
Expand Down Expand Up @@ -65,14 +62,6 @@ fun IrClass.getEnumEntry(name: String): IrEnumEntry {
.first { it.name == Name.identifier(name) }
}

fun IrType.forEachIndexedTypeArgument(block: (Int, IrType?) -> Unit) {
(this as? IrSimpleType)
?.arguments
?.forEachIndexed { index, it ->
block(index, it.typeOrNull?.eraseTypeParameters())
}
}

fun List<IrType>.forEachIndexedTypeArgument(block: (Int, IrType?) -> Unit) {
memoryOptimizedFlatMap { (it as? IrSimpleType)?.arguments.orEmpty() }
.forEachIndexed { index, it -> block(index, it.typeOrNull?.eraseTypeParameters()) }
Expand All @@ -98,7 +87,7 @@ fun IrClass.addOverridingMethod(
updateFrom(function)
name = function.name
modality = Modality.FINAL
origin = IrDeclarationOrigin.DEFINED_COMPAT
origin = IrDeclarationOrigin.DEFINED
isFakeOverride = false
}.apply {
overriddenSymbols = function.overriddenSymbols + functions.map(IrSimpleFunction::symbol)
Expand Down Expand Up @@ -182,7 +171,7 @@ fun IrClass.addOverridingProperty(
updateFrom(property)
name = property.name
modality = Modality.FINAL
origin = IrDeclarationOrigin.DEFINED_COMPAT
origin = IrDeclarationOrigin.DEFINED
isFakeOverride = false
}.apply {
overriddenSymbols = property.overriddenSymbols + properties.map(IrProperty::symbol)
Expand Down Expand Up @@ -222,17 +211,17 @@ fun IrClass.overridePropertyBackingField(context: IrGeneratorContext, property:
name = property.name
isVar = property.isVar
modality = Modality.FINAL
origin = IrDeclarationOrigin.DEFINED_COMPAT
origin = IrDeclarationOrigin.DEFINED
}.apply {
val returnType = property.getter!!.returnType
addBackingFieldCompat {
addBackingField {
type = returnType
visibility = DescriptorVisibilities.PRIVATE
}
overriddenSymbols = listOf(property.symbol)
addGetter {
this.returnType = returnType
origin = IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR_COMPAT
origin = IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR
}.apply {
parameters = listOf(createDispatchReceiverParameterWithClassParent())
body = DeclarationIrBuilder(context, symbol).irBlockBody {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import org.jetbrains.kotlin.backend.jvm.codegen.AnnotationCodegen.Companion.anno
import org.jetbrains.kotlin.ir.declarations.IrMutableAnnotationContainer
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.expressions.IrAnnotation
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.removeAnnotations
import org.jetbrains.kotlin.ir.util.kotlinFqName
import org.jetbrains.kotlin.name.FqName

fun interface AnnotationFilter {

fun filter(annotations: List<IrConstructorCall>): List<IrConstructorCall>
fun filter(annotations: List<IrAnnotation>): List<IrAnnotation>

companion object {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.mokkery.plugin.ir.transformer.mock.stubs

import dev.mokkery.plugin.Kotlin
import dev.mokkery.plugin.core.ir.compat.referenceFunctionsCompat
import dev.mokkery.plugin.core.ir.pluginContext
import dev.mokkery.plugin.ir.irCall
import org.jetbrains.kotlin.ir.types.IrSimpleType
Expand All @@ -26,7 +25,8 @@ object ArrayStubStrategy : StubStrategy {
}
return stub {
val arrayFunc = pluginContext
.referenceFunctionsCompat(CallableId(Kotlin.kotlin, Name.identifier(name)))
.finderForBuiltins()
.findFunctions(CallableId(Kotlin.kotlin, Name.identifier(name)))
.first()
scope.builder.irCall(arrayFunc) {
val typeArgs = (type as IrSimpleType).arguments
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.mokkery.tests

import org.jetbrains.kotlin.platform.wasm.WasmTarget
import org.jetbrains.kotlin.test.services.KotlinStandardLibrariesPathProvider
import java.io.File

Expand Down Expand Up @@ -53,6 +54,10 @@ object ClasspathBasedStandardLibrariesPathProvider : KotlinStandardLibrariesPath

override fun kotlinTestJsKLib(): File = getFile("kotlin-test-js")

override fun fullWasmStdlib(target: WasmTarget): File = getFile("kotlin.wasm.stdlib.${target.alias}.path")

override fun kotlinTestWasmKLib(target: WasmTarget): File = getFile("kotlin.wasm.test.${target.alias}.path")

override fun webStdlibForTests(): File = getFile("kotlin-stdlib-web")

override fun scriptingPluginFilesForTests(): Collection<File> = TODO()
Expand Down
Loading
Loading