IR: keep local scope with counter maps across LDL invocations

Since LocalDeclarationsLowering is a BodyLoweringPass, local
functions inside one declaration are handled independently of local
functions in the other declaration. This can lead to name clashes, in
case a local function with the same name and signature is declared in
overloads in the same container, which results in a signature clash
error in JVM IR.

The issue became more common with the introduction of adapted function
references, where psi2ir generates a local adapter-function with a
predefined name, which can easily clash with another reference to the
same target in an overload. This led to a compilation error when
bootstrapping Kotlin with JVM IR, for example in GradleIRBuilder.kt
where there are a lot of references to the same function.
This commit is contained in:
Alexander Udalov
2020-05-04 17:39:26 +02:00
parent 50506658c0
commit 91ef053fbc
10 changed files with 166 additions and 23 deletions
@@ -2095,6 +2095,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/noAdaptedReferencesIfNoOptimizedReferencesEnabled.kt");
}
@TestMetadata("noNameClashForReferencesToSameFunction.kt")
public void testNoNameClashForReferencesToSameFunction() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/noNameClashForReferencesToSameFunction.kt");
}
@TestMetadata("noReflectionForAdaptedCallableReferences.kt")
public void testNoReflectionForAdaptedCallableReferences() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/noReflectionForAdaptedCallableReferences.kt");
@@ -12962,6 +12967,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/functions/localFunctions/nameClash.kt");
}
@TestMetadata("nameClashAcrossDifferentContainers.kt")
public void testNameClashAcrossDifferentContainers() throws Exception {
runTest("compiler/testData/codegen/box/functions/localFunctions/nameClashAcrossDifferentContainers.kt");
}
@TestMetadata("overloadedLocalFunWithoutClosure.kt")
public void testOverloadedLocalFunWithoutClosure() throws Exception {
runTest("compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunWithoutClosure.kt");