Skip to content

Commit 37b9bf1

Browse files
authored
Merge pull request #3581 from augusto2112/tsstyperef-dynamic-add-struct
[lldb] Consider bound types when deciding if the overall type is dynamic
2 parents 9ff3a97 + 248daba commit 37b9bf1

File tree

2 files changed

+59
-28
lines changed

2 files changed

+59
-28
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5410,6 +5410,15 @@ bool SwiftASTContext::IsPossibleDynamicType(opaque_compiler_type_t type,
54105410
if (can_type == GetASTContext()->TheBridgeObjectType)
54115411
return true;
54125412

5413+
if (auto *bound_type =
5414+
llvm::dyn_cast<swift::BoundGenericType>(can_type.getPointer())) {
5415+
for (auto generic_arg : bound_type->getGenericArgs()) {
5416+
if (IsPossibleDynamicType(generic_arg.getPointer(), dynamic_pointee_type,
5417+
check_cplusplus, check_objc))
5418+
return true;
5419+
}
5420+
}
5421+
54135422
if (dynamic_pointee_type)
54145423
dynamic_pointee_type->Clear();
54155424
return false;

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,37 +1990,59 @@ bool TypeSystemSwiftTypeRef::IsPossibleDynamicType(opaque_compiler_type_t type,
19901990
auto impl = [&]() {
19911991
using namespace swift::Demangle;
19921992
Demangler dem;
1993-
auto *node = DemangleCanonicalType(dem, type);
1994-
if (!node)
1995-
return false;
1993+
std::function<bool(NodePointer)> is_possible_dynamic =
1994+
[&](NodePointer node) -> bool {
1995+
if (!node)
1996+
return false;
19961997

1997-
if (node->getKind() == Node::Kind::TypeAlias) {
1998-
auto resolved = ResolveTypeAlias(this, GetSwiftASTContext(), dem, node);
1999-
if (auto *n = std::get<swift::Demangle::NodePointer>(resolved))
2000-
node = n;
2001-
}
1998+
if (node->getKind() == Node::Kind::TypeAlias) {
1999+
auto resolved = ResolveTypeAlias(this, GetSwiftASTContext(), dem, node);
2000+
if (auto *n = std::get<swift::Demangle::NodePointer>(resolved))
2001+
node = n;
2002+
}
20022003

2003-
switch (node->getKind()) {
2004-
case Node::Kind::Class:
2005-
case Node::Kind::BoundGenericClass:
2006-
case Node::Kind::Protocol:
2007-
case Node::Kind::ProtocolList:
2008-
case Node::Kind::ProtocolListWithClass:
2009-
case Node::Kind::ProtocolListWithAnyObject:
2010-
case Node::Kind::ExistentialMetatype:
2011-
case Node::Kind::DynamicSelf:
2012-
return true;
2013-
case Node::Kind::BuiltinTypeName: {
2014-
if (!node->hasText())
2004+
switch (node->getKind()) {
2005+
case Node::Kind::Class:
2006+
case Node::Kind::BoundGenericClass:
2007+
case Node::Kind::Protocol:
2008+
case Node::Kind::ProtocolList:
2009+
case Node::Kind::ProtocolListWithClass:
2010+
case Node::Kind::ProtocolListWithAnyObject:
2011+
case Node::Kind::ExistentialMetatype:
2012+
case Node::Kind::DynamicSelf:
2013+
return true;
2014+
case Node::Kind::BoundGenericStructure:
2015+
case Node::Kind::BoundGenericEnum: {
2016+
if (node->getNumChildren() < 2)
2017+
return false;
2018+
NodePointer type_list = node->getLastChild();
2019+
if (type_list->getKind() != Node::Kind::TypeList)
2020+
return false;
2021+
for (size_t i = 0; i < type_list->getNumChildren(); ++i) {
2022+
NodePointer child = type_list->getChild(i);
2023+
if (child->getKind() == Node::Kind::Type) {
2024+
child = child->getFirstChild();
2025+
if (is_possible_dynamic(child))
2026+
return true;
2027+
}
2028+
}
20152029
return false;
2016-
StringRef name = node->getText();
2017-
return name == swift::BUILTIN_TYPE_NAME_RAWPOINTER ||
2018-
name == swift::BUILTIN_TYPE_NAME_NATIVEOBJECT ||
2019-
name == swift::BUILTIN_TYPE_NAME_BRIDGEOBJECT;
2020-
}
2021-
default:
2022-
return ContainsGenericTypeParameter(node);
2023-
}
2030+
}
2031+
case Node::Kind::BuiltinTypeName: {
2032+
if (!node->hasText())
2033+
return false;
2034+
StringRef name = node->getText();
2035+
return name == swift::BUILTIN_TYPE_NAME_RAWPOINTER ||
2036+
name == swift::BUILTIN_TYPE_NAME_NATIVEOBJECT ||
2037+
name == swift::BUILTIN_TYPE_NAME_BRIDGEOBJECT;
2038+
}
2039+
default:
2040+
return ContainsGenericTypeParameter(node);
2041+
}
2042+
};
2043+
2044+
auto *node = DemangleCanonicalType(dem, type);
2045+
return is_possible_dynamic(node);
20242046
};
20252047
VALIDATE_AND_RETURN(
20262048
impl, IsPossibleDynamicType, type,

0 commit comments

Comments
 (0)