Skip to content

[SourceKit] Fix SyntaxModel assertion failure due to consuming tokens twice or out of order #29769

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

nathawes
Copy link
Contributor

@nathawes nathawes commented Feb 11, 2020

The SyntaxModel walker would end up visiting the attributes attached to a PatternBindingDecl twice if it contained more than one VarDecl, hitting the below assertion on the second visit because the tokens corresponding to the attribute had already been consumed the first time around:

Assertion failed: (0 && "Attribute's TokenNodes already consumed?"), function handleSpecialDeclAttribute

It would also hit the same assertion for attributes on an EnumCaseDecl, but even when it only had a single child EnumElementDecl. This because when we visited the EnumCaseDecl and pushed its structure node, we'd consume and emit any tokens before it's start position. This meant that when we tried to process the attributes attached to the child EnumElementDecl its tokens had already been consumed, triggering the assertion.

In both cases the attributes syntactically attach to the parent PatternBindingDecl or EnumCaseDecl, but in the AST they're accessed via their child VarDecls or EnumElementDecls.

Resolves rdar://problem/53747546

@nathawes
Copy link
Contributor Author

@swift-ci please test

@nathawes nathawes requested a review from rintaro February 11, 2020 22:55
@nathawes nathawes force-pushed the fix-syntax-model-assertion-failures branch from dcd0159 to 7e66dab Compare February 11, 2020 23:39
@nathawes nathawes changed the title [SourceKit] Fix SyntaxModel assertion failure due to visiting attributes twice [SourceKit] Fix SyntaxModel assertion failure due to consuming tokens twice or out of order Feb 11, 2020
@nathawes
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 200c186b57e5ce4f8038a44ca676e6fa4d7f2dd2

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 200c186b57e5ce4f8038a44ca676e6fa4d7f2dd2

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 200c186b57e5ce4f8038a44ca676e6fa4d7f2dd2

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 200c186b57e5ce4f8038a44ca676e6fa4d7f2dd2

@nathawes
Copy link
Contributor Author

@swift-ci please smoke test

…s twice or prematurely

The SyntaxModel walker would end up visiting the attributes attached to a
PatternBindingDecl twice if it contained more than one VarDecl, hitting the
below assertion on the second visit because the tokens corresponding to the
attribute had already been consumed the first time around:
```
Assertion failed: (0 && "Attribute's TokenNodes already consumed?"), function
  handleSpecialDeclAttribute
```
It would also hit the same assertion for attributes on an EnumCaseDecl, but even
when it only had a single child EnumElementDecl.  This because when we visited
the EnumCaseDecl and pushed its structure node, we'd consume and emit any tokens
before it's start position. This meant that when we tried to process the
attributes attached to the child EnumElementDecl its tokens had already been
consumed, triggering the assertion.

In both cases the attributes syntactically attach to the parent
PatternBindingDecl or EnumCaseDecl, but in the AST they're accessed via their
child VarDecls or EnumElementDecls.

Resolves rdar://problem/53747546
@nathawes nathawes force-pushed the fix-syntax-model-assertion-failures branch from fcbb779 to 5e1985c Compare February 12, 2020 21:44
@nathawes
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

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

LGTM!

@nathawes nathawes merged commit 947c6c9 into swiftlang:master Feb 12, 2020
@nathawes nathawes deleted the fix-syntax-model-assertion-failures branch February 12, 2020 23:44
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