|
13 | 13 | // This file implements type checking support for Swift's concurrency model.
|
14 | 14 | //
|
15 | 15 | //===----------------------------------------------------------------------===//
|
| 16 | +#include "TypeCheckConcurrency.h" |
16 | 17 | #include "TypeChecker.h"
|
17 | 18 | #include "swift/AST/ASTWalker.h"
|
18 | 19 | #include "swift/AST/ParameterList.h"
|
|
21 | 22 |
|
22 | 23 | using namespace swift;
|
23 | 24 |
|
24 |
| -/// Check whether the @asyncHandler attribute can be applied to the given |
25 |
| -/// function declaration. |
26 |
| -/// |
27 |
| -/// \param diagnose Whether to emit a diagnostic when a problem is encountered. |
28 |
| -/// |
29 |
| -/// \returns \c true if there was a problem with adding the attribute, \c false |
30 |
| -/// otherwise. |
31 |
| -static bool checkAsyncHandler(FuncDecl *func, bool diagnose) { |
| 25 | +bool swift::checkAsyncHandler(FuncDecl *func, bool diagnose) { |
32 | 26 | if (!func->getResultInterfaceType()->isVoid()) {
|
33 | 27 | if (diagnose) {
|
34 | 28 | func->diagnose(diag::asynchandler_returns_value)
|
@@ -233,30 +227,6 @@ class IsolationRestriction {
|
233 | 227 |
|
234 | 228 | explicit IsolationRestriction(Kind kind) : kind(kind) { }
|
235 | 229 |
|
236 |
| - /// Determine whether the given value is an instance member of an actor |
237 |
| - /// class that is isolated to the current actor instance. |
238 |
| - /// |
239 |
| - /// \returns the type of the actor. |
240 |
| - static ClassDecl *getActorIsolatingInstanceMember(ValueDecl *value) { |
241 |
| - // Only instance members are isolated. |
242 |
| - if (!value->isInstanceMember()) |
243 |
| - return nullptr; |
244 |
| - |
245 |
| - // Are we within an actor class? |
246 |
| - auto classDecl = value->getDeclContext()->getSelfClassDecl(); |
247 |
| - if (!classDecl || !classDecl->isActor()) |
248 |
| - return nullptr; |
249 |
| - |
250 |
| - // Functions that are an asynchronous context can be accessed from anywhere. |
251 |
| - if (auto func = dyn_cast<AbstractFunctionDecl>(value)) { |
252 |
| - if (func->isAsyncContext()) |
253 |
| - return nullptr; |
254 |
| - } |
255 |
| - |
256 |
| - // This member is part of the isolated state. |
257 |
| - return classDecl; |
258 |
| - } |
259 |
| - |
260 | 230 | public:
|
261 | 231 | Kind getKind() const { return kind; }
|
262 | 232 |
|
@@ -354,8 +324,7 @@ class IsolationRestriction {
|
354 | 324 | return forLocalCapture(decl->getDeclContext());
|
355 | 325 |
|
356 | 326 | // Protected actor instance members can only be accessed on 'self'.
|
357 |
| - if (auto actorClass = getActorIsolatingInstanceMember( |
358 |
| - cast<ValueDecl>(decl))) |
| 327 | + if (auto actorClass = getActorIsolatingMember(cast<ValueDecl>(decl))) |
359 | 328 | return forActorSelf(actorClass);
|
360 | 329 |
|
361 | 330 | // All other accesses are unsafe.
|
@@ -635,3 +604,23 @@ void swift::checkActorIsolation(const Expr *expr, const DeclContext *dc) {
|
635 | 604 | ActorIsolationWalker walker(dc);
|
636 | 605 | const_cast<Expr *>(expr)->walk(walker);
|
637 | 606 | }
|
| 607 | + |
| 608 | +ClassDecl *swift::getActorIsolatingMember(ValueDecl *value) { |
| 609 | + // Only instance members are isolated. |
| 610 | + if (!value->isInstanceMember()) |
| 611 | + return nullptr; |
| 612 | + |
| 613 | + // Are we within an actor class? |
| 614 | + auto classDecl = value->getDeclContext()->getSelfClassDecl(); |
| 615 | + if (!classDecl || !classDecl->isActor()) |
| 616 | + return nullptr; |
| 617 | + |
| 618 | + // Functions that are an asynchronous context can be accessed from anywhere. |
| 619 | + if (auto func = dyn_cast<AbstractFunctionDecl>(value)) { |
| 620 | + if (func->isAsyncContext()) |
| 621 | + return nullptr; |
| 622 | + } |
| 623 | + |
| 624 | + // This member is part of the isolated state. |
| 625 | + return classDecl; |
| 626 | +} |
0 commit comments