[FE, IR] Support deserialization

This commit is contained in:
Anastasiya Shadrina
2021-10-29 05:53:47 +07:00
committed by TeamCityServer
parent 2fbfee3e11
commit 617af898b0
8 changed files with 118 additions and 6 deletions
@@ -15975,6 +15975,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
public void testSimple() throws Exception {
runTest("compiler/testData/codegen/box/extensionClasses/simple.kt");
}
@Test
@TestMetadata("useFromAnotherModule.kt")
public void testUseFromAnotherModule() throws Exception {
runTest("compiler/testData/codegen/box/extensionClasses/useFromAnotherModule.kt");
}
}
@Nested
@@ -16217,6 +16223,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/this.kt");
}
@Test
@TestMetadata("useFromAnotherModule.kt")
public void testUseFromAnotherModule() throws Exception {
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/useFromAnotherModule.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP")
@TestDataPath("$PROJECT_ROOT")
@@ -8,11 +8,13 @@ package org.jetbrains.kotlin.ir.declarations.lazy
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
import org.jetbrains.kotlin.ir.types.IrType
import kotlin.properties.ReadWriteProperty
import org.jetbrains.kotlin.name.Name
interface IrLazyFunctionBase : IrLazyDeclarationBase, IrTypeParametersContainer {
@OptIn(ObsoleteDescriptorBasedAPI::class)
@@ -28,8 +30,17 @@ interface IrLazyFunctionBase : IrLazyDeclarationBase, IrTypeParametersContainer
fun createValueParameters(): List<IrValueParameter> =
typeTranslator.buildWithScope(this) {
descriptor.valueParameters.mapTo(arrayListOf()) {
stubGenerator.generateValueParameterStub(it).apply { parent = this@IrLazyFunctionBase }
val result = arrayListOf<IrValueParameter>()
descriptor.contextReceiverParameters.mapIndexedTo(result) { i, contextReceiverParameter ->
factory.createValueParameter(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, IrValueParameterSymbolImpl(contextReceiverParameter),
Name.identifier("contextReceiverParameter$i"), i, contextReceiverParameter.type.toIrType(),
null, isCrossinline = false, isNoinline = false, isHidden = false, isAssignable = false
).apply { parent = this@IrLazyFunctionBase }
}
descriptor.valueParameters.mapTo(result) {
stubGenerator.generateValueParameterStub(it, it.index + descriptor.contextReceiverParameters.size)
.apply { parent = this@IrLazyFunctionBase }
}
}
@@ -234,7 +234,7 @@ abstract class DeclarationStubGenerator(
private fun KotlinType.toIrType() = typeTranslator.translateType(this)
internal fun generateValueParameterStub(descriptor: ValueParameterDescriptor): IrValueParameter = with(descriptor) {
internal fun generateValueParameterStub(descriptor: ValueParameterDescriptor, index: Int): IrValueParameter = with(descriptor) {
IrLazyValueParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, computeOrigin(this), IrValueParameterSymbolImpl(this), this, name, index,
type.toIrType(), varargElementType?.toIrType(), isCrossinline, isNoinline, isHidden = false, isAssignable = false, this@DeclarationStubGenerator, typeTranslator)
.also { irValueParameter ->
@@ -0,0 +1,25 @@
// !LANGUAGE: +ContextReceivers
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
// MODULE: lib
// FILE: A.kt
package a
class O(val o: String)
context(O)
class OK(val k: String) {
val result = o + k
}
// MODULE: main(lib)
// FILE: B.kt
fun box(): String {
return with(a.O("O")) {
val ok = a.OK("K")
ok.result
}
}
@@ -0,0 +1,31 @@
// !LANGUAGE: +ContextReceivers
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_FIR: JVM_IR
// MODULE: lib
// FILE: A.kt
package a
context(Int)
fun one(dummy: Any?) = this@Int
context(Int)
val two get() = this@Int
class Foo {
context(Int)
val three get() = this@Int
context(Int)
fun four(dummy: Any?) = this@Int
}
// MODULE: main(lib)
// FILE: B.kt
fun box(): String {
return with(1) {
if (a.one(null) + a.two + a.Foo().three + a.Foo().four(null) == 4) "OK" else "fail"
}
}
@@ -15975,6 +15975,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
public void testSimple() throws Exception {
runTest("compiler/testData/codegen/box/extensionClasses/simple.kt");
}
@Test
@TestMetadata("useFromAnotherModule.kt")
public void testUseFromAnotherModule() throws Exception {
runTest("compiler/testData/codegen/box/extensionClasses/useFromAnotherModule.kt");
}
}
@Nested
@@ -16217,6 +16223,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/this.kt");
}
@Test
@TestMetadata("useFromAnotherModule.kt")
public void testUseFromAnotherModule() throws Exception {
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/useFromAnotherModule.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP")
@TestDataPath("$PROJECT_ROOT")