-
Notifications
You must be signed in to change notification settings - Fork 344
[lldb] Implement TypeSystemSwiftTypeRef::IsPossibleDynamicType #2232
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
Changes from all commits
cd9a7fc
6ef3f67
4beccfb
1122b69
e97417a
26fa282
8552c56
f8d2fb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1764,13 +1764,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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Side note: And here we should have an error channel ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by changing the return type of this function? or by logging? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was just me rambling — you didn't design this API :-) It would be best if all CompilerType operations had a way to signal an error case, so we aren't silently ignoring errors. Either by returning Optionals, Expected, and for the functions that return a new type, potentially even a special Error type in a special Error TypeSystem, so the operations still compose nicely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I totally agree. |
||
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 = [&]() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: This is a good example of some of LLDB's less than great APIs. I'm sure we're not very consistent in whether this should get cleared or not in the failure case...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
SwiftASTContext
it is cleared unconditionally.