Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
yield_position_test.cc
Go to the documentation of this file.
1// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include <utility>
6
10#include "vm/object.h"
11#include "vm/unit_test.h"
12
13namespace dart {
14
16
18 return a->Pos() - b->Pos();
19}
20
22 auto array = new (flow_graph->zone()) YieldPoints();
23 const auto& blocks = flow_graph->reverse_postorder();
24 for (auto block : blocks) {
26 while (!it.Done()) {
27 if (auto suspend_instr = it.Current()->AsSuspend()) {
28 array->Add(suspend_instr->token_pos());
29 }
30 it.Advance();
31 }
32 }
33 array->Sort(LowestFirst);
34 return array;
35}
36
38 auto array = new YieldPoints();
39 const auto& pc_descriptor = PcDescriptors::Handle(code.pc_descriptors());
40 PcDescriptors::Iterator it(pc_descriptor, UntaggedPcDescriptors::kOther);
41 while (it.MoveNext()) {
43 array->Add(it.TokenPos());
44 }
45 }
46 array->Sort(LowestFirst);
47 return array;
48}
49
51 const char* kScript =
52 R"(
53 import 'dart:async';
54
55 Future foo() async {
56 print('pos-0');
57 await 0;
58 print('pos-1');
59 await 1;
60 print('pos-2');
61 await 2;
62 }
63 )";
64
66
67 const auto& root_library = Library::Handle(LoadTestScript(kScript));
68 // Ensure the outer function was compiled once, ensuring we have a closure
69 // function for the inner closure.
70 Invoke(root_library, "foo");
71
72 const auto& function = Function::Handle(GetFunction(root_library, "foo"));
73
74 // Ensure we have 3 different return instructions with yield indices attached
75 // to them.
76 TestPipeline pipeline(function, mode);
77 FlowGraph* flow_graph = pipeline.RunPasses({
78 CompilerPass::kComputeSSA,
79 });
80
81 auto validate_indices = [](const YieldPoints& yield_points) {
82 EXPECT_EQ(3, yield_points.length());
83
84 EXPECT_EQ(88, yield_points[0].Pos());
85 EXPECT_EQ(129, yield_points[1].Pos());
86 EXPECT_EQ(170, yield_points[2].Pos());
87 };
88
89 validate_indices(*GetYieldPointsFromGraph(flow_graph));
90
91 // Ensure we have 3 different yield indices attached to the code via pc
92 // descriptors.
96 const auto& code = Code::Handle(function.CurrentCode());
97 validate_indices(*GetYieldPointsFromCode(code));
98}
99
100ISOLATE_UNIT_TEST_CASE(IRTest_YieldIndexAvailableJIT) {
102}
103
104ISOLATE_UNIT_TEST_CASE(IRTest_YieldIndexAvailableAOT) {
106}
107
108} // namespace dart
#define RELEASE_ASSERT(cond)
Definition assert.h:327
static ErrorPtr EnsureUnoptimizedCode(Thread *thread, const Function &function)
Definition compiler.cc:855
const GrowableArray< BlockEntryInstr * > & reverse_postorder() const
Definition flow_graph.h:207
Zone * zone() const
Definition flow_graph.h:261
Instruction * Current() const
Definition il.h:1847
static Object & Handle()
Definition object.h:407
intptr_t YieldIndex() const
Definition object.h:6133
TokenPosition TokenPos() const
Definition object.h:6129
FlowGraph * RunPasses(std::initializer_list< CompilerPass::Id > passes)
static Thread * Current()
Definition thread.h:361
static constexpr intptr_t kInvalidYieldIndex
static bool b
struct MyStruct a[10]
const uint8_t uint32_t uint32_t GError ** error
Dart_NativeFunction function
Definition fuchsia.cc:51
LibraryPtr LoadTestScript(const char *script, Dart_NativeEntryResolver resolver, const char *lib_uri)
ZoneGrowableArray< TokenPosition > YieldPoints
static YieldPoints * GetYieldPointsFromGraph(FlowGraph *flow_graph)
int LowestFirst(const TokenPosition *a, const TokenPosition *b)
ObjectPtr Invoke(const Library &lib, const char *name)
FunctionPtr GetFunction(const Library &lib, const char *name)
static YieldPoints * GetYieldPointsFromCode(const Code &code)
void RunTestInMode(CompilerPass::PipelineMode mode)
void SetupCoreLibrariesForUnitTest()
Definition unit_test.cc:148
#define ISOLATE_UNIT_TEST_CASE(name)
Definition unit_test.h:64