Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: Module validation failed #6253

Open
Sija opened this issue Jun 24, 2018 · 14 comments
Open

ICE: Module validation failed #6253

Sija opened this issue Jun 24, 2018 · 14 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. status:needs-more-info topic:compiler

Comments

@Sija
Copy link
Contributor

Sija commented Jun 24, 2018

Module validation failed: Function return type does not match operand type of return inst!
  ret %"(Array(AnyHash::JSONTypes::Value) | Bool | Float32 | Float64 | Hash(String | Symbol, AnyHash::JSONTypes::Value)+ | Int128 | Int16 | Int32 | Int64 | Int8 | JSON::Any | Set(AnyHash::JSONTypes::Value) | String | Symbol | Time | UInt128 | UInt16 | UInt32 | UInt64 | UInt8 | Nil)" %1, !dbg !28
 %"(Array(AnyHash::JSONTypes::Value) | Bool | Float32 | Float64 | Hash(String | Symbol, AnyHash::JSONTypes::Value) | Int128 | Int16 | Int32 | Int64 | Int8 | JSON::Any | Set(AnyHash::JSONTypes::Value) | String | Symbol | Time | UInt128 | UInt16 | UInt32 | UInt64 | UInt8 | Nil)" = type { i32, [3 x i64] } (Exception)
  from Crystal::CodeGenVisitor#finish:Nil
  from Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Tuple(Array(Crystal::Compiler::CompilationUnit), Array(String)) | Nil)
  from Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result
  from Crystal::Command#run:(Bool | Crystal::Compiler::Result | Nil)
  from main

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/crystal-lang/crystal/issues

I have a hard time isolating the code responsible for the issue.
Happens with Crystal 0.26.0, Amber 0.8 and raven.cr (develop branch) on macOS.

@faustinoaq
Copy link
Contributor

faustinoaq commented Jun 24, 2018

@Sija Interesting, Does this error show any specific file/line?

@RX14 RX14 added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler labels Jun 25, 2018
@RX14 RX14 changed the title Compiler bug ICE: Module validation failed Jun 25, 2018
@Sija
Copy link
Contributor Author

Sija commented Jun 26, 2018

@faustinoaq none I can find, with --debug flag it fails with:

$ shards build --debug

Dependencies are satisfied
Building: pet-tracker
Error target pet-tracker failed to compile:
Module validation failed: conflicting debug info for argument
  call void @llvm.dbg.declare(metadata i32 %__temp_1797, metadata !1566, metadata !366), !dbg !1528
!1529 = !DILocalVariable(name: "self", arg: 1, scope: !1513, file: !322, line: 61, type: !1530)
!1566 = !DILocalVariable(name: "__temp_1797", arg: 1, scope: !1513, file: !322, line: 61, type: !14)

Crystal::CodeGenVisitor#finish:Nil
Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Tuple(Array(Crystal::Compiler::CompilationUnit), Array(String)) | Nil)
Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result
Crystal::Command#run:(Bool | Crystal::Compiler::Result | Nil)
main

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/crystal-lang/crystal/issues

@Sija
Copy link
Contributor Author

Sija commented Jul 1, 2018

Ahh, finally with master (props to @RX14 for #6261!) we have some proper backtrace:

$ ../crystal/bin/crystal build src/pet-tracker.cr --debug

Using compiled compiler at `.build/crystal'
Module validation failed: conflicting debug info for argument
  call void @llvm.dbg.declare(metadata i32 %__temp_1797, metadata !1566, metadata !366), !dbg !1528
!1529 = !DILocalVariable(name: "self", arg: 1, scope: !1513, file: !322, line: 61, type: !1530)
!1566 = !DILocalVariable(name: "__temp_1797", arg: 1, scope: !1513, file: !322, line: 61, type: !14)

/Users/sija/Code/crystal/src/llvm/module.cr:78:9 in 'verify'
/Users/sija/Code/crystal/src/compiler/crystal/codegen/codegen.cr:343:9 in 'finish'
/Users/sija/Code/crystal/src/compiler/crystal/codegen/codegen.cr:67:7 in 'codegen'
/Users/sija/Code/crystal/src/compiler/crystal/codegen/codegen.cr:63:5 in 'codegen:debug:single_module'
/Users/sija/Code/crystal/src/compiler/crystal/compiler.cr:22:7 in 'codegen'
/Users/sija/Code/crystal/src/compiler/crystal/compiler.cr:145:16 in 'compile'
/Users/sija/Code/crystal/src/compiler/crystal/command.cr:264:7 in 'compile'
/Users/sija/Code/crystal/src/compiler/crystal/command.cr:262:5 in 'compile'
/Users/sija/Code/crystal/src/compiler/crystal/command.cr:164:5 in 'build'
/Users/sija/Code/crystal/src/compiler/crystal/command.cr:69:7 in 'run'
/Users/sija/Code/crystal/src/compiler/crystal/command.cr:48:5 in 'run'
/Users/sija/Code/crystal/src/compiler/crystal/command.cr:47:3 in 'run'
/Users/sija/Code/crystal/src/compiler/crystal.cr:8:1 in '__crystal_main'
/Users/sija/Code/crystal/src/crystal/main.cr:104:5 in 'main_user_code'
/Users/sija/Code/crystal/src/crystal/main.cr:93:7 in 'main'
/Users/sija/Code/crystal/src/crystal/main.cr:133:3 in 'main'

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/crystal-lang/crystal/issues

@bew
Copy link
Contributor

bew commented Jul 4, 2018

Funny, here is another undocumented thing to debug this kind of error:
https://github.com/crystal-lang/crystal/blob/master/src/compiler/crystal/codegen/codegen.cr#L324-L338

One can do DUMP=1 crystal build <file> to dump the llvm-ir before the ir validation (that triggers a module validation error as OP).
You can also do DUMP=some_regex crystal build <file> to dump only the llvm module that matches some_regex.

@Sija
Copy link
Contributor Author

Sija commented Jul 4, 2018

@bew Nice find! I'll dig into that and report back.

@Sija
Copy link
Contributor Author

Sija commented Jul 4, 2018

Interestingly, the latter exception relates to https://github.com/amberframework/amber/blob/v0.8.0/src/amber/server/server.cr#L63, if I comment that line we're back to square/exception one.

Mentioned self is of a type Amber::Server and __temp_1797 is Signal.

@Sija
Copy link
Contributor Author

Sija commented Jul 8, 2018

Seems like the second error has been fixed by #6346 and/or possibly others.

@Sija
Copy link
Contributor Author

Sija commented Jul 26, 2018

Interestingly now it fails with:

Using compiled compiler at `.build/crystal'
Error in src/pet-tracker.cr:3: instantiating 'Amber::Server:Class#start()'

Amber::Server.start
              ^~~~~

in lib/amber/src/amber/server/server.cr:17: instantiating 'Amber::Server#run()'

      instance.run
               ^~~

in lib/amber/src/amber/server/server.cr:47: instantiating 'Amber::Cluster:Class#fork()'

        thread_count.times { Cluster.fork }
                                     ^~~~

in lib/amber/src/amber/server/cluster.cr:15: instantiating 'Process:Class#fork()'

      Process.fork { Process.run(PROGRAM_NAME, nil, env_hash, true, false, input: Process::Redirect::Inherit, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit) }
              ^~~~

in /Users/sija/Code/crystal/src/process.cr:80: instantiating 'fork_internal()'

    pid = fork_internal do
          ^~~~~~~~~~~~~

in /Users/sija/Code/crystal/src/process.cr:80: instantiating 'fork_internal()'

    pid = fork_internal do
          ^~~~~~~~~~~~~

in lib/amber/src/amber/server/cluster.cr:15: instantiating 'Process:Class#fork()'

      Process.fork { Process.run(PROGRAM_NAME, nil, env_hash, true, false, input: Process::Redirect::Inherit, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit) }
              ^~~~

in lib/amber/src/amber/server/cluster.cr:15: instantiating 'env_hash()'

      Process.fork { Process.run(PROGRAM_NAME, nil, env_hash, true, false, input: Process::Redirect::Inherit, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit) }
                                                    ^~~~~~~~

in lib/amber/src/amber/server/cluster.cr:8: no overload matches 'Hash(Char, Char)#[]=' with types String, String
Overloads are:
 - Hash(K, V)#[]=(key : K, value : V)

        env["FORKED"] = "1"
           ^

Edit: fixed in #6499

@miketheman
Copy link
Contributor

#codetriage
@Sija I think it might have something to do with #6333

I boiled it down to a simple example:

puts typeof(ENV.to_h)

Running on 0.25.1, we get Hash(String, String) https://carc.in/#/r/4onf

Here's a console with old vs new, showing the output change.

$ crystal --version
Crystal 0.25.1 (2018-06-30)

LLVM: 5.0.2
Default target: x86_64-apple-macosx

$ crystal eval 'puts typeof(ENV.to_h)'
Hash(String, String)

$ ~/workspace/miketheman/crystal/bin/crystal --version
Using compiled compiler at `.build/crystal'
Crystal 0.25.1+109 [ff3225fad] (2018-08-06)

LLVM: 6.0.1
Default target: x86_64-apple-macosx

$ ~/workspace/miketheman/crystal/bin/crystal eval 'puts typeof(ENV.to_h)'
Using compiled compiler at `.build/crystal'
Hash(Char, Char)

The signature has between 0.25.1 and ff3225f - and I used git bisect to try and narrow it down - but there's been a variety of toolchain changes that I can't seem to nail down to bisect from 0.25.1 onwards.

Tagging @straight-shoota and @RX14 who committed that changeset - maybe they can shed some light on this?

@straight-shoota
Copy link
Member

Yeah, this seems to be caused by ENV.each yielding String, String instead of {String, String}. That messes up Enumerable#first which is used by Enumerable#to_h.

@RX14 RX14 closed this as completed in #6499 Aug 7, 2018
@RX14 RX14 reopened this Aug 7, 2018
@RX14
Copy link
Contributor

RX14 commented Aug 7, 2018

I doubt the original error has been fixed - just masked by a compile error which has now been solved.

@Sija
Copy link
Contributor Author

Sija commented Aug 18, 2018

I've just managed to narrow it down to extending Hash.

@straight-shoota
Copy link
Member

straight-shoota commented Sep 7, 2019

I've just managed to narrow it down to extending Hash.

My example from #6997 (comment) also includes subclasses of Hash (Shards::Dependency and Shards::Target). So it seems plausible that this is somehow causing this.

Maybe crystal-lang/shards#230 should be reconsidered?

@Sija
Copy link
Contributor Author

Sija commented Sep 7, 2019

@straight-shoota Well, guess what, there was a PR fixing it, but @ysbaddaden decided it was a nitpicking... Perhaps it's not after all? :P

Edit: you've beat me by a minute, 🎩 for the good memory :)

All in all it's still avoiding the issue instead of fixing it, but I guess it's better that way until someone (@asterite - thinking of you!) will be brave enough to tackle the root cause of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. status:needs-more-info topic:compiler
Projects
None yet
Development

No branches or pull requests

7 participants