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

[2.12] Configurable warnings (backported) #9248

Merged
merged 28 commits into from Oct 22, 2020

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Oct 15, 2020

Backport of:

NthPortal and others added 3 commits October 13, 2020 16:25
Remove calls to System.exit/sys.exit outside of main methods.

(cherry picked from commit 61abb61)
Complete the reporting refactor to use internal.Reporter.

The partest blocker was fixed in v1.0.14. sbt and IDE
are not validated, so reporters.Reporter is not removed.

There are internal dependencies on cancel and comment
functionality, which is resolved here by typecasing.
Both features need to be implemented otherwise.

ConsoleReporter is still a reporter.Reporter.

(cherry picked from commit d59389e)
Let legacy Reporter handle adaptations.

Reporter knows how to adapt new API and enforce maxerrs.
The onus of supporting legacy reporter is on legacy reporter.

Keep new reporters simple enough.

Old reporters remain legacy reporters.
Some tests expect to downcast to the reporter
they assigned to `global.reporter`. Also avoid
delegating to `NoReporter`.

(cherry picked from commit e3b1e7c)
@dwijnand dwijnand force-pushed the 2.12/conf-warnings branch 2 times, most recently from f247d42 to 6ee01f2 Compare October 16, 2020 09:00
som-snytt and others added 9 commits October 16, 2020 10:09
(cherry picked from commit 043c5ad)
The extended explanation attached to the first feature
warning would fool the reporter if the feature is reported
again at the same position.

Use a conventional leading `"----"` to demarcate the
explanation, and use only the prefix to see if the error
has already been issued at a position.

(cherry picked from commit 6a27388)
(cherry picked from commit 7ca0a7f)
This can be handy for retaining source compatibility. Or for when you
just know better.

Fixes scala/bug#8908

(cherry picked from commit ee18631)
(cherry picked from commit 9ced2d8)
ContextReporter no longer extends Reporter. The ContextReporter is
only used in the context, and it reports through Global.reporter. But
it's never assigned to Global.reporter. So better keep the two
separate. This also saves the inherited fields (ContextReporters are
allocated manies, type checking every Apply uses silent).

Remove most reporter mixins to get to a linear inheritance structure,
no more delegating reporters.

Ignore the `force` parameter of `info0`.

Some quirks to remain source compatible with the sbt compiler interface.
`nsc.reporters.Reporter` only exists for sbt compatibility, Global
has a `FilteringReporter`. `-Xreporter` must be a FilteringReporter.

(cherry picked from commit 5f6b28c)
(cherry picked from commit b13d671)
(cherry picked from commit 3e7e0ab)
(cherry picked from commit 2cf8e5c)
@dwijnand

This comment has been minimized.

@dwijnand dwijnand force-pushed the 2.12/conf-warnings branch 4 times, most recently from c6a31d6 to 6b89537 Compare October 19, 2020 14:40
@dwijnand dwijnand marked this pull request as ready for review October 20, 2020 07:29
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.

Looked through the FIXMEs. I pushed a change for the ones in WConfTest, commented on the others.

src/compiler/scala/tools/nsc/backend/jvm/opt/Inliner.scala Outdated Show resolved Hide resolved
src/compiler/scala/tools/nsc/typechecker/Typers.scala Outdated Show resolved Hide resolved
src/compiler/scala/tools/reflect/FormatInterpolator.scala Outdated Show resolved Hide resolved
src/reflect/scala/reflect/internal/Variances.scala Outdated Show resolved Hide resolved
test/files/pos/nowarnMacros/Test_2.scala Outdated Show resolved Hide resolved
src/compiler/scala/tools/nsc/Global.scala Outdated Show resolved Hide resolved
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.

LGTM otherwise - I'm impressed how you pushed this through! I really didn't think this was feasible so cleanly and in such a short time, you proved me wrong 🙂

lrytz and others added 15 commits October 21, 2020 16:03
Warnings are assigned a category.

Warnings can be filtered by category, by message regex, by site where
they are issued, and by source path. Deprecations can additionally be
filtered by origin (deprecated definition) and `since` version.

Filtered warnings can be reported as error, warning, info, summary
(like deprecations) or silent.

Adds a `-rootdir` compiler flag. It is used to relativize file paths
when using source filters (`-Wconf:src=some/source/File.scala:s`).
There might be other uses for it in the future.

Unchecked warnings are now all shown by default (they were summarized
like deprecations before).

The `-deprecation`, `-feature` and `-unchecked` settings are no longer
directly used in the compiler, they are shortcuts for specific `Wconf`
configurations. The compiler only looks at `-Wconf`.

Message filtering is performed in `global.currentRun.reporting`, not
in the `Global.reporter`. The reasons are:
  - Separation of concerns: `Reporter`s worry about how to do reporting,
    removing duplicate messages.
  - Custom `Reporter`s are used by sbt, silencer, REPL, etc. It's too
    hard to do the necessary changes to the `Reporter` interface.
  - The `Wconf` setting could change between compiler runs.
    `currentRun.reporting` respects those changes.

So all warnings in the compiler should go through `global.runReporting`
(which is the same as `global.currentRun.reporting`). This method takes
four parameters: pos, msg, category (new), site (new). The site is
usually `context.owner` (in the frontend) or `currentOwner` (in
transformations).

`Context` has a `warn` method with 3 parameters (pos, msg, category) and
inserts the `owner` as `site`, so this is used in the frontend (context
reporters are also used to support silent mode / trying twice).

The `global.warning` method is deprecated and no longer used.

There are a few calls to `Reporter.warning` left in the codebase where
no `runReporting` is reachable, I think they are all OK not to
categorize / allow filtering. E.g., when running Scaladoc

```
reporter.warning(null, "Plugins are not available when using Scaladoc")
```

(cherry picked from commit 39d3b3a)
Integrate the fantastic [silencer](https://github.com/ghik/silencer)
compiler plugin by @ghik into the compiler, which allows suppressing
warnings locally using he `@nowarn` annotation.

The `@nowarn` annotation suppresses warnings within the scope covered by
the annotation.
  - `@nowarn def foo = ...`, `@nowarn class C { ... }` suppress
    warnings in a definition
  - `expression: @nowarn` suppress warnings in a specific expression

The annotation can be configured to filter selected warnings, for
example `@nowarn("cat=deprecation")` only suppresses deprecation
warnings. The filter configuration syntax is the same as in `-Wconf`.

MiMa exception for addition of `scala.annotation.nowarn`

Reporting warnings is now delayed until after typer, because the typer
collects `@nowarn` annotations.

If we stop before typer (e.g., because there are errors in the parser),
all warnings are shown, even if they are enclosed in `@silent`.

If a phase before typer has both errors and warnings, all errors are
printed before the warnings.

(cherry picked from commit 02bce3d)
(cherry picked from commit 8d8222b)
(cherry picked from commit 60fcf45)
(cherry picked from commit 1489e59)
(cherry picked from commit 670a55c)
- echo without Position parameter to ContextReporter, used in splain
- StoreReporter.Info type/value aliases (scalameta, scapegoat)
- make `info0` deprecatedOverriding instead of final (scalameta)

(cherry picked from commit b5d951b)
Even though these warnings are emitted in the typer phase, the actual
invocation is done at the end of type checking in the root context.
So we should not use the `context.warning` method, as it injects
`context.owner` as the warning site, which is always the root symbol.

(cherry picked from commit a466056)
Previously, hasWarning meant a warning had been displayed
(as opposed to counted). Since last refactor, it means
counted, so warnings were summarized under -nowarn.
Until 2.13.1, there was no summary under -nowarn.

Let -nowarn mean -Xmaxwarns 0 (to mean show me no warnings)
and additionally don't summarize any warnings (including
erroring under -Werror).

Named constants for Reporter.filter

Test that suppression is relaxed in debug mode.

Restore maxwarns after suppressing

Scaladoc also touches nowarn

ConsoleReporter respects nowarn, since PerRunReporting
suppression mechanism has a checkpoint after typer,
such that subsequent warnings are issued directly and
therefore bump the warnings count.

(cherry picked from commit 2a2f416)
If there is an error running a forked command, such as
a Test or javac, log it instead of letting sbt swallow
the exception. (It offers to let you run the last command
to see the stack trace.)

This helps if javac goes missing.

(cherry picked from commit f342293)
Previously, a bad compiler option was ignored.

Add a common idiom to StreamCapture to set stdout;
the idiom may be suboptimal for testing.

Convert a partest to junit for regex, and eliminate
one check file.

(cherry picked from commit 580ed07)
Remove withDefault.

OutputSetting is StringSetting loosely coupled
to outputDirs.

MultiStringSetting takes a default

Back out clearSetByUser, which worked around initialization
of the setting.

(cherry picked from commit 649fea5)
(cherry picked from commit 0c52dc4)
@dwijnand dwijnand merged commit 262f5f2 into scala:2.12.x Oct 22, 2020
@dwijnand dwijnand deleted the 2.12/conf-warnings branch October 22, 2020 10:09
@SethTisue SethTisue modified the milestones: 2.12.14, 2.12.13 Oct 24, 2020
@SethTisue
Copy link
Member

needs community build work: scala/community-build#1265

x + " works"
^
x + " works"
^
Copy link
Contributor

Choose a reason for hiding this comment

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

Noticed that this is a regression. The text is supposed to align with text at prompt. I haven't checked the current head.

finaglehelper pushed a commit to twitter/finatra that referenced this pull request Mar 11, 2021
Problem
=======

Upgrade source to https://github.com/scala/scala/releases/tag/v2.12.13 from https://github.com/scala/scala/releases/tag/v2.12.12. This upgrade includes a highlighted feature of configurable warnings and errors (https://www.scala-lang.org/2021/01/12/configuring-and-suppressing-warnings.html / scala/scala#9248).

Other noticable changes our code based will experience

* Exhaustivity warnings for patterns involving tuples
* Better type checking for `CharSequence` arguments scala/scala#9292
* Simplified Reporters scala/scala#8338
* Promotion of `-deprecation` to `-Xlint:deprecation` scala/scala#7714
* Improves performance of building `immutable.{TreeMap,TreeSet}` by using mutation within the builder scala/scala#8794

Full list of changes can be found at https://github.com/scala/scala/pulls?q=is%3Amerged+milestone%3A2.12.13+

Solution
========

* Bump `BUILD` file `SCALA_REV` && `SCALAC_REV_FOR_DEPS`.
* Depdnencies which are not built for scala 2.12.13 needed to be bumped `SEMANTICDB_PLUGIN_REV` && `SEMANTICDB_REV` && `SCALAFIX_REV`.
* Include `-S-Xlint:-deprecation` to `pants.ini` preventing build failures on deprecated annotations (existing behavior)
* Bump `cache_key_gen_version` in `pants.ini` for newly built artifacts on different scala version.
* Removed scalafix plugin (`scalac-profiling`) which is not built for 2.12.13. `scalac-profiling` code looks abandoned by ~3 years.
* Updated all failing tests that could have depended or expected ordered sequences when the sequence was generated from non ordered collections.

Notes
=====

It seems a few tests and golden files in source have depended or tested against a stable sort order when sorted order is not guaranteed. This has been seen in a few places such as output json objects (map key fields), code that uses `groupBy` for rekeying results to the user and transforming into sequences, strings built from sequences or maps that are not guaranteed to be ordered.

The following PR are related to this change in expectations

scala/scala#8794
scala/scala#8948
scala/scala#9218
scala/scala#9376
scala/scala#9091
scala/scala#9216

We took the liberty updating tests with what the current map order would be or updating the test in a way that wouldn't depend on order. Since we may not fully understand all the context of the tests we are hoping this either signals to the owners that there might be some issue with assumed order or signal that upgrading might break implementations due to bug in scala 2.12.13. {D611202} will improve the files changed for workflow builder outside of this change.

Please feel to reach out directly and discuss the changes here or bring up issues with this upgrade. Slack [[https://app.slack.com/client/T86S8GHEG/C01NZAFRLFK|#scala-upgrade-2-12-13]]

JIRA Issues: SCALA-25

Differential Revision: https://phabricator.twitter.biz/D607826
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
6 participants