Skip to content

Commit 58b3c21

Browse files
committed
swift-module-digester: use getEffectiveAccess() to get accessibility when checking ABI stability.
This allows us to include internal decls with @usableFromInline attribute, whose stored property changes can effect ABI.
1 parent 6cc6f4f commit 58b3c21

File tree

8 files changed

+47
-11
lines changed

8 files changed

+47
-11
lines changed

test/api-digester/Inputs/cake.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,6 @@ public extension P1 {
8888
}
8989

9090
infix operator ..*..
91+
92+
@usableFromInline
93+
class UsableFromInlineClass {}

test/api-digester/Inputs/cake1.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ public struct fixedLayoutStruct {
5555
public var a = 1
5656
}
5757

58+
@usableFromInline
5859
@_fixed_layout
59-
public struct fixedLayoutStruct2 {
60+
struct fixedLayoutStruct2 {
6061
public private(set) var NoLongerWithFixedBinaryOrder = 1
6162
public var BecomeFixedBinaryOrder: Int { return 1 }
6263
}

test/api-digester/Inputs/cake2.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ public struct fixedLayoutStruct {
5959
private lazy var lazy_d = 4
6060
}
6161

62+
@usableFromInline
6263
@_fixed_layout
63-
public struct fixedLayoutStruct2 {
64+
struct fixedLayoutStruct2 {
6465
public var NoLongerWithFixedBinaryOrder: Int { return 1 }
6566
public var BecomeFixedBinaryOrder = 1
6667
}

test/api-digester/Outputs/Cake-abi.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,3 @@ cake2: Var RequiementChanges.addedVar has been added as a protocol requirement
7878
cake1: Class C4 has changed its super class from OldType to NewType
7979
cake1: Class SubGenericClass has changed its super class from GenericClass<P1> to GenericClass<P2>
8080
cake1: Class SuperClassRemoval has removed its super class C3
81-
cake1: Func ClassWithOpenMember.bar() is no longer open for subclassing
82-
cake1: Func ClassWithOpenMember.foo() is no longer open for subclassing
83-
cake1: Var ClassWithOpenMember.property is no longer open for subclassing

test/api-digester/Outputs/Cake.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ cake1: Protocol P3 has generic signature change from <Self : P1, Self : P2> to <
99
cake1: AssociatedType RequiementChanges.removedType has been removed
1010
cake1: Constructor Somestruct2.init(_:) has been removed
1111
cake1: Constructor fixedLayoutStruct.init(b:a:) has been removed
12-
cake1: Constructor fixedLayoutStruct2.init(NoLongerWithFixedBinaryOrder:) has been removed
1312
cake1: Func C4.foo() has been removed
1413
cake1: Func RequiementChanges.removedFunc() has been removed
1514
cake1: Subscript RemoveSetters.subscript(_:) has removed its setter

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@
231231
"declKind": "Func",
232232
"usr": "s:4cake2C1C4foo1yyFZ",
233233
"moduleName": "cake",
234-
"static": true,
235-
"isOpen": true
234+
"static": true
236235
},
237236
{
238237
"kind": "Var",
@@ -1200,6 +1199,37 @@
12001199
"Infix"
12011200
]
12021201
},
1202+
{
1203+
"kind": "TypeDecl",
1204+
"name": "UsableFromInlineClass",
1205+
"printedName": "UsableFromInlineClass",
1206+
"children": [
1207+
{
1208+
"kind": "Constructor",
1209+
"name": "init",
1210+
"printedName": "init()",
1211+
"children": [
1212+
{
1213+
"kind": "TypeNominal",
1214+
"name": "UsableFromInlineClass",
1215+
"printedName": "UsableFromInlineClass",
1216+
"usr": "s:4cake21UsableFromInlineClassC"
1217+
}
1218+
],
1219+
"declKind": "Constructor",
1220+
"usr": "s:4cake21UsableFromInlineClassCACycfc",
1221+
"moduleName": "cake",
1222+
"implicit": true,
1223+
"isInternal": true
1224+
}
1225+
],
1226+
"declKind": "Class",
1227+
"usr": "s:4cake21UsableFromInlineClassC",
1228+
"moduleName": "cake",
1229+
"declAttributes": [
1230+
"UsableFromInline"
1231+
]
1232+
},
12031233
{
12041234
"kind": "TypeDecl",
12051235
"name": "Int",

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,10 @@ bool SDKContext::isEqual(const SDKNode &Left, const SDKNode &Right) {
770770
return EqualCache[&Left][&Right];
771771
}
772772

773+
AccessLevel SDKContext::getAccessLevel(const ValueDecl *VD) const {
774+
return checkingABI() ? VD->getEffectiveAccess() : VD->getFormalAccess();
775+
}
776+
773777
bool SDKNode::operator==(const SDKNode &Other) const {
774778
return Ctx.isEqual(*this, Other);
775779
}
@@ -1055,8 +1059,8 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD)
10551059
IsStatic = VD->isStatic();
10561060
IsOverriding = VD->getOverriddenDecl();
10571061
IsProtocolReq = isa<ProtocolDecl>(VD->getDeclContext()) && VD->isProtocolRequirement();
1058-
IsOpen = VD->getFormalAccess() == AccessLevel::Open;
1059-
IsInternal = VD->getFormalAccess() < AccessLevel::Public;
1062+
IsOpen = Ctx.getAccessLevel(VD) == AccessLevel::Open;
1063+
IsInternal = Ctx.getAccessLevel(VD) < AccessLevel::Public;
10601064
SelfIndex = getSelfIndex(VD);
10611065
FixedBinaryOrder = getFixedBinaryOrder(VD);
10621066
ReferenceOwnership = getReferenceOwnership(VD);
@@ -1222,7 +1226,7 @@ SwiftDeclCollector::shouldIgnore(Decl *D, const Decl* Parent) {
12221226
if (auto VD = dyn_cast<ValueDecl>(D)) {
12231227
if (VD->getBaseName().empty())
12241228
return true;
1225-
switch (VD->getFormalAccess()) {
1229+
switch (Ctx.getAccessLevel(VD)) {
12261230
case AccessLevel::Internal:
12271231
case AccessLevel::Private:
12281232
case AccessLevel::FilePrivate:

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ class SDKContext {
188188
}
189189
bool isEqual(const SDKNode &Left, const SDKNode &Right);
190190
bool checkingABI() const { return Opts.ABI; }
191+
AccessLevel getAccessLevel(const ValueDecl *VD) const;
191192
const CheckerOptions &getOpts() const { return Opts; }
192193
ArrayRef<ABIAttributeInfo> getABIAttributeInfo() const { return ABIAttrs; }
193194

0 commit comments

Comments
 (0)