Fix two bugs related to the casts optimizations.

The protocol_lookup the testcase from Interpreter test-cases exposed two bugs, once I tried to compiler with with -O:
 - SILCloner was generating an open_existential_ref from an open_existential_metatype instruction during cloning even if the existential in question was not a class existential.
 - DynamicCasts was not considering the fact that subclasses of a given class may implement a protocol, even if the class does not implement it.

Swift SVN r27260
This commit is contained in:
Roman Levenstein
2015-04-13 22:12:54 +00:00
parent eaeaf5dfd3
commit 194aed3df2
4 changed files with 62 additions and 4 deletions

View File

@@ -130,6 +130,13 @@ classifyDynamicCastToProtocol(CanType source,
if (auto *CD = source.getClassOrBoundGenericClass()) {
if (canClassOrSuperclassesHaveExtensions(CD, isWholeModuleOpts))
return DynamicCastFeasibility::MaySucceed;
// Derived types may conform to the protocol.
if (!CD->isFinal()) {
// TODO: If it is a private type or internal type and we
// can prove that there are no derived types conforming to a
// protocol, then we can still return WillFail.
return DynamicCastFeasibility::MaySucceed;
}
}
// If the source type is private or target protocol is private,