asterius icon indicating copy to clipboard operation
asterius copied to clipboard

"RuntimeError: unreachable"

Open lemmih opened this issue 3 years ago • 7 comments

Describe the bug Running this code fails with 'RuntimeError: unreachable':

{-# LANGUAGE PackageImports #-}
module Main where

import Graphics.SvgTree
import Graphics.SvgTree.Printer
import "lens" Control.Lens

main :: IO ()
main = putStrLn $ ppTree (CircleTree $ Circle mempty (Num 0, Num 0) (Num 2))
root@ac07adc0d6f9:/workspace# ahc-link --input-hs test.hs --run
[INFO] Compiling test.hs to WebAssembly
[INFO] Converting linked IR to binaryen IR
[INFO] Running binaryen optimization
[INFO] Validating binaryen IR
[INFO] Writing WebAssembly binary to "./test.wasm"
[INFO] Writing JavaScript runtime modules to "."
[INFO] Writing JavaScript loader module to "./test.wasm.mjs"
[INFO] Writing JavaScript req module to "./test.req.mjs"
[INFO] Writing JavaScript entry module to "./test.mjs"
[INFO] Running ./test.mjs
test: JSException "RuntimeError: unreachable\n    at <anonymous>:wasm-function[5314]:0x1320cb\n    at <anonymous>:wasm-function[12289]:0x2db0f9\n    at scheduleTSO (<anonymous>:wasm-function[12290]:0x2db126)\n    at Scheduler.tick (file:///workspace/rts.scheduler.mjs:346:22)\n    at Immediate.<anonymous> (file:///workspace/rts.scheduler.mjs:381:29)\n    at processImmediate (internal/timers.js:458:21)"

Running the same code but with a circle radius of '0' works fine:

main = putStrLn $ ppTree (CircleTree $ Circle mempty (Num 0, Num 0) (Num 0))
root@ac07adc0d6f9:/workspace# ahc-link --input-hs test.hs --run
[INFO] Compiling test.hs to WebAssembly
[INFO] Converting linked IR to binaryen IR
[INFO] Running binaryen optimization
[INFO] Validating binaryen IR
[INFO] Writing WebAssembly binary to "./test.wasm"
[INFO] Writing JavaScript runtime modules to "."
[INFO] Writing JavaScript loader module to "./test.wasm.mjs"
[INFO] Writing JavaScript req module to "./test.req.mjs"
[INFO] Writing JavaScript entry module to "./test.mjs"
[INFO] Running ./test.mjs
<circle />

Oh, running with --verbose-err gives this (reformatted):

test: JSException "RuntimeError: barf: _hs_ToFixedLength\n
    at ExceptionHelper.barf (file:///workspace/rts.exception.mjs:147:13)\n
    at barf (<anonymous>:wasm-function[817]:0x3f822)\n
    at doublezmconversionzm2zi0zi2zi0zmL7SF9hmoOH71AQFMRAfBSp_DataziDoubleziConversionziText_toFixedzulen_entry (<anonymous>:wasm-function[5319]:0x13237f)\n
    at scheduleTSO (<anonymous>:wasm-function[12294]:0x2db6b4)\n
    at scheduleTSO_wrapper (<anonymous>:wasm-function[12295]:0x2db6e1)\n
    at Scheduler.tick (file:///workspace/rts.scheduler.mjs:346:22)\n
    at Immediate.<anonymous> (file:///workspace/rts.scheduler.mjs:381:29)\n
    at processImmediate (internal/timers.js:458:21)"

To Reproduce Put the above code in test.hs and run it with: ahc-link --input-hs test.hs --run. It depends on 'reanimate-svg' which is already included in the docker image.

Expected behavior I expected it to print <circle r="2"/>.

Environment

  • OS name + version: Ubuntu 20.04
  • Version of the code: Latest docker image

lemmih avatar Aug 02 '20 08:08 lemmih

Ah, it must be because I'm using double-conversion which uses cbits. Guess you can close this issue.

lemmih avatar Aug 02 '20 08:08 lemmih

Can I manually compile the C code with emscripten and make it available somehow?

lemmih avatar Aug 02 '20 08:08 lemmih

compile the C code with emscripten and make it available somehow?

That code can only be used via foreign import javascript, which means one needs to patch the ccall logic for now and handle the emscripten packaging logic themselves. This is the best we can do for now, but we've about to start working on adding a C toolchain to handle C stuff, so the status quo will be improved; can't give an exact ETA yet though.

TerrorJack avatar Aug 03 '20 10:08 TerrorJack

Alright. Can I detect when my package is being compiled by asterius? Something like if impl(asterius) {} in the cabal file?

lemmih avatar Aug 03 '20 15:08 lemmih

#725 solves my issue but no new docker image has been built. Are new docker images not built automatically when new patches are pushed?

lemmih avatar Aug 06 '20 05:08 lemmih

terrorjack/asterius:latest has now been updated to terrorjack/asterius:200805. The docker images are built with a different CI infra, and takes a lot of time to build.

TerrorJack avatar Aug 06 '20 11:08 TerrorJack

My library now works with Asterius. :) But it requires a lot of memory to compile, a little more than 6GB. Do you have any tips or tricks for reducing the memory requirements?

lemmih avatar Aug 06 '20 13:08 lemmih