Skip to content

Commit 9ffee69

Browse files
committed
Merge pull request 'Fibers' (dart-lang#16) from fibers into main
Reviewed-on: http://git.local/dependencies/dart/pulls/16
2 parents 1f38b23 + 30746b5 commit 9ffee69

30 files changed

+818
-688
lines changed

runtime/platform/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
#include <stdlib.h>
9090
#include <string.h>
9191
#include <sys/types.h>
92-
92+
#include <functional>
9393
#include <cassert> // For assert() in constant expressions.
9494

9595
#if defined(_WIN32)

runtime/tests/vm/dart/fiber/fiber_test.dart

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ import 'package:expect/expect.dart';
55
var globalState = "";
66

77
void main() {
8-
// testBase();
9-
10-
while (true) {
11-
testClosures();
12-
}
13-
// testRecycle();
8+
testBase();
9+
testClosures();
10+
testRecycle();
1411
}
1512

1613
void testBase() {
@@ -60,51 +57,51 @@ void testClosures() {
6057
);
6158
Expect.equals("after fiber", localState);
6259

63-
// localState = "localState";
64-
// Fiber.launch(
65-
// () {
66-
// Expect.equals("localState", localState);
67-
// localState = "after main fiber";
68-
// Fiber.schedule(Fiber.current());
69-
// Fiber.spawn(
70-
// () {
71-
// Expect.equals("after main fiber", localState);
72-
// localState = "after child fiber";
73-
// Fiber.reschedule();
74-
// Expect.equals("after child fiber after main fiber", localState);
75-
// localState = "finish";
76-
// },
77-
// name: "child",
78-
// );
79-
// Expect.equals("after child fiber", localState);
80-
// localState = "after child fiber after main fiber";
81-
// Fiber.suspend();
82-
// },
83-
// terminate: true,
84-
// );
85-
// Expect.equals("finish", localState);
60+
localState = "localState";
61+
Fiber.launch(
62+
() {
63+
Expect.equals("localState", localState);
64+
localState = "after main fiber";
65+
Fiber.schedule(Fiber.current());
66+
Fiber.spawn(
67+
() {
68+
Expect.equals("after main fiber", localState);
69+
localState = "after child fiber";
70+
Fiber.reschedule();
71+
Expect.equals("after child fiber after main fiber", localState);
72+
localState = "finish";
73+
},
74+
name: "child",
75+
);
76+
Expect.equals("after child fiber", localState);
77+
localState = "after child fiber after main fiber";
78+
Fiber.suspend();
79+
},
80+
terminate: true,
81+
);
82+
Expect.equals("finish", localState);
8683

87-
// localState = "level 1";
88-
// Fiber.launch(
89-
// () {
90-
// Expect.equals("level 1", localState);
91-
// localState = "level 2";
92-
// Fiber.spawn(
93-
// () {
94-
// Expect.equals("level 2", localState);
95-
// localState = "level 3";
96-
// Fiber.spawn(
97-
// () {
98-
// Expect.equals("level 3", localState);
99-
// localState = "level 4";
100-
// },
101-
// name: "child",
102-
// );
103-
// },
104-
// name: "child",
105-
// );
106-
// },
107-
// terminate: true,
108-
// );
109-
// Expect.equals("level 4", localState);
84+
localState = "level 1";
85+
Fiber.launch(
86+
() {
87+
Expect.equals("level 1", localState);
88+
localState = "level 2";
89+
Fiber.spawn(
90+
() {
91+
Expect.equals("level 2", localState);
92+
localState = "level 3";
93+
Fiber.spawn(
94+
() {
95+
Expect.equals("level 3", localState);
96+
localState = "level 4";
97+
},
98+
name: "child",
99+
);
100+
},
101+
name: "child",
102+
);
103+
},
104+
terminate: true,
105+
);
106+
Expect.equals("level 4", localState);
110107
}

runtime/vm/compiler/backend/il.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8614,8 +8614,7 @@ void CoroutineTransferInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
86148614
__ LoadFieldFromOffset(SPREG, kToCoroutine, Coroutine::stack_base_offset());
86158615
__ PopRegister(FPREG);
86168616
if (!FLAG_precompiled_mode) __ RestoreCodePointer();
8617-
if (FLAG_precompiled_mode)
8618-
__ movq(PP, compiler::Address(THR, Thread::global_object_pool_offset()));
8617+
if (FLAG_precompiled_mode) __ movq(PP, compiler::Address(THR, Thread::global_object_pool_offset()));
86198618

86208619
__ LoadFieldFromOffset(kToStackLimit, kToCoroutine, Coroutine::overflow_stack_limit_offset());
86218620
__ StoreToOffset(kToCoroutine, THR, Thread::coroutine_offset());

runtime/vm/compiler/backend/range_analysis.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,8 +2836,6 @@ void LoadFieldInstr::InferRange(RangeAnalysis* analysis, Range* range) {
28362836

28372837
case Slot::Kind::kTypedDataBase_length:
28382838
case Slot::Kind::kTypedDataView_offset_in_bytes:
2839-
case Slot::Kind::kCoroutine_attributes:
2840-
case Slot::Kind::kCoroutine_index:
28412839
*range = Range(RangeBoundary::FromConstant(0), RangeBoundary::MaxSmi());
28422840
break;
28432841

runtime/vm/compiler/backend/slot.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,6 @@ bool Slot::IsImmutableLengthSlot() const {
239239
case Slot::Kind::kClosure_hash:
240240
case Slot::Kind::kRecord_shape:
241241
case Slot::Kind::kAbstractType_hash:
242-
case Slot::Kind::kCoroutine_attributes:
243-
case Slot::Kind::kCoroutine_index:
244242
return false;
245243
}
246244
UNREACHABLE();

runtime/vm/compiler/backend/slot.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ class ParsedFunction;
125125
V(Record, UntaggedRecord, shape, Smi, FINAL) \
126126
V(TypeArguments, UntaggedTypeArguments, hash, Smi, VAR) \
127127
V(TypeArguments, UntaggedTypeArguments, length, Smi, FINAL) \
128-
V(AbstractType, UntaggedTypeArguments, hash, Smi, VAR) \
129-
V(Coroutine, UntaggedCoroutine, index, Smi, VAR) \
130-
V(Coroutine, UntaggedCoroutine, attributes, Smi, VAR)
128+
V(AbstractType, UntaggedTypeArguments, hash, Smi, VAR)
131129

132130
// The list of slots that correspond to non-nullable boxed fields of native
133131
// Dart objects that do not contain integers in the following format:
@@ -189,7 +187,9 @@ class ParsedFunction;
189187
FINAL) \
190188
V(FunctionType, UntaggedFunctionType, packed_type_parameter_counts, Uint16, \
191189
FINAL) \
192-
V(SubtypeTestCache, UntaggedSubtypeTestCache, num_inputs, Uint32, FINAL)
190+
V(SubtypeTestCache, UntaggedSubtypeTestCache, num_inputs, Uint32, FINAL) \
191+
V(Coroutine, UntaggedCoroutine, index, IntPtr, VAR) \
192+
V(Coroutine, UntaggedCoroutine, attributes, IntPtr, VAR)
193193

194194
// Native slots containing untagged addresses that do not exist in JIT mode.
195195
// See UNTAGGED_NATIVE_DART_SLOTS_LIST for the format.

runtime/vm/compiler/frontend/kernel_to_il.cc

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,13 +926,11 @@ const Function& TypedListGetNativeFunction(Thread* thread, classid_t cid) {
926926
V(Coroutine_getEntry, Coroutine_entry) \
927927
V(Coroutine_getTrampoline, Coroutine_trampoline) \
928928
V(Coroutine_getArguments, Coroutine_arguments) \
929-
V(Coroutine_getAttributes, Coroutine_attributes) \
930929
V(Coroutine_getCaller, Coroutine_caller) \
931930
V(Coroutine_getScheduler, Coroutine_scheduler) \
932931
V(Coroutine_getProcessor, Coroutine_processor) \
933932
V(Coroutine_getToProcessorNext, Coroutine_to_processor_next) \
934933
V(Coroutine_getToProcessorPrevious, Coroutine_to_processor_previous) \
935-
V(Coroutine_getIndex, Coroutine_index) \
936934
V(SuspendState_getThenCallback, SuspendState_then_callback) \
937935
V(SuspendState_getErrorCallback, SuspendState_error_callback) \
938936
V(TypedDataViewOffsetInBytes, TypedDataView_offset_in_bytes) \
@@ -958,7 +956,6 @@ const Function& TypedListGetNativeFunction(Thread* thread, classid_t cid) {
958956
V(Coroutine_setEntry, Coroutine_entry) \
959957
V(Coroutine_setTrampoline, Coroutine_trampoline) \
960958
V(Coroutine_setArguments, Coroutine_arguments) \
961-
V(Coroutine_setAttributes, Coroutine_attributes) \
962959
V(Coroutine_setCaller, Coroutine_caller) \
963960
V(Coroutine_setScheduler, Coroutine_scheduler) \
964961
V(Coroutine_setProcessor, Coroutine_processor) \
@@ -1165,6 +1162,9 @@ bool FlowGraphBuilder::IsRecognizedMethodForFlowGraph(
11651162
case MethodRecognizer::kCoroutineTransfer:
11661163
case MethodRecognizer::kCoroutine_getCurrent:
11671164
case MethodRecognizer::kCoroutine_atIndex:
1165+
case MethodRecognizer::kCoroutine_getAttributes:
1166+
case MethodRecognizer::kCoroutine_setAttributes:
1167+
case MethodRecognizer::kCoroutine_getIndex:
11681168
return true;
11691169
default:
11701170
return false;
@@ -1969,6 +1969,26 @@ FlowGraph* FlowGraphBuilder::BuildGraphOfRecognizedMethod(
19691969
body += LoadIndexed(kArrayCid);
19701970
break;
19711971
}
1972+
case MethodRecognizer::kCoroutine_getIndex: {
1973+
body += LoadLocal(parsed_function_->RawParameterVariable(0));
1974+
body += LoadNativeField(Slot::Coroutine_index());
1975+
body += Box(kUnboxedInt64);
1976+
break;
1977+
}
1978+
case MethodRecognizer::kCoroutine_getAttributes: {
1979+
body += LoadLocal(parsed_function_->RawParameterVariable(0));
1980+
body += LoadNativeField(Slot::Coroutine_attributes());
1981+
body += Box(kUnboxedInt64);
1982+
break;
1983+
}
1984+
case MethodRecognizer::kCoroutine_setAttributes: {
1985+
body += LoadLocal(parsed_function_->RawParameterVariable(0));
1986+
body += LoadLocal(parsed_function_->RawParameterVariable(1));
1987+
body += UnboxTruncate(kUnboxedInt64);
1988+
body += StoreNativeField(Slot::Coroutine_attributes());
1989+
body += NullConstant();
1990+
break;
1991+
}
19721992
#define IL_BODY(method, slot) \
19731993
case MethodRecognizer::k##method: \
19741994
ASSERT_EQUAL(function.NumParameters(), 1); \

0 commit comments

Comments
 (0)