Yes indeed.
I have re-tested it as we did the other day, and I noticed that it only generates these optimizations if --!native
is specified:
Running on RbxStu V4 with the following code:
local bytecodeA = runtime.getbytecode([[
--!optimize 2
local function a(value)
return 4 * value -- uses LOADN, then MUL
end
local function b(value: number): number
return 4 * value -- uses LOADN, then mul; doesn't benefit from the type information.
end
]])
print(disassemble(bytecodeA))
warn("===========\n--!native used\n===========")
local bytecodeB = runtime.getbytecode([[
--!native
--!optimize 2
local function a(value)
return 4 * value -- uses LOADN, then MUL
end
local function b(value: number): number
return 4 * value -- uses MULK directly, skipping LOADN; benefits from the type information
end
]])
print(disassemble(bytecodeB))
It is amazing to see the compiler finally improving the generation of bytecode, although only when --!native
is specified, which is kind of a shame…