[FIR2IR] Support safe calls

This commit is contained in:
Mikhail Glukhikh
2020-03-20 15:57:39 +03:00
parent 2e8b22e4be
commit ca22e05acd
23 changed files with 307 additions and 143 deletions
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.classifierOrNull
import org.jetbrains.kotlin.ir.types.makeNotNull
import org.jetbrains.kotlin.ir.util.defaultType
internal class CallGenerator(
@@ -43,7 +44,49 @@ internal class CallGenerator(
private fun ConeKotlinType.toIrType(): IrType = with(typeConverter) { toIrType() }
fun convertToIrCall(qualifiedAccess: FirQualifiedAccess, typeRef: FirTypeRef): IrExpression {
val type = typeRef.toIrType()
val explicitReceiver = qualifiedAccess.explicitReceiver
if (!qualifiedAccess.safe || explicitReceiver == null) {
return convertToUnsafeIrCall(qualifiedAccess, typeRef)
}
return qualifiedAccess.convertWithOffsets { startOffset, endOffset ->
val type = typeRef.toIrType()
val callableSymbol = (qualifiedAccess.calleeReference as? FirResolvedNamedReference)?.resolvedSymbol as? FirCallableSymbol<*>
val typeShouldBeNotNull = callableSymbol?.fir?.returnTypeRef?.coneTypeSafe<ConeKotlinType>()?.isNullable == false
val unsafeIrCall = convertToUnsafeIrCall(qualifiedAccess, typeRef, makeNotNull = typeShouldBeNotNull)
IrBlockImpl(startOffset, endOffset, type, IrStatementOrigin.SAFE_CALL).apply {
val receiver = visitor.convertToIrExpression(explicitReceiver)
val receiverVariable = declarationStorage.declareTemporaryVariable(receiver).apply {
parent = conversionScope.parentFromStack()
}
statements += receiverVariable
statements += IrWhenImpl(startOffset, endOffset, type).apply {
val variableSymbol = symbolTable.referenceValue(receiverVariable.descriptor)
val condition = IrCallImpl(
startOffset, endOffset, irBuiltIns.booleanType, irBuiltIns.eqeqSymbol, origin = IrStatementOrigin.EQEQ
).apply {
putValueArgument(0, IrGetValueImpl(startOffset, endOffset, variableSymbol))
putValueArgument(1, IrConstImpl.constNull(startOffset, endOffset, irBuiltIns.nothingNType))
}
branches += IrBranchImpl(
condition, IrConstImpl.constNull(startOffset, endOffset, irBuiltIns.nothingNType)
)
val newReceiver = IrGetValueImpl(startOffset, endOffset, variableSymbol)
val replacedCall = unsafeIrCall.replaceReceiver(
newReceiver, isDispatch = explicitReceiver == qualifiedAccess.dispatchReceiver
)
branches += IrElseBranchImpl(
IrConstImpl.boolean(startOffset, endOffset, irBuiltIns.booleanType, true),
replacedCall
)
}
}
}
}
private fun convertToUnsafeIrCall(
qualifiedAccess: FirQualifiedAccess, typeRef: FirTypeRef, makeNotNull: Boolean = false
): IrExpression {
val type = typeRef.toIrType().let { if (makeNotNull) it.makeNotNull() else it }
val symbol = qualifiedAccess.calleeReference.toSymbol(
session,
classifierStorage,
@@ -293,6 +336,22 @@ internal class CallGenerator(
}
}
private fun IrExpression.replaceReceiver(newReceiver: IrExpression, isDispatch: Boolean): IrExpression {
when (this) {
is IrCallImpl -> {
if (!isDispatch) {
extensionReceiver = newReceiver
} else {
dispatchReceiver = newReceiver
}
}
is IrFieldExpressionBase -> {
receiver = newReceiver
}
}
return this
}
private fun generateErrorCallExpression(
startOffset: Int,
endOffset: Int,
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
import kotlin.test.assertEquals
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// See KT-14242
var x = 1
fun box(): String {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
// See KT-14242
var x = 1
fun box(): String {
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
fun <T : Number?> foo(t: T) {
t?.toInt()
}
-1
View File
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
fun <T : Any, R> T.let(f: (T) -> R): R = f(this)
fun box(): String {
+13 -2
View File
@@ -12,8 +12,19 @@ FILE fqName:<root> fileName:/bangbang.kt
RETURN type=kotlin.Nothing from='public final fun test2 (a: kotlin.Any?): kotlin.Int declared in <root>'
CALL 'public final fun CHECK_NOT_NULL <T0> (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): T0 of kotlin.internal.ir.CHECK_NOT_NULL declared in kotlin.internal.ir' type=kotlin.Int origin=EXCLEXCL
<T0>: kotlin.Int
arg0: CALL 'public open fun hashCode (): kotlin.Int declared in kotlin.Any' type=kotlin.Int? origin=null
$this: GET_VAR 'a: kotlin.Any? declared in <root>.test2' type=kotlin.Any? origin=null
arg0: BLOCK type=kotlin.Int? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Any? [val]
GET_VAR 'a: kotlin.Any? declared in <root>.test2' type=kotlin.Any? origin=null
WHEN type=kotlin.Int? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: kotlin.Any? [val] declared in <root>.test2' type=kotlin.Any? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun hashCode (): kotlin.Int declared in kotlin.Any' type=kotlin.Int origin=null
$this: GET_VAR 'val tmp_0: kotlin.Any? [val] declared in <root>.test2' type=kotlin.Any? origin=null
FUN name:test3 visibility:public modality:FINAL <X> (a:X of <root>.test3) returnType:X of <root>.test3
TYPE_PARAMETER name:X index:0 variance: superTypes:[kotlin.Any?]
VALUE_PARAMETER name:a index:0 type:X of <root>.test3
@@ -1,39 +0,0 @@
FILE fqName:<root> fileName:/chainOfSafeCalls.kt
CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.C
CONSTRUCTOR visibility:public <> () returnType:<root>.C [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]'
FUN name:foo visibility:public modality:FINAL <> ($this:<root>.C) returnType:<root>.C
$this: VALUE_PARAMETER name:<this> type:<root>.C
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun foo (): <root>.C declared in <root>.C'
GET_VAR '<this>: <root>.C declared in <root>.C.foo' type=<root>.C origin=null
FUN name:bar visibility:public modality:FINAL <> ($this:<root>.C) returnType:<root>.C?
$this: VALUE_PARAMETER name:<this> type:<root>.C
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun bar (): <root>.C? declared in <root>.C'
GET_VAR '<this>: <root>.C declared in <root>.C.bar' type=<root>.C origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
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 kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:test visibility:public modality:FINAL <> (nc:<root>.C?) returnType:<root>.C?
VALUE_PARAMETER name:nc index:0 type:<root>.C?
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test (nc: <root>.C?): <root>.C? declared in <root>'
CALL 'public final fun foo (): <root>.C declared in <root>.C' type=<root>.C? origin=null
$this: CALL 'public final fun foo (): <root>.C declared in <root>.C' type=<root>.C? origin=null
$this: CALL 'public final fun bar (): <root>.C? declared in <root>.C' type=<root>.C? origin=null
$this: CALL 'public final fun foo (): <root>.C declared in <root>.C' type=<root>.C? origin=null
$this: GET_VAR 'nc: <root>.C? declared in <root>.test' type=<root>.C? origin=null
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class C {
fun foo(): C = this
fun bar(): C? = this
@@ -20,9 +20,31 @@ FILE fqName:<root> fileName:/coercionToUnit.kt
element: CONST String type=kotlin.String value=""
FUN name:test3 visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
CALL 'public open fun println (p0: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit? origin=null
$this: GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static]' type=java.io.PrintStream? origin=GET_PROPERTY
p0: CONST String type=kotlin.String value="Hello,"
CALL 'public open fun println (p0: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit? origin=null
$this: GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static]' type=java.io.PrintStream? origin=GET_PROPERTY
p0: CONST String type=kotlin.String value="world!"
BLOCK type=kotlin.Unit? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:java.io.PrintStream? [val]
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static]' type=java.io.PrintStream? origin=GET_PROPERTY
WHEN type=kotlin.Unit? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: java.io.PrintStream? [val] declared in <root>.test3' type=java.io.PrintStream? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun println (p0: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit origin=null
$this: GET_VAR 'val tmp_0: java.io.PrintStream? [val] declared in <root>.test3' type=java.io.PrintStream? origin=null
p0: CONST String type=kotlin.String value="Hello,"
BLOCK type=kotlin.Unit? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:java.io.PrintStream? [val]
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:out type:java.io.PrintStream? visibility:public [final,static]' type=java.io.PrintStream? origin=GET_PROPERTY
WHEN type=kotlin.Unit? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_1: java.io.PrintStream? [val] declared in <root>.test3' type=java.io.PrintStream? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun println (p0: kotlin.String?): kotlin.Unit declared in java.io.PrintStream' type=kotlin.Unit origin=null
$this: GET_VAR 'val tmp_1: java.io.PrintStream? [val] declared in <root>.test3' type=java.io.PrintStream? origin=null
p0: CONST String type=kotlin.String value="world!"
@@ -1,13 +0,0 @@
FILE fqName:<root> fileName:/dotQualified.kt
FUN name:length visibility:public modality:FINAL <> (s:kotlin.String) returnType:kotlin.Int
VALUE_PARAMETER name:s index:0 type:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun length (s: kotlin.String): kotlin.Int declared in <root>'
CALL 'public open fun <get-length> (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=GET_PROPERTY
$this: GET_VAR 's: kotlin.String declared in <root>.length' type=kotlin.String origin=null
FUN name:lengthN visibility:public modality:FINAL <> (s:kotlin.String?) returnType:kotlin.Int?
VALUE_PARAMETER name:s index:0 type:kotlin.String?
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun lengthN (s: kotlin.String?): kotlin.Int? declared in <root>'
CALL 'public open fun <get-length> (): kotlin.Int declared in kotlin.String' type=kotlin.Int? origin=GET_PROPERTY
$this: GET_VAR 's: kotlin.String? declared in <root>.lengthN' type=kotlin.String? origin=null
@@ -1,2 +1,3 @@
// FIR_IDENTICAL
fun length(s: String) = s.length
fun lengthN(s: String?) = s?.length
@@ -4,6 +4,17 @@ FILE fqName:<root> fileName:/extFunSafeInvoke.kt
VALUE_PARAMETER name:fn index:1 type:kotlin.Function3<kotlin.Any, kotlin.Int, kotlin.String, kotlin.Unit>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test (receiver: kotlin.Any?, fn: kotlin.Function3<kotlin.Any, kotlin.Int, kotlin.String, kotlin.Unit>): IrErrorType declared in <root>'
ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [kotlin/Function3.invoke]>#' type=IrErrorType
CONST Int type=kotlin.Int value=42
CONST String type=kotlin.String value="Hello"
BLOCK type=IrErrorType origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Any? [val]
GET_VAR 'receiver: kotlin.Any? declared in <root>.test' type=kotlin.Any? origin=null
WHEN type=IrErrorType origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: kotlin.Any? [val] declared in <root>.test' type=kotlin.Any? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: ERROR_CALL 'Unresolved reference: <Inapplicable(INAPPLICABLE): [kotlin/Function3.invoke]>#' type=IrErrorType
CONST Int type=kotlin.Int value=42
CONST String type=kotlin.String value="Hello"
+26 -4
View File
@@ -50,15 +50,37 @@ FILE fqName:<root> fileName:/kt30020.kt
<T>: kotlin.Int
$receiver: CALL 'public final fun CHECK_NOT_NULL <T0> (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): T0 of kotlin.internal.ir.CHECK_NOT_NULL declared in kotlin.internal.ir' type=kotlin.collections.MutableList<kotlin.Any> origin=EXCLEXCL
<T0>: kotlin.collections.MutableList<kotlin.Any>
arg0: CALL 'public abstract fun <get-xs> (): kotlin.collections.MutableList<kotlin.Any> declared in <root>.X' type=kotlin.collections.MutableList<kotlin.Any>? origin=GET_PROPERTY
$this: GET_VAR 'nx: <root>.X? declared in <root>.test' type=<root>.X? origin=null
arg0: BLOCK type=kotlin.collections.MutableList<kotlin.Any>? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:<root>.X? [val]
GET_VAR 'nx: <root>.X? declared in <root>.test' type=<root>.X? origin=null
WHEN type=kotlin.collections.MutableList<kotlin.Any>? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: <root>.X? [val] declared in <root>.test' type=<root>.X? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public abstract fun <get-xs> (): kotlin.collections.MutableList<kotlin.Any> declared in <root>.X' type=kotlin.collections.MutableList<kotlin.Any> origin=GET_PROPERTY
$this: GET_VAR 'val tmp_0: <root>.X? [val] declared in <root>.test' type=<root>.X? origin=null
element: CONST Int type=kotlin.Int value=5
CALL 'public final fun plusAssign <T> (element: T of kotlin.collections.plusAssign): kotlin.Unit [inline,operator] declared in kotlin.collections' type=kotlin.Unit origin=null
<T>: kotlin.Int
$receiver: CALL 'public final fun CHECK_NOT_NULL <T0> (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): T0 of kotlin.internal.ir.CHECK_NOT_NULL declared in kotlin.internal.ir' type=kotlin.collections.MutableList<kotlin.Any> origin=EXCLEXCL
<T0>: kotlin.collections.MutableList<kotlin.Any>
arg0: CALL 'public abstract fun f (): kotlin.collections.MutableList<kotlin.Any> declared in <root>.X' type=kotlin.collections.MutableList<kotlin.Any>? origin=null
$this: GET_VAR 'nx: <root>.X? declared in <root>.test' type=<root>.X? origin=null
arg0: BLOCK type=kotlin.collections.MutableList<kotlin.Any>? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:<root>.X? [val]
GET_VAR 'nx: <root>.X? declared in <root>.test' type=<root>.X? origin=null
WHEN type=kotlin.collections.MutableList<kotlin.Any>? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_1: <root>.X? [val] declared in <root>.test' type=<root>.X? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public abstract fun f (): kotlin.collections.MutableList<kotlin.Any> declared in <root>.X' type=kotlin.collections.MutableList<kotlin.Any> origin=null
$this: GET_VAR 'val tmp_1: <root>.X? [val] declared in <root>.test' type=<root>.X? origin=null
element: CONST Int type=kotlin.Int value=6
FUN name:testExtensionReceiver visibility:public modality:FINAL <> ($receiver:kotlin.collections.MutableList<kotlin.Any>) returnType:kotlin.Unit
$receiver: VALUE_PARAMETER name:<this> type:kotlin.collections.MutableList<kotlin.Any>
@@ -34,8 +34,19 @@ FILE fqName:test fileName:/safeCallWithIncrementDecrement.kt
$receiver: VALUE_PARAMETER name:<this> type:kotlin.Int?
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun inc (): kotlin.Int? [operator] declared in test'
CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int? origin=null
$this: GET_VAR '<this>: kotlin.Int? declared in test.inc' type=kotlin.Int? origin=null
BLOCK type=kotlin.Int? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Int? [val]
GET_VAR '<this>: kotlin.Int? declared in test.inc' type=kotlin.Int? origin=null
WHEN type=kotlin.Int? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: kotlin.Int? [val] declared in test.inc' type=kotlin.Int? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
$this: GET_VAR 'val tmp_0: kotlin.Int? [val] declared in test.inc' type=kotlin.Int? origin=null
FUN name:get visibility:public modality:FINAL <> ($receiver:kotlin.Int?, index:kotlin.Int) returnType:kotlin.Int [operator]
$receiver: VALUE_PARAMETER name:<this> type:kotlin.Int?
VALUE_PARAMETER name:index index:0 type:kotlin.Int
@@ -50,26 +61,59 @@ FILE fqName:test fileName:/safeCallWithIncrementDecrement.kt
FUN name:testProperty visibility:public modality:FINAL <> (nc:test.C?) returnType:kotlin.Unit
VALUE_PARAMETER name:nc index:0 type:test.C?
BLOCK_BODY
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Int? [val]
CALL 'public final fun <get-p> (): kotlin.Int declared in test' type=kotlin.Int? origin=GET_PROPERTY
$receiver: GET_VAR 'nc: test.C? declared in test.testProperty' type=test.C? origin=null
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Int? [val]
BLOCK type=kotlin.Int? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:test.C? [val]
GET_VAR 'nc: test.C? declared in test.testProperty' type=test.C? origin=null
WHEN type=kotlin.Int? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_2: test.C? [val] declared in test.testProperty' type=test.C? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public final fun <get-p> (): kotlin.Int declared in test' type=kotlin.Int origin=GET_PROPERTY
$receiver: GET_VAR 'val tmp_2: test.C? [val] declared in test.testProperty' type=test.C? origin=null
CALL 'public final fun <set-p> (value: kotlin.Int): kotlin.Unit declared in test' type=kotlin.Unit origin=EQ
$receiver: GET_VAR 'nc: test.C? declared in test.testProperty' type=test.C? origin=null
value: CALL 'public final fun inc (): kotlin.Int? [operator] declared in test' type=kotlin.Int? origin=null
$receiver: GET_VAR 'val tmp_0: kotlin.Int? [val] declared in test.testProperty' type=kotlin.Int? origin=null
GET_VAR 'val tmp_0: kotlin.Int? [val] declared in test.testProperty' type=kotlin.Int? origin=null
$receiver: GET_VAR 'val tmp_1: kotlin.Int? [val] declared in test.testProperty' type=kotlin.Int? origin=null
GET_VAR 'val tmp_1: kotlin.Int? [val] declared in test.testProperty' type=kotlin.Int? origin=null
FUN name:testArrayAccess visibility:public modality:FINAL <> (nc:test.C?) returnType:kotlin.Unit
VALUE_PARAMETER name:nc index:0 type:test.C?
BLOCK_BODY
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Int [val]
VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:kotlin.Int [val]
CALL 'public final fun get (index: kotlin.Int): kotlin.Int [operator] declared in test' type=kotlin.Int origin=null
$receiver: CALL 'public final fun <get-p> (): kotlin.Int declared in test' type=kotlin.Int? origin=GET_PROPERTY
$receiver: GET_VAR 'nc: test.C? declared in test.testArrayAccess' type=test.C? origin=null
$receiver: BLOCK type=kotlin.Int? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_4 type:test.C? [val]
GET_VAR 'nc: test.C? declared in test.testArrayAccess' type=test.C? origin=null
WHEN type=kotlin.Int? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_4: test.C? [val] declared in test.testArrayAccess' type=test.C? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public final fun <get-p> (): kotlin.Int declared in test' type=kotlin.Int origin=GET_PROPERTY
$receiver: GET_VAR 'val tmp_4: test.C? [val] declared in test.testArrayAccess' type=test.C? origin=null
index: CONST Int type=kotlin.Int value=0
CALL 'public final fun set (index: kotlin.Int, value: kotlin.Int): kotlin.Unit [operator] declared in test' type=kotlin.Unit origin=null
$receiver: CALL 'public final fun <get-p> (): kotlin.Int declared in test' type=kotlin.Int? origin=GET_PROPERTY
$receiver: GET_VAR 'nc: test.C? declared in test.testArrayAccess' type=test.C? origin=null
$receiver: BLOCK type=kotlin.Int? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_5 type:test.C? [val]
GET_VAR 'nc: test.C? declared in test.testArrayAccess' type=test.C? origin=null
WHEN type=kotlin.Int? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_5: test.C? [val] declared in test.testArrayAccess' type=test.C? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public final fun <get-p> (): kotlin.Int declared in test' type=kotlin.Int origin=GET_PROPERTY
$receiver: GET_VAR 'val tmp_5: test.C? [val] declared in test.testArrayAccess' type=test.C? origin=null
index: CONST Int type=kotlin.Int value=0
value: CALL 'public final fun inc (): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null
$this: GET_VAR 'val tmp_1: kotlin.Int [val] declared in test.testArrayAccess' type=kotlin.Int origin=null
GET_VAR 'val tmp_1: kotlin.Int [val] declared in test.testArrayAccess' type=kotlin.Int origin=null
$this: GET_VAR 'val tmp_3: kotlin.Int [val] declared in test.testArrayAccess' type=kotlin.Int origin=null
GET_VAR 'val tmp_3: kotlin.Int [val] declared in test.testArrayAccess' type=kotlin.Int origin=null
+67 -12
View File
@@ -64,22 +64,55 @@ FILE fqName:<root> fileName:/safeCalls.kt
VALUE_PARAMETER name:x index:0 type:kotlin.String?
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test1 (x: kotlin.String?): kotlin.Int? declared in <root>'
CALL 'public open fun <get-length> (): kotlin.Int declared in kotlin.String' type=kotlin.Int? origin=GET_PROPERTY
$this: GET_VAR 'x: kotlin.String? declared in <root>.test1' type=kotlin.String? origin=null
BLOCK type=kotlin.Int? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.String? [val]
GET_VAR 'x: kotlin.String? declared in <root>.test1' type=kotlin.String? origin=null
WHEN type=kotlin.Int? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: kotlin.String? [val] declared in <root>.test1' type=kotlin.String? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun <get-length> (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=GET_PROPERTY
$this: GET_VAR 'val tmp_0: kotlin.String? [val] declared in <root>.test1' type=kotlin.String? origin=null
FUN name:test2 visibility:public modality:FINAL <> (x:kotlin.String?) returnType:kotlin.Int?
VALUE_PARAMETER name:x index:0 type:kotlin.String?
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test2 (x: kotlin.String?): kotlin.Int? declared in <root>'
CALL 'public open fun hashCode (): kotlin.Int declared in kotlin.Any' type=kotlin.Int? origin=null
$this: GET_VAR 'x: kotlin.String? declared in <root>.test2' type=kotlin.String? origin=null
BLOCK type=kotlin.Int? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.String? [val]
GET_VAR 'x: kotlin.String? declared in <root>.test2' type=kotlin.String? origin=null
WHEN type=kotlin.Int? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_1: kotlin.String? [val] declared in <root>.test2' type=kotlin.String? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun hashCode (): kotlin.Int declared in kotlin.Any' type=kotlin.Int origin=null
$this: GET_VAR 'val tmp_1: kotlin.String? [val] declared in <root>.test2' type=kotlin.String? origin=null
FUN name:test3 visibility:public modality:FINAL <> (x:kotlin.String?, y:kotlin.Any?) returnType:kotlin.Boolean?
VALUE_PARAMETER name:x index:0 type:kotlin.String?
VALUE_PARAMETER name:y index:1 type:kotlin.Any?
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test3 (x: kotlin.String?, y: kotlin.Any?): kotlin.Boolean? declared in <root>'
CALL 'public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any' type=kotlin.Boolean? origin=null
$this: GET_VAR 'x: kotlin.String? declared in <root>.test3' type=kotlin.String? origin=null
other: GET_VAR 'y: kotlin.Any? declared in <root>.test3' type=kotlin.Any? origin=null
BLOCK type=kotlin.Boolean? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:kotlin.String? [val]
GET_VAR 'x: kotlin.String? declared in <root>.test3' type=kotlin.String? origin=null
WHEN type=kotlin.Boolean? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_2: kotlin.String? [val] declared in <root>.test3' type=kotlin.String? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any' type=kotlin.Boolean origin=null
$this: GET_VAR 'val tmp_2: kotlin.String? [val] declared in <root>.test3' type=kotlin.String? origin=null
other: GET_VAR 'y: kotlin.Any? declared in <root>.test3' type=kotlin.Any? origin=null
FUN name:test4 visibility:public modality:FINAL <> (x:<root>.Ref?) returnType:kotlin.Unit
VALUE_PARAMETER name:x index:0 type:<root>.Ref?
BLOCK_BODY
@@ -91,9 +124,20 @@ FILE fqName:<root> fileName:/safeCalls.kt
VALUE_PARAMETER name:s index:0 type:kotlin.String?
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test5 (s: kotlin.String?): kotlin.Int? declared in <root>'
CALL 'public open fun extLength (): kotlin.Int declared in <root>.IHost' type=kotlin.Int? origin=null
$this: GET_VAR '<this>: <root>.IHost declared in <root>.test5' type=<root>.IHost origin=null
$receiver: GET_VAR 's: kotlin.String? declared in <root>.test5' type=kotlin.String? origin=null
BLOCK type=kotlin.Int? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:kotlin.String? [val]
GET_VAR 's: kotlin.String? declared in <root>.test5' type=kotlin.String? origin=null
WHEN type=kotlin.Int? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_3: kotlin.String? [val] declared in <root>.test5' type=kotlin.String? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun extLength (): kotlin.Int declared in <root>.IHost' type=kotlin.Int origin=null
$this: GET_VAR '<this>: <root>.IHost declared in <root>.test5' type=<root>.IHost origin=null
$receiver: GET_VAR 'val tmp_3: kotlin.String? [val] declared in <root>.test5' type=kotlin.String? origin=null
FUN name:foo visibility:public modality:FINAL <> ($receiver:kotlin.Int) returnType:kotlin.Int
$receiver: VALUE_PARAMETER name:<this> type:kotlin.Int
BLOCK_BODY
@@ -101,5 +145,16 @@ FILE fqName:<root> fileName:/safeCalls.kt
CONST Int type=kotlin.Int value=239
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
CALL 'public final fun foo (): kotlin.Int declared in <root>' type=kotlin.Int? origin=null
$receiver: CONST Int type=kotlin.Int value=42
BLOCK type=kotlin.Int? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_4 type:kotlin.Int [val]
CONST Int type=kotlin.Int value=42
WHEN type=kotlin.Int? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_4: kotlin.Int [val] declared in <root>.box' type=kotlin.Int origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public final fun foo (): kotlin.Int declared in <root>' type=kotlin.Int origin=null
$receiver: GET_VAR 'val tmp_4: kotlin.Int [val] declared in <root>.box' type=kotlin.Int origin=null
@@ -35,8 +35,19 @@ FILE fqName:<root> fileName:/temporaryInEnumEntryInitializer.kt
CONSTRUCTOR visibility:private <> () returnType:<root>.En.ENTRY [primary]
BLOCK_BODY
ENUM_CONSTRUCTOR_CALL 'private constructor <init> (x: kotlin.String?) [primary] declared in <root>.En'
x: CALL 'public open fun toString (): kotlin.String declared in kotlin.Any' type=kotlin.String? origin=null
$this: CALL 'public final fun <get-n> (): kotlin.Any? declared in <root>' type=kotlin.Any? origin=GET_PROPERTY
x: BLOCK type=kotlin.String? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Any? [val]
CALL 'public final fun <get-n> (): kotlin.Any? declared in <root>' type=kotlin.Any? origin=GET_PROPERTY
WHEN type=kotlin.String? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: kotlin.Any? [val] declared in <root>.En.ENTRY.<init>' type=kotlin.Any? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun toString (): kotlin.String declared in kotlin.Any' type=kotlin.String origin=null
$this: GET_VAR 'val tmp_0: kotlin.Any? [val] declared in <root>.En.ENTRY.<init>' type=kotlin.Any? origin=null
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_ENTRY name:ENTRY modality:FINAL visibility:private superTypes:[<root>.En]'
FUN ENUM_CLASS_SPECIAL_MEMBER name:values visibility:public modality:FINAL <> () returnType:kotlin.Array<<root>.En>
SYNTHETIC_BODY kind=ENUM_VALUES
@@ -1,36 +0,0 @@
FILE fqName:<root> fileName:/temporaryInInitBlock.kt
CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.C
CONSTRUCTOR visibility:public <> (x:kotlin.Any?) returnType:<root>.C [primary]
VALUE_PARAMETER name:x index:0 type:kotlin.Any?
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:s visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:s type:kotlin.String? visibility:private [final]
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-s> visibility:public modality:FINAL <> ($this:<root>.C) returnType:kotlin.String?
correspondingProperty: PROPERTY name:s visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.C
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-s> (): kotlin.String? declared in <root>.C'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:s type:kotlin.String? visibility:private [final]' type=kotlin.String? origin=null
receiver: GET_VAR '<this>: <root>.C declared in <root>.C.<get-s>' type=<root>.C origin=null
ANONYMOUS_INITIALIZER isStatic=false
BLOCK_BODY
SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:s type:kotlin.String? visibility:private [final]' type=kotlin.Unit origin=null
receiver: GET_VAR '<this>: <root>.C declared in <root>.C' type=<root>.C origin=null
value: CALL 'public open fun toString (): kotlin.String declared in kotlin.Any' type=kotlin.String? origin=null
$this: GET_VAR 'x: kotlin.Any? declared in <root>.C.<init>' type=kotlin.Any? origin=null
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
overridden:
public open fun hashCode (): kotlin.Int declared in kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
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 kotlin.Any
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
class C(x: Any?) {
val s: String?
init {
@@ -31,6 +31,28 @@ FILE fqName:<root> fileName:/variableAsFunctionCall.kt
VALUE_PARAMETER name:ns index:0 type:kotlin.String?
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test4 (ns: kotlin.String?): kotlin.String? declared in <root>'
CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.String? origin=INVOKE
$this: CALL 'public final fun k (): kotlin.Function0<kotlin.String> declared in <root>' type=kotlin.Function0<kotlin.String>? origin=null
$receiver: GET_VAR 'ns: kotlin.String? declared in <root>.test4' type=kotlin.String? origin=null
BLOCK type=kotlin.String? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.Function0<kotlin.String>? [val]
BLOCK type=kotlin.Function0<kotlin.String>? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.String? [val]
GET_VAR 'ns: kotlin.String? declared in <root>.test4' type=kotlin.String? origin=null
WHEN type=kotlin.Function0<kotlin.String>? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_1: kotlin.String? [val] declared in <root>.test4' type=kotlin.String? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public final fun k (): kotlin.Function0<kotlin.String> declared in <root>' type=kotlin.Function0<kotlin.String> origin=null
$receiver: GET_VAR 'val tmp_1: kotlin.String? [val] declared in <root>.test4' type=kotlin.String? origin=null
WHEN type=kotlin.String? origin=null
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: GET_VAR 'val tmp_0: kotlin.Function0<kotlin.String>? [val] declared in <root>.test4' type=kotlin.Function0<kotlin.String>? origin=null
arg1: CONST Null type=kotlin.Nothing? value=null
then: CONST Null type=kotlin.Nothing? value=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.String origin=INVOKE
$this: GET_VAR 'val tmp_0: kotlin.Function0<kotlin.String>? [val] declared in <root>.test4' type=kotlin.Function0<kotlin.String>? origin=null