Skip to content

[SyntaxBuilder] Add default conformance to syntax collection elements #40120

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

Conversation

kimdv
Copy link
Contributor

@kimdv kimdv commented Nov 10, 2021

@@ -179,3 +180,27 @@ def _digest_trivia(trivia):
_digest_trivia(trivia)

return digest.hexdigest()


def create_syntax_buildable_expressible_as_syntax_collection_conformances():
Copy link
Member

Choose a reason for hiding this comment

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

IIUC this generates a map that looks as follows:

{
  'ConditionElement': [
    'ExpressibleAsConditionElementList'
  ],
  …
}

Please correct me if I’m wrong.

I’ve got a couple suggestions for this

  • Could you add a doc comment that shows the structure of the generated map by an example
  • Wouldn’t it be cleaner if it didn’t use ExpressibleAs* types as elements?
  • If the function just generates a mapping of syntax nodes to the collections they may appear as a child in, I think a more descriptive name for the function would be something like syntax_collection_element_to_collection_mapping.

Copy link
Contributor Author

@kimdv kimdv Nov 14, 2021

Choose a reason for hiding this comment

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

Could you add a doc comment that shows the structure of the generated map by an example

Added.

Wouldn’t it be cleaner if it didn’t use ExpressibleAs* types as elements?

The idea was to have the same list as in https://github.com/apple/swift/blob/06039917bda350f8832ce56590d5691329f96075/utils/gyb_syntax_support/protocolsMap.py#L3

If don't add ExpressibleAs* here, we need to add in this method, then we also need to remove it in protocolsMap.py to be able to use the same logic as now in https://github.com/apple/swift-syntax/pull/334/files#diff-1692562863ad5b0153cfede0d8b3fa518b3792f644fa2425ad41b1ac2f9ed33fR46

If the function just generates a mapping of syntax nodes to the collections they may appear as a child in, I think a more descriptive name for the function would be something like syntax_collection_element_to_collection_mapping.

Done

Copy link
Member

Choose a reason for hiding this comment

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

The idea was to have the same list as in

https://github.com/apple/swift/blob/06039917bda350f8832ce56590d5691329f96075/utils/gyb_syntax_support/protocolsMap.py#L3

If don't add ExpressibleAs* here, we need to add in this method, then we also need to remove it in protocolsMap.py to be able to use the same logic as now in https://github.com/apple/swift-syntax/pull/334/files#diff-1692562863ad5b0153cfede0d8b3fa518b3792f644fa2425ad41b1ac2f9ed33fR46

That makes sense. I don’t have too strong opinions on whether the generated map looks like

{
  'ConditionElement': ['ConditionElementList']
}

or

{
  'ExpressibleAsConditionElement': ['ExpressibleAsConditionElementList']
}

I just didn’t like the mixed approach where the keys weren’t ExpressibleAs* types but the values were ExpressibleAs*. And IIUC the old version generated that mixed version.

Having the function generate a map that’s compatible with protocolsMap.py seems very reasonable to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the protocolsMap.py.
Should we change the name as it is SYNTAX_BUILDABLE_EXPRESSIBLE_BY_CONFORMANCES now?

Copy link
Member

Choose a reason for hiding this comment

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

I think the name is still fine. It does effectively add conformances to ExpressibleBy and not to the raw buildable types.

@kimdv kimdv force-pushed the kimdv/add-default-syntax-collection-conformance branch 6 times, most recently from 6d050a4 to da6b762 Compare November 15, 2021 17:59
@kimdv kimdv force-pushed the kimdv/add-default-syntax-collection-conformance branch 2 times, most recently from 90231c2 to 6ba9f20 Compare November 16, 2021 17:43
@kimdv kimdv force-pushed the kimdv/add-default-syntax-collection-conformance branch from 6ba9f20 to 8b13466 Compare November 16, 2021 21:37
@kimdv kimdv force-pushed the kimdv/add-default-syntax-collection-conformance branch from 8b13466 to 3b307b7 Compare November 16, 2021 21:44
@kimdv
Copy link
Contributor Author

kimdv commented Nov 17, 2021

swiftlang/swift-syntax#334

@swift-ci Please smoke test

@ahoppen
Copy link
Member

ahoppen commented Nov 17, 2021

swiftlang/swift-syntax#334

@swift-ci Please smoke test

@kimdv
Copy link
Contributor Author

kimdv commented Nov 17, 2021

@ahoppen I got write access now.
So when PR is approved and Ci passes, then I'm allowed to merge right?

@ahoppen
Copy link
Member

ahoppen commented Nov 17, 2021

Congratulations 🎉

Yes, that’s correct. Feel free to also trigger CI when you think the PR is ready.

@kimdv kimdv merged commit 37649de into swiftlang:main Nov 17, 2021
@kimdv kimdv deleted the kimdv/add-default-syntax-collection-conformance branch November 17, 2021 11:35
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.

2 participants