Skip to content

Commit 7df9a5a

Browse files
committed
Merge pull request 'fibers' (#2) from fibers into main
Reviewed-on: http://git.local/dependencies/dart/pulls/2
2 parents f30b97e + 09fa1e9 commit 7df9a5a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+6756
-3762
lines changed

build-sdk-debug.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
./tools/build.py -m debug -a x64 runtime dart_precompiled_runtime create_common_sdk create_platform_sdk
2+
./tools/build.py -m debug -a x64 runtime dart_precompiled_runtime ddc dartanalyzer analysis_server create_common_sdk create_platform_sdk

dart.S

-1
This file was deleted.

runtime/lib/fiber.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
#include "vm/tagged_pointer.h"
1111

1212
namespace dart {
13-
DEFINE_NATIVE_ENTRY(Coroutine_factory, 0, 2) {
13+
DEFINE_NATIVE_ENTRY(Coroutine_factory, 0, 3) {
1414
GET_NON_NULL_NATIVE_ARGUMENT(Smi, stack, arguments->NativeArgAt(1));
15-
return Coroutine::New(stack.Value());
15+
GET_NON_NULL_NATIVE_ARGUMENT(Closure, entry, arguments->NativeArgAt(2));
16+
return Coroutine::New(stack.Value(), Function::Handle(entry.function()).ptr());
1617
}
1718
} // namespace dart

runtime/lib/object.cc

+4
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ DEFINE_NATIVE_ENTRY(Fiber_coroutineTransfer, 0, 2) {
326326
UNREACHABLE();
327327
}
328328

329+
DEFINE_NATIVE_ENTRY(Fiber_coroutineFork, 0, 2) {
330+
UNREACHABLE();
331+
}
332+
329333

330334
DEFINE_NATIVE_ENTRY(Internal_collectAllGarbage, 0, 0) {
331335
isolate->group()->heap()->CollectAllGarbage(GCReason::kDebugging,

runtime/vm/BUILD.gn

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import("//build_overrides/build.gni")
66
import("//third_party/protobuf/proto_library.gni")
77
import("../../build/executable_suffix.gni")
88
import("../../sdk/lib/async/async_sources.gni")
9-
import("../../sdk/lib/fiber/fiber_sources.gni")
109
import("../../sdk/lib/collection/collection_sources.gni")
1110
import("../../sdk/lib/convert/convert_sources.gni")
1211
import("../../sdk/lib/core/core_sources.gni")
1312
import("../../sdk/lib/developer/developer_sources.gni")
1413
import("../../sdk/lib/ffi/ffi_sources.gni")
14+
import("../../sdk/lib/fiber/fiber_sources.gni")
1515
import("../../sdk/lib/internal/internal_sources.gni")
1616
import("../../sdk/lib/isolate/isolate_sources.gni")
1717
import("../../sdk/lib/math/math_sources.gni")
@@ -24,11 +24,11 @@ import("../bin/cli_sources.gni")
2424
import("../bin/io_sources.gni")
2525
import("../configs.gni")
2626
import("../lib/async_sources.gni")
27-
import("../lib/fiber_sources.gni")
2827
import("../lib/convert_sources.gni")
2928
import("../lib/core_sources.gni")
3029
import("../lib/developer_sources.gni")
3130
import("../lib/ffi_sources.gni")
31+
import("../lib/fiber_sources.gni")
3232
import("../lib/isolate_sources.gni")
3333
import("../lib/math_sources.gni")
3434
import("../lib/mirrors_sources.gni")
@@ -227,11 +227,11 @@ library_for_all_configs("libdart_lib") {
227227
extra_deps += [ "$fuchsia_sdk/pkg/trace-engine" ]
228228
}
229229
include_dirs = [ ".." ]
230-
allsources = async_runtime_cc_files + fiber_runtime_cc_files +
231-
core_runtime_cc_files + developer_runtime_cc_files +
232-
isolate_runtime_cc_files + math_runtime_cc_files +
233-
mirrors_runtime_cc_files + typed_data_runtime_cc_files +
234-
vmservice_runtime_cc_files + ffi_runtime_cc_files
230+
allsources = async_runtime_cc_files + core_runtime_cc_files +
231+
developer_runtime_cc_files + isolate_runtime_cc_files +
232+
math_runtime_cc_files + mirrors_runtime_cc_files +
233+
typed_data_runtime_cc_files + vmservice_runtime_cc_files +
234+
ffi_runtime_cc_files + fiber_runtime_cc_files
235235
sources = [ "bootstrap.cc" ] + rebase_path(allsources, ".", "../lib")
236236
snapshot_sources = []
237237
}

runtime/vm/app_snapshot.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -9455,7 +9455,7 @@ void Deserializer::ReadInstructions(CodePtr code, bool deferred) {
94559455
instr = image_reader_->GetInstructionsAt(active_offset);
94569456
unchecked_offset = ReadUnsigned();
94579457
code->untag()->active_instructions_ = instr;
9458-
Code::InitializeCachedEntryPointsFrom(code, instr, unchecked_offset);
9458+
Code::InitializeCachedEntryPointsFrom(code, instr, unchecked_offset);
94599459
#endif // defined(DART_PRECOMPILED_RUNTIME)
94609460
}
94619461

runtime/vm/bootstrap_natives.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ namespace dart {
264264
V(Internal_nativeEffect, 1) \
265265
V(Fiber_coroutineInitialize, 1) \
266266
V(Fiber_coroutineTransfer, 2) \
267+
V(Fiber_coroutineFork, 2) \
267268
V(Internal_collectAllGarbage, 0) \
268269
V(Internal_makeListFixedLength, 1) \
269270
V(Internal_makeFixedListUnmodifiable, 1) \
@@ -315,7 +316,7 @@ namespace dart {
315316
V(DartNativeApiFunctionPointer, 1) \
316317
V(TransferableTypedData_factory, 2) \
317318
V(TransferableTypedData_materialize, 1) \
318-
V(Coroutine_factory, 2)
319+
V(Coroutine_factory, 3)
319320

320321
// List of bootstrap native entry points used in the dart:mirror library.
321322
#define MIRRORS_BOOTSTRAP_NATIVE_LIST(V) \

runtime/vm/compiler/backend/constant_propagator.cc

+3
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,9 @@ void ConstantPropagator::VisitCoroutineTransferStub(CoroutineTransferStubInstr*
15731573
SetValue(instr, non_constant_);
15741574
}
15751575

1576+
void ConstantPropagator::VisitCoroutineForkStub(CoroutineForkStubInstr* instr) {
1577+
}
1578+
15761579
void ConstantPropagator::VisitSuspend(SuspendInstr* instr) {
15771580
SetValue(instr, non_constant_);
15781581
}

runtime/vm/compiler/backend/flow_graph.cc

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <array>
88

9+
#include "platform/text_buffer.h"
910
#include "vm/bit_vector.h"
1011
#include "vm/compiler/backend/dart_calling_conventions.h"
1112
#include "vm/compiler/backend/flow_graph_compiler.h"

runtime/vm/compiler/backend/il.cc

+20-26
Original file line numberDiff line numberDiff line change
@@ -8557,27 +8557,15 @@ LocationSummary* CoroutineInitializeStubInstr::MakeLocationSummary(
85578557
const intptr_t kNumInputs = 1;
85588558
const intptr_t kNumTemps = 0;
85598559
LocationSummary* locs = new (zone) LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall);
8560-
locs->set_in(0, Location::RegisterLocation(CoroutineInitializeStubABI::kFromCoroutineReg));
8560+
locs->set_in(0, Location::RegisterLocation(CoroutineInitializeStubABI::kCoroutineReg));
85618561
return locs;
85628562
}
85638563

85648564
void CoroutineInitializeStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
85658565
ObjectStore* object_store = compiler->isolate_group()->object_store();
85668566
Code& stub = Code::ZoneHandle(compiler->zone());
85678567
stub = object_store->coroutine_initialize_stub();
8568-
__ PushRegister(FPREG);
8569-
__ PushRegister(THR);
8570-
__ PushRegister(TMP);
8571-
__ PushRegister(PP);
8572-
__ PushRegister(CODE_REG);
8573-
__ LoadFieldFromOffset(CoroutineTransferStubABI::kFromContextReg, CoroutineTransferStubABI::kFromCoroutineReg, compiler::target::Coroutine::context_offset());
8574-
__ StoreToOffset(SPREG, CoroutineTransferStubABI::kFromContextReg, CoroutineTransferStubABI::kContextSpOffset);
8575-
compiler->GenerateStubCall(source(), stub, UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
8576-
__ PopRegister(CODE_REG);
8577-
__ PopRegister(PP);
8578-
__ PopRegister(TMP);
8579-
__ PopRegister(THR);
8580-
__ PopRegister(FPREG);
8568+
compiler->GenerateStubCall(source(), stub, UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
85818569
}
85828570

85838571
LocationSummary* CoroutineTransferStubInstr::MakeLocationSummary(
@@ -8595,19 +8583,25 @@ void CoroutineTransferStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
85958583
ObjectStore* object_store = compiler->isolate_group()->object_store();
85968584
Code& stub = Code::ZoneHandle(compiler->zone());
85978585
stub = object_store->coroutine_transfer_stub();
8598-
__ PushRegister(FPREG);
8599-
__ PushRegister(THR);
8600-
__ PushRegister(TMP);
8601-
__ PushRegister(PP);
8602-
__ PushRegister(CODE_REG);
8603-
__ LoadFieldFromOffset(CoroutineTransferStubABI::kFromContextReg, CoroutineTransferStubABI::kFromCoroutineReg, compiler::target::Coroutine::context_offset());
8604-
__ StoreToOffset(SPREG, CoroutineTransferStubABI::kFromContextReg, CoroutineTransferStubABI::kContextSpOffset);
86058586
compiler->GenerateStubCall(source(), stub, UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
8606-
__ PopRegister(CODE_REG);
8607-
__ PopRegister(PP);
8608-
__ PopRegister(TMP);
8609-
__ PopRegister(THR);
8610-
__ PopRegister(FPREG);
8587+
}
8588+
8589+
LocationSummary* CoroutineForkStubInstr::MakeLocationSummary(
8590+
Zone* zone,
8591+
bool opt) const {
8592+
const intptr_t kNumInputs = 2;
8593+
const intptr_t kNumTemps = 0;
8594+
LocationSummary* locs = new (zone) LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall);
8595+
locs->set_in(0, Location::RegisterLocation(CoroutineForkStubABI::kCallerCoroutineReg));
8596+
locs->set_in(1, Location::RegisterLocation(CoroutineForkStubABI::kForkedCoroutineReg));
8597+
return locs;
8598+
}
8599+
8600+
void CoroutineForkStubInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
8601+
ObjectStore* object_store = compiler->isolate_group()->object_store();
8602+
Code& stub = Code::ZoneHandle(compiler->zone());
8603+
stub = object_store->coroutine_fork_stub();
8604+
compiler->GenerateStubCall(source(), stub, UntaggedPcDescriptors::kOther, locs(), deopt_id(), env());
86118605
}
86128606

86138607
Definition* SuspendInstr::Canonicalize(FlowGraph* flow_graph) {

runtime/vm/compiler/backend/il.h

+37-25
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ struct InstrAttrs {
547547
M(Call1ArgStub, _) \
548548
M(CoroutineInitializeStub, _) \
549549
M(CoroutineTransferStub, _) \
550+
M(CoroutineForkStub, _) \
550551
M(LoadThread, kNoGC) \
551552
M(Deoptimize, kNoGC) \
552553
M(SimdOp, kNoGC) \
@@ -11477,16 +11478,13 @@ class Call1ArgStubInstr : public TemplateDefinition<1, Throws> {
1147711478

1147811479
class CoroutineInitializeStubInstr : public TemplateDefinition<1, NoThrow> {
1147911480
public:
11480-
CoroutineInitializeStubInstr(const InstructionSource& source,
11481-
Value* root,
11482-
intptr_t deopt_id)
11483-
: TemplateDefinition(source, deopt_id), token_pos_(source.token_pos) {
11481+
CoroutineInitializeStubInstr(Value* root, intptr_t deopt_id)
11482+
: TemplateDefinition(InstructionSource(TokenPosition::kNoSource),
11483+
deopt_id) {
1148411484
SetInputAt(0, root);
1148511485
}
1148611486

1148711487
Value* root() const { return inputs_[0]; }
11488-
virtual TokenPosition token_pos() const { return token_pos_; }
11489-
1149011488
virtual bool CanCallDart() const { return true; }
1149111489
virtual bool ComputeCanDeoptimize() const { return false; }
1149211490
virtual bool ComputeCanDeoptimizeAfterCall() const { return true; }
@@ -11497,32 +11495,23 @@ class CoroutineInitializeStubInstr : public TemplateDefinition<1, NoThrow> {
1149711495

1149811496
DECLARE_INSTRUCTION(CoroutineInitializeStub);
1149911497
PRINT_OPERANDS_TO_SUPPORT
11500-
11501-
#define FIELD_LIST(F) F(const TokenPosition, token_pos_)
11502-
11503-
DECLARE_INSTRUCTION_SERIALIZABLE_FIELDS(CoroutineInitializeStubInstr,
11504-
TemplateDefinition,
11505-
FIELD_LIST)
11506-
#undef FIELD_LIST
11498+
DECLARE_EMPTY_SERIALIZATION(CoroutineInitializeStubInstr, TemplateDefinition)
1150711499

1150811500
private:
1150911501
DISALLOW_COPY_AND_ASSIGN(CoroutineInitializeStubInstr);
1151011502
};
1151111503

1151211504
class CoroutineTransferStubInstr : public TemplateDefinition<2, NoThrow> {
1151311505
public:
11514-
CoroutineTransferStubInstr(const InstructionSource& source,
11515-
Value* from,
11516-
Value* to,
11517-
intptr_t deopt_id)
11518-
: TemplateDefinition(source, deopt_id), token_pos_(source.token_pos) {
11506+
CoroutineTransferStubInstr(Value* from, Value* to, intptr_t deopt_id)
11507+
: TemplateDefinition(InstructionSource(TokenPosition::kNoSource),
11508+
deopt_id) {
1151911509
SetInputAt(0, from);
1152011510
SetInputAt(1, to);
1152111511
}
1152211512

1152311513
Value* from() const { return inputs_[0]; }
1152411514
Value* to() const { return inputs_[1]; }
11525-
virtual TokenPosition token_pos() const { return token_pos_; }
1152611515

1152711516
virtual bool CanCallDart() const { return true; }
1152811517
virtual bool ComputeCanDeoptimize() const { return false; }
@@ -11534,16 +11523,39 @@ class CoroutineTransferStubInstr : public TemplateDefinition<2, NoThrow> {
1153411523

1153511524
DECLARE_INSTRUCTION(CoroutineTransferStub);
1153611525
PRINT_OPERANDS_TO_SUPPORT
11526+
DECLARE_EMPTY_SERIALIZATION(CoroutineTransferStubInstr, TemplateDefinition)
1153711527

11538-
#define FIELD_LIST(F) F(const TokenPosition, token_pos_)
11528+
private:
11529+
DISALLOW_COPY_AND_ASSIGN(CoroutineTransferStubInstr);
11530+
};
1153911531

11540-
DECLARE_INSTRUCTION_SERIALIZABLE_FIELDS(CoroutineTransferStubInstr,
11541-
TemplateDefinition,
11542-
FIELD_LIST)
11543-
#undef FIELD_LIST
11532+
class CoroutineForkStubInstr : public TemplateDefinition<2, NoThrow> {
11533+
public:
11534+
CoroutineForkStubInstr(Value* from, Value* to, intptr_t deopt_id)
11535+
: TemplateDefinition(InstructionSource(TokenPosition::kNoSource),
11536+
deopt_id) {
11537+
SetInputAt(0, from);
11538+
SetInputAt(1, to);
11539+
}
11540+
11541+
Value* from() const { return inputs_[0]; }
11542+
Value* to() const { return inputs_[1]; }
11543+
11544+
virtual bool CanCallDart() const { return true; }
11545+
virtual bool ComputeCanDeoptimize() const { return false; }
11546+
virtual bool ComputeCanDeoptimizeAfterCall() const { return true; }
11547+
virtual bool HasUnknownSideEffects() const { return true; }
11548+
virtual intptr_t NumberOfInputsConsumedBeforeCall() const {
11549+
return InputCount();
11550+
}
11551+
11552+
DECLARE_INSTRUCTION(CoroutineForkStub);
11553+
PRINT_OPERANDS_TO_SUPPORT
11554+
11555+
DECLARE_EMPTY_SERIALIZATION(CoroutineForkStubInstr, TemplateDefinition)
1154411556

1154511557
private:
11546-
DISALLOW_COPY_AND_ASSIGN(CoroutineTransferStubInstr);
11558+
DISALLOW_COPY_AND_ASSIGN(CoroutineForkStubInstr);
1154711559
};
1154811560

1154911561
// Suspends execution using the suspend stub specified using [StubId].

runtime/vm/compiler/backend/il_printer.cc

+8
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,14 @@ void CoroutineTransferStubInstr::PrintOperandsTo(BaseTextBuffer* f) const {
15911591
f->AddString(")");
15921592
}
15931593

1594+
void CoroutineForkStubInstr::PrintOperandsTo(BaseTextBuffer* f) const {
1595+
const char* name = "CoroutineFork";
1596+
f->Printf("%s(", name);
1597+
from()->PrintTo(f);
1598+
to()->PrintTo(f);
1599+
f->AddString(")");
1600+
}
1601+
15941602
void SuspendInstr::PrintOperandsTo(BaseTextBuffer* f) const {
15951603
const char* name = "";
15961604
switch (stub_id_) {

runtime/vm/compiler/backend/slot.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ class ParsedFunction;
8484
V(WeakProperty, UntaggedWeakProperty, key, Dynamic, WEAK) \
8585
V(WeakProperty, UntaggedWeakProperty, value, Dynamic, WEAK) \
8686
V(WeakReference, UntaggedWeakReference, target, Dynamic, WEAK) \
87-
V(WeakReference, UntaggedWeakReference, type_arguments, TypeArguments, FINAL)
87+
V(WeakReference, UntaggedWeakReference, type_arguments, TypeArguments, FINAL)\
88+
V(Coroutine, UntaggedCoroutine, caller, Coroutine, VAR) \
89+
V(Coroutine, UntaggedCoroutine, entry, Coroutine, VAR) \
8890

8991
// The list of slots that correspond to non-nullable boxed fields of native
9092
// Dart objects that contain integers in the following format:

runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc

+36-6
Original file line numberDiff line numberDiff line change
@@ -3375,6 +3375,8 @@ Fragment StreamingFlowGraphBuilder::BuildStaticInvocation(TokenPosition* p) {
33753375
return BuildCoroutineInitialize();
33763376
case MethodRecognizer::kCoroutineTransfer:
33773377
return BuildCoroutineTransfer();
3378+
case MethodRecognizer::kCoroutineFork:
3379+
return BuildCoroutineFork();
33783380
case MethodRecognizer::kNativeEffect:
33793381
return BuildNativeEffect();
33803382
case MethodRecognizer::kReachabilityFence:
@@ -6020,22 +6022,50 @@ Fragment StreamingFlowGraphBuilder::BuildNativeEffect() {
60206022

60216023
Fragment StreamingFlowGraphBuilder::BuildCoroutineInitialize() {
60226024
Fragment instructions;
6023-
Array& argument_names = Array::ZoneHandle(Z);
6024-
instructions += BuildArguments(&argument_names, nullptr /* arg count */, nullptr /* positional arg count */);
6025+
ReadUInt();
6026+
ReadListLength();
6027+
ReadListLength();
6028+
instructions += BuildExpression();
6029+
ReadListLength();
60256030
instructions += B->CoroutineInitialize(TokenPosition::kNoSource);
6026-
instructions += NullConstant();
60276031
return instructions;
60286032
}
60296033

60306034
Fragment StreamingFlowGraphBuilder::BuildCoroutineTransfer() {
60316035
Fragment instructions;
6032-
Array& argument_names = Array::ZoneHandle(Z);
6033-
instructions += BuildArguments(&argument_names, nullptr /* arg count */, nullptr /* positional arg count */);
6036+
ReadUInt();
6037+
ReadListLength();
6038+
ReadListLength();
6039+
instructions += BuildExpression();
6040+
LocalVariable* from = MakeTemporary();
6041+
instructions += LoadLocal(from);
6042+
instructions += BuildExpression();
6043+
LocalVariable* to = MakeTemporary();
6044+
instructions += LoadLocal(to);
6045+
ReadListLength();
60346046
instructions += B->CoroutineTransfer(TokenPosition::kNoSource);
6035-
instructions += NullConstant();
6047+
instructions += Drop();
6048+
instructions += Drop();
60366049
return instructions;
60376050
}
60386051

6052+
Fragment StreamingFlowGraphBuilder::BuildCoroutineFork() {
6053+
Fragment instructions;
6054+
ReadUInt();
6055+
ReadListLength();
6056+
ReadListLength();
6057+
instructions += BuildExpression();
6058+
LocalVariable* from = MakeTemporary();
6059+
instructions += LoadLocal(from);
6060+
instructions += BuildExpression();
6061+
LocalVariable* to = MakeTemporary();
6062+
instructions += LoadLocal(to);
6063+
ReadListLength();
6064+
instructions += B->CoroutineFork(TokenPosition::kNoSource);
6065+
instructions += Drop();
6066+
instructions += Drop();
6067+
return instructions;
6068+
}
60396069

60406070
Fragment StreamingFlowGraphBuilder::BuildReachabilityFence() {
60416071
const intptr_t argc = ReadUInt(); // Read argument count.

runtime/vm/compiler/frontend/kernel_binary_flowgraph.h

+2
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ class StreamingFlowGraphBuilder : public KernelReaderHelper {
380380

381381
Fragment BuildCoroutineTransfer();
382382

383+
Fragment BuildCoroutineFork();
384+
383385
// Build the call-site manually, to avoid doing initialization checks
384386
// for late fields.
385387
Fragment BuildReachabilityFence();

0 commit comments

Comments
 (0)