Skip to content

Prevent incorrect node_choices and ignore token_choices #1034

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
merged 7 commits into from
Oct 28, 2022

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Oct 27, 2022

The python files put structural restrictions on the allowed syntax node kinds for node_choices, token_choices and text_choices but we weren’t enforcing them anywhere during creation of raw nodes.

With #1010 we are actually making use of these restrictions and are failing if the invariant we impose on ourselves are not upheld, which caused #1025.

After some discussion with @rintaro and @bnbarham we agreed that we should:

  • Make sure no incorrect node types are passed to nodes that have node_choices by introducing the equivalent of SynaxChildChoices in the RawSyntax world
  • Disallow multiple different token kinds as different node_choices. All tokens should have the same node_choice. This way we don’t need to look at token kinds to determine which case of a SyntaxChildEnum a token belongs to
  • Once we drop support of the C++ parser, we can delete token_choices and text_choices. Since they weren’t enforced, they were misleading and are not providing any real value.

Fixes #1025
Resolves rdar://101589498

@ahoppen ahoppen requested a review from rintaro October 27, 2022 19:37
@ahoppen
Copy link
Member Author

ahoppen commented Oct 27, 2022

@swift-ci Please test

% end
%
% if token_choices:
if let tok = syntaxNode.as(TokenSyntax.self) {
Copy link
Member

@rintaro rintaro Oct 27, 2022

Choose a reason for hiding this comment

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

We should be able to have init(_: TokenSyntax) initializer now. (see line: 66)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Thanks

@ahoppen ahoppen force-pushed the ahoppen/raw-node-choices branch from d2c1a1c to f3a89c2 Compare October 27, 2022 20:27
@ahoppen
Copy link
Member Author

ahoppen commented Oct 27, 2022

@swift-ci Please test

Comment on lines 66 to 69
% # We don't add 'init(_: TokenSyntax)' because we need to check the
% # token kind.
% if choice.is_token():
% pass
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the comment too 🙏

%           # We don't add 'init(_: TokenSyntax)' because we need to check the
%           # token kind.

@ahoppen ahoppen force-pushed the ahoppen/raw-node-choices branch from f3a89c2 to ecd2ba9 Compare October 27, 2022 20:44
@ahoppen
Copy link
Member Author

ahoppen commented Oct 27, 2022

@swift-ci Please test

jpsim added a commit to realm/SwiftLint that referenced this pull request Oct 27, 2022
Moves syntax classifications to a new IDEUtils module.

Pulls in swiftlang/swift-syntax#1034
@ahoppen ahoppen force-pushed the ahoppen/raw-node-choices branch from ecd2ba9 to c34bbb6 Compare October 27, 2022 23:22
@ahoppen ahoppen force-pushed the ahoppen/raw-node-choices branch from c34bbb6 to f7b50bc Compare October 27, 2022 23:23
@ahoppen
Copy link
Member Author

ahoppen commented Oct 27, 2022

@swift-ci Please test

jpsim added a commit to realm/SwiftLint that referenced this pull request Oct 28, 2022
Moves syntax classifications to a new IDEUtils module.

Pulls in swiftlang/swift-syntax#1034
@ahoppen ahoppen merged commit 5881fce into swiftlang:main Oct 28, 2022
@ahoppen ahoppen deleted the ahoppen/raw-node-choices branch October 28, 2022 07:15
@ahoppen ahoppen mentioned this pull request Oct 28, 2022
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.

Crash when parsing initializer with unavailable attribute
2 participants