Skip to content

[IDE] Ensure every walkToPre call is matched with a walkToPost call in SemaAnnotator #36628

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 1 commit into from
Apr 1, 2021

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Mar 29, 2021

We had some unbalanced calls of walkTo*Pre and walkTo*Post in SemaAnnotator, causing the new test case to crash in assert builds.

The main fix was to set Cancelled to true if traversal is being stopped in walkToExprPre.

While I was at it, I also

  • Added some more checks, ensuring that no more walkTo* calls are issued after Cancelled has been set to true.
  • Added some comments, describing the intended traversal behaviour.
  • Fixed a case where we were returning true (i.e. visit children) although we were setting Cancelled to false
  • Moved walkToExprPost to be place right after walkToExprPre

Resolves rdar://64139829 [SR-12957]

@ahoppen ahoppen requested a review from bnbarham March 29, 2021 13:36
@bnbarham bnbarham requested a review from nathawes March 30, 2021 03:25
Comment on lines -137 to +142
return true;
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Heh. Nathan and I were bamboozled by this one as well. This is actually in a lambda where the true/false is reversed. I'm happy for that to be changed/something else, but the false here actually means "no error". Ie. the check below is:

if (ReportParamList(ParamList)) return false;

So this should be true as is, not false.

Copy link
Member Author

Choose a reason for hiding this comment

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

But… why? Before anyone gets hit by this again, I’m inverting the return value of ReportParamList.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why indeed 😆. Sounds good to me!

Comment on lines 44 to 49
/// If \c walkTo*Pre returns \c true, the children are visited and \c
/// walkTo*Post is called after all children have been visited. If \c walkTo*Pre
/// returns \c false, the corresponding \c walkTo*Post call will not be issued.
/// Once the traversal is terminated, no more \c walk* calls are issued. Nodes
/// that have already received a \c walkTo*Pre call will *not* receive a \c
/// walkTo*Post call.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this comment! I really should have when I did my change in this class since all the true/falses/post being called/not really isn't obvious and took me a while to understand. You could also mention that if walkTo*Post returns false then the walk is cancelled.

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 call. It’s now included in the comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks :)

…n SemaAnnotator

We had some unbalanced calls of `walkTo*Pre` and `walkTo*Post` in `SemaAnnotator`.

The main fix was to set `Cancelled` to `true` if traversal is being stopped in `walkToExprPre`.

While I was at it, I also
- Added some more checks, ensuring that no more `walkTo*` calls are issued after `Cancelled` has been set to `true`.
- Added some comments, describing the intended traversal behaviour.
- Inverted the return value of the `ReportParamList` lambda to be in line with the return value of the enclosing `walkToDeclPre`
- Moved `walkToExprPost` to be place right after `walkToExprPre`

Resolves rdar://64139829 [SR-12957]
@ahoppen ahoppen force-pushed the pr/balanced-pre-post branch from bb93209 to 981b663 Compare March 30, 2021 10:35
@ahoppen
Copy link
Member Author

ahoppen commented Mar 31, 2021

@swift-ci Please smoke test Linux

@ahoppen ahoppen merged commit c3bfc54 into swiftlang:main Apr 1, 2021
@ahoppen ahoppen deleted the pr/balanced-pre-post branch April 1, 2021 16:21
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