scala-collection-contrib icon indicating copy to clipboard operation
scala-collection-contrib copied to clipboard

Improvements to the Scala 3 crossbuild

Open som-snytt opened this issue 1 year ago • 16 comments
trafficstars

Exercise in -Xsource:3-cross.

~Not sure if~ it needs to stay on 3.3.3 LTS.

Scala 2 needs uninitialized. Scala 3 needs inline tap.

Scala 2 could support import chaining.given directly, though it doesn't matter for Scala 2 implicits. https://github.com/scala/bug/issues/12999

som-snytt avatar Apr 08 '24 02:04 som-snytt

(I can be a reviewer of last resort here if needed, but I'm hoping one or more collections volunteers might step in)

SethTisue avatar May 23 '24 16:05 SethTisue

If no one else will step in sooner, I will take a look tomorrow. At first sight it looks like a stuff I should be familiar with.

OndrejSpanel avatar May 23 '24 17:05 OndrejSpanel

The change that is not syntactic is protected[this] to protected. I assume protected[this] is the most pernicious form of qualified access.

som-snytt avatar May 23 '24 17:05 som-snytt

-Wnonunit-statement did its job, because cruft is generated and unused. The better solution is

elems.getOrElseUpdate(k, Set.empty[V]).addOne(v)

on the add side. Not sure about the subtract side, where you want the remove.

It indicates that updateWith is not great for internal operations.

Actually, it warns on the addOne because even though it's the this.type of the set, you don't know which set that is. It demands a stabilized value:

    val vs = elems.getOrElseUpdate(k, Set.empty[V])
    vs.addOne(v)

I don't see this as "unnecessary ceremony".

Use of tap is also a test of cross-compilation. Scala 3 ought already to intercept that API to make it inline, so this is a way to raise awareness.

som-snytt avatar May 24 '24 12:05 som-snytt

Scala 3 ought already to intercept that API to make it inline, so this is a way to raise awareness.

Is that documented somewhere? https://www.scala-lang.org/api/current/scala/util/ChainingOps.html does not say a word about this. When I discussed in https://contributors.scala-lang.org/t/scala-3-specific-stdlib-improvements/6661/5, nobody mentioned that there.

OndrejSpanel avatar May 24 '24 14:05 OndrejSpanel

Regarding -Wnonunit-statement, I guess it is your call. While some of the changes are not necessary, all changes look harmless to me.

OndrejSpanel avatar May 24 '24 15:05 OndrejSpanel

On the warning, I think it's like saying, "Well, that unit test didn't uncover any issues, so just delete the test."

som-snytt avatar May 24 '24 15:05 som-snytt

I forgot to retract the experiment with tap, though I think it's a worthwhile experiment.

For the updateWith, we're not really updating, we're getting and mutating. In the case where the mutated set or count is exhausted, we remove the key.

som-snytt avatar May 24 '24 18:05 som-snytt

why closed?

SethTisue avatar May 25 '24 16:05 SethTisue

Reopening. To close this intentionaly I think it is at least worth a comment why (or a link to issue or PR supeseding this).

OndrejSpanel avatar May 27 '24 15:05 OndrejSpanel

Looks like Som has lost interest; would a volunteer from @scala/collections like to finish it up in a replacement PR?

SethTisue avatar Jun 22 '24 00:06 SethTisue

I can prepare a PR as described in:

The minimal PR porting to 2.13.14 while staying on 3.3.3 could just replace the library version in build.sbt (and perhaps update sbt version at the same time)

That should be just a few SBT lines.

OndrejSpanel avatar Jun 22 '24 07:06 OndrejSpanel

o 2.13.14 while staying on 3.3.3 could just replace the library version in build.sbt (and perhaps update sbt version at the same time)

This is both already merged in master as PRs made by scala-steward (#245, #246)

Scala 3.3.3 is also already used since #234, also by scala-steward.

I can create a PR based on commits which avoid updateWith, as that makes sense to me and should make future maintenance easier.

One other change which might be beneficial is to use 2.3.14 stdlib even with Scala 3.3.3 (cf. https://users.scala-lang.org/t/what-scala-library-version-is-used-by-which-scala-3-version/9999/7)

@SethTisue @som-snytt any opinion on this?

OndrejSpanel avatar Jun 24 '24 11:06 OndrejSpanel

One other change which might be beneficial is to use 2.3.14 stdlib even with Scala 3.3.3 (cf. https://users.scala-lang.org/t/what-scala-library-version-is-used-by-which-scala-3-version/9999/7)

@SethTisue @som-snytt any opinion on this?

Hmm... is there a specific reason to add the override? If not I'd just leave it alone and wait for whatever 3.3.4 gives us.

SethTisue avatar Jun 24 '24 21:06 SethTisue

Hmm... is there a specific reason to add the override?

Not really. Just a way to sneakily force the 2.13.14 fixes on unsuspecting users.

OndrejSpanel avatar Jun 25 '24 05:06 OndrejSpanel

@OndrejSpanel the 2.13.14 bump has been merged for inclusion in Scala 3.3.4 (and the Steward should give us that upgrade here once it's available, so I think we can just wait)

SethTisue avatar Jul 15 '24 16:07 SethTisue