Files
ladybird/Tests/LibJS/Bytecode/expected/switch-completion-value.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

51 lines
2.4 KiB
Plaintext

JS bytecode executable ""
[ 0] 0: GetLexicalEnvironment dst:reg4
[ 8] GetGlobal dst:reg6, identifier:console
[ 18] GetById dst:reg7, base:reg6, property:log, base_identifier:console
[ 30] GetGlobal dst:reg9, identifier:eval
[ 40] CallDirectEval dst:reg8, callee:reg9, this_value:Undefined, eval, arguments:[String("switch(1) { case 1: 'hello'; let x = 1; }")]
[ 68] Call dst:reg5, callee:reg7, this_value:reg6, console.log, arguments:[reg8]
[ 90] GetGlobal dst:reg7, identifier:console
[ a0] GetById dst:reg8, base:reg7, property:log, base_identifier:console
[ b8] GetGlobal dst:reg10, identifier:eval
[ c8] CallDirectEval dst:reg9, callee:reg10, this_value:Undefined, eval, arguments:[String("switch(1) { case 1: 'first'; 'second'; }")]
[ f0] Call dst:reg6, callee:reg8, this_value:reg7, console.log, arguments:[reg9]
[ 118] GetGlobal dst:reg7, identifier:console
[ 128] GetById dst:reg8, base:reg7, property:log, base_identifier:console
[ 140] GetGlobal dst:reg10, identifier:eval
[ 150] CallDirectEval dst:reg9, callee:reg10, this_value:Undefined, eval, arguments:[String("switch(1) { case 1: 'matched'; break; default: 'default'; }")]
[ 178] Call dst:reg5, callee:reg8, this_value:reg7, console.log, arguments:[reg9]
[ 1a0] End value:reg5
JS bytecode executable "eval"
[ 0] 0: GetLexicalEnvironment dst:reg4
[ 8] Mov dst:reg5, src:Undefined
[ 18] 1: JumpStrictlyEquals lhs:Int32(1), rhs:Int32(1), true_target:@38, false_target:@30
[ 30] 2: End value:reg5
[ 38] 3: Mov dst:reg5, src:String("hello")
[ 48] Mov dst:x~0, src:Int32(1)
[ 58] 4: End value:reg5
JS bytecode executable "eval"
[ 0] 0: GetLexicalEnvironment dst:reg4
[ 8] Mov dst:reg5, src:Undefined
[ 18] 1: JumpStrictlyEquals lhs:Int32(1), rhs:Int32(1), true_target:@38, false_target:@30
[ 30] 2: End value:reg5
[ 38] 3: Mov dst:reg5, src:String("first")
[ 48] Mov dst:reg5, src:String("second")
[ 58] 4: End value:reg5
JS bytecode executable "eval"
[ 0] 0: GetLexicalEnvironment dst:reg4
[ 8] Mov dst:reg5, src:Undefined
[ 18] 1: JumpStrictlyEquals lhs:Int32(1), rhs:Int32(1), true_target:@38, false_target:@30
[ 30] 2: Jump target:@50
[ 38] 3: Mov dst:reg5, src:String("matched")
[ 48] End value:reg5
[ 50] 4: Mov dst:reg5, src:String("default")
[ 60] 5: End value:reg5
"hello"
"second"
"matched"