mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SIL: Fix isPotentiallyAnyObject(), and move from AST to SIL
This commit is contained in:
@@ -1118,20 +1118,6 @@ bool TypeBase::isAnyObject() {
|
|||||||
return canTy.getExistentialLayout().isAnyObject();
|
return canTy.getExistentialLayout().isAnyObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Distinguish between class-bound types that might be AnyObject vs other
|
|
||||||
// class-bound types. Only types that are potentially AnyObject might have a
|
|
||||||
// transparent runtime type wrapper like __SwiftValue. This must look through
|
|
||||||
// all optional types because dynamic casting sees through them.
|
|
||||||
bool TypeBase::isPotentiallyAnyObject() {
|
|
||||||
Type unwrappedTy = lookThroughAllOptionalTypes();
|
|
||||||
if (auto archetype = unwrappedTy->getAs<ArchetypeType>()) {
|
|
||||||
// Does archetype have any requirements that contradict AnyObject?
|
|
||||||
// 'T : AnyObject' requires a layout constraint, not a conformance.
|
|
||||||
return archetype->getConformsTo().empty() && !archetype->getSuperclass();
|
|
||||||
}
|
|
||||||
return unwrappedTy->isAnyObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ExistentialLayout::isErrorExistential() const {
|
bool ExistentialLayout::isErrorExistential() const {
|
||||||
auto protocols = getProtocols();
|
auto protocols = getProtocols();
|
||||||
return (!hasExplicitAnyObject &&
|
return (!hasExplicitAnyObject &&
|
||||||
|
|||||||
@@ -225,6 +225,22 @@ static CanType getHashableExistentialType(ModuleDecl *M) {
|
|||||||
return hashable->getDeclaredInterfaceType()->getCanonicalType();
|
return hashable->getDeclaredInterfaceType()->getCanonicalType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Distinguish between class-bound types that might be AnyObject vs other
|
||||||
|
// class-bound types. Only types that are potentially AnyObject might have a
|
||||||
|
// transparent runtime type wrapper like __SwiftValue. This must look through
|
||||||
|
// all optional types because dynamic casting sees through them.
|
||||||
|
static bool isPotentiallyAnyObject(Type type) {
|
||||||
|
Type unwrappedTy = type->lookThroughAllOptionalTypes();
|
||||||
|
if (auto archetype = unwrappedTy->getAs<ArchetypeType>()) {
|
||||||
|
for (auto *proto : archetype->getConformsTo()) {
|
||||||
|
if (!proto->getInvertibleProtocolKind())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return !archetype->getSuperclass();
|
||||||
|
}
|
||||||
|
return unwrappedTy->isAnyObject();
|
||||||
|
}
|
||||||
|
|
||||||
// Returns true if casting \p sourceFormalType to \p targetFormalType preserves
|
// Returns true if casting \p sourceFormalType to \p targetFormalType preserves
|
||||||
// ownership.
|
// ownership.
|
||||||
//
|
//
|
||||||
@@ -321,11 +337,11 @@ bool swift::doesCastPreserveOwnershipForTypes(SILModule &module,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// (B2) unwrapping
|
// (B2) unwrapping
|
||||||
if (sourceType->isPotentiallyAnyObject())
|
if (isPotentiallyAnyObject(sourceType))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// (B1) wrapping
|
// (B1) wrapping
|
||||||
if (targetType->isPotentiallyAnyObject()) {
|
if (isPotentiallyAnyObject(targetType)) {
|
||||||
// A class type cannot be wrapped in __SwiftValue, so casting
|
// A class type cannot be wrapped in __SwiftValue, so casting
|
||||||
// from a class to AnyObject preserves ownership.
|
// from a class to AnyObject preserves ownership.
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// RUN: %target-swift-emit-silgen -enable-sil-opaque-values -Xllvm -sil-full-demangle -primary-file %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
|
// RUN: %target-swift-emit-silgen -enable-sil-opaque-values -Xllvm -sil-full-demangle -primary-file %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
|
||||||
|
|
||||||
// XFAIL: noncopyable_generics
|
|
||||||
|
|
||||||
// Test SILGen -enable-sil-opaque-values with tests that depend on the stdlib.
|
// Test SILGen -enable-sil-opaque-values with tests that depend on the stdlib.
|
||||||
|
|
||||||
// FIXME: "HECK" lines all need to be updated for OSSA.
|
// FIXME: "HECK" lines all need to be updated for OSSA.
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// RUN: %target-sil-opt -rc-id-dumper -enable-sil-opaque-values -module-name Swift %s -o /dev/null | %FileCheck %s
|
// RUN: %target-sil-opt -rc-id-dumper -enable-sil-opaque-values -module-name Swift %s -o /dev/null | %FileCheck %s
|
||||||
|
|
||||||
// XFAIL: noncopyable_generics
|
|
||||||
|
|
||||||
import Builtin
|
import Builtin
|
||||||
|
|
||||||
typealias AnyObject = Builtin.AnyObject
|
typealias AnyObject = Builtin.AnyObject
|
||||||
|
|||||||
Reference in New Issue
Block a user