v8/test/cctest/interpreter/bytecode_expectations/StandardForLoop.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

475 lines
14 KiB
Plaintext

#
# Autogenerated by generate-bytecode-expectations.
#
---
wrap: no
test function name: f
---
snippet: "
function f() {
for (let x = 0; x < 10; ++x) { let y = x; }
}
f();
"
frame size: 2
parameter count: 1
bytecode array length: 22
bytecodes: [
/* 30 S> */ B(LdaZero),
B(Star0),
/* 35 S> */ B(LdaSmi), I8(10),
/* 35 E> */ B(TestLessThan), R(0), U8(0),
B(JumpIfFalse), U8(13),
/* 56 S> */ B(Mov), R(0), R(1),
/* 43 S> */ B(Ldar), R(1),
B(Inc), U8(1),
B(Star0),
/* 17 E> */ B(JumpLoop), U8(15), I8(0),
B(LdaUndefined),
/* 61 S> */ B(Return),
]
constant pool: [
]
handlers: [
]
---
snippet: "
function f() {
for (let x = 0; x < 10; ++x) { eval('1'); }
}
f();
"
frame size: 15
parameter count: 1
bytecode array length: 149
bytecodes: [
/* 10 E> */ B(CreateFunctionContext), U8(0), U8(4),
B(PushContext), R(4),
B(Ldar), R(this),
B(StaCurrentContextSlot), U8(3),
B(CreateMappedArguments),
B(StaCurrentContextSlot), U8(5),
B(Ldar), R(3),
B(StaCurrentContextSlot), U8(4),
B(CreateBlockContext), U8(1),
B(PushContext), R(5),
B(LdaTheHole),
B(StaCurrentContextSlot), U8(2),
/* 30 S> */ B(LdaZero),
/* 30 E> */ B(StaCurrentContextSlot), U8(2),
B(LdaCurrentContextSlot), U8(2),
B(Star0),
B(LdaSmi), I8(1),
B(Star1),
/* 59 E> */ B(CreateBlockContext), U8(2),
B(PushContext), R(6),
B(LdaTheHole),
B(StaCurrentContextSlot), U8(2),
B(Ldar), R(0),
B(StaCurrentContextSlot), U8(2),
B(LdaSmi), I8(1),
B(TestEqual), R(1), U8(0),
B(JumpIfFalse), U8(6),
B(LdaZero),
B(Star1),
B(Jump), U8(8),
/* 43 S> */ B(LdaCurrentContextSlot), U8(2),
B(Inc), U8(1),
/* 43 E> */ B(StaCurrentContextSlot), U8(2),
B(LdaSmi), I8(1),
B(Star2),
/* 35 S> */ B(LdaCurrentContextSlot), U8(2),
B(Star7),
B(LdaSmi), I8(10),
/* 35 E> */ B(TestLessThan), R(7), U8(2),
B(JumpIfFalse), U8(4),
B(Jump), U8(6),
B(PopContext), R(6),
B(Jump), U8(68),
B(LdaSmi), I8(1),
B(TestEqual), R(2), U8(3),
B(JumpIfFalse), U8(45),
/* 48 S> */ B(LdaLookupGlobalSlot), U8(3), U8(4), U8(3),
B(Star7),
B(LdaConstant), U8(4),
B(Star8),
B(LdaZero),
B(Star12),
B(LdaSmi), I8(31),
B(Star13),
B(LdaSmi), I8(48),
B(Star14),
B(Mov), R(7), R(9),
B(Mov), R(8), R(10),
B(Mov), R(closure), R(11),
B(CallRuntime), U16(Runtime::kResolvePossiblyDirectEval), R(9), U8(6),
B(Star7),
/* 48 E> */ B(CallUndefinedReceiver1), R(7), R(8), U8(6),
B(LdaZero),
B(Star2),
B(LdaCurrentContextSlot), U8(2),
B(Star0),
/* 17 E> */ B(JumpLoop), U8(47), I8(1),
B(LdaSmi), I8(1),
B(TestEqual), R(2), U8(8),
B(JumpIfFalse), U8(6),
B(PopContext), R(6),
B(Jump), U8(7),
B(PopContext), R(6),
B(JumpLoop), U8(110), I8(0),
B(PopContext), R(5),
B(LdaUndefined),
/* 61 S> */ B(Return),
]
constant pool: [
SCOPE_INFO_TYPE,
SCOPE_INFO_TYPE,
SCOPE_INFO_TYPE,
ONE_BYTE_INTERNALIZED_STRING_TYPE ["eval"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["1"],
]
handlers: [
]
---
snippet: "
function f() {
for (let x = 0; x < 10; ++x) { (function() { return x; })(); }
}
f();
"
frame size: 6
parameter count: 1
bytecode array length: 94
bytecodes: [
/* 30 S> */ B(LdaZero),
B(Star3),
B(Star0),
B(LdaSmi), I8(1),
B(Star1),
/* 78 E> */ B(CreateBlockContext), U8(0),
B(PushContext), R(4),
B(LdaTheHole),
B(StaCurrentContextSlot), U8(2),
B(Ldar), R(0),
B(StaCurrentContextSlot), U8(2),
B(LdaSmi), I8(1),
B(TestEqual), R(1), U8(0),
B(JumpIfFalse), U8(6),
B(LdaZero),
B(Star1),
B(Jump), U8(8),
/* 43 S> */ B(LdaCurrentContextSlot), U8(2),
B(Inc), U8(1),
/* 43 E> */ B(StaCurrentContextSlot), U8(2),
B(LdaSmi), I8(1),
B(Star2),
/* 35 S> */ B(LdaCurrentContextSlot), U8(2),
B(Star5),
B(LdaSmi), I8(10),
/* 35 E> */ B(TestLessThan), R(5), U8(2),
B(JumpIfFalse), U8(4),
B(Jump), U8(6),
B(PopContext), R(4),
B(Jump), U8(41),
B(LdaSmi), I8(1),
B(TestEqual), R(2), U8(3),
B(JumpIfFalse), U8(18),
/* 48 S> */ B(CreateClosure), U8(1), U8(0), U8(2),
B(Star5),
/* 74 E> */ B(CallUndefinedReceiver0), R(5), U8(4),
B(LdaZero),
B(Star2),
B(LdaCurrentContextSlot), U8(2),
B(Star0),
/* 17 E> */ B(JumpLoop), U8(20), I8(1),
B(LdaSmi), I8(1),
B(TestEqual), R(2), U8(6),
B(JumpIfFalse), U8(6),
B(PopContext), R(4),
B(Jump), U8(7),
B(PopContext), R(4),
B(JumpLoop), U8(83), I8(0),
B(LdaUndefined),
/* 80 S> */ B(Return),
]
constant pool: [
SCOPE_INFO_TYPE,
SHARED_FUNCTION_INFO_TYPE,
]
handlers: [
]
---
snippet: "
function f() {
for (let { x, y } = { x: 0, y: 3 }; y > 0; --y) { let z = x + y; }
}
f();
"
frame size: 4
parameter count: 1
bytecode array length: 37
bytecodes: [
/* 37 S> */ B(CreateObjectLiteral), U8(0), U8(0), U8(41),
B(Star3),
/* 28 S> */ B(LdaNamedProperty), R(3), U8(1), U8(1),
B(Star0),
/* 31 S> */ B(LdaNamedProperty), R(3), U8(2), U8(3),
B(Star1),
/* 55 S> */ B(LdaZero),
/* 55 E> */ B(TestGreaterThan), R(1), U8(5),
B(JumpIfFalse), U8(16),
/* 75 S> */ B(Ldar), R(1),
/* 77 E> */ B(Add), R(0), U8(6),
B(Star2),
/* 62 S> */ B(Ldar), R(1),
B(Dec), U8(7),
B(Star1),
/* 17 E> */ B(JumpLoop), U8(17), I8(0),
B(LdaUndefined),
/* 84 S> */ B(Return),
]
constant pool: [
OBJECT_BOILERPLATE_DESCRIPTION_TYPE,
ONE_BYTE_INTERNALIZED_STRING_TYPE ["x"],
ONE_BYTE_INTERNALIZED_STRING_TYPE ["y"],
]
handlers: [
]
---
snippet: "
function* f() {
for (let x = 0; x < 10; ++x) { let y = x; }
}
f();
"
frame size: 5
parameter count: 1
bytecode array length: 61
bytecodes: [
B(SwitchOnGeneratorState), R(0), U8(0), U8(1),
B(Mov), R(closure), R(3),
B(Mov), R(this), R(4),
/* 11 E> */ B(InvokeIntrinsic), U8(Runtime::k_CreateJSGeneratorObject), R(3), U8(2),
B(Star0),
/* 11 E> */ B(SuspendGenerator), R(0), R(0), U8(3), U8(0),
B(ResumeGenerator), R(0), R(0), U8(3),
B(Star3),
B(InvokeIntrinsic), U8(Runtime::k_GeneratorGetResumeMode), R(0), U8(1),
B(SwitchOnSmiNoFeedback), U8(1), U8(2), I8(0),
B(Ldar), R(3),
/* 11 E> */ B(Throw),
B(Ldar), R(3),
B(Return),
/* 31 S> */ B(LdaZero),
B(Star1),
/* 36 S> */ B(LdaSmi), I8(10),
/* 36 E> */ B(TestLessThan), R(1), U8(0),
B(JumpIfFalse), U8(13),
/* 57 S> */ B(Mov), R(1), R(2),
/* 44 S> */ B(Ldar), R(2),
B(Inc), U8(1),
B(Star1),
/* 18 E> */ B(JumpLoop), U8(15), I8(0),
B(LdaUndefined),
/* 62 S> */ B(Return),
]
constant pool: [
Smi [20],
Smi [10],
Smi [7],
]
handlers: [
]
---
snippet: "
function* f() {
for (let x = 0; x < 10; ++x) yield x;
}
f();
"
frame size: 4
parameter count: 1
bytecode array length: 91
bytecodes: [
B(SwitchOnGeneratorState), R(0), U8(0), U8(2),
B(Mov), R(closure), R(2),
B(Mov), R(this), R(3),
/* 11 E> */ B(InvokeIntrinsic), U8(Runtime::k_CreateJSGeneratorObject), R(2), U8(2),
B(Star0),
/* 11 E> */ B(SuspendGenerator), R(0), R(0), U8(2), U8(0),
B(ResumeGenerator), R(0), R(0), U8(2),
B(Star2),
B(InvokeIntrinsic), U8(Runtime::k_GeneratorGetResumeMode), R(0), U8(1),
B(SwitchOnSmiNoFeedback), U8(2), U8(2), I8(0),
B(Ldar), R(2),
/* 11 E> */ B(Throw),
B(Ldar), R(2),
B(Return),
/* 31 S> */ B(LdaZero),
B(Star1),
/* 36 S> */ B(LdaSmi), I8(10),
/* 36 E> */ B(TestLessThan), R(1), U8(0),
B(JumpIfFalse), U8(43),
/* 47 S> */ B(LdaFalse),
B(Star3),
B(Mov), R(1), R(2),
B(InvokeIntrinsic), U8(Runtime::k_CreateIterResultObject), R(2), U8(2),
/* 47 E> */ B(SuspendGenerator), R(0), R(0), U8(2), U8(1),
B(ResumeGenerator), R(0), R(0), U8(2),
B(Star2),
B(InvokeIntrinsic), U8(Runtime::k_GeneratorGetResumeMode), R(0), U8(1),
B(SwitchOnSmiNoFeedback), U8(4), U8(2), I8(0),
B(Ldar), R(2),
/* 47 E> */ B(Throw),
B(Ldar), R(2),
B(Return),
/* 44 S> */ B(Ldar), R(1),
B(Inc), U8(1),
B(Star1),
/* 18 E> */ B(JumpLoop), U8(45), I8(0),
B(LdaUndefined),
/* 56 S> */ B(Return),
]
constant pool: [
Smi [20],
Smi [62],
Smi [10],
Smi [7],
Smi [10],
Smi [7],
]
handlers: [
]
---
snippet: "
async function f() {
for (let x = 0; x < 10; ++x) { let y = x; }
}
f();
"
frame size: 8
parameter count: 1
bytecode array length: 70
bytecodes: [
B(Mov), R(closure), R(3),
B(Mov), R(this), R(4),
/* 16 E> */ B(InvokeIntrinsic), U8(Runtime::k_AsyncFunctionEnter), R(3), U8(2),
B(Star0),
B(Mov), R(context), R(3),
/* 36 S> */ B(LdaZero),
B(Star1),
/* 41 S> */ B(LdaSmi), I8(10),
/* 41 E> */ B(TestLessThan), R(1), U8(0),
B(JumpIfFalse), U8(13),
/* 62 S> */ B(Mov), R(1), R(2),
/* 49 S> */ B(Ldar), R(2),
B(Inc), U8(1),
B(Star1),
/* 23 E> */ B(JumpLoop), U8(15), I8(0),
B(LdaUndefined),
B(Star5),
B(LdaFalse),
B(Star6),
B(Mov), R(0), R(4),
B(InvokeIntrinsic), U8(Runtime::k_AsyncFunctionResolve), R(4), U8(3),
/* 67 S> */ B(Return),
B(Star4),
B(CreateCatchContext), R(4), U8(0),
B(Star3),
B(LdaTheHole),
B(SetPendingMessage),
B(Ldar), R(3),
B(PushContext), R(4),
B(LdaImmutableCurrentContextSlot), U8(2),
B(Star6),
B(LdaFalse),
B(Star7),
B(Mov), R(0), R(5),
B(InvokeIntrinsic), U8(Runtime::k_AsyncFunctionReject), R(5), U8(3),
/* 67 S> */ B(Return),
]
constant pool: [
SCOPE_INFO_TYPE,
]
handlers: [
[14, 46, 46],
]
---
snippet: "
async function f() {
for (let x = 0; x < 10; ++x) await x;
}
f();
"
frame size: 7
parameter count: 1
bytecode array length: 104
bytecodes: [
B(SwitchOnGeneratorState), R(0), U8(0), U8(1),
B(Mov), R(closure), R(2),
B(Mov), R(this), R(3),
/* 16 E> */ B(InvokeIntrinsic), U8(Runtime::k_AsyncFunctionEnter), R(2), U8(2),
B(Star0),
B(Mov), R(context), R(2),
/* 36 S> */ B(LdaZero),
B(Star1),
/* 41 S> */ B(LdaSmi), I8(10),
/* 41 E> */ B(TestLessThan), R(1), U8(0),
B(JumpIfFalse), U8(43),
/* 52 S> */ B(Mov), R(0), R(3),
B(Mov), R(1), R(4),
B(InvokeIntrinsic), U8(Runtime::k_AsyncFunctionAwaitUncaught), R(3), U8(2),
/* 52 E> */ B(SuspendGenerator), R(0), R(0), U8(3), U8(0),
B(ResumeGenerator), R(0), R(0), U8(3),
B(Star3),
B(InvokeIntrinsic), U8(Runtime::k_GeneratorGetResumeMode), R(0), U8(1),
B(Star4),
B(LdaZero),
B(TestReferenceEqual), R(4),
B(JumpIfTrue), U8(5),
B(Ldar), R(3),
B(ReThrow),
/* 49 S> */ B(Ldar), R(1),
B(Inc), U8(1),
B(Star1),
/* 23 E> */ B(JumpLoop), U8(45), I8(0),
B(LdaUndefined),
B(Star4),
B(LdaTrue),
B(Star5),
B(Mov), R(0), R(3),
B(InvokeIntrinsic), U8(Runtime::k_AsyncFunctionResolve), R(3), U8(3),
/* 61 S> */ B(Return),
B(Star3),
B(CreateCatchContext), R(3), U8(1),
B(Star2),
B(LdaTheHole),
B(SetPendingMessage),
B(Ldar), R(2),
B(PushContext), R(3),
B(LdaImmutableCurrentContextSlot), U8(2),
B(Star5),
B(LdaTrue),
B(Star6),
B(Mov), R(0), R(4),
B(InvokeIntrinsic), U8(Runtime::k_AsyncFunctionReject), R(4), U8(3),
/* 61 S> */ B(Return),
]
constant pool: [
Smi [42],
SCOPE_INFO_TYPE,
]
handlers: [
[18, 80, 80],
]