Skip to content

[lldb] Consider bound types when deciding if the overall type is dynamic #3581

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
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5410,6 +5410,15 @@ bool SwiftASTContext::IsPossibleDynamicType(opaque_compiler_type_t type,
if (can_type == GetASTContext()->TheBridgeObjectType)
return true;

if (auto *bound_type =
llvm::dyn_cast<swift::BoundGenericType>(can_type.getPointer())) {
for (auto generic_arg : bound_type->getGenericArgs()) {
if (IsPossibleDynamicType(generic_arg.getPointer(), dynamic_pointee_type,
check_cplusplus, check_objc))
return true;
}
}

if (dynamic_pointee_type)
dynamic_pointee_type->Clear();
return false;
Expand Down
78 changes: 50 additions & 28 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1990,37 +1990,59 @@ bool TypeSystemSwiftTypeRef::IsPossibleDynamicType(opaque_compiler_type_t type,
auto impl = [&]() {
using namespace swift::Demangle;
Demangler dem;
auto *node = DemangleCanonicalType(dem, type);
if (!node)
return false;
std::function<bool(NodePointer)> is_possible_dynamic =
[&](NodePointer node) -> bool {
if (!node)
return false;

if (node->getKind() == Node::Kind::TypeAlias) {
auto resolved = ResolveTypeAlias(this, GetSwiftASTContext(), dem, node);
if (auto *n = std::get<swift::Demangle::NodePointer>(resolved))
node = n;
}
if (node->getKind() == Node::Kind::TypeAlias) {
auto resolved = ResolveTypeAlias(this, GetSwiftASTContext(), 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())
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::BoundGenericStructure:
case Node::Kind::BoundGenericEnum: {
if (node->getNumChildren() < 2)
return false;
NodePointer type_list = node->getLastChild();
if (type_list->getKind() != Node::Kind::TypeList)
return false;
for (size_t i = 0; i < type_list->getNumChildren(); ++i) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (NodePointer child : *type_list) {

NodePointer child = type_list->getChild(i);
if (child->getKind() == Node::Kind::Type) {
child = child->getFirstChild();
if (is_possible_dynamic(child))
return true;
}
}
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);
}
}
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);
}
};

auto *node = DemangleCanonicalType(dem, type);
return is_possible_dynamic(node);
};
VALIDATE_AND_RETURN(
impl, IsPossibleDynamicType, type,
Expand Down