FIR2IR: approximate type argument if reified
This commit is contained in:
committed by
Mikhail Glukhikh
parent
721248f883
commit
72dea05854
+14
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.backend.generators
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.backend.*
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
@@ -20,6 +21,7 @@ import org.jetbrains.kotlin.fir.resolve.inference.isBuiltinFunctionalType
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.typeContext
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
@@ -29,6 +31,7 @@ import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.psi.KtPropertyDelegate
|
||||
import org.jetbrains.kotlin.psi2ir.generators.hasNoSideEffects
|
||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||
|
||||
class CallAndReferenceGenerator(
|
||||
private val components: Fir2IrComponents,
|
||||
@@ -36,6 +39,7 @@ class CallAndReferenceGenerator(
|
||||
private val conversionScope: Fir2IrConversionScope
|
||||
) : Fir2IrComponents by components {
|
||||
|
||||
private val approximator = object : AbstractTypeApproximator(session.typeContext) {}
|
||||
private val adapterGenerator = AdapterGenerator(components, conversionScope)
|
||||
|
||||
private fun FirTypeRef.toIrType(): IrType = with(typeConverter) { toIrType() }
|
||||
@@ -563,7 +567,13 @@ class CallAndReferenceGenerator(
|
||||
if (argumentsCount <= typeArgumentsCount) {
|
||||
apply {
|
||||
for ((index, argument) in access.typeArguments.withIndex()) {
|
||||
val argumentIrType = (argument as FirTypeProjectionWithVariance).typeRef.toIrType()
|
||||
val typeParameter = access.findTypeParameter(index)
|
||||
val argumentFirType = (argument as FirTypeProjectionWithVariance).typeRef
|
||||
val argumentIrType = if (typeParameter?.isReified == true) {
|
||||
argumentFirType.approximatedIfNeededOrSelf(approximator, Visibilities.Public).toIrType()
|
||||
} else {
|
||||
argumentFirType.toIrType()
|
||||
}
|
||||
putTypeArgument(index, argumentIrType)
|
||||
}
|
||||
}
|
||||
@@ -587,6 +597,9 @@ class CallAndReferenceGenerator(
|
||||
}
|
||||
}
|
||||
|
||||
private fun FirQualifiedAccess.findTypeParameter(index: Int): FirTypeParameter? =
|
||||
((calleeReference as? FirResolvedNamedReference)?.resolvedSymbol?.fir as? FirTypeParametersOwner)?.typeParameters?.get(index)
|
||||
|
||||
private fun FirQualifiedAccess.findIrDispatchReceiver(explicitReceiverExpression: IrExpression?): IrExpression? =
|
||||
findIrReceiver(explicitReceiverExpression, isDispatch = true)
|
||||
|
||||
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
// WITH_COROUTINES
|
||||
|
||||
@@ -33,7 +33,7 @@ FILE fqName:<root> fileName:/intersectionType1_NI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun foo <T> (a: kotlin.Array<<root>.In<T of <root>.foo>>, b: kotlin.Array<<root>.In<kotlin.String>>): kotlin.Boolean declared in <root>'
|
||||
CALL 'public final fun ofType <K> (y: kotlin.Any?): kotlin.Boolean [inline] declared in <root>' type=kotlin.Boolean origin=null
|
||||
<K>: T of <root>.foo
|
||||
<K>: kotlin.Any?
|
||||
$receiver: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=<root>.In<T of <root>.foo> origin=null
|
||||
$this: CALL 'public final fun select <S> (x: S of <root>.select, y: S of <root>.select): S of <root>.select declared in <root>' type=kotlin.Array<out <root>.In<T of <root>.foo>> origin=null
|
||||
<S>: kotlin.Array<out <root>.In<T of <root>.foo>>
|
||||
|
||||
@@ -33,7 +33,7 @@ FILE fqName:<root> fileName:/intersectionType1_OI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun foo <T> (a: kotlin.Array<<root>.In<T of <root>.foo>>, b: kotlin.Array<<root>.In<kotlin.String>>): kotlin.Boolean declared in <root>'
|
||||
CALL 'public final fun ofType <K> (y: kotlin.Any?): kotlin.Boolean [inline] declared in <root>' type=kotlin.Boolean origin=null
|
||||
<K>: T of <root>.foo
|
||||
<K>: kotlin.Any?
|
||||
$receiver: CALL 'public final fun get (index: kotlin.Int): T of kotlin.Array [operator] declared in kotlin.Array' type=<root>.In<T of <root>.foo> origin=null
|
||||
$this: CALL 'public final fun select <S> (x: S of <root>.select, y: S of <root>.select): S of <root>.select declared in <root>' type=kotlin.Array<out <root>.In<T of <root>.foo>> origin=null
|
||||
<S>: kotlin.Array<out <root>.In<T of <root>.foo>>
|
||||
|
||||
@@ -132,7 +132,7 @@ FILE fqName:<root> fileName:/intersectionType3_NI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testInIs1 (x: <root>.In<<root>.A>, y: <root>.In<<root>.B>): kotlin.Boolean declared in <root>'
|
||||
CALL 'public final fun isT <T> (): kotlin.Boolean [inline] declared in <root>' type=kotlin.Boolean origin=null
|
||||
<T>: <root>.A
|
||||
<T>: kotlin.Any
|
||||
$receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.A> origin=null
|
||||
<S>: <root>.In<<root>.A>
|
||||
x: GET_VAR 'x: <root>.In<<root>.A> declared in <root>.testInIs1' type=<root>.In<<root>.A> origin=null
|
||||
@@ -143,7 +143,7 @@ FILE fqName:<root> fileName:/intersectionType3_NI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testInIs2 (x: <root>.In<<root>.Z1>, y: <root>.In<<root>.Z2>): kotlin.Boolean declared in <root>'
|
||||
CALL 'public final fun isT <T> (): kotlin.Boolean [inline] declared in <root>' type=kotlin.Boolean origin=null
|
||||
<T>: <root>.Z1
|
||||
<T>: kotlin.Any
|
||||
$receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.Z1> origin=null
|
||||
<S>: <root>.In<<root>.Z1>
|
||||
x: GET_VAR 'x: <root>.In<<root>.Z1> declared in <root>.testInIs2' type=<root>.In<<root>.Z1> origin=null
|
||||
@@ -154,7 +154,7 @@ FILE fqName:<root> fileName:/intersectionType3_NI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testInIs3 (x: <root>.In<<root>.A1>, y: <root>.In<<root>.A2>): kotlin.Boolean declared in <root>'
|
||||
CALL 'public final fun isT <T> (): kotlin.Boolean [inline] declared in <root>' type=kotlin.Boolean origin=null
|
||||
<T>: <root>.A1
|
||||
<T>: <root>.A
|
||||
$receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.A1> origin=null
|
||||
<S>: <root>.In<<root>.A1>
|
||||
x: GET_VAR 'x: <root>.In<<root>.A1> declared in <root>.testInIs3' type=<root>.In<<root>.A1> origin=null
|
||||
@@ -165,7 +165,7 @@ FILE fqName:<root> fileName:/intersectionType3_NI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testInAs1 (x: <root>.In<<root>.A>, y: <root>.In<<root>.B>): kotlin.Unit declared in <root>'
|
||||
CALL 'public final fun asT <T> (): kotlin.Unit [inline] declared in <root>' type=kotlin.Unit origin=null
|
||||
<T>: <root>.A
|
||||
<T>: kotlin.Any
|
||||
$receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.A> origin=null
|
||||
<S>: <root>.In<<root>.A>
|
||||
x: GET_VAR 'x: <root>.In<<root>.A> declared in <root>.testInAs1' type=<root>.In<<root>.A> origin=null
|
||||
@@ -176,7 +176,7 @@ FILE fqName:<root> fileName:/intersectionType3_NI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testInAs2 (x: <root>.In<<root>.Z1>, y: <root>.In<<root>.Z2>): kotlin.Unit declared in <root>'
|
||||
CALL 'public final fun asT <T> (): kotlin.Unit [inline] declared in <root>' type=kotlin.Unit origin=null
|
||||
<T>: <root>.Z1
|
||||
<T>: kotlin.Any
|
||||
$receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.Z1> origin=null
|
||||
<S>: <root>.In<<root>.Z1>
|
||||
x: GET_VAR 'x: <root>.In<<root>.Z1> declared in <root>.testInAs2' type=<root>.In<<root>.Z1> origin=null
|
||||
@@ -187,7 +187,7 @@ FILE fqName:<root> fileName:/intersectionType3_NI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testInAs3 (x: <root>.In<<root>.A1>, y: <root>.In<<root>.A2>): kotlin.Unit declared in <root>'
|
||||
CALL 'public final fun asT <T> (): kotlin.Unit [inline] declared in <root>' type=kotlin.Unit origin=null
|
||||
<T>: <root>.A1
|
||||
<T>: <root>.A
|
||||
$receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.A1> origin=null
|
||||
<S>: <root>.In<<root>.A1>
|
||||
x: GET_VAR 'x: <root>.In<<root>.A1> declared in <root>.testInAs3' type=<root>.In<<root>.A1> origin=null
|
||||
|
||||
@@ -132,7 +132,7 @@ FILE fqName:<root> fileName:/intersectionType3_OI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testInIs1 (x: <root>.In<<root>.A>, y: <root>.In<<root>.B>): kotlin.Boolean declared in <root>'
|
||||
CALL 'public final fun isT <T> (): kotlin.Boolean [inline] declared in <root>' type=kotlin.Boolean origin=null
|
||||
<T>: <root>.A
|
||||
<T>: kotlin.Any
|
||||
$receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.A> origin=null
|
||||
<S>: <root>.In<<root>.A>
|
||||
x: GET_VAR 'x: <root>.In<<root>.A> declared in <root>.testInIs1' type=<root>.In<<root>.A> origin=null
|
||||
@@ -143,7 +143,7 @@ FILE fqName:<root> fileName:/intersectionType3_OI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testInIs2 (x: <root>.In<<root>.Z1>, y: <root>.In<<root>.Z2>): kotlin.Boolean declared in <root>'
|
||||
CALL 'public final fun isT <T> (): kotlin.Boolean [inline] declared in <root>' type=kotlin.Boolean origin=null
|
||||
<T>: <root>.Z1
|
||||
<T>: kotlin.Any
|
||||
$receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.Z1> origin=null
|
||||
<S>: <root>.In<<root>.Z1>
|
||||
x: GET_VAR 'x: <root>.In<<root>.Z1> declared in <root>.testInIs2' type=<root>.In<<root>.Z1> origin=null
|
||||
@@ -154,7 +154,7 @@ FILE fqName:<root> fileName:/intersectionType3_OI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testInIs3 (x: <root>.In<<root>.A1>, y: <root>.In<<root>.A2>): kotlin.Boolean declared in <root>'
|
||||
CALL 'public final fun isT <T> (): kotlin.Boolean [inline] declared in <root>' type=kotlin.Boolean origin=null
|
||||
<T>: <root>.A1
|
||||
<T>: <root>.A
|
||||
$receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.A1> origin=null
|
||||
<S>: <root>.In<<root>.A1>
|
||||
x: GET_VAR 'x: <root>.In<<root>.A1> declared in <root>.testInIs3' type=<root>.In<<root>.A1> origin=null
|
||||
@@ -165,7 +165,7 @@ FILE fqName:<root> fileName:/intersectionType3_OI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testInAs1 (x: <root>.In<<root>.A>, y: <root>.In<<root>.B>): kotlin.Unit declared in <root>'
|
||||
CALL 'public final fun asT <T> (): kotlin.Unit [inline] declared in <root>' type=kotlin.Unit origin=null
|
||||
<T>: <root>.A
|
||||
<T>: kotlin.Any
|
||||
$receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.A> origin=null
|
||||
<S>: <root>.In<<root>.A>
|
||||
x: GET_VAR 'x: <root>.In<<root>.A> declared in <root>.testInAs1' type=<root>.In<<root>.A> origin=null
|
||||
@@ -176,7 +176,7 @@ FILE fqName:<root> fileName:/intersectionType3_OI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testInAs2 (x: <root>.In<<root>.Z1>, y: <root>.In<<root>.Z2>): kotlin.Unit declared in <root>'
|
||||
CALL 'public final fun asT <T> (): kotlin.Unit [inline] declared in <root>' type=kotlin.Unit origin=null
|
||||
<T>: <root>.Z1
|
||||
<T>: kotlin.Any
|
||||
$receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.Z1> origin=null
|
||||
<S>: <root>.In<<root>.Z1>
|
||||
x: GET_VAR 'x: <root>.In<<root>.Z1> declared in <root>.testInAs2' type=<root>.In<<root>.Z1> origin=null
|
||||
@@ -187,7 +187,7 @@ FILE fqName:<root> fileName:/intersectionType3_OI.kt
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun testInAs3 (x: <root>.In<<root>.A1>, y: <root>.In<<root>.A2>): kotlin.Unit declared in <root>'
|
||||
CALL 'public final fun asT <T> (): kotlin.Unit [inline] declared in <root>' type=kotlin.Unit origin=null
|
||||
<T>: <root>.A1
|
||||
<T>: <root>.A
|
||||
$receiver: CALL 'public final fun sel <S> (x: S of <root>.sel, y: S of <root>.sel): S of <root>.sel declared in <root>' type=<root>.In<<root>.A1> origin=null
|
||||
<S>: <root>.In<<root>.A1>
|
||||
x: GET_VAR 'x: <root>.In<<root>.A1> declared in <root>.testInAs3' type=<root>.In<<root>.A1> origin=null
|
||||
|
||||
Reference in New Issue
Block a user