Cover when-based exact callable fast paths

This commit is contained in:
Sergey Chernov 2026-04-21 14:37:27 +03:00
parent 80693e7690
commit 97990f00ce

View File

@ -427,6 +427,25 @@ class BytecodeRecentOpsTest {
assertEquals(11, scope.eval("calc()").toInt()) assertEquals(11, scope.eval("calc()").toInt())
} }
@Test
fun whenExactLambdaCallUsesInlineBytecode() = runTest {
val scope = Script.newScope()
scope.eval(
"""
val base = { x -> x + 1 }
fun calc(flag: Bool) {
(when(flag) {
true -> base
else -> base
})(10)
}
""".trimIndent()
)
val disasm = scope.disassembleSymbol("calc")
assertFalse(disasm.contains("CALL_SLOT"), disasm)
assertEquals(11, scope.eval("calc(true)").toInt())
}
@Test @Test
fun letLiteralUsesInlineBytecode() = runTest { fun letLiteralUsesInlineBytecode() = runTest {
val scope = Script.newScope() val scope = Script.newScope()
@ -686,6 +705,27 @@ class BytecodeRecentOpsTest {
assertEquals(0, scope.eval("calc()").toInt()) assertEquals(0, scope.eval("calc()").toInt())
} }
@Test
fun whenConstructorAliasUsesDirectCall() = runTest {
val scope = Script.newScope()
scope.eval(
"""
fun calc(flag: Bool) {
val ctor = when(flag) {
true -> Map
else -> Map
}
val m = ctor() as Map
m.size
}
""".trimIndent()
)
val disasm = scope.disassembleSymbol("calc")
assertTrue(disasm.contains("CALL_DIRECT"), disasm)
assertFalse(disasm.contains("CALL_SLOT"), disasm)
assertEquals(0, scope.eval("calc(true)").toInt())
}
@Test @Test
fun localNamedFunctionUsesDirectCall() = runTest { fun localNamedFunctionUsesDirectCall() = runTest {
val scope = Script.newScope() val scope = Script.newScope()