GetFirefly / firefly

An alternative BEAM implementation, designed for WebAssembly
Apache License 2.0
3.61k stars 104 forks source link

Some issues building and compiling .erl #432

Closed erszcz closed 4 years ago

erszcz commented 4 years ago

Hi!

This is a great project! I've tried following the build steps on MacOS but got this error:

/Users/erszcz/work/lumen/lumen/compiler/codegen/lib/lumen/compiler/Translation/MLIR.cpp:37:27: error: no matching constructor for initialization of 'mlir::LLVM::LLVMDialect'
  auto *llvmDialect = new mlir::LLVM::LLVMDialect(mlirContext, llvmContext);
                          ^                       ~~~~~~~~~~~~~~~~~~~~~~~~
/Users/erszcz/.local/share/llvm/lumen/include/mlir/Dialect/LLVMIR/LLVMOpsDialect.h.inc:12:12: note: candidate constructor not viable: requires single argument 'context', but 2 arguments were provided
  explicit LLVMDialect(::mlir::MLIRContext *context);
           ^
/Users/erszcz/.local/share/llvm/lumen/include/mlir/Dialect/LLVMIR/LLVMOpsDialect.h.inc:10:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
class LLVMDialect : public ::mlir::Dialect {
      ^
1 error generated.

Environment details:

$ rustup --version
rustup 1.21.1 (7832b2ebe 2019-12-20)
$ cargo --version
cargo 1.45.0-nightly (cb06cb269 2020-05-08)
$ rustc --version
rustc 1.45.0-nightly (769d12eec 2020-05-12)

However, applying this patch allows me to build the project:

$ git diff
diff --git a/compiler/codegen/lib/lumen/compiler/Translation/MLIR.cpp b/compiler/codegen/lib/lumen/compiler/Translation/MLIR.cpp
index ce6dc9cf..a0316bc5 100644
--- a/compiler/codegen/lib/lumen/compiler/Translation/MLIR.cpp
+++ b/compiler/codegen/lib/lumen/compiler/Translation/MLIR.cpp
@@ -34,7 +34,7 @@ extern "C" void MLIRRegisterDialects(MLIRContextRef mlirCtx, LLVMContextRef llvm
   // NOTE: The dialect constructors internally call registerDialect,
   // which moves ownership of the dialect objects to the MLIRContext,
   // so we don't have to manage them ourselves.
-  auto *llvmDialect = new mlir::LLVM::LLVMDialect(mlirContext, llvmContext);
+  auto *llvmDialect = new mlir::LLVM::LLVMDialect(mlirContext);
   auto *eirDialect = new lumen::eir::EirDialect(mlirContext);
 }

Alas, it's not enough to get the compiler to work:

$ cat hello.erl
-module(test).
-compile(export_all).

main(_) ->
    io:format("hello\n", []).
$ ./bin/lumen compile -lc hello.erl
... debug output elided
Assertion failed: (ScopedContext::getCurrentScopedContext() && "Unexpected Null ScopedContext"), function getBuilder, file /Users/paulschoenfelder/src/github.com/bitwalker/llvm-project/mlir/lib/EDSC/Builders.cpp, line 54.
Abort trap: 6

Just thinking out loud, but might it be that the README on develop is not up to date with regard to LLVM version to use?

KronicDeth commented 4 years ago

Sorry, forgot to update the README. Use 2020-04-26 release of LLVM.

I'll update the README too.

On the specific note of your example code, we haven't implemented io:format/2 as a BIF and you're not explicitly listing io.erl from the Erlang source, so I doubt it would work anyway. erlang:display/1 is available, but that can only print a term. It's like the equivalent of IO.inspect/1 in Elixir. We use it lumen/tests.

KronicDeth commented 4 years ago

@erszcz use the updated README in https://github.com/lumen/lumen/blob/f8e61a3eb6a7a8636e70ac50703aef5d51f508ea/README.md. If you still have a problem, please open a new issue to address it.

erszcz commented 4 years ago

@KronicDeth Thanks for a swift response! With this LLVM version it builds and compiles example code fine.