Skip to content

Commit b3614a4

Browse files
committed
swift-module-digester: include unavailable variables with fixed layout order when checking ABI stability.
1 parent e5e61d4 commit b3614a4

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

test/api-digester/Inputs/cake.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public struct fixedLayoutStruct {
4949
public var a = 1
5050
private var b = 2
5151
var c = 3
52+
@available(*, unavailable)
53+
public let unavailableProperty = 1
5254
}
5355

5456
extension Int: P1 { public func bar() {} }

test/api-digester/Outputs/cake-abi.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,49 @@
839839
"fixedbinaryorder": 2,
840840
"hasStorage": true
841841
},
842+
{
843+
"kind": "Var",
844+
"name": "unavailableProperty",
845+
"printedName": "unavailableProperty",
846+
"children": [
847+
{
848+
"kind": "TypeNominal",
849+
"name": "Int",
850+
"printedName": "Int",
851+
"usr": "s:Si"
852+
},
853+
{
854+
"kind": "Getter",
855+
"name": "_",
856+
"printedName": "_()",
857+
"children": [
858+
{
859+
"kind": "TypeNominal",
860+
"name": "Int",
861+
"printedName": "Int",
862+
"usr": "s:Si"
863+
}
864+
],
865+
"declKind": "Accessor",
866+
"usr": "s:4cake17fixedLayoutStructV19unavailablePropertySivg",
867+
"moduleName": "cake",
868+
"implicit": true,
869+
"declAttributes": [
870+
"Transparent"
871+
]
872+
}
873+
],
874+
"declKind": "Var",
875+
"usr": "s:4cake17fixedLayoutStructV19unavailablePropertySivp",
876+
"moduleName": "cake",
877+
"declAttributes": [
878+
"HasInitialValue",
879+
"Available"
880+
],
881+
"fixedbinaryorder": 3,
882+
"isLet": true,
883+
"hasStorage": true
884+
},
842885
{
843886
"kind": "Constructor",
844887
"name": "init",

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,17 @@ SwiftDeclCollector::constructInitNode(ConstructorDecl *CD) {
12001200

12011201
bool swift::ide::api::
12021202
SwiftDeclCollector::shouldIgnore(Decl *D, const Decl* Parent) {
1203+
if (Ctx.checkingABI()) {
1204+
if (auto *VD = dyn_cast<ValueDecl>(D)) {
1205+
// Private vars with fixed binary orders can have ABI-impact, so we should
1206+
// whitelist them if we're checking ABI.
1207+
if (getFixedBinaryOrder(VD).hasValue())
1208+
return false;
1209+
// Typealias should have no impact on ABI.
1210+
if (isa<TypeAliasDecl>(VD))
1211+
return true;
1212+
}
1213+
}
12031214
if (D->isPrivateStdlibDecl(false))
12041215
return true;
12051216
if (AvailableAttr::isUnavailable(D))
@@ -1209,18 +1220,10 @@ SwiftDeclCollector::shouldIgnore(Decl *D, const Decl* Parent) {
12091220
if (auto VD = dyn_cast<ValueDecl>(D)) {
12101221
if (VD->getBaseName().empty())
12111222
return true;
1212-
1213-
// Exclude type alias decls because they should have no impact on ABI.
1214-
if (isa<TypeAliasDecl>(VD) && Ctx.checkingABI())
1215-
return true;
12161223
switch (VD->getFormalAccess()) {
12171224
case AccessLevel::Internal:
12181225
case AccessLevel::Private:
12191226
case AccessLevel::FilePrivate:
1220-
// Private vars with fixed binary orders can have ABI-impact, so we should
1221-
// whitelist them if we're checking ABI.
1222-
if (Ctx.checkingABI() && getFixedBinaryOrder(VD).hasValue())
1223-
break;
12241227
return true;
12251228
case AccessLevel::Public:
12261229
case AccessLevel::Open:

0 commit comments

Comments
 (0)