[JS IR] Fix a IC dependency building for class methods.

The patch fixes lost IC dependencies for inherited class or interface methods.
 Especially between a fake override function and its implementation.
 Since IrSymbolDeserializer doesn't provide all class methods,
 they are collected from the class definitions.

^KT-53063 Fixed
This commit is contained in:
Alexander Korepanov
2022-07-05 12:34:54 +02:00
committed by Space
parent edbccd0add
commit 6525f7a7ac
42 changed files with 504 additions and 30 deletions
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.ir.backend.js.ic
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.ir.backend.js.*
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrLinker
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.JsIrFragmentAndBinaryAst
@@ -239,9 +240,9 @@ class CacheUpdater(
return exportedSymbols
}
private fun resolveFakeOverrideInlineFunction(symbol: IrSymbol): IdSignature? {
private fun resolveFakeOverrideFunction(symbol: IrSymbol): IdSignature? {
return (symbol.owner as? IrSimpleFunction)?.let { overridable ->
if (overridable.isFakeOverride && overridable.isInline) {
if (overridable.isFakeOverride) {
overridable.resolveFakeOverride()?.symbol?.signature
} else {
null
@@ -249,6 +250,47 @@ class CacheUpdater(
}
}
private fun collectImplementedSymbol(deserializedSymbols: Map<IdSignature, IrSymbol>): Map<IdSignature, IrSymbol> {
return buildMap(deserializedSymbols.size) {
for ((signature, symbol) in deserializedSymbols) {
put(signature, symbol)
fun <T> addSymbol(decl: T): Boolean where T : IrDeclarationWithVisibility, T : IrSymbolOwner {
when (decl.visibility) {
DescriptorVisibilities.LOCAL -> return false
DescriptorVisibilities.PRIVATE -> return false
DescriptorVisibilities.PRIVATE_TO_THIS -> return false
}
val sig = decl.symbol.signature
if (sig != null && sig !in deserializedSymbols) {
return put(sig, decl.symbol) == null
}
return false
}
fun addNestedDeclarations(irClass: IrClass) {
for (decl in irClass.declarations) {
when (decl) {
is IrSimpleFunction -> addSymbol(decl)
is IrProperty -> {
decl.getter?.let(::addSymbol)
decl.setter?.let(::addSymbol)
}
is IrClass -> {
if (addSymbol(decl)) {
addNestedDeclarations(decl)
}
}
}
}
}
(symbol.owner as? IrClass)?.let(::addNestedDeclarations)
}
}
}
private fun rebuildDirtySourceMetadata(
jsIrLinker: JsIrLinker,
loadedFragments: Map<KotlinLibraryFile, IrModuleFragment>,
@@ -264,16 +306,19 @@ class CacheUpdater(
val libSrcFile = KotlinSourceFile(fileDeserializer.file)
val reachableSignatures = fileDeserializer.symbolDeserializer.signatureDeserializer.signatureToIndexMapping()
val allImplementedSymbols = fileDeserializer.symbolDeserializer.deserializedSymbols
val maybeImportedSignatures = reachableSignatures.keys.toMutableSet()
for ((signature, symbol) in allImplementedSymbols) {
if (signature in reachableSignatures) {
val implementedSymbols = collectImplementedSymbol(fileDeserializer.symbolDeserializer.deserializedSymbols)
for ((signature, symbol) in implementedSymbols) {
var symbolCanBeExported = maybeImportedSignatures.remove(signature)
resolveFakeOverrideFunction(symbol)?.let { resolvedSignature ->
if (resolvedSignature !in implementedSymbols) {
maybeImportedSignatures.add(resolvedSignature)
}
symbolCanBeExported = true
}
if (symbolCanBeExported) {
signatureHashCalculator.addHashForSignatureIfNotExist(signature, symbol)
idSignatureToFile[signature] = lib to libSrcFile
maybeImportedSignatures.remove(signature)
val resolvedSignature = resolveFakeOverrideInlineFunction(symbol) ?: continue
maybeImportedSignatures.add(resolvedSignature)
}
}
@@ -80,6 +80,11 @@ public class InvalidationTestGenerated extends AbstractInvalidationTest {
runTest("js/js.translator/testData/incremental/invalidation/exportsThroughInlineFunction/");
}
@TestMetadata("fakeOverrideClassFunctionQualifiers")
public void testFakeOverrideClassFunctionQualifiers() throws Exception {
runTest("js/js.translator/testData/incremental/invalidation/fakeOverrideClassFunctionQualifiers/");
}
@TestMetadata("fakeOverrideInheritance")
public void testFakeOverrideInheritance() throws Exception {
runTest("js/js.translator/testData/incremental/invalidation/fakeOverrideInheritance/");
@@ -100,6 +105,11 @@ public class InvalidationTestGenerated extends AbstractInvalidationTest {
runTest("js/js.translator/testData/incremental/invalidation/fakeOverrideInlineProperty/");
}
@TestMetadata("fakeOverrideInterfaceFunctionQualifiers")
public void testFakeOverrideInterfaceFunctionQualifiers() throws Exception {
runTest("js/js.translator/testData/incremental/invalidation/fakeOverrideInterfaceFunctionQualifiers/");
}
@TestMetadata("fastPath1")
public void testFastPath1() throws Exception {
runTest("js/js.translator/testData/incremental/invalidation/fastPath1/");
@@ -6,14 +6,11 @@ STEP 1:
modifications:
U : l1.1_simple_class.kt -> l1.kt
modified ir: l1.kt
updated exports: l1.kt
STEP 2:
modifications:
U : l1.2_inline_class.kt -> l1.kt
modified ir: l1.kt
updated exports: l1.kt
STEP 3:
modifications:
U : l1.1_simple_class.kt -> l1.kt
modified ir: l1.kt
updated exports: l1.kt
@@ -0,0 +1,3 @@
open class Module2OpenClass {
public suspend fun testFunction2() = 2
}
@@ -0,0 +1,4 @@
open class Module2OpenClass {
public suspend fun testFunction2() = 2
public fun testFunction22() = 22
}
@@ -0,0 +1,2 @@
open class Module2OpenClass {
}
@@ -0,0 +1,4 @@
open class Module2OpenClass {
public fun testFunction2() = 2
public fun testFunction22() = 22
}
@@ -0,0 +1,7 @@
open class Module2OpenClass {
public fun testFunction2() = 2
public fun testFunction22() = 22
public val testField222: Int
get() = 222
}
@@ -0,0 +1,7 @@
open class Module2OpenClass {
public fun testFunction2() = 20
public fun testFunction22() = 220
public val testField222: Int
get() = 2220
}
@@ -0,0 +1,7 @@
open class Module2OpenClass {
public fun testFunction2() = 20
inline public fun testFunction22() = 220
public val testField222: Int
get() = 2220
}
@@ -0,0 +1,7 @@
open class Module2OpenClass {
public fun testFunction2() = 20
inline public fun testFunction22() = 220
inline public val testField222: Int
get() = 2220
}
@@ -0,0 +1,7 @@
open class Module2OpenClass {
public fun testFunction2() = 20
inline public fun testFunction22() = 2201
inline public val testField222: Int
get() = 2220
}
@@ -0,0 +1,7 @@
open class Module2OpenClass {
public fun testFunction2() = 20
inline public fun testFunction22() = 2201
inline public val testField222: Int
get() = 22201
}
@@ -0,0 +1,48 @@
STEP 0:
modifications:
U : l1.0.kt -> l1.kt
added file: l1.kt
STEP 1:
modifications:
U : l1.1.kt -> l1.kt
modified ir: l1.kt
updated exports: l1.kt
STEP 2:
modifications:
U : l1.2.kt -> l1.kt
modified ir: l1.kt
STEP 3:
modifications:
U : l1.3.kt -> l1.kt
modified ir: l1.kt
STEP 4:
updated exports: l1.kt
STEP 5:
modifications:
U : l1.5.kt -> l1.kt
modified ir: l1.kt
STEP 6:
modifications:
U : l1.6.kt -> l1.kt
modified ir: l1.kt
STEP 7:
modifications:
U : l1.7.kt -> l1.kt
modified ir: l1.kt
STEP 8:
modifications:
U : l1.8.kt -> l1.kt
modified ir: l1.kt
STEP 9:
modifications:
U : l1.9.kt -> l1.kt
modified ir: l1.kt
STEP 10:
modifications:
U : l1.10.kt -> l1.kt
modified ir: l1.kt
updated exports: l1.kt
STEP 11:
modifications:
U : l1.0.kt -> l1.kt
modified ir: l1.kt
@@ -0,0 +1,3 @@
class Module1Class: Module2OpenClass() {
fun testFunction1() = 1
}
@@ -0,0 +1,25 @@
STEP 0:
dependencies: lib1
added file: l2.kt
STEP 1:
dependencies: lib1
updated exports: l2.kt
STEP 2:
dependencies: lib1
updated imports: l2.kt
STEP 3:
dependencies: lib1
STEP 4:
dependencies: lib1
updated exports: l2.kt
STEP 5:
dependencies: lib1
STEP 6..9:
dependencies: lib1
updated imports: l2.kt
STEP 10:
dependencies: lib1
updated imports: l2.kt
updated exports: l2.kt
STEP 11:
dependencies: lib1
@@ -0,0 +1,10 @@
fun box(stepId: Int): String {
val obj = Module1Class()
when (stepId) {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 -> {
if (obj.testFunction1() != 1) return "Fail 1"
}
else -> return "Unknown"
}
return "OK"
}
@@ -0,0 +1,11 @@
fun box(stepId: Int): String {
val obj = Module1Class()
when (stepId) {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 -> {
if (obj.testFunction1() != 1) return "Fail 1"
if (obj.testFunction22() != 22) return "Fail 22"
}
else -> return "Unknown"
}
return "OK"
}
@@ -0,0 +1,27 @@
fun box(stepId: Int): String {
val obj = Module1Class()
when (stepId) {
0, 1, 2, 3, 4, 10, 11 -> {
if (obj.testFunction1() != 1) return "Fail 1"
if (obj.testFunction22() != 22) return "Fail 22"
if (obj.testField222 != 222) return "Fail 222"
}
5, 6, 7 -> {
if (obj.testFunction1() != 1) return "Fail 1"
if (obj.testFunction22() != 220) return "Fail 220"
if (obj.testField222 != 2220) return "Fail 2220"
}
8 -> {
if (obj.testFunction1() != 1) return "Fail 1"
if (obj.testFunction22() != 2201) return "Fail 2201"
if (obj.testField222 != 2220) return "Fail 2220"
}
9 -> {
if (obj.testFunction1() != 1) return "Fail 1"
if (obj.testFunction22() != 2201) return "Fail 2201"
if (obj.testField222 != 22201) return "Fail 22201"
}
else -> return "Unknown"
}
return "OK"
}
@@ -0,0 +1,31 @@
STEP 0:
modifications:
U : m.0.kt -> m.kt
dependencies: lib1, lib2
added file: m.kt
STEP 1:
modifications:
U : m.1.kt -> m.kt
dependencies: lib1, lib2
modified ir: m.kt
STEP 2:
dependencies: lib1, lib2
STEP 3:
dependencies: lib1, lib2
STEP 4:
dependencies: lib1, lib2
modifications:
U : m.4.kt -> m.kt
modified ir: m.kt
STEP 5:
dependencies: lib1, lib2
STEP 6..9:
dependencies: lib1, lib2
updated imports: m.kt
STEP 10:
modifications:
U : m.0.kt -> m.kt
dependencies: lib1, lib2
modified ir: m.kt
STEP 11:
dependencies: lib1, lib2
@@ -0,0 +1,23 @@
MODULES: lib1, lib2, main
STEP 0..1:
libs: lib1, lib2, main
dirty js: lib1, lib2, main
STEP 2:
libs: lib1, lib2, main
dirty js: lib1, lib2
STEP 3:
libs: lib1, lib2, main
dirty js: lib1
STEP 4:
libs: lib1, lib2, main
dirty js: main, lib1, lib2
STEP 5:
libs: lib1, lib2, main
dirty js: lib1
STEP 6..10:
libs: lib1, lib2, main
dirty js: lib1, lib2, main
STEP 11:
libs: lib1, lib2, main
dirty js: lib1
@@ -18,6 +18,7 @@ STEP 3:
modifications:
U : A.0.kt -> A.kt
modified ir: A.kt
updated imports: B.kt, C.kt
STEP 4:
modifications:
U : B.0.kt -> B.kt
@@ -1,8 +1,6 @@
STEP 0:
dependencies: lib1
added file: l2.kt
STEP 1:
STEP 1..2:
dependencies: lib1
updated imports: l2.kt
STEP 2:
dependencies: lib1
@@ -1,11 +1,5 @@
MODULES: lib1, lib2, main
STEP 0:
STEP 0..2:
libs: lib1, lib2, main
dirty js: lib1, lib2, main
STEP 1:
libs: lib1, lib2, main
dirty js: lib1, lib2, main
STEP 2:
libs: lib1, lib2, main
dirty js: lib1, main
@@ -0,0 +1,3 @@
interface Module2Interface {
public suspend fun testFunction2() = 2
}
@@ -0,0 +1,4 @@
interface Module2Interface {
public suspend fun testFunction2() = 2
public fun testFunction22() = 22
}
@@ -0,0 +1,4 @@
interface Module2Interface {
public fun testFunction2() = 2
public fun testFunction22() = 22
}
@@ -0,0 +1,7 @@
interface Module2Interface {
public fun testFunction2() = 2
public fun testFunction22() = 22
public val testField222: Int
get() = 222
}
@@ -0,0 +1,7 @@
interface Module2Interface {
public fun testFunction2() = 20
public fun testFunction22() = 220
public val testField222: Int
get() = 2220
}
@@ -0,0 +1,2 @@
interface Module2Interface {
}
@@ -0,0 +1,34 @@
STEP 0:
modifications:
U : l1.0.kt -> l1.kt
added file: l1.kt
STEP 1:
modifications:
U : l1.1.kt -> l1.kt
modified ir: l1.kt
updated exports: l1.kt
STEP 2:
modifications:
U : l1.2.kt -> l1.kt
modified ir: l1.kt
STEP 3:
modifications:
U : l1.3.kt -> l1.kt
modified ir: l1.kt
STEP 4:
updated exports: l1.kt
STEP 5:
modifications:
U : l1.5.kt -> l1.kt
modified ir: l1.kt
STEP 6:
modifications:
U : l1.6.kt -> l1.kt
modified ir: l1.kt
updated exports: l1.kt
STEP 7:
modifications:
U : l1.0.kt -> l1.kt
modified ir: l1.kt
STEP 8:
updated exports: l1.kt
@@ -0,0 +1,3 @@
class Module1Class: Module2Interface {
fun testFunction1() = 1
}
@@ -0,0 +1,25 @@
STEP 0:
dependencies: lib1
added file: l2.kt
STEP 1:
dependencies: lib1
updated exports: l2.kt
STEP 2:
dependencies: lib1
updated imports: l2.kt
STEP 3:
dependencies: lib1
STEP 4:
dependencies: lib1
updated exports: l2.kt
STEP 5:
dependencies: lib1
STEP 6:
dependencies: lib1
updated imports: l2.kt
updated exports: l2.kt
STEP 7:
dependencies: lib1
STEP 8:
dependencies: lib1
updated exports: l2.kt
@@ -0,0 +1,10 @@
fun box(stepId: Int): String {
val obj = Module1Class()
when (stepId) {
0, 1, 2, 3, 4, 5, 6, 7, 8 -> {
if (obj.testFunction1() != 1) return "Fail 1"
}
else -> return "Unknown"
}
return "OK"
}
@@ -0,0 +1,11 @@
fun box(stepId: Int): String {
val obj = Module1Class()
when (stepId) {
0, 1, 2, 3, 4, 5, 6, 7, 8 -> {
if (obj.testFunction1() != 1) return "Fail 1"
if (obj.testFunction22() != 22) return "Fail 22"
}
else -> return "Unknown"
}
return "OK"
}
@@ -0,0 +1,17 @@
fun box(stepId: Int): String {
val obj = Module1Class()
when (stepId) {
0, 1, 2, 3, 4, 6, 7, 8 -> {
if (obj.testFunction1() != 1) return "Fail 1"
if (obj.testFunction22() != 22) return "Fail 22"
if (obj.testField222 != 222) return "Fail 222"
}
5 -> {
if (obj.testFunction1() != 1) return "Fail 1"
if (obj.testFunction22() != 220) return "Fail 220"
if (obj.testField222 != 2220) return "Fail 2220"
}
else -> return "Unknown"
}
return "OK"
}
@@ -0,0 +1,15 @@
suspend fun testCrossReference(): Int {
val obj = Module1Class()
return obj.testFunction2()
}
fun box(stepId: Int): String {
val obj = Module1Class()
when (stepId) {
0, 1, 2, 3, 4, 5, 6, 7, 8 -> {
if (obj.testFunction1() != 1) return "Fail 1"
}
else -> return "Unknown"
}
return "OK"
}
@@ -0,0 +1,31 @@
STEP 0:
dependencies: lib1, lib2
modifications:
U : m.0.kt -> m.kt
added file: m.kt
STEP 1:
dependencies: lib1, lib2
modifications:
U : m.1.kt -> m.kt
modified ir: m.kt
STEP 2..3:
dependencies: lib1, lib2
STEP 4:
dependencies: lib1, lib2
modifications:
U : m.4.kt -> m.kt
modified ir: m.kt
STEP 5:
dependencies: lib1, lib2
STEP 6:
dependencies: lib1, lib2
modifications:
U : m.0.kt -> m.kt
modified ir: m.kt
STEP 7:
dependencies: lib1, lib2
STEP 8:
dependencies: lib1, lib2
modifications:
U : m.8.kt -> m.kt
modified ir: m.kt
@@ -0,0 +1,26 @@
MODULES: lib1, lib2, main
STEP 0..1:
libs: lib1, lib2, main
dirty js: lib1, lib2, main
STEP 2:
libs: lib1, lib2, main
dirty js: lib1, lib2
STEP 3:
libs: lib1, lib2, main
dirty js: lib1
STEP 4:
libs: lib1, lib2, main
dirty js: lib1, lib2, main
STEP 5:
libs: lib1, lib2, main
dirty js: lib1
STEP 6:
libs: lib1, lib2, main
dirty js: lib1, lib2, main
STEP 7:
libs: lib1, lib2, main
dirty js: lib1
STEP 8:
libs: lib1, lib2, main
dirty js: lib1, lib2, main
@@ -3,8 +3,10 @@ STEP 0:
added file: l2.kt
STEP 1..3:
dependencies: lib1
updated imports: l2.kt
STEP 4:
dependencies: lib1
modifications:
U : l2.4.kt -> l2.kt
modified ir: l2.kt
updated exports: l2.kt
@@ -1,8 +1,6 @@
STEP 0:
dependencies: lib1, lib2
added file: m.kt
STEP 1..3:
STEP 1..4:
dependencies: lib1, lib2
updated imports: m.kt
STEP 4:
dependencies: lib1, lib2
@@ -1,11 +1,8 @@
MODULES: lib1, lib2, main
STEP 0:
STEP 0..3:
libs: lib1, lib2, main
dirty js: lib1, lib2, main
STEP 1..3:
libs: lib1, lib2, main
dirty js: lib1, main
STEP 4:
libs: lib1, lib2, main
dirty js: lib2
dirty js: lib2, main