Skip to content

Commit d1f892c

Browse files
committed
[ASTGen] Generate '@reasync' and '@rethrows'
Also, fallback 'shouldBeRejectedByParser' attribute names to 'CustomAttr'.
1 parent 3d91c33 commit d1f892c

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,9 @@ struct BridgedDeclAttributes {
847847
BRIDGED_INLINE swift::DeclAttributes unbridged() const;
848848
};
849849

850+
SWIFT_NAME("BridgedDeclAttribute.shouldBeRejectedByParser(_:)")
851+
bool BridgedDeclAttribute_shouldBeRejectedByParser(BridgedDeclAttrKind cKind);
852+
850853
SWIFT_NAME("BridgedDeclAttribute.isDeclModifier(_:)")
851854
bool BridgedDeclAttribute_isDeclModifier(BridgedDeclAttrKind cKind);
852855

lib/AST/Bridging/DeclAttributeBridging.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ BridgedDeclAttribute BridgedDeclAttribute_createSimple(
101101
cAtLoc.unbridged(), cAttrLoc.unbridged());
102102
}
103103

104+
bool BridgedDeclAttribute_shouldBeRejectedByParser(BridgedDeclAttrKind cKind) {
105+
auto optKind = unbridged(cKind);
106+
if (!optKind)
107+
return false;
108+
return DeclAttribute::shouldBeRejectedByParser(*optKind);
109+
}
110+
104111
bool BridgedDeclAttribute_isDeclModifier(BridgedDeclAttrKind cKind) {
105112
auto optKind = unbridged(cKind);
106113
if (!optKind)

lib/ASTGen/Sources/ASTGen/DeclAttrs.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ extension ASTGenVisitor {
193193
fatalError("unimplemented")
194194
case .unavailableFromAsync:
195195
return handle(self.generateUnavailableFromAsyncAttr(attribute: node)?.asDeclAttribute)
196+
case .reasync:
197+
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .atReasync))
198+
case .rethrows:
199+
return handle(self.generateSimpleDeclAttr(attribute: node, kind: .atRethrows))
196200
case .none where attrName == "_unavailableInEmbedded":
197201
return handle(self.generateUnavailableInEmbeddedAttr(attribute: node)?.asDeclAttribute)
198202
case .none where attrName == "_functionBuilder":
@@ -329,11 +333,10 @@ extension ASTGenVisitor {
329333
.clangImporterSynthesizedType,
330334
.forbidSerializingReference,
331335
.custom,
332-
.setterAccess,
333-
.rethrows,
334-
.reasync:
335-
// TODO: Diagnose or fallback to custom attributes?
336-
return
336+
.setterAccess:
337+
assert(BridgedDeclAttribute.shouldBeRejectedByParser(attrKind))
338+
// Fall back to CustomAttr.
339+
break
337340

338341
case .none:
339342
// Fall back to CustomAttr.

test/ASTGen/attrs.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// RUN: -enable-experimental-feature LifetimeDependence \
88
// RUN: -enable-experimental-feature RawLayout \
99
// RUN: -enable-experimental-feature SymbolLinkageMarkers \
10+
// RUN: -enable-experimental-concurrency \
1011
// RUN: -enable-experimental-move-only \
1112
// RUN: -enable-experimental-feature ParserASTGen \
1213
// RUN: | %sanitize-address > %t/astgen.ast
@@ -18,6 +19,7 @@
1819
// RUN: -enable-experimental-feature LifetimeDependence \
1920
// RUN: -enable-experimental-feature RawLayout \
2021
// RUN: -enable-experimental-feature SymbolLinkageMarkers \
22+
// RUN: -enable-experimental-concurrency \
2123
// RUN: -enable-experimental-move-only \
2224
// RUN: | %sanitize-address > %t/cpp-parser.ast
2325

@@ -32,8 +34,10 @@
3234
// RUN: -enable-experimental-feature LifetimeDependence \
3335
// RUN: -enable-experimental-feature RawLayout \
3436
// RUN: -enable-experimental-feature SymbolLinkageMarkers \
37+
// RUN: -enable-experimental-concurrency \
3538
// RUN: -enable-experimental-move-only
3639

40+
// REQUIRES: concurrency
3741
// REQUIRES: executable_test
3842
// REQUIRES: swift_swift_parser
3943
// REQUIRES: swift_feature_ParserASTGen
@@ -250,3 +254,8 @@ struct LayoutOuter {
250254
}
251255
}
252256
@_rawLayout(like: LayoutOuter.Nested<Int>) struct TypeExprTest: ~Copyable {}
257+
258+
@reasync protocol ReasyncProtocol {}
259+
@rethrows protocol RethrowingProtocol {
260+
func source() throws
261+
}

0 commit comments

Comments
 (0)