SILGen: just for fun let's do toll-free bridging for <T : NSError> archetypes too

Swift SVN r31262
This commit is contained in:
Slava Pestov
2015-08-16 18:47:26 +00:00
parent e5cb73fe41
commit 6014f1d3cc
2 changed files with 11 additions and 1 deletions

View File

@@ -279,9 +279,12 @@ static bool isBridgedErrorClass(SILModule &M,
if (!t)
return false;
if (auto archetypeType = t->getAs<ArchetypeType>())
t = archetypeType->getSuperclass();
// NSError (TODO: and CFError) can be bridged.
auto errorType = M.Types.getNSErrorType();
if (errorType && t->isEqual(errorType)) {
if (t && errorType && t->isEqual(errorType)) {
return true;
}

View File

@@ -11,6 +11,13 @@ func NSErrorErrorType_erasure(x: NSError) -> ErrorType {
return x
}
// CHECK-LABEL: sil hidden @_TF10objc_error34NSErrorErrorType_archetype_erasureuRdq_CSo7NSError_Fq_PSs9ErrorType_
// CHECK: [[ERROR_TYPE:%.*]] = init_existential_ref %0 : $T : $T, $ErrorType
// CHECK: return [[ERROR_TYPE]]
func NSErrorErrorType_archetype_erasure<T : NSError>(t: T) -> ErrorType {
return t
}
// Test patterns that are non-trivial, but irrefutable. SILGen shouldn't crash
// on these.
func test_doesnt_throw() {