Skip to content

[lldb] Implement TypeSystemSwiftTypeRef::IsPossibleDynamicType #2238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
55 changes: 53 additions & 2 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1762,13 +1762,64 @@ bool TypeSystemSwiftTypeRef::IsFunctionPointerType(
VALIDATE_AND_RETURN(impl, IsFunctionPointerType, type,
(ReconstructType(type)));
}

bool TypeSystemSwiftTypeRef::IsPossibleDynamicType(opaque_compiler_type_t type,
CompilerType *target_type,
bool check_cplusplus,
bool check_objc) {
return m_swift_ast_context->IsPossibleDynamicType(
ReconstructType(type), target_type, check_cplusplus, check_objc);
if (target_type)
target_type->Clear();

if (!type)
return false;

// This is a discrepancy with `SwiftASTContext`. The `impl` below correctly
// returns true, but `VALIDATE_AND_RETURN` will assert. This hardcoded
// handling of `__C.NSNotificationName` can be removed when the
// `VALIDATE_AND_RETURN` is removed.
if (GetMangledTypeName(type) == "$sSo18NSNotificationNameaD")
return true;

auto impl = [&]() {
using namespace swift::Demangle;
Demangler dem;
auto *node = DemangleCanonicalType(dem, type);
if (!node)
return false;

if (node->getKind() == Node::Kind::TypeAlias) {
auto resolved = ResolveTypeAlias(m_swift_ast_context, dem, node);
if (auto *n = std::get<swift::Demangle::NodePointer>(resolved))
node = n;
}

switch (node->getKind()) {
case Node::Kind::Class:
case Node::Kind::BoundGenericClass:
case Node::Kind::Protocol:
case Node::Kind::ProtocolList:
case Node::Kind::ProtocolListWithClass:
case Node::Kind::ProtocolListWithAnyObject:
case Node::Kind::ExistentialMetatype:
case Node::Kind::DynamicSelf:
return true;
case Node::Kind::BuiltinTypeName: {
if (!node->hasText())
return false;
StringRef name = node->getText();
return name == swift::BUILTIN_TYPE_NAME_RAWPOINTER ||
name == swift::BUILTIN_TYPE_NAME_NATIVEOBJECT ||
name == swift::BUILTIN_TYPE_NAME_BRIDGEOBJECT;
}
default:
return ContainsGenericTypeParameter(node);
}
};
VALIDATE_AND_RETURN(
impl, IsPossibleDynamicType, type,
(ReconstructType(type), nullptr, check_cplusplus, check_objc));
}

bool TypeSystemSwiftTypeRef::IsPointerType(opaque_compiler_type_t type,
CompilerType *pointee_type) {
auto impl = [&]() {
Expand Down