v8/test/cctest/interpreter/bytecode_expectations/Generators.golden
Benedikt Meurer 06359f7453 [debug] Don't put a source position on internal Returns.
Be explicit about source positions for `Return`s in the
BytecodeGenerator, and only do self-healing explicitly in the
`ReturnStatement` translation, where an end position of
`kNoSourcePosition` is turned into the return position of the
function literal.

This allows us to reason more easily about which `Return`s actually
receive a meaningful source position, and in particular it allows us
to construct the internal `Return`s for `yield` and `yield*` with no
source position attached to them. Previously they'd get the source
position for the implicit (final) return attached to it, which confused
the debugger and led to breakpoints being set in the completely wrong
spot.

Considering the simplified example

```
function* foo(){
  var a = 1;
}
```

this would previously generate the following bytecode

```
        0 : SwitchOnGeneratorState r0, [0], [1] { 0: @20 }
        4 : Mov <closure>, r2
        7 : Mov <this>, r3
 13 E> 10 : InvokeIntrinsic [_CreateJSGeneratorObject], r2-r3
       14 : Star0
 13 E> 15 : SuspendGenerator r0, r0-r1, [0]
       20 : ResumeGenerator r0, r0-r1
       24 : Star2
       25 : InvokeIntrinsic [_GeneratorGetResumeMode], r0-r0
       29 : SwitchOnSmiNoFeedback [1], [2], [0] { 0: @39, 1: @36 }
       33 : Ldar r2
 13 E> 35 : Throw
       36 : Ldar r2
 30 S> 38 : Return    <=========================== internal Return
 27 S> 39 : LdaSmi [1]
       41 : Star1
       42 : LdaUndefined
 30 S> 43 : Return
```

where everything between offset 4 and 42 corresponds to the implicit
yield at the beginning of every generator function, in particular the
code between 20 and 42 corresponds to that initial yields resumption
logic. Notice how the internal Return at offset 38 gets assigned the
source position of the function literal (the same as the implicit
return at the end). This confuses the debugger quite a bit when trying
to set a breakpoint on the closing brace, since it's going in bytecode
order and will thus discover the `Return` at offset 38 first (matching
the source position 30 it's currently looking for) and setting the
breakpoint there. This `Return` bytecode however is only executed when
the generator is resumed via `GeneratorPrototype.return()`, and it'll
not hit when the developer uses the generator normally, which is not
the desired behavior and extremely confusing (especially since stepping
on the other hand works as expected).

With this patch, we no longer slap a source position (and in particular
not the function literal's return position) onto these internal
`Return`s as you can see from the generated bytecode below:

```
       0 : SwitchOnGeneratorState r0, [0], [1] { 0: @20 }
       4 : Mov <closure>, r2
       7 : Mov <this>, r3
13 E> 10 : InvokeIntrinsic [_CreateJSGeneratorObject], r2-r3
      14 : Star0
13 E> 15 : SuspendGenerator r0, r0-r1, [0]
      20 : ResumeGenerator r0, r0-r1
      24 : Star2
      25 : InvokeIntrinsic [_GeneratorGetResumeMode], r0-r0
      29 : SwitchOnSmiNoFeedback [1], [2], [0] { 0: @39, 1: @36 }
      33 : Ldar r2
13 E> 35 : Throw
      36 : Ldar r2
      38 : Return
27 S> 39 : LdaSmi [1]
      41 : Star1
      42 : LdaUndefined
30 S> 43 : Return
```

This also allows us to remove the break position finding hack that was
kept in BreakIterator::BreakIndexFromPosition() for generators and
modules.

Fixed: chromium:901819
Change-Id: If19a6b26e2622d49b6b5e54bf7a162747543f970
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2727820
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73119}
2021-03-02 08:42:10 +00:00

320 lines
11 KiB
Plaintext

#
# Autogenerated by generate-bytecode-expectations.
#
---
wrap: no
test function name: f
---
snippet: "
function* f() { }
f();
"
frame size: 3
parameter count: 1
bytecode array length: 41
bytecodes: [
B(SwitchOnGeneratorState), R(0), U8(0), U8(1),
B(Mov), R(closure), R(1),
B(Mov), R(this), R(2),
/* 11 E> */ B(InvokeIntrinsic), U8(Runtime::k_CreateJSGeneratorObject), R(1), U8(2),
B(Star0),
/* 11 E> */ B(SuspendGenerator), R(0), R(0), U8(1), U8(0),
B(ResumeGenerator), R(0), R(0), U8(1),
B(Star1),
B(InvokeIntrinsic), U8(Runtime::k_GeneratorGetResumeMode), R(0), U8(1),
B(SwitchOnSmiNoFeedback), U8(1), U8(2), I8(0),
B(Ldar), R(1),
/* 11 E> */ B(Throw),
B(Ldar), R(1),
B(Return),
B(LdaUndefined),
/* 16 S> */ B(Return),
]
constant pool: [
Smi [20],
Smi [10],
Smi [7],
]
handlers: [
]
---
snippet: "
function* f() { yield 42 }
f();
"
frame size: 3
parameter count: 1
bytecode array length: 74
bytecodes: [
B(SwitchOnGeneratorState), R(0), U8(0), U8(2),
B(Mov), R(closure), R(1),
B(Mov), R(this), R(2),
/* 11 E> */ B(InvokeIntrinsic), U8(Runtime::k_CreateJSGeneratorObject), R(1), U8(2),
B(Star0),
/* 11 E> */ B(SuspendGenerator), R(0), R(0), U8(1), U8(0),
B(ResumeGenerator), R(0), R(0), U8(1),
B(Star1),
B(InvokeIntrinsic), U8(Runtime::k_GeneratorGetResumeMode), R(0), U8(1),
B(SwitchOnSmiNoFeedback), U8(2), U8(2), I8(0),
B(Ldar), R(1),
/* 11 E> */ B(Throw),
B(Ldar), R(1),
B(Return),
/* 16 S> */ B(LdaSmi), I8(42),
B(Star1),
B(LdaFalse),
B(Star2),
B(InvokeIntrinsic), U8(Runtime::k_CreateIterResultObject), R(1), U8(2),
/* 16 E> */ B(SuspendGenerator), R(0), R(0), U8(1), U8(1),
B(ResumeGenerator), R(0), R(0), U8(1),
B(Star1),
B(InvokeIntrinsic), U8(Runtime::k_GeneratorGetResumeMode), R(0), U8(1),
B(SwitchOnSmiNoFeedback), U8(4), U8(2), I8(0),
B(Ldar), R(1),
/* 16 E> */ B(Throw),
B(Ldar), R(1),
B(Return),
B(LdaUndefined),
/* 25 S> */ B(Return),
]
constant pool: [
Smi [20],
Smi [53],
Smi [10],
Smi [7],
Smi [10],
Smi [7],
]
handlers: [
]
---
snippet: "
function* f() { for (let x of [42]) yield x }
f();
"
frame size: 14
parameter count: 1
bytecode array length: 210
bytecodes: [
B(SwitchOnGeneratorState), R(0), U8(0), U8(2),
B(Mov), R(closure), R(4),
B(Mov), R(this), R(5),
/* 11 E> */ B(InvokeIntrinsic), U8(Runtime::k_CreateJSGeneratorObject), R(4), U8(2),
B(Star0),
/* 11 E> */ B(SuspendGenerator), R(0), R(0), U8(4), U8(0),
B(ResumeGenerator), R(0), R(0), U8(4),
B(Star4),
B(InvokeIntrinsic), U8(Runtime::k_GeneratorGetResumeMode), R(0), U8(1),
B(SwitchOnSmiNoFeedback), U8(2), U8(2), I8(0),
B(Ldar), R(4),
/* 11 E> */ B(Throw),
B(Ldar), R(4),
B(Return),
/* 30 S> */ B(CreateArrayLiteral), U8(4), U8(0), U8(37),
B(Star6),
B(GetIterator), R(6), U8(1), U8(3),
B(JumpIfJSReceiver), U8(7),
B(CallRuntime), U16(Runtime::kThrowSymbolIteratorInvalid), R(0), U8(0),
B(Star5),
B(LdaNamedProperty), R(5), U8(5), U8(5),
B(Star4),
B(LdaFalse),
B(Star6),
B(Mov), R(context), R(9),
B(LdaTrue),
B(Star6),
/* 25 S> */ B(CallProperty0), R(4), R(5), U8(7),
B(Star10),
B(JumpIfJSReceiver), U8(7),
B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), R(10), U8(1),
B(LdaNamedProperty), R(10), U8(6), U8(9),
B(JumpIfToBooleanTrue), U8(58),
B(LdaNamedProperty), R(10), U8(7), U8(11),
B(Star10),
B(LdaFalse),
B(Star6),
B(Mov), R(10), R(1),
/* 25 S> */ B(Mov), R(1), R(3),
/* 36 S> */ B(LdaFalse),
B(Star12),
B(Mov), R(3), R(11),
B(InvokeIntrinsic), U8(Runtime::k_CreateIterResultObject), R(11), U8(2),
/* 36 E> */ B(SuspendGenerator), R(0), R(0), U8(11), U8(1),
B(ResumeGenerator), R(0), R(0), U8(11),
B(Star11),
B(InvokeIntrinsic), U8(Runtime::k_GeneratorGetResumeMode), R(0), U8(1),
B(SwitchOnSmiNoFeedback), U8(8), U8(2), I8(0),
B(Ldar), R(11),
/* 36 E> */ B(Throw),
B(LdaSmi), I8(1),
B(Star7),
B(Mov), R(11), R(8),
B(Jump), U8(16),
B(Ldar), R(11),
/* 16 E> */ B(JumpLoop), U8(73), I8(0),
B(LdaSmi), I8(-1),
B(Star8),
B(Star7),
B(Jump), U8(5),
B(Star8),
B(LdaZero),
B(Star7),
B(LdaTheHole),
B(SetPendingMessage),
B(Star9),
B(Ldar), R(6),
B(JumpIfToBooleanTrue), U8(35),
B(Mov), R(context), R(11),
B(LdaNamedProperty), R(5), U8(10), U8(13),
B(JumpIfUndefinedOrNull), U8(26),
B(Star12),
B(CallProperty0), R(12), R(5), U8(15),
B(JumpIfJSReceiver), U8(19),
B(Star13),
B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), R(13), U8(1),
B(Jump), U8(11),
B(Star11),
B(LdaZero),
B(TestReferenceEqual), R(7),
B(JumpIfTrue), U8(5),
B(Ldar), R(11),
B(ReThrow),
B(Ldar), R(9),
B(SetPendingMessage),
B(Ldar), R(7),
B(SwitchOnSmiNoFeedback), U8(11), U8(2), I8(0),
B(Jump), U8(8),
B(Ldar), R(8),
B(ReThrow),
B(Ldar), R(8),
B(Return),
B(LdaUndefined),
/* 44 S> */ B(Return),
]
constant pool: [
Smi [20],
Smi [113],
Smi [10],
Smi [7],
ARRAY_BOILERPLATE_DESCRIPTION_TYPE,
ONE_BYTE_INTERNALIZED_STRING_TYPE ["next"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["done"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["value"],
Smi [15],
Smi [7],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["return"],
Smi [6],
Smi [9],
]
handlers: [
[66, 142, 148],
[161, 180, 182],
]
---
snippet: "
function* g() { yield 42 }
function* f() { yield* g() }
f();
"
frame size: 7
parameter count: 1
bytecode array length: 188
bytecodes: [
B(SwitchOnGeneratorState), R(0), U8(0), U8(2),
B(Mov), R(closure), R(1),
B(Mov), R(this), R(2),
/* 38 E> */ B(InvokeIntrinsic), U8(Runtime::k_CreateJSGeneratorObject), R(1), U8(2),
B(Star0),
/* 38 E> */ B(SuspendGenerator), R(0), R(0), U8(1), U8(0),
B(ResumeGenerator), R(0), R(0), U8(1),
B(Star1),
B(InvokeIntrinsic), U8(Runtime::k_GeneratorGetResumeMode), R(0), U8(1),
B(SwitchOnSmiNoFeedback), U8(2), U8(2), I8(0),
B(Ldar), R(1),
/* 38 E> */ B(Throw),
B(Ldar), R(1),
B(Return),
/* 43 S> */ B(LdaGlobal), U8(4), U8(0),
B(Star5),
/* 50 E> */ B(CallUndefinedReceiver0), R(5), U8(2),
B(Star6),
B(GetIterator), R(6), U8(4), U8(6),
B(JumpIfJSReceiver), U8(7),
B(CallRuntime), U16(Runtime::kThrowSymbolIteratorInvalid), R(0), U8(0),
B(Star3),
B(LdaNamedProperty), R(3), U8(5), U8(8),
B(Star5),
B(LdaUndefined),
B(Star4),
B(LdaZero),
B(Star2),
B(Ldar), R(2),
B(SwitchOnSmiNoFeedback), U8(6), U8(2), I8(1),
B(CallProperty1), R(5), R(3), R(4), U8(10),
B(Jump), U8(59),
B(LdaNamedProperty), R(3), U8(8), U8(12),
B(JumpIfUndefinedOrNull), U8(10),
B(Star6),
B(CallProperty1), R(6), R(3), R(4), U8(14),
B(Jump), U8(45),
B(Ldar), R(4),
B(Return),
B(LdaNamedProperty), R(3), U8(9), U8(16),
B(JumpIfUndefinedOrNull), U8(10),
B(Star6),
B(CallProperty1), R(6), R(3), R(4), U8(18),
B(Jump), U8(28),
B(LdaNamedProperty), R(3), U8(8), U8(20),
B(JumpIfUndefinedOrNull), U8(17),
B(Star6),
B(CallProperty0), R(6), R(3), U8(22),
B(Jump), U8(2),
B(JumpIfJSReceiver), U8(8),
B(Star6),
B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), R(6), U8(1),
B(CallRuntime), U16(Runtime::kThrowThrowMethodMissing), R(0), U8(0),
B(Star1),
B(JumpIfJSReceiver), U8(7),
B(CallRuntime), U16(Runtime::kThrowIteratorResultNotAnObject), R(1), U8(1),
B(LdaNamedProperty), R(1), U8(10), U8(24),
B(JumpIfToBooleanTrue), U8(22),
B(Ldar), R(1),
/* 43 E> */ B(SuspendGenerator), R(0), R(0), U8(6), U8(1),
B(ResumeGenerator), R(0), R(0), U8(6),
B(Star4),
B(InvokeIntrinsic), U8(Runtime::k_GeneratorGetResumeMode), R(0), U8(1),
B(Star2),
B(JumpLoop), U8(101), I8(0),
B(LdaNamedProperty), R(1), U8(11), U8(26),
B(Star3),
B(LdaSmi), I8(1),
B(TestReferenceEqual), R(2),
B(JumpIfFalse), U8(5),
B(Ldar), R(3),
B(Return),
B(LdaUndefined),
/* 54 S> */ B(Return),
]
constant pool: [
Smi [20],
Smi [159],
Smi [10],
Smi [7],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["g"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["next"],
Smi [11],
Smi [28],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["return"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["throw"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["done"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["value"],
]
handlers: [
]