rce-incorporated / Fiu

Luau bytecode interpreter for Luau
MIT License
91 stars 18 forks source link

Fiu VM Error { Name: (main) Line: 267 PC: 17 Opcode: FORGLOOP }: invalid key to 'next' #35

Closed capthehacker99 closed 6 months ago

capthehacker99 commented 6 months ago

This script runs fine using luau:

local lols = {}
function lols:get_tabs()
    return {
        "Foo",
        "Bar",
        "Alice",
        "Bob"
    }
end

for i, v in next, lols:get_tabs() do
    print(v)
end

However when compiled into bytecode and ran using fiu it will output the following error: Fiu VM Error { Name: (main) Line: 267 PC: 17 Opcode: FORGLOOP }: invalid key to 'next'

capthehacker99 commented 6 months ago

It seems to be related to NAMECALL as it uses table_remove which can trigger this error as shown here: https://devforum.roblox.com/t/invalid-key-to-next/223193

capthehacker99 commented 6 months ago

Removing table_remove doesn't do anything so it might be something else, but it seems to happen only with namecalling. Iterating the table directly doesn't trigger this error.

blatantfr commented 6 months ago

Getting the same error lol

TheGreatSageEqualToHeaven commented 6 months ago

Does the same thing occur with generalized iteration disabled?

TheGreatSageEqualToHeaven commented 6 months ago

The provided snippet, works. What settings are you using?

image

capthehacker99 commented 6 months ago

Default settings image

capthehacker99 commented 6 months ago

The same thing occurs with generalized iteration disabled. It happens at runtime using Fiu main.

TheGreatSageEqualToHeaven commented 6 months ago

How did you get the Luau bytecode you are using?

capthehacker99 commented 6 months ago

luau-compile -O2 -g1 --binary test.lua > outbc.bc

SnorlaxAssist commented 6 months ago

Fiu VM Error { Name: (main) Line: 267 PC: 17 Opcode: FORGLOOP }: invalid key to 'next'

Seems like the error you commented above is a much larger script in which anything could've possibly happened. And for the sample you provided I could not get the same error you got.

capthehacker99 commented 6 months ago

No the given script is the one that causes the error, it is not part of a larger script

capthehacker99 commented 6 months ago

After experimenting modifying the script to this:

local lols = {}
function lols:get_tabs()
    return {
        "Foo",
        "Bar",
        "Alice",
        "Bob"
    }
end

local onext = next
next = function(a, b)
    print("NEXT", unpack(a), b)
    return onext(a, b)
end

for i, v in next, lols:get_tabs() do
    print(v)
end

Running it with luau it outputs this:

NEXT    Foo     nil
Foo
NEXT    Foo     1
Bar
NEXT    Foo     2
Alice
NEXT    Foo     3
Bob
NEXT    Foo     4

However, when compiled to bytecode and ran using Fiu it outputs this:

NEXT    Foo     table: 0x000001d099479588
Fiu VM Error { Name: (main) Line: 277 PC: 23 Opcode: FORGLOOP }: Fiu VM Error { Name: (??) Line: 18 PC: 14 Opcode: CALL }: invalid key to 'next'

From this I can see that Fiu makes it so that next gets called with the second argument being a table instead of being nil like vanilla luau VM which triggers the invalid key to 'next' error.

Btw the variable fiu from the image above is just:

local fiu = (function()
-- Fiu's Source.lua from the main branch
end)()
SnorlaxAssist commented 6 months ago

I tried your modified script, and running both luau and fiu seems to work just as fine, I might be missing what else could be a problem here.

Screenshot 2024-05-19 at 5 35 15 PM
capthehacker99 commented 6 months ago

I tried your modified script, and running both luau and fiu seems to work just as fine, I might be missing what else could be a problem here. Screenshot 2024-05-19 at 5 35 15 PM

What version of fiu and luau are you running on? I clone the latest version of fiu and luau from the main branch and build it and tested it and it still have this issue.

capthehacker99 commented 6 months ago

image

SnorlaxAssist commented 6 months ago

What version of fiu and luau are you running on?

I'm using Luau v0.625, and the fiu version is the latest one from main branch. This also worked on all optimization levels.

capthehacker99 commented 6 months ago

What version of fiu and luau are you running on?

I'm using Luau v0.625, and the fiu version is the latest one from main branch. This also worked on all optimization levels.

I checkout luau v0.625 and use that, and this error still happens. You seem to be using some kind of test file, Maybe that interferes with the script somehow? I tried this on both Windows and Arch and this error persists.

TheGreatSageEqualToHeaven commented 6 months ago

@capthehacker99 We won't be working to fix any issues you make that don't provide proper reproduction steps and code, I recommend updating the Luau in your path as a first fix as all of the samples you have provided give us working results.

capthehacker99 commented 6 months ago

The luau in my path is the latest version in the main branch in the luau repo. I had no idea why you guys can't reproduce the issue cuz both me and blatant has this issue. Here is a video of me reproducing the issue: https://youtu.be/gla66qJVPkg

TheGreatSageEqualToHeaven commented 6 months ago

The luau in my path is the latest version in the main branch in the luau repo. I had no idea why you guys can't reproduce the issue cuz both me and blatant has this issue. Here is a video of me reproducing the issue: https://youtu.be/gla66qJVPkg

This is pretty odd, can you zip up the directory you did this in and send me it?

SnorlaxAssist commented 6 months ago

I have found something interesting, your issue with fiu works with lune, and fiu-tests, but does not work with Luau's own compiled binary, luau, even if you try require("./Source.lua") luau would error, not sure why. This might be a luau bug?

Another thing luau for some reason in Fiu does not do any mult-ret returns after calling a function, and all returns are completely shifted, but in lune or fiu-tests, this doesn't seem to be a problem.

TheGreatSageEqualToHeaven commented 6 months ago

This is a Luau issue that'll get fixed in a new release soon, we couldn't reproduce it because none of the dynamic flags (specifically LuauFastCrossTableMove in this case) are enabled in Lune and our test suite. For now I just recommend waiting, we cant do much on our side.

TheGreatSageEqualToHeaven commented 6 months ago

Additionally a Luau engineer disabled the flag in Studio so it will work there.