Skip to content

Commit c069090

Browse files
authored
Merge pull request swiftlang#18788 from brentdax/indigestion
Add some proper diagnostics to the API digester
2 parents 70bdea4 + 004ada9 commit c069090

File tree

6 files changed

+212
-109
lines changed

6 files changed

+212
-109
lines changed

include/swift/AST/DiagnosticsCommon.def

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ ERROR(attr_only_on_parameters, none,
9393
ERROR(function_type_no_parens,none,
9494
"single argument function types require parentheses", ())
9595

96+
// FIXME: Used by swift-api-digester. Don't want to set up a separate diagnostics
97+
// file just for a few errors.
98+
ERROR(sdk_node_unrecognized_key,none,
99+
"unrecognized key '%0' in SDK node", (StringRef))
100+
ERROR(sdk_node_unrecognized_node_kind,none,
101+
"unrecognized SDK node kind '%0'", (StringRef))
102+
ERROR(sdk_node_unrecognized_type_attr_kind,none,
103+
"unrecognized type attribute '%0' in SDK node", (StringRef))
104+
ERROR(sdk_node_unrecognized_decl_attr_kind,none,
105+
"unrecognized declaration attribute '%0' in SDK node", (StringRef))
106+
ERROR(sdk_node_unrecognized_decl_kind,none,
107+
"unrecognized declaration kind '%0' in SDK node", (StringRef))
108+
96109
//------------------------------------------------------------------------------
97110
// MARK: Circular reference diagnostics
98111
//------------------------------------------------------------------------------

include/swift/IDE/APIDigesterData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum class SDKNodeKind: uint8_t {
3333
#include "DigesterEnums.def"
3434
};
3535

36-
SDKNodeKind parseSDKNodeKind(StringRef Content);
36+
Optional<SDKNodeKind> parseSDKNodeKind(StringRef Content);
3737

3838
enum class NodeAnnotation: uint8_t{
3939
#define NODE_ANNOTATION(NAME) NAME,

lib/IDE/APIDigesterData.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ operator<<(raw_ostream &Out, const NodeAnnotation Value) {
3939
llvm_unreachable("Undefined SDK node kind.");
4040
}
4141

42-
SDKNodeKind swift::ide::api::parseSDKNodeKind(StringRef Content) {
43-
return llvm::StringSwitch<SDKNodeKind>(Content)
42+
Optional<SDKNodeKind> swift::ide::api::parseSDKNodeKind(StringRef Content) {
43+
return llvm::StringSwitch<Optional<SDKNodeKind>>(Content)
4444
#define NODE_KIND(NAME, VALUE) .Case(#VALUE, SDKNodeKind::NAME)
4545
#include "swift/IDE/DigesterEnums.def"
46+
.Default(None)
4647
;
4748
}
4849

@@ -326,7 +327,7 @@ serializeDiffItem(llvm::BumpPtrAllocator &Alloc,
326327
switch (parseDiffItemKind(DiffItemKind)) {
327328
case APIDiffItemKind::ADK_CommonDiffItem: {
328329
return new (Alloc.Allocate<CommonDiffItem>())
329-
CommonDiffItem(parseSDKNodeKind(NodeKind),
330+
CommonDiffItem(*parseSDKNodeKind(NodeKind),
330331
parseSDKNodeAnnotation(NodeAnnotation), ChildIndex,
331332
LeftUsr, RightUsr, LeftComment, RightComment, ModuleName);
332333
}

test/api-digester/diagnostics.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"kind": "Root",
3+
"name": "TopLevel",
4+
"printedName": "TopLevel",
5+
"badKey": ["foo", "bar", "baz"],
6+
"children": [
7+
{
8+
"kind": "Zyzyx",
9+
"typeAttributes": ["autoclosure", "fnord", "inout", "Available"],
10+
"declAttributes": ["Available", "Fnord", "ObjC", "inout"],
11+
"declKind": "Subroutine"
12+
}
13+
]
14+
}

test/api-digester/diagnostics.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// REQUIRES: OS=macosx
2+
// RUN: not %api-digester -deserialize-sdk -input-paths %S/diagnostics.json -o - 2>&1 | %FileCheck %s
3+
4+
// CHECK: diagnostics.json:5:3: error: unrecognized key 'badKey' in SDK node
5+
// CHECK: diagnostics.json:8:15: error: unrecognized SDK node kind 'Zyzyx'
6+
// CHECK: diagnostics.json:9:41: error: unrecognized type attribute 'fnord' in SDK node
7+
// CHECK: diagnostics.json:9:59: error: unrecognized type attribute 'Available' in SDK node
8+
// CHECK: diagnostics.json:10:39: error: unrecognized declaration attribute 'Fnord' in SDK node
9+
// CHECK: diagnostics.json:10:56: error: unrecognized declaration attribute 'inout' in SDK node
10+
// CHECK: diagnostics.json:11:19: error: unrecognized declaration kind 'Subroutine' in SDK node
11+
12+
// Make sure we don't try to output a result:
13+
// CHECK-NOT: "kind": "Root",

0 commit comments

Comments
 (0)