Use direct calls for constant constructors

This commit is contained in:
sergeych committed 2026-04-21 13:30:09 +03:00
1 parent 30c9a5a565
commit ffa64d691b
2 files changed
+59 -14

No files matched your search

@@ -361,6 +361,23 @@ class BytecodeRecentOpsTest {
assertEquals(11, scope.eval("calc()").toInt())
}
@Test
fun optionalExactLambdaCallUsesInlineBytecode() = runTest {
val scope = Script.newScope()
scope.eval(
"""
type IntFn = (Int)->Int
fun calc() {
val f: IntFn? = { x -> x + 1 }
f?(10)
}
""".trimIndent()
)
val disasm = scope.disassembleSymbol("calc")
assertFalse(disasm.contains("CALL_SLOT"), disasm)
assertEquals(11, scope.eval("calc()").toInt())
}
@Test
fun letLiteralUsesInlineBytecode() = runTest {
val scope = Script.newScope()
@@ -516,6 +533,40 @@ class BytecodeRecentOpsTest {
assertEquals(6, scope.eval("calc()").toInt())
}
@Test
fun mapLiteralUsesDirectConstructorCall() = runTest {
val scope = Script.newScope()
scope.eval(
"""
fun calc() {
val m = { a: 1, b: 2 }
m.size
}
""".trimIndent()
)
val disasm = scope.disassembleSymbol("calc")
assertTrue(disasm.contains("CALL_DIRECT"), disasm)
assertFalse(disasm.contains("CALL_SLOT"), disasm)
assertEquals(2, scope.eval("calc()").toInt())
}
@Test
fun mapEntryLiteralUsesDirectConstructorCall() = runTest {
val scope = Script.newScope()
scope.eval(
"""
fun calc() {
val e = "a" => 2
e.value
}
""".trimIndent()
)
val disasm = scope.disassembleSymbol("calc")
assertTrue(disasm.contains("CALL_DIRECT"), disasm)
assertFalse(disasm.contains("CALL_SLOT"), disasm)
assertEquals(2, scope.eval("calc()").toInt())
}
@Test
fun optionalIndexPreIncSkipsOnNullReceiver() = runTest {
eval(