JVM IR: avoid unnecessary toIrBasedKotlinType in ExpressionCodegen

Result of calling `ExpressionCodegen.gen` was used only in two call
sites in the inliner. In all other call sites, we were doing unnecessary
work (and sometimes were even failing) by trying to construct a
KotlinType instance out from an IrType.

Note that even though the code from KT-50617 no longer fails to compile,
the underlying problem is still not solved, since the IrType for foo's
dispatch receiver is constructed incorrectly. The reason is that
SymbolTable links everything by IdSignature, which is identical for
classes with the same FQ name.

 #KT-50617 Fixed
This commit is contained in:
Alexander Udalov
2022-01-18 02:39:09 +01:00
parent 5f22bcd03b
commit f40a0ca704
11 changed files with 72 additions and 4 deletions
@@ -42057,6 +42057,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/classDeclaration.kt");
}
@Test
@TestMetadata("differingNumberOfGenericTypeParameters.kt")
public void testDifferingNumberOfGenericTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/differingNumberOfGenericTypeParameters.kt");
}
@Test
@TestMetadata("functionDeclaration.kt")
public void testFunctionDeclaration() throws Exception {
@@ -207,9 +207,13 @@ class ExpressionCodegen(
noLineNumberScope = previousState
}
// TODO remove
fun gen(expression: IrExpression, type: Type, irType: IrType, data: BlockInfo): StackValue {
fun gen(expression: IrExpression, type: Type, irType: IrType, data: BlockInfo) {
expression.accept(this, data).materializeAt(type, irType)
}
// TODO remove
fun genToStackValue(expression: IrExpression, type: Type, irType: IrType, data: BlockInfo): StackValue {
gen(expression, type, irType, data)
return StackValue.onStack(type, irType.toIrBasedKotlinType())
}
@@ -665,7 +669,7 @@ class ExpressionCodegen(
expression.symbol.owner.realType.toIrBasedKotlinType()
)
else
gen(expression, type, parameterType, data)
genToStackValue(expression, type, parameterType, data)
// We do not mangle functions if Result is the only parameter of the function. This means that if a function
// taking `Result` as a parameter overrides a function taking `Any?`, there is no bridge unless needed for
@@ -137,7 +137,7 @@ class IrInlineCodegen(
val argValue = if (irValueParameter.index >= 0)
codegen.genOrGetLocal(argumentExpression, parameterType, irValueParameter.type, blockInfo)
else
codegen.gen(argumentExpression, parameterType, irValueParameter.type, blockInfo)
codegen.genToStackValue(argumentExpression, parameterType, irValueParameter.type, blockInfo)
if (inlineArgumentsInPlace) {
codegen.visitor.addInplaceArgumentEndMarker()
}
@@ -0,0 +1,18 @@
// IGNORE_BACKEND: NATIVE, JS_IR, WASM
// IGNORE_BACKEND_FIR: JVM_IR
// MODULE: lib
// FILE: 1.kt
interface B<X>
object T : B<String>
fun B<*>.foo() {}
// MODULE: main(lib)
// FILE: 2.kt
interface B
fun box(): String {
T.foo()
return "OK"
}
@@ -41595,6 +41595,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/classDeclaration.kt");
}
@Test
@TestMetadata("differingNumberOfGenericTypeParameters.kt")
public void testDifferingNumberOfGenericTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/differingNumberOfGenericTypeParameters.kt");
}
@Test
@TestMetadata("functionDeclaration.kt")
public void testFunctionDeclaration() throws Exception {
@@ -42057,6 +42057,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/classDeclaration.kt");
}
@Test
@TestMetadata("differingNumberOfGenericTypeParameters.kt")
public void testDifferingNumberOfGenericTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/differingNumberOfGenericTypeParameters.kt");
}
@Test
@TestMetadata("functionDeclaration.kt")
public void testFunctionDeclaration() throws Exception {
@@ -33532,6 +33532,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/classDeclaration.kt");
}
@TestMetadata("differingNumberOfGenericTypeParameters.kt")
public void testDifferingNumberOfGenericTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/differingNumberOfGenericTypeParameters.kt");
}
@TestMetadata("functionDeclaration.kt")
public void testFunctionDeclaration() throws Exception {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/functionDeclaration.kt");
@@ -29993,6 +29993,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/classDeclaration.kt");
}
@Test
@TestMetadata("differingNumberOfGenericTypeParameters.kt")
public void testDifferingNumberOfGenericTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/differingNumberOfGenericTypeParameters.kt");
}
@Test
@TestMetadata("functionDeclaration.kt")
public void testFunctionDeclaration() throws Exception {
@@ -30095,6 +30095,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/classDeclaration.kt");
}
@Test
@TestMetadata("differingNumberOfGenericTypeParameters.kt")
public void testDifferingNumberOfGenericTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/differingNumberOfGenericTypeParameters.kt");
}
@Test
@TestMetadata("functionDeclaration.kt")
public void testFunctionDeclaration() throws Exception {
@@ -25054,6 +25054,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/classDeclaration.kt");
}
@TestMetadata("differingNumberOfGenericTypeParameters.kt")
public void testDifferingNumberOfGenericTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/differingNumberOfGenericTypeParameters.kt");
}
@TestMetadata("functionDeclaration.kt")
public void testFunctionDeclaration() throws Exception {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/functionDeclaration.kt");
@@ -32290,6 +32290,12 @@ public class ExternalTestGenerated extends AbstractExternalNativeBlackBoxTest {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/classDeclaration.kt");
}
@Test
@TestMetadata("differingNumberOfGenericTypeParameters.kt")
public void testDifferingNumberOfGenericTypeParameters() throws Exception {
runTest("compiler/testData/codegen/box/sameFileInSourceAndDependencies/differingNumberOfGenericTypeParameters.kt");
}
@Test
@TestMetadata("functionDeclaration.kt")
public void testFunctionDeclaration() throws Exception {