Skip to content

Kotlin 2.2 #1286

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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
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
8 changes: 6 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ plugins {
alias(dokka)
// alias(kover)
alias(ktlint)
alias(korro) apply false
alias(kodex) apply false

// TODO cannot define korro and kodex here due to leaking them kotlin-compiler-embeddable into the build classpath
// alias(korro) apply false
// alias(kodex) apply false

alias(simpleGit) apply false
alias(dependencyVersions)
alias(buildconfig) apply false
Expand Down Expand Up @@ -155,6 +158,7 @@ val modulesUsingJava11 = with(projects) {
dataframeGeo,
examples.ideaExamples.titanic,
tests,
plugins.dataframeGradlePlugin,
)
}.map { it.path }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,5 @@ public class ReducedGroupBy<T, G>(
}

@PublishedApi
internal fun <T, G> GroupBy<T, G>.reduce(reducer: Selector<DataFrame<G>, DataRow<G>?>) = ReducedGroupBy(this, reducer)
internal fun <T, G> GroupBy<T, G>.reduce(reducer: Selector<DataFrame<G>, DataRow<G>?>): ReducedGroupBy<T, G> =
ReducedGroupBy(this, reducer)
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ public class ReducedPivot<T>(
}

@PublishedApi
internal fun <T> Pivot<T>.reduce(reducer: Selector<DataFrame<T>, DataRow<T>?>) = ReducedPivot(this, reducer)
internal fun <T> Pivot<T>.reduce(reducer: Selector<DataFrame<T>, DataRow<T>?>): ReducedPivot<T> =
ReducedPivot(this, reducer)

@PublishedApi
internal inline fun <T> Pivot<T>.delegate(crossinline body: PivotGroupBy<T>.() -> DataFrame<T>): DataRow<T> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public fun <T> DataFrame<T>.toHTML(
configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT,
cellRenderer: CellRenderer = DefaultCellRenderer,
getFooter: (DataFrame<T>) -> String? = { "DataFrame [${it.size}]" },
) = toHtml(configuration, cellRenderer, getFooter)
): DataFrameHtmlData = toHtml(configuration, cellRenderer, getFooter)

@Deprecated(TO_STANDALONE_HTML, ReplaceWith(TO_STANDALONE_HTML_REPLACE), DeprecationLevel.ERROR)
public fun <T> DataFrame<T>.toStandaloneHTML(
Expand Down
17 changes: 9 additions & 8 deletions dataframe-arrow/api/dataframe-arrow.api
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/io/ArrowWriter :
public abstract fun getMismatchSubscriber ()Lkotlin/jvm/functions/Function1;
public abstract fun getMode ()Lorg/jetbrains/kotlinx/dataframe/io/ArrowWriter$Mode;
public abstract fun getTargetSchema ()Lorg/apache/arrow/vector/types/pojo/Schema;
public abstract fun saveArrowFeatherToByteArray ()[B
public abstract fun saveArrowIPCToByteArray ()[B
public abstract fun writeArrowFeather (Ljava/io/File;)V
public abstract fun writeArrowFeather (Ljava/io/OutputStream;)V
public abstract fun writeArrowFeather (Ljava/nio/channels/WritableByteChannel;)V
public abstract fun writeArrowIPC (Ljava/io/File;Z)V
public abstract fun writeArrowIPC (Ljava/io/OutputStream;)V
public abstract fun writeArrowIPC (Ljava/nio/channels/WritableByteChannel;)V
public fun saveArrowFeatherToByteArray ()[B
public fun saveArrowIPCToByteArray ()[B
public fun writeArrowFeather (Ljava/io/File;)V
public fun writeArrowFeather (Ljava/io/OutputStream;)V
public fun writeArrowFeather (Ljava/nio/channels/WritableByteChannel;)V
public fun writeArrowIPC (Ljava/io/File;Z)V
public fun writeArrowIPC (Ljava/io/OutputStream;)V
public fun writeArrowIPC (Ljava/nio/channels/WritableByteChannel;)V
public static synthetic fun writeArrowIPC$default (Lorg/jetbrains/kotlinx/dataframe/io/ArrowWriter;Ljava/io/File;ZILjava/lang/Object;)V
}

public final class org/jetbrains/kotlinx/dataframe/io/ArrowWriter$Companion {
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version=1.0.0
jupyterApiTCRepo=
kotlin.jupyter.add.scanner=false
org.gradle.jvmargs=-Xmx4G -Duser.language=en -Duser.country=US -Dfile.encoding=UTF-8

# build.number.detection=false
# build.number=0.8.0

Expand All @@ -12,6 +13,9 @@ org.gradle.jvmargs=-Xmx4G -Duser.language=en -Duser.country=US -Dfile.encoding=U
# KSP plugin in the modules that use it.
kotlin.dataframe.add.ksp=false

# We don't support ksp2
ksp.useKSP2=false

# Enables debug mode for dataframe.
# This can make certain tests and checks run that should not be run in production.
# It can also be turned on from the command line with `-Pkotlin.dataframe.debug=true`
Expand Down
14 changes: 7 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[versions]
ksp = "2.0.20-1.0.24"
ksp = "2.2.0-2.0.2"
kotlinJupyter = "0.12.0-383"

ktlint = "12.3.0"

# make sure to sync both manually with :generator module
kotlin = "2.0.20" # needs jupyter compatibility with Kotlin 2.1 to update
kotlinpoet = "1.18.1"
kotlin = "2.2.0" # needs jupyter compatibility with Kotlin 2.1 to update
kotlinpoet = "2.2.0"

dokka = "1.9.20"
libsPublisher = "1.9.23-dev-45"
dokka = "2.0.0"
libsPublisher = "2.2.0-rc3-dev-57"

# "Bootstrap" version of the dataframe, used in the build itself to generate @DataSchema APIs,
# dogfood Gradle / KSP plugins in tests and idea-examples modules
Expand Down Expand Up @@ -48,14 +48,14 @@ jsoup = "1.18.3"
arrow = "18.1.0"
kodex = "0.4.4"
simpleGit = "2.2.1"
dependencyVersions = "0.51.0"
dependencyVersions = "0.52.0"
plugin-publish = "1.3.0"
shadow = "8.3.5"
android-gradle-api = "7.3.1" # need to revise our tests to update
ktor = "3.0.1" # needs jupyter compatibility with Kotlin 2.1 to update
kotlin-compile-testing = "1.6.0"
duckdb = "1.1.3"
buildconfig = "5.5.1"
buildconfig = "5.6.7"
benchmark = "0.4.12"

geotools = "32.1"
Expand Down
4 changes: 2 additions & 2 deletions plugins/dataframe-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies {
implementation(projects.dataframeOpenapiGenerator)

implementation(libs.kotlin.gradle.plugin.api)
implementation(libs.kotlin.gradle.plugin)
compileOnly(libs.kotlin.gradle.plugin)
implementation(libs.serialization.core)
implementation(libs.serialization.json)
implementation(libs.ksp.gradle)
Expand Down Expand Up @@ -100,7 +100,7 @@ val integrationTestConfiguration by configurations.creating {
extendsFrom(configurations.testImplementation.get())
}

val integrationTestTask = task<Test>("integrationTest") {
val integrationTestTask = tasks.register<Test>("integrationTest") {
dependsOn(":plugins:symbol-processor:publishToMavenLocal")
dependsOn(":dataframe-arrow:publishToMavenLocal")
dependsOn(":dataframe-excel:publishToMavenLocal")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.gradle.api.logging.LogLevel
import org.gradle.api.tasks.TaskProvider
import org.gradle.internal.logging.services.DefaultLoggingManager
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrField
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrParameterKind
import org.jetbrains.kotlin.ir.declarations.path
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
import org.jetbrains.kotlin.ir.expressions.IrBody
Expand All @@ -23,7 +24,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
import org.jetbrains.kotlin.ir.expressions.IrGetValue
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImplWithShape
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionExpressionImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl
Expand All @@ -38,8 +39,8 @@ import org.jetbrains.kotlin.ir.types.typeWith
import org.jetbrains.kotlin.ir.util.SetDeclarationsParentVisitor
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
import org.jetbrains.kotlin.ir.util.isLocal
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.IrTransformer
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId
Expand All @@ -51,8 +52,8 @@ data class ContainingDeclarations(val clazz: IrClass?, val function: IrFunction?

@OptIn(UnsafeDuringIrConstructionAPI::class)
class ExplainerIrTransformer(val pluginContext: IrPluginContext) :
FileLoweringPass,
IrElementTransformer<ContainingDeclarations> {
IrTransformer<ContainingDeclarations>(),
FileLoweringPass {
lateinit var file: IrFile
lateinit var source: String

Expand Down Expand Up @@ -151,12 +152,15 @@ class ExplainerIrTransformer(val pluginContext: IrPluginContext) :
if (expression.startOffset < 0) return expression
if (expression.type.classFqName in dataFrameLike) {
if (expression.symbol.owner.name == Name.identifier("component1")) return expression
var receiver = expression.extensionReceiver
// expression.extensionReceiver = extension callables,
val extensionReceiverIndex =
expression.symbol.owner.parameters.indexOfFirst { it.kind == IrParameterKind.ExtensionReceiver }
var receiver: IrExpression?
// expression.arguments[extensionReceiverIndex] = extension callables,
// expression.dispatchReceiver = member callables such as "GroupBy.aggregate"
if (receiver != null) {
val transformedExtensionReceiver = expression.extensionReceiver?.transform(this, data)
expression.extensionReceiver = transformedExtensionReceiver
if (extensionReceiverIndex >= 0) {
receiver = expression.arguments[extensionReceiverIndex]!!
val transformedExtensionReceiver = receiver.transform(this, data)
expression.arguments[extensionReceiverIndex] = transformedExtensionReceiver
} else {
receiver = expression.dispatchReceiver
val transformedExtensionReceiver = expression.dispatchReceiver?.transform(this, data)
Expand All @@ -179,9 +183,26 @@ class ExplainerIrTransformer(val pluginContext: IrPluginContext) :
CallableId(FqName("kotlin"), Name.identifier("also")),
).single()

val result = IrCallImpl(-1, -1, expression.type, alsoReference, 1, 1).apply {
this.extensionReceiver = expression
putTypeArgument(0, expression.type)
val result = IrCallImplWithShape(
startOffset = -1,
endOffset = -1,
type = expression.type,
symbol = alsoReference,
typeArgumentsCount = 1,
valueArgumentsCount = 1,
contextParameterCount = 0,
hasDispatchReceiver = true,
hasExtensionReceiver = true,
).apply {
val extensionReceiverIndex =
this.symbol.owner.parameters.indexOfFirst { it.kind == IrParameterKind.ExtensionReceiver }
if (extensionReceiverIndex >= 0) {
this.arguments[extensionReceiverIndex] = expression
} else {
this.insertExtensionReceiver(expression)
}

typeArguments[0] = expression.type

val symbol = IrSimpleFunctionSymbolImpl()
val alsoLambda = pluginContext.irFactory
Expand All @@ -202,25 +223,24 @@ class ExplainerIrTransformer(val pluginContext: IrPluginContext) :
isInfix = false,
isExpect = false,
).apply {
valueParameters = buildList {
add(
pluginContext.irFactory.createValueParameter(
startOffset = -1,
endOffset = -1,
origin = IrDeclarationOrigin.DEFINED,
symbol = IrValueParameterSymbolImpl(),
name = Name.identifier("it"),
index = 0,
type = expression.type,
varargElementType = null,
isCrossinline = false,
isNoinline = false,
isHidden = false,
isAssignable = false,
),
// replace all regular value parameters with a single one `it`
parameters = parameters.filterNot { it.kind == IrParameterKind.Regular } +
pluginContext.irFactory.createValueParameter(
startOffset = -1,
endOffset = -1,
origin = IrDeclarationOrigin.DEFINED,
kind = IrParameterKind.Regular,
name = Name.identifier("it"),
type = expression.type,
isAssignable = false,
symbol = IrValueParameterSymbolImpl(),
varargElementType = null,
isCrossinline = false,
isNoinline = false,
isHidden = false,
)
}
val itSymbol = valueParameters[0].symbol

val itSymbol = parameters.first { it.kind == IrParameterKind.Regular }.symbol
val source = try {
source.substring(expression.startOffset, expression.endOffset)
} catch (e: Exception) {
Expand All @@ -229,14 +249,21 @@ class ExplainerIrTransformer(val pluginContext: IrPluginContext) :
val expressionId = expressionId(expression)
val receiverId = receiver?.let { expressionId(it) }
val valueArguments = buildList<IrExpression?> {
add(source.irConstImpl())
add(ownerName.asStringStripSpecialMarkers().irConstImpl())
add(IrGetValueImpl(-1, -1, itSymbol))
add(expressionId.irConstImpl())
add(receiverId.irConstImpl())
add(data.clazz?.fqNameWhenAvailable?.asString().irConstImpl())
add(data.function?.name?.asString().irConstImpl())
add(IrConstImpl.int(-1, -1, pluginContext.irBuiltIns.intType, data.statementIndex))
add(source.irConstImpl()) // source: String
add(ownerName.asStringStripSpecialMarkers().irConstImpl()) // name: String
add(IrGetValueImpl(-1, -1, itSymbol)) // df: Any
add(expressionId.irConstImpl()) // id: String
add(receiverId.irConstImpl()) // receiverId: String?
add(data.clazz?.fqNameWhenAvailable?.asString().irConstImpl()) // containingClassFqName: String?
add(data.function?.name?.asString().irConstImpl()) // containingFunName: String?
add(
IrConstImpl.int(
-1,
-1,
pluginContext.irBuiltIns.intType,
data.statementIndex,
),
) // statementIndex: Int
}
body = pluginContext.irFactory.createBlockBody(-1, -1).apply {
val callableId = CallableId(
Expand All @@ -245,19 +272,24 @@ class ExplainerIrTransformer(val pluginContext: IrPluginContext) :
Name.identifier("doAction"),
)
val doAction = pluginContext.referenceFunctions(callableId).single()
statements += IrCallImpl(
statements += IrCallImplWithShape(
startOffset = -1,
endOffset = -1,
type = doAction.owner.returnType,
symbol = doAction,
typeArgumentsCount = 0,
valueArgumentsCount = valueArguments.size,
contextParameterCount = 0,
hasDispatchReceiver = true,
hasExtensionReceiver = false,
).apply {
val clazz = ClassId(explainerPackage, Name.identifier("PluginCallbackProxy"))
val plugin = pluginContext.referenceClass(clazz)!!
dispatchReceiver = IrGetObjectValueImpl(-1, -1, plugin.defaultType, plugin)

val firstValueArgumentIndex = 1 // skipping dispatch receiver
valueArguments.forEachIndexed { i, argument ->
putValueArgument(i, argument)
this.arguments[firstValueArgumentIndex + i] = argument
}
}
}
Expand All @@ -271,12 +303,16 @@ class ExplainerIrTransformer(val pluginContext: IrPluginContext) :
function = alsoLambda,
origin = IrStatementOrigin.LAMBDA,
)
putValueArgument(0, alsoLambdaExpression)

val firstValueArgumentIndex = this.symbol.owner.parameters
.indexOfFirst { it.kind == IrParameterKind.Regular }
.takeUnless { it < 0 } ?: this.symbol.owner.parameters.size
this.arguments[firstValueArgumentIndex] = alsoLambdaExpression
}
return result
}

private fun String?.irConstImpl(): IrConstImpl<out String?> {
private fun String?.irConstImpl(): IrConstImpl {
val nullableString = pluginContext.irBuiltIns.stringType.makeNullable()
val argument = if (this == null) {
IrConstImpl.constNull(-1, -1, nullableString)
Expand Down
Loading