Skip to content

Commit 20b8d4c

Browse files
authored
Merge pull request #26643 from nkcsgexi/abi-checker-5.1-fix
[5.1] ABI/API checker: avoid printing fully qualified names in generic signature
2 parents 425a146 + 0f83231 commit 20b8d4c

File tree

10 files changed

+36
-21
lines changed

10 files changed

+36
-21
lines changed

test/api-digester/Inputs/cake_baseline/cake.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,5 @@ public class Zoo {
193193
return Cat()
194194
}
195195
}
196+
197+
public func returnFunctionTypeOwnershipChange() -> (C1) -> () { return { _ in } }

test/api-digester/Inputs/cake_current/cake.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,5 @@ public class Zoo {
200200
return Dog()
201201
}
202202
}
203+
204+
public func returnFunctionTypeOwnershipChange() -> (__owned C1) -> () { return { _ in } }

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/* Generic Signature Changes */
33
cake: Func P1.P1Constraint() has generic signature change from <τ_0_0 where τ_0_0 : P1, τ_0_0 : P2> to <τ_0_0 where τ_0_0 : P1>
4-
cake: Protocol P3 has generic signature change from <τ_0_0 : cake.P1, τ_0_0 : cake.P2> to <τ_0_0 : cake.P1, τ_0_0 : cake.P4>
4+
cake: Protocol P3 has generic signature change from <τ_0_0 : P1, τ_0_0 : P2> to <τ_0_0 : P1, τ_0_0 : P4>
55

66
/* RawRepresentable Changes */
77

@@ -44,6 +44,7 @@ cake: Func Somestruct2.foo1(_:) has parameter 0 type change from C3 to C1
4444
cake: Func Zoo.getCurrentAnimalInlinable() has return type change from Cat to Dog
4545
cake: Func ownershipChange(_:_:) has parameter 0 changing from InOut to Default
4646
cake: Func ownershipChange(_:_:) has parameter 1 changing from Shared to Owned
47+
cake: Func returnFunctionTypeOwnershipChange() has return type change from (C1) -> () to (__owned C1) -> ()
4748
cake: Var Zoo.current has declared type change from Cat to Dog
4849

4950
/* Decl Attribute changes */

test/api-digester/Outputs/Cake.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/* Generic Signature Changes */
33
cake: Func P1.P1Constraint() has generic signature change from <Self where Self : P1, Self : P2> to <Self where Self : P1>
4-
cake: Protocol P3 has generic signature change from <Self : cake.P1, Self : cake.P2> to <Self : cake.P1, Self : cake.P4>
4+
cake: Protocol P3 has generic signature change from <Self : P1, Self : P2> to <Self : P1, Self : P4>
55

66
/* RawRepresentable Changes */
77

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"declKind": "Protocol",
6060
"usr": "s:4cake2P3P",
6161
"moduleName": "cake",
62-
"genericSig": "<τ_0_0 : cake.P1, τ_0_0 : cake.P2>",
62+
"genericSig": "<τ_0_0 : P1, τ_0_0 : P2>",
6363
"conformances": [
6464
{
6565
"kind": "Conformance",
@@ -1238,7 +1238,7 @@
12381238
"declKind": "Protocol",
12391239
"usr": "s:4cake4PSubP",
12401240
"moduleName": "cake",
1241-
"genericSig": "<τ_0_0 : cake.PSuper>",
1241+
"genericSig": "<τ_0_0 : PSuper>",
12421242
"conformances": [
12431243
{
12441244
"kind": "Conformance",

test/api-digester/Outputs/cake.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"declKind": "Protocol",
6060
"usr": "s:4cake2P3P",
6161
"moduleName": "cake",
62-
"genericSig": "<Self : cake.P1, Self : cake.P2>",
62+
"genericSig": "<Self : P1, Self : P2>",
6363
"conformances": [
6464
{
6565
"kind": "Conformance",
@@ -1137,7 +1137,7 @@
11371137
"declKind": "Protocol",
11381138
"usr": "s:4cake4PSubP",
11391139
"moduleName": "cake",
1140-
"genericSig": "<Self : cake.PSuper>",
1140+
"genericSig": "<Self : PSuper>",
11411141
"conformances": [
11421142
{
11431143
"kind": "Conformance",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
Func BidirectionalCollection.difference(from:by:) has parameter 1 type change from (τ_0_0.Element, τ_1_0.Element) -> Bool to (τ_1_0.Element, τ_0_0.Element) -> Bool

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,14 @@ static bool isSDKNodeEqual(SDKContext &Ctx, const SDKNode &L, const SDKNode &R)
794794
return false;
795795
if (Left->getPrintedName() == Right->getPrintedName())
796796
return true;
797-
return Left->getName() == Right->getName() &&
798-
Left->hasSameChildren(*Right);
797+
if (Ctx.checkingABI()) {
798+
// For abi checking where we don't have sugar types at all, the printed
799+
// name difference is enough to indicate these two types differ.
800+
return false;
801+
} else {
802+
return Left->getName() == Right->getName() &&
803+
Left->hasSameChildren(*Right);
804+
}
799805
}
800806

801807
case SDKNodeKind::DeclFunction: {
@@ -1082,16 +1088,20 @@ StringRef printGenericSignature(SDKContext &Ctx, ArrayRef<Requirement> AllReqs)
10821088
return StringRef();
10831089
OS << "<";
10841090
bool First = true;
1091+
PrintOptions Opts = PrintOptions::printInterface();
1092+
// We always print unqualifed type names to avoid false positives introduced
1093+
// by the heuristics working differently.
1094+
Opts.FullyQualifiedTypesIfAmbiguous = false;
10851095
for (auto Req: AllReqs) {
10861096
if (!First) {
10871097
OS << ", ";
10881098
} else {
10891099
First = false;
10901100
}
10911101
if (Ctx.checkingABI())
1092-
getCanonicalRequirement(Req).print(OS, PrintOptions::printInterface());
1102+
getCanonicalRequirement(Req).print(OS, Opts);
10931103
else
1094-
Req.print(OS, PrintOptions::printInterface());
1104+
Req.print(OS, Opts);
10951105
}
10961106
OS << ">";
10971107
return Ctx.buffer(OS.str());
@@ -2077,7 +2087,7 @@ swift::ide::api::getSDKNodeRoot(SDKContext &SDKCtx,
20772087
if (Opts.Verbose)
20782088
llvm::errs() << "Loading module: " << Name << "...\n";
20792089
auto *M = Ctx.getModuleByName(Name);
2080-
if (!M) {
2090+
if (!M || M->failedToLoad()) {
20812091
llvm::errs() << "Failed to load module: " << Name << '\n';
20822092
if (Opts.AbortOnModuleLoadFailure)
20832093
return nullptr;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ void swift::ide::api::SDKNodeType::diagnose(SDKNode *Right) {
927927
}
928928

929929
void swift::ide::api::SDKNodeTypeFunc::diagnose(SDKNode *Right) {
930-
SDKNode::diagnose(Right);
930+
SDKNodeType::diagnose(Right);
931931
auto *RT = dyn_cast<SDKNodeTypeFunc>(Right);
932932
if (!RT || !shouldDiagnoseType(this))
933933
return;
@@ -2145,7 +2145,7 @@ static int diagnoseModuleChange(SDKContext &Ctx, SDKNodeRoot *LeftModule,
21452145
// Find member hoist changes to help refine diagnostics.
21462146
findTypeMemberDiffs(LeftModule, RightModule, Ctx.getTypeMemberDiffs());
21472147
DiagnosisEmitter::diagnosis(LeftModule, RightModule, Ctx);
2148-
return 0;
2148+
return options::CompilerStyleDiags && Ctx.getDiags().hadAnyError() ? 1 : 0;
21492149
}
21502150

21512151
static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
@@ -2167,7 +2167,7 @@ static int diagnoseModuleChange(StringRef LeftPath, StringRef RightPath,
21672167
RightCollector.deSerialize(RightPath);
21682168
diagnoseModuleChange(Ctx, LeftCollector.getSDKRoot(), RightCollector.getSDKRoot(),
21692169
OutputPath, std::move(ProtocolReqWhitelist));
2170-
return 0;
2170+
return options::CompilerStyleDiags && Ctx.getDiags().hadAnyError() ? 1 : 0;
21712171
}
21722172

21732173
static void populateAliasChanges(NodeMap &AliasMap, DiffVector &AllItems,

utils/api_checker/swift-api-checker.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ def get_api_digester_path(tool_path):
7373
class DumpConfig:
7474
def __init__(self, tool_path, platform):
7575
target_map = {
76-
'iphoneos': 'arm64-apple-ios10.0',
77-
'macosx': 'x86_64-apple-macosx10.11',
78-
'appletvos': 'arm64-apple-tvos10.0',
79-
'watchos': 'armv7k-apple-watchos3.0',
76+
'iphoneos': 'arm64-apple-ios13.0',
77+
'macosx': 'x86_64-apple-macosx10.15',
78+
'appletvos': 'arm64-apple-tvos13.0',
79+
'watchos': 'armv7k-apple-watchos6.0',
8080
}
8181
self.tool_path = get_api_digester_path(tool_path)
8282
self.platform = platform
@@ -149,8 +149,8 @@ def main():
149149
the output file of the module baseline should end with .json
150150
''')
151151

152-
basic_group.add_argument('--swift-version', default='4', help='''
153-
Swift version to use; default is 4
152+
basic_group.add_argument('--swift-version', default='5', help='''
153+
Swift version to use; default is 5
154154
''')
155155

156156
basic_group.add_argument('--module', default=None, help='''

0 commit comments

Comments
 (0)