Skip to content

Commit f7b3e4b

Browse files
authored
Merge pull request #27770 from gottesmm/pr-fedc6e35f83040331ae2bec83b08320f3b31ba0e
[sil] Add support for adding _semantics attributes to nominal types.
2 parents 8d05192 + 454dd00 commit f7b3e4b

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ DECL_ATTR(inline, Inline,
202202
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
203203
20)
204204
DECL_ATTR(_semantics, Semantics,
205-
OnAbstractFunction | OnSubscript |
205+
OnAbstractFunction | OnSubscript | OnNominalType |
206206
AllowMultipleAttributes | UserInaccessible |
207207
ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove,
208208
21)

include/swift/AST/Decl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3512,6 +3512,18 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
35123512
/// with placeholders for unimportable stored properties.
35133513
ArrayRef<Decl *> getStoredPropertiesAndMissingMemberPlaceholders() const;
35143514

3515+
/// Return the range of semantics attributes attached to this NominalTypeDecl.
3516+
auto getSemanticsAttrs() const
3517+
-> decltype(getAttrs().getAttributes<SemanticsAttr>()) {
3518+
return getAttrs().getAttributes<SemanticsAttr>();
3519+
}
3520+
3521+
bool hasSemanticsAttr(StringRef attrValue) const {
3522+
return llvm::any_of(getSemanticsAttrs(), [&](const SemanticsAttr *attr) {
3523+
return attrValue.equals(attr->Value);
3524+
});
3525+
}
3526+
35153527
// Implement isa/cast/dyncast/etc.
35163528
static bool classof(const Decl *D) {
35173529
return D->getKind() >= DeclKind::First_NominalTypeDecl &&

test/attr/attr_semantics.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,16 @@ func func_with_nested_semantics_2() {
1919
func exit(_ code : UInt32) -> Void
2020
exit(0)
2121
}
22+
23+
@_semantics("struct")
24+
struct StructWithSemantics {}
25+
26+
@_semantics("class")
27+
class ClassWithSemantics {}
28+
29+
@_semantics("enum")
30+
enum EnumWithSemantics {}
31+
32+
@_semantics("struct1")
33+
@_semantics("struct2")
34+
struct StructWithDuplicateSemantics {}

0 commit comments

Comments
 (0)