Skip to content

[lldb] Implement TypeSystemSwiftTypeRef::GetNumTemplateArguments #2892

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

Conversation

augusto2112
Copy link

This follows the same behavior as SwiftASTContext::GetNumTemplateArguments, which only returns the number of template arguments of generic types and not generic functions.

rdar://68171376

@augusto2112
Copy link
Author

@swift-ci test

@augusto2112 augusto2112 force-pushed the get-num-template-args-swifttyperef branch from da826cc to 5ece8d6 Compare April 28, 2021 20:27
@augusto2112
Copy link
Author

@swift-ci test

case Node::Kind::BoundGenericOtherNominalType:
case Node::Kind::BoundGenericTypeAlias:
case Node::Kind::BoundGenericFunction: {
auto child = node->getChild(1);
Copy link

@kastiglione kastiglione Apr 28, 2021

Choose a reason for hiding this comment

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

I am pretty sure getChild fails when accessing an index that doesn't exist, so generally we defensively check the number of children before accessing.

also llvm style is to indicate pointers even with auto declarations, ex auto *child:

Copy link
Author

Choose a reason for hiding this comment

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

One question I had about children: can I assume the indexes of the children won't change between different compiler releases? For example, right now TypeList is always the child at index 1 of these BoundGenericX nodes, can I assume this will always be true, or should I iterate over the children until I find the first one with kind TypeList?

Choose a reason for hiding this comment

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

I believe this is ABI and so shouldn't change. I think we assume indexes in some places, and in other places we iterate. I think assuming a known index is fine, but let's see what Adrian says.

Choose a reason for hiding this comment

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

      if (node->getNumChildren() > 1) {
        NodePointer child =  getChild(1);

Choose a reason for hiding this comment

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

The ordering is ABI, but there are some node types that by design some nodes can have an arbitrary number of children and future extensions might add additional children, I believe.

@augusto2112 augusto2112 force-pushed the get-num-template-args-swifttyperef branch from 5ece8d6 to f2e4194 Compare April 29, 2021 18:18
@augusto2112
Copy link
Author

@swift-ci test

Copy link

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

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

@augusto2112 augusto2112 force-pushed the get-num-template-args-swifttyperef branch from f2e4194 to 9746edf Compare April 30, 2021 15:34
@augusto2112 augusto2112 force-pushed the get-num-template-args-swifttyperef branch from 9746edf to 9df8052 Compare April 30, 2021 15:41
@augusto2112
Copy link
Author

@swift-ci test

@augusto2112 augusto2112 merged commit cf0cef7 into swiftlang:swift/release/5.5 May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants