Skip to content

Could we fix "Stack overflow in type inference" by moving compilation to another Task? #50603

@NHDaly

Description

@NHDaly

There have been several issues reporting Stack overflow during type inference, which can crash a julia process entirely.

Here are a few of them:

One of the most common places this occurs is if we're in a try/catch, and we're trying to handle the exception we've caught, but it turns out that we're right up near the edge of the stack, and the exception we caught is a StackOverflowError, and so then in the catch block when trying to handle it (log it, switch on its type, report it to our users, abort the current operation, etc), we end up hitting a stack overflow during type inference since we're calling code for the first time that hasn't been compiled yet for this specific exception.

But it could also happen during normal julia operation: If you're about to dispatch to a function that would push you over the stack limit, but before you call, you need to compile it, you can hit this error.


It seems like this situation could be solved by having separate Task(s) where we do compilation, and switching over to them when we need to compile something. The benefit would be that we would avoid stack overflows during inference, which really screw up the runtime. The downside is that this task switch would likely make compilation more expensive.

Maybe first we need to work on performance of task switching?

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler:inferenceType inferencedesignDesign of APIs or of the language itselfmultithreadingBase.Threads and related functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions