FIR2IR: pre-cache type parameters before function creation

Type parameters can be referred from e.g. function return type,
so we should determine them earlier to be able to set their indexes
This commit is contained in:
Mikhail Glukhikh
2020-02-20 13:55:12 +03:00
parent 899d471646
commit a3f676317f
12 changed files with 11 additions and 12 deletions
@@ -144,6 +144,12 @@ class Fir2IrDeclarationStorage(
leaveScope(descriptor) leaveScope(descriptor)
} }
private fun preCacheTypeParameters(owner: FirTypeParametersOwner) {
owner.typeParameters.mapIndexed { index, typeParameter ->
getIrTypeParameter(typeParameter, index)
}
}
private fun IrTypeParametersContainer.setTypeParameters(owner: FirTypeParametersOwner) { private fun IrTypeParametersContainer.setTypeParameters(owner: FirTypeParametersOwner) {
typeParameters = owner.typeParameters.mapIndexed { index, typeParameter -> typeParameters = owner.typeParameters.mapIndexed { index, typeParameter ->
getIrTypeParameter(typeParameter, index).apply { parent = this@setTypeParameters } getIrTypeParameter(typeParameter, index).apply { parent = this@setTypeParameters }
@@ -468,6 +474,7 @@ class Fir2IrDeclarationStorage(
val containerSource = function.containerSource val containerSource = function.containerSource
val descriptor = containerSource?.let { WrappedFunctionDescriptorWithContainerSource(it) } ?: WrappedSimpleFunctionDescriptor() val descriptor = containerSource?.let { WrappedFunctionDescriptorWithContainerSource(it) } ?: WrappedSimpleFunctionDescriptor()
val updatedOrigin = if (function.symbol.callableId.isKFunctionInvoke()) IrDeclarationOrigin.FAKE_OVERRIDE else origin val updatedOrigin = if (function.symbol.callableId.isKFunctionInvoke()) IrDeclarationOrigin.FAKE_OVERRIDE else origin
preCacheTypeParameters(function)
return function.convertWithOffsets { startOffset, endOffset -> return function.convertWithOffsets { startOffset, endOffset ->
enterScope(descriptor) enterScope(descriptor)
val result = irSymbolTable.declareSimpleFunction(startOffset, endOffset, origin, descriptor) { symbol -> val result = irSymbolTable.declareSimpleFunction(startOffset, endOffset, origin, descriptor) { symbol ->
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME // WITH_RUNTIME
import kotlin.test.assertEquals import kotlin.test.assertEquals
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS, NATIVE // IGNORE_BACKEND: JS, NATIVE
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME // WITH_RUNTIME
import kotlin.test.assertEquals import kotlin.test.assertEquals
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME // WITH_RUNTIME
import kotlin.test.assertEquals import kotlin.test.assertEquals
@@ -1,5 +1,4 @@
// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType // !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType
// IGNORE_BACKEND_FIR: JVM_IR
fun foo(x: String, y: Char = 'K'): String = x + y fun foo(x: String, y: Char = 'K'): String = x + y
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TODO: muted automatically, investigate should it be ran for JS or not // TODO: muted automatically, investigate should it be ran for JS or not
// DONT_RUN_GENERATED_CODE: JS // DONT_RUN_GENERATED_CODE: JS
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// JVM_TARGET: 1.8 // JVM_TARGET: 1.8
//WITH_RUNTIME //WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM // TARGET_BACKEND: JVM
// FILE: First.java // FILE: First.java
@@ -65,7 +65,7 @@ FILE fqName:test fileName:/boundInnerGenericConstructor.kt
$this: VALUE_PARAMETER name:<this> type:kotlin.Any $this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:foo visibility:public modality:FINAL <A, B> (a:A of test.foo, b:B of test.foo, x:kotlin.Function2<A of test.foo, B of test.foo, test.Foo.Inner<A of test.foo, B of test.foo>>) returnType:test.Foo.Inner<A of test.foo, B of test.foo> [inline] FUN name:foo visibility:public modality:FINAL <A, B> (a:A of test.foo, b:B of test.foo, x:kotlin.Function2<A of test.foo, B of test.foo, test.Foo.Inner<A of test.foo, B of test.foo>>) returnType:test.Foo.Inner<A of test.foo, B of test.foo> [inline]
TYPE_PARAMETER name:A index:0 variance: superTypes:[kotlin.Any?] TYPE_PARAMETER name:A index:0 variance: superTypes:[kotlin.Any?]
TYPE_PARAMETER name:B index:0 variance: superTypes:[kotlin.Any?] TYPE_PARAMETER name:B index:1 variance: superTypes:[kotlin.Any?]
VALUE_PARAMETER name:a index:0 type:A of test.foo VALUE_PARAMETER name:a index:0 type:A of test.foo
VALUE_PARAMETER name:b index:1 type:B of test.foo VALUE_PARAMETER name:b index:1 type:B of test.foo
VALUE_PARAMETER name:x index:2 type:kotlin.Function2<A of test.foo, B of test.foo, test.Foo.Inner<A of test.foo, B of test.foo>> VALUE_PARAMETER name:x index:2 type:kotlin.Function2<A of test.foo, B of test.foo, test.Foo.Inner<A of test.foo, B of test.foo>>
@@ -1,7 +1,7 @@
FILE fqName:<root> fileName:/fixationOrder1.kt FILE fqName:<root> fileName:/fixationOrder1.kt
FUN name:foo visibility:public modality:FINAL <X, Y> () returnType:kotlin.Function1<X of <root>.foo, Y of <root>.foo> FUN name:foo visibility:public modality:FINAL <X, Y> () returnType:kotlin.Function1<X of <root>.foo, Y of <root>.foo>
TYPE_PARAMETER name:X index:0 variance: superTypes:[kotlin.Any?] TYPE_PARAMETER name:X index:0 variance: superTypes:[kotlin.Any?]
TYPE_PARAMETER name:Y index:0 variance: superTypes:[kotlin.Any?] TYPE_PARAMETER name:Y index:1 variance: superTypes:[kotlin.Any?]
BLOCK_BODY BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun foo <X, Y> (): kotlin.Function1<X of <root>.foo, Y of <root>.foo> declared in <root>' RETURN type=kotlin.Nothing from='public final fun foo <X, Y> (): kotlin.Function1<X of <root>.foo, Y of <root>.foo> declared in <root>'
CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin' type=kotlin.Nothing origin=null
@@ -24,7 +24,7 @@ FILE fqName:<root> fileName:/fixationOrder1.kt
$this: VALUE_PARAMETER name:<this> type:kotlin.Any $this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:check visibility:public modality:FINAL <T, R> (x:T of <root>.check, y:R of <root>.check, f:kotlin.Function1<T of <root>.check, R of <root>.check>) returnType:<root>.Inv2<T of <root>.check, R of <root>.check> FUN name:check visibility:public modality:FINAL <T, R> (x:T of <root>.check, y:R of <root>.check, f:kotlin.Function1<T of <root>.check, R of <root>.check>) returnType:<root>.Inv2<T of <root>.check, R of <root>.check>
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
TYPE_PARAMETER name:R index:0 variance: superTypes:[kotlin.Any?] TYPE_PARAMETER name:R index:1 variance: superTypes:[kotlin.Any?]
VALUE_PARAMETER name:x index:0 type:T of <root>.check VALUE_PARAMETER name:x index:0 type:T of <root>.check
VALUE_PARAMETER name:y index:1 type:R of <root>.check VALUE_PARAMETER name:y index:1 type:R of <root>.check
VALUE_PARAMETER name:f index:2 type:kotlin.Function1<T of <root>.check, R of <root>.check> VALUE_PARAMETER name:f index:2 type:kotlin.Function1<T of <root>.check, R of <root>.check>
+1 -1
View File
@@ -1,7 +1,7 @@
FILE fqName:<root> fileName:/builtinMap.kt FILE fqName:<root> fileName:/builtinMap.kt
FUN name:plus visibility:public modality:FINAL <K1, V1> ($receiver:kotlin.collections.Map<out K1 of <root>.plus, V1 of <root>.plus>, pair:kotlin.Pair<K1 of <root>.plus, V1 of <root>.plus>) returnType:kotlin.collections.Map<K1 of <root>.plus, V1 of <root>.plus> FUN name:plus visibility:public modality:FINAL <K1, V1> ($receiver:kotlin.collections.Map<out K1 of <root>.plus, V1 of <root>.plus>, pair:kotlin.Pair<K1 of <root>.plus, V1 of <root>.plus>) returnType:kotlin.collections.Map<K1 of <root>.plus, V1 of <root>.plus>
TYPE_PARAMETER name:K1 index:0 variance: superTypes:[kotlin.Any?] TYPE_PARAMETER name:K1 index:0 variance: superTypes:[kotlin.Any?]
TYPE_PARAMETER name:V1 index:0 variance: superTypes:[kotlin.Any?] TYPE_PARAMETER name:V1 index:1 variance: superTypes:[kotlin.Any?]
$receiver: VALUE_PARAMETER name:<this> type:kotlin.collections.Map<out K1 of <root>.plus, V1 of <root>.plus> $receiver: VALUE_PARAMETER name:<this> type:kotlin.collections.Map<out K1 of <root>.plus, V1 of <root>.plus>
VALUE_PARAMETER name:pair index:0 type:kotlin.Pair<K1 of <root>.plus, V1 of <root>.plus> VALUE_PARAMETER name:pair index:0 type:kotlin.Pair<K1 of <root>.plus, V1 of <root>.plus>
BLOCK_BODY BLOCK_BODY