scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.85k stars 1.06k forks source link

Enable compilation in the client's browser and natively on bare metal by abstracting over the compiler's execution context #17767

Closed bjornregnell closed 1 year ago

bjornregnell commented 2 years ago

It would be a game-changer if the compiler could be executed on more platforms:

This would open up for many more use cases, for instance better web-based development environments.

If I understand input from @sjrd, there are some obstacles that need workarounds:

  1. The compiler relies on the actual file system
  2. Support for macros use JVM class loading of class files
  3. The ScalaJS backen produces classfiles that are used downstream by other tools such as zinc to support incremental compilation.

Achieving the goal of plug-able execution platforms would perhaps not necessarily mean a fork of the compiler if the actual execution platform could be abstracted over as a context? Perhaps the things that are specific to the JVM step-by-step can be moved to a CompilerExecutionContext and the mechanics that are very platform-specific then be implemented in different given contexts? This could be an interesting, incremental modularization of the code base, perhaps with other benefits as well...

This issue is based on previous discussions here with @julienrf and @sjrd : https://teachers.scala-lang.org/t/web-based-development-environments/18/4

bjornregnell commented 2 years ago

This is perhaps also relevant to Almond? @alexarchambault @sbrunk

bjornregnell commented 2 years ago

It would be really cool to be able to compete with dynamic languages such as Python by providing the Scala compiler as a portable thing that could be executed like a function...

contrun commented 2 years ago

Excellent idea. I'd like to add a few example usage if we're able to run dotty on the web.

bjornregnell commented 2 years ago

Cool use cases @contrun ! I guess this all boils down to a trade-off between 1) how valuable this would be for the community and 2) how much effort it would take by core compiler contributors. So every input on the value of this as well as what it would take achieve it from a technical point of view is valuable.