From 8b062af602a12e3efb745c3b7b6a2cce7f728246 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Wed, 22 Jan 2025 13:18:46 +0100 Subject: [PATCH 1/4] Reintroduce failing tests --- effekt/jvm/src/test/scala/effekt/LLVMTests.scala | 5 ----- effekt/jvm/src/test/scala/effekt/StdlibTests.scala | 7 ------- 2 files changed, 12 deletions(-) diff --git a/effekt/jvm/src/test/scala/effekt/LLVMTests.scala b/effekt/jvm/src/test/scala/effekt/LLVMTests.scala index 356ea86cb..5aadb57a2 100644 --- a/effekt/jvm/src/test/scala/effekt/LLVMTests.scala +++ b/effekt/jvm/src/test/scala/effekt/LLVMTests.scala @@ -22,11 +22,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", - examplesDir / "benchmarks" / "input_output" / "word_count_ascii.effekt", - examplesDir / "benchmarks" / "input_output" / "word_count_utf8.effekt", ) /** diff --git a/effekt/jvm/src/test/scala/effekt/StdlibTests.scala b/effekt/jvm/src/test/scala/effekt/StdlibTests.scala index 44fbe0be8..a9635a1e9 100644 --- a/effekt/jvm/src/test/scala/effekt/StdlibTests.scala +++ b/effekt/jvm/src/test/scala/effekt/StdlibTests.scala @@ -40,13 +40,6 @@ class StdlibLLVMTests extends StdlibTests { override def debug = sys.env.get("EFFEKT_DEBUG").nonEmpty override def ignored: List[File] = List( - // Syscall param write(buf) points to uninitialised byte(s) - examplesDir / "stdlib" / "io" / "filesystem" / "files.effekt", - examplesDir / "stdlib" / "io" / "filesystem" / "async_file_io.effekt", - - // Conditional jump or move depends on uninitialised value(s) - examplesDir / "stdlib" / "io" / "filesystem" / "wordcount.effekt", - // String comparison using `<`, `<=`, `>`, `>=` is not implemented yet on LLVM examplesDir / "stdlib" / "string" / "compare.effekt", ) From e499beeca6ecb2dd7b9c241bf013e16310f55902 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Wed, 22 Jan 2025 17:13:57 +0100 Subject: [PATCH 2/4] Avoid the use of macro as parameter name --- libraries/llvm/io.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/llvm/io.c b/libraries/llvm/io.c index bdc3cfbbb..024c485b7 100644 --- a/libraries/llvm/io.c +++ b/libraries/llvm/io.c @@ -177,11 +177,11 @@ void c_fs_close(Int file, Stack stack) { /** * Maps the libuv error code to a stable (platform independent) numeric value. * - * Tries to use most common errno integer values, but introduces fresh values (> 200) - * for those without common errno values. + * Tries to use most common error number integer values, but introduces fresh values (> 200) + * for those without common error number values. */ -Int c_error_number(Int errno) { - switch (errno) { +Int c_error_number(Int error) { + switch (error) { case UV_EPERM: return 1; // EPERM case UV_ENOENT: return 2; // ENOENT case UV_ESRCH: return 3; // ESRCH From 3b0916204d1e2d90267862073df1d32f6e880a0c Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Wed, 22 Jan 2025 18:25:01 +0100 Subject: [PATCH 3/4] Use different filenames for different backends --- examples/benchmarks/input_output/dyck_one.effekt | 10 ++++++---- .../benchmarks/input_output/word_count_ascii.effekt | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/benchmarks/input_output/dyck_one.effekt b/examples/benchmarks/input_output/dyck_one.effekt index d34664af8..fb233977e 100644 --- a/examples/benchmarks/input_output/dyck_one.effekt +++ b/examples/benchmarks/input_output/dyck_one.effekt @@ -37,17 +37,19 @@ def size(tree: Tree): Int = } } +extern def filename(): String = + js { "/tmp/dyck_one_js.txt" } + llvm { "/tmp/dyck_one_llvm.txt" } + def run(n: Int): Int = { with on[IOError].panic - val filename = "/tmp/dyck_one.txt" - val _ = { - with writeFile(filename) + with writeFile(filename()) emitTree(n) } - with readFile(filename) + with readFile(filename()) with returning::scanner[Byte, Int] attempt { readTree().size } { panic("Expected tree.")} } diff --git a/examples/benchmarks/input_output/word_count_ascii.effekt b/examples/benchmarks/input_output/word_count_ascii.effekt index cfc3df1b9..533ed127a 100644 --- a/examples/benchmarks/input_output/word_count_ascii.effekt +++ b/examples/benchmarks/input_output/word_count_ascii.effekt @@ -59,13 +59,15 @@ def countWords(): Output / read[Byte] = { Output(chars, words, lines) } +extern def filename(): String = + js { "/tmp/word_count_ascii_js.txt" } + llvm { "/tmp/word_count_ascii_llvm.txt" } + def run(n: Int) = { with on[IOError].panic; - val filename = "/tmp/word_count_ascii.txt" - val _ = { - with writeFile(filename) + with writeFile(filename()) with repeat(n) for[Int] { range(32, 127) } { c => repeat(10) { @@ -76,7 +78,7 @@ def run(n: Int) = { } val output = { - with readFile(filename) + with readFile(filename()) countWords() } From 0a13886cac26d9f4b762a59ffe222ba4b2f66067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattis=20B=C3=B6ckle?= Date: Wed, 22 Jan 2025 23:56:32 +0100 Subject: [PATCH 4/4] Initialize the memory used for bytearrays We were accessing uninitialized memory whenever using bytearrays which causes valgrind to complain. Now that memory is just initialized to 0 --- libraries/llvm/bytearray.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/llvm/bytearray.c b/libraries/llvm/bytearray.c index 00be83d31..736f79ab3 100644 --- a/libraries/llvm/bytearray.c +++ b/libraries/llvm/bytearray.c @@ -22,6 +22,7 @@ struct Pos c_bytearray_new(const Int size) { void *objPtr = malloc(sizeof(struct Header) + size); struct Header *headerPtr = objPtr; *headerPtr = (struct Header) { .rc = 0, .eraser = c_bytearray_erase_noop, }; + memset(objPtr + sizeof(struct Header), 0, size); return (struct Pos) { .tag = size, .obj = objPtr,