Open kalinon opened 3 years ago
Duplicate of https://github.com/crystal-lang/crystal/issues/8551?
@Blacksmoke16 possibly, but i did not see any mention of --debug
. my issue only occurs when using that flag. Compile/run works fine without.
This is still present in 0.36.1
The code from #8968 also produces a similar error. So probably is duplicate of #8968 & #8551. Seems to be happening during the codegen step.
I was able to track this down to the union of generic types during codegen. Using the example code from #8968 (https://play.crystal-lang.org/#/r/8sai) i was able to get the following stack trace:
BUG: called create_llvm_type for ValueType (Exception)
from src/compiler/crystal/codegen/llvm_typer.cr:254:7 in 'create_llvm_type'
from src/compiler/crystal/codegen/llvm_typer.cr:88:37 in 'llvm_type'
from src/compiler/crystal/codegen/llvm_typer.cr:374:9 in 'llvm_embedded_type'
from src/compiler/crystal/codegen/llvm_typer.cr:308:32 in 'create_llvm_struct_type'
from src/compiler/crystal/codegen/llvm_typer.cr:261:44 in 'llvm_struct_type'
from src/compiler/crystal/codegen/llvm_typer.cr:140:20 in 'create_llvm_type'
from src/compiler/crystal/codegen/llvm_typer.cr:88:37 in 'llvm_type'
from src/compiler/crystal/codegen/unions.cr:34:28 in 'create_llvm_type'
from src/compiler/crystal/codegen/llvm_typer.cr:90:26 in 'llvm_type'
from src/compiler/crystal/codegen/llvm_typer.cr:84:5 in 'llvm_type'
from src/compiler/crystal/codegen/llvm_builder_helper.cr:182:5 in 'llvm_type'
from src/compiler/crystal/codegen/llvm_builder_helper.cr:179:23 in 'cast_to_pointer'
from src/compiler/crystal/codegen/unions.cr:121:7 in 'downcast_distinct_union_types'
from src/compiler/crystal/codegen/cast.cr:415:7 in 'downcast_distinct'
from src/compiler/crystal/codegen/cast.cr:291:15 in 'downcast'
from src/compiler/crystal/codegen/codegen.cr:1145:17 in 'visit'
from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from src/compiler/crystal/codegen/codegen.cr:2184:7 in 'accept'
from src/compiler/crystal/codegen/call.cr:100:7 in 'prepare_call_args_non_external'
from src/compiler/crystal/codegen/call.cr:57:7 in 'prepare_call_args'
from src/compiler/crystal/codegen/call.cr:21:26 in 'visit'
from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from src/compiler/crystal/codegen/codegen.cr:2184:7 in 'accept'
from src/compiler/crystal/codegen/call.cr:405:11 in 'codegen_dispatch'
from src/compiler/crystal/codegen/call.cr:15:7 in 'visit'
from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from src/compiler/crystal/codegen/codegen.cr:2184:7 in 'accept'
from src/compiler/crystal/codegen/codegen.cr:619:9 in 'visit'
from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from src/compiler/crystal/codegen/codegen.cr:2184:7 in 'accept'
from src/compiler/crystal/codegen/codegen.cr:67:7 in 'codegen'
from src/compiler/crystal/codegen/codegen.cr:65:5 in 'codegen:debug:single_module'
from src/compiler/crystal/progress_tracker.cr:22:7 in 'codegen'
from src/compiler/crystal/compiler.cr:172:16 in 'compile'
from src/compiler/crystal/command.cr:296:3 in 'compile'
from src/compiler/crystal/command.cr:294:5 in 'compile'
from src/compiler/crystal/command.cr:187:5 in 'build'
from src/compiler/crystal/command.cr:73:7 in 'run'
from src/compiler/crystal/command.cr:49:5 in 'run'
from src/compiler/crystal/command.cr:48:3 in 'run'
from src/compiler/crystal.cr:11:1 in '__crystal_main'
from src/crystal/main.cr:110:5 in 'main_user_code'
from src/crystal/main.cr:96:7 in 'main'
from src/crystal/main.cr:119:3 in 'main'
Debugging and prints got me the following information when downcast_distinct_union_types
is being called.
from src/compiler/crystal/codegen/unions.cr:121:7 in 'downcast_distinct_union_types'
value: %84 = phi %"(GreaterThan(Int32) | NotBlank)"* [ %8, %current_def7 ], [ %10, %current_def10 ], !dbg !61
to_type: (AbstractComparison(Int32) | AbstractComparison(ValueType) | GreaterThan(Int32))
The to_type
has both AbstractComparison(Int32)
and its generic type AbstractComparison(ValueType)
defined. This eventually leads to the error. I was able to clumsily reject the generic type by adding a reject in including_types
defined in types.cr
:
The reject will filter out any instance_types
that is the same as its generic_type
.
def including_types
instances = generic_types.values
subclasses.each do |subclass|
if subclass.is_a?(GenericClassType)
subtypes = subclass.including_types
instances << subtypes if subtypes
else
instances << subclass
end
end
instances.reject! {|i| i.is_a?(GenericClassInstanceType) && i.instance_type.to_s == i.generic_type.to_s}
program.union_of instances
end
This allowed me to compile successfully, but I do not want to open a PR on this. Perhaps someone like @straight-shoota or @Blacksmoke16 will know how to fix this issue correctly.
@asterite looks like you wrote the original code (5 years ago!) anything jump out at you?
@kalinon I don't have time to look into this, but my advise is to not use --debug
@asterite thanks for the response. I'm guessing you mean don't use --debug
for everyday compiling? I needed --debug
for the symbolic info to trace it via debug tools. Unless there's another reason not to.
I am experiencing the same issue on my linux machine :
BUG: called create_llvm_type for Root (Exception)
from /crystal/src/compiler/crystal/codegen/llvm_typer.cr:254:7 in 'create_llvm_type'
from /crystal/src/pointer.cr:117:6 in 'llvm_type'
from /crystal/src/compiler/crystal/codegen/llvm_typer.cr:379:7 in 'create_llvm_struct_type'
from /crystal/src/compiler/crystal/codegen/llvm_typer.cr:263:33 in 'llvm_struct_type'
from /crystal/src/compiler/crystal/codegen/llvm_typer.cr:257:5 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:173:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:173:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:173:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:233:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:233:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:233:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:315:7 in 'get_debug_type'
from /crystal/src/compiler/crystal/codegen/debug.cr:351:7 in 'declare_variable'
from /crystal/src/compiler/crystal/codegen/codegen.cr:1837:17 in 'alloca_non_closured_vars'
from /crystal/src/compiler/crystal/codegen/call.cr:295:7 in 'visit'
from /crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from /crystal/src/compiler/crystal/codegen/codegen.cr:667:9 in 'accept'
from /crystal/src/compiler/crystal/codegen/codegen.cr:2281:7 in 'codegen_fun'
from /crystal/src/compiler/crystal/codegen/fun.cr:51:3 in 'accept'
from /crystal/src/compiler/crystal/codegen/call.cr:331:5 in 'visit'
from /crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from /crystal/src/compiler/crystal/codegen/codegen.cr:667:9 in 'accept'
from /crystal/src/compiler/crystal/codegen/codegen.cr:727:15 in 'accept'
from /crystal/src/compiler/crystal/codegen/codegen.cr:667:9 in 'accept'
from /crystal/src/compiler/crystal/codegen/codegen.cr:437:17 in 'accept'
from /crystal/src/compiler/crystal/codegen/codegen.cr:667:9 in 'accept'
from /crystal/src/compiler/crystal/codegen/codegen.cr:437:17 in 'accept'
from /crystal/src/compiler/crystal/codegen/codegen.cr:667:9 in 'accept'
from /crystal/src/compiler/crystal/codegen/codegen.cr:437:17 in 'accept'
from /crystal/src/compiler/crystal/codegen/codegen.cr:667:9 in 'accept'
from /crystal/src/compiler/crystal/codegen/codegen.cr:2246:7 in 'codegen'
from /crystal/src/compiler/crystal/compiler.cr:173:16 in 'compile'
from /crystal/src/compiler/crystal/command.cr:220:5 in 'run_command'
from /crystal/src/compiler/crystal/command.cr:64:5 in '__crystal_main'
from /crystal/src/crystal/main.cr:115:5 in 'main'
from src/env/__libc_start_main.c:94:2 in 'libc_start_main_stage2'
Crystal 1.3.2 [932f193ae] (2022-01-18)
LLVM: 10.0.0 Default target: x86_64-unknown-linux-gnu
I get the following error when compiling my examples with --debug. Im pretty sure it has something to do with my use of generics in my entitas framework: entitas.cr. Getting into the compiler gets a little over my head so figured id pass this one up the chain.
How to reproduce on OSX:
Crystal version:
OS Version:
Error: