FirNestedClassifierScope: don't give empty map substitutor to a processor

Optimization related to KT-58008 (hides the issue in some cases)
This commit is contained in:
Mikhail Glukhikh
2023-04-24 17:20:22 +02:00
committed by Space Team
parent 4172ce1018
commit 5daafd5ed5
5 changed files with 112 additions and 8 deletions
@@ -16,22 +16,22 @@ FILE: referenceToExtension.kt
super<R|kotlin/Any|>()
}
public final val memberVal: R|GenericTest.A<T>| = R|SubstitutionOverride</GenericTest.A.A>|<R|T|>()
public final val memberVal: R|GenericTest.A<T>| = R|/GenericTest.A.A|<R|T|>()
public get(): R|GenericTest.A<T>|
public final fun memberFun(): R|GenericTest.A<T>| {
^memberFun R|SubstitutionOverride</GenericTest.A.A>|<R|T|>()
^memberFun R|/GenericTest.A.A|<R|T|>()
}
}
public final val <T> R|GenericTest.B<T>|.extensionVal: R|GenericTest.A<T>|
public get(): R|GenericTest.A<T>| {
^ R|SubstitutionOverride</GenericTest.A.A>|<R|T|>()
^ R|/GenericTest.A.A|<R|T|>()
}
public final fun <T> R|GenericTest.B<T>|.extensionFun(): R|GenericTest.A<T>| {
^extensionFun R|SubstitutionOverride</GenericTest.A.A>|<R|T|>()
^extensionFun R|/GenericTest.A.A|<R|T|>()
}
public final fun test_1(): R|kotlin/Unit| {
@@ -31,10 +31,15 @@ abstract class FirNestedClassifierScope(val klass: FirClass, val useSiteSession:
processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit
) {
val matchedClass = getNestedClassSymbol(name) ?: return
val substitution = klass.typeParameters.associate {
it.symbol to it.toConeType()
val substitutor = if (klass.typeParameters.isEmpty()) {
ConeSubstitutor.Empty
} else {
val substitution = klass.typeParameters.associate {
it.symbol to it.toConeType()
}
ConeSubstitutorByMap(substitution, useSiteSession)
}
processor(matchedClass, ConeSubstitutorByMap(substitution, useSiteSession))
processor(matchedClass, substitutor)
}
abstract fun isEmpty(): Boolean
@@ -1,7 +1,6 @@
// WITH_STDLIB
// WITH_COROUTINES
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K2: JVM_IR
// ISSUE: KT-58008
import kotlin.coroutines.*
@@ -0,0 +1,69 @@
FILE fqName:<root> fileName:/TypeParameterInNestedClass.kt
CLASS OBJECT name:Retry modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Retry
CONSTRUCTOR visibility:private <> () returnType:<root>.Retry [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Retry modality:FINAL visibility:public superTypes:[kotlin.Any]'
CLASS CLASS name:Builder modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Retry.Builder<B of <root>.Retry.Builder>
TYPE_PARAMETER name:B index:0 variance: superTypes:[kotlin.Any?] reified:false
CONSTRUCTOR visibility:public <> (action:kotlin.coroutines.SuspendFunction0<B of <root>.Retry.Builder>) returnType:<root>.Retry.Builder<B of <root>.Retry.Builder> [primary]
VALUE_PARAMETER name:action index:0 type:kotlin.coroutines.SuspendFunction0<B of <root>.Retry.Builder>
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Builder modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:action visibility:private modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:action type:kotlin.coroutines.SuspendFunction0<B of <root>.Retry.Builder> visibility:private [final]
EXPRESSION_BODY
GET_VAR 'action: kotlin.coroutines.SuspendFunction0<B of <root>.Retry.Builder> declared in <root>.Retry.Builder.<init>' type=kotlin.coroutines.SuspendFunction0<B of <root>.Retry.Builder> origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-action> visibility:private modality:FINAL <> ($this:<root>.Retry.Builder<B of <root>.Retry.Builder>) returnType:kotlin.coroutines.SuspendFunction0<B of <root>.Retry.Builder>
correspondingProperty: PROPERTY name:action visibility:private modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:<root>.Retry.Builder<B of <root>.Retry.Builder>
BLOCK_BODY
RETURN type=kotlin.Nothing from='private final fun <get-action> (): kotlin.coroutines.SuspendFunction0<B of <root>.Retry.Builder> declared in <root>.Retry.Builder'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:action type:kotlin.coroutines.SuspendFunction0<B of <root>.Retry.Builder> visibility:private [final]' type=kotlin.coroutines.SuspendFunction0<B of <root>.Retry.Builder> origin=null
receiver: GET_VAR '<this>: <root>.Retry.Builder<B of <root>.Retry.Builder> declared in <root>.Retry.Builder.<get-action>' type=<root>.Retry.Builder<B of <root>.Retry.Builder> 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:withExponentialBackoff visibility:public modality:FINAL <W> ($this:<root>.Retry, action:kotlin.Function0<W of <root>.Retry.withExponentialBackoff>) returnType:<root>.Retry.Builder<W of <root>.Retry.withExponentialBackoff>
TYPE_PARAMETER name:W index:0 variance: superTypes:[kotlin.Any?] reified:false
$this: VALUE_PARAMETER name:<this> type:<root>.Retry
VALUE_PARAMETER name:action index:0 type:kotlin.Function0<W of <root>.Retry.withExponentialBackoff>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun withExponentialBackoff <W> (action: kotlin.Function0<W of <root>.Retry.withExponentialBackoff>): <root>.Retry.Builder<W of <root>.Retry.withExponentialBackoff> declared in <root>.Retry'
CONSTRUCTOR_CALL 'public constructor <init> (action: kotlin.coroutines.SuspendFunction0<B of <root>.Retry.Builder>) [primary] declared in <root>.Retry.Builder' type=<root>.Retry.Builder<W of <root>.Retry.withExponentialBackoff> origin=null
<class: B>: W of <root>.Retry.withExponentialBackoff
action: BLOCK type=kotlin.coroutines.SuspendFunction0<B of <root>.Retry.Builder> origin=SUSPEND_CONVERSION
FUN ADAPTER_FOR_SUSPEND_CONVERSION name:suspendConversion visibility:local modality:FINAL <> ($receiver:kotlin.Function0<W of <root>.Retry.withExponentialBackoff>) returnType:B of <root>.Retry.Builder [suspend]
$receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION name:callee type:kotlin.Function0<W of <root>.Retry.withExponentialBackoff>
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun suspendConversion (): B of <root>.Retry.Builder [suspend] declared in <root>.Retry.withExponentialBackoff'
CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=B of <root>.Retry.Builder origin=null
$this: GET_VAR 'callee: kotlin.Function0<W of <root>.Retry.withExponentialBackoff> declared in <root>.Retry.withExponentialBackoff.suspendConversion' type=kotlin.Function0<W of <root>.Retry.withExponentialBackoff> origin=null
FUNCTION_REFERENCE 'local final fun suspendConversion (): B of <root>.Retry.Builder [suspend] declared in <root>.Retry.withExponentialBackoff' type=kotlin.coroutines.SuspendFunction0<B of <root>.Retry.Builder> origin=SUSPEND_CONVERSION reflectionTarget=null
$receiver: GET_VAR 'action: kotlin.Function0<W of <root>.Retry.withExponentialBackoff> declared in <root>.Retry.withExponentialBackoff' type=kotlin.Function0<W of <root>.Retry.withExponentialBackoff> 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
@@ -0,0 +1,31 @@
object Retry {
private constructor() /* primary */ {
super/*Any*/()
/* <init>() */
}
class Builder<B : Any?> {
constructor(action: SuspendFunction0<B>) /* primary */ {
super/*Any*/()
/* <init>() */
}
private val action: SuspendFunction0<B>
field = action
private get
}
fun <W : Any?> withExponentialBackoff(action: Function0<W>): Builder<W> {
return Builder<W>(action = { // BLOCK
local suspend fun Function0<W>.suspendConversion(): B {
return callee.invoke()
}
action::suspendConversion
})
}
}