effekt-lang / effekt-lang/effekt

llvm: segmentation fault caused by time-travelling region variable

Open
#1,281 1 comment 0 reactions 0 assignees View on GitHub
area:llvm bug
Dominant language
Scala
Stars
469
Forks
41
Avg merge
1d 16h
Merged PRs (30d)
23

Description

Sending a region variable (i.e. a `var foo in reg`) back in time (before it was defined) is inconsistent in js vs llvm. I'm not sure if this should even be allowed, but the llvm implementation is definitely broken
(run with --no-optimize because bugs):
```effekt
import option
interface Field[T] {
def getValue(): T
def setValue(t: T): Unit
}

def field[T](init: T){reg: Region}: Field[T] at reg = {
var value in reg = init
box new Field[T] {
def getValue() = value
def setValue(t) = { value = t }
}
}

interface TimeTravel {
def runInParallelWorld[T]{self: TimeTravel}{block: => T}: T
def throw(c: => Unit at {io}): Nothing
}

def timeTravel(block: {TimeTravel} => Unit at {io}) = try block{tt} with tt: TimeTravel {
def runInParallelWorld[T] = resume { {self}{block2} =>
val t = block2()
self.throw(box { resume { {_}{_} => t } })
}
def throw(c) = c()
}

def main() = timeTravel(box { {tt} =>
region reg {
val f: Field[Int] at reg = tt.runInParallelWorld{tt} { field(42){reg} }
println(f.getValue()) // js: 42, llvm: 0
f.setValue(43)
println(f.getValue()) // js: 43, llvm: 43
}
})
```
This is with integers, and already the behaviour is different. The real trouble happens when using objects:
```effekt
def main() = timeTravel(box { {tt} =>
region reg {
val f: Field[Option[String]] at reg = tt.runInParallelWorld{tt} { field(Some("hello")){reg} }
println(f.getValue().show { s => s.show() }) // js: Some(hello), llvm: segmentation fault!
}
})
```
`region` inherently allows for this "sending a variable back in time" business, although I don't think I've seen any formal semantics that accounts for this. I'm surprised that the JS implementation handles this weirdness so well! Still, I have a hunch that maybe, just maybe, even the JS implementation might have weird behaviours in complex enough programs

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.