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

Support src filter in -WConf (Closes #17635) #18783

Merged
merged 1 commit into from
Apr 25, 2024
Merged

Conversation

povder
Copy link
Contributor

@povder povder commented Oct 28, 2023

Fixes #18782

@povder
Copy link
Contributor Author

povder commented Oct 28, 2023

Related to #18782 #17634 #17635

@som-snytt
Copy link
Contributor

added the f- word to the comment, which links the ticket; I hope that was intended.

Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

Thanks @povder!

compiler/src/dotty/tools/dotc/reporting/WConf.scala Outdated Show resolved Hide resolved
case None => false

case Any, Deprecated, Feature, Unchecked, None
case MessagePattern(pattern: Regex)
case MessageID(errorId: ErrorMessageID)
case SourcePattern(pattern: Regex)
Copy link

Choose a reason for hiding this comment

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

Old code had a cache, shouldn't that be provided too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cache added


enum MessageFilter:

private val sourcePatternCache = mutable.Map.empty[SourceFile, Boolean]
Copy link
Member

Choose a reason for hiding this comment

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

The cache should probably be cleared on each compiler run (dotc.Compiler.newRun). What utilities does dotty have to manage caches?

Copy link
Contributor

@szymon-rd szymon-rd Oct 31, 2023

Choose a reason for hiding this comment

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

There is the PerRun in Definitions.

Or we could make it a Map of (pattern, SourceFile) -> Boolean. I think there is no state to influence the check if a source file matches a pattern.

Copy link
Member

Choose a reason for hiding this comment

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

Multiple compiler instances running at the same time might concurrently try to access and update this cache, so if this really needs to be a global map (seems like it should be tied to the Context instead?) it needs to be a ConcurrentHashMap (I'm surprised this wasn't caught by https://github.com/lampepfl/dotty/blob/main/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not knowing how this works exactly from the concurrency perspective I attempted porting over Scala2 implementation which was a plain mutable map. Given concerns about the concurrency though, would it be acceptable to not do caching in this PR? We could always make an optimization later without holding back the feature

Copy link

Choose a reason for hiding this comment

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

TBH, it was me who mentioned the cache. I can withdraw my comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cache removed

@povder povder requested a review from smarter November 14, 2023 01:59
@@ -266,6 +269,7 @@ private sealed trait WarningSettings:
|Examples:
| - change every warning into an error: -Wconf:any:error
| - silence deprecations: -Wconf:cat=deprecation:s
| - silence warnings in src_managed directory: -Wconf:src=src_managed/.*
Copy link

Choose a reason for hiding this comment

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

Shouldn't this example end with :s or :silent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -96,5 +101,52 @@ class ScalaSettingsTests:
assertEquals(Action.Silent, sut.action(depr))


private def wconfSrcFilterTest(argsStr: String, source: util.SourceFile, expectedAction: reporting.Action): Unit =
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a test with malformed regex and add an assertion on the error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Add also a test that mixes it with different wconf flags

Copy link
Contributor Author

@povder povder Mar 4, 2024

Choose a reason for hiding this comment

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

Please add a test with malformed regex and add an assertion on the error.

Added

d65e8f8#diff-f4b356d10a0ec15d5030bed4c51b0fc839753cc43c5854475ed9701e6bc5148bR170

Copy link
Contributor Author

@povder povder Mar 4, 2024

Choose a reason for hiding this comment

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

Add also a test that mixes it with different wconf flags

Added

d65e8f8#diff-f4b356d10a0ec15d5030bed4c51b0fc839753cc43c5854475ed9701e6bc5148bR187

)
)

@Test def `WConf src filter can be mixed with other filters with rightmost taking precedence`: Unit =
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, in Scala 2 the leftmost takes precedence. Also -Wconf:help (on Scala 3) says otherwise.

https://github.com/lampepfl/dotty/blob/a095115b43398feeac3ee4329edb87f87da00012/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala#L268-L269

So this is a bug that should be fixed. I think a separate PR is better, so I filed #19885.

@tOverney
Copy link
Contributor

It's really awesome to see this PR and all the efforts done by @povder !

What is holding this up at the moment? Is it the "change requested" review from @szymon-rd from December?

It would be amazing to get this feature back in Scala3

@povder
Copy link
Contributor Author

povder commented Apr 22, 2024

@szymon-rd @Kordyjan I've addressed the comments quite a while ago, could I have another review or possibly this could be merged now?

Copy link
Contributor

@szymon-rd szymon-rd left a comment

Choose a reason for hiding this comment

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

LGTM now - But I am no longer in the team maintaining this repo, so probably better to tag someone else to merge it to main @Kordyjan
edit: Oh, I see you already tagged him

@Gedochao Gedochao assigned Linyxus and unassigned szymon-rd Apr 23, 2024
@Gedochao Gedochao requested review from Linyxus and removed request for charego April 23, 2024 10:04
Copy link
Contributor

@Linyxus Linyxus left a comment

Choose a reason for hiding this comment

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

Looks great to me!

@Gedochao Gedochao merged commit 86e2fe5 into scala:main Apr 25, 2024
19 checks passed
@mkurz
Copy link
Contributor

mkurz commented Apr 25, 2024

Would it be possible to backport this to 3.3.x?

@Gedochao Gedochao added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Apr 25, 2024
nicolasstucki added a commit to dotty-staging/dotty that referenced this pull request Apr 25, 2024
@Gedochao Gedochao removed the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Apr 25, 2024
@Kordyjan
Copy link
Contributor

Would it be possible to backport this to 3.3.x?

I think it will be backported. We are trying to have all reporting and lining improvements on LTS.

@mkurz
Copy link
Contributor

mkurz commented Apr 25, 2024

Would it be possible to backport this to 3.3.x?

I think it will be backported. We are trying to have all reporting and lining improvements on LTS.

Awesome! Should I open a backport PR? Or will you do this?

nicolasstucki added a commit that referenced this pull request Apr 25, 2024
Conflict between #18783 and #19766.

See `val sets = ScalaSettings` in the test just above.
mkurz pushed a commit to mkurz/dotty that referenced this pull request Apr 29, 2024
@mkurz
Copy link
Contributor

mkurz commented Apr 29, 2024

I opened a backport PR:

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.

-Wconf src filter not implemented