Scala 3 Experts? Have a few questions about changes to implicit search

27 views
Skip to first unread message

David Hall

unread,
Apr 16, 2021, 1:31:09 AM4/16/21
to scala-...@googlegroups.com
Hi everyone,

Working on porting Breeze to Scala 3. It's mostly been mechanical, but I think there's been a major change to how implicits are prioritized and I want to check my understanding.

E.g. if I have

val x : DenseVector[Double] = ???
x := 0.0

which needs an implicit OpSet.InPlaceImpl2[DenseVector[Double], Double]. Previously this would find the right implicit value in DenseVector's companion object. Now however, it's ambiguous with the one in Vector's companion:

ambiguous implicit arguments: both value dv_s_UpdateOp_Double_OpSet in trait DenseVectorOps and value v_s_UpdateOp_Double_OpSet in trait VectorOps match type breeze.linalg.operators.OpSet.InPlaceImpl2[TT, Double] of parameter op of method := in trait NumericOps

This is highly annoying because it means I'll need to reorganize all of the implicits, unless I'm missing something. I can't find the spec for Scala 3, so I dunno what to expect.

There's at least one other oddity, but this is by far the biggest.

Any experts here? Happy to hash this out over email or talk over video call at some point if that's easier.

Thanks!

-- David

David Hall

unread,
Apr 16, 2021, 2:48:59 AM4/16/21
to scala-...@googlegroups.com
Here's the branch in case anyone wants to play with it:

David Hall

unread,
Apr 16, 2021, 3:45:11 PM4/16/21
to scala-...@googlegroups.com
And I went ahead and minimized it and filed a bug against Dotty.


-- David

David Hall

unread,
Apr 26, 2021, 1:05:05 AM4/26/21
to scala-...@googlegroups.com
Hi everyone,

So, as you may have seen from the issue I linked, the implicit search behavior I've been relying on for roughly a decade has been declared a bug in Scala 2... I have managed to mostly refactor things to a state where things aren't totally broken, but I'm now pretty stuck on an important last step: getting implicit operators to "back off" to less specific instantiations when necessary. (e.g. I don't have a way of adding a Matrix and a SliceMatrix, but I do have a way to do a Matrix and a Matrix, so we can downcast the op.) Contravariance in Scala 2 has meant that I don't want to do the "obvious" thing and make operators contravariant in their arguments, because historically Scala's preferred the "least specific" in that case. All the tricks I've tried have failed.

I'd really appreciate some help if anyone's got some cycles.

-- David

David Hall

unread,
Apr 26, 2021, 1:06:26 AM4/26/21
to scala-...@googlegroups.com
(FWIW, this means I can't even fall back on my stance that you can just rely on Scala 2.13 Breeze. I suspect that the implicit search changes will mean the Scala 2.13 artifacts won't behave well at all in Scala 3.)

David Hall

unread,
May 4, 2021, 2:18:00 AM5/4/21
to scala-...@googlegroups.com
For anyone following along at home, the good news is that I got it compiling and tests passing under Scala 3, but the bad news is that I broke Scala 2.12 and probably 2.13 pretty badly with diverging implicits all over the place... and pretty much everything triggers clean compiles now and clean compiles in Scala 2.12 take about 10 minutes.

I increasingly don't think it will be reasonable to support both Scala 2 and Scala 3, at least for something as implicit parameter happy as Breeze.

Marcel Luethi

unread,
May 4, 2021, 11:54:30 AM5/4/21
to scala-...@googlegroups.com
Hi David

Thanks for the update.

I don't know how others think, but I find breeze sufficiently stable and feature complete for my day to day work, that I could easily live with a solution where Breeze for Scala 2.13 would only receive the most important bug-fixes and all new developments would only be available with Scala 3.0. From what I understand,,it should also be possible to use Scala 3.0 libraries from Scala 2.13, if this is really a need.

Best regards,

Marcel

--
You received this message because you are subscribed to the Google Groups "Scala Breeze" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-breeze...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-breeze/CALW2ey1Aq%3DtGQ8Xu3437oYt91ozc75-fs%2BXtPuXAGBFyYriopw%40mail.gmail.com.

David Hall

unread,
May 4, 2021, 1:27:11 PM5/4/21
to scala-...@googlegroups.com
I think it's not going to be as easy as that, unfortunately. I get a different set of diverging implicit expansions under 2.13 and I suspect those still show up using a 3.0 library from 2.13, but I could be wrong.

Darren Wilkinson

unread,
May 5, 2021, 3:09:15 AM5/5/21
to Scala Breeze
FWIW, I think that Breeze (for Scala 2) has been very stable now for a number of years. So I personally think it's fine to draw a line under it and switch to Scala 3 only for future versions. If it encourages others to speed up their migration to Scala 3, so much the better.

David Hall

unread,
May 5, 2021, 2:03:09 PM5/5/21
to scala-...@googlegroups.com
Thanks!

I managed to get it working so we'll see how it goes. One of the more important consumers of Breeze is Spark, which is still not even on Scala 2.13 (though it looks like it's not too far away?). That, and a lot of stubbornness, is what's driving me to try to keep 2.12/2.13 support.

-- David

--
You received this message because you are subscribed to the Google Groups "Scala Breeze" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-breeze...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages