marten icon indicating copy to clipboard operation
marten copied to clipboard

Compiling Marten projects in debug mode result in compilation errors

Open ellmetha opened this issue 2 years ago • 2 comments

Description

It appears trying to compile a Marten project in debug mode (with the --debug option) results in a compilation error. The problem might be on the Crystal compiler side of things, but let's investigate.

Versions

  • Crystal 1.11.2
  • Marten 0.4.4

How to reproduce

  1. Create an empty Marten project with marten new project testproject
  2. CD into the created project: cd testproject
  3. Install the project dependencies: shards install
  4. Try to compile the server in debug mode: crystal build src/server.cr -o bin/server --debug

The following error is returned:

BUG: called create_llvm_type for M (Exception)
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'raise<Exception>:NoReturn'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'raise<String>:NoReturn'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::LLVMTyper#create_llvm_type<Crystal::Type+, Bool>:NoReturn'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::LLVMTyper#llvm_type<Crystal::Type+, Bool>:LLVM::Type'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::LLVMTyper#create_llvm_type<Crystal::PointerInstanceType, Bool>:LLVM::Type'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::LLVMTyper#llvm_type<Crystal::Type+, Bool>:LLVM::Type'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::LLVMTyper#create_llvm_struct_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Bool>:LLVM::Type'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::LLVMTyper#llvm_struct_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Bool>:LLVM::Type'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::LLVMTyper#create_llvm_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Bool>:LLVM::Type'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::LLVMTyper#llvm_type<Crystal::Type+, Bool>:LLVM::Type'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::LLVMTyper#create_llvm_struct_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Bool>:LLVM::Type'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::LLVMTyper#llvm_struct_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Bool>:LLVM::Type'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_debug_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Crystal::Type+>:Pointer(Void)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_debug_type<Crystal::MixedUnionType, Crystal::Type+>:Pointer(Void)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_debug_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Crystal::Type+>:Pointer(Void)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_debug_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Crystal::Type+>:Pointer(Void)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_debug_type<Crystal::PointerInstanceType, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_debug_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Crystal::Type+>:Pointer(Void)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_debug_type<Crystal::PointerInstanceType, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_debug_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Crystal::Type+>:Pointer(Void)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_debug_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Crystal::Type+>:Pointer(Void)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_debug_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Crystal::Type+>:Pointer(Void)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_debug_type<Crystal::PointerInstanceType, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_debug_type<(Crystal::GenericClassInstanceType+ | Crystal::GenericClassType+ | Crystal::GenericModuleInstanceType | Crystal::GenericModuleType | Crystal::NonGenericClassType | Crystal::NonGenericModuleType+ | Crystal::VirtualType), Crystal::Type+>:Pointer(Void)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#get_debug_type<Crystal::Type+, Crystal::Type+>:(LibLLVM::MetadataRef | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:Crystal::LLVMTypedFunction'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:Crystal::LLVMTypedFunction'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#create_initialize_class_var_function<Crystal::MetaTypeVar, Crystal::ClassVarInitializer>:(Crystal::LLVMTypedFunction | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#initialize_class_var<Crystal::MetaTypeVar>:(LLVM::Value | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#codegen_assign<Crystal::ASTNode+, Crystal::ASTNode+, Crystal::Assign>:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::Expressions>:Bool'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::ClassDef>:Bool'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::ModuleDef>:Bool'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::ModuleDef>:Bool'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::ModuleDef>:Bool'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::FileNode>:Bool'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::Expressions>:Bool'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::FileNode>:Bool'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::Expressions>:Bool'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::FileNode>:Bool'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::CodeGenVisitor#visit<Crystal::Expressions>:Bool'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Tuple(Array(Crystal::Compiler::CompilationUnit), Array(String)) | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::Compiler#compile:combine_rpath<Array(Crystal::Compiler::Source), String, Bool>:Crystal::Compiler::Result'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in 'Crystal::Command::run<Array(String)>:(Bool | Crystal::Repl::Value | Nil)'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal in '__crystal_main'
  from /opt/homebrew/Cellar/crystal/1.11.2/bin/crystal 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

ellmetha avatar Apr 08 '24 02:04 ellmetha

Looks like you might have ran into https://github.com/crystal-lang/crystal/issues/3770 however there is actually a group of related issues with similar stack traces so it could fall under one of those too. Based on the described issue and the stack trace, it looks like the source is here:

https://github.com/martenframework/marten/blob/a1e7023ad71b680d2f06c1504f5bbb67191e0e55/src/marten/db/query/many_to_many_set.cr#L7

which could point to one of many methods using the M generic.

devnote-dev avatar Apr 08 '24 03:04 devnote-dev

Thanks for the info! Yes, there are also some issues (such as https://github.com/crystal-lang/crystal/issues/6588) that seem to suggest this may be related to generics inheritance (which Marten relies on for its query set mechanism). I suspect this may be related.

ellmetha avatar Apr 09 '24 02:04 ellmetha