JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.48k stars 5.46k forks source link

REPL hints and tab completion freezes the REPL #55434

Open thofma opened 1 month ago

thofma commented 1 month ago

Sometimes tab completion freezes the REPL. For example, I type

julia> complicated_hard_to_infer_function(f(x) * y, g(x), TAB

and this gives me a frozen REPL for a few minutes, where not even Ctrl-C does something useful. Not a great user experience (in particular the Ctrl-C not responding part).

@MasonProtter provided the following reproducer (my original example is free of @generated):

julia> @generated function foo()
           @info "Compiling foo()"
           sleep(10)
           (;a=1, b=2)
       end;

julia> foo().[ Info: Compiling foo()

This is with julia 1.10.

Can we make the under the hood type inference give up if the result cannot be returned "immediately"? Alternatively, can we make Ctrl-C work?

Edit: It is really bad on 1.11, where this is triggered by the tab completion "hint", so almost always.

Keno commented 1 month ago

Tab completion needs to be moved run on a separate thread. I don't think there are any other good options.

vtjnash commented 1 month ago

Most of inference supports cancellation (except the IRInterp where the implementation is marked broken) via LimitedAccuracy and the dont_work_on_me flag. It could be hooked to timeout after either some amount of delay or on the next keystroke (particularly better with threads so it could keep running though). I have also been working on resumable inference, which maybe completed soon, and could be used as a basis for this in the REPLCompletions

IanButterworth commented 1 month ago

It's probably clear already, but this is even more of an issue on 1.11+ because of tab completion hinting. i.e. on 1.11 I hit this just by typing foo().

julia> foo().[ Info: Compiling foo()
IanButterworth commented 1 month ago

And I don't believe we're likely to make 1.11 start up with multiple threads by default, so I think the only option for 1.11 is to add a timeout? Perhaps a shorter timeout for hinting

IanButterworth commented 1 month ago

so I think the only option for 1.11 is to add a timeout?

@vtjnash @Keno do you think thats the case? I think this needs figuring out, ideally before first release