[JS IR] Support a module friendship in IC infrastructure
^KT-55097 Fixed
This commit is contained in:
committed by
Space Team
parent
76e629340f
commit
c31705240a
@@ -122,6 +122,7 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
private inner class TestStepInfo(
|
||||
val moduleName: String,
|
||||
val modulePath: String,
|
||||
val friends: List<String>,
|
||||
val expectedFileStats: Map<String, Set<String>>
|
||||
)
|
||||
|
||||
@@ -144,16 +145,23 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
|
||||
val outputKlibFile = resolveModuleArtifact(module, buildDir)
|
||||
|
||||
val friends = mutableListOf<File>()
|
||||
if (buildKlib) {
|
||||
val dependencies = moduleStep.dependencies.mapTo(mutableListOf(File(STDLIB_KLIB))) {
|
||||
resolveModuleArtifact(it.moduleName, buildDir)
|
||||
val dependencies = mutableListOf(File(STDLIB_KLIB))
|
||||
for (dep in moduleStep.dependencies) {
|
||||
val klibFile = resolveModuleArtifact(dep.moduleName, buildDir)
|
||||
dependencies += klibFile
|
||||
if (dep.isFriend) {
|
||||
friends += klibFile
|
||||
}
|
||||
}
|
||||
val configuration = createConfiguration(module, projStep.language)
|
||||
buildArtifact(configuration, module, moduleSourceDir, dependencies, outputKlibFile)
|
||||
buildArtifact(configuration, module, moduleSourceDir, dependencies, friends, outputKlibFile)
|
||||
}
|
||||
return TestStepInfo(
|
||||
module.safeModuleName,
|
||||
outputKlibFile.canonicalPath,
|
||||
friends.map { it.canonicalPath },
|
||||
expectedFileStats
|
||||
)
|
||||
}
|
||||
@@ -228,10 +236,16 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
for (projStep in projectInfo.steps) {
|
||||
val testInfo = projStep.order.map { setupTestStep(projStep, it, true) }
|
||||
|
||||
val mainModuleInfo = testInfo.last()
|
||||
testInfo.find { it != mainModuleInfo && it.friends.isNotEmpty() }?.let {
|
||||
error("module ${it.moduleName} has friends, but only main module may have the friends")
|
||||
}
|
||||
|
||||
val configuration = createConfiguration(projStep.order.last(), projStep.language)
|
||||
val cacheUpdater = CacheUpdater(
|
||||
mainModule = testInfo.last().modulePath,
|
||||
mainModule = mainModuleInfo.modulePath,
|
||||
allModules = testInfo.mapTo(mutableListOf(STDLIB_KLIB)) { it.modulePath },
|
||||
mainModuleFriends = mainModuleInfo.friends,
|
||||
cacheDir = buildDir.resolve("incremental-cache").absolutePath,
|
||||
compilerConfiguration = configuration,
|
||||
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
||||
@@ -281,7 +295,12 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
}
|
||||
|
||||
private fun buildArtifact(
|
||||
configuration: CompilerConfiguration, moduleName: String, sourceDir: File, dependencies: Collection<File>, outputKlibFile: File
|
||||
configuration: CompilerConfiguration,
|
||||
moduleName: String,
|
||||
sourceDir: File,
|
||||
dependencies: Collection<File>,
|
||||
friends: Collection<File>,
|
||||
outputKlibFile: File
|
||||
) {
|
||||
if (outputKlibFile.exists()) outputKlibFile.delete()
|
||||
|
||||
@@ -290,8 +309,12 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
val sourceFiles = sourceDir.filteredKtFiles().map { environment.createPsiFile(it) }
|
||||
|
||||
val sourceModule = prepareAnalyzedSourceModule(
|
||||
projectJs, sourceFiles, configuration, dependencies.map { it.canonicalPath }, emptyList(), // TODO
|
||||
AnalyzerWithCompilerReport(configuration)
|
||||
project = projectJs,
|
||||
files = sourceFiles,
|
||||
configuration = configuration,
|
||||
dependencies = dependencies.map { it.canonicalPath },
|
||||
friendDependencies = friends.map { it.canonicalPath },
|
||||
analyzer = AnalyzerWithCompilerReport(configuration)
|
||||
)
|
||||
|
||||
val moduleSourceFiles = (sourceModule.mainModule as MainModule.SourceFiles).files
|
||||
|
||||
@@ -193,6 +193,7 @@ abstract class AbstractJsKLibABITestCase : KtUsefulTestCase() {
|
||||
val cacheUpdater = CacheUpdater(
|
||||
mainModule = mainModuleKlibFile.absolutePath,
|
||||
allModules = allDependencies.regularDependencies.map { it.path },
|
||||
mainModuleFriends = emptyList(),
|
||||
cacheDir = buildDir.resolve("libs-cache").absolutePath,
|
||||
compilerConfiguration = configuration,
|
||||
irFactory = { IrFactoryImplForJsIC(WholeWorldStageController()) },
|
||||
|
||||
+5
@@ -155,6 +155,11 @@ public class InvalidationTestGenerated extends AbstractInvalidationTest {
|
||||
runTest("js/js.translator/testData/incremental/invalidation/fastPath2/");
|
||||
}
|
||||
|
||||
@TestMetadata("friendDependency")
|
||||
public void testFriendDependency() throws Exception {
|
||||
runTest("js/js.translator/testData/incremental/invalidation/friendDependency/");
|
||||
}
|
||||
|
||||
@TestMetadata("functionDefaultParams")
|
||||
public void testFunctionDefaultParams() throws Exception {
|
||||
runTest("js/js.translator/testData/incremental/invalidation/functionDefaultParams/");
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
open class PublicClass {
|
||||
internal fun foo(): Int = 0
|
||||
internal val bar: Int = 1
|
||||
open internal fun baz(): Int = 2
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
open class PublicClass {
|
||||
internal fun foo(): Int = 1
|
||||
internal val bar: Int = 1
|
||||
open internal fun baz(): Int = 3
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
open class PublicClass {
|
||||
internal fun foo(): Int = 2
|
||||
internal val bar: Int = 1
|
||||
open internal fun baz(): Int = 3
|
||||
|
||||
inline internal fun foo_inline(): Int = 1
|
||||
inline internal val bar_inline: Int get() = 1
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
open class PublicClass {
|
||||
internal fun foo(): Int = 2
|
||||
internal val bar: Int = 1
|
||||
open internal fun baz(): Int = 3
|
||||
|
||||
inline internal fun foo_inline(): Int = 1
|
||||
inline internal val bar_inline: Int get() = 2
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
open class PublicClass {
|
||||
internal fun foo(): Int = 2
|
||||
internal val bar: Int = 1
|
||||
open internal fun baz(): Int = 3
|
||||
|
||||
inline internal fun foo_inline(): Int = 2
|
||||
inline internal val bar_inline: Int get() = 2
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
open class PublicClass {
|
||||
internal fun foo(): Int = 2
|
||||
internal val bar: Int = 2
|
||||
open internal fun baz(): Int = 3
|
||||
|
||||
inline internal fun foo_inline(): Int = 3
|
||||
inline internal val bar_inline: Int get() = 2
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
open class PublicClass {
|
||||
internal fun foo(): Int = 3
|
||||
internal val bar: Int = 2
|
||||
open internal fun baz(): Int = 3
|
||||
|
||||
inline internal fun foo_inline(): Int = 3
|
||||
inline internal val bar_inline: Int get() = 3
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
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
|
||||
STEP 2:
|
||||
modifications:
|
||||
U : l1.2.kt -> l1.kt
|
||||
modified ir: l1.kt
|
||||
STEP 3:
|
||||
updated exports: l1.kt
|
||||
STEP 4:
|
||||
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:
|
||||
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
|
||||
@@ -0,0 +1,7 @@
|
||||
fun box(stepId: Int): String {
|
||||
val x = test()
|
||||
if (x != stepId) {
|
||||
return "Fail: $x != $stepId"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
STEP 0:
|
||||
dependencies: lib1
|
||||
friends: lib1
|
||||
modifications:
|
||||
U : publicClass.0.kt -> publicClass.kt
|
||||
U : test.0.kt -> test.kt
|
||||
added file: m.kt, test.kt, publicClass.kt
|
||||
STEP 1:
|
||||
dependencies: lib1
|
||||
friends: lib1
|
||||
STEP 2:
|
||||
dependencies: lib1
|
||||
friends: lib1
|
||||
STEP 3:
|
||||
dependencies: lib1
|
||||
friends: lib1
|
||||
modifications:
|
||||
U : test.3.kt -> test.kt
|
||||
modified ir: test.kt
|
||||
updated exports: publicClass.kt
|
||||
STEP 4:
|
||||
dependencies: lib1
|
||||
friends: lib1
|
||||
modifications:
|
||||
U : test.4.kt -> test.kt
|
||||
modified ir: test.kt
|
||||
updated exports: publicClass.kt
|
||||
STEP 5..6:
|
||||
dependencies: lib1
|
||||
friends: lib1
|
||||
updated imports: test.kt, publicClass.kt
|
||||
STEP 7:
|
||||
dependencies: lib1
|
||||
friends: lib1
|
||||
modifications:
|
||||
U : test.7.kt -> test.kt
|
||||
modified ir: test.kt
|
||||
updated exports: publicClass.kt
|
||||
STEP 8..9:
|
||||
dependencies: lib1
|
||||
friends: lib1
|
||||
updated imports: publicClass.kt
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class PublicClassHeir : PublicClass() {
|
||||
override internal fun baz(): Int = 4
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun test(): Int {
|
||||
val v = PublicClassHeir()
|
||||
return v.foo() + v.bar + v.baz() - 5
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun test(): Int {
|
||||
val v = PublicClassHeir()
|
||||
return v.foo() + v.bar + v.baz() + v.foo_inline() - 5
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun test(): Int {
|
||||
val v = PublicClassHeir()
|
||||
return v.foo() + v.bar + v.baz() + v.foo_inline() + v.bar_inline - 5
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
fun test(): Int {
|
||||
val v = PublicClassHeir()
|
||||
return v.foo() + v.bar + v.baz()
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
MODULES: lib1, main
|
||||
|
||||
STEP 0:
|
||||
libs: lib1, main
|
||||
dirty js: lib1, main
|
||||
STEP 1..2:
|
||||
libs: lib1, main
|
||||
dirty js: lib1
|
||||
STEP 3:
|
||||
libs: lib1, main
|
||||
dirty js: lib1, main
|
||||
STEP 4:
|
||||
libs: lib1, main
|
||||
dirty js: main
|
||||
STEP 5..9:
|
||||
libs: lib1, main
|
||||
dirty js: lib1, main
|
||||
Reference in New Issue
Block a user