From f56221fbe05ca376d77e287cdbcecd6e653c7d5b Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 13 Apr 2022 14:33:24 -0400 Subject: [PATCH] more friendly/useful error for stack overflow in type inference fixes #44852 --- src/gf.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/gf.c b/src/gf.c index eeefe02300b00..3fc75f862500a 100644 --- a/src/gf.c +++ b/src/gf.c @@ -317,10 +317,19 @@ jl_code_info_t *jl_type_infer(jl_method_instance_t *mi, size_t world, int force) src = (jl_code_info_t*)jl_apply(fargs, 3); } JL_CATCH { - jl_printf((JL_STREAM*)STDERR_FILENO, "Internal error: encountered unexpected error in runtime:\n"); - jl_static_show((JL_STREAM*)STDERR_FILENO, jl_current_exception()); - jl_printf((JL_STREAM*)STDERR_FILENO, "\n"); - jlbacktrace(); // written to STDERR_FILENO + jl_value_t *e = jl_current_exception(); + if (e == jl_stackovf_exception) { + jl_printf((JL_STREAM*)STDERR_FILENO, "Internal error: stack overflow in type inference of "); + jl_static_show_func_sig((JL_STREAM*)STDERR_FILENO, (jl_value_t*)mi->specTypes); + jl_printf((JL_STREAM*)STDERR_FILENO, ".\n"); + jl_printf((JL_STREAM*)STDERR_FILENO, "This might be caused by recursion over very long tuples or argument lists.\n"); + } + else { + jl_printf((JL_STREAM*)STDERR_FILENO, "Internal error: encountered unexpected error in runtime:\n"); + jl_static_show((JL_STREAM*)STDERR_FILENO, e); + jl_printf((JL_STREAM*)STDERR_FILENO, "\n"); + jlbacktrace(); // written to STDERR_FILENO + } src = NULL; } ct->world_age = last_age;