diff --git a/include/swift/AST/ASTPrinter.h b/include/swift/AST/ASTPrinter.h index 47edd72820d..73cf9c131d5 100644 --- a/include/swift/AST/ASTPrinter.h +++ b/include/swift/AST/ASTPrinter.h @@ -36,6 +36,7 @@ namespace swift { class ValueDecl; class SourceLoc; enum class tok; + enum class AccessorKind; /// Describes the context in which a name is being printed, which /// affects the keywords that need to be escaped. @@ -339,6 +340,7 @@ void printEnumElementsAsCases( void getInheritedForPrinting(const Decl *decl, const PrintOptions &options, llvm::SmallVectorImpl &Results); +StringRef getAccessorKindString(AccessorKind value); } // namespace swift #endif // LLVM_SWIFT_AST_ASTPRINTER_H diff --git a/include/swift/AST/DiagnosticsCommon.def b/include/swift/AST/DiagnosticsCommon.def index 8e559bb01a8..a48f814df22 100644 --- a/include/swift/AST/DiagnosticsCommon.def +++ b/include/swift/AST/DiagnosticsCommon.def @@ -132,6 +132,8 @@ ERROR(sdk_node_unrecognized_decl_attr_kind,none, "unrecognized declaration attribute '%0' in SDK node", (StringRef)) ERROR(sdk_node_unrecognized_decl_kind,none, "unrecognized declaration kind '%0' in SDK node", (StringRef)) +ERROR(sdk_node_unrecognized_accessor_kind,none, + "unrecognized accessor kind '%0' in SDK node", (StringRef)) //------------------------------------------------------------------------------ // MARK: Circular reference diagnostics diff --git a/include/swift/AST/DiagnosticsModuleDiffer.def b/include/swift/AST/DiagnosticsModuleDiffer.def index 894ed29998a..6aed98056b0 100644 --- a/include/swift/AST/DiagnosticsModuleDiffer.def +++ b/include/swift/AST/DiagnosticsModuleDiffer.def @@ -42,8 +42,6 @@ ERROR(raw_type_change,none,"%0(%1) is now %2 representable", (StringRef, StringR ERROR(removed_decl,none,"%0 has been removed%select{| (deprecated)}1", (StringRef, bool)) -ERROR(removed_setter,none,"%0 has removed its setter", (StringRef)) - ERROR(moved_decl,none,"%0 has been moved to %1", (StringRef, StringRef)) ERROR(renamed_decl,none,"%0 has been renamed to %1", (StringRef, StringRef)) diff --git a/include/swift/IDE/DigesterEnums.def b/include/swift/IDE/DigesterEnums.def index 2ccb0a613ef..c9babe39a97 100644 --- a/include/swift/IDE/DigesterEnums.def +++ b/include/swift/IDE/DigesterEnums.def @@ -64,8 +64,7 @@ NODE_KIND_RANGE(Type, TypeNominal, TypeAlias) NODE_KIND(DeclFunction, Function) NODE_KIND(DeclConstructor, Constructor) -NODE_KIND(DeclGetter, Getter) -NODE_KIND(DeclSetter, Setter) +NODE_KIND(DeclAccessor, Accessor) NODE_KIND(DeclSubscript, Subscript) NODE_KIND_RANGE(DeclAbstractFunc, DeclFunction, DeclSubscript) @@ -126,13 +125,10 @@ KEY_BOOL(IsDeprecated, deprecated) KEY_BOOL(IsOverriding, overriding) KEY_BOOL(IsProtocolReq, protocolReq) KEY_BOOL(HasDefaultArg, hasDefaultArg) -KEY_BOOL(HasSetter, hasSetter) KEY_BOOL(IsLet, isLet) KEY_BOOL(IsOpen, isOpen) KEY_BOOL(IsInternal, isInternal) KEY_BOOL(HasStorage, hasStorage) -KEY_BOOL(HasDidset, hasDidset) -KEY_BOOL(HasWillset, hasWillset) KEY_BOOL(ReqNewWitnessTableEntry, reqNewWitnessTableEntry) KEY_BOOL(IsABIPlaceholder, isABIPlaceholder) KEY_BOOL(IsExternal, isExternal) @@ -166,6 +162,8 @@ KEY(typeAttributes) KEY(declAttributes) KEY(declKind) KEY(ownership) +KEY(accessors) +KEY(accessorKind) KNOWN_TYPE(Optional) KNOWN_TYPE(ImplicitlyUnwrappedOptional) diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index c35ffb2cdc1..a2281276f27 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -310,16 +310,6 @@ static StringRef getDefaultArgumentKindString(DefaultArgumentKind value) { llvm_unreachable("Unhandled DefaultArgumentKind in switch."); } -static StringRef getAccessorKindString(AccessorKind value) { - switch (value) { -#define ACCESSOR(ID) -#define SINGLETON_ACCESSOR(ID, KEYWORD) \ - case AccessorKind::ID: return #KEYWORD; -#include "swift/AST/AccessorKinds.def" - } - - llvm_unreachable("Unhandled AccessorKind in switch."); -} static StringRef getMagicIdentifierLiteralExprKindString(MagicIdentifierLiteralExpr::Kind value) { switch (value) { @@ -3759,3 +3749,14 @@ void GenericEnvironment::dump(raw_ostream &os) const { void GenericEnvironment::dump() const { dump(llvm::errs()); } + +StringRef swift::getAccessorKindString(AccessorKind value) { + switch (value) { +#define ACCESSOR(ID) +#define SINGLETON_ACCESSOR(ID, KEYWORD) \ + case AccessorKind::ID: return #KEYWORD; +#include "swift/AST/AccessorKinds.def" + } + + llvm_unreachable("Unhandled AccessorKind in switch."); +} \ No newline at end of file diff --git a/test/api-digester/Inputs/cake_baseline/cake.swift b/test/api-digester/Inputs/cake_baseline/cake.swift index b83af08ebf3..a0309ff7f8c 100644 --- a/test/api-digester/Inputs/cake_baseline/cake.swift +++ b/test/api-digester/Inputs/cake_baseline/cake.swift @@ -53,6 +53,9 @@ public struct fixedLayoutStruct { public var b = 2 public func foo() {} public var a = 1 + public var height: Int { + _read { yield 0 } + } } @usableFromInline diff --git a/test/api-digester/Inputs/cake_current/cake.swift b/test/api-digester/Inputs/cake_current/cake.swift index df54719b3b3..5785984e629 100644 --- a/test/api-digester/Inputs/cake_current/cake.swift +++ b/test/api-digester/Inputs/cake_current/cake.swift @@ -57,6 +57,9 @@ public struct fixedLayoutStruct { public func foo() {} private var c = 3 private lazy var lazy_d = 4 + public var height: Int { + get { return 0 } + } } @usableFromInline diff --git a/test/api-digester/Outputs/Cake-abi.txt b/test/api-digester/Outputs/Cake-abi.txt index 0d7d7774339..1f841cd245e 100644 --- a/test/api-digester/Outputs/Cake-abi.txt +++ b/test/api-digester/Outputs/Cake-abi.txt @@ -7,16 +7,18 @@ cake: Protocol P3 has generic signature change from <τ_0_0 : cake.P1, τ_0_0 : /* Removed Decls */ Swift: Extension Int has been removed +cake: Accessor GlobalVarChangedToLet.Modify() has been removed cake: Accessor GlobalVarChangedToLet.Set() has been removed +cake: Accessor RemoveSetters.Value.Modify() has been removed cake: Accessor RemoveSetters.Value.Set() has been removed +cake: Accessor RemoveSetters.subscript(_:).Modify() has been removed +cake: Accessor RemoveSetters.subscript(_:).Set() has been removed +cake: Accessor fixedLayoutStruct.height.Read() has been removed cake: AssociatedType RequiementChanges.removedType has been removed cake: Class C3 has been removed cake: Constructor Somestruct2.init(_:) has been removed cake: Func C4.foo() has been removed cake: Func RequiementChanges.removedFunc() has been removed -cake: Subscript RemoveSetters.subscript(_:) has removed its setter -cake: Var GlobalVarChangedToLet has removed its setter -cake: Var RemoveSetters.Value has removed its setter cake: Var RequiementChanges.removedVar has been removed /* Moved Decls */ @@ -42,7 +44,9 @@ cake: Func ownershipChange(_:_:) has parameter 0 changing from InOut to Default cake: Func ownershipChange(_:_:) has parameter 1 changing from Shared to Owned /* Decl Attribute changes */ +cake: Accessor GlobalLetChangedToVar.Modify() is a new API without @available attribute cake: Accessor GlobalLetChangedToVar.Set() is a new API without @available attribute +cake: Accessor fixedLayoutStruct2.BecomeFixedBinaryOrder.Modify() is a new API without @available attribute cake: Accessor fixedLayoutStruct2.BecomeFixedBinaryOrder.Set() is a new API without @available attribute cake: AssociatedType RequiementChanges.addedTypeWithDefault is a new API without @available attribute cake: AssociatedType RequiementChanges.addedTypeWithoutDefault is a new API without @available attribute diff --git a/test/api-digester/Outputs/Cake.txt b/test/api-digester/Outputs/Cake.txt index 3a1b8dda861..4dd7e49479b 100644 --- a/test/api-digester/Outputs/Cake.txt +++ b/test/api-digester/Outputs/Cake.txt @@ -9,13 +9,11 @@ cake: Protocol P3 has generic signature change from " - }, + } + ], + "declKind": "Var", + "usr": "s:4cake2C1C3InsACSgvp", + "moduleName": "cake", + "declAttributes": [ + "HasInitialValue", + "ReferenceOwnership", + "HasStorage" + ], + "fixedbinaryorder": 0, + "ownership": 1, + "hasStorage": true, + "accessors": [ { - "kind": "Getter", + "kind": "Accessor", "name": "Get", "printedName": "Get()", "children": [ @@ -254,10 +267,11 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "get" }, { - "kind": "Setter", + "kind": "Accessor", "name": "Set", "printedName": "Set()", "children": [ @@ -287,20 +301,30 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "set" + }, + { + "kind": "Accessor", + "name": "Modify", + "printedName": "Modify()", + "children": [ + { + "kind": "TypeNominal", + "name": "Void", + "printedName": "()" + } + ], + "declKind": "Accessor", + "usr": "s:4cake2C1C3InsACSgvM", + "moduleName": "cake", + "implicit": true, + "declAttributes": [ + "Transparent" + ], + "accessorKind": "_modify" } - ], - "declKind": "Var", - "usr": "s:4cake2C1C3InsACSgvp", - "moduleName": "cake", - "declAttributes": [ - "HasInitialValue", - "ReferenceOwnership", - "HasStorage" - ], - "fixedbinaryorder": 0, - "ownership": 1, - "hasStorage": true + ] }, { "kind": "Var", @@ -311,9 +335,22 @@ "kind": "TypeNominal", "name": "UnownedStorage", "printedName": "C1" - }, + } + ], + "declKind": "Var", + "usr": "s:4cake2C1C4Ins2ACvp", + "moduleName": "cake", + "declAttributes": [ + "HasInitialValue", + "ReferenceOwnership", + "HasStorage" + ], + "fixedbinaryorder": 1, + "ownership": 2, + "hasStorage": true, + "accessors": [ { - "kind": "Getter", + "kind": "Accessor", "name": "Get", "printedName": "Get()", "children": [ @@ -330,10 +367,11 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "get" }, { - "kind": "Setter", + "kind": "Accessor", "name": "Set", "printedName": "Set()", "children": [ @@ -355,20 +393,30 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "set" + }, + { + "kind": "Accessor", + "name": "Modify", + "printedName": "Modify()", + "children": [ + { + "kind": "TypeNominal", + "name": "Void", + "printedName": "()" + } + ], + "declKind": "Accessor", + "usr": "s:4cake2C1C4Ins2ACvM", + "moduleName": "cake", + "implicit": true, + "declAttributes": [ + "Transparent" + ], + "accessorKind": "_modify" } - ], - "declKind": "Var", - "usr": "s:4cake2C1C4Ins2ACvp", - "moduleName": "cake", - "declAttributes": [ - "HasInitialValue", - "ReferenceOwnership", - "HasStorage" - ], - "fixedbinaryorder": 1, - "ownership": 2, - "hasStorage": true + ] } ], "declKind": "Class", @@ -523,9 +571,15 @@ "name": "Int", "printedName": "Int", "usr": "s:Si" - }, + } + ], + "declKind": "Var", + "usr": "s:4cake6NumberO8rawValueSivp", + "moduleName": "cake", + "implicit": true, + "accessors": [ { - "kind": "Getter", + "kind": "Accessor", "name": "Get", "printedName": "Get()", "children": [ @@ -542,13 +596,10 @@ "implicit": true, "declAttributes": [ "Inlinable" - ] + ], + "accessorKind": "get" } - ], - "declKind": "Var", - "usr": "s:4cake6NumberO8rawValueSivp", - "moduleName": "cake", - "implicit": true + ] } ], "declKind": "Enum", @@ -642,9 +693,20 @@ "name": "Int", "printedName": "Int", "usr": "s:Si" - }, + } + ], + "declKind": "Var", + "usr": "s:4cake17fixedLayoutStructV1aSivp", + "moduleName": "cake", + "declAttributes": [ + "HasInitialValue", + "HasStorage" + ], + "fixedbinaryorder": 0, + "hasStorage": true, + "accessors": [ { - "kind": "Getter", + "kind": "Accessor", "name": "Get", "printedName": "Get()", "children": [ @@ -661,10 +723,11 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "get" }, { - "kind": "Setter", + "kind": "Accessor", "name": "Set", "printedName": "Set()", "children": [ @@ -686,18 +749,30 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "set" + }, + { + "kind": "Accessor", + "name": "Modify", + "printedName": "Modify()", + "children": [ + { + "kind": "TypeNominal", + "name": "Void", + "printedName": "()" + } + ], + "declKind": "Accessor", + "usr": "s:4cake17fixedLayoutStructV1aSivM", + "moduleName": "cake", + "implicit": true, + "declAttributes": [ + "Transparent" + ], + "accessorKind": "_modify" } - ], - "declKind": "Var", - "usr": "s:4cake17fixedLayoutStructV1aSivp", - "moduleName": "cake", - "declAttributes": [ - "HasInitialValue", - "HasStorage" - ], - "fixedbinaryorder": 0, - "hasStorage": true + ] }, { "kind": "Var", @@ -709,27 +784,6 @@ "name": "Int", "printedName": "Int", "usr": "s:Si" - }, - { - "kind": "Getter", - "name": "Get", - "printedName": "Get()", - "children": [ - { - "kind": "TypeNominal", - "name": "Int", - "printedName": "Int", - "usr": "s:Si" - } - ], - "declKind": "Accessor", - "usr": "s:4cake17fixedLayoutStructV1b33_3D8926C30F7417F2EF9A277D0C73FBDBLLSivg", - "moduleName": "cake", - "implicit": true, - "isInternal": true, - "declAttributes": [ - "Transparent" - ] } ], "declKind": "Var", @@ -741,9 +795,7 @@ "HasStorage" ], "fixedbinaryorder": 1, - "hasStorage": true, - "hasDidset": true, - "hasWillset": true + "hasStorage": true }, { "kind": "Var", @@ -755,27 +807,6 @@ "name": "Int", "printedName": "Int", "usr": "s:Si" - }, - { - "kind": "Getter", - "name": "Get", - "printedName": "Get()", - "children": [ - { - "kind": "TypeNominal", - "name": "Int", - "printedName": "Int", - "usr": "s:Si" - } - ], - "declKind": "Accessor", - "usr": "s:4cake17fixedLayoutStructV1cSivg", - "moduleName": "cake", - "implicit": true, - "isInternal": true, - "declAttributes": [ - "Transparent" - ] } ], "declKind": "Var", @@ -799,9 +830,22 @@ "name": "Int", "printedName": "Int", "usr": "s:Si" - }, + } + ], + "declKind": "Var", + "usr": "s:4cake17fixedLayoutStructV19unavailablePropertySivp", + "moduleName": "cake", + "declAttributes": [ + "HasInitialValue", + "Available", + "HasStorage" + ], + "fixedbinaryorder": 3, + "isLet": true, + "hasStorage": true, + "accessors": [ { - "kind": "Getter", + "kind": "Accessor", "name": "Get", "printedName": "Get()", "children": [ @@ -818,20 +862,10 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "get" } - ], - "declKind": "Var", - "usr": "s:4cake17fixedLayoutStructV19unavailablePropertySivp", - "moduleName": "cake", - "declAttributes": [ - "HasInitialValue", - "Available", - "HasStorage" - ], - "fixedbinaryorder": 3, - "isLet": true, - "hasStorage": true + ] } ], "declKind": "Struct", @@ -899,9 +933,14 @@ "name": "Int", "printedName": "Int", "usr": "s:Si" - }, + } + ], + "declKind": "Var", + "usr": "s:4cake21ProWithAssociatedTypePAAE9NonReqVarSivp", + "moduleName": "cake", + "accessors": [ { - "kind": "Getter", + "kind": "Accessor", "name": "Get", "printedName": "Get()", "children": [ @@ -915,12 +954,10 @@ "declKind": "Accessor", "usr": "s:4cake21ProWithAssociatedTypePAAE9NonReqVarSivg", "moduleName": "cake", - "genericSig": "<τ_0_0 where τ_0_0 : ProWithAssociatedType>" + "genericSig": "<τ_0_0 where τ_0_0 : ProWithAssociatedType>", + "accessorKind": "get" } - ], - "declKind": "Var", - "usr": "s:4cake21ProWithAssociatedTypePAAE9NonReqVarSivp", - "moduleName": "cake" + ] } ], "declKind": "Protocol", @@ -954,7 +991,35 @@ "usr": "s:4cake13SubsContainerP6getterS2i_tcip", "moduleName": "cake", "genericSig": "<τ_0_0 where τ_0_0 : SubsContainer>", - "protocolReq": true + "protocolReq": true, + "accessors": [ + { + "kind": "Accessor", + "name": "Get", + "printedName": "Get()", + "children": [ + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + }, + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + } + ], + "declKind": "Accessor", + "usr": "s:4cake13SubsContainerP6getterS2i_tcig", + "moduleName": "cake", + "genericSig": "<τ_0_0 where τ_0_0 : SubsContainer>", + "protocolReq": true, + "reqNewWitnessTableEntry": true, + "accessorKind": "get" + } + ] }, { "kind": "Subscript", @@ -979,7 +1044,91 @@ "moduleName": "cake", "genericSig": "<τ_0_0 where τ_0_0 : SubsContainer>", "protocolReq": true, - "hasSetter": true + "accessors": [ + { + "kind": "Accessor", + "name": "Get", + "printedName": "Get()", + "children": [ + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + }, + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + } + ], + "declKind": "Accessor", + "usr": "s:4cake13SubsContainerP6setterS2i_tcig", + "moduleName": "cake", + "genericSig": "<τ_0_0 where τ_0_0 : SubsContainer>", + "protocolReq": true, + "reqNewWitnessTableEntry": true, + "accessorKind": "get" + }, + { + "kind": "Accessor", + "name": "Set", + "printedName": "Set()", + "children": [ + { + "kind": "TypeNominal", + "name": "Void", + "printedName": "()" + }, + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + }, + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + } + ], + "declKind": "Accessor", + "usr": "s:4cake13SubsContainerP6setterS2i_tcis", + "moduleName": "cake", + "genericSig": "<τ_0_0 where τ_0_0 : SubsContainer>", + "protocolReq": true, + "reqNewWitnessTableEntry": true, + "accessorKind": "set" + }, + { + "kind": "Accessor", + "name": "Modify", + "printedName": "Modify()", + "children": [ + { + "kind": "TypeNominal", + "name": "Void", + "printedName": "()" + }, + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + } + ], + "declKind": "Accessor", + "usr": "s:4cake13SubsContainerP6setterS2i_tciM", + "moduleName": "cake", + "genericSig": "<τ_0_0 where τ_0_0 : SubsContainer>", + "protocolReq": true, + "implicit": true, + "reqNewWitnessTableEntry": true, + "accessorKind": "_modify" + } + ] } ], "declKind": "Protocol", @@ -1144,27 +1293,6 @@ "name": "Int", "printedName": "Int", "usr": "s:Si" - }, - { - "kind": "Getter", - "name": "Get", - "printedName": "Get()", - "children": [ - { - "kind": "TypeNominal", - "name": "Int", - "printedName": "Int", - "usr": "s:Si" - } - ], - "declKind": "Accessor", - "usr": "s:4cake21UsableFromInlineClassC4Prop33_3D8926C30F7417F2EF9A277D0C73FBDBLLSivg", - "moduleName": "cake", - "implicit": true, - "isInternal": true, - "declAttributes": [ - "Transparent" - ] } ], "declKind": "Var", diff --git a/test/api-digester/Outputs/cake.json b/test/api-digester/Outputs/cake.json index d165a84a257..3216f94e912 100644 --- a/test/api-digester/Outputs/cake.json +++ b/test/api-digester/Outputs/cake.json @@ -271,9 +271,21 @@ "kind": "TypeNominal", "name": "WeakStorage", "printedName": "C1?" - }, + } + ], + "declKind": "Var", + "usr": "s:4cake2C1C3InsACSgvp", + "moduleName": "cake", + "declAttributes": [ + "HasInitialValue", + "ReferenceOwnership", + "HasStorage" + ], + "ownership": 1, + "hasStorage": true, + "accessors": [ { - "kind": "Getter", + "kind": "Accessor", "name": "Get", "printedName": "Get()", "children": [ @@ -298,10 +310,11 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "get" }, { - "kind": "Setter", + "kind": "Accessor", "name": "Set", "printedName": "Set()", "children": [ @@ -331,19 +344,10 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "set" } - ], - "declKind": "Var", - "usr": "s:4cake2C1C3InsACSgvp", - "moduleName": "cake", - "declAttributes": [ - "HasInitialValue", - "ReferenceOwnership", - "HasStorage" - ], - "ownership": 1, - "hasStorage": true + ] }, { "kind": "Var", @@ -354,9 +358,21 @@ "kind": "TypeNominal", "name": "UnownedStorage", "printedName": "C1" - }, + } + ], + "declKind": "Var", + "usr": "s:4cake2C1C4Ins2ACvp", + "moduleName": "cake", + "declAttributes": [ + "HasInitialValue", + "ReferenceOwnership", + "HasStorage" + ], + "ownership": 2, + "hasStorage": true, + "accessors": [ { - "kind": "Getter", + "kind": "Accessor", "name": "Get", "printedName": "Get()", "children": [ @@ -373,10 +389,11 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "get" }, { - "kind": "Setter", + "kind": "Accessor", "name": "Set", "printedName": "Set()", "children": [ @@ -398,19 +415,10 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "set" } - ], - "declKind": "Var", - "usr": "s:4cake2C1C4Ins2ACvp", - "moduleName": "cake", - "declAttributes": [ - "HasInitialValue", - "ReferenceOwnership", - "HasStorage" - ], - "ownership": 2, - "hasStorage": true + ] } ], "declKind": "Class", @@ -588,9 +596,15 @@ "name": "Int", "printedName": "Int", "usr": "s:Si" - }, + } + ], + "declKind": "Var", + "usr": "s:4cake6NumberO8rawValueSivp", + "moduleName": "cake", + "implicit": true, + "accessors": [ { - "kind": "Getter", + "kind": "Accessor", "name": "Get", "printedName": "Get()", "children": [ @@ -607,13 +621,10 @@ "implicit": true, "declAttributes": [ "Inlinable" - ] + ], + "accessorKind": "get" } - ], - "declKind": "Var", - "usr": "s:4cake6NumberO8rawValueSivp", - "moduleName": "cake", - "implicit": true + ] } ], "declKind": "Enum", @@ -707,9 +718,19 @@ "name": "Int", "printedName": "Int", "usr": "s:Si" - }, + } + ], + "declKind": "Var", + "usr": "s:4cake17fixedLayoutStructV1aSivp", + "moduleName": "cake", + "declAttributes": [ + "HasInitialValue", + "HasStorage" + ], + "hasStorage": true, + "accessors": [ { - "kind": "Getter", + "kind": "Accessor", "name": "Get", "printedName": "Get()", "children": [ @@ -726,10 +747,11 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "get" }, { - "kind": "Setter", + "kind": "Accessor", "name": "Set", "printedName": "Set()", "children": [ @@ -751,17 +773,10 @@ "implicit": true, "declAttributes": [ "Transparent" - ] + ], + "accessorKind": "set" } - ], - "declKind": "Var", - "usr": "s:4cake17fixedLayoutStructV1aSivp", - "moduleName": "cake", - "declAttributes": [ - "HasInitialValue", - "HasStorage" - ], - "hasStorage": true + ] } ], "declKind": "Struct", @@ -829,9 +844,14 @@ "name": "Int", "printedName": "Int", "usr": "s:Si" - }, + } + ], + "declKind": "Var", + "usr": "s:4cake21ProWithAssociatedTypePAAE9NonReqVarSivp", + "moduleName": "cake", + "accessors": [ { - "kind": "Getter", + "kind": "Accessor", "name": "Get", "printedName": "Get()", "children": [ @@ -845,12 +865,10 @@ "declKind": "Accessor", "usr": "s:4cake21ProWithAssociatedTypePAAE9NonReqVarSivg", "moduleName": "cake", - "genericSig": "" + "genericSig": "", + "accessorKind": "get" } - ], - "declKind": "Var", - "usr": "s:4cake21ProWithAssociatedTypePAAE9NonReqVarSivp", - "moduleName": "cake" + ] }, { "kind": "TypeAlias", @@ -901,7 +919,35 @@ "usr": "s:4cake13SubsContainerP6getterS2i_tcip", "moduleName": "cake", "genericSig": "", - "protocolReq": true + "protocolReq": true, + "accessors": [ + { + "kind": "Accessor", + "name": "Get", + "printedName": "Get()", + "children": [ + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + }, + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + } + ], + "declKind": "Accessor", + "usr": "s:4cake13SubsContainerP6getterS2i_tcig", + "moduleName": "cake", + "genericSig": "", + "protocolReq": true, + "reqNewWitnessTableEntry": true, + "accessorKind": "get" + } + ] }, { "kind": "Subscript", @@ -926,7 +972,65 @@ "moduleName": "cake", "genericSig": "", "protocolReq": true, - "hasSetter": true + "accessors": [ + { + "kind": "Accessor", + "name": "Get", + "printedName": "Get()", + "children": [ + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + }, + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + } + ], + "declKind": "Accessor", + "usr": "s:4cake13SubsContainerP6setterS2i_tcig", + "moduleName": "cake", + "genericSig": "", + "protocolReq": true, + "reqNewWitnessTableEntry": true, + "accessorKind": "get" + }, + { + "kind": "Accessor", + "name": "Set", + "printedName": "Set()", + "children": [ + { + "kind": "TypeNominal", + "name": "Void", + "printedName": "()" + }, + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + }, + { + "kind": "TypeNominal", + "name": "Int", + "printedName": "Int", + "usr": "s:Si" + } + ], + "declKind": "Accessor", + "usr": "s:4cake13SubsContainerP6setterS2i_tcis", + "moduleName": "cake", + "genericSig": "", + "protocolReq": true, + "reqNewWitnessTableEntry": true, + "accessorKind": "set" + } + ] } ], "declKind": "Protocol", diff --git a/tools/swift-api-digester/ModuleAnalyzerNodes.cpp b/tools/swift-api-digester/ModuleAnalyzerNodes.cpp index b830d8bb69f..28fe6e31ed6 100644 --- a/tools/swift-api-digester/ModuleAnalyzerNodes.cpp +++ b/tools/swift-api-digester/ModuleAnalyzerNodes.cpp @@ -27,6 +27,7 @@ static StringRef getAttrName(DeclAttrKind Kind) { struct swift::ide::api::SDKNodeInitInfo { SDKContext &Ctx; DeclKind DKind; + AccessorKind AccKind; #define KEY_STRING(X, Y) StringRef X; #include "swift/IDE/DigesterEnums.def" @@ -128,8 +129,7 @@ SDKNodeDeclTypeAlias::SDKNodeDeclTypeAlias(SDKNodeInitInfo Info): SDKNodeDeclVar::SDKNodeDeclVar(SDKNodeInitInfo Info): SDKNodeDecl(Info, SDKNodeKind::DeclVar), IsLet(Info.IsLet), - HasStorage(Info.HasStorage), HasDidSet(Info.HasDidset), - HasWillSet(Info.HasWillset) {} + HasStorage(Info.HasStorage) {} SDKNodeDeclAbstractFunc::SDKNodeDeclAbstractFunc(SDKNodeInitInfo Info, SDKNodeKind Kind): SDKNodeDecl(Info, Kind), IsThrowing(Info.IsThrowing), @@ -143,19 +143,16 @@ SDKNodeDeclFunction::SDKNodeDeclFunction(SDKNodeInitInfo Info): SDKNodeDeclConstructor::SDKNodeDeclConstructor(SDKNodeInitInfo Info): SDKNodeDeclAbstractFunc(Info, SDKNodeKind::DeclConstructor) {} -SDKNodeDeclGetter::SDKNodeDeclGetter(SDKNodeInitInfo Info): - SDKNodeDeclAbstractFunc(Info, SDKNodeKind::DeclGetter) {} - -SDKNodeDeclSetter::SDKNodeDeclSetter(SDKNodeInitInfo Info): - SDKNodeDeclAbstractFunc(Info, SDKNodeKind::DeclSetter) {} +SDKNodeDeclAccessor::SDKNodeDeclAccessor(SDKNodeInitInfo Info): + SDKNodeDeclAbstractFunc(Info, SDKNodeKind::DeclAccessor), + AccKind(Info.AccKind) {} SDKNodeDeclAssociatedType::SDKNodeDeclAssociatedType(SDKNodeInitInfo Info): SDKNodeDecl(Info, SDKNodeKind::DeclAssociatedType) {}; SDKNodeDeclSubscript::SDKNodeDeclSubscript(SDKNodeInitInfo Info): SDKNodeDeclAbstractFunc(Info, SDKNodeKind::DeclSubscript), - HasSetter(Info.HasSetter), HasStorage(Info.HasStorage), - HasDidSet(Info.HasDidset), HasWillSet(Info.HasWillset) {} + HasStorage(Info.HasStorage) {} StringRef SDKNodeDecl::getHeaderName() const { if (Location.empty()) @@ -163,22 +160,22 @@ StringRef SDKNodeDecl::getHeaderName() const { return llvm::sys::path::filename(Location.split(":").first); } -SDKNodeDeclGetter *SDKNodeDeclVar::getGetter() const { - auto children = getChildren(); - for (unsigned I = 1, N = children.size(); I < N; I ++) { - if (auto *getter = dyn_cast(children[I])) - return getter; +static SDKNodeDeclAccessor *getAccessorInternal(ArrayRef Accessors, + AccessorKind Kind) { + for (auto *AC: Accessors) { + if (cast(AC)->getAccessorKind() == Kind) { + return cast(AC); + } } return nullptr; } -SDKNodeDeclSetter *SDKNodeDeclVar::getSetter() const { - auto children = getChildren(); - for (unsigned I = 1, N = children.size(); I < N; I ++) { - if (auto *getter = dyn_cast(children[I])) - return getter; - } - return nullptr; +SDKNodeDeclAccessor *SDKNodeDeclVar::getAccessor(AccessorKind Kind) const { + return getAccessorInternal(Accessors, Kind); +} + +SDKNodeDeclAccessor *SDKNodeDeclSubscript::getAccessor(AccessorKind Kind) const { + return getAccessorInternal(Accessors, Kind); } SDKNodeType *SDKNodeDeclVar::getType() const { @@ -351,8 +348,7 @@ StringRef SDKNodeType::getTypeRoleDescription() const { llvm_unreachable("Type Parent is wrong"); case SDKNodeKind::DeclFunction: case SDKNodeKind::DeclConstructor: - case SDKNodeKind::DeclGetter: - case SDKNodeKind::DeclSetter: + case SDKNodeKind::DeclAccessor: case SDKNodeKind::DeclSubscript: return SDKNodeDeclAbstractFunc::getTypeRoleDescription(Ctx, P->getChildIndex(this)); @@ -399,6 +395,11 @@ StringRef SDKNodeDecl::getScreenInfo() const { } void SDKNodeDecl::printFullyQualifiedName(llvm::raw_ostream &OS) const { + if (auto *ACC = dyn_cast(this)) { + ACC->getStorage()->printFullyQualifiedName(OS); + OS << "." << getPrintedName(); + return; + } std::vector Parent; for (auto *P = getParent(); isa(P); P = P->getParent()) Parent.push_back(P); @@ -454,6 +455,16 @@ void SDKNodeDeclType::addConformance(SDKNode *Conf) { Conformances.push_back(Conf); } +void SDKNodeDeclSubscript::addAccessor(SDKNode *AC) { + cast(AC)->Owner = this; + Accessors.push_back(AC); +} + +void SDKNodeDeclVar::addAccessor(SDKNode *AC) { + cast(AC)->Owner = this; + Accessors.push_back(AC); +} + SDKNodeType *SDKNodeTypeWitness::getUnderlyingType() const { return getOnlyChild()->getAs(); } @@ -531,8 +542,7 @@ static Optional parseKeyKind(StringRef Content) { return llvm::StringSwitch>(Content) #define KEY(NAME) .Case(#NAME, KeyKind::KK_##NAME) #include "swift/IDE/DigesterEnums.def" - .Default(None) - ; + .Default(None); } static StringRef getKeyContent(SDKContext &Ctx, KeyKind Kind) { @@ -562,6 +572,7 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx, SDKNodeInitInfo Info(Ctx); NodeVector Children; NodeVector Conformances; + NodeVector Accessors; for (auto &Pair : *Node) { auto keyString = GetScalarString(Pair.getKey()); @@ -641,6 +652,27 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx, }); break; } + case KeyKind::KK_accessors: { + for (auto &Mapping : *cast(Pair.getValue())) { + Accessors.push_back(constructSDKNode(Ctx, + cast(&Mapping))); + } + break; + } + case KeyKind::KK_accessorKind: { + AccessorKind unknownKind = (AccessorKind)((uint8_t)(AccessorKind::Last) + 1); + Info.AccKind = llvm::StringSwitch( + GetScalarString(Pair.getValue())) +#define ACCESSOR(ID) +#define SINGLETON_ACCESSOR(ID, KEYWORD) .Case(#KEYWORD, AccessorKind::ID) +#include "swift/AST/AccessorKinds.def" + .Default(unknownKind); + if (Info.AccKind == unknownKind) { + Ctx.diagnose(Pair.getValue(), diag::sdk_node_unrecognized_accessor_kind, + GetScalarString(Pair.getValue())); + } + break; + } case KeyKind::KK_declKind: { auto dKind = llvm::StringSwitch>( GetScalarString(Pair.getValue())) @@ -669,6 +701,13 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx, for (auto *Conf: Conformances) { cast(Result)->addConformance(Conf); } + for (auto *Acc: Accessors) { + if (auto *SD = dyn_cast(Result)) { + SD->addAccessor(Acc); + } else if (auto *VD = dyn_cast(Result)) { + VD->addAccessor(Acc); + } + } return Result; } @@ -768,9 +807,7 @@ static bool isSDKNodeEqual(SDKContext &Ctx, const SDKNode &L, const SDKNode &R) return false; LLVM_FALLTHROUGH; } - case SDKNodeKind::DeclConstructor: - case SDKNodeKind::DeclGetter: - case SDKNodeKind::DeclSetter: { + case SDKNodeKind::DeclConstructor: { auto Left = L.getAs(); auto Right = R.getAs(); if (Left->isThrowing() ^ Right->isThrowing()) @@ -779,18 +816,24 @@ static bool isSDKNodeEqual(SDKContext &Ctx, const SDKNode &L, const SDKNode &R) return false; LLVM_FALLTHROUGH; } + case SDKNodeKind::DeclAccessor: { + if (auto *LA = dyn_cast(&L)) { + if (auto *RA = dyn_cast(&R)) { + if (LA->getAccessorKind() != RA->getAccessorKind()) + return false; + } + } + LLVM_FALLTHROUGH; + } case SDKNodeKind::DeclVar: { - if (Ctx.checkingABI()) { - // If we're checking ABI, the definition order matters. - // If they're both members for fixed layout types, we never consider - // them equal because we need to check definition orders. - if (auto *LV = dyn_cast(&L)) { - if (auto *RV = dyn_cast(&R)) { - if (LV->isLet() != RV->isLet()) - return false; + if (auto *LV = dyn_cast(&L)) { + if (auto *RV = dyn_cast(&R)) { + if (Ctx.checkingABI()) { if (LV->hasStorage() != RV->hasStorage()) return false; } + if (!hasSameContents(LV->getAllAccessors(), RV->getAllAccessors())) + return false; } } LLVM_FALLTHROUGH; @@ -815,7 +858,7 @@ static bool isSDKNodeEqual(SDKContext &Ctx, const SDKNode &L, const SDKNode &R) case SDKNodeKind::DeclSubscript: { if (auto *Left = dyn_cast(&L)) { if (auto *Right = dyn_cast(&R)) { - if (Left->hasSetter() != Right->hasSetter()) + if (!hasSameContents(Left->getAllAccessors(), Right->getAllAccessors())) return false; } } @@ -1299,15 +1342,11 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD) if (auto *VAD = dyn_cast(VD)) { IsLet = VAD->isLet(); } - // Record whether a subscript has getter/setter. - if (auto *SD = dyn_cast(VD)) { - HasSetter = SD->getSetter(); - } - if (auto *VAR = dyn_cast(VD)) { HasStorage = VAR->hasStorage(); - HasDidset = VAR->getDidSetFunc(); - HasWillset = VAR->getWillSetFunc(); + } + if (auto *ACC = dyn_cast(VD)) { + AccKind = ACC->getAccessorKind(); } } @@ -1430,6 +1469,22 @@ SDKContext::shouldIgnore(Decl *D, const Decl* Parent) const { if (Opts.SwiftOnly && isFromClang(D)) { return true; } + if (auto *ACC = dyn_cast(D)) { + // Only include accessors if they are part of var and subscript decl. + if (!isa(Parent)) { + return true; + } + // Only include getter/setter if we are checking source compatibility. + if (!checkingABI()) { + switch (ACC->getAccessorKind()) { + case AccessorKind::Get: + case AccessorKind::Set: + break; + default: + return true; + } + } + } if (checkingABI()) { if (auto *VD = dyn_cast(D)) { // Private vars with fixed binary orders can have ABI-impact, so we should @@ -1447,8 +1502,6 @@ SDKContext::shouldIgnore(Decl *D, const Decl* Parent) const { return true; } if (auto VD = dyn_cast(D)) { - if (VD->getBaseName().empty()) - return true; switch (getAccessLevel(VD)) { case AccessLevel::Internal: case AccessLevel::Private: @@ -1532,17 +1585,16 @@ SwiftDeclCollector::constructExternalExtensionNode(NominalTypeDecl *NTD, SDKNode *swift::ide::api:: SwiftDeclCollector::constructVarNode(ValueDecl *VD) { - auto Var = SDKNodeInitInfo(Ctx, VD).createSDKNode(SDKNodeKind::DeclVar); + auto Var = cast(SDKNodeInitInfo(Ctx, VD).createSDKNode(SDKNodeKind::DeclVar)); TypeInitInfo Info; Info.IsImplicitlyUnwrappedOptional = VD->getAttrs(). hasAttribute(); Var->addChild(constructTypeNode(VD->getInterfaceType(), Info)); if (auto VAD = dyn_cast(VD)) { - if (auto Getter = VAD->getGetter()) - Var->addChild(constructFunctionNode(Getter, SDKNodeKind::DeclGetter)); - if (auto Setter = VAD->getSetter()) { - if (Setter->getFormalAccess() > AccessLevel::Internal) - Var->addChild(constructFunctionNode(Setter, SDKNodeKind::DeclSetter)); + for(auto *AC: VAD->getAllAccessors()) { + if (!Ctx.shouldIgnore(AC, VAD)) { + Var->addAccessor(constructFunctionNode(AC, SDKNodeKind::DeclAccessor)); + } } } return Var; @@ -1567,10 +1619,17 @@ SwiftDeclCollector::constructAssociatedTypeNode(AssociatedTypeDecl *ATD) { SDKNode *swift::ide::api:: SwiftDeclCollector::constructSubscriptDeclNode(SubscriptDecl *SD) { - auto Subs = SDKNodeInitInfo(Ctx, SD).createSDKNode(SDKNodeKind::DeclSubscript); + auto *Subs = cast(SDKNodeInitInfo(Ctx, SD). + createSDKNode(SDKNodeKind::DeclSubscript)); Subs->addChild(constructTypeNode(SD->getElementInterfaceType())); - for (auto *Node: createParameterNodes(SD->getIndices())) + for (auto *Node: createParameterNodes(SD->getIndices())) { Subs->addChild(Node); + } + for(auto *AC: SD->getAllAccessors()) { + if (!Ctx.shouldIgnore(AC, SD)) { + Subs->addAccessor(constructFunctionNode(AC, SDKNodeKind::DeclAccessor)); + } + } return Subs; } @@ -1821,20 +1880,23 @@ void SDKNodeTypeNominal::jsonize(json::Output &out) { void SDKNodeDeclSubscript::jsonize(json::Output &out) { SDKNodeDeclAbstractFunc::jsonize(out); - output(out, KeyKind::KK_hasSetter, HasSetter); output(out, KeyKind::KK_hasStorage, HasStorage); - output(out, KeyKind::KK_hasDidset, HasDidSet); - output(out, KeyKind::KK_hasWillset, HasWillSet); + out.mapOptional(getKeyContent(Ctx, KeyKind::KK_accessors).data(), Accessors); } void SDKNodeDeclVar::jsonize(json::Output &out) { SDKNodeDecl::jsonize(out); output(out, KeyKind::KK_isLet, IsLet); output(out, KeyKind::KK_hasStorage, HasStorage); - output(out, KeyKind::KK_hasDidset, HasDidSet); - output(out, KeyKind::KK_hasWillset, HasWillSet); + out.mapOptional(getKeyContent(Ctx, KeyKind::KK_accessors).data(), Accessors); } +void SDKNodeDeclAccessor::jsonize(json::Output &out) { + SDKNodeDeclAbstractFunc::jsonize(out); + out.mapRequired(getKeyContent(Ctx, KeyKind::KK_accessorKind).data(), AccKind); +} + + namespace swift { namespace json { // In the namespace of swift::json, we define several functions so that the @@ -1864,6 +1926,16 @@ struct ScalarEnumerationTraits { } }; +template<> +struct ScalarEnumerationTraits { + static void enumeration(Output &out, AccessorKind &value) { +#define ACCESSOR(ID) +#define SINGLETON_ACCESSOR(ID, KEYWORD) \ + out.enumCase(value, #KEYWORD, AccessorKind::ID); +#include "swift/AST/AccessorKinds.def" + } +}; + template<> struct ObjectTraits { static void mapping(Output &out, SDKNode *&value) { @@ -1937,8 +2009,6 @@ static parseJsonEmit(SDKContext &Ctx, StringRef FileName) { yaml::Node *N = DI->getRoot(); assert(N && "Failed to find a root"); Result = SDKNode::constructSDKNode(Ctx, cast(N)); - if (Ctx.getDiags().hadAnyError()) - exit(1); } return {std::move(FileBufOrErr.get()), Result}; } diff --git a/tools/swift-api-digester/ModuleAnalyzerNodes.h b/tools/swift-api-digester/ModuleAnalyzerNodes.h index 499eb25afaa..a947418c102 100644 --- a/tools/swift-api-digester/ModuleAnalyzerNodes.h +++ b/tools/swift-api-digester/ModuleAnalyzerNodes.h @@ -169,6 +169,7 @@ public: #include "swift/AST/KnownIdentifiers.def" SDKContext(CheckerOptions Options); + llvm::BumpPtrAllocator &allocator() { return Allocator; } @@ -579,23 +580,22 @@ public: static bool classof(const SDKNode *N); }; +class SDKNodeDeclAccessor; class SDKNodeDeclVar : public SDKNodeDecl { bool IsLet; bool HasStorage; - bool HasDidSet; - bool HasWillSet; + std::vector Accessors; public: SDKNodeDeclVar(SDKNodeInitInfo Info); static bool classof(const SDKNode *N); - SDKNodeDeclGetter *getGetter() const; - SDKNodeDeclSetter *getSetter() const; + SDKNodeDeclAccessor *getAccessor(AccessorKind Kind) const; + ArrayRef getAllAccessors() const { return Accessors; } SDKNodeType *getType() const; bool isLet() const { return IsLet; } void jsonize(json::Output &Out) override; void diagnose(SDKNode *Right) override; bool hasStorage() const { return HasStorage; } - bool hasDidSet() const { return HasDidSet; } - bool hasWillSet() const { return HasWillSet; } + void addAccessor(SDKNode* AC); }; class SDKNodeDeclAbstractFunc : public SDKNodeDecl { @@ -619,19 +619,16 @@ public: }; class SDKNodeDeclSubscript: public SDKNodeDeclAbstractFunc { - bool HasSetter; bool HasStorage; - bool HasDidSet; - bool HasWillSet; + std::vector Accessors; public: SDKNodeDeclSubscript(SDKNodeInitInfo Info); static bool classof(const SDKNode *N); - bool hasSetter() const { return HasSetter; } bool hasStorage() const { return HasStorage; } + SDKNodeDeclAccessor *getAccessor(AccessorKind Kind) const; + ArrayRef getAllAccessors() const { return Accessors; } void jsonize(json::Output &Out) override; - void diagnose(SDKNode *Right) override; - bool hasDidSet() const { return HasDidSet; } - bool hasWillSet() const { return HasWillSet; } + void addAccessor(SDKNode* AC); }; class SDKNodeDeclFunction: public SDKNodeDeclAbstractFunc { @@ -651,16 +648,17 @@ public: static bool classof(const SDKNode *N); }; -class SDKNodeDeclGetter: public SDKNodeDeclAbstractFunc { +class SDKNodeDeclAccessor: public SDKNodeDeclAbstractFunc { + SDKNodeDecl *Owner; + AccessorKind AccKind; + friend class SDKNodeDeclVar; + friend class SDKNodeDeclSubscript; public: - SDKNodeDeclGetter(SDKNodeInitInfo Info); - static bool classof(const SDKNode *N); -}; - -class SDKNodeDeclSetter: public SDKNodeDeclAbstractFunc { -public: - SDKNodeDeclSetter(SDKNodeInitInfo Info); + SDKNodeDeclAccessor(SDKNodeInitInfo Info); + AccessorKind getAccessorKind() const { return AccKind; } static bool classof(const SDKNode *N); + SDKNodeDecl* getStorage() const { return Owner; } + void jsonize(json::Output &Out) override; }; // The additional information we need for a type node in the digest. @@ -753,7 +751,6 @@ int findDeclUsr(StringRef dumpPath, CheckerOptions Opts); void nodeSetDifference(ArrayRef Left, ArrayRef Right, NodeVector &LeftMinusRight, NodeVector &RightMinusLeft); - } // end of abi namespace } // end of ide namespace } // end of Swift namespace diff --git a/tools/swift-api-digester/ModuleDiagsConsumer.cpp b/tools/swift-api-digester/ModuleDiagsConsumer.cpp index a81a79c49df..7be1551b515 100644 --- a/tools/swift-api-digester/ModuleDiagsConsumer.cpp +++ b/tools/swift-api-digester/ModuleDiagsConsumer.cpp @@ -33,7 +33,6 @@ enum LocalDiagID : uint32_t { static StringRef getCategoryName(uint32_t ID) { switch(ID) { case LocalDiagID::removed_decl: - case LocalDiagID::removed_setter: return "/* Removed Decls */"; case LocalDiagID::moved_decl: case LocalDiagID::decl_kind_changed: diff --git a/tools/swift-api-digester/swift-api-digester.cpp b/tools/swift-api-digester/swift-api-digester.cpp index 06f77a632c9..58531fd7355 100644 --- a/tools/swift-api-digester/swift-api-digester.cpp +++ b/tools/swift-api-digester/swift-api-digester.cpp @@ -795,16 +795,6 @@ void swift::ide::api::SDKNodeDeclFunction::diagnose(SDKNode *Right) { } } -void swift::ide::api::SDKNodeDeclSubscript::diagnose(SDKNode *Right) { - SDKNodeDeclAbstractFunc::diagnose(Right); - auto *R = dyn_cast(Right); - if (!R) - return; - if (hasSetter() && !R->hasSetter()) { - emitDiag(diag::removed_setter); - } -} - void swift::ide::api::SDKNodeDecl::diagnose(SDKNode *Right) { SDKNode::diagnose(Right); auto *RD = dyn_cast(Right); @@ -882,9 +872,6 @@ void swift::ide::api::SDKNodeDeclVar::diagnose(SDKNode *Right) { auto *RV = dyn_cast(Right); if (!RV) return; - if (getSetter() && !RV->getSetter()) { - emitDiag(diag::removed_setter); - } if (Ctx.checkingABI()) { if (hasFixedBinaryOrder() != RV->hasFixedBinaryOrder()) { emitDiag(diag::var_has_fixed_order_change, hasFixedBinaryOrder()); @@ -976,8 +963,15 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass { static void printSpaces(llvm::raw_ostream &OS, SDKNode *N) { assert(N); + StringRef Space = " "; + // Accessor doesn't have parent. + if (auto *AC = dyn_cast(N)) { + OS << Space; + printSpaces(OS, AC->getStorage()); + return; + } for (auto P = N; !isa(P); P = P->getParent()) - OS << " "; + OS << Space; } static void debugMatch(SDKNode *Left, SDKNode *Right, NodeMatchReason Reason, @@ -1003,6 +997,13 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass { } } + static StringRef getParentProtocolName(SDKNode *Node) { + if (auto *Acc = dyn_cast(Node)) { + Node = Acc->getStorage(); + } + return Node->getParent()->getAs()->getFullyQualifiedName(); + } + public: PrunePass(SDKContext &Ctx): Ctx(Ctx), UpdateMap(Ctx.getNodeUpdateMap()) {} PrunePass(SDKContext &Ctx, llvm::StringSet<> prWhitelist): @@ -1043,8 +1044,7 @@ public: ShouldComplain = false; } if (ShouldComplain && - ProtocolReqWhitelist.count(D->getParent()->getAs()-> - getFullyQualifiedName())) { + ProtocolReqWhitelist.count(getParentProtocolName(D))) { // Ignore protocol requirement additions if the protocol has been added // to the whitelist. ShouldComplain = false; @@ -1083,6 +1083,9 @@ public: Conf->getName(), TD->isProtocol()); } + if (auto *Acc = dyn_cast(Left)) { + Acc->emitDiag(diag::removed_decl, Acc->isDeprecated()); + } return; case NodeMatchReason::FuncToProperty: case NodeMatchReason::ModernizeEnum: @@ -1131,11 +1134,9 @@ public: } case SDKNodeKind::TypeWitness: case SDKNodeKind::DeclOperator: - case SDKNodeKind::DeclSubscript: case SDKNodeKind::DeclAssociatedType: case SDKNodeKind::DeclFunction: - case SDKNodeKind::DeclSetter: - case SDKNodeKind::DeclGetter: + case SDKNodeKind::DeclAccessor: case SDKNodeKind::DeclConstructor: case SDKNodeKind::DeclTypeAlias: case SDKNodeKind::TypeFunc: @@ -1148,15 +1149,25 @@ public: SNMatcher.match(); break; } + case SDKNodeKind::DeclSubscript: { + auto *LSub = dyn_cast(Left); + auto *RSub = dyn_cast(Right); + SequentialNodeMatcher(LSub->getChildren(), RSub->getChildren(), *this).match(); +#define ACCESSOR(ID) \ + singleMatch(LSub->getAccessor(AccessorKind::ID), \ + RSub->getAccessor(AccessorKind::ID), *this); +#include "swift/AST/AccessorKinds.def" + break; + } case SDKNodeKind::DeclVar: { auto *LVar = dyn_cast(Left); auto *RVar = dyn_cast(Right); // Match property type. singleMatch(LVar->getType(), RVar->getType(), *this); - // Match property getter function. - singleMatch(LVar->getGetter(), RVar->getGetter(), *this); - // Match property setter function. - singleMatch(LVar->getSetter(), RVar->getSetter(), *this); +#define ACCESSOR(ID) \ + singleMatch(LVar->getAccessor(AccessorKind::ID), \ + RVar->getAccessor(AccessorKind::ID), *this); +#include "swift/AST/AccessorKinds.def" break; } } @@ -1224,7 +1235,7 @@ class TypeMemberDiffFinder : public SDKNodeVisitor { declNode->isStatic()) TypeMemberDiffs.insert({diffNode, node}); // Move from a getter/setter function to a property - else if (node->getKind() == SDKNodeKind::DeclGetter && + else if (node->getKind() == SDKNodeKind::DeclAccessor && diffNode->getKind() == SDKNodeKind::DeclFunction && node->isNameValid()) { diffNode->annotate(NodeAnnotation::Rename);