Skip to content

Using experimental annotation in Predef causes cyclic reference. #20223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
noti0na1 opened this issue Apr 18, 2024 · 5 comments
Closed

Using experimental annotation in Predef causes cyclic reference. #20223

noti0na1 opened this issue Apr 18, 2024 · 5 comments

Comments

@noti0na1
Copy link
Member

Currently blocking #20222

Compiler version

The main branch
3.5.0-RC1-bin-SNAPSHOT-nonbootstrapped-git-7291e54

Minimized code

Predef.scala

import scala.annotation.experimental

extension (inline opt: Option.type)
  @experimental
  inline def fromNullable[T](t: T | Null): Option[T] = Option(t).asInstanceOf

Output

> clean; scalac

[error] -- [E046] Cyclic Error: /dotty/library/src-non-bootstrapped/scala/annotation/experimental.scala:3:1 
[error] 3 |@deprecatedInheritance("Scheduled for being final in the future", "3.4.0")
[error]   | ^
[error]   | Cyclic reference involving class experimental
[error]   |
[error]   |  Run with -explain-cyclic for more details.
[error]   |
[error]   | longer explanation available when compiling with `-explain`
[error] -- [E008] Not Found Error: /dotty/library/src/scala/quoted/Expr.scala:70:17 
[error] 70 |    scala.Predef.summon[ToExpr[T]].apply(x)
[error]    |    ^^^^^^^^^^^^^^^^^^^
[error]    |    value summon is not a member of object Predef
[error] -- [E008] Not Found Error: /dotty/library/src/scala/quoted/Expr.scala:85:17 
[error] 85 |    scala.Predef.summon[FromExpr[T]].unapply(x)
[error]    |    ^^^^^^^^^^^^^^^^^^^
[error]    |    value summon is not a member of object Predef
[error] -- [E006] Not Found Error: /dotty/library/src/scala/quoted/Quotes.scala:68:6 
[error] 68 |      summon[FromExpr[T]].unapply(self)
[error]    |      ^^^^^^
[error]    |      Not found: summon
[error]    |
[error]    | longer explanation available when compiling with `-explain`
[error] -- [E006] Not Found Error: /dotty/library/src/scala/quoted/Quotes.scala:77:21 
[error] 77 |      val fromExpr = summon[FromExpr[T]]
[error]    |                     ^^^^^^
[error]    |                     Not found: summon
[error]    |
[error]    | longer explanation available when compiling with `-explain`
[error] -- [E006] Not Found Error: /dotty/library/src/scala/quoted/ToExpr.scala:100:46 
[error] 100 |      '{ Array[T](${Expr(arr.toSeq)}*)(${Expr(summon[ClassTag[T]])}) }
[error]     |                                              ^^^^^^
[error]     |                                              Not found: summon
[error]     |
[error]     | longer explanation available when compiling with `-explain`
[error] -- [E006] Not Found Error: /dotty/library/src/scala/quoted/ToExpr.scala:168:24 
[error] 168 |      Expr.ofSeq(xs.map(summon[ToExpr[T]].apply))
[error]     |                        ^^^^^^
[error]     |                        Not found: summon
[error]     |
[error]     | longer explanation available when compiling with `-explain`
[error] -- [E006] Not Found Error: /dotty/library/src/scala/quoted/ToExpr.scala:174:25 
[error] 174 |      Expr.ofList(xs.map(summon[ToExpr[T]].apply))
[error]     |                         ^^^^^^
[error]     |                         Not found: summon
[error]     |
[error]     | longer explanation available when compiling with `-explain`
[error] -- [E008] Not Found Error: /dotty/library/src/scala/reflect/Selectable.scala:24:60 
[error] 24 |      val fld = rcls.getField(NameTransformer.encode(name)).nn
[error]    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |value nn is not a member of java.lang.reflect.Field | Null, but could be made available as an extension method.
[error]    |
[error]    |The following import might fix the problem:
[error]    |
[error]    |  import scala.runtime.stdLibPatches.Predef.nn
[error]    |
[error] -- [E008] Not Found Error: /dotty/library/src/scala/reflect/Selectable.scala:38:72 
[error] 38 |    val mth = rcls.getMethod(NameTransformer.encode(name), paramTypes*).nn
[error]    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |value nn is not a member of java.lang.reflect.Method | Null, but could be made available as an extension method.
[error]    |
[error]    |The following import might fix the problem:
[error]    |
[error]    |  import scala.runtime.stdLibPatches.Predef.nn
[error]    |
[error] -- [E008] Not Found Error: /dotty/library/src/scala/runtime/LazyVals.scala:18:79 
[error] 18 |      val unsafeField = classOf[sun.misc.Unsafe].getDeclaredField("theUnsafe").nn
[error]    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |value nn is not a member of java.lang.reflect.Field | Null, but could be made available as an extension method.
[error]    |
[error]    |The following import might fix the problem:
[error]    |
[error]    |  import scala.runtime.stdLibPatches.Predef.nn
[error]    |
[error] -- [E008] Not Found Error: /dotty/library/src/scala/runtime/LazyVals.scala:29:50 
[error] 29 |    val processors = java.lang.Runtime.getRuntime.nn.availableProcessors()
[error]    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |value nn is not a member of Runtime | Null, but could be made available as an extension method.
[error]    |
[error]    |The following import might fix the problem:
[error]    |
[error]    |  import scala.runtime.stdLibPatches.Predef.nn
[error]    |
[error] -- [E008] Not Found Error: /dotty/library/src/scala/runtime/coverage/Invoker.scala:54:66 
[error] 54 |    MeasurementsPrefix + runtimeUUID + "." + Thread.currentThread.nn.getId
[error]    |                                             ^^^^^^^^^^^^^^^^^^^^^^^
[error]    |value nn is not a member of Thread | Null, but could be made available as an extension method.
[error]    |
[error]    |The following import might fix the problem:
[error]    |
[error]    |  import scala.runtime.stdLibPatches.Predef.nn
[error]    |
[error] -- [E046] Cyclic Error: /dotty/library/src/scala/runtime/stdLibPatches/Predef.scala:68:15 
[error] 68 |    inline def fromNullable[T](t: T | Null): Option[T] = Option(t).asInstanceOf
[error]    |               ^
[error]    |               Cyclic reference involving method fromNullable
[error]    |
[error]    |                Run with -explain-cyclic for more details.
[error]    |
[error]    | longer explanation available when compiling with `-explain`
[warn] -- Warning: /dotty/library/src/scala/runtime/stdLibPatches/Predef.scala:64:10 
[warn] 64 |      !(x eq y)
[warn]    |          ^^
[warn]    |Alphanumeric method eq is not declared infix; it should not be used as infix operator.
[warn]    |Instead, use method syntax .eq(...) or backticked identifier `eq`.
[warn]    |The latter can be rewritten automatically under -rewrite -source 3.4-migration.
[error] -- [E008] Not Found Error: /dotty/library/src/scala/util/FromDigits.scala:138:56 
[error] 138 |    if (x == 0.0f && !zeroFloat.pattern.matcher(digits).nn.matches) throw NumberTooSmall()
[error]     |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]     |value nn is not a member of java.util.regex.Matcher | Null, but could be made available as an extension method.
[error]     |
[error]     |The following import might fix the problem:
[error]     |
[error]     |  import scala.runtime.stdLibPatches.Predef.nn
[error]     |
[error] -- [E008] Not Found Error: /dotty/library/src/scala/util/FromDigits.scala:156:56 
[error] 156 |    if (x == 0.0d && !zeroFloat.pattern.matcher(digits).nn.matches) throw NumberTooSmall()
[error]     |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]     |value nn is not a member of java.util.regex.Matcher | Null, but could be made available as an extension method.
[error]     |
[error]     |The following import might fix the problem:
[error]     |
[error]     |  import scala.runtime.stdLibPatches.Predef.nn
[error]     |
[error] No warnings can be incurred under -Werror (or -Xfatal-warnings)
[warn] one warning found
[error] 17 errors found
[error] (scala3-library / Compile / compileIncremental) Compilation failed
[error] Total time: 6 s, completed 18 Apr 2024, 14:59:41

Expectation

Should be able to use experimental annotation in library to add new functions.

@odersky
Copy link
Contributor

odersky commented Apr 18, 2024

I think we just add it in 3.5 without the @experimental. Looks hard to avoid cycles in this case.

@nicolasstucki
Copy link
Contributor

[error] 8 |@deprecatedInheritance("Scheduled for being final in the future", "3.4.0")
[error]   | ^
[error]   |Cyclic reference involving class experimental
[error]   |
[error]   |The error occurred while trying to compute the signature of class experimental
[error]   |  which required to compute the signature of object Predef
[error]   |  which required to compute the signature of object Predef
[error]   |  which required to compute the signature of method fromNullable
[error]   |  which required to compute the base classes of class experimental
[error]   |  which required to compute the signature of class experimental

@nicolasstucki
Copy link
Contributor

As a workaround, we could remove @deprecatedInheritance from class experimental and handle deprecatedInheritance intrinsically in the compiler.

@nicolasstucki
Copy link
Contributor

Long-term solution: define these operations directly in Predef (see #19231)

@nicolasstucki nicolasstucki removed their assignment Apr 18, 2024
@hamzaremmal
Copy link
Member

Simplest fix is to make @experimental final and remove the @deprecatedInheritance annotation from it. We are currently working on 3.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants