koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.26k stars 162 forks source link

Error in Backend.C.ParcReuse.orderConFields with var and default parameter #273

Closed olsaarik closed 9 months ago

olsaarik commented 2 years ago

Hi! The following program produces an internal compiler error:

effect eff
  ctl a() : bool

fun g(s : sslice, limit : int = s.count) : eff ()
  ()

fun h() : eff ()
  val s = "a".slice
  var s' := "b".slice
  g(s', s'.count - s.count)

fun main()
  ()

Here's what koka prints:

compile: minimal.kk
loading: std/core
loading: std/core/types
loading: std/core/hnd
check  : minimal
failure during code generation:
  *** internal compiler error: Backend.C.ParcReuse.orderConFields: multiple fields with mixed raw/scan fields itself in [(s0,TCon (TypeCon {typeconName = std/core/sslice, typeconKind = KCon V})),(s1.234,TCon (TypeCon {typeconName = std/core/sslice, typeconKind = KCon V}))]

I minimized the program as much as I easily could. Modifications that avoid the error include:

The koka version is 2.4.0.

daanx commented 2 years ago

Ha, welcome Olli :-) Apologies for the late reply but it's a busy week. The error you see is actually a limitation of the runtime system. At the moment, the sslice slices contain references to the string but also a raw ssize_t and cannot be mixed themselves in another datatype as values as that would make scanning reference fields more complex in the runtime. I was actually aware of this and have a fix for it (by just making the ssize_t an int -- I'll try to push it out soon! Thanks!

olsaarik commented 2 years ago

Cool! And this by the way wasn't blocking at all. I managed to reorganize my code a bit to avoid this.

TimWhiting commented 9 months ago

This is fixed in the latest release, thanks for the feedback!