Skip to content
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
2 changes: 2 additions & 0 deletions include/swift/AST/DiagnosticsModuleDiffer.def
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ ERROR(type_witness_change,none,"%0 has type witness type for %1 changing from %2

ERROR(decl_new_witness_table_entry,none,"%0 now requires %select{|no}1 new witness table entry", (StringRef, bool))

ERROR(new_decl_without_intro,none,"%0 is a new API without @available attribute", (StringRef))

#ifndef DIAG_NO_UNDEF
# if defined(DIAG)
# undef DIAG
Expand Down
4 changes: 4 additions & 0 deletions test/api-digester/Inputs/cake1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,7 @@ public protocol HasMutatingMethodClone: HasMutatingMethod {
mutating func foo()
var bar: Int { mutating get }
}

public extension Int {
public func IntEnhancer() {}
}
15 changes: 15 additions & 0 deletions test/api-digester/Outputs/Cake-abi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cake1: Protocol P3 has generic signature change from <τ_0_0 : cake.P1, τ_0_0 :
/* RawRepresentable Changes */

/* Removed Decls */
Swift: Extension Int has been removed
cake1: Accessor GlobalVarChangedToLet.Set() has been removed
cake1: Accessor RemoveSetters.Value.Set() has been removed
cake1: AssociatedType RequiementChanges.removedType has been removed
Expand Down Expand Up @@ -56,6 +57,20 @@ cake1: Var C1.CIIns1 changes from weak to strong
cake1: Var C1.CIIns2 changes from strong to weak
cake1: Var GlobalLetChangedToVar changes from let to var
cake1: Var GlobalVarChangedToLet changes from var to let
cake2: Accessor GlobalLetChangedToVar.Set() is a new API without @available attribute
cake2: Accessor fixedLayoutStruct2.BecomeFixedBinaryOrder.Set() is a new API without @available attribute
cake2: AssociatedType RequiementChanges.addedTypeWithDefault is a new API without @available attribute
cake2: AssociatedType RequiementChanges.addedTypeWithoutDefault is a new API without @available attribute
cake2: Class C0 is a new API without @available attribute
cake2: Class C8 is a new API without @available attribute
cake2: Constructor C1.init(_:) is a new API without @available attribute
cake2: EnumElement FrozenKind.AddedCase is a new API without @available attribute
cake2: Func RequiementChanges.addedFunc() is a new API without @available attribute
cake2: Func fixedLayoutStruct.OKChange() is a new API without @available attribute
cake2: Protocol P4 is a new API without @available attribute
cake2: Var RequiementChanges.addedVar is a new API without @available attribute
cake2: Var fixedLayoutStruct.$__lazy_storage_$_lazy_d is a new API without @available attribute
cake2: Var fixedLayoutStruct.c is a new API without @available attribute

/* Fixed-layout Type changes */
cake1: EnumElement FrozenKind.Fixed in a non-resilient type changes position from 1 to 2
Expand Down
1 change: 1 addition & 0 deletions test/api-digester/Outputs/Cake.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cake1: Protocol P3 has generic signature change from <Self : cake.P1, Self : cak
/* RawRepresentable Changes */

/* Removed Decls */
Swift: Extension Int has been removed
cake1: Accessor GlobalVarChangedToLet.Set() has been removed
cake1: Accessor RemoveSetters.Value.Set() has been removed
cake1: AssociatedType RequiementChanges.removedType has been removed
Expand Down
4 changes: 4 additions & 0 deletions test/api-digester/Outputs/cake-abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,10 @@
"moduleName": "cake",
"genericSig": "<τ_0_0 where τ_0_0 : PSuper>",
"isABIPlaceholder": true,
"intro_Macosx": "9999",
"intro_iOS": "9999",
"intro_tvOS": "9999",
"intro_watchOS": "9999",
"funcSelfKind": "NonMutating"
}
],
Expand Down
4 changes: 4 additions & 0 deletions test/api-digester/Outputs/cake.json
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,10 @@
"moduleName": "cake",
"genericSig": "<Self where Self : PSuper>",
"isABIPlaceholder": true,
"intro_Macosx": "9999",
"intro_iOS": "9999",
"intro_tvOS": "9999",
"intro_watchOS": "9999",
"funcSelfKind": "NonMutating"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Func _collectReferencesInsideObject(_:) is a new API without @available attribute
Func _loadDestroyTLSCounter() is a new API without @available attribute
Protocol _RuntimeFunctionCountersStats is a new API without @available attribute
Struct _GlobalRuntimeFunctionCountersState is a new API without @available attribute
Struct _ObjectRuntimeFunctionCountersState is a new API without @available attribute
Struct _RuntimeFunctionCounters is a new API without @available attribute
Func _measureRuntimeFunctionCountersDiffs(objects:_:) is a new API without @available attribute
9 changes: 0 additions & 9 deletions test/api-digester/Outputs/stability-stdlib-abi.swift.expected

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// The init(signOf:magnitudeOf:) blames are false positives. They are not new APIs.
Constructor Double.init(signOf:magnitudeOf:) is a new API without @available attribute
Constructor Float.init(signOf:magnitudeOf:) is a new API without @available attribute
Constructor Float80.init(signOf:magnitudeOf:) is a new API without @available attribute

Constructor __RawDictionaryStorage.init(coder:) is a new API without @available attribute
Constructor __RawSetStorage.init(coder:) is a new API without @available attribute
Constructor __SwiftNativeNSData.init(coder:) is a new API without @available attribute
Constructor __SwiftNativeNSDictionary.init(coder:) is a new API without @available attribute
Constructor __SwiftNativeNSSet.init(coder:) is a new API without @available attribute

Func _cos(_:) has been removed
Func _exp(_:) has been removed
Func _exp2(_:) has been removed

Func _log(_:) has been removed
Func _log10(_:) has been removed
Func _log2(_:) has been removed

Func _nearbyint(_:) has been removed
Func _rint(_:) has been removed
Func _sin(_:) has been removed
15 changes: 15 additions & 0 deletions test/api-digester/stability-stdlib-abi-with-asserts.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// REQUIRES: OS=macosx
// REQUIRES: swift_stdlib_asserts
// RUN: %empty-directory(%t.tmp)
// mkdir %t.tmp/module-cache && mkdir %t.tmp/dummy.sdk
// RUN: %api-digester -dump-sdk -module Swift -o %t.tmp/current-stdlib.json -module-cache-path %t.tmp/module-cache -sdk %t.tmp/dummy.sdk -abi -avoid-location
// RUN: %api-digester -diagnose-sdk -input-paths %S/Inputs/stdlib-stable-abi.json -input-paths %t.tmp/current-stdlib.json -abi -o %t.tmp/changes.txt -v
// RUN: %clang -E -P -x c %S/Outputs/stability-stdlib-abi.without.asserts.swift.expected -o - > %t.tmp/stability-stdlib-abi.swift.expected
// RUN: %clang -E -P -x c %S/Outputs/stability-stdlib-abi.asserts.additional.swift.expected -o - >> %t.tmp/stability-stdlib-abi.swift.expected
// RUN: %clang -E -P -x c %t.tmp/stability-stdlib-abi.swift.expected -o - | sed '/^\s*$/d' | sort > %t.tmp/stability-stdlib-abi.swift.expected.sorted
// RUN: %clang -E -P -x c %t.tmp/changes.txt -o - | sed '/^\s*$/d' | sort > %t.tmp/changes.txt.tmp
// RUN: diff -u %t.tmp/stability-stdlib-abi.swift.expected.sorted %t.tmp/changes.txt.tmp

// The digester can incorrectly register a generic signature change when
// declarations are shuffled. rdar://problem/46618883
// UNSUPPORTED: swift_evolve
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// REQUIRES: OS=macosx
// REQUIRES: swift_stdlib_no_asserts
// RUN: %empty-directory(%t.tmp)
// mkdir %t.tmp/module-cache && mkdir %t.tmp/dummy.sdk
// RUN: %api-digester -dump-sdk -module Swift -o %t.tmp/current-stdlib.json -module-cache-path %t.tmp/module-cache -sdk %t.tmp/dummy.sdk -abi -avoid-location
// RUN: %api-digester -diagnose-sdk -input-paths %S/Inputs/stdlib-stable-abi.json -input-paths %t.tmp/current-stdlib.json -abi -o %t.tmp/changes.txt -v
// RUN: %clang -E -P -x c %S/Outputs/stability-stdlib-abi.swift.expected -o - | sed '/^\s*$/d' | sort > %t.tmp/stability-stdlib-abi.swift.expected
// RUN: %clang -E -P -x c %S/Outputs/stability-stdlib-abi.without.asserts.swift.expected -o - | sed '/^\s*$/d' | sort > %t.tmp/stability-stdlib-abi.swift.expected
// RUN: %clang -E -P -x c %t.tmp/changes.txt -o - | sed '/^\s*$/d' | sort > %t.tmp/changes.txt.tmp
// RUN: diff -u %t.tmp/stability-stdlib-abi.swift.expected %t.tmp/changes.txt.tmp

Expand Down
18 changes: 15 additions & 3 deletions tools/swift-api-digester/ModuleAnalyzerNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,15 @@ StringRef SDKNodeDecl::getScreenInfo() const {
OS << "(" << HeaderName << ")";
if (!OS.str().empty())
OS << ": ";
OS << getDeclKind() << " " << getFullyQualifiedName();
bool IsExtension = false;
if (auto *TD = dyn_cast<SDKNodeDeclType>(this)) {
IsExtension = TD->isExternal();
}
if (IsExtension)
OS << "Extension";
else
OS << getDeclKind();
OS << " " << getFullyQualifiedName();
return Ctx.buffer(OS.str());
}

Expand Down Expand Up @@ -1137,25 +1145,29 @@ static bool isABIPlaceholderRecursive(Decl *D) {
}

StringRef SDKContext::getPlatformIntroVersion(Decl *D, PlatformKind Kind) {
if (!D)
return StringRef();
for (auto *ATT: D->getAttrs()) {
if (auto *AVA = dyn_cast<AvailableAttr>(ATT)) {
if (AVA->Platform == Kind && AVA->Introduced) {
return buffer(AVA->Introduced->getAsString());
}
}
}
return StringRef();
return getPlatformIntroVersion(D->getDeclContext()->getAsDecl(), Kind);
}

StringRef SDKContext::getLanguageIntroVersion(Decl *D) {
if (!D)
return StringRef();
for (auto *ATT: D->getAttrs()) {
if (auto *AVA = dyn_cast<AvailableAttr>(ATT)) {
if (AVA->isLanguageVersionSpecific() && AVA->Introduced) {
return buffer(AVA->Introduced->getAsString());
}
}
}
return StringRef();
return getLanguageIntroVersion(D->getDeclContext()->getAsDecl());
}

SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, Type Ty, TypeInitInfo Info) :
Expand Down
5 changes: 5 additions & 0 deletions tools/swift-api-digester/ModuleAnalyzerNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ struct CheckerOptions {
bool AbortOnModuleLoadFailure;
bool PrintModule;
bool SwiftOnly;
bool SkipOSCheck;
StringRef LocationFilter;
};

Expand Down Expand Up @@ -293,6 +294,9 @@ struct PlatformIntroVersion {
StringRef tvos;
StringRef watchos;
StringRef swift;
bool hasOSAvailability() const {
return !macos.empty() || !ios.empty() || !tvos.empty() || !watchos.empty();
}
};

class SDKNodeDecl: public SDKNode {
Expand Down Expand Up @@ -347,6 +351,7 @@ class SDKNodeDecl: public SDKNode {
StringRef getScreenInfo() const;
bool hasFixedBinaryOrder() const { return FixedBinaryOrder.hasValue(); }
uint8_t getFixedBinaryOrder() const { return *FixedBinaryOrder; }
PlatformIntroVersion getIntroducingVersion() const { return introVersions; }
virtual void jsonize(json::Output &Out) override;
virtual void diagnose(SDKNode *Right) override;

Expand Down
1 change: 1 addition & 0 deletions tools/swift-api-digester/ModuleDiagsConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static StringRef getCategoryName(uint32_t ID) {
case LocalDiagID::decl_new_attr:
case LocalDiagID::var_let_changed:
case LocalDiagID::func_self_access_change:
case LocalDiagID::new_decl_without_intro:
return "/* Decl Attribute changes */";
case LocalDiagID::default_arg_removed:
case LocalDiagID::decl_type_change:
Expand Down
16 changes: 15 additions & 1 deletion tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ SwiftOnly("swift-only",
llvm::cl::init(false),
llvm::cl::cat(Category));

static llvm::cl::opt<bool>
DisableOSChecks("disable-os-checks",
llvm::cl::desc("Skip OS related diagnostics"),
llvm::cl::init(false),
llvm::cl::cat(Category));

static llvm::cl::opt<bool>
PrintModule("print-module", llvm::cl::desc("Print module names in diagnostics"),
llvm::cl::cat(Category));
Expand Down Expand Up @@ -1003,6 +1009,14 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
if (D->hasFixedBinaryOrder()) {
D->emitDiag(diag::decl_added);
}
// Diagnose the missing of @available attributes.
// Decls with @_alwaysEmitIntoClient aren't required to have an
// @available attribute.
if (!Ctx.getOpts().SkipOSCheck &&
!D->getIntroducingVersion().hasOSAvailability() &&
!D->hasDeclAttribute(DeclAttrKind::DAK_AlwaysEmitIntoClient)) {
D->emitDiag(diag::new_decl_without_intro);
}
}
}
// Complain about added protocol requirements
Expand Down Expand Up @@ -1038,7 +1052,6 @@ class PrunePass : public MatchedNodeListener, public SDKTreeDiffPass {
}
}
}

return;
case NodeMatchReason::Removed:
assert(!Right);
Expand Down Expand Up @@ -2371,6 +2384,7 @@ static CheckerOptions getCheckOpts() {
Opts.LocationFilter = options::LocationFilter;
Opts.PrintModule = options::PrintModule;
Opts.SwiftOnly = options::SwiftOnly;
Opts.SkipOSCheck = options::DisableOSChecks;
return Opts;
}

Expand Down