Enable lightweight lambdas (aka invokedynamic) since 2.0

#KT-45375 Fixed
 #KT-58173 Open
This commit is contained in:
Alexander Udalov
2023-04-20 11:07:41 +02:00
committed by Space Team
parent b1b33475fa
commit 3f034e8b67
80 changed files with 4686 additions and 253 deletions
@@ -191,13 +191,16 @@ class SteppingDebugRunner(testServices: TestServices) : DebugRunner(testServices
override fun storeStep(loggedItems: ArrayList<SteppingTestLoggedData>, event: Event) {
assert(event is LocatableEvent)
val location = (event as LocatableEvent).location()
loggedItems.add(
SteppingTestLoggedData(
val data =
if (isIndyLambda(location)) {
// Invokedynamic lambdas are not synthetic in JDI, and they don't have source information.
SteppingTestLoggedData(-1, true, "<lambda>")
} else SteppingTestLoggedData(
location.lineNumber(),
location.method().isSynthetic,
location.formatAsExpectation()
)
)
loggedItems.add(data)
}
}
@@ -234,12 +237,18 @@ class LocalVariableDebugRunner(testServices: TestServices) : DebugRunner(testSer
// Local variable table completely absent - not distinguished from an empty table.
listOf()
}
loggedItems.add(
SteppingTestLoggedData(
val data =
if (isIndyLambda(location)) {
// Invokedynamic lambdas are not synthetic in JDI, and they don't have source information.
SteppingTestLoggedData(-1, true, "<lambda>")
} else SteppingTestLoggedData(
location.lineNumber(),
false,
location.formatAsExpectation(visibleVars)
)
)
loggedItems.add(data)
}
}
private fun isIndyLambda(location: Location): Boolean =
"$\$Lambda$" in location.declaringType().name()
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.NO_SMAP_DUMP
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.SEPARATE_SMAP_DUMPS
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
import org.jetbrains.kotlin.test.model.BinaryArtifacts
import org.jetbrains.kotlin.test.model.FrontendKinds
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.moduleStructure
@@ -77,7 +78,11 @@ class SMAPDumpHandler(testServices: TestServices) : JvmBinaryArtifactHandler(tes
}
val testDataFile = testServices.moduleStructure.originalTestDataFiles.first()
val expectedFile = testDataFile.withExtension(extension)
val firExpectedFile = testDataFile.withExtension("fir.$extension")
val expectedFile =
if (testServices.moduleStructure.modules.first().frontendKind == FrontendKinds.FIR && firExpectedFile.exists())
firExpectedFile
else testDataFile.withExtension(extension)
assertions.assertEqualsToFile(expectedFile, dumper.generateResultingDump())
if (separateDumpEnabled && isSeparateCompilation) {
@@ -46,10 +46,14 @@ class LocalVariableRecord(
append(variableType)
}
append("=")
append(value)
append(value.toString().normalizeIndyLambdas())
}
}
private fun String.normalizeIndyLambdas(): String =
// Invokedynamic lambdas have an unstable hash in the name.
replace("\\\$Lambda\\\$.*".toRegex(), "<lambda>")
private const val EXPECTATIONS_MARKER = "// EXPECTATIONS"
private const val FORCE_STEP_INTO_MARKER = "// FORCE_STEP_INTO"