chipsalliance / chisel

Chisel: A Modern Hardware Design Language
https://www.chisel-lang.org/
Apache License 2.0
3.82k stars 576 forks source link

Scala 3 / Dotty support #2908

Open TurnOffNOD opened 1 year ago

TurnOffNOD commented 1 year ago

Type of issue: scala 3 support.

Is your feature request related to a problem? Please describe. Now scala is developing new version scala 3, and scala users are much lesser than python, so changing from scala 2 to scala 3 will be much faster than python 2 changing to python3.

Maybe it is better to support scala 3 faster.

Additional context SpinalHDL is preparing to support scala 3 from version 1.6.0: https://github.com/SpinalHDL/SpinalHDL/releases/tag/v1.6.0

Dolu1990 commented 1 year ago

So i implemented Scala 3 support for SpinalHDL.

So overall, i'm not realy happy about how Scala 3 turned, from my perspective / usecase, it is kinda like python2 -> python3 paine. Seems like more paine and suffering than anything else, not event considering the end user side of things XD

mwachs5 commented 1 year ago

@Dolu1990 could you elaborate a bit on "So far, seems to me that Scala 3 lost some of the internal DSL vibe compared to Scala 2 (from the our use case perspective)"? What are some examples of things that no longer work well?

jackkoenig commented 1 year ago

Hey Charles, thanks for letting us know about your experience.

Per the Anonymous classes, we actually provided early feedback that led to them adding a reflective form of Selectable, so I think anonymous types can be okay:

abstract class Bundle extends reflect.Selectable

val foo = new Bundle {
  val x = 3
  val y = "hi"
}

foo.x // 3: scala.Int

(Scala 3.3 Scastie: https://scastie.scala-lang.org/ElSvOOAATAeC4hyBGpqmeg)

I very much would like to upgrade to Scala 3, I'm glad to hear that upgrading your compiler plugin wasn't too bad. Many of our macros go away (chained apply in particular is made obsolete by using), SourceInfo should be easy, but @instantiable and @public may be tricky.

The move away from DSL is somewhat unfortunate but has seemed to be the zeitgeist in Scala for a few years now 😑. I think it's mostly okay from the Chisel perspective but I should check more closely.

Seq being immutable was a Scala 2.13 change and yeah that was a pretty big pain, no lie 😅.

Compiler crashes aren't great, I'm hopeful that we're so late that many have been resolved by now but we shall see!

Dolu1990 commented 1 year ago

Hi,

could you elaborate a bit on "So far, seems to me that Scala 3 lost some of the internal DSL vibe compared to Scala 2 (from the our use case perspective)"? What are some examples of things that no longer work well?

@mwachs5 So mostly 3 things i can remember which gived me that feeling :

@jackkoenig Hi ^^

Per the Anonymous classes, we actually provided early feedback that led to them adding a reflective form of Selectable, so I think anonymous types can be okay:

Yes it is what i used too, for basics it works well, but in more imbricated cases, the Scala 3 compiler had failures :

Note, those were related to having anon Selectable in anon Selectable and so one.

The move away from DSL is somewhat unfortunate but has seemed to be the zeitgeist in Scala for a few years now

:(

I think it's mostly okay from the Chisel perspective but I should check more closely.

Main issue from a user perspective, is that, as hardware is subject to much more testing / nasty failure modes than software. People will hate modifying a working code base, as it would be a risk + time require to tests everything again. (also, very often, testing isn't fully automated, ex FPGA emulation and so on)

Seq being immutable was a Scala 2.13 change and yeah that was a pretty big pain, no lie sweat_smile.

Yes XD

Compiler crashes aren't great, I'm hopeful that we're so late that many have been resolved by now but we shall see!

That was my hope too :D, so i made all the work on scala 3 14 months ago. I think the main reason of the crashes were related to the following Area feature :

val x new Area{
  val y = new Area{
    val x = new Area{
      val miaou = Reg(UInt(8 bits))
    }
  }
}
x.y.z.miaou := 0

You may not hit those.

Since then, scala 3 migration is on hold.