Skip to content

Commit 873f562

Browse files
committed
[AST/Sema] Support for @concurrent attribute in type context
1 parent 7c6ec33 commit 873f562

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

include/swift/AST/TypeAttr.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ TYPE_ATTR(isolated, Isolated)
6868
SIMPLE_TYPE_ATTR(nonisolated, Nonisolated)
6969
SIMPLE_TYPE_ATTR(_addressable, Addressable)
7070
TYPE_ATTR(execution, Execution)
71+
SIMPLE_TYPE_ATTR(concurrent, Concurrent)
7172

7273
// SIL-specific attributes
7374
SIMPLE_SIL_TYPE_ATTR(async, Async)

lib/ASTGen/Sources/ASTGen/TypeAttrs.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ extension ASTGenVisitor {
4242
// Simple type attributes.
4343
case .autoclosure,
4444
.addressable,
45+
.concurrent,
4546
.escaping,
4647
.noEscape,
4748
.noDerivative,

lib/Sema/TypeCheckType.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4201,11 +4201,11 @@ NeverNullType TypeResolver::resolveASTFunctionType(
42014201
}
42024202
}
42034203

4204-
if (auto executionAttr = claim<ExecutionTypeAttr>(attrs)) {
4204+
auto checkExecutionBehaviorAttribute = [&](TypeAttribute *attr) {
42054205
if (!repr->isAsync()) {
4206-
diagnoseInvalid(repr, executionAttr->getAtLoc(),
4206+
diagnoseInvalid(repr, attr->getAttrLoc(),
42074207
diag::execution_behavior_type_attr_only_on_async,
4208-
executionAttr->getAttrName());
4208+
attr->getAttrName());
42094209
}
42104210

42114211
switch (isolation.getKind()) {
@@ -4214,29 +4214,33 @@ NeverNullType TypeResolver::resolveASTFunctionType(
42144214

42154215
case FunctionTypeIsolation::Kind::GlobalActor:
42164216
diagnoseInvalid(
4217-
repr, executionAttr->getAtLoc(),
4217+
repr, attr->getAttrLoc(),
42184218
diag::execution_behavior_type_attr_incompatible_with_global_isolation,
4219-
executionAttr->getAttrName(), isolation.getGlobalActorType());
4219+
attr->getAttrName(), isolation.getGlobalActorType());
42204220
break;
42214221

42224222
case FunctionTypeIsolation::Kind::Parameter:
42234223
diagnoseInvalid(
4224-
repr, executionAttr->getAtLoc(),
4224+
repr, attr->getAttrLoc(),
42254225
diag::execution_behavior_type_attr_incompatible_with_isolated_param,
4226-
executionAttr->getAttrName());
4226+
attr->getAttrName());
42274227
break;
42284228

42294229
case FunctionTypeIsolation::Kind::Erased:
42304230
diagnoseInvalid(
4231-
repr, executionAttr->getAtLoc(),
4231+
repr, attr->getAttrLoc(),
42324232
diag::execution_behavior_type_attr_incompatible_with_isolated_any,
4233-
executionAttr->getAttrName());
4233+
attr->getAttrName());
42344234
break;
42354235

42364236
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
42374237
llvm_unreachable("cannot happen because multiple @execution attributes "
42384238
"aren't allowed.");
42394239
}
4240+
};
4241+
4242+
if (auto executionAttr = claim<ExecutionTypeAttr>(attrs)) {
4243+
checkExecutionBehaviorAttribute(executionAttr);
42404244

42414245
if (!repr->isInvalid()) {
42424246
switch (executionAttr->getBehavior()) {
@@ -4248,6 +4252,10 @@ NeverNullType TypeResolver::resolveASTFunctionType(
42484252
break;
42494253
}
42504254
}
4255+
} else if (auto concurrentAttr = claim<ConcurrentTypeAttr>(attrs)) {
4256+
checkExecutionBehaviorAttribute(concurrentAttr);
4257+
if (!repr->isInvalid())
4258+
isolation = FunctionTypeIsolation::forNonIsolated();
42514259
} else {
42524260
if (ctx.LangOpts.getFeatureState(Feature::AsyncCallerExecution)
42534261
.isEnabledForAdoption()) {

0 commit comments

Comments
 (0)