scala / scala3

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

scalac: bad option '-Xelide-below' was ignored #15766

Open sabenuse opened 2 years ago

sabenuse commented 2 years ago

3.1.2

the Compile opton -Xelide-below have removed?

Florian3k commented 2 years ago

It's not present in Scala 3: https://docs.scala-lang.org/scala3/guides/migration/options-lookup.html

szymon-rd commented 2 years ago

In general, you should be able to achieve similar behavior with inline. What do you want to do?

sabenuse commented 2 years ago

how can i add it ?

szymon-rd commented 2 years ago

@sabenuse It is a new language feature in Scala 3. If you use the inline if, then you can introduce a behavior that makes a method de facto elided at compile-time:

type LogLevel = Int

object LogLevel {
  inline val Info = 0
  inline val Warn = 1
  inline val Debug = 2
}

inline val appLogLevel = LogLevel.Warn

inline def log(msg: String, inline level: LogLevel): Unit = 
  inline if (level <= appLogLevel) then println(msg)

log("Warn log", LogLevel.Warn)

log("Debug log", LogLevel. Debug)
b-studios commented 1 year ago

Hey, does anybody know whether it is supposed to be supported in the future? I am surprised to find it in the docs:

https://dotty.epfl.ch/api/scala/annotation/elidable.html

but get the same message as the OP.

Use-case I want to use it for "design by contract". Disabling assertions for production in a compiler flag seems like a reasonable thing to do. Having to develop your own assertions might not scale to code that already uses assertions.

tpunder commented 1 year ago

I just ran into this issue while trying to cross-compile Scala 2 and Scala 3 code. I assumed it was supported since @elidable is still part of the API (https://scala-lang.org/api/3.2.2/scala/annotation/elidable.html) and the code compiles fine using @elidable.

If it is no longer supported then it would probably be nice to remove it from the API or at least add a big note in the API docs that it is not supported in Scala 3 and that -Xelide-below is no longer valid.

SethTisue commented 1 year ago

at least add a big note in the API docs that it is not supported in Scala 3

yes, a PR with that would be welcome over at https://github.com/scala/scala

liontiger23 commented 1 year ago

Is the removal of compiler option intentional? Or can someone in theory support this option via PR?

som-snytt commented 1 year ago

@liontiger23 see https://github.com/scala/scala/pull/10408 for amended doc. That is, there are better mechanisms.

liontiger23 commented 1 year ago

@liontiger23 see https://github.com/scala/scala/pull/10408 for amended doc. That is, there are better mechanisms.

I understand that it is currently not implemented in the compiler.

My question is whether the contribution that supports this option be accepted? Or maybe there are some problems in practice or in principle with the existence of this functionality?

som-snytt commented 1 year ago

I believe their intention is not to implement it because there are better mechanisms as described in the scaladoc. I am not the authority; that is what I observe. The problem in practice is maintenance and too many ways to accomplish the same thing.

liontiger23 commented 1 year ago

I am not convinced that it is a better mechanism.

Proposed workaround using inline if requires source code modification in order to change the eliding behavior, while compile option allowed to change behavior at build time without any source code modification.

som-snytt commented 1 year ago

For the general case, I would want an easy way to specify "prod" vs "dev" module at build time (to use the right config module).

I think the assert use case (mentioned above) deserves its own ticket.

They've been migrating tickets to discussions; this one might be a good candidate for that.

(I was a fan of the Scala 2 feature in so far as I fixed some bugs in it.)

Edit: sjrd's reply on discord is uncharacteristically encouraging.