Skip to content

ABI/API checker: populate several lazily computed attributes to nodes #26940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions test/api-digester/Inputs/stdlib-stable-abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -21902,6 +21902,41 @@
],
"funcSelfKind": "NonMutating"
},
{
"kind": "Function",
"name": "_isConcrete",
"printedName": "_isConcrete(_:)",
"children": [
{
"kind": "TypeNominal",
"name": "Bool",
"printedName": "Swift.Bool",
"usr": "s:Sb"
},
{
"kind": "TypeNominal",
"name": "Metatype",
"printedName": "τ_0_0.Type",
"children": [
{
"kind": "TypeNominal",
"name": "GenericTypeParam",
"printedName": "τ_0_0"
}
]
}
],
"declKind": "Func",
"usr": "s:s11_isConcreteySbxmlF",
"moduleName": "Swift",
"genericSig": "<τ_0_0>",
"sugared_genericSig": "<T>",
"declAttributes": [
"Transparent",
"AlwaysEmitIntoClient"
],
"funcSelfKind": "NonMutating"
},
{
"kind": "Function",
"name": "_isBitwiseTakable",
Expand Down Expand Up @@ -35458,7 +35493,8 @@
"Final",
"ObjCNonLazyRealization",
"UsableFromInline",
"FixedLayout"
"FixedLayout",
"ObjC"
],
"superclassUsr": "c:@M@Swift@objc(cs)__ContiguousArrayStorageBase",
"superclassNames": [
Expand Down Expand Up @@ -49970,7 +50006,8 @@
"declAttributes": [
"ObjCNonLazyRealization",
"UsableFromInline",
"FixedLayout"
"FixedLayout",
"ObjC"
],
"superclassUsr": "c:@M@Swift@objc(cs)__SwiftNativeNSDictionary",
"superclassNames": [
Expand All @@ -49986,7 +50023,8 @@
"moduleName": "Swift",
"declAttributes": [
"UsableFromInline",
"FixedLayout"
"FixedLayout",
"ObjC"
],
"superclassUsr": "c:@M@Swift@objc(cs)__RawDictionaryStorage",
"superclassNames": [
Expand Down Expand Up @@ -115758,7 +115796,8 @@
"declAttributes": [
"ObjCNonLazyRealization",
"UsableFromInline",
"FixedLayout"
"FixedLayout",
"ObjC"
],
"superclassUsr": "c:@M@Swift@objc(cs)__SwiftNativeNSSet",
"superclassNames": [
Expand All @@ -115774,7 +115813,8 @@
"moduleName": "Swift",
"declAttributes": [
"UsableFromInline",
"FixedLayout"
"FixedLayout",
"ObjC"
],
"superclassUsr": "c:@M@Swift@objc(cs)__RawSetStorage",
"superclassNames": [
Expand Down Expand Up @@ -147323,7 +147363,8 @@
"moduleName": "Swift",
"declAttributes": [
"UsableFromInline",
"FixedLayout"
"FixedLayout",
"ObjC"
],
"superclassUsr": "c:@M@Swift@objc(cs)__SwiftNativeNSArray",
"superclassNames": [
Expand Down Expand Up @@ -147711,7 +147752,8 @@
"moduleName": "Swift",
"declAttributes": [
"FixedLayout",
"UsableFromInline"
"UsableFromInline",
"ObjC"
],
"superclassUsr": "c:@M@Swift@objc(cs)__SwiftNativeNSArrayWithContiguousStorage",
"superclassNames": [
Expand Down Expand Up @@ -299699,7 +299741,7 @@
"funcSelfKind": "NonMutating"
}
],
"json_format_version": 4,
"json_format_version": 5,
"tool_arguments": [
"-dump-sdk",
"-module",
Expand Down
13 changes: 11 additions & 2 deletions test/api-digester/Outputs/Cake-binary-vs-interface.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
// We shouldn't see this. rdar://54797231
cake: Class C4 is now with @objc
cake: Func FrozenKind.__derived_enum_equals(_:_:) has been removed
cake: Accessor GlobalLetChangedToVar.Get() is a new API without @available attribute
cake: Accessor GlobalVarChangedToLet.Get() is a new API without @available attribute
cake: Accessor GlobalVarChangedToLet.Modify() is a new API without @available attribute
cake: Accessor GlobalVarChangedToLet.Set() is a new API without @available attribute
cake: Enum FrozenKind is now with @frozen
cake: Enum IceKind is now with @frozen
cake: Func FrozenKind.==(_:_:) is a new API without @available attribute
cake: Var C1.CIIns1 is no longer a stored property
cake: Var C1.CIIns2 is no longer a stored property
cake: Var RemoveSetters.Value is no longer a stored property
2 changes: 1 addition & 1 deletion test/api-digester/Outputs/cake-abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1823,5 +1823,5 @@
]
}
],
"json_format_version": 4
"json_format_version": 5
}
2 changes: 1 addition & 1 deletion test/api-digester/Outputs/cake.json
Original file line number Diff line number Diff line change
Expand Up @@ -1674,5 +1674,5 @@
]
}
],
"json_format_version": 4
"json_format_version": 5
}
23 changes: 15 additions & 8 deletions test/api-digester/Outputs/clang-module-dump.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"protocolReq": true,
"objc_name": "anotherFunctionFromProt",
"declAttributes": [
"ObjC"
"ObjC",
"Dynamic"
],
"reqNewWitnessTableEntry": true,
"funcSelfKind": "NonMutating"
Expand All @@ -44,7 +45,8 @@
"moduleName": "Foo",
"objc_name": "AnotherObjcProt",
"declAttributes": [
"ObjC"
"ObjC",
"Dynamic"
]
},
{
Expand Down Expand Up @@ -76,7 +78,8 @@
"isOpen": true,
"objc_name": "someFunction",
"declAttributes": [
"ObjC"
"ObjC",
"Dynamic"
],
"funcSelfKind": "NonMutating"
},
Expand All @@ -100,7 +103,8 @@
"objc_name": "init",
"declAttributes": [
"Override",
"ObjC"
"ObjC",
"Dynamic"
]
}
],
Expand All @@ -110,7 +114,8 @@
"isOpen": true,
"objc_name": "ClangInterface",
"declAttributes": [
"ObjC"
"ObjC",
"Dynamic"
],
"superclassUsr": "c:objc(cs)NSObject",
"superclassNames": [
Expand Down Expand Up @@ -161,7 +166,8 @@
"protocolReq": true,
"objc_name": "someFunctionFromProt",
"declAttributes": [
"ObjC"
"ObjC",
"Dynamic"
],
"reqNewWitnessTableEntry": true,
"funcSelfKind": "NonMutating"
Expand All @@ -172,9 +178,10 @@
"moduleName": "Foo",
"objc_name": "ObjcProt",
"declAttributes": [
"ObjC"
"ObjC",
"Dynamic"
]
}
],
"json_format_version": 4
"json_format_version": 5
}
2 changes: 1 addition & 1 deletion test/api-digester/Outputs/empty-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"kind": "Root",
"name": "TopLevel",
"printedName": "TopLevel",
"json_format_version": 4
"json_format_version": 5
}
8 changes: 7 additions & 1 deletion test/api-digester/compare-dump-binary-vs-interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
// RUN: %empty-directory(%t.sdk)
// RUN: %empty-directory(%t.module-cache)

// The goal of this test to make sure flag -use-interface-for-module works.
// We first build .swiftinterface with -enable-library-evolution
// Secondly, we We first build .swiftmodule without -enable-library-evolution
// Using swift-api-digester to load via .swiftinterface and .swiftmodule should
// always give us some difference.

// Generate .swiftinterface file for module cake
// RUN: %target-swift-frontend -typecheck -emit-parseable-module-interface-path %t.mod1/cake.swiftinterface %S/Inputs/cake_baseline/cake.swift -I %S/Inputs/APINotesLeft %clang-importer-sdk-nosource -parse-as-library -enable-library-evolution -disable-objc-attr-requires-foundation-module -module-cache-path %t.module-cache

// Generate .swiftmodule file for module cake
// RUN: %target-swift-frontend -emit-module -o %t.mod1/cake.swiftmodule %S/Inputs/cake_baseline/cake.swift -I %S/Inputs/APINotesLeft %clang-importer-sdk-nosource -parse-as-library -disable-objc-attr-requires-foundation-module -module-cache-path %t.module-cache -enable-library-evolution
// RUN: %target-swift-frontend -emit-module -o %t.mod1/cake.swiftmodule %S/Inputs/cake_baseline/cake.swift -I %S/Inputs/APINotesLeft %clang-importer-sdk-nosource -parse-as-library -disable-objc-attr-requires-foundation-module -module-cache-path %t.module-cache

// Dump Json file for cake ABI via .swiftmodule file
// RUN: %api-digester -dump-sdk -module cake -o - -module-cache-path %t.module-cache %clang-importer-sdk-nosource -I %t.mod1 -I %S/Inputs/APINotesLeft -abi > %t.dump1.json
Expand Down
36 changes: 20 additions & 16 deletions tools/swift-api-digester/ModuleAnalyzerNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,24 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Type Ty, TypeInitInfo Info) :
}
}

static std::vector<DeclAttrKind> collectDeclAttributes(Decl *D) {
std::vector<DeclAttrKind> Results;
for (auto *Attr: D->getAttrs())
Results.push_back(Attr->getKind());
if (auto *VD = dyn_cast<ValueDecl>(D)) {
#define HANDLE(COND, KIND_NAME) \
if (VD->COND && !llvm::is_contained(Results, DeclAttrKind::KIND_NAME)) \
Results.emplace_back(DeclAttrKind::KIND_NAME);
// These attributes may be semantically applicable to the current decl but absent from
// the actual AST. Populting them to the nodes ensure we don't have false positives.
HANDLE(isObjC(), DAK_ObjC)
HANDLE(isFinal(), DAK_Final)
HANDLE(isDynamic(), DAK_Dynamic)
#undef HANDLE
}
return Results;
}

SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Decl *D):
Ctx(Ctx), DKind(D->getKind()),
Location(calculateLocation(Ctx, D)),
Expand All @@ -1294,22 +1312,8 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Decl *D):
ObjCName(Ctx.getObjcName(D)),
IsImplicit(D->isImplicit()),
IsDeprecated(D->getAttrs().getDeprecated(D->getASTContext())),
IsABIPlaceholder(isABIPlaceholderRecursive(D)) {

// Force some attributes that are lazily computed.
// FIXME: we should use these AST predicates directly instead of looking at
// the attributes rdar://50217247.
if (auto *VD = dyn_cast<ValueDecl>(D)) {
(void) VD->isObjC();
(void) VD->isFinal();
(void) VD->isDynamic();
}

// Capture all attributes.
auto AllAttrs = D->getAttrs();
std::transform(AllAttrs.begin(), AllAttrs.end(), std::back_inserter(DeclAttrs),
[](DeclAttribute *attr) { return attr->getKind(); });
}
IsABIPlaceholder(isABIPlaceholderRecursive(D)),
DeclAttrs(collectDeclAttributes(D)) {}

SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, OperatorDecl *OD):
SDKNodeInitInfo(Ctx, cast<Decl>(OD)) {
Expand Down
2 changes: 1 addition & 1 deletion tools/swift-api-digester/ModuleAnalyzerNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace api {
///
/// When the json format changes in a way that requires version-specific handling, this number should be incremented.
/// This ensures we could have backward compatibility so that version changes in the format won't stop the checker from working.
const uint8_t DIGESTER_JSON_VERSION = 4; // Add objc_name field
const uint8_t DIGESTER_JSON_VERSION = 5; // Populate ObjC, Dynamic and Final to attribute list
const uint8_t DIGESTER_JSON_DEFAULT_VERSION = 0; // Use this version number for files before we have a version number in json.

class SDKNode;
Expand Down