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

REPL hints and tab completion freezes the REPL #55434

Closed
thofma opened this issue Aug 9, 2024 · 12 comments · Fixed by #57192
Closed

REPL hints and tab completion freezes the REPL #55434

thofma opened this issue Aug 9, 2024 · 12 comments · Fixed by #57192
Labels
bug Indicates an unexpected problem or unintended behavior completions Tab and autocompletion in the repl REPL Julia's REPL (Read Eval Print Loop)
Milestone

Comments

@thofma
Copy link
Contributor

thofma commented Aug 9, 2024

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.

Edit edit: For the fellow victims of this: One can turn it off (on 1.11) by typing the following in the REPL

Base.active_repl.options.hint_tab_completes = false

or putting

atreplinit() do repl
    if VERSION >= v"1.11.0-0"
        repl.options.hint_tab_completes = false
    end
end

in your startup.jl.

@giordano giordano added the REPL Julia's REPL (Read Eval Print Loop) label Aug 9, 2024
@Keno
Copy link
Member

Keno commented Aug 10, 2024

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

@vtjnash
Copy link
Member

vtjnash commented Aug 10, 2024

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
Copy link
Member

IanButterworth commented Aug 12, 2024

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
Copy link
Member

IanButterworth commented Aug 12, 2024

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

@thofma thofma changed the title Tab completion freezes the REPL REPL hints and tab completion freezes the REPL Aug 23, 2024
@IanButterworth
Copy link
Member

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

@IanButterworth IanButterworth added the completions Tab and autocompletion in the repl label Sep 24, 2024
@IanButterworth IanButterworth added the bug Indicates an unexpected problem or unintended behavior label Oct 20, 2024
@exaexa
Copy link
Contributor

exaexa commented Nov 8, 2024

@thofma thanks so much for the workaround!

@IanButterworth IanButterworth added this to the 1.12 milestone Nov 16, 2024
@IanButterworth
Copy link
Member

I'm putting this on the 1.12 milestone as I don't believe it's properly fixable on 1.11

The two non mutually exclusive suggestions are:

@exaexa
Copy link
Contributor

exaexa commented Nov 16, 2024

@IanButterworth defaulting to many threads is a resource hog and interrupting is not stable at all. Can we have a simpler option that does this effectively instead? (perhaps an env variable that disables the autocomplete hint, to prevent unfixable freezes?)

Note: Base.active_repl does not exist at time when startup.jl is executed so that file can't be used as a "global config" for this purpose very easily.

@exaexa
Copy link
Contributor

exaexa commented Nov 16, 2024

(cc @stelmo )

@IanButterworth
Copy link
Member

@exaexa
Copy link
Contributor

exaexa commented Nov 16, 2024

Oh cool. Is that somewhere in docs? (Must have missed it in there)

@newptcai
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior completions Tab and autocompletion in the repl REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants