Crystal: Compiler crash: "Module validation failed: Terminator found in the middle of a basic block!"

Created on 4 Aug 2016  Â·  3Comments  Â·  Source: crystal-lang/crystal

Crystal 0.18.7 (2016-07-03)

require "./src/pg"

DB = PG.connect("postgres:///")

QUERY_1 = "select $1, $2"
ARGS_1  = {-1, true}

rows = 0
DB.exec(QUERY_1, ARGS_1) { |row| rows += 1 }
p rows
crystal-pg ➤ crystal build test-crash.cr                                                                                                            git:master
Module validation failed: Terminator found in the middle of a basic block!
label %initialized89
Call parameter type does not match function signature!
%Nil zeroinitializer
 i32  %156 = call i32 @"*p<Int32>:Int32"(%Nil zeroinitializer)

[4498693843] *raise<String>:NoReturn +163
[4509221027] *Crystal::CodeGenVisitor#finish:Hash(String, LLVM::Module) +2035
[4508788874] *Crystal::Compiler#codegen<Crystal::Program, Crystal::Expressions, Array(Crystal::Compiler::Source), String>:(Array(String) | Nil) +5722
[4500100384] *Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result +5472
[4498913273] *Crystal::Command#run:(Array(Crystal::ImplementationTrace) | Array(Crystal::Init::View+:Class) | Array(String) | Bool | Crystal::Compiler::Result
| Hash(String, String) | IO::FileDescriptor+ | Nil) +2569
[4498788513] main +18721

Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crys
tal-lang/crystal/issues
bug compiler

Most helpful comment

Thank you!

Reduced:

lib LibC
  fun exit(Int32) : NoReturn
end

def foo : Nil
  LibC.exit(0)
  yield
end

def bar(x)
  x
end

foo { }
bar 0

In your case the problem is that in ExtendedQuery, params.map will return a tuple (Tuple#map returns a tuple), so it's an infinite recursion. You'll have to do params.map { ... }.to_a. That infinite recursion translates into a NoReturn in Crystal, that's why in the reduction I simply use an exit. I don't know why it happens yet.

All 3 comments

If the args passed in as an array does not cause it to crash apparently

Thank you!

Reduced:

lib LibC
  fun exit(Int32) : NoReturn
end

def foo : Nil
  LibC.exit(0)
  yield
end

def bar(x)
  x
end

foo { }
bar 0

In your case the problem is that in ExtendedQuery, params.map will return a tuple (Tuple#map returns a tuple), so it's an infinite recursion. You'll have to do params.map { ... }.to_a. That infinite recursion translates into a NoReturn in Crystal, that's why in the reduction I simply use an exit. I don't know why it happens yet.

Amazing

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jhass picture jhass  Â·  3Comments

pbrusco picture pbrusco  Â·  3Comments

lgphp picture lgphp  Â·  3Comments

asterite picture asterite  Â·  3Comments

Papierkorb picture Papierkorb  Â·  3Comments