Skip to content

Commit 4340fb7

Browse files
committed
[Sema] Add skeleton implementation of @runtimeMetadata attribute
Use of the attribute is gated on `RuntimeDiscoverableAttrs` flag.
1 parent a6427ca commit 4340fb7

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6756,6 +6756,14 @@ ERROR(moveonly_cannot_conform_to_protocol, none,
67566756
ERROR(moveonly_cannot_conform_to_protocol_with_name, none,
67576757
"move-only %0 %1 cannot conform to protocol %2",
67586758
(DescriptiveDeclKind, DeclName, DeclName))
6759+
6760+
//------------------------------------------------------------------------------
6761+
// MARK: Runtime discoverable attributes (@runtimeMetadata)
6762+
//------------------------------------------------------------------------------
6763+
6764+
ERROR(runtime_discoverable_attrs_are_experimental,none,
6765+
"runtime discoverable attributes are an experimental feature", ())
6766+
67596767
#define UNDEFINE_DIAGNOSTIC_MACROS
67606768
#include "DefineDiagnosticMacros.h"
67616769

lib/Sema/TypeCheckAttr.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
336336
void visitKnownToBeLocalAttr(KnownToBeLocalAttr *attr);
337337

338338
void visitSendableAttr(SendableAttr *attr);
339+
340+
void visitRuntimeMetadataAttr(RuntimeMetadataAttr *attr);
339341
};
340342

341343
} // end anonymous namespace
@@ -6934,6 +6936,15 @@ void AttributeChecker::visitCompilerInitializedAttr(
69346936
}
69356937
}
69366938

6939+
void AttributeChecker::visitRuntimeMetadataAttr(RuntimeMetadataAttr *attr) {
6940+
if (!Ctx.LangOpts.hasFeature(Feature::RuntimeDiscoverableAttrs)) {
6941+
diagnose(attr->getLocation(),
6942+
diag::runtime_discoverable_attrs_are_experimental);
6943+
attr->setInvalid();
6944+
return;
6945+
}
6946+
}
6947+
69376948
namespace {
69386949

69396950
class ClosureAttributeChecker

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,6 +1623,8 @@ namespace {
16231623

16241624
UNINTERESTING_ATTR(EagerMove)
16251625
UNINTERESTING_ATTR(NoEagerMove)
1626+
1627+
UNINTERESTING_ATTR(RuntimeMetadata)
16261628
#undef UNINTERESTING_ATTR
16271629

16281630
void visitAvailableAttr(AvailableAttr *attr) {

test/IDE/complete_decl_attribute.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ actor MyGlobalActor {
118118
// KEYWORD3-NEXT: Keyword/None: globalActor[#Class Attribute#]; name=globalActor
119119
// KEYWORD3-NEXT: Keyword/None: preconcurrency[#Class Attribute#]; name=preconcurrency
120120
// KEYWORD3-NEXT: Keyword/None: typeWrapper[#Class Attribute#]; name=typeWrapper
121+
// KEYWORD3-NEXT: Keyword/None: runtimeMetadata[#Class Attribute#]; name=runtimeMetadata
121122
// KEYWORD3-NEXT: End completions
122123

123124
@#^KEYWORD3_2^#IB class C2 {}
@@ -153,6 +154,7 @@ actor MyGlobalActor {
153154
// KEYWORD5-NEXT: Keyword/None: globalActor[#Struct Attribute#]; name=globalActor
154155
// KEYWORD5-NEXT: Keyword/None: preconcurrency[#Struct Attribute#]; name=preconcurrency
155156
// KEYWORD5-NEXT: Keyword/None: typeWrapper[#Struct Attribute#]; name=typeWrapper
157+
// KEYWORD5-NEXT: Keyword/None: runtimeMetadata[#Struct Attribute#]; name=runtimeMetadata
156158
// KEYWORD5-NEXT: End completions
157159

158160
@#^ON_GLOBALVAR^# var globalVar
@@ -312,6 +314,7 @@ struct _S {
312314
// ON_MEMBER_LAST-DAG: Keyword/None: preconcurrency[#Declaration Attribute#]; name=preconcurrency
313315
// ON_MEMBER_LAST-DAG: Keyword/None: typeWrapper[#Declaration Attribute#]; name=typeWrapper
314316
// ON_MEMBER_LAST-DAG: Keyword/None: typeWrapperIgnored[#Declaration Attribute#]; name=typeWrapperIgnored
317+
// ON_MEMBER_LAST-DAG: Keyword/None: runtimeMetadata[#Declaration Attribute#]; name=runtimeMetadata
315318
// ON_MEMBER_LAST-NOT: Keyword
316319
// ON_MEMBER_LAST-DAG: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct
317320
// ON_MEMBER_LAST-DAG: Decl[Struct]/CurrModule/TypeRelation[Convertible]: MyPropertyWrapper[#MyPropertyWrapper#]; name=MyPropertyWrapper
@@ -383,6 +386,7 @@ func dummy2() {}
383386
// KEYWORD_LAST-DAG: Keyword/None: preconcurrency[#Declaration Attribute#]; name=preconcurrency
384387
// KEYWORD_LAST-DAG: Keyword/None: typeWrapper[#Declaration Attribute#]; name=typeWrapper
385388
// KEYWORD_LAST-DAG: Keyword/None: typeWrapperIgnored[#Declaration Attribute#]; name=typeWrapperIgnored
389+
// KEYWORD_LAST-DAG: Keyword/None: runtimeMetadata[#Declaration Attribute#]; name=runtimeMetadata
386390
// KEYWORD_LAST-NOT: Keyword
387391
// KEYWORD_LAST-DAG: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct
388392
// KEYWORD_LAST-DAG: Decl[Struct]/CurrModule/TypeRelation[Convertible]: MyPropertyWrapper[#MyPropertyWrapper#]; name=MyPropertyWrapper

0 commit comments

Comments
 (0)