Skip to content

Truly independent web browser

LibJS: Branch directly on generator completion types

Shannon Booth4dcec29adb3d
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/generators.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/generators.rs
index c287e26deff..4c8fdac972e 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/generators.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/generators.rs
@@ -9,6 +9,7 @@
use libjs_abi::CompletionType;
use libjs_abi::IteratorHint;
+use crate::ast::BinaryOp;
use crate::bytecode::instruction::typed as op;
use crate::bytecode::operand::*;
use crate::utf16::Utf16View;
@@ -40,6 +41,24 @@ impl CompletionRegisters {
}
}
+ /// Jumps to `true_target` if the completion is of `completion_type`, and to `false_target` otherwise.
+ fn jump_if_type(
+ self,
+ generator: &mut Generator<'_>,
+ completion_type: CompletionType,
+ true_target: Label,
+ false_target: Label,
+ ) {
+ let completion_type = generator.add_constant_number(f64::from(completion_type as u8));
+ generator.emit_comparison_jump(
+ BinaryOp::StrictlyEquals,
+ self.completion_type,
+ completion_type,
+ true_target,
+ false_target,
+ );
+ }
+
/// Takes the completion that the function was resumed with from the accumulator.
fn receive(self, generator: &mut Generator<'_>) {
generator.emit_mov(self.completion, Operand::register(Register::ACCUMULATOR));
@@ -104,31 +123,13 @@ pub(super) fn generate_yield_of_value(
let normal_block = generator.new_label();
let throw_cont = generator.new_label();
- let type_is_normal = generator.allocate_register();
- let normal_type = generator.add_constant_number(f64::from(CompletionType::Normal as u8));
- let arith_feedback = generator.next_arith_feedback();
- generator.emit(op::StrictlyEquals {
- arith_feedback,
- dst: type_is_normal,
- lhs: received.completion_type,
- rhs: normal_type,
- });
- generator.emit_jump_if(type_is_normal, normal_block, throw_cont);
+ received.jump_if_type(generator, CompletionType::Normal, normal_block, throw_cont);
let throw_value_block = generator.new_label();
let return_value_block = generator.new_label();
generator.bind_reachable_label(throw_cont);
- let type_is_throw = generator.allocate_register();
- let throw_type = generator.add_constant_number(f64::from(CompletionType::Throw as u8));
- let arith_feedback = generator.next_arith_feedback();
- generator.emit(op::StrictlyEquals {
- arith_feedback,
- dst: type_is_throw,
- lhs: received.completion_type,
- rhs: throw_type,
- });
- generator.emit_jump_if(type_is_throw, throw_value_block, return_value_block);
+ received.jump_if_type(generator, CompletionType::Throw, throw_value_block, return_value_block);
generator.bind_reachable_label(throw_value_block);
generator.emit(op::Throw { src: received.value });
@@ -162,15 +163,7 @@ pub(super) fn generate_await_with_completions(
let normal_block = generator.new_label();
let throw_block = generator.new_label();
- let normal_type = generator.add_constant_number(f64::from(CompletionType::Normal as u8));
- let arith_feedback = generator.next_arith_feedback();
- generator.emit(op::JumpStrictlyEquals {
- arith_feedback,
- lhs: received.completion_type,
- rhs: normal_type,
- true_target: normal_block,
- false_target: throw_block,
- });
+ received.jump_if_type(generator, CompletionType::Normal, normal_block, throw_block);
generator.bind_reachable_label(throw_block);
generator.emit(op::Throw { src: received.value });
@@ -225,15 +218,12 @@ fn generate_yield_from(generator: &mut Generator<'_>, value: Operand, received:
// Branch on received.[[Type]].
let type_is_normal_block = generator.new_label();
let is_type_throw_block = generator.new_label();
- let is_normal = generator.allocate_register();
- let arith_feedback = generator.next_arith_feedback();
- generator.emit(op::StrictlyEquals {
- arith_feedback,
- dst: is_normal,
- lhs: received.completion_type,
- rhs: normal_const,
- });
- generator.emit_jump_if(is_normal, type_is_normal_block, is_type_throw_block);
+ received.jump_if_type(
+ generator,
+ CompletionType::Normal,
+ type_is_normal_block,
+ is_type_throw_block,
+ );
// =========================================================================
// a. If received.[[Type]] is normal, then
@@ -296,16 +286,12 @@ fn generate_yield_from(generator: &mut Generator<'_>, value: Operand, received:
generator.bind_reachable_label(is_type_throw_block);
let type_is_throw_block = generator.new_label();
let type_is_return_block = generator.new_label();
- let throw_const = generator.add_constant_number(f64::from(CompletionType::Throw as u8));
- let is_throw = generator.allocate_register();
- let arith_feedback = generator.next_arith_feedback();
- generator.emit(op::StrictlyEquals {
- arith_feedback,
- dst: is_throw,
- lhs: received.completion_type,
- rhs: throw_const,
- });
- generator.emit_jump_if(is_throw, type_is_throw_block, type_is_return_block);
+ received.jump_if_type(
+ generator,
+ CompletionType::Throw,
+ type_is_throw_block,
+ type_is_return_block,
+ );
generator.bind_reachable_label(type_is_throw_block);
@@ -590,16 +576,7 @@ fn generate_yield(
// If resumptionValue.[[Type]] is not return, jump to continuation.
let return_block = generator.new_label();
- let is_not_return = generator.allocate_register();
- let return_type = generator.add_constant_number(f64::from(CompletionType::Return as u8));
- let arith_feedback = generator.next_arith_feedback();
- generator.emit(op::StrictlyInequals {
- arith_feedback,
- dst: is_not_return,
- lhs: received.completion_type,
- rhs: return_type,
- });
- generator.emit_jump_if(is_not_return, continuation_label, return_block);
+ received.jump_if_type(generator, CompletionType::Return, return_block, continuation_label);
// Return path: Await(resumptionValue.[[Value]]).
generator.bind_reachable_label(return_block);
@@ -608,16 +585,12 @@ fn generate_yield(
// If awaited.[[Type]] is throw, jump to continuation.
let awaited_normal_block = generator.new_label();
- let is_throw = generator.allocate_register();
- let throw_type = generator.add_constant_number(f64::from(CompletionType::Throw as u8));
- let arith_feedback = generator.next_arith_feedback();
- generator.emit(op::StrictlyEquals {
- arith_feedback,
- dst: is_throw,
- lhs: received.completion_type,
- rhs: throw_type,
- });
- generator.emit_jump_if(is_throw, continuation_label, awaited_normal_block);
+ received.jump_if_type(
+ generator,
+ CompletionType::Throw,
+ continuation_label,
+ awaited_normal_block,
+ );
// awaited.[[Type]] is normal: set type to Return and jump to continuation.
generator.bind_reachable_label(awaited_normal_block);
diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs b/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs
index ab64f45b162..252e884e521 100644
--- a/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs
+++ b/Libraries/LibJS/Rust/src/bytecode/codegen/stream.rs
@@ -192,17 +192,23 @@ struct LastJump {
label_position_count: u32,
}
+/// A comparison that a conditional jump can make itself.
+#[derive(Clone, Copy)]
+struct Comparison {
+ operator: BinaryOp,
+ arith_feedback: u16,
+ lhs: Operand,
+ rhs: Operand,
+}
+
/// A comparison that was just emitted, in case it turns out to feed a conditional jump.
#[derive(Clone, Copy)]
struct LastComparison {
start: u32,
end: u32,
operand_position_count: u32,
- operator: BinaryOp,
- arith_feedback: u16,
dst: Operand,
- lhs: Operand,
- rhs: Operand,
+ comparison: Comparison,
}
impl Stream {
@@ -1652,7 +1658,7 @@ impl Generator<'_> {
/// Takes the comparison that made `condition` back, if that is what the code just did.
#[inline(always)]
- fn take_last_comparison(&mut self, condition: Operand) -> Option<LastComparison> {
+ fn take_last_comparison(&mut self, condition: Operand) -> Option<Comparison> {
let stream = &mut self.context.stream;
let comparison = stream.last_comparison?;
if comparison.dst != condition || comparison.end as usize != stream.current.bytes.len() {
@@ -1666,7 +1672,7 @@ impl Generator<'_> {
.truncate(comparison.operand_position_count as usize);
stream.last_comparison = None;
stream.last_destination = None;
- Some(comparison)
+ Some(comparison.comparison)
}
fn constant_truthiness(&self, condition: Operand) -> Option<bool> {
@@ -1741,13 +1747,36 @@ impl Generator<'_> {
self.context.stream.current.dead = was_dead;
}
- fn put_fused_jump(&mut self, comparison: LastComparison, true_target: Label, false_target: Label, back_edge: bool) {
- let LastComparison {
+ /// Branches on a comparison without materializing its boolean result.
+ pub(super) fn emit_comparison_jump(
+ &mut self,
+ operator: BinaryOp,
+ lhs: Operand,
+ rhs: Operand,
+ true_target: Label,
+ false_target: Label,
+ ) {
+ if self.is_stream_dead() {
+ return;
+ }
+ self.reference_label(true_target);
+ self.reference_label(false_target);
+ let arith_feedback = self.next_arith_feedback();
+ let comparison = Comparison {
+ operator,
+ arith_feedback,
+ lhs,
+ rhs,
+ };
+ self.put_fused_jump(comparison, true_target, false_target, false);
+ }
+
+ fn put_fused_jump(&mut self, comparison: Comparison, true_target: Label, false_target: Label, back_edge: bool) {
+ let Comparison {
operator,
arith_feedback,
lhs,
rhs,
- ..
} = comparison;
macro_rules! fused {
($($operator:ident => $jump:ident, $jump_loop:ident;)*) => {
@@ -2614,11 +2643,13 @@ impl Generator<'_> {
start,
end,
operand_position_count,
- operator,
- arith_feedback: u16::try_from(arith_feedback_before).unwrap_or(u16::MAX),
dst,
- lhs,
- rhs,
+ comparison: Comparison {
+ operator,
+ arith_feedback: u16::try_from(arith_feedback_before).unwrap_or(u16::MAX),
+ lhs,
+ rhs,
+ },
});
}
self.push_value(dst, first_temporary);
diff --git a/Tests/LibJS/Bytecode/expected/async-generator-yield-await.txt b/Tests/LibJS/Bytecode/expected/async-generator-yield-await.txt
index b2ab0934546..957c0e947d4 100644
--- a/Tests/LibJS/Bytecode/expected/async-generator-yield-await.txt
+++ b/Tests/LibJS/Bytecode/expected/async-generator-yield-await.txt
@@ -13,8 +13,8 @@ block0:
[ 14] End value:reg5
-f$5eac5b38 async-generator-yield-await.js:4:5
- Registers: 13
+f$9c99666c async-generator-yield-await.js:4:5
+ Registers: 9
Blocks: 17
Constants:
[0] = Undefined
@@ -52,38 +52,34 @@ block7:
block8:
[ 50] Mov dst:reg6, src:reg0
[ 53] GetCompletionFields type_dst:reg7, value_dst:reg8, completion:reg6
- [ 57] StrictlyInequalsRhsInt32 arith_feedback:2, dst:reg9, lhs:reg7, rhs:4
- [ 60] JumpIf condition:reg9, true_target:block12, false_target:block9
+ [ 57] JumpStrictlyEqualsRhsInt32 arith_feedback:2, lhs:reg7, rhs:4, true_target:block9, false_target:block12
block9:
- [ 6a] Await continuation_label:block10, argument:reg8
+ [ 67] Await continuation_label:block10, argument:reg8
block10:
- [ 70] Mov dst:reg6, src:reg0
- [ 73] GetCompletionFields type_dst:reg7, value_dst:reg8, completion:reg6
- [ 77] StrictlyEqualsRhsInt32 arith_feedback:3, dst:reg10, lhs:reg7, rhs:5
- [ 80] JumpIf condition:reg10, true_target:block12, false_target:block11
+ [ 6d] Mov dst:reg6, src:reg0
+ [ 70] GetCompletionFields type_dst:reg7, value_dst:reg8, completion:reg6
+ [ 74] JumpStrictlyEqualsRhsInt32 arith_feedback:3, lhs:reg7, rhs:5, true_target:block12, false_target:block11
block11:
- [ 8a] SetCompletionType completion:reg6
- [ 8d] Jump target:block12
+ [ 84] SetCompletionType completion:reg6
+ [ 87] Jump target:block12
block12:
- [ 92] Mov dst:reg6, src:reg0
- [ 95] GetCompletionFields type_dst:reg7, value_dst:reg8, completion:reg6
- [ 99] StrictlyEqualsRhsInt32 arith_feedback:4, dst:reg11, lhs:reg7, rhs:1
- [ a2] JumpIf condition:reg11, true_target:block16, false_target:block13
+ [ 8c] Mov dst:reg6, src:reg0
+ [ 8f] GetCompletionFields type_dst:reg7, value_dst:reg8, completion:reg6
+ [ 93] JumpStrictlyEqualsRhsInt32 arith_feedback:4, lhs:reg7, rhs:1, true_target:block16, false_target:block13
block13:
- [ ac] StrictlyEqualsRhsInt32 arith_feedback:5, dst:reg12, lhs:reg7, rhs:5
- [ b5] JumpIf condition:reg12, true_target:block14, false_target:block15
+ [ a3] JumpStrictlyEqualsRhsInt32 arith_feedback:5, lhs:reg7, rhs:5, true_target:block14, false_target:block15
block14:
- [ bf] Throw src:reg8
+ [ b3] Throw src:reg8
block15:
- [ c1] Yield value:reg8
+ [ b5] Yield value:reg8
block16:
- [ c8] Mov dst:reg5, src:reg8
- [ cb] Yield value:Undefined
+ [ bc] Mov dst:reg5, src:reg8
+ [ bf] Yield value:Undefined
diff --git a/Tests/LibJS/Bytecode/expected/async-generator-yield-star.txt b/Tests/LibJS/Bytecode/expected/async-generator-yield-star.txt
new file mode 100644
index 00000000000..1169a77a036
--- /dev/null
+++ b/Tests/LibJS/Bytecode/expected/async-generator-yield-star.txt
@@ -0,0 +1,235 @@
+$c0fc0013 async-generator-yield-star.js:5:1
+ Registers: 8
+ Blocks: 1
+ Constants:
+ [0] = Undefined
+
+block0:
+ [ 0] Enter
+ [ 1] Mov dst:reg5, src:Undefined
+ [ 4] GetGlobal value_feedback:0, dst:reg6, `delegate`
+ [ c] NewPrimitiveArray dst:reg7, elements:[1]
+ [ 1a] Call call_feedback:0, dst:reg6, callee:reg6, this_value:Undefined, arguments:[reg7]
+ [ 22] GetById dst:reg7, base:reg6, `next`
+ [ 29] Call call_feedback:1, dst:reg5, callee:reg7, this_value:reg6
+ [ 30] End value:reg5
+
+
+delegate$40183890 async-generator-yield-star.js:2:5
+ Registers: 24
+ Blocks: 51
+ Constants:
+ [0] = Undefined
+ [1] = Int32(1)
+
+block0:
+ [ 0] Enter
+ [ 1] Yield continuation_label:block1, value:Undefined
+
+block1:
+ [ 8] GetIterator dst_iterator_object:reg8, dst_iterator_next:reg9, dst_iterator_done:reg10, iterable:arg0, fast_array_mode_allowed:false
+ [ 11] Mov dst:reg6, src:Int32(1)
+ [ 14] Mov dst:reg7, src:Undefined
+ [ 17] Jump target:block2
+
+block2:
+ [ 1c] JumpStrictlyEqualsRhsInt32 arith_feedback:0, lhs:reg6, rhs:1, true_target:block3, false_target:block13
+
+block3:
+ [ 2c] Call call_feedback:0, dst:reg11, callee:reg9, this_value:reg8, arguments:[reg7]
+ [ 34] Await continuation_label:block4, argument:reg11
+
+block4:
+ [ 3a] Mov dst:reg5, src:reg0
+ [ 3d] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 41] JumpStrictlyEqualsRhsInt32 arith_feedback:1, lhs:reg6, rhs:1, true_target:block6, false_target:block5
+
+block5:
+ [ 51] Throw src:reg7
+
+block6:
+ [ 53] Mov dst:reg11, src:reg7
+ [ 56] ThrowIfNotObject src:reg11
+ [ 58] GetById dst:reg12, base:reg11, `done`
+ [ 5f] JumpIf condition:reg12, true_target:block7, false_target:block8
+
+block7:
+ [ 69] GetById dst:reg13, base:reg11, `value`
+ [ 70] Jump target:block47
+
+block8:
+ [ 75] GetById dst:reg14, base:reg11, `value`
+ [ 7c] Yield continuation_label:block9, value:reg14
+
+block9:
+ [ 83] Mov dst:reg5, src:reg0
+ [ 86] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 8a] JumpStrictlyEqualsRhsInt32 arith_feedback:2, lhs:reg6, rhs:4, true_target:block10, false_target:block46
+
+block10:
+ [ 9a] Await continuation_label:block11, argument:reg7
+
+block11:
+ [ a0] Mov dst:reg5, src:reg0
+ [ a3] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ a7] JumpStrictlyEqualsRhsInt32 arith_feedback:3, lhs:reg6, rhs:5, true_target:block46, false_target:block12
+
+block12:
+ [ b7] SetCompletionType completion:reg5
+ [ ba] Jump target:block46
+
+block13:
+ [ bf] JumpStrictlyEqualsRhsInt32 arith_feedback:4, lhs:reg6, rhs:5, true_target:block14, false_target:block31
+
+block14:
+ [ cf] GetMethod dst:reg15, object:reg8, `throw`
+ [ d6] JumpUndefined condition:reg15, true_target:block25, false_target:block15
+
+block15:
+ [ e0] Call call_feedback:1, dst:reg11, callee:reg15, this_value:reg8, arguments:[reg7]
+ [ e8] Await continuation_label:block16, argument:reg11
+
+block16:
+ [ ee] Mov dst:reg5, src:reg0
+ [ f1] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ f5] JumpStrictlyEqualsRhsInt32 arith_feedback:5, lhs:reg6, rhs:1, true_target:block18, false_target:block17
+
+block17:
+ [ 105] Throw src:reg7
+
+block18:
+ [ 107] Mov dst:reg11, src:reg7
+ [ 10a] ThrowIfNotObject src:reg11
+ [ 10c] GetById dst:reg12, base:reg11, `done`
+ [ 113] JumpIf condition:reg12, true_target:block19, false_target:block20
+
+block19:
+ [ 11d] GetById dst:reg13, base:reg11, `value`
+ [ 124] Jump target:block47
+
+block20:
+ [ 129] GetById dst:reg16, base:reg11, `value`
+ [ 130] Yield continuation_label:block21, value:reg16
+
+block21:
+ [ 137] Mov dst:reg5, src:reg0
+ [ 13a] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 13e] JumpStrictlyEqualsRhsInt32 arith_feedback:6, lhs:reg6, rhs:4, true_target:block22, false_target:block46
+
+block22:
+ [ 14e] Await continuation_label:block23, argument:reg7
+
+block23:
+ [ 154] Mov dst:reg5, src:reg0
+ [ 157] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 15b] JumpStrictlyEqualsRhsInt32 arith_feedback:7, lhs:reg6, rhs:5, true_target:block46, false_target:block24
+
+block24:
+ [ 16b] SetCompletionType completion:reg5
+ [ 16e] Jump target:block46
+
+block25:
+ [ 173] GetMethod dst:reg17, object:reg8, `return`
+ [ 17a] JumpUndefined condition:reg17, true_target:block30, false_target:block26
+
+block26:
+ [ 184] Call call_feedback:2, dst:reg18, callee:reg17, this_value:reg8
+ [ 18b] Await continuation_label:block27, argument:reg18
+
+block27:
+ [ 191] Mov dst:reg5, src:reg0
+ [ 194] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 198] JumpStrictlyEqualsRhsInt32 arith_feedback:8, lhs:reg6, rhs:1, true_target:block29, false_target:block28
+
+block28:
+ [ 1a8] Throw src:reg7
+
+block29:
+ [ 1aa] ThrowIfNotObject src:reg7
+ [ 1ac] Jump target:block30
+
+block30:
+ [ 1b1] NewTypeError dst:reg19, yield* protocol violation: iterator must have a throw method
+ [ 1b5] Throw src:reg19
+
+block31:
+ [ 1b7] GetMethod dst:reg20, object:reg8, `return`
+ [ 1be] JumpUndefined condition:reg20, true_target:block32, false_target:block36
+
+block32:
+ [ 1c8] Await continuation_label:block33, argument:reg7
+
+block33:
+ [ 1ce] Mov dst:reg5, src:reg0
+ [ 1d1] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 1d5] JumpStrictlyEqualsRhsInt32 arith_feedback:9, lhs:reg6, rhs:1, true_target:block35, false_target:block34
+
+block34:
+ [ 1e5] Throw src:reg7
+
+block35:
+ [ 1e7] Yield value:reg7
+
+block36:
+ [ 1ee] Call call_feedback:3, dst:reg21, callee:reg20, this_value:reg8, arguments:[reg7]
+ [ 1f6] Await continuation_label:block37, argument:reg21
+
+block37:
+ [ 1fc] Mov dst:reg5, src:reg0
+ [ 1ff] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 203] JumpStrictlyEqualsRhsInt32 arith_feedback:10, lhs:reg6, rhs:1, true_target:block39, false_target:block38
+
+block38:
+ [ 213] Throw src:reg7
+
+block39:
+ [ 215] Mov dst:reg21, src:reg7
+ [ 218] ThrowIfNotObject src:reg21
+ [ 21a] GetById dst:reg12, base:reg21, `done`
+ [ 221] JumpIf condition:reg12, true_target:block40, false_target:block41
+
+block40:
+ [ 22b] GetById dst:reg22, base:reg21, `value`
+ [ 232] Yield value:reg22
+
+block41:
+ [ 239] GetById dst:reg23, base:reg21, `value`
+ [ 240] Yield continuation_label:block42, value:reg23
+
+block42:
+ [ 247] Mov dst:reg5, src:reg0
+ [ 24a] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 24e] JumpStrictlyEqualsRhsInt32 arith_feedback:11, lhs:reg6, rhs:4, true_target:block43, false_target:block46
+
+block43:
+ [ 25e] Await continuation_label:block44, argument:reg7
+
+block44:
+ [ 264] Mov dst:reg5, src:reg0
+ [ 267] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 26b] JumpStrictlyEqualsRhsInt32 arith_feedback:12, lhs:reg6, rhs:5, true_target:block46, false_target:block45
+
+block45:
+ [ 27b] SetCompletionType completion:reg5
+ [ 27e] Jump target:block46
+
+block46:
+ [ 283] Mov dst:reg5, src:reg0
+ [ 286] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 28a] Jump target:block2
+
+block47:
+ [ 28f] Mov dst:reg5, src:reg13
+ [ 292] Await continuation_label:block48, argument:reg5
+
+block48:
+ [ 298] Mov dst:reg6, src:reg0
+ [ 29b] GetCompletionFields type_dst:reg7, value_dst:reg8, completion:reg6
+ [ 29f] JumpStrictlyEqualsRhsInt32 arith_feedback:13, lhs:reg7, rhs:1, true_target:block50, false_target:block49
+
+block49:
+ [ 2af] Throw src:reg8
+
+block50:
+ [ 2b1] Mov dst:reg5, src:reg8
+ [ 2b4] Yield value:reg5
diff --git a/Tests/LibJS/Bytecode/expected/async-generator-yield.txt b/Tests/LibJS/Bytecode/expected/async-generator-yield.txt
index 35f96b87a80..be24bbbeda4 100644
--- a/Tests/LibJS/Bytecode/expected/async-generator-yield.txt
+++ b/Tests/LibJS/Bytecode/expected/async-generator-yield.txt
@@ -13,8 +13,8 @@ block0:
[ 14] End value:reg5
-f$ebc3098b async-generator-yield.js:5:5
- Registers: 12
+f$29b014bf async-generator-yield.js:5:5
+ Registers: 8
Blocks: 14
Constants:
[0] = Undefined
@@ -40,38 +40,34 @@ block4:
block5:
[ 2e] Mov dst:reg5, src:reg0
[ 31] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
- [ 35] StrictlyInequalsRhsInt32 arith_feedback:1, dst:reg8, lhs:reg6, rhs:4
- [ 3e] JumpIf condition:reg8, true_target:block9, false_target:block6
+ [ 35] JumpStrictlyEqualsRhsInt32 arith_feedback:1, lhs:reg6, rhs:4, true_target:block6, false_target:block9
block6:
- [ 48] Await continuation_label:block7, argument:reg7
+ [ 45] Await continuation_label:block7, argument:reg7
block7:
- [ 4e] Mov dst:reg5, src:reg0
- [ 51] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
- [ 55] StrictlyEqualsRhsInt32 arith_feedback:2, dst:reg9, lhs:reg6, rhs:5
- [ 5e] JumpIf condition:reg9, true_target:block9, false_target:block8
+ [ 4b] Mov dst:reg5, src:reg0
+ [ 4e] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 52] JumpStrictlyEqualsRhsInt32 arith_feedback:2, lhs:reg6, rhs:5, true_target:block9, false_target:block8
block8:
- [ 68] SetCompletionType completion:reg5
- [ 6b] Jump target:block9
+ [ 62] SetCompletionType completion:reg5
+ [ 65] Jump target:block9
block9:
- [ 70] Mov dst:reg5, src:reg0
- [ 73] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
- [ 77] StrictlyEqualsRhsInt32 arith_feedback:3, dst:reg10, lhs:reg6, rhs:1
- [ 80] JumpIf condition:reg10, true_target:block13, false_target:block10
+ [ 6a] Mov dst:reg5, src:reg0
+ [ 6d] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 71] JumpStrictlyEqualsRhsInt32 arith_feedback:3, lhs:reg6, rhs:1, true_target:block13, false_target:block10
block10:
- [ 8a] StrictlyEqualsRhsInt32 arith_feedback:4, dst:reg11, lhs:reg6, rhs:5
- [ 93] JumpIf condition:reg11, true_target:block11, false_target:block12
+ [ 81] JumpStrictlyEqualsRhsInt32 arith_feedback:4, lhs:reg6, rhs:5, true_target:block11, false_target:block12
block11:
- [ 9d] Throw src:reg7
+ [ 91] Throw src:reg7
block12:
- [ 9f] Yield value:reg7
+ [ 93] Yield value:reg7
block13:
- [ a6] Mov dst:reg5, src:reg7
- [ a9] Yield value:Undefined
+ [ 9a] Mov dst:reg5, src:reg7
+ [ 9d] Yield value:Undefined
diff --git a/Tests/LibJS/Bytecode/expected/generator-yield-call.txt b/Tests/LibJS/Bytecode/expected/generator-yield-call.txt
index af5826f8963..620fd0379a2 100644
--- a/Tests/LibJS/Bytecode/expected/generator-yield-call.txt
+++ b/Tests/LibJS/Bytecode/expected/generator-yield-call.txt
@@ -20,8 +20,8 @@ block0:
[ 37] End value:reg5
-f$72770005 generator-yield-call.js:6:5
- Registers: 11
+f$b327fc49 generator-yield-call.js:6:5
+ Registers: 9
Blocks: 12
Constants:
[0] = Undefined
@@ -37,40 +37,36 @@ block1:
block2:
[ 16] Mov dst:reg6, src:reg0
[ 19] GetCompletionFields type_dst:reg7, value_dst:reg8, completion:reg6
- [ 1d] StrictlyEqualsRhsInt32 arith_feedback:0, dst:reg9, lhs:reg7, rhs:1
- [ 26] JumpIf condition:reg9, true_target:block6, false_target:block3
+ [ 1d] JumpStrictlyEqualsRhsInt32 arith_feedback:0, lhs:reg7, rhs:1, true_target:block6, false_target:block3
block3:
- [ 30] StrictlyEqualsRhsInt32 arith_feedback:1, dst:reg10, lhs:reg7, rhs:5
- [ 39] JumpIf condition:reg10, true_target:block4, false_target:block5
+ [ 2d] JumpStrictlyEqualsRhsInt32 arith_feedback:1, lhs:reg7, rhs:5, true_target:block4, false_target:block5
block4:
- [ 43] Throw src:reg8
+ [ 3d] Throw src:reg8
block5:
- [ 45] Yield value:reg8
+ [ 3f] Yield value:reg8
block6:
- [ 4c] Mov dst:reg5, src:reg8
- [ 4f] GetById dst:reg5, base:arg1, `y`
- [ 56] Yield continuation_label:block7, value:reg5
+ [ 46] Mov dst:reg5, src:reg8
+ [ 49] GetById dst:reg5, base:arg1, `y`
+ [ 50] Yield continuation_label:block7, value:reg5
block7:
- [ 5d] Mov dst:reg6, src:reg0
- [ 60] GetCompletionFields type_dst:reg7, value_dst:reg8, completion:reg6
- [ 64] StrictlyEqualsRhsInt32 arith_feedback:2, dst:reg9, lhs:reg7, rhs:1
- [ 6d] JumpIf condition:reg9, true_target:block11, false_target:block8
+ [ 57] Mov dst:reg6, src:reg0
+ [ 5a] GetCompletionFields type_dst:reg7, value_dst:reg8, completion:reg6
+ [ 5e] JumpStrictlyEqualsRhsInt32 arith_feedback:2, lhs:reg7, rhs:1, true_target:block11, false_target:block8
block8:
- [ 77] StrictlyEqualsRhsInt32 arith_feedback:3, dst:reg10, lhs:reg7, rhs:5
- [ 80] JumpIf condition:reg10, true_target:block9, false_target:block10
+ [ 6e] JumpStrictlyEqualsRhsInt32 arith_feedback:3, lhs:reg7, rhs:5, true_target:block9, false_target:block10
block9:
- [ 8a] Throw src:reg8
+ [ 7e] Throw src:reg8
block10:
- [ 8c] Yield value:reg8
+ [ 80] Yield value:reg8
block11:
- [ 93] Mov dst:reg5, src:reg8
- [ 96] Yield value:Undefined
+ [ 87] Mov dst:reg5, src:reg8
+ [ 8a] Yield value:Undefined
diff --git a/Tests/LibJS/Bytecode/expected/generator-yield-finally.txt b/Tests/LibJS/Bytecode/expected/generator-yield-finally.txt
index da66ebbfda0..f57bae99160 100644
--- a/Tests/LibJS/Bytecode/expected/generator-yield-finally.txt
+++ b/Tests/LibJS/Bytecode/expected/generator-yield-finally.txt
@@ -12,8 +12,8 @@ block0:
[ 13] End value:reg5
-f$2d49b16e generator-yield-finally.js:4:9
- Registers: 12
+f$2af43e8b generator-yield-finally.js:4:9
+ Registers: 10
Blocks: 23
Constants:
[0] = Undefined
@@ -32,86 +32,80 @@ block1:
block2:
[ f] Mov dst:reg7, src:reg0
[ 12] GetCompletionFields type_dst:reg8, value_dst:reg9, completion:reg7
- [ 16] StrictlyEqualsRhsInt32 arith_feedback:0, dst:reg10, lhs:reg8, rhs:1
- [ 1f] JumpIf condition:reg10, true_target:block6, false_target:block3
+ [ 16] JumpStrictlyEqualsRhsInt32 arith_feedback:0, lhs:reg8, rhs:1, true_target:block6, false_target:block3
block3:
- [ 29] StrictlyEqualsRhsInt32 arith_feedback:1, dst:reg11, lhs:reg8, rhs:5
- [ 32] JumpIf condition:reg11, true_target:block4, false_target:block5
+ [ 26] JumpStrictlyEqualsRhsInt32 arith_feedback:1, lhs:reg8, rhs:5, true_target:block4, false_target:block5
block4:
- [ 3c] Throw src:reg9
+ [ 36] Throw src:reg9
block5:
- [ 3e] Mov dst:reg6, src:reg9
- [ 41] Mov dst:reg5, src:Int32(2)
- [ 44] Jump target:block13
+ [ 38] Mov dst:reg6, src:reg9
+ [ 3b] Mov dst:reg5, src:Int32(2)
+ [ 3e] Jump target:block13
block6:
- [ 49] Mov dst:reg7, src:reg9
- [ 4c] Yield continuation_label:block7, value:Int32(2)
+ [ 43] Mov dst:reg7, src:reg9
+ [ 46] Yield continuation_label:block7, value:Int32(2)
block7:
- [ 53] Mov dst:reg7, src:reg0
- [ 56] GetCompletionFields type_dst:reg8, value_dst:reg9, completion:reg7
- [ 5a] StrictlyEqualsRhsInt32 arith_feedback:2, dst:reg10, lhs:reg8, rhs:1
- [ 63] JumpIf condition:reg10, true_target:block11, false_target:block8
+ [ 4d] Mov dst:reg7, src:reg0
+ [ 50] GetCompletionFields type_dst:reg8, value_dst:reg9, completion:reg7
+ [ 54] JumpStrictlyEqualsRhsInt32 arith_feedback:2, lhs:reg8, rhs:1, true_target:block11, false_target:block8
block8:
- [ 6d] StrictlyEqualsRhsInt32 arith_feedback:3, dst:reg11, lhs:reg8, rhs:5
- [ 76] JumpIf condition:reg11, true_target:block9, false_target:block10
+ [ 64] JumpStrictlyEqualsRhsInt32 arith_feedback:3, lhs:reg8, rhs:5, true_target:block9, false_target:block10
block9:
- [ 80] Throw src:reg9
+ [ 74] Throw src:reg9
block10:
- [ 82] Mov dst:reg6, src:reg9
- [ 85] Mov dst:reg5, src:Int32(2)
- [ 88] Jump target:block13
+ [ 76] Mov dst:reg6, src:reg9
+ [ 79] Mov dst:reg5, src:Int32(2)
+ [ 7c] Jump target:block13
block11:
- [ 8d] Mov dst:reg7, src:reg9
- [ 90] Mov dst:reg5, src:Int32(0)
- [ 93] Jump target:block13
+ [ 81] Mov dst:reg7, src:reg9
+ [ 84] Mov dst:reg5, src:Int32(0)
+ [ 87] Jump target:block13
block12:
- [ 98] Catch value_feedback:0, dst:reg6
- [ 9c] Mov dst:reg5, src:Int32(1)
+ [ 8c] Catch value_feedback:0, dst:reg6
+ [ 90] Mov dst:reg5, src:Int32(1)
block13:
- [ 9f] Yield continuation_label:block14, value:Int32(3)
+ [ 93] Yield continuation_label:block14, value:Int32(3)
block14:
- [ a6] Mov dst:reg7, src:reg0
- [ a9] GetCompletionFields type_dst:reg8, value_dst:reg9, completion:reg7
- [ ad] StrictlyEqualsRhsInt32 arith_feedback:4, dst:reg10, lhs:reg8, rhs:1
- [ b6] JumpIf condition:reg10, true_target:block18, false_target:block15
+ [ 9a] Mov dst:reg7, src:reg0
+ [ 9d] GetCompletionFields type_dst:reg8, value_dst:reg9, completion:reg7
+ [ a1] JumpStrictlyEqualsRhsInt32 arith_feedback:4, lhs:reg8, rhs:1, true_target:block18, false_target:block15
block15:
- [ c0] StrictlyEqualsRhsInt32 arith_feedback:5, dst:reg11, lhs:reg8, rhs:5
- [ c9] JumpIf condition:reg11, true_target:block16, false_target:block17
+ [ b1] JumpStrictlyEqualsRhsInt32 arith_feedback:5, lhs:reg8, rhs:5, true_target:block16, false_target:block17
block16:
- [ d3] Throw src:reg9
+ [ c1] Throw src:reg9
block17:
- [ d5] Yield value:reg9
+ [ c3] Yield value:reg9
block18:
- [ dc] Mov dst:reg7, src:reg9
- [ df] JumpStrictlyEqualsRhsInt32 arith_feedback:6, lhs:reg5, rhs:0, true_target:block22, false_target:block19
+ [ ca] Mov dst:reg7, src:reg9
+ [ cd] JumpStrictlyEqualsRhsInt32 arith_feedback:6, lhs:reg5, rhs:0, true_target:block22, false_target:block19
block19:
- [ ef] JumpStrictlyEqualsRhsInt32 arith_feedback:7, lhs:reg5, rhs:2, true_target:block20, false_target:block21
+ [ dd] JumpStrictlyEqualsRhsInt32 arith_feedback:7, lhs:reg5, rhs:2, true_target:block20, false_target:block21
block20:
- [ ff] Yield value:reg6
+ [ ed] Yield value:reg6
block21:
- [ 106] Throw src:reg6
+ [ f4] Throw src:reg6
block22:
- [ 108] Yield value:Undefined
+ [ f6] Yield value:Undefined
Exception handlers:
- [ 8 .. 98] => handler block12
+ [ 8 .. 8c] => handler block12
diff --git a/Tests/LibJS/Bytecode/expected/generator-yield-star.txt b/Tests/LibJS/Bytecode/expected/generator-yield-star.txt
index 58264a48937..dd5bc59cd97 100644
--- a/Tests/LibJS/Bytecode/expected/generator-yield-star.txt
+++ b/Tests/LibJS/Bytecode/expected/generator-yield-star.txt
@@ -13,8 +13,8 @@ block0:
[ 2a] End value:reg5
-f$b179cfdd generator-yield-star.js:4:5
- Registers: 21
+f$92834a43 generator-yield-star.js:4:5
+ Registers: 19
Blocks: 19
Constants:
[0] = Undefined
@@ -31,73 +31,71 @@ block1:
[ 17] Jump target:block2
block2:
- [ 1c] StrictlyEqualsRhsInt32 arith_feedback:0, dst:reg11, lhs:reg6, rhs:1
- [ 25] JumpIf condition:reg11, true_target:block3, false_target:block6
+ [ 1c] JumpStrictlyEqualsRhsInt32 arith_feedback:0, lhs:reg6, rhs:1, true_target:block3, false_target:block6
block3:
- [ 2f] Call call_feedback:0, dst:reg12, callee:reg9, this_value:reg8, arguments:[reg7]
- [ 37] ThrowIfNotObject src:reg12
- [ 39] GetById dst:reg13, base:reg12, `done`
- [ 40] JumpIf condition:reg13, true_target:block4, false_target:block5
+ [ 2c] Call call_feedback:0, dst:reg11, callee:reg9, this_value:reg8, arguments:[reg7]
+ [ 34] ThrowIfNotObject src:reg11
+ [ 36] GetById dst:reg12, base:reg11, `done`
+ [ 3d] JumpIf condition:reg12, true_target:block4, false_target:block5
block4:
- [ 4a] GetById dst:reg14, base:reg12, `value`
- [ 51] Jump target:block18
+ [ 47] GetById dst:reg13, base:reg11, `value`
+ [ 4e] Jump target:block18
block5:
- [ 56] YieldIteratorResult continuation_label:block17, value:reg12
+ [ 53] YieldIteratorResult continuation_label:block17, value:reg11
block6:
- [ 5c] StrictlyEqualsRhsInt32 arith_feedback:1, dst:reg15, lhs:reg6, rhs:5
- [ 65] JumpIf condition:reg15, true_target:block7, false_target:block12
+ [ 59] JumpStrictlyEqualsRhsInt32 arith_feedback:1, lhs:reg6, rhs:5, true_target:block7, false_target:block12
block7:
- [ 6f] GetMethod dst:reg16, object:reg8, `throw`
- [ 76] JumpUndefined condition:reg16, true_target:block11, false_target:block8
+ [ 69] GetMethod dst:reg14, object:reg8, `throw`
+ [ 70] JumpUndefined condition:reg14, true_target:block11, false_target:block8
block8:
- [ 80] Call call_feedback:1, dst:reg12, callee:reg16, this_value:reg8, arguments:[reg7]
- [ 88] ThrowIfNotObject src:reg12
- [ 8a] GetById dst:reg13, base:reg12, `done`
- [ 91] JumpIf condition:reg13, true_target:block9, false_target:block10
+ [ 7a] Call call_feedback:1, dst:reg11, callee:reg14, this_value:reg8, arguments:[reg7]
+ [ 82] ThrowIfNotObject src:reg11
+ [ 84] GetById dst:reg12, base:reg11, `done`
+ [ 8b] JumpIf condition:reg12, true_target:block9, false_target:block10
block9:
- [ 9b] GetById dst:reg14, base:reg12, `value`
- [ a2] Jump target:block18
+ [ 95] GetById dst:reg13, base:reg11, `value`
+ [ 9c] Jump target:block18
block10:
- [ a7] YieldIteratorResult continuation_label:block17, value:reg12
+ [ a1] YieldIteratorResult continuation_label:block17, value:reg11
block11:
- [ ad] IteratorClose iterator_object:reg8, iterator_next:reg9, iterator_done:reg10, completion_value:Undefined
- [ b5] NewTypeError dst:reg17, yield* protocol violation: iterator must have a throw method
- [ b9] Throw src:reg17
+ [ a7] IteratorClose iterator_object:reg8, iterator_next:reg9, iterator_done:reg10, completion_value:Undefined
+ [ af] NewTypeError dst:reg15, yield* protocol violation: iterator must have a throw method
+ [ b3] Throw src:reg15
block12:
- [ bb] GetMethod dst:reg18, object:reg8, `return`
- [ c2] JumpUndefined condition:reg18, true_target:block13, false_target:block14
+ [ b5] GetMethod dst:reg16, object:reg8, `return`
+ [ bc] JumpUndefined condition:reg16, true_target:block13, false_target:block14
block13:
- [ cc] Yield value:reg7
+ [ c6] Yield value:reg7
block14:
- [ d3] Call call_feedback:2, dst:reg19, callee:reg18, this_value:reg8, arguments:[reg7]
- [ db] ThrowIfNotObject src:reg19
- [ dd] GetById dst:reg13, base:reg19, `done`
- [ e4] JumpIf condition:reg13, true_target:block15, false_target:block16
+ [ cd] Call call_feedback:2, dst:reg17, callee:reg16, this_value:reg8, arguments:[reg7]
+ [ d5] ThrowIfNotObject src:reg17
+ [ d7] GetById dst:reg12, base:reg17, `done`
+ [ de] JumpIf condition:reg12, true_target:block15, false_target:block16
block15:
- [ ee] GetById dst:reg20, base:reg19, `value`
- [ f5] Yield value:reg20
+ [ e8] GetById dst:reg18, base:reg17, `value`
+ [ ef] Yield value:reg18
block16:
- [ fc] YieldIteratorResult continuation_label:block17, value:reg19
+ [ f6] YieldIteratorResult continuation_label:block17, value:reg17
block17:
- [ 102] Mov dst:reg5, src:reg0
- [ 105] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
- [ 109] Jump target:block2
+ [ fc] Mov dst:reg5, src:reg0
+ [ ff] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 103] Jump target:block2
block18:
- [ 10e] Mov dst:reg5, src:reg14
- [ 111] Yield value:Undefined
+ [ 108] Mov dst:reg5, src:reg13
+ [ 10b] Yield value:Undefined
diff --git a/Tests/LibJS/Bytecode/expected/generator-yield.txt b/Tests/LibJS/Bytecode/expected/generator-yield.txt
index 8358d49af1d..da5bf95157c 100644
--- a/Tests/LibJS/Bytecode/expected/generator-yield.txt
+++ b/Tests/LibJS/Bytecode/expected/generator-yield.txt
@@ -19,8 +19,8 @@ block0:
[ 45] End value:reg5
-multi_yield$5798a4db generator-yield.js:7:5
- Registers: 10
+multi_yield$16e7a897 generator-yield.js:7:5
+ Registers: 8
Blocks: 12
Constants:
[0] = Undefined
@@ -37,39 +37,35 @@ block1:
block2:
[ f] Mov dst:reg5, src:reg0
[ 12] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
- [ 16] StrictlyEqualsRhsInt32 arith_feedback:0, dst:reg8, lhs:reg6, rhs:1
- [ 1f] JumpIf condition:reg8, true_target:block6, false_target:block3
+ [ 16] JumpStrictlyEqualsRhsInt32 arith_feedback:0, lhs:reg6, rhs:1, true_target:block6, false_target:block3
block3:
- [ 29] StrictlyEqualsRhsInt32 arith_feedback:1, dst:reg9, lhs:reg6, rhs:5
- [ 32] JumpIf condition:reg9, true_target:block4, false_target:block5
+ [ 26] JumpStrictlyEqualsRhsInt32 arith_feedback:1, lhs:reg6, rhs:5, true_target:block4, false_target:block5
block4:
- [ 3c] Throw src:reg7
+ [ 36] Throw src:reg7
block5:
- [ 3e] Yield value:reg7
+ [ 38] Yield value:reg7
block6:
- [ 45] Mov dst:reg5, src:reg7
- [ 48] Yield continuation_label:block7, value:Int32(2)
+ [ 3f] Mov dst:reg5, src:reg7
+ [ 42] Yield continuation_label:block7, value:Int32(2)
block7:
- [ 4f] Mov dst:reg5, src:reg0
- [ 52] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
- [ 56] StrictlyEqualsRhsInt32 arith_feedback:2, dst:reg8, lhs:reg6, rhs:1
- [ 5f] JumpIf condition:reg8, true_target:block11, false_target:block8
+ [ 49] Mov dst:reg5, src:reg0
+ [ 4c] GetCompletionFields type_dst:reg6, value_dst:reg7, completion:reg5
+ [ 50] JumpStrictlyEqualsRhsInt32 arith_feedback:2, lhs:reg6, rhs:1, true_target:block11, false_target:block8
block8:
- [ 69] StrictlyEqualsRhsInt32 arith_feedback:3, dst:reg9, lhs:reg6, rhs:5
- [ 72] JumpIf condition:reg9, true_target:block9, false_target:block10
+ [ 60] JumpStrictlyEqualsRhsInt32 arith_feedback:3, lhs:reg6, rhs:5, true_target:block9, false_target:block10
block9:
- [ 7c] Throw src:reg7
+ [ 70] Throw src:reg7
block10:
- [ 7e] Yield value:reg7
+ [ 72] Yield value:reg7
block11:
- [ 85] Mov dst:reg5, src:reg7
- [ 88] Yield value:Undefined
+ [ 79] Mov dst:reg5, src:reg7
+ [ 7c] Yield value:Undefined
diff --git a/Tests/LibJS/Bytecode/input/async-generator-yield-star.js b/Tests/LibJS/Bytecode/input/async-generator-yield-star.js
new file mode 100644
index 00000000000..8ea5a7fcf93
--- /dev/null
+++ b/Tests/LibJS/Bytecode/input/async-generator-yield-star.js
@@ -0,0 +1,5 @@
+async function* delegate(value) {
+ return yield* value;
+}
+
+delegate([1]).next();