cats icon indicating copy to clipboard operation
cats copied to clipboard

Suppress Compiler Warnings (kernel)

Open satorg opened this issue 2 years ago β€’ 23 comments

This is an ongoing effort for suppressing compiler warnings that keep plaguing the project.

Suppresses the warnings in kernel* modules for all Scala versions.

satorg avatar Apr 16 '22 18:04 satorg

Seems there can be some issues with @nowarn("cat=unused-params") while upgrading to Scala 3.1.x versions (see discussion in https://github.com/http4s/http4s/pull/6300#pullrequestreview-943891503)

Perhaps, it may make sense to make use of val _ = someUnusedParam pattern in this PR as well...

satorg avatar Apr 17 '22 02:04 satorg

The other option is we continue to keep fatal warnings disabled on Scala 3 πŸ˜•

armanbilge avatar Apr 17 '22 02:04 armanbilge

I don't think it's going to help... Scala 3.0 silently ignores unused parameters along with any kind of @nowarn annotation. Whereas Scala 3.1 will be failing on @nowarn("cat=unused-params") anyway regardless of the fatal warnings option.

satorg avatar Apr 17 '22 04:04 satorg

Added more thoughts on how to overcome the compatibility issue: https://github.com/http4s/http4s/pull/6300#discussion_r851824642

I'm considering to take that approach, but sincerely open to discussion :)

satorg avatar Apr 18 '22 01:04 satorg

Hi @armanbilge. I realized that warnings for Scala 2.12 for unused .. well, everything .. were suppressed entirely in sbt-typelevel:

      val warnings212 = Seq("-Xlint:-unused,_")

So.. I wonder – was it made intentionally and can we assume now that the warnings regarding unused stuff will never show up for Scala 2.12?

satorg avatar Jun 17 '22 05:06 satorg

Oh, interesting πŸ˜… sbt-typelevel inherited those settings from sbt-spiewak which derived them from sbt-tpolecat. So probably intentional. In any case, it's what all the builds are using now, and many were using before too, so it probably works just fine.

armanbilge avatar Jun 17 '22 05:06 armanbilge

That's fine... Just curious though – is it just because 2.12 is sunsetting and no one likes messing around with it? Or is it something more special...

satorg avatar Jun 17 '22 05:06 satorg

Here's the original commit. https://github.com/djspiewak/sbt-spiewak/commit/95a45d0ea91a015c1e38e9f56d5533bb3acd8f28

armanbilge avatar Jun 17 '22 06:06 armanbilge

Oh that's interesting... It was introduced even before Scala 2.13.0 was released. Seems like Daniel just didn't like that sort of warnings at all πŸ˜„

satorg avatar Jun 17 '22 06:06 satorg

Btw, remember sbt-typelevel hosts itself and sbt uses Scala 2.12. I'll have to check later but I'm pretty sure I have unused warnings when I develop it. So maybe it's enabled by something else πŸ€”

armanbilge avatar Jun 17 '22 06:06 armanbilge

Well, for Cats it's definitely disabled because when I enable it temporarily and re-compile for 2.12, then the "unused" warnings begin coming in numbers.

satorg avatar Jun 17 '22 15:06 satorg

You're right. I was dreaming about sbt-typelevel, seems I don't have unused warnings there at all πŸ™ƒ

armanbilge avatar Jun 17 '22 15:06 armanbilge

@satorg I've bumped sbt-typelevel to a snapshot with your PR (thanks again for doing that!). That should unblock your work, and we'll make sure to get on a stable release before we merge :)

armanbilge avatar Jul 12 '22 01:07 armanbilge

@armanbilge Initially I intended to fix compiler warnings in a bulk. And I completed with "kernel" modules quite a long ago. But turned out that "core" modules have quite a lot of warnings like these:

[warn] /Users/.../typelevel/cats/core/src/main/scala/cats/syntax/bitraverse.scala:26:22: parameter value evidence$1 in method catsSyntaxBitraverse is never used
[warn]   implicit final def catsSyntaxBitraverse[F[_, _]: Bitraverse, A, B](fab: F[A, B]): BitraverseOps[F, A, B] =
[warn]                      ^
[warn] /Users/.../typelevel/cats/core/src/main/scala/cats/syntax/bitraverse.scala:31:22: parameter value evidence$2 in method catsSyntaxNestedBitraverse is never used
[warn]   implicit final def catsSyntaxNestedBitraverse[F[_, _]: Bitraverse, G[_], A, B](
[warn]                      ^
[warn] /Users/.../typelevel/cats/core/src/main/scala/cats/syntax/bitraverse.scala:48:22: parameter value evidence$4 in method catsSyntaxBitraverseBinCompat0 is never use
[warn]   implicit final def catsSyntaxBitraverseBinCompat0[F[_, _]: Bitraverse, A, B](
[warn]                      ^

which require quite gentle and precise handling I think.

But since the "kernel" modules seem to be ready, I'd like to separate the work into multiple PRs and thus keep the kernel-related part within this PR to let it being reviewed and hopefully merged. Meanwhile I can continue working on the "core" part.

Would it work, wdyt?

satorg avatar Jul 12 '22 22:07 satorg

Yup, that sounds like a very good plan to me! We can re-enable fatal warnings module-by-module.

armanbilge avatar Jul 12 '22 22:07 armanbilge

Ok nice, thank you. I think this PR is pretty much ready then.

satorg avatar Jul 12 '22 23:07 satorg

@satorg I'm sorry, I haven't forgotten about this PR.

The truth is I've been hesitating, because I'm weighing what I think are fairly straightforward changes here with the fact it requires putting Cats on an sbt-typelevel milestone. There are some non-trivial changes coming to sbt-typelevel and I'd rather not have to worry about accidentally breaking the Cats build (the fact that Cats Effect is stuck on the milestone is stress enough!).

In theory we could backport your scalac warning fixes to sbt-tl 0.4.x. However if you're eager to work on that what I'd actually love help with is integrating with the scalac-options library for 0.5.x.

armanbilge avatar Sep 12 '22 03:09 armanbilge

@armanbilge yeah, no worries. I also feel a bit hesitant about pushing this work out. Because before continuing it would be better to stabilize the build system itself.

However if you're eager to work on that what I'd actually love help with is integrating with the scalac-options library for 0.5.x.

Ah ok, I think I can help with that. Thanks.

satorg avatar Sep 12 '22 04:09 satorg

Converted to "Draft" to put on hold until work on scalac compiler options is stabilized.

satorg avatar Sep 16 '22 05:09 satorg

I arrived via good first issues [sic]. I know about options on Scala 2 and somewhat on Scala 3, and I generally endorse using -Xlint, also it's not "fatal warnings" but -Werror which I pronounce "worry". I'm interested in learning how cats can be supported by the options cross-compilation, but maybe you're already working out a solution.

som-snytt avatar Mar 21 '23 13:03 som-snytt

@satorg @som-snytt if there are folks motivated to work on this, I'm thinking we should just update Cats to the sbt-typelevel milestone to unblock this work.

In https://github.com/typelevel/cats/pull/4187#issuecomment-1243184576 I was worried about too many changes happening in sbt-typelevel, but besides the Laika upgrade the other objectives have been dormant, and I don't think that they are going to land in 0.5 after all. That's okay πŸ™

armanbilge avatar Mar 22 '23 16:03 armanbilge

@armanbilge @som-snytt if I remember correctly, there are quite a few warnings that are handled differently in different Scala versions (i.e. 2.12, 2.13, 3). And that is what we tried to address with scalac-compat. I think, it could come handy for Cats too. Are we fine with bringing it in there?

satorg avatar Mar 22 '23 16:03 satorg

Yes, scalac-compat has been wonderful! We are using it in Cats Effect now as well.

armanbilge avatar Mar 22 '23 16:03 armanbilge