Skip to content

Commit

Permalink
type parameter...!
Browse files Browse the repository at this point in the history
  • Loading branch information
ForteScarlet committed Nov 13, 2024
1 parent 62b8c6e commit 1a9f59c
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 9 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/IProject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object IProject : ProjectDetail() {

// Remember the libs.versions.toml!
val ktVersion = "2.0.20"
val pluginVersion = "0.9.3"
val pluginVersion = "0.9.4"

override val version: String = "$ktVersion-$pluginVersion"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.context.MutableCheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.getContainingClassSymbol
import org.jetbrains.kotlin.fir.analysis.checkers.processOverriddenFunctions
import org.jetbrains.kotlin.fir.builder.buildFunctionTypeParameter
import org.jetbrains.kotlin.fir.caches.FirCache
import org.jetbrains.kotlin.fir.caches.firCachesFactory
import org.jetbrains.kotlin.fir.caches.getValue
import org.jetbrains.kotlin.fir.collectUpperBounds
import org.jetbrains.kotlin.fir.copy
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.builder.buildProperty
import org.jetbrains.kotlin.fir.declarations.builder.buildPropertyAccessor
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunctionCopy
import org.jetbrains.kotlin.fir.declarations.builder.buildTypeParameterCopy
import org.jetbrains.kotlin.fir.declarations.builder.*
import org.jetbrains.kotlin.fir.declarations.utils.isFinal
import org.jetbrains.kotlin.fir.declarations.utils.isOverride
import org.jetbrains.kotlin.fir.declarations.utils.isSuspend
Expand All @@ -45,6 +43,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.*
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.ir.builders.declarations.buildTypeParameter
import org.jetbrains.kotlin.name.CallableId
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
Expand Down Expand Up @@ -151,12 +150,20 @@ class SuspendTransformFirTransformer(
// In the generated IR, data and dataBlocking will share an `A`, generating the error.
// The error: Duplicate IR node
// [IR VALIDATION] JvmIrValidationBeforeLoweringPhase: Duplicate IR node: TYPE_PARAMETER name:A index:0 variance: superTypes:[kotlin.Any?] reified:false of FUN GENERATED[...]
// TODO onebot type parameters?
typeParameters.replaceAll {
buildTypeParameterCopy(it) {
symbol = FirTypeParameterSymbol()
containingDeclarationSymbol = newFunSymbol // it.containingDeclarationSymbol
symbol = it.symbol // FirTypeParameterSymbol()
}
}

// valueParameters.replaceAll { vp ->
// buildValueParameterCopy(vp) {
// containingFunctionSymbol = newFunSymbol
// }
// }

annotations.clear()
annotations.addAll(functionAnnotations)
body = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,47 @@ public class Bar : java/lang/Object {
}

public final class Foo$DefaultImpls : java/lang/Object {
public static java.util.concurrent.CompletableFuture runAsync(Foo $this)

public static java.lang.Object runBlocking(Foo $this)

public static java.util.concurrent.CompletableFuture valueAsync(Foo $this)

public static Bar valueBlocking(Foo $this)
}

final class Foo$runAsync$1 : kotlin/coroutines/jvm/internal/SuspendLambda, kotlin/jvm/functions/Function1 {
int label

final Foo this$0

void <init>(Foo $receiver, kotlin.coroutines.Continuation $completion)

public final kotlin.coroutines.Continuation create(kotlin.coroutines.Continuation $completion)

public final java.lang.Object invoke(kotlin.coroutines.Continuation p1)

public java.lang.Object invoke(java.lang.Object p1)

public final java.lang.Object invokeSuspend(java.lang.Object $result)
}

final class Foo$runBlocking$1 : kotlin/coroutines/jvm/internal/SuspendLambda, kotlin/jvm/functions/Function1 {
int label

final Foo this$0

void <init>(Foo $receiver, kotlin.coroutines.Continuation $completion)

public final kotlin.coroutines.Continuation create(kotlin.coroutines.Continuation $completion)

public final java.lang.Object invoke(kotlin.coroutines.Continuation p1)

public java.lang.Object invoke(java.lang.Object p1)

public final java.lang.Object invokeSuspend(java.lang.Object $result)
}

final class Foo$valueAsync$1 : kotlin/coroutines/jvm/internal/SuspendLambda, kotlin/jvm/functions/Function1 {
int label

Expand Down Expand Up @@ -41,6 +77,12 @@ final class Foo$valueBlocking$1 : kotlin/coroutines/jvm/internal/SuspendLambda,
}

public abstract interface Foo : java/lang/Object {
public abstract java.lang.Object run(kotlin.coroutines.Continuation p0)

public abstract java.util.concurrent.CompletableFuture runAsync()

public abstract java.lang.Object runBlocking()

public abstract java.lang.Object value(kotlin.coroutines.Continuation p0)

public abstract java.util.concurrent.CompletableFuture valueAsync()
Expand All @@ -51,6 +93,10 @@ public abstract interface Foo : java/lang/Object {
public final class FooImpl : java/lang/Object, Foo {
public void <init>()

public java.util.concurrent.CompletableFuture runAsync()

public java.lang.Object runBlocking()

public java.lang.Object value(kotlin.coroutines.Continuation $completion)

public java.util.concurrent.CompletableFuture valueAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ FILE fqName:<root> fileName:/Main.kt
overridden:
public open fun hashCode (): kotlin.Int declared in <root>.Foo
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN FAKE_OVERRIDE name:run visibility:public modality:ABSTRACT <R> ($this:<root>.Foo<<root>.Tar>) returnType:R of <root>.Foo.runBlocking [suspend,fake_override]
annotations:
JvmBlocking(baseName = <null>, suffix = <null>, asProperty = <null>)
JvmAsync(baseName = <null>, suffix = <null>, asProperty = <null>)
overridden:
public abstract fun run <R> (): R of <root>.Foo.runBlocking declared in <root>.Foo
TYPE_PARAMETER name:R index:0 variance: superTypes:[kotlin.Any] reified:false
$this: VALUE_PARAMETER name:<this> type:<root>.Foo<<root>.Tar>
FUN FAKE_OVERRIDE name:runAsync visibility:public modality:OPEN <R> ($this:<root>.Foo<<root>.Tar>) returnType:java.util.concurrent.CompletableFuture [fake_override]
annotations:
Api4J
overridden:
public open fun runAsync <R> (): java.util.concurrent.CompletableFuture declared in <root>.Foo
TYPE_PARAMETER name:R index:0 variance: superTypes:[kotlin.Any] reified:false
$this: VALUE_PARAMETER name:<this> type:<root>.Foo<<root>.Tar>
FUN FAKE_OVERRIDE name:runBlocking visibility:public modality:OPEN <R> ($this:<root>.Foo<<root>.Tar>) returnType:R of <root>.FooImpl.runBlocking [fake_override]
annotations:
Api4J
overridden:
public open fun runBlocking <R> (): R of <root>.Foo.runBlocking declared in <root>.Foo
TYPE_PARAMETER name:R index:0 variance: superTypes:[kotlin.Any] reified:false
$this: VALUE_PARAMETER name:<this> type:<root>.Foo<<root>.Tar>
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
overridden:
public open fun toString (): kotlin.String declared in <root>.Foo
Expand Down Expand Up @@ -91,6 +113,38 @@ FILE fqName:<root> fileName:/Main.kt
overridden:
public open fun toString (): kotlin.String declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN GENERATED[love.forte.plugin.suspendtrans.fir.SuspendTransformPluginKey] name:runAsync visibility:public modality:OPEN <R> ($this:<root>.Foo<T of <root>.Foo>) returnType:java.util.concurrent.CompletableFuture
annotations:
Api4J
TYPE_PARAMETER name:R index:0 variance: superTypes:[kotlin.Any] reified:false
$this: VALUE_PARAMETER name:<this> type:<root>.Foo<T of <root>.Foo>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun runAsync <R> (): java.util.concurrent.CompletableFuture declared in <root>.Foo'
CALL 'public final fun $runInAsync$ <T> (block: kotlin.coroutines.SuspendFunction0<T of love.forte.plugin.suspendtrans.runtime.$runInAsync$>, scope: kotlinx.coroutines.CoroutineScope?): java.util.concurrent.CompletableFuture declared in love.forte.plugin.suspendtrans.runtime' type=java.util.concurrent.CompletableFuture origin=null
<T>: <none>
block: FUN_EXPR type=kotlin.coroutines.SuspendFunction0<java.util.concurrent.CompletableFuture> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<no name provided> visibility:local modality:FINAL <> () returnType:java.util.concurrent.CompletableFuture [suspend]
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <no name provided> (): java.util.concurrent.CompletableFuture declared in <root>.Foo.runAsync'
CALL 'public abstract fun run <R> (): R of <root>.Foo.runBlocking declared in <root>.Foo' type=R of <root>.Foo.runBlocking origin=null
<R>: <none>
$this: GET_VAR '<this>: <root>.Foo<T of <root>.Foo> declared in <root>.Foo.runAsync' type=<root>.Foo<T of <root>.Foo> origin=null
FUN GENERATED[love.forte.plugin.suspendtrans.fir.SuspendTransformPluginKey] name:runBlocking visibility:public modality:OPEN <R> ($this:<root>.Foo<T of <root>.Foo>) returnType:R of <root>.Foo.runBlocking
annotations:
Api4J
TYPE_PARAMETER name:R index:0 variance: superTypes:[kotlin.Any] reified:false
$this: VALUE_PARAMETER name:<this> type:<root>.Foo<T of <root>.Foo>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun runBlocking <R> (): R of <root>.Foo.runBlocking declared in <root>.Foo'
CALL 'public final fun $runInBlocking$ <T> (block: kotlin.coroutines.SuspendFunction0<T of love.forte.plugin.suspendtrans.runtime.$runInBlocking$>): T of love.forte.plugin.suspendtrans.runtime.$runInBlocking$ declared in love.forte.plugin.suspendtrans.runtime' type=T of love.forte.plugin.suspendtrans.runtime.$runInBlocking$ origin=null
<T>: <none>
block: FUN_EXPR type=kotlin.coroutines.SuspendFunction0<R of <root>.Foo.runBlocking> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<no name provided> visibility:local modality:FINAL <> () returnType:R of <root>.Foo.runBlocking [suspend]
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun <no name provided> (): R of <root>.Foo.runBlocking declared in <root>.Foo.runBlocking'
CALL 'public abstract fun run <R> (): R of <root>.Foo.runBlocking declared in <root>.Foo' type=R of <root>.Foo.runBlocking origin=null
<R>: <none>
$this: GET_VAR '<this>: <root>.Foo<T of <root>.Foo> declared in <root>.Foo.runBlocking' type=<root>.Foo<T of <root>.Foo> origin=null
FUN GENERATED[love.forte.plugin.suspendtrans.fir.SuspendTransformPluginKey] name:valueAsync visibility:public modality:OPEN <> ($this:<root>.Foo<T of <root>.Foo>) returnType:java.util.concurrent.CompletableFuture
annotations:
Api4J
Expand Down Expand Up @@ -119,6 +173,13 @@ FILE fqName:<root> fileName:/Main.kt
RETURN type=kotlin.Nothing from='local final fun <no name provided> (): T of <root>.Foo declared in <root>.Foo.valueBlocking'
CALL 'public abstract fun value (): T of <root>.Foo declared in <root>.Foo' type=T of <root>.Foo origin=null
$this: GET_VAR '<this>: <root>.Foo<T of <root>.Foo> declared in <root>.Foo.valueBlocking' type=<root>.Foo<T of <root>.Foo> origin=null
FUN name:run visibility:public modality:ABSTRACT <R> ($this:<root>.Foo<T of <root>.Foo>) returnType:R of <root>.Foo.runBlocking [suspend]
annotations:
JvmBlocking(baseName = <null>, suffix = <null>, asProperty = <null>)
JvmAsync(baseName = <null>, suffix = <null>, asProperty = <null>)
JvmSynthetic
TYPE_PARAMETER name:R index:0 variance: superTypes:[kotlin.Any] reified:false
$this: VALUE_PARAMETER name:<this> type:<root>.Foo<T of <root>.Foo>
FUN name:value visibility:public modality:ABSTRACT <> ($this:<root>.Foo<T of <root>.Foo>) returnType:T of <root>.Foo [suspend]
annotations:
JvmBlocking(baseName = <null>, suffix = <null>, asProperty = <null>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ FILE: Main.kt
public abstract interface Foo<out T : R|Bar|> : R|kotlin/Any| {
@R|love/forte/plugin/suspendtrans/annotation/JvmBlocking|() @R|love/forte/plugin/suspendtrans/annotation/JvmAsync|() public abstract suspend fun value(): R|T|

@R|love/forte/plugin/suspendtrans/annotation/JvmBlocking|() @R|love/forte/plugin/suspendtrans/annotation/JvmAsync|() public abstract suspend fun <R : R|kotlin/Any|> run(): R|R|

@R|love/forte/plugin/suspendtrans/annotation/Api4J|() public open fun valueAsync(): R|java/util/concurrent/CompletableFuture<out T>|

@R|love/forte/plugin/suspendtrans/annotation/Api4J|() public open fun valueBlocking(): R|T|

@R|love/forte/plugin/suspendtrans/annotation/Api4J|() public open fun <R : R|kotlin/Any|> runAsync(): R|java/util/concurrent/CompletableFuture<out R>|

@R|love/forte/plugin/suspendtrans/annotation/Api4J|() public open fun <R : R|kotlin/Any|> runBlocking(): R|R|

}
public final class FooImpl : R|Foo<Tar>| {
public constructor(): R|FooImpl| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ interface Foo<out T : Bar> {
@JvmAsync
suspend fun value(): T

@JvmBlocking
@JvmAsync
suspend fun <R : Any> run(): R
}

class FooImpl : Foo<Tar> {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ include(":runtime:suspend-transform-runtime")
include(":plugins:suspend-transform-plugin-gradle")

//Samples
//include(":tests:test-jvm")
include(":tests:test-jvm")
//include(":tests:test-js")
4 changes: 2 additions & 2 deletions tests/test-jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("love.forte.plugin.suspend-transform:suspend-transform-plugin-gradle:2.0.20-0.9.3")
classpath("org.jetbrains.kotlin:kotlin-compiler:2.1.0-Beta1")
classpath("love.forte.plugin.suspend-transform:suspend-transform-plugin-gradle:2.0.20-0.9.4")
classpath("org.jetbrains.kotlin:kotlin-compiler:2.0.20")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package love.forte.plugin.suspendtrans.sample

import love.forte.plugin.suspendtrans.annotation.JvmAsync

interface Api<T : Any> {
suspend fun run(): T
}

interface ApiResult<T : Any>

/**
*
* @author ForteScarlet
*/
interface ApiExecutable {
@JvmAsync
fun <T : Any> execute(api: Api<T>): T // ApiResult<T>
}

0 comments on commit 1a9f59c

Please sign in to comment.