Skip to content

Commit d01c19b

Browse files
committed
[AST/Sema] Support for @concurrent attribute in type context
1 parent e46edd0 commit d01c19b

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
@@ -4195,11 +4195,11 @@ NeverNullType TypeResolver::resolveASTFunctionType(
41954195
}
41964196
}
41974197

4198-
if (auto executionAttr = claim<ExecutionTypeAttr>(attrs)) {
4198+
auto checkExecutionBehaviorAttribute = [&](TypeAttribute *attr) {
41994199
if (!repr->isAsync()) {
4200-
diagnoseInvalid(repr, executionAttr->getAtLoc(),
4200+
diagnoseInvalid(repr, attr->getAttrLoc(),
42014201
diag::execution_behavior_type_attr_only_on_async,
4202-
executionAttr->getAttrName());
4202+
attr->getAttrName());
42034203
}
42044204

42054205
switch (isolation.getKind()) {
@@ -4208,29 +4208,33 @@ NeverNullType TypeResolver::resolveASTFunctionType(
42084208

42094209
case FunctionTypeIsolation::Kind::GlobalActor:
42104210
diagnoseInvalid(
4211-
repr, executionAttr->getAtLoc(),
4211+
repr, attr->getAttrLoc(),
42124212
diag::execution_behavior_type_attr_incompatible_with_global_isolation,
4213-
executionAttr->getAttrName(), isolation.getGlobalActorType());
4213+
attr->getAttrName(), isolation.getGlobalActorType());
42144214
break;
42154215

42164216
case FunctionTypeIsolation::Kind::Parameter:
42174217
diagnoseInvalid(
4218-
repr, executionAttr->getAtLoc(),
4218+
repr, attr->getAttrLoc(),
42194219
diag::execution_behavior_type_attr_incompatible_with_isolated_param,
4220-
executionAttr->getAttrName());
4220+
attr->getAttrName());
42214221
break;
42224222

42234223
case FunctionTypeIsolation::Kind::Erased:
42244224
diagnoseInvalid(
4225-
repr, executionAttr->getAtLoc(),
4225+
repr, attr->getAttrLoc(),
42264226
diag::execution_behavior_type_attr_incompatible_with_isolated_any,
4227-
executionAttr->getAttrName());
4227+
attr->getAttrName());
42284228
break;
42294229

42304230
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
42314231
llvm_unreachable("cannot happen because multiple @execution attributes "
42324232
"aren't allowed.");
42334233
}
4234+
};
4235+
4236+
if (auto executionAttr = claim<ExecutionTypeAttr>(attrs)) {
4237+
checkExecutionBehaviorAttribute(executionAttr);
42344238

42354239
if (!repr->isInvalid()) {
42364240
switch (executionAttr->getBehavior()) {
@@ -4242,6 +4246,10 @@ NeverNullType TypeResolver::resolveASTFunctionType(
42424246
break;
42434247
}
42444248
}
4249+
} else if (auto concurrentAttr = claim<ConcurrentTypeAttr>(attrs)) {
4250+
checkExecutionBehaviorAttribute(concurrentAttr);
4251+
if (!repr->isInvalid())
4252+
isolation = FunctionTypeIsolation::forNonIsolated();
42454253
} else {
42464254
if (ctx.LangOpts.getFeatureState(Feature::AsyncCallerExecution)
42474255
.isEnabledForAdoption()) {

0 commit comments

Comments
 (0)