-
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
[lldb] Implement TypeSystemSwiftTypeRef::IsPossibleDynamicType #2232
Conversation
This is written to match The I'm not entirely sure how to translate
I have other questions too, ex is |
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.
Very nice! I guess we could add unit tests for the cases in the switch if we want to.
return m_swift_ast_context->IsPossibleDynamicType( | ||
ReconstructType(type), target_type, check_cplusplus, check_objc); | ||
if (target_type) | ||
target_type->Clear(); |
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.
case Node::Kind::BuiltinTypeName: { | ||
if (!node->hasText()) | ||
return false; | ||
auto name = node->getText(); |
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.
Would you mind spelling the type out here, so it's obvious that it isn't a char*? Otherwise the comparison below looks scary :-)
return true; | ||
case Node::Kind::BuiltinTypeName: { | ||
if (!node->hasText()) | ||
return false; |
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: And here we should have an error channel ...
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.
by changing the return type of this function? or by logging?
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree.
Surprise! HasArchetype() is probably always false. We should only see generic type parameters, but no Archetypes any more. I hope there is a testcase that breaks for the opaque archetype case.
You could try and see what the type
These two should be identical. |
In
|
case Node::Kind::TypeAlias: { | ||
if (node->getNumChildren() == 2) { | ||
auto *module = node->getFirstChild(); | ||
auto *identifier = node->getLastChild(); | ||
return module->getKind() == Node::Kind::Module && | ||
identifier->getKind() == Node::Kind::Identifier && | ||
module->getText() == "Swift" && | ||
identifier->getText() == "AnyObject"; |
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.
I don't like this. $ss9AnyObjectaD
caused a failure, and this block handles that specific case. I will investigate a better solution, probably a way to resolve the alias.
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.
I have found AnyObject to be special before, too. Maybe this comes from SwiftASTContext but if it's in the compiler we probably just have to accept it.
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.
I ended up replacing this with ResolveTypeAlias
in 26fa282. Hopefully that's more reasonable.
auto *identifier = node->getLastChild(); | ||
return module->getKind() == Node::Kind::Module && | ||
identifier->getKind() == Node::Kind::Identifier && | ||
module->getText() == "Swift" && |
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.
nitpick: theres a swift::something_STDLIB_NAME constant in swift/strings.h that we should use here
@swift-ci test |
It looks like this will have to go back to an explicit check for The test failure is:
When resolving this alias, the result is a class ( |
Side note: There are a few Foundation types that are special-cased in ClangImporter and thus keep creating inconsistencies like this. I believe that this is on of them. You'll find mentions of it elsewhere, too. In the overlay it is:
and as you said it points to just an NSString.I think we should return true here (since it is an ObjC class) and ignore this particular type in the comparison. |
I wondered along these, whether this behavior is better.
These all lean toward saying the type is not dynamic, but I am just as fine doing what you said, and returning true. |
That's a good observation.
Generally speaking, ObjC classes are dynamic, but NSString is special, because it is bridged to a Swift struct type. |
@swift-ci test |
I went with this approach. The ignoring is done in 8552c56. |
Implement
TypeSystemSwiftTypeRef::IsPossibleDynamicType
to match theSwiftASTContext
implementation.rdar://68170302