Wondering if anyone can help me with an issue I’m having where I’m hitting a complexity limit.
Stack overflow (e.g., infinite or very deep recursion)
[0x10c756057] *CallStack::print_backtrace:Int32 +39
[0x10c6a7a20] __crystal_sigfault_handler +96
[0x7fff68526b5d] _sigtramp +29
[0x10c0450ce] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2302
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
...
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
...
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c584dc8] *Crystal::MainVisitor#expand<Crystal::StringInterpolation>:Bool +1608
[0x10c0466f6] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +7974
[0x10c4ab1b8] *Crystal::MainVisitor#type_assign<Crystal::Var+, Crystal::ASTNode+, Crystal::Assign, Nil>:(Crystal::MetaVar | Nil) +40
[0x10c4aa1f3] *Crystal::MainVisitor#visit<Crystal::Assign>:Bool +83
[0x10c044fdc] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2060
[0x10c04768b] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +11963
[0x10c699a04] *Crystal::Call#instantiate<Crystal::Matches, Crystal::Type+, Nil, Bool>:Array(Crystal::Def+) +6708
[0x10c694bdf] *Crystal::Call#lookup_matches_in_type<Crystal::Type+, Array(Crystal::Type+), (Array(Crystal::NamedArgumentType) | Nil), Nil, String, Bool, Bool, Bool>:Array(Crystal::Def+) +6463
[0x10c69b43a] *Crystal::Call#lookup_matches_in:with_literals<Crystal::Type+, Array(Crystal::Type+), (Array(Crystal::NamedArgumentType) | Nil), Bool>:Array(Crystal::Def+) +154
[0x10c60e040] *Crystal::Call#lookup_matches:with_literals<Bool>:Array(Crystal::Def+) +2240
[0x10be29217] *Crystal::Call#recalculate:Nil +2503
[0x10c0cf8b3] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +6819
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0cecd4] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +3780
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c584dc8] *Crystal::MainVisitor#expand<Crystal::StringInterpolation>:Bool +1608
[0x10c0466f6] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +7974
[0x10c0ce165] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +853
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c4ab1b8] *Crystal::MainVisitor#type_assign<Crystal::Var+, Crystal::ASTNode+, Crystal::Assign, Nil>:(Crystal::MetaVar | Nil) +40
[0x10c4aa1f3] *Crystal::MainVisitor#visit<Crystal::Assign>:Bool +83
[0x10c044fdc] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2060
[0x10c04768b] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +11963
[0x10c699a04] *Crystal::Call#instantiate<Crystal::Matches, Crystal::Type+, Nil, Bool>:Array(Crystal::Def+) +6708
[0x10c694bdf] *Crystal::Call#lookup_matches_in_type<Crystal::Type+, Array(Crystal::Type+), (Array(Crystal::NamedArgumentType) | Nil), Nil, String, Bool, Bool, Bool>:Array(Crystal::Def+) +6463
[0x10c69b43a] *Crystal::Call#lookup_matches_in:with_literals<Crystal::Type+, Array(Crystal::Type+), (Array(Crystal::NamedArgumentType) | Nil), Bool>:Array(Crystal::Def+) +154
[0x10c60e040] *Crystal::Call#lookup_matches:with_literals<Bool>:Array(Crystal::Def+) +2240
[0x10be29217] *Crystal::Call#recalculate:Nil +2503
[0x10c0cf8b3] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +6819
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c0cecd4] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +3780
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c04768b] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +11963
[0x10c680414] *Crystal::Call#match_block_arg<Crystal::Match>:Tuple(Array(Crystal::Var+) | Nil, Crystal::Type+ | Nil) +5812
[0x10c698195] *Crystal::Call#instantiate<Crystal::Matches, Crystal::Type+, Nil, Bool>:Array(Crystal::Def+) +453
[0x10c694bdf] *Crystal::Call#lookup_matches_in_type<Crystal::Type+, Array(Crystal::Type+), (Array(Crystal::NamedArgumentType) | Nil), Nil, String, Bool, Bool, Bool>:Array(Crystal::Def+) +6463
[0x10c69b43a] *Crystal::Call#lookup_matches_in:with_literals<Crystal::Type+, Array(Crystal::Type+), (Array(Crystal::NamedArgumentType) | Nil), Bool>:Array(Crystal::Def+) +154
[0x10c60e040] *Crystal::Call#lookup_matches:with_literals<Bool>:Array(Crystal::Def+) +2240
[0x10be29217] *Crystal::Call#recalculate:Nil +2503
[0x10c0cf8b3] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +6819
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c04768b] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +11963
[0x10c4a857c] *Crystal::MainVisitor#visit<Crystal::Block>:(Bool | Nil) +2780
[0x10c4acb6a] *Crystal::MainVisitor#visit<Crystal::Yield>:Bool +1530
[0x10c045156] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2438
[0x10c04768b] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +11963
[0x10c699a04] *Crystal::Call#instantiate<Crystal::Matches, Crystal::Type+, Nil, Bool>:Array(Crystal::Def+) +6708
[0x10c694bdf] *Crystal::Call#lookup_matches_in_type<Crystal::Type+, Array(Crystal::Type+), (Array(Crystal::NamedArgumentType) | Nil), Nil, String, Bool, Bool, Bool>:Array(Crystal::Def+) +6463
[0x10c69b43a] *Crystal::Call#lookup_matches_in:with_literals<Crystal::Type+, Array(Crystal::Type+), (Array(Crystal::NamedArgumentType) | Nil), Bool>:Array(Crystal::Def+) +154
[0x10c60e040] *Crystal::Call#lookup_matches:with_literals<Bool>:Array(Crystal::Def+) +2240
[0x10be29217] *Crystal::Call#recalculate:Nil +2503
[0x10c0cf8b3] *Crystal::MainVisitor#visit<Crystal::Call>:Bool +6819
[0x10c0450d2] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +2306
[0x10c04768b] *Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil +11963
[0x10c2e3df1] *Crystal::Program#visit_main<Crystal::ASTNode+, Crystal::MainVisitor, Bool, Bool>:Crystal::ASTNode+ +129
[0x10c1ecba1] *Crystal::Program#semantic<Crystal::ASTNode+, Bool>:Crystal::ASTNode+ +10769
[0x10c6c1117] *Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result +71
[0x10c6aa622] *Crystal::Command#run:(Bool | Crystal::Compiler::Result | Nil) +1090
[0x10be01b7f] __crystal_main +14095
This happens when I add one too many functions to the code I’m working on. You can easily replicate this on your own device by:
- requires a local running instance of
redis-server
- clone: https://github.com/aca-labs/crystal-engine-drivers
- run:
shards update
- run:
crystal run ./src/app.cr
- browse to: http://localhost:3000/#/aca_drivers/drivers%2Fhelvar%2Fnet.cr?filter=
- click
run
This will compile and run a spec against a driver (we build commercial building automation systems and this is a development tool we built for writing drivers in crystal) - the Helvar::Net
driver is the one triggering this behaviour
The build will probably succeed if you just clone the repository as I limited the number of functions being generated to prevent this compiling issue. But if you uncomment some of these lines the issue will occur
This might be something @asterite would have some experience with - also I am happy to delve deep into the compiler internals if this is something that can be converted from a recursive algorithm to a dynamic one.
Not a super pressing issue at the moment as I don’t need all the functions but would be good to resolve or even understand what is triggering the behaviour.