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

Compiler crash with opaque types, inline, varargs, unsigned #3700

Closed
keynmol opened this issue Jan 21, 2024 · 2 comments · Fixed by #3712
Closed

Compiler crash with opaque types, inline, varargs, unsigned #3700

keynmol opened this issue Jan 21, 2024 · 2 comments · Fixed by #3712

Comments

@keynmol
Copy link
Contributor

keynmol commented Jan 21, 2024

Error (you can see full stack trace in this run of Github actions: https://github.com/indoorvivants/sn-bindgen-examples/actions/runs/7588621095/job/20671553894?pr=116#step:9:122):

Exception in thread "main" java.lang.ClassCastException: class dotty.tools.dotc.core.Symbols$Symbol cannot be cast to class dotty.tools.dotc.core.Symbols$ClassSymbol (dotty.tools.dotc.core.Symbols$Symbol and dotty.tools.dotc.core.Symbols$ClassSymbol are in unnamed module of loader 'app')
        at dotty.tools.dotc.core.Symbols$Symbol.asClass(Symbols.scala:178)
        at scala.scalanative.nscplugin.NirGenType.isPrimitiveValueType(NirGenType.scala:85)
        at scala.scalanative.nscplugin.NirGenType.isPrimitiveValueType$(NirGenType.scala:20)
        at scala.scalanative.nscplugin.NirCodeGen.isPrimitiveValueType(NirCodeGen.scala:18)
        at scala.scalanative.nscplugin.NirGenExpr$ExprBuffer.ensureUnboxed(NirGenExpr.scala:1883)
        at scala.scalanative.nscplugin.NirGenExpr$ExprBuffer.genArg$1(NirGenExpr.scala:1503)
        at scala.scalanative.nscplugin.NirGenExpr$ExprBuffer.genExternMethodArgs$$anonfun$2$$anonfun$1(NirGenExpr.scala:1534)
        at scala.collection.immutable.List.foreach(List.scala:333)
        at scala.scalanative.nscplugin.NirGenExpr$ExprBuffer.genExternMethodArgs$$anonfun$2(NirGenExpr.scala:1547)
        at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:575)
        at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:573)
        at scala.collection.AbstractIterable.foreach(Iterable.scala:933)

I believe this is a minimisation with scala-cli (scala-cli compile test.scala --server=false):

//> using platform native
//> using nativeVersion 0.4.17
//> using scala 3.3.1

import scalanative.libc.stdio
import scalanative.unsafe.*
import scalanative.unsigned.*

opaque type cmark_event_type = CUnsignedInt
object cmark_event_type:
  inline def define(inline a: Long): cmark_event_type = a.toUInt
  val CMARK_EVENT_NONE = define(0)

@main def hello = 
  val evtype = cmark_event_type.CMARK_EVENT_NONE

  stdio.printf(c"bla: %s, hello: %d", evtype)

For some reason def define is necessary for the crash to occur

@mpilquist
Copy link

Looks like we'll need this in a 0.4 release to unblock the upgrade to Scala 3.4.0 for scodec: https://github.com/scodec/scodec/actions/runs/8123425652/job/22203814072#step:8:24

@WojciechMazur
Copy link
Contributor

@mpilquist Thank you for bringing this topic up. In general we'd like to backport some of the changes from 0.5.x to 0.4x line for some time (at most 2-3 releases) after 0.5.0 final. However, at this point there is a lot of changes between these 2 branches, making backports difficult sometimes. Even though the fix itself is simple, it might depend on other changes, that might have not been backported. I'll try to check again what we can do about it, hopefully we should be able to publish 0.4.18 along with other bugfixes soon

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