Behaviour of `@experimental` in Scala 3

I have found a simple solution to the complications using experimental code. The idea is simple: we can add an -experimental compiler flag allowing users to use any experimental features. At the same time, this flag would not break the transitive properties of experimental code (i.e. any code that depends on experimental code is itself experimental).

This implies that an application that wants to use experimental features only needs to add the -experimental flag on any compiler version. Libraries can opt-in as purely experimental using -experimental.

To achieve this, the -experimental behave as follows:

  • Annotate all top-level classes with @experimental (possibly as a desugaring)
  • Build tools / incremental compilation: Toggling on or off the -experimental flag will invalidate all compiled classes to force them to be recompiled with or without the added @exerimental annotations
2 Likes