Skip to content

Commit f66dd8e

Browse files
authored
swift-api-digester: keep track of type declarations with fixed layout. (swiftlang#14991)
We need special logic to check abi-stability for decls with fixed layout.
1 parent e64d810 commit f66dd8e

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ NODE_ANNOTATION(StaticChange)
7272
NODE_ANNOTATION(OwnershipChange)
7373

7474
DECL_ATTR(deprecated)
75+
DECL_ATTR(fixedLayout)
7576

7677
KEY(kind)
7778
KEY(name)

test/api-digester/Inputs/cake.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
public protocol P1 {}
22
public protocol P2 {}
3+
4+
@_fixed_layout
35
public struct S1: P1 {
46
public static func foo1() {}
57
mutating public func foo2() {}
@@ -32,4 +34,4 @@ public func foo2(_ a: Int = #line, b: S1) {}
3234

3335
public enum Number: Int {
3436
case one
35-
}
37+
}

test/api-digester/Outputs/cake.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@
115115
"P1",
116116
"P2"
117117
],
118+
"declAttributes": [
119+
"fixedLayout"
120+
],
118121
"children": [
119122
{
120123
"kind": "Function",

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ class SDKNodeDecl : public SDKNode {
433433
StringRef getFullyQualifiedName() const;
434434
bool isSDKPrivate() const;
435435
bool isDeprecated() const;
436+
bool hasFixedLayout() const;
436437
bool isStatic() const { return IsStatic; };
437438
bool isFromExtension() const { return ExtInfo; }
438439
const ParentExtensionInfo& getExtensionInfo() const {
@@ -714,6 +715,10 @@ bool SDKNodeDecl::isDeprecated() const {
714715
return hasDeclAttribute(SDKDeclAttrKind::DAK_deprecated);
715716
}
716717

718+
bool SDKNodeDecl::hasFixedLayout() const {
719+
return hasDeclAttribute(SDKDeclAttrKind::DAK_fixedLayout);
720+
}
721+
717722
bool SDKNodeDecl::isSDKPrivate() const {
718723
if (getName().startswith("__"))
719724
return true;
@@ -1295,6 +1300,11 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD)
12951300
if (VD->getAttrs().getDeprecated(VD->getASTContext()))
12961301
DeclAttrs.push_back(SDKDeclAttrKind::DAK_deprecated);
12971302

1303+
// If this is fixed_layout struct.
1304+
if (VD->getAttrs().hasAttribute<FixedLayoutAttr>()) {
1305+
DeclAttrs.push_back(SDKDeclAttrKind::DAK_fixedLayout);
1306+
}
1307+
12981308
// If the decl is declared in an extension, calculate the extension info.
12991309
if (auto *Ext = dyn_cast_or_null<ExtensionDecl>(VD->getDeclContext())) {
13001310
ExtInfo = new (Ctx) ParentExtensionInfo();

0 commit comments

Comments
 (0)