Skip to content
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

Regression in 3.3.1: Compiler crash "assertion failed: NoType" #18934

Open
mberndt123 opened this issue Nov 15, 2023 · 7 comments
Open

Regression in 3.3.1: Compiler crash "assertion failed: NoType" #18934

mberndt123 opened this issue Nov 15, 2023 · 7 comments
Labels
area:implicits related to implicits area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug itype:crash

Comments

@mberndt123
Copy link

mberndt123 commented Nov 15, 2023

Hi,

The project in the attachment makes the Scala 3.3.1 compiler crash on my machine. The complete code is:

import zio.ZLayer
import zio.{ZIO, Runtime, Task}
import cats.effect.Async
import zio.interop.catz.*

def foo = 
  ZIO.runtime[Any].flatMap: runtime =>
    given Runtime[Any] = runtime
    Async[Task]
    (??? : Task[Unit])

And the important bit of the error message seems to be this:

java.lang.AssertionError: assertion failed: NoType while typechecking /home/matthias/minimized/backend/src/main/scala/Main.scala

I have attached the complete output of sbt compile as a log file.

The crash goes away when I do either of the following:

  • remove the dependency on "dev.zio" %% "zio-http" % "3.0.0-RC2" from build.sbt
  • set scalaVersion to 3.3.0 in build.sbt

It then prints the following error:

[info] welcome to sbt 1.9.7 (Private Build Java 17.0.8.1)
[info] loading project definition from /home/matthias/minimized/project
[info] loading settings for project minimized from build.sbt ...
[info] set current project to minimized (in build file:/home/matthias/minimized/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] compiling 1 Scala source to /home/matthias/minimized/backend/target/scala-3.3.1/classes ...
[error] -- [E172] Type Error: /home/matthias/minimized/backend/src/main/scala/Main.scala:9:15 
[error] 9 |    Async[Task]
[error]   |               ^
[error]   |Could not find an instance of Monad for zio.Task.
[error]   |I found:
[error]   |
[error]   |    zio.interop.catz.asyncRuntimeInstance[E](
[error]   |      /* missing */summon[zio.Runtime[zio.clock.Clock & zio.interop.CBlocking]])
[error]   |
[error]   |But no implicit values were found that match type zio.Runtime[zio.clock.Clock & zio.interop.CBlocking].
[error] one error found
[error] (backend / Compile / compileIncremental) Compilation failed
[error] Total time: 6 s, completed 15.11.2023, 14:31:41

minimized.tar.gz
sbt-compile.log

@mberndt123 mberndt123 added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 15, 2023
@mberndt123 mberndt123 changed the title Compiler crash "assertion failed: NoType" Regression in 3.3.1: Compiler crash "assertion failed: NoType" Nov 15, 2023
@WojciechMazur
Copy link
Contributor

Thank you for the minimisation, I was able to reproduce it on my machine.
As a side note zio-interop-cats:3.1.1.0 is almost 2 years old, while using the latest version of this project 23.1.0.0 the snippet would correctly compile. There probably needs to be some issue related to binary incompatibility of the two libraries.

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Nov 15, 2023

I think it is not specified how the compiler should behave in case of binary incompatibility of 2 libraries.
In our case the ZIO project seems to not set any versioning scheme which might be helpfull when using binary incompatible versions of dependencies. In our case the zio-interop-cats uses ZIO 1.0.8 which is beining evicted by 2.0.x introduced via dependency of zio-http. This can be workarounded by upgrading zio-interop-cats as described in previous comment.

Even if we'd adjust the code to compile (see snippet below) and we would be able to pass it through all transform phases it still would fail in the backend:

//> using dep dev.zio::zio-interop-cats:3.1.1.0
//> using dep dev.zio::zio-http:3.0.0-RC3

import zio.{Runtime,Task}
import cats.effect.Async
import zio.interop.catz.*

given [T]: zio.Runtime[T] = ???

def foo = cats.effect.Async.apply[Task]

results in

exception occurred while compiling /Users/wmazur/projects/sandbox/main.scala
Error: cannot resolve reference to type zio.type.ZManaged
the classfile defining the type might be missing from the classpath
Error compiling project (Scala 3.3.0, JVM)

However, in each case we should try to provide a meaningfull error message.

@WojciechMazur WojciechMazur added area:typer area:implicits related to implicits and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 15, 2023
@WojciechMazur
Copy link
Contributor

Bisect points that the compiler started crashing after extending the implicit search mechanism in ea13cad Probably the noChainConversionsNote should be guarded in some way to prevent crashing the compiler.

Last good release: 3.3.1-RC1-bin-20230131-42f2764-NIGHTLY
First bad release: 3.3.1-RC1-bin-20230201-e751f51-NIGHTLY

@WojciechMazur WojciechMazur added area:reporting Error reporting including formatting, implicit suggestions, etc and removed area:typer labels Nov 15, 2023
@mberndt123
Copy link
Author

Yeah, I just copy-pasted the sbt line from the ZIO documentation. Thanks for the hint that updating that stops the compiler from crashing.

@WojciechMazur
Copy link
Contributor

The implicit search seems to fails because the Async[Task] requires an instance of object introduced via conversion.
It's defined as follows
In ZIO 2.x: implicit final def asyncRuntimeInstance[E](implicit runtime: Runtime[Any]): Async[Task]
In ZIO 1.x: implicit final def asyncRuntimeInstance[E](implicit runtime: Runtime[Clock & CBlocking]): Async[Task]
where the Clock in ZIO 1.x is defined as

package object clock:
  type Clock = Hash[Clock.Service]
  object Clock:
      trait Service

but in ZIO 2.x it's a regular trait trait Clock defined in the top level.
During typer/implicit search it seems that we're using the asyncRuntimeInstance defined in ZIO 1.x, but the package object clock.Clock cannot be found.

Because in any case the compilation should fail either with error or crash I have no idea how to reproduce it for the Vulpix regression tests.

@dwijnand
Copy link
Member

Bisect points that the compiler started crashing after extending the implicit search mechanism in ea13cad Probably the noChainConversionsNote should be guarded in some way to prevent crashing the compiler.

I addressed how that change addressed a related crash with the fix (and follow up to the fix) #18719 and #18727. But I'm not sure how exactly that affects the issue here.

@WojciechMazur
Copy link
Contributor

It seems that it is still failing in nightly - 3.4.0-RC1-bin-20231117-5bb6f0d-NIGHTLY I'm adding stacktrace of the crash below

 scala-cli compile main.scala -S 3.nightly --server=false
dotty.tools.FatalError: cannot resolve reference to type zio.type.ZManaged
the classfile defining the type might be missing from the classpath
        at dotty.tools.FatalError$.apply(FatalError.scala:3)
        at dotty.tools.dotc.core.TypeErasure.checkedSuperType(TypeErasure.scala:761)
        at dotty.tools.dotc.core.TypeErasure.dotty$tools$dotc$core$TypeErasure$$apply(TypeErasure.scala:644)
        at dotty.tools.dotc.core.TypeErasure.paramErasure$1(TypeErasure.scala:692)
        at dotty.tools.dotc.core.TypeErasure.$anonfun$1(TypeErasure.scala:700)
        at scala.collection.immutable.List.mapConserve(List.scala:472)
        at dotty.tools.dotc.core.TypeErasure.dotty$tools$dotc$core$TypeErasure$$apply(TypeErasure.scala:700)
        at dotty.tools.dotc.core.TypeErasure.eraseResult(TypeErasure.scala:880)
        at dotty.tools.dotc.core.TypeErasure.eraseInfo(TypeErasure.scala:816)
        at dotty.tools.dotc.core.TypeErasure$.transformInfo(TypeErasure.scala:274)
        at dotty.tools.dotc.transform.Erasure.transform(Erasure.scala:97)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:832)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:124)
        at dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:118)
        at dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:111)
        at dotty.tools.dotc.core.Symbols$.toDenot(Symbols.scala:498)
        at dotty.tools.dotc.transform.Mixin.needsTraitSetter(Mixin.scala:174)
        at dotty.tools.dotc.transform.Mixin.transformSym$$anonfun$1(Mixin.scala:153)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:333)
        at dotty.tools.dotc.core.Scopes$Scope.foreach(Scopes.scala:94)
        at dotty.tools.dotc.transform.Mixin.transformSym(Mixin.scala:157)
        at dotty.tools.dotc.core.DenotTransformers$SymTransformer.transform(DenotTransformers.scala:70)
        at dotty.tools.dotc.core.DenotTransformers$SymTransformer.transform$(DenotTransformers.scala:65)
        at dotty.tools.dotc.transform.Mixin.transform(Mixin.scala:113)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:832)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:849)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:878)
        at dotty.tools.dotc.core.Symbols$Symbol.recomputeDenot(Symbols.scala:124)
        at dotty.tools.dotc.core.Symbols$Symbol.computeDenot(Symbols.scala:118)
        at dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:111)
        at dotty.tools.dotc.core.Symbols$ClassSymbol.classDenot(Symbols.scala:485)
        at dotty.tools.dotc.core.Symbols$.toClassDenot(Symbols.scala:501)
        at dotty.tools.backend.jvm.BTypesFromSymbols.$anonfun$1(BTypesFromSymbols.scala:115)
        at scala.collection.Iterator$$anon$10.nextCur(Iterator.scala:594)
        at scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:608)
        at scala.collection.mutable.Growable.addAll(Growable.scala:61)
        at scala.collection.mutable.Growable.addAll$(Growable.scala:57)
        at scala.collection.immutable.SetBuilderImpl.addAll(Set.scala:405)
        at scala.collection.immutable.Set$.from(Set.scala:362)
        at scala.collection.IterableOnceOps.toSet(IterableOnce.scala:1322)
        at scala.collection.IterableOnceOps.toSet$(IterableOnce.scala:1322)
        at scala.collection.AbstractIterator.toSet(Iterator.scala:1300)
        at dotty.tools.backend.jvm.BTypesFromSymbols.superInterfaces$1(BTypesFromSymbols.scala:115)
        at dotty.tools.backend.jvm.BTypesFromSymbols.setClassInfo(BTypesFromSymbols.scala:123)
        at dotty.tools.backend.jvm.BTypesFromSymbols.classBTypeFromSymbol$$anonfun$1(BTypesFromSymbols.scala:65)
        at scala.collection.mutable.HashMap.getOrElse(HashMap.scala:451)
        at dotty.tools.backend.jvm.BTypesFromSymbols.classBTypeFromSymbol(BTypesFromSymbols.scala:66)
        at dotty.tools.backend.jvm.BTypesFromSymbols.setClassInfo(BTypesFromSymbols.scala:106)
        at dotty.tools.backend.jvm.BTypesFromSymbols.classBTypeFromSymbol$$anonfun$1(BTypesFromSymbols.scala:65)
        at scala.collection.mutable.HashMap.getOrElse(HashMap.scala:451)
        at dotty.tools.backend.jvm.BTypesFromSymbols.classBTypeFromSymbol(BTypesFromSymbols.scala:66)
        at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBType(BCodeHelpers.scala:178)
        at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBType$(BCodeHelpers.scala:130)
        at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.getClassBType(BCodeSkelBuilder.scala:134)
        at dotty.tools.backend.jvm.BCodeHelpers.primitiveOrClassToBType$1$$anonfun$1(BCodeHelpers.scala:715)
        at scala.collection.immutable.HashMap.getOrElse(HashMap.scala:722)
        at dotty.tools.backend.jvm.BCodeHelpers.primitiveOrClassToBType$1(BCodeHelpers.scala:715)
        at dotty.tools.backend.jvm.BCodeHelpers.dotty$tools$backend$jvm$BCodeHelpers$$typeToTypeKind(BCodeHelpers.scala:734)
        at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.toTypeKind(BCodeHelpers.scala:202)
        at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.toTypeKind$(BCodeHelpers.scala:130)
        at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.toTypeKind(BCodeSkelBuilder.scala:134)
        at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.tpeTK(BCodeSkelBuilder.scala:166)
        at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:298)
        at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadQualifier(BCodeBodyBuilder.scala:1193)
        at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genApply(BCodeBodyBuilder.scala:836)
        at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadTo(BCodeBodyBuilder.scala:387)
        at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoad(BCodeBodyBuilder.scala:305)
        at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.loop$1(BCodeBodyBuilder.scala:1211)
        at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadArguments(BCodeBodyBuilder.scala:1218)
        at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genApply(BCodeBodyBuilder.scala:837)
        at dotty.tools.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.genLoadTo(BCodeBodyBuilder.scala:387)
        at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.emitNormalMethodBody$1(BCodeSkelBuilder.scala:893)
        at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genDefDef(BCodeSkelBuilder.scala:916)
        at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:693)
        at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen$$anonfun$1(BCodeSkelBuilder.scala:699)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:333)
        at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.gen(BCodeSkelBuilder.scala:699)
        at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.genPlainClass(BCodeSkelBuilder.scala:293)
        at dotty.tools.backend.jvm.CodeGen.genClass(CodeGen.scala:155)
        at dotty.tools.backend.jvm.CodeGen.genClassDef$1(CodeGen.scala:63)
        at dotty.tools.backend.jvm.CodeGen.genClassDefs$1(CodeGen.scala:118)
        at dotty.tools.backend.jvm.CodeGen.genClassDefs$1$$anonfun$1(CodeGen.scala:116)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:333)
        at dotty.tools.backend.jvm.CodeGen.genClassDefs$1(CodeGen.scala:116)
        at dotty.tools.backend.jvm.CodeGen.genUnit(CodeGen.scala:121)
        at dotty.tools.backend.jvm.GenBCode.run(GenBCode.scala:83)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:345)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:333)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:351)
        at dotty.tools.backend.jvm.GenBCode.runOn(GenBCode.scala:91)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:315)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:337)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:348)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:357)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:71)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:357)
        at dotty.tools.dotc.Run.compileSources(Run.scala:261)
        at dotty.tools.dotc.Run.compile(Run.scala:246)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
        at dotty.tools.dotc.Driver.process(Driver.scala:197)
        at dotty.tools.dotc.Driver.process(Driver.scala:165)
        at dotty.tools.dotc.Driver.process(Driver.scala:177)
        at dotty.tools.dotc.Driver.main(Driver.scala:207)
        at dotty.tools.dotc.Main.main(Main.scala)
Error while emitting /Users/wmazur/projects/sandbox/main.scala
cannot resolve reference to type zio.type.ZManaged
the classfile defining the type might be missing from the classpath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug itype:crash
Projects
None yet
Development

No branches or pull requests

3 participants