Skip to content

Conversation

@hamishknight
Copy link
Contributor

Replace the use of bool and pointer returns for walkToXXXPre/walkToXXXPost, and instead use explicit actions such as Action::Continue(E), Action::SkipChildren(E), and Action::Stop(). There are also conditional variants, e.g Action::SkipChildrenIf, Action::VisitChildrenIf, and Action::StopIf.

There is still more work that can be done here, in particular:

  • SourceEntityWalker still needs to be migrated.
  • Some uses of return false in pre-visitation methods can likely now be replaced by Action::Stop.
  • We still use bool and pointer returns internally within the ASTWalker traversal, which could likely be improved.

But I'm leaving those as future work for now as this patch is already large enough.

@hamishknight
Copy link
Contributor Author

@bnbarham You may have inadvertently nerd sniped me into doing this 😄

@hamishknight
Copy link
Contributor Author

@swift-ci please test source compatibility

@hamishknight
Copy link
Contributor Author

swiftlang/llvm-project#5238

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please SourceKit stress test

Copy link
Contributor

@bnbarham bnbarham left a comment

Choose a reason for hiding this comment

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

Thanks so much @hamishknight, this makes everything so much clearer!

I went through around half and stopped at all the Sema changes. Generally it seems there's a bunch of places we can now use stop rather than keeping a separate member, but given the size of the change I'd prefer those in another PR anyway.

Comment on lines +264 to +265
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above I'd say (ie. yes).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think I'd like to go through and fix these up in a follow-up

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd hope tests would catch this if not, based on the rest of the class it does seem like we mean "stop" here rather than "skip". Worth trying, but also happy to do that in a separate PR given the size of this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

shouldSkip doesn't touch isDone, so I wonder if isDone was supposed to be checked in the other branch as well 🤔. Probably doesn't really matter, I imagine we'll remove all the isDone after anyway.

Copy link
Contributor Author

@hamishknight hamishknight Sep 6, 2022

Choose a reason for hiding this comment

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

Yeah, for now I'd like to try and leave this patch as NFC as possible (modulo 26bd877), I can look into this in a follow-up (and hopefully eliminate isDone() altogether).

@hamishknight hamishknight force-pushed the walk-this-way branch 2 times, most recently from 1a15b3d to 248460e Compare September 6, 2022 13:33
@hamishknight
Copy link
Contributor Author

`walkToTypeReprPost` should return `true` to keep
walking, so we really want to check if the
`offendingType` hasn't been found yet. Otherwise
we'll bail as soon as we visit the first type.
Turns out we were getting away with dereferencing
`nullptr` in a few cases as `walk` would use
`nullptr` to indicate that the walk should be
stopped, and luckily Clang didn't optimize it to
something broken.

This commit is fairly defensive and sprinkles
some null checks for calls to `walk` directly
on a body of a function or top-level code decl.
Replace the use of bool and pointer returns for
`walkToXXXPre`/`walkToXXXPost`, and instead use
explicit actions such as `Action::Continue(E)`,
`Action::SkipChildren(E)`, and `Action::Stop()`.
There are also conditional variants, e.g
`Action::SkipChildrenIf`, `Action::VisitChildrenIf`,
and `Action::StopIf`.

There is still more work that can be done here, in
particular:

- SourceEntityWalker still needs to be migrated.
- Some uses of `return false` in pre-visitation
methods can likely now be replaced by
`Action::Stop`.
- We still use bool and pointer returns internally
within the ASTWalker traversal, which could likely
be improved.

But I'm leaving those as future work for now as
this patch is already large enough.
@hamishknight
Copy link
Contributor Author

swiftlang/llvm-project#5238

@swift-ci please test

@hamishknight
Copy link
Contributor Author

🚢

@hamishknight hamishknight merged commit 85b02d6 into swiftlang:main Sep 13, 2022
@hamishknight hamishknight deleted the walk-this-way branch September 13, 2022 13: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