Skip to content

Update CodeGen to enable the Luau::CodeGen::CodeGen_ColdFunctions flag, and set up random number generators for NCG.#61

Merged
aatxe merged 2 commits into
mainfrom
awe/ir-asm-views
May 7, 2026
Merged

Update CodeGen to enable the Luau::CodeGen::CodeGen_ColdFunctions flag, and set up random number generators for NCG.#61
aatxe merged 2 commits into
mainfrom
awe/ir-asm-views

Conversation

@aatxe

@aatxe aatxe commented May 7, 2026

Copy link
Copy Markdown
Member

We got a bug report about IR and assembly generation failing sometimes. The circumstances for when this happen seem to be when the top-level function gets marked cold. We have a flag that we use in the luau CLI to avoid this issue, and we can set up the same flag to avoid the issue here. There's actually a secondary issue where, at the least, arm64 generation relies on offsetof extensively and we're currently building for wasm32, causing the offset math to not line up and the codegen to error out.

An example program demonstrating this bug:

local e: string = "lol"
local r = e:rep(3)
local x = string.rep(e, 3)
print(x)
print(r)
print(e)
local xd = buffer.create(32)
buffer.writeu32(xd, 29, 0)

It's a bit funny to learn that NCG relies on the host platform being 64-bit, but it's a non-trivial problem to work around. The easiest solution would be to enable wasm64, where the offsets will once again match up with our native architectures. Unfortunately, wasm64 is not supported in Safari as of the time of writing, and a significant portion of our Playground users are on Safari. An alternative solution would be to, from a host build, generate the entire table of offsets necessary, and then load that for the wasm build, rather than using offsetof directly. I'll look into the viability of this going forward, or if wasm64 support is on the horizon for Safari.

@aatxe aatxe merged commit 684bf6d into main May 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant