Skip to content
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

Fix the non-miniphase tree traverser #16684

Merged
merged 2 commits into from
Jan 18, 2023

Conversation

PaulCoral
Copy link
Contributor

Fixes #16678. The issue is related to the second tree traverser (needed as miniphase traverser do not cover every cases).

Symbols are added to a set during the traversal of their own definition to avoid recording recursive. In the second tree traverser this symbol is never removed, so the following usage are never cached, resulting in false positive.

@szymon-rd

- Fix the non-miniphase traverser
- Update test cases
@szymon-rd
Copy link
Contributor

Could you fix the conflicts? @PaulCoral

@smarter
Copy link
Member

smarter commented Jan 16, 2023

I'm concerned that this phase uses both the miniphase traversing logic and a TreeTraverser, aren't you traversing the same trees multiple times?

@szymon-rd
Copy link
Contributor

@smarter Paul responded to this concern in his initial PR:
#16157 (comment)

@PaulCoral
Copy link
Contributor Author

Could you fix the conflicts? @PaulCoral

Yes, this seems OK to me.

(also I resolve conflict with main and it passes the test locally)

@smarter
Copy link
Member

smarter commented Jan 17, 2023

Paul responded to this concern in his initial PR:

I'm still somewhat confused:

  • you can pattern match on the tree in prepareOthers if you need to do different things on different trees, this doesn't require doing a traversal
  • if you really need to do a full traversal, then maybe the phase should not be a mini phase and instead just do the traversal

@szymon-rd
Copy link
Contributor

I agree that this is a bit confusing. But IMO it should land in another issue and PR.

@PaulCoral
Copy link
Contributor Author

Paul responded to this concern in his initial PR:

I'm still somewhat confused:

  • you can pattern match on the tree in prepareOthers if you need to do different things on different trees, this doesn't require doing a traversal
  • if you really need to do a full traversal, then maybe the phase should not be a mini phase and instead just do the traversal

The current design of the traversal may appear to be quite confusing and has been a subject of some debate. Here, the full traversal is needed as the miniphase does not traverse many type-related parts of the tree, and thus, the symbols are not registered, resulting in many false positives (e.g. an import used only as a type argument). The first design in #16157 was using only a Traversers. It was also decided that it could be useful to convert to miniphase, as in the future, some linter options could be added through other miniphases, resulting in a single tree traversal. Using a TreeTraverser avoids duplicating the code of the foldOver method in Trees.scala, and the traversals are usually very short (often only type parameter clauses).

I agree that this is a bit confusing. But IMO it should land in another issue and PR.

I agree that it may not be optimal, a should maybe be discussed.

@smarter
Copy link
Member

smarter commented Jan 18, 2023

Thanks for the explanation. I think it would be helpful to add a pattern match on tree in prepareForOther to be explicit about the trees that end up here (similar to https://github.com/lampepfl/dotty/blob/b824375daa21f96b12ddbfa8ea98672adc3d2a1a/compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala#L165-L172).
Even if we end up doing the same thing for all trees, it would be helpful to understand what the code does exactly. But this doesn't have to be done in this PR of course.

@szymon-rd
Copy link
Contributor

Merging it now.

@szymon-rd szymon-rd merged commit 9337bd6 into scala:main Jan 18, 2023
@PaulCoral PaulCoral deleted the fix/Wunused/non_miniphase_traverser branch June 8, 2023 19:49
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 2023
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.

-Wunused:all and named function arguments
4 participants