Files
ladybird/Tests/LibJS/Bytecode/expected/nested-for-loop-completion.txt
Andreas Kling 234203ed9b LibJS: Ensure deterministic ordering in scope analysis and codegen
The scope collector uses HashMaps for identifier groups and variables,
which means their iteration order is non-deterministic. This causes
local variable indices and function declaration instantiation (FDI)
bytecode to vary between runs.

Fix this by sorting identifier group keys alphabetically before
assigning local variable indices, and sorting vars_to_initialize by
name before emitting FDI bytecode.

Also make register allocation deterministic by always picking the
lowest-numbered free register instead of whichever one happens to be
at the end of the free list.

This is preparation for bringing in a new source->bytecode pipeline
written in Rust. Checking for regressions is significantly easier
if we can expect identical output from both pipelines.
2026-02-24 09:39:42 +01:00

23 lines
1012 B
Plaintext

JS bytecode executable ""
[ 0] 0: GetLexicalEnvironment dst:reg4
[ 8] SetGlobal identifier:n, src:Int32(4)
[ 18] Mov dst:reg5, src:Undefined
[ 28] Jump target:@88
[ 30] 1: SetGlobal identifier:depth, src:Int32(0)
[ 40] Mov dst:reg6, src:Undefined
[ 50] Jump target:@e8
[ 58] 2: GetGlobal dst:reg6, identifier:n
[ 68] Add dst:reg7, lhs:reg6, rhs:Int32(1)
[ 78] SetGlobal identifier:n, src:reg7
[ 88] 3: GetGlobal dst:reg6, identifier:n
[ 98] JumpLessThanEquals lhs:reg6, rhs:Int32(7), true_target:@30, false_target:@b0
[ b0] 4: End value:reg5
[ b8] 5: GetGlobal dst:reg7, identifier:depth
[ c8] Add dst:reg8, lhs:reg7, rhs:Int32(2)
[ d8] SetGlobal identifier:depth, src:reg8
[ e8] 6: GetGlobal dst:reg7, identifier:depth
[ f8] JumpLessThanEquals lhs:reg7, rhs:Int32(0), true_target:@b8, false_target:@110
[ 110] 7: Mov dst:reg5, src:reg6
[ 120] Mov dst:reg5, src:reg6
[ 130] Jump target:@58