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

Better error reporting for stack overflow in type inference: Line number of the function being inferred / call site #49237

Closed
NHDaly opened this issue Apr 3, 2023 · 3 comments
Labels
compiler:inference Type inference error messages Better, more actionable error messages

Comments

@NHDaly
Copy link
Member

NHDaly commented Apr 3, 2023

We've seen many errors in prod of the "stack overflow in type inference" variety, and one of the issues is that it's currently not actionable enough.

For example, we recently saw this error:

Internal error: stack overflow in type inference of iterate(Base.Iterators.ProductIterator{Tuple{Base.Set{...}, Base.Set{...}, ...}}
This might be caused by recursion over very long tuples or argument lists.

I truncated the message, but that Tuple{} goes on for a very long time.

However, we currently can't figure out where in our code that is coming from!
It would be helpful to also report two locations, I think:

  1. The source location (file:line) of the dynamic dispatch that caused this type inference invocation
  2. The source location (file:line) of the method being inferred.

In this case, the function being inferred (2.) would be in Base somewhere, so not all that helpful. But maybe sometimes it would be.
But (1.) would be extremely useful, so that we could figure out where this was coming from!

In fact, even better would be to actually dump the stack trace... if that was possible it would be a huge improvement. Thanks!

The exception is reported here:

julia/src/gf.c

Lines 324 to 327 in f32a5c6

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");


Other examples of this exception reported in julia, here:

@Yasser-Brh
Copy link

Subject: Stack Overflow in Type Inference with Julia 1.10.3 - Seeking Solutions

Hello,

I'm currently experiencing a problem with Julia version 1.10.3 on Linux (x86_64). I have encountered an internal error related to stack overflow during type inference. The error message suggests that it might be related to recursion involving very long tuples or argument lists. Here's the specific error:


Internal error: stack overflow in type inference of shouldlog(Logging.ConsoleLogger, Base.CoreLogging.LogLevel, Module, Symbol, Symbol).
This might be caused by recursion over very long tuples or argument lists.
Internal error: encountered unexpected error during compilation of shouldlog:


Although my code does involve some recursion, it is not extensive. I'm wondering if anyone else has experienced similar issues or has insights into potential solutions for this type of problem. Any suggestions on how to handle or debug this error would be greatly appreciated.

Here are some details about my system and Julia installation:

OS: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
Julia Version: 1.10.3
LLVM version: libLLVM-15.0.7

Thank you in advance for any help or guidance you can provide!

@nsajko
Copy link
Contributor

nsajko commented May 10, 2024

@Yasser-Brh ask on the Julia Discourse. Prepare a self-contained reproducing example beforehand.

@nsajko
Copy link
Contributor

nsajko commented Oct 1, 2024

As far as I understand/hope stack overflow in type inference is a thing of the past now after #55575.

@nsajko nsajko closed this as completed Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference error messages Better, more actionable error messages
Projects
None yet
Development

No branches or pull requests

3 participants