swift-module-digester: diagnose value ownership changes for parameters.

This commit is contained in:
Xi Ge
2018-10-04 18:02:43 -07:00
parent 01c4c3c12b
commit a1e66a0515
9 changed files with 23 additions and 1 deletions

View File

@@ -86,6 +86,8 @@ ERROR(func_type_escaping_changed,none,"%0 has %select{removed|added}2 @escaping
ERROR(func_self_access_change,none,"%0 has self access kind changing from %1 to %2", (StringRef, StringRef, StringRef))
ERROR(param_ownership_change,none,"%0 has %1 changing from %2 to %3", (StringRef, StringRef, StringRef, StringRef))
#ifndef DIAG_NO_UNDEF
# if defined(DIAG)
# undef DIAG

View File

@@ -134,3 +134,5 @@ public class EscapingFunctionType {
}
infix operator ..*..
public func ownershipChange(_ a: inout Int, _ b: __shared Int) {}

View File

@@ -144,3 +144,5 @@ public class EscapingFunctionType {
}
prefix operator ..*..
public func ownershipChange(_ a: Int, _ b: __owned Int) {}

View File

@@ -36,6 +36,8 @@ cake1: Func C7.foo(_:_:) has removed default argument from parameter 1
cake1: Func EscapingFunctionType.addedEscaping(_:) has added @escaping in parameter 0
cake1: Func EscapingFunctionType.removedEscaping(_:) has removed @escaping in parameter 0
cake1: Func Somestruct2.foo1(_:) has parameter 0 type change from C3 to C1
cake1: Func ownershipChange(_:_:) has parameter 0 changing from InOut to Default
cake1: Func ownershipChange(_:_:) has parameter 1 changing from Shared to Owned
/* Decl Attribute changes */
cake1: Class C5 is now without @objc

View File

@@ -31,6 +31,8 @@ cake1: Constructor S1.init(_:) has parameter 0 type change from Int to Double
cake1: Func C1.foo2(_:) has parameter 0 type change from Int to () -> ()
cake1: Func C7.foo(_:_:) has removed default argument from parameter 0
cake1: Func C7.foo(_:_:) has removed default argument from parameter 1
cake1: Func ownershipChange(_:_:) has parameter 0 changing from InOut to Default
cake1: Func ownershipChange(_:_:) has parameter 1 changing from Shared to Owned
/* Decl Attribute changes */
cake1: Func C1.foo1() is now not static

View File

@@ -312,6 +312,10 @@ bool SDKNodeType::hasTypeAttribute(TypeAttrKind DAKind) const {
TypeAttributes.end();
}
StringRef SDKNodeType::getParamValueOwnership() const {
return ParamValueOwnership.empty() ? "Default" : ParamValueOwnership;
}
StringRef SDKNodeType::getTypeRoleDescription() const {
assert(isTopLevelType());
auto P = cast<SDKNodeDecl>(getParent());

View File

@@ -368,7 +368,7 @@ public:
bool hasDefaultArgument() const { return HasDefaultArg; }
bool isTopLevelType() const { return !isa<SDKNodeType>(getParent()); }
StringRef getTypeRoleDescription() const;
StringRef getParamValueOwnership() const { return ParamValueOwnership; }
StringRef getParamValueOwnership() const;
static bool classof(const SDKNode *N);
virtual void jsonize(json::Output &Out) override;
virtual void diagnose(SDKNode *Right) override;

View File

@@ -48,6 +48,7 @@ static StringRef getCategoryName(uint32_t ID) {
case LocalDiagID::default_arg_removed:
case LocalDiagID::decl_type_change:
case LocalDiagID::func_type_escaping_changed:
case LocalDiagID::param_ownership_change:
return "/* Type Changes */";
case LocalDiagID::raw_type_change:
return "/* RawRepresentable Changes */";

View File

@@ -871,6 +871,13 @@ void swift::ide::api::SDKNodeType::diagnose(SDKNode *Right) {
Diags.diagnose(SourceLoc(), diag::default_arg_removed,
LParent->getScreenInfo(), Descriptor);
}
if (getParamValueOwnership() != RT->getParamValueOwnership()) {
Diags.diagnose(SourceLoc(), diag::param_ownership_change,
getParent()->getAs<SDKNodeDecl>()->getScreenInfo(),
getTypeRoleDescription(),
getParamValueOwnership(),
RT->getParamValueOwnership());
}
}
void swift::ide::api::SDKNodeTypeFunc::diagnose(SDKNode *Right) {