Skip to content

Commit

Permalink
Revise ignored LLVM tests (#776)
Browse files Browse the repository at this point in the history
Eventually closes #740
  • Loading branch information
marvinborner authored Jan 27, 2025
1 parent acb9c98 commit f92d229
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 93 deletions.
27 changes: 0 additions & 27 deletions effekt/jvm/src/test/scala/effekt/LLVMTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class LLVMTests extends EffektTests {
)

lazy val bugs: List[File] = List(
// names not sanitized (even?)
examplesDir / "pos" / "special_names.effekt",
// Jump to the invalid address stated on the next line
examplesDir / "benchmarks" / "input_output" / "dyck_one.effekt",
examplesDir / "benchmarks" / "input_output" / "number_matrix.effekt",
Expand All @@ -33,36 +31,14 @@ class LLVMTests extends EffektTests {
* Documentation of currently failing tests and their reason
*/
lazy val missingFeatures: List[File] = List(

// now show instance for records / datatypes
examplesDir / "pos" / "builtins.effekt",
examplesDir / "pos" / "namespaces.effekt",
examplesDir / "pos" / "triples.effekt",
examplesDir / "pos" / "either.effekt",

// inspect
examplesDir / "pos" / "probabilistic.effekt",
examplesDir / "pos" / "nim.effekt",
examplesDir / "pos" / "exists.effekt",

// arrays
examplesDir / "pos" / "arrays.effekt",
examplesDir / "pos" / "raytracer.effekt",
examplesDir / "pos" / "issue319.effekt",
examplesDir / "pos" / "array",

// Regex
examplesDir / "pos" / "simpleparser.effekt",

// tuples
examplesDir / "pos" / "records.effekt",

// toplevel def and let bindings
examplesDir / "pos" / "capture" / "mbed.effekt",

// unsafe cont
examplesDir / "pos" / "propagators.effekt",
examplesDir / "pos" / "unsafe_cont.effekt",

// Only JS (tests should be moved to a JS folder)
examplesDir / "pos" / "genericcompare.effekt",
Expand All @@ -71,9 +47,6 @@ class LLVMTests extends EffektTests {
examplesDir / "pos" / "capture" / "resources.effekt",
examplesDir / "pos" / "io",

// first class functions closing over capabilities
examplesDir / "pos" / "capture" / "state_eff.effekt",

// higher order foreign functions are not supported
examplesDir / "pos" / "capture" / "ffi_blocks.effekt",

Expand Down
1 change: 1 addition & 0 deletions effekt/jvm/src/test/scala/effekt/ReplTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class ReplTests extends munit.FunSuite {
|Imported Functions
|==================
|def main(): Unit / {}
|def show(c: Color): String / {}
|""".stripMargin

assertNoDiff(runRepl("import examples/pos/builtins"), expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ ${indentedLines(instructions.map(show).mkString("\n"))}
case Parameter(tpe, name) => s"${show(tpe)} ${localName(name)}"
}

def localName(name: String): LLVMString = "%" + name
def globalName(name: String): LLVMString = "@" + name
def sanitize(name: String): String = name.replace("?", "Q").replace("!", "B")

def localName(name: String): LLVMString = "%" + sanitize(name)
def globalName(name: String): LLVMString = "@" + sanitize(name)

// indent all lines with four spaces
def indentedLines(text: String): String = text.split("\n").map(" " + _).mkString("\n")
Expand Down
20 changes: 11 additions & 9 deletions examples/pos/array/list_conversion.effekt
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
module examples/pos/list/collect

def listToArrayAndBack[A](list: List[A]): Unit = {
list.foreach { x => inspect(x) }
import array

def listToArrayAndBack(list: List[Int]): Unit = {
list.foreach { x => println(x) }
println("")

val arr = fromList(list)
val arr = array::fromList(list)
println("size " ++ show(arr.size))
arr.foreachIndex { (i, x) =>
println(i)
inspect(x)
println(x)
}
println("")

val reconstructedList = arr.toList()
reconstructedList.foreach { x => inspect(x) }
reconstructedList.foreach { x => println(x) }
println("")
}

def arrayToListAndBack[A](arr: Array[A]): Unit = {
def arrayToListAndBack(arr: Array[Int]): Unit = {
println("size " ++ show(arr.size))
arr.foreachIndex { (i, x) =>
println(i)
inspect(x)
println(x)
}
println("")

val list = arr.toList
list.foreach { x => inspect(x) }
list.foreach { x => println(x) }
println("")

val reconstructedArray = fromList(list)
println("size " ++ show(reconstructedArray.size))
reconstructedArray.foreachIndex { (i, x) =>
println(i)
inspect(x)
println(x)
}
println("")
}
Expand Down
2 changes: 2 additions & 0 deletions examples/pos/array/sum.effekt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module examples/pos/array/sum

import array

def main() = {
val emptyArray: Array[Int] = array::allocate(0)
println(emptyArray.sum())
Expand Down
2 changes: 2 additions & 0 deletions examples/pos/arrays.effekt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module examples/pos/arrays

import array

def main() = {
val arr = array::allocate[String](5);

Expand Down
8 changes: 7 additions & 1 deletion examples/pos/builtins.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ module examples/pos/builtins

type Color { Red(); Green(); Blue() }

def show(c: Color): String = c match {
case Red() => "Red()"
case Green() => "Green()"
case Blue() => "Blue()"
}

def main() = {
println(1);
println("foo");
println(true);
println(1 == 2);
inspect(Red())
println(show(Red()))
}
9 changes: 7 additions & 2 deletions examples/pos/either.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ type Either[A, B] {
Right(value: B)
}

def show(either: Either[Int, String]): String = either match {
case Left(value) => "Left(" ++ show(value) ++ ")"
case Right(value) => "Right(" ++ value ++ ")"
}

def main() = {
val l: Either[Int, String] = Left(42);
val l2 = Left[Int, String](42);
inspect(l);
inspect(l2)
println(show(l));
println(show(l2))
}
16 changes: 8 additions & 8 deletions examples/pos/exists.effekt
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
type Exists {
Op[Z](el: Z, combine: (Z, Z) => Z at {})
Op[Z](el: Z, combine: (Z, Z) => Z at {}, show: Z => String at {})
}


def test1() = {
val intBox = Op(1, box { (x, y) => x + y });
val stringBox = Op("hello!", box { (x, y) => x ++ y });
val intBox = Op(1, box { (x, y) => x + y }, box { e => show(e) });
val stringBox = Op("hello!", box { (x, y) => x ++ y }, box { e => e});

def combineAndPrint(op: Exists): Unit = op match {
case Op(el, combine) => inspect(combine(el, el))
case Op(el, combine, show) => println(show(combine(el, el)))
}

combineAndPrint(intBox)
combineAndPrint(stringBox)
}

def test2() = {
val intBox = Op(1, box { (x, y) => x + y });
val stringBox = Op("hello!", box { (x, y) => x ++ y });
val intBox = Op(1, box { (x, y) => x + y }, box { e => show(e) });
val stringBox = Op("hello!", box { (x, y) => x ++ y }, box { e => e });

def repack(op: Exists): Exists = op match {
case Op(el, combine) => Op(el, combine)
case Op(el, combine, show) => Op(el, combine, show)
}

def combineAndPrint(op: Exists): Unit = op match {
case Op(el, combine) => inspect(combine(el, el))
case Op(el, combine, show) => println(show(combine(el, el)))
}

combineAndPrint(repack(intBox))
Expand Down
6 changes: 4 additions & 2 deletions examples/pos/issue319.effekt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import array

def main() = {
val array = fromList([1,2,3]);
inspect(array.toList)
val array = array::fromList([1,2,3]);
println(array.toList)
}
6 changes: 5 additions & 1 deletion examples/pos/namespaces.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module namespaces

type Person { Person(name: String, id: Int) }

def show(p: Person): String = p match {
case Person(name, id) => "Person(" ++ name ++ ", " ++ show(id) ++ ")"
}

def somePerson(): Person =
Person("Jonathan", 1334579)

def main() = inspect(somePerson())
def main() = println(show(somePerson()))
48 changes: 30 additions & 18 deletions examples/pos/nim.effekt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module examples/pos/nim

import list

// Example from "Liberating effects with rows and handlers"
// Translated from Koka https://github.com/koka-lang/koka/blob/master/test/algeff/nim.kk

Expand All @@ -8,6 +10,11 @@ type Player {
Alice()
}

def show(p: Player): String = p match {
case Bob() => "Bob()"
case Alice() => "Alice()"
}

effect Move(p: Player, sticks: Int): Int

def aliceTurn(n: Int): Player / Move =
Expand Down Expand Up @@ -46,6 +53,16 @@ type GTree {
Winner(p: Player)
}

def show(moves: Moves[GTree]): String = moves match {
case Done() => "Done()"
case Step(n, g, rest) => "Step(" ++ show(n) ++ ", " ++ show(g) ++ ", " ++ show(rest) ++ ")"
}

def show(tree: GTree): String = tree match {
case Take(p, moves) => "Take(" ++ show(p) ++ ", " ++ show(moves) ++ ")"
case Winner(p) => "Winner(" ++ show(p) ++ ")"
}

def range(from: Int, to: Int) { block: Int => Unit } = {
var i = from;
while (i <= to) {
Expand Down Expand Up @@ -74,7 +91,7 @@ def printError { prog: => Unit / error } = try { prog() } with error { (msg) =>

def cheatReport[R] { prog: => R / cheat }: R / error =
try { prog() } with cheat { (p) =>
do error(genericShow(p) ++ " cheated!")
do error(show(p) ++ " cheated!")
}

def check { prog: => Player / Move } = try { prog() } with Move { (p, n) =>
Expand All @@ -91,15 +108,6 @@ def pc { prog: => Player / Move } = try { prog() } with Move { (p, n) =>

effect Choose(): Bool

type List[A] {
Nil();
Cons(head: A, tail: List[A])
}
def concat[A](l1: List[A], l2: List[A]): List[A] = l1 match {
case Nil() => l2
case Cons(a, rest) => concat(rest, Cons(a, l2))
}

def bobChooses { prog: => Player / Move } =
if (do Choose()) {
pc { prog() }
Expand All @@ -108,7 +116,7 @@ def bobChooses { prog: => Player / Move } =
}

def allResults[R] { prog: => R / Choose } = try { [prog()] } with Choose { () =>
concat(resume(true), resume(false))
append(resume(true), resume(false))
}

def coin[R] { prog: => R / Choose } = try { prog() } with Choose { () =>
Expand All @@ -133,6 +141,10 @@ type Scoreboard {
Board(alice: Int, bob: Int)
}

def show(board: Scoreboard): String = board match {
case Board(alice, bob) => "Board(" ++ show(alice) ++ ", " ++ show(bob) ++ ")"
}

effect GetScore(): Scoreboard
effect UpdateScore(p: Player): Unit

Expand Down Expand Up @@ -163,26 +175,26 @@ def testPrint2() = {
bobChooses { val p = game(7); do UpdateScore(p); p }; ()
}
};
inspect(do GetScore())
println(show(do GetScore()))
}
}

def main() = {
inspect(perfect { game(7) }); // Alice
inspect(perfect { game(12) }); // Bob
inspect(gametree { game(3) }); // Figure 1 in the paper
println(perfect { show(game(7)) }); // Alice
println(perfect { show(game(12)) }); // Bob
println(show(gametree { game(3) })); // Figure 1 in the paper
printError {
val result = perfect { cheatReport { check { game(7) } } }; // alice
println("result is " ++ genericShow(result))
println("result is " ++ show(result))
};
printError {
pc { cheatReport { check { game(12) } } }; () // bob cheats
};
printError { perfect {
val result = cheatReport { check { pc { game(12) } } }; // bob
println("result is " ++ genericShow(result))
println("result is " ++ show(result))
}};
inspect(allResults { bobChooses { game(7) } }); // List(Bob, Alice)
println(show(allResults { bobChooses { game(7) } }) { e => show(e) }); // List(Bob, Alice)
deterministic {
println(do Choose()); // true
println(do Choose()); // false
Expand Down
2 changes: 1 addition & 1 deletion examples/pos/probabilistic.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cons(MkWeighted(0.2, false), Cons(MkWeighted(0.48, true), Cons(MkWeighted(0.32000000000000006, false), Nil())))
Cons(MkWeighted(0.2, false), Cons(MkWeighted(0.48, true), Cons(MkWeighted(0.32, false), Nil())))
Unobserved()Unobserved()Unobserved()
Unobserved()Observed(true)Unobserved()
Unobserved()Observed(true)Observed(false)
Expand Down
Loading

0 comments on commit f92d229

Please sign in to comment.