Skip to content

clamp down on warnings in library project#8998

Closed
SethTisue wants to merge 4 commits intoscala:2.13.xfrom
SethTisue:library-feature-warnings
Closed

clamp down on warnings in library project#8998
SethTisue wants to merge 4 commits intoscala:2.13.xfrom
SethTisue:library-feature-warnings

Conversation

@SethTisue
Copy link
Member

and use -Wconf to prevent them from coming back

@scala-jenkins scala-jenkins added this to the 2.13.4 milestone May 20, 2020
@SethTisue SethTisue added the internal not resulting in user-visible changes (build changes, tests, internal cleanups) label May 20, 2020
@SethTisue SethTisue changed the title no more feature warnings in library project clamp down on warnings in library project May 20, 2020
@SethTisue SethTisue force-pushed the library-feature-warnings branch from 565b57a to 94412e0 Compare May 20, 2020 03:58
Compile / scalacOptions ++= Seq[String]("-sourcepath", (Compile / scalaSource).value.toString),
Compile / scalacOptions += "-Xlint:-deprecation,-inaccessible,-nonlocal-return,-valpattern,-doc-detached,_",
Compile / scalacOptions ++= Seq("-sourcepath", (Compile / scalaSource).value.toString),
Compile / scalacOptions ++= Seq("-feature", "-Xlint", "-Werror"),
Copy link
Contributor

@som-snytt som-snytt May 20, 2020

Choose a reason for hiding this comment

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

Some multi-arg warnings remain. Adolescent quarantine meme: https://www.youtube.com/watch?v=SbjAltHJRHY

Not sure about the no-warn suppresses nothing. We need @nowarn @nowarn(cat=...) to keep nowarn from warning.

Copy link
Member Author

Choose a reason for hiding this comment

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

weird, I didn't get the warnings/errors locally. I'll figure it out.

@SethTisue
Copy link
Member Author

SethTisue commented May 20, 2020

last commit is red in CI with errors I'm not seeing locally. I'll look into it

UPDATE: oh, I think it's because locally the compiler is 2.13.2, whereas on CI we build & use a newer compiler (-Dstarr.version=2.13.3-bin-94412e0-SNAPSHOT) which then produces more warnings. I could bootstrap locally but that would take time; it should be sufficient to use 2.13.head which is 2.13.3-bin-45da54e (-Dstarr.version=2.13.3-bin-45da54e)

@SethTisue
Copy link
Member Author

SethTisue commented May 21, 2020

some of the warnings are about AnyRefMap and LongMap having multi-arg infix +=; I opened scala/bug#12012 on that

@SethTisue
Copy link
Member Author

oh, I think it's because locally the compiler is 2.13.2, whereas on CI we build & use a newer compiler

and from here the plot thickens, as follows

going warning-free both bootstrapped and non-bootstrapped is a bit tricky, in two different situations, both of which I hit in this PR:

  • if we introduce a new warning category and then need to suppress that warning in some of our own code, we cannot @nowarn(cat="the-new-category") because this will fail non-bootstrapped because the category doesn't exist yet
    • workaround: use a blanket @nowarn, with a comment that the suppression should be made more specific after next re-STARR
  • if the reference compiler has a bug that causes a spurious warning, and then we fix that bug in the current compiler, then if some of our own code produces that spurious warning, we cannot @nowarn it because the bootstrapped compile will fail with "@nowarn annotation does not suppress any warnings"
    • workaround: use a blanket @nowarn, but also intentionally add something to the code that is harmless but will cause both compilers to warn, with a comment that it can be removed and the suppression made more specific after next re-STARR

maybe a more elegant solution exists for either or both of these. the workaround I found for the first problem isn't too bad, but the workaround for the second is a bit more gruesome

perhaps this is an argument for only enabling -Werror in the bootstrapped CI build and not during local development — which I think @dwijnand wanted anyway

/** Adds a new key/value pair to this map and returns the map. */
@annotation.nowarn
// TODO: after next re-STARR, fix the nowarn (here and in LongMap) to be more specific:
// @annotation.nowarn("cat=lint-multiarg-infix") // scala/bug#12012
Copy link
Contributor

Choose a reason for hiding this comment

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

@nowarn("cat=dog": @nowarn)! Otherwise, I think we just live with the build noise.

Also this one doesn't show up in the PR that deprecates them. The lint is hidden by the deprecation? Even if the deprecation is only summarized?

// have the blanket @nowarn, but then also intentionally put something warnable in. So that's
// what this is doing here. After next re-STARR, we can remove this, and then also change the
// @nowarn above to be more specific: @annotation.nowarn("cat=lint-unit-specialization")
0
Copy link
Contributor

Choose a reason for hiding this comment

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

That's pretty baroque. Sorry, I see this is a draft beer. Is it easier and more blankety to suppress all "suppresses nothing" warnings in build.sbt, then remove that after restarr? Does anyone else miss season one of american idol? Ryan Starr is the same age as Kelly Clarkson.

* process exits with a non-zero value, the LazyList will provide all lines up
* to termination but will not throw an exception.
*/
@annotation.nowarn("cat=lint-multiarg-infix") // should the warning trigger just because the method name ends in punctuation?! currently it does
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking that crazyLines_: is a suspicious name but actually multiargs is of course only for left-assoc:

log crazyLines_: builder

Maybe nothing about id_op suggests infix.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW the other hope was that a warning would hasten its exit to a module.

@SethTisue SethTisue self-assigned this Oct 8, 2020
@SethTisue
Copy link
Member Author

This is really near the top of my queue again — looking forward to finishing it off.

@NthPortal
Copy link
Contributor

@SethTisue are you okay with me stealing this?

@SethTisue
Copy link
Member Author

SethTisue commented Oct 8, 2020

are you okay with me stealing this?

absolutely

I was just discussing this with Dale recently. we were thinking:

  • warnings should never be fatal by default in local development, it's too annoying. but probably provide a convenient way to flip the fatal switch on locally
  • on CI, warnings should only be fatal before bootstrap, not after, because the other choice would be too annoying for contributors
    • the downside here is there might be new warnings post-bootstrap that are telling us something important and we wouldn't know about it until we re-STARR after release. we probably want to add some pre-release backstop for this to the release steps. perhaps re-STARR before release and after? maybe that's too big a hammer, maybe it would be fine to just have a release step that says, "re-STARR locally and see what turns up, but don't PR it"

wdyt?

@NthPortal
Copy link
Contributor

warnings should never be fatal by default in local development, it's too annoying. but probably provide a convenient way to flip the fatal switch on locally

I've done this at work. It's fairly easy to have a fatalWarnings (or Werror) boolean settings key that adds -Werror to scalacOption. You can have it set automatically from env variables (like travis or jenkins ones).

on CI, warnings should only be fatal before bootstrap, not after, because the other choice would be too annoying for contributors

another options might be to configure warnings for @nowarn uses that suppress nothing to info-summary, so that they get logged (and we can clean them up periodically if needed), but we don't run into the issue of needing to double-re-STARR.

@dwijnand
Copy link
Member

dwijnand commented Oct 9, 2020

I've done this at work. It's fairly easy to have a fatalWarnings (or Werror) boolean settings key that adds -Werror to scalacOption. You can have it set automatically from env variables (like travis or jenkins ones).

There's isCI.value which is set in terms of env vars.

another options might be to configure warnings for @nowarn uses that suppress nothing to info-summary, so that they get logged (and we can clean them up periodically if needed), but we don't run into the issue of needing to double-re-STARR.

IMO: let's not bite off more than we can chew, let's start with just fatal warnings for non-bootstrapped and try the even stricter "and for bootstrapped" variant after a few months.

@sjrd
Copy link
Member

sjrd commented Oct 9, 2020

I don't understand what's the problem with bootstrap. Can someone elaborate?

@dwijnand
Copy link
Member

dwijnand commented Oct 9, 2020

As you're making changes to warnings it can be annoying for individual commits to fail to bootstrap the compiler because of a slightly wrong warning, which IMO could prove more friction than value.

As an example the changes to REPL.scala in c02a234 (#9140) which is fixed in e8734c1 (#9140).

@sjrd
Copy link
Member

sjrd commented Oct 9, 2020

Hum, I would typically squash such commits, in the same way that I would squash a commit that fixes a bug introduced in the same PR.

@dwijnand
Copy link
Member

dwijnand commented Oct 9, 2020

And maybe that's a fine compromise/workaround (I see it as arguable IMO, as it's useful to keep some diffs separate). I'm just saying let's take the half step first, as I've found it exhausting to work with very strict warnings-as-errors (e.g. fatal unused imports in the REPL...).

@NthPortal
Copy link
Contributor

NthPortal commented Oct 9, 2020

There's isCI.value which is set in terms of env vars.

I did not know that. I will change it to use that. I can't seem to find it/get sbt to load the build with that. does it need to be qualified by something?

let's not bite off more than we can chew, let's start with just fatal warnings for non-bootstrapped and try the even stricter "and for bootstrapped" variant after a few months.

I have no idea how to only enable fatal warnings for non-bootstrapped builds, so doing so is actually significantly harder for me

@dwijnand
Copy link
Member

dwijnand commented Oct 9, 2020

I did not know that. I will change it to use that. I can't seem to find it/get sbt to load the build with that. does it need to be qualified by something?

Sorry, insideCI.value.

I have no idea how to only enable fatal warnings for non-bootstrapped builds, so doing so is actually significantly harder for me

Yeah, I understand, and if it's better to land a version of this PR even without that - I don't want it to block the progress. I'm still learning myself (part of the reason I built the restarr/restarrFull commands in ScriptCommands).

I think the presence of starr.version in the sys.props is a reasonable approximation for "we're testing bootstrapping", as it's what (AFAICT!) both the Jenkins CI and Travis CI's setups use.
(Ironically it doesn't approximate correctly for my restarrFull but I can adapt that later.)

@NthPortal
Copy link
Contributor

NthPortal commented Oct 12, 2020

on CI, warnings should only be fatal before bootstrap, not after, because the other choice would be too annoying for contributors

after my work on cleaning up warnings, I think I actually disagree with this. it's a real pain for errors to suddenly appear much later than they were introduced, simply because they don't fail without bootstrapping

@SethTisue
Copy link
Member Author

after my work on cleaning up warnings, I think I actually disagree with this. it's a real pain for errors to suddenly appear much later than they were introduced, simply because they don't fail without bootstrapping

how do you suggest we handle the difficulties I described in May?

@NthPortal
Copy link
Contributor

how do you suggest we handle the difficulties I described in May?

-Wconf:msg=@nowarn annotation does not suppress any warnings:is.

I don't personally think having @nowarn annotations that do nothing for a short period of time is a huge worry, and if we only suppress them when we enable -Werror, then they'll happen locally as a reminder to eventually get rid of them

@SethTisue
Copy link
Member Author

SethTisue commented Oct 12, 2020

okay, we have a plan, then!

(and also, we can adjust further, later, based on experience)

@NthPortal
Copy link
Contributor

@som-snytt is there a category for I can use instead of that message?

@som-snytt
Copy link
Contributor

A nullifying category would be handy. I've only joked about the idiom to nowarn nowarn. (I'm afraid of notifying someone; I wonder if it's too late to register github user nowarn. Maybe Arnie already has it.)

@dwijnand
Copy link
Member

dwijnand commented Oct 13, 2020

it's a real pain for errors to suddenly appear much later than they were introduced, simply because they don't fail without bootstrapping

That experience mirrors our users: new compiler (for us: new starr), new warnings. The other side of the coin is the pain for errors to appear while you're making changes in the compiler, like an unused warning or a partial pattern match: should compilation fail (disallowing a test run) because of those, in the non-bootstrapped build?

I'm happy to test out your's and Seth's plan, however. 🎲

@dwijnand
Copy link
Member

Oh, btw, @NthPortal, I'm hoping my exhaustivity checking PR is merged soon, with the idea that with your PRs we'll opt-out of the warnings to avoid them being fatal - so as to not burden you with dealing with them all. If you want to deal with them, go ahead, otherwise I'll eventually rotate back and do it.

@NthPortal
Copy link
Contributor

it does appear there is unused-nowarn, which is perhaps cleaner than my @nowarn annotation does not suppress any warnings

@som-snytt
Copy link
Contributor

I forgot that scalac -Wconf:help lists all categories.

I don't think I ever read it all the way to the end; it's sitting on my night table underneath a couple of novels.

@SethTisue
Copy link
Member Author

superseded by #9235

@SethTisue SethTisue closed this Oct 16, 2020
@SethTisue SethTisue removed this from the 2.13.4 milestone Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal not resulting in user-visible changes (build changes, tests, internal cleanups)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants