FIR: temp: make klib symbol provider know parent packages

Current qualified access resolving algo rely (likely incorrectly,
see #KT-58037) on a providers' "knowledge" about parent packages.
This commit adds this "knowledge" to k-lib based provider.
#KT-57353 fixed
This commit is contained in:
Ilya Chernikov
2023-03-22 17:03:19 +01:00
committed by Space Team
parent ed2b817409
commit 8cc9f911d5
18 changed files with 114 additions and 6 deletions
@@ -6,9 +6,6 @@
package org.jetbrains.kotlin.fir.session
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.caches.FirCache
import org.jetbrains.kotlin.fir.caches.firCachesFactory
import org.jetbrains.kotlin.fir.caches.getValue
import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
import org.jetbrains.kotlin.fir.deserialization.*
import org.jetbrains.kotlin.fir.isNewPlaceForBodyGeneration
@@ -17,7 +14,6 @@ import org.jetbrains.kotlin.fir.scopes.FirKotlinScopeProvider
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
import org.jetbrains.kotlin.library.KotlinLibrary
import org.jetbrains.kotlin.library.metadata.*
import org.jetbrains.kotlin.library.metadata.resolver.KotlinResolvedLibrary
import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
import org.jetbrains.kotlin.metadata.deserialization.NameResolverImpl
@@ -52,6 +48,20 @@ class KlibBasedSymbolProvider(
}
}
private val knownPackagesInLibraries: Set<FqName> by lazy {
buildSet<FqName> {
for ((_, header) in moduleHeaders) {
for (fragmentName in header.packageFragmentNameList) {
var curPackage = FqName(fragmentName)
while (!curPackage.isRoot) {
add(curPackage)
curPackage = curPackage.parent()
}
}
}
}
}
private val annotationDeserializer = KlibBasedAnnotationDeserializer(session)
private val constDeserializer = FirConstDeserializer(session, KlibMetadataSerializerProtocol)
private val deserializationConfiguration = CompilerDeserializationConfiguration(session.languageVersionSettings)
@@ -182,7 +192,7 @@ class KlibBasedSymbolProvider(
override fun isNewPlaceForBodyGeneration(classProto: ProtoBuf.Class) = false
override fun getPackage(fqName: FqName): FqName? {
return if (fqName.toString() in fragmentNamesInLibraries) {
return if (fqName in knownPackagesInLibraries) {
fqName
} else {
null
@@ -26,6 +26,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -26,6 +26,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
+11
View File
@@ -0,0 +1,11 @@
// MODULE: lib
// FILE: lib.kt
package my.lib.pkg
object Foo {
fun ok() = "OK"
}
// MODULE: main(lib)
// FILE: main.kt
fun box(): String = my.lib.pkg.Foo.ok()
@@ -26,6 +26,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -26,6 +26,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -26,6 +26,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -31,6 +31,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true, "ranges/stepped", "compileKotlinAgainstKotlin", "testsWithJava9", "testsWithJava15", "testsWithJava17");
}
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -26,6 +26,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true, "compileKotlinAgainstKotlin");
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -26,6 +26,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true, "compileKotlinAgainstKotlin");
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -26,6 +26,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true, "compileKotlinAgainstKotlin");
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -26,6 +26,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true, "compileKotlinAgainstKotlin");
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_K2: JS_IR
// DONT_TARGET_EXACT_BACKEND: JS
// KJS_WITH_FULL_RUNTIME
@@ -35,6 +35,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -39,6 +39,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -33,6 +33,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -37,6 +37,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
@Test
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@@ -31,6 +31,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true, "compileKotlinAgainstKotlin");
}
@TestMetadata("kt-57353.kt")
public void testKt_57353() throws Exception {
runTest("compiler/testData/codegen/box/kt-57353.kt");
}
@TestMetadata("compiler/testData/codegen/box/annotations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)