Comments (5)
The issue 2. is hard to reproduce as on the LLVM REPL, as it works for normal strings:
> def foo(s: String): Unit = s.split("\n").foreach { x => println(x) }
foo: String => Unit
> foo("a\nb")
a
b
()
but when I try to pipe strings gotten from files into it, I run into a hard crash (possibly a different one than in 3.)
> def getInput(s: String) = { var out in global = ""; eventloop(box { with on[IOError].panic; with filesystem; out = do readFile(s) }); out }
getInput: String => String
> getInput("tiny.input")
[error] Process exited with non-zero exit code 134.
🔍 Here's a more detailed sanitiser trace
=================================================================
==11270==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x619000000080 in thread T0
#0 0x1049712c0 in wrap_free+0x90 (libclang_rt.asan_osx_dynamic.dylib:arm64+0x4d2c0) (BuildId: 7615c595d022355bb91dd63f44086bc832000000200000000100000000000b00)
#1 0x10455b2f0 in topLevel+0x40 (interactive:arm64+0x1000072f0) (BuildId: ac687bd67e75387bb75bb5090faec84932000000200000000100000000000b00)
#2 0x1046bfeb4 in uv_run+0x25c (libuv.1.dylib:arm64+0x7eb4) (BuildId: 208160f0746f3fb2a43dfcdb736ed89c32000000200000000100000000000b00)
#3 0x10455d9bc in k_332+0x1c (interactive:arm64+0x1000099bc) (BuildId: ac687bd67e75387bb75bb5090faec84932000000200000000100000000000b00)
#4 0x10477d088 in start+0x204 (dyld:arm64+0x5088) (BuildId: 38ee9fe9b66d30668c5c6ddf0d6944c632000000200000000100000000060c00)
#5 0x304dfffffffffffc (<unknown module>)
Address 0x619000000080 is a wild pointer inside of access range of size 0x000000000001.
SUMMARY: AddressSanitizer: bad-free (libclang_rt.asan_osx_dynamic.dylib:arm64+0x4d2c0) (BuildId: 7615c595d022355bb91dd63f44086bc832000000200000000100000000000b00) in wrap_free+0x90
==11270==ABORTING
which seems like the very same bug as 2., if my eyes don't deceive me.
When formatted nicely, getInput
looks like:
def getInput(s: String) = {
var out in global = "";
eventloop(box {
with on[IOError].panic;
with filesystem;
// escape hatch, trying to return a string
out = do readFile(s)
})
out
}
On the JS backend, it returns only an empty string (which makes sense as out
has not been written into yet), so this is probably not the way to go about making a small testcase...
from effekt.
I added a sanitiser trace to 3. by applying the following patch:
diff --git c/effekt/jvm/src/main/scala/effekt/Runner.scala i/effekt/jvm/src/main/scala/effekt/Runner.scala
index 5eb85f65..d5f52921 100644
--- c/effekt/jvm/src/main/scala/effekt/Runner.scala
+++ i/effekt/jvm/src/main/scala/effekt/Runner.scala
@@ -209,7 +209,7 @@ object LLVMRunner extends Runner[String] {
override def prelude: List[String] = List("effekt", "option", "list", "result", "exception", "string") // "array", "ref")
- lazy val gccCmd = discoverExecutable(List("cc", "clang", "gcc"), List("--version"))
+ lazy val gccCmd = discoverExecutable(List("clang"), List("--version"))
lazy val llcCmd = discoverExecutable(List("llc", "llc-15", "llc-16"), List("--version"))
lazy val optCmd = discoverExecutable(List("opt", "opt-15", "opt-16"), List("--version"))
@@ -267,7 +267,7 @@ object LLVMRunner extends Runner[String] {
val gccMainFile = (C.config.libPath / ".." / "llvm" / "main.c").unixPath
val executableFile = basePath
- val gccArgs = Seq(gcc, gccMainFile, "-o", executableFile, objPath) ++ libuvArgs
+ val gccArgs = Seq(gcc, "-fsanitize=address,undefined,leak,integer", gccMainFile, "-o", executableFile, objPath) ++ libuvArgs
exec(gccArgs: _*)
executableFile
from effekt.
Here's some more details: I tried printing the frees in @topLevel
:
<called from `runPos`>
Freeing base: 0x144d2c800
Freeing base.0: 0x0
Freeing base.1: 0x619000000080
Freeing base.2: 0x0
Freeing env: 0x154d34800
<called from `run`>
Freeing base: 0x144d2c800
Freeing base.0: 0x0
Freeing base.1: 0x619000000080
<uhoh, 💥>
from effekt.
It turns out that 2. is "just" mishandling escapes on the LLVM backends:
def main() = {
eventloop(box {
with on[IOError].panic;
with filesystem;
def analyse(str: String) = {
println("Analysing: '" ++ str ++ "'")
each (0, str.length) { i =>
with on[OutOfBounds].panic;
val c = str.charAt(i)
println("char " ++ c.show ++ " (" ++ c.toInt.show ++ ")")
}
}
val longstr = "kjrqmzv9mmtxhgvsevenhvq7\nfour2tszbgmxpbvninebxns6nineqbqzgjpmpqr"
analyse(longstr)
val contents = do readFile("day1-tiny.input") // same contents as `longstr`, just from a file
analyse(contents)
})
}
If you look into the log, you'll see:
Analysing: 'kjrqmzv9mmtxhgvsevenhvq7\nfour2tszbgmxpbvninebxns6nineqbqzgjpmpqr'
char k (107)
[...]
char \ (92)
char n (110)
[...]
Analysing: 'kjrqmzv9mmtxhgvsevenhvq7
four2tszbgmxpbvninebxns6nineqbqzgjpmpqr'
char k (107)
[...]
char
(10)
[...]
So actually the string read from a file is correct, the string literal isn't.
from effekt.
I've split this to two separate issues: #503 and #504
from effekt.
Related Issues (20)
- Tests for `exception` stdlib. HOT 1
- [To be discussed] Allow match guards as boolean expressions
- Rename constructors of collections HOT 1
- Wrong primitive names in LLVM I/O HOT 2
- Top-level constants in the LLVM backend
- `equals` does not work properly in chez Backends
- Convention for error reporting and aborting HOT 1
- Store string literals in their unescaped form HOT 6
- Functions outside of the event loop segfault on LLVM
- Overeager JS inliner forgets to parenthesize HOT 1
- Consistently name generated ML binary
- Support for prefix operators HOT 5
- `array::copy(from, start, to, offset, length)` copies one element more
- References escape their region when using `var` HOT 1
- More descriptive comments when generating LLVM from Machine
- Unexpected end of input on opening brace after newline HOT 1
- Existentially quantified types are defined in outer scope HOT 2
- Investigate using memory use markers in the generated LLVM
- Renamer stack-overflows on large test suites HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from effekt.