Fir2Ir: simplify getCachedIrTypeParameter
I could not figure out the reason for the special case in that function. Tests do not show anything useful.
This commit is contained in:
committed by
Alexander Udalov
parent
e504d9faed
commit
3a4b8962f9
+8
-23
@@ -96,11 +96,11 @@ class Fir2IrClassifierStorage(
|
||||
internal fun preCacheTypeParameters(owner: FirTypeParameterRefsOwner, irOwnerSymbol: IrSymbol) {
|
||||
for ((index, typeParameter) in owner.typeParameters.withIndex()) {
|
||||
val original = typeParameter.symbol.fir
|
||||
getCachedIrTypeParameter(original, index)
|
||||
getCachedIrTypeParameter(original)
|
||||
?: createIrTypeParameterWithoutBounds(original, index, irOwnerSymbol)
|
||||
if (owner is FirProperty && owner.isVar) {
|
||||
val context = ConversionTypeContext.DEFAULT.inSetter()
|
||||
getCachedIrTypeParameter(original, index, context)
|
||||
getCachedIrTypeParameter(original, context)
|
||||
?: createIrTypeParameterWithoutBounds(original, index, irOwnerSymbol, context)
|
||||
}
|
||||
}
|
||||
@@ -429,27 +429,12 @@ class Fir2IrClassifierStorage(
|
||||
|
||||
internal fun getCachedIrTypeParameter(
|
||||
typeParameter: FirTypeParameter,
|
||||
index: Int = UNDEFINED_PARAMETER_INDEX,
|
||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
||||
): IrTypeParameter? {
|
||||
// Here transformation is a bit difficult because one FIR property type parameter
|
||||
// can be transformed to two different type parameters: one for getter and another one for setter
|
||||
val simpleCachedParameter = typeParameterCache[typeParameter]
|
||||
if (simpleCachedParameter != null) {
|
||||
if (typeContext.origin != ConversionTypeOrigin.SETTER) {
|
||||
return simpleCachedParameter
|
||||
}
|
||||
if (index < 0) {
|
||||
val parent = simpleCachedParameter.parent
|
||||
if (parent !is IrSimpleFunction || parent.returnType == irBuiltIns.unitType) {
|
||||
return simpleCachedParameter
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeContext.origin == ConversionTypeOrigin.SETTER) {
|
||||
typeParameterCacheForSetter[typeParameter]?.let { return it }
|
||||
}
|
||||
return null
|
||||
return if (typeContext.origin == ConversionTypeOrigin.SETTER)
|
||||
typeParameterCacheForSetter[typeParameter]
|
||||
else
|
||||
typeParameterCache[typeParameter]
|
||||
}
|
||||
|
||||
internal fun getIrTypeParameter(
|
||||
@@ -458,7 +443,7 @@ class Fir2IrClassifierStorage(
|
||||
ownerSymbol: IrSymbol,
|
||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
||||
): IrTypeParameter {
|
||||
getCachedIrTypeParameter(typeParameter, index, typeContext)?.let { return it }
|
||||
getCachedIrTypeParameter(typeParameter, typeContext)?.let { return it }
|
||||
return typeParameter.run {
|
||||
val irTypeParameter = createIrTypeParameterWithoutBounds(typeParameter, index, ownerSymbol, typeContext)
|
||||
irTypeParameter.superTypes = bounds.map { it.toIrType() }
|
||||
@@ -592,7 +577,7 @@ class Fir2IrClassifierStorage(
|
||||
typeContext: ConversionTypeContext
|
||||
): IrTypeParameterSymbol {
|
||||
val firTypeParameter = firTypeParameterSymbol.fir
|
||||
return getCachedIrTypeParameter(firTypeParameter, typeContext = typeContext)?.symbol
|
||||
return getCachedIrTypeParameter(firTypeParameter, typeContext)?.symbol
|
||||
// We can try to use default cache because setter can use parent type parameters
|
||||
?: typeParameterCache[firTypeParameter]?.symbol
|
||||
?: error("Cannot find cached type parameter by FIR symbol: ${firTypeParameterSymbol.name}")
|
||||
|
||||
+6
@@ -7181,6 +7181,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fakeOverridesForIntersectionTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericSetter.kt")
|
||||
public void testGenericSetter() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/genericSetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("importCompanion.kt")
|
||||
public void testImportCompanion() throws Exception {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// MODULE: lib
|
||||
// FILE: 1.kt
|
||||
var <T> T.prop: Int
|
||||
get() = 33
|
||||
set(value) {}
|
||||
|
||||
// MODULE: main(lib)
|
||||
// FILE: 2.kt
|
||||
fun <T> setProp(t: T, v: Int) {
|
||||
t.prop = v
|
||||
}
|
||||
|
||||
fun box() = "OK"
|
||||
+6
@@ -7067,6 +7067,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fakeOverridesForIntersectionTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericSetter.kt")
|
||||
public void testGenericSetter() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/genericSetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("importCompanion.kt")
|
||||
public void testImportCompanion() throws Exception {
|
||||
|
||||
+6
@@ -7181,6 +7181,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fakeOverridesForIntersectionTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericSetter.kt")
|
||||
public void testGenericSetter() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/genericSetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("importCompanion.kt")
|
||||
public void testImportCompanion() throws Exception {
|
||||
|
||||
+6
@@ -163,6 +163,12 @@ public class JvmIrAgainstOldBoxTestGenerated extends AbstractJvmIrAgainstOldBoxT
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fakeOverridesForIntersectionTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericSetter.kt")
|
||||
public void testGenericSetter() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/genericSetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("importCompanion.kt")
|
||||
public void testImportCompanion() throws Exception {
|
||||
|
||||
+6
@@ -163,6 +163,12 @@ public class JvmOldAgainstIrBoxTestGenerated extends AbstractJvmOldAgainstIrBoxT
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/fakeOverridesForIntersectionTypes.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericSetter.kt")
|
||||
public void testGenericSetter() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/genericSetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("importCompanion.kt")
|
||||
public void testImportCompanion() throws Exception {
|
||||
|
||||
+6
@@ -5515,6 +5515,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/expectClassActualTypeAlias.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("genericSetter.kt")
|
||||
public void testGenericSetter() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/compileKotlinAgainstKotlin/genericSetter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("innerClassConstructor.kt")
|
||||
public void testInnerClassConstructor() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user