Skip to content

Commit 94ae6c9

Browse files
authored
Merge pull request #2507 from swiftwasm/main
[pull] swiftwasm from main
2 parents 7f03e1c + d121d7d commit 94ae6c9

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

+344
-986
lines changed

docs/ByteTree.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

docs/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ documentation, please create a thread on the Swift forums under the
8686

8787
## Explanations
8888

89-
- [ByteTree.md](/docs/ByteTree.md):
90-
Describes the ByteTree binary format used for serializing syntax trees
91-
in `libSyntax`.
9289
- [WebAssembly.md](/docs/WebAssembly.md):
9390
Explains some decisions that were made while implementing the WebAssembly target.
9491

include/swift/ABI/Executor.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@
1919

2020
#include <inttypes.h>
2121
#include "swift/ABI/HeapObject.h"
22+
#include "swift/Runtime/Casting.h"
2223

2324
namespace swift {
2425
class AsyncContext;
2526
class AsyncTask;
2627
class DefaultActor;
2728
class Job;
2829

30+
/// FIXME: only exists for the quick-and-dirty MainActor implementation.
31+
SWIFT_EXPORT_FROM(swift_Concurrency)
32+
Metadata* MainActorMetadata;
33+
2934
/// An ExecutorRef isn't necessarily just a pointer to an executor
3035
/// object; it may have other bits set.
3136
class ExecutorRef {
@@ -45,6 +50,13 @@ class ExecutorRef {
4550
return ExecutorRef(0);
4651
}
4752

53+
/// FIXME: only exists for the quick-and-dirty MainActor implementation.
54+
/// NOTE: I didn't go with Executor::forMainActor(DefaultActor*) because
55+
/// __swift_run_job_main_executor can't take more than one argument.
56+
constexpr static ExecutorRef mainExecutor() {
57+
return ExecutorRef(2);
58+
}
59+
4860
/// Given a pointer to a default actor, return an executor reference
4961
/// for it.
5062
static ExecutorRef forDefaultActor(DefaultActor *actor) {
@@ -57,6 +69,20 @@ class ExecutorRef {
5769
return Value == 0;
5870
}
5971

72+
/// FIXME: only exists for the quick-and-dirty MainActor implementation.
73+
bool isMainExecutor() const {
74+
if (Value == ExecutorRef::mainExecutor().Value)
75+
return true;
76+
77+
HeapObject *heapObj = reinterpret_cast<HeapObject*>(Value & ~PointerMask);
78+
79+
if (heapObj == nullptr || MainActorMetadata == nullptr)
80+
return false;
81+
82+
Metadata const* metadata = swift_getObjectType(heapObj);
83+
return metadata == MainActorMetadata;
84+
}
85+
6086
/// Is this a default-actor executor reference?
6187
bool isDefaultActor() const {
6288
return Value & IsDefaultActor;
@@ -77,10 +103,12 @@ class ExecutorRef {
77103
}
78104

79105
bool operator==(ExecutorRef other) const {
80-
return Value == other.Value;
106+
return Value == other.Value
107+
/// FIXME: only exists for the quick-and-dirty MainActor implementation.
108+
|| (isMainExecutor() && other.isMainExecutor());
81109
}
82110
bool operator!=(ExecutorRef other) const {
83-
return Value != other.Value;
111+
return !(*this == other);
84112
}
85113
};
86114

0 commit comments

Comments
 (0)