-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
allow a function instead of a string as Prompt.prompt #22809
Conversation
base/repl/LineEdit.jl
Outdated
prompt_string(s::AbstractString) = s | ||
prompt_string(f::Function) = eval(Expr(:call, f)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why isn't this f()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
World errors I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
invokelatest then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I had world errors, so I did as in #19924. I'd rather keep it as is to be consistent with other such eval
s in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the evals were added here before invokelatest was implemented, that should be the canonical way of doing this now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok done
Looks like there are a couple of tests in |
OK, will see if I can add some tests. |
6101609
to
3e8dd35
Compare
3e8dd35
to
ed523b5
Compare
I would like to merge this soon (if no objection of course), as this shouldn't be breaking and seems harmless. |
freebsd test freeze might be related? @iblis17 can you reproduce locally? |
I'm running testing locally; will be back after 8 hrs... |
@tkelman The |
@ararslan might also be able to take a look? |
Checking out this branch, building, then running
I get all tests passing with no freezes. Laptop natively running FreeBSD 11.0-RELEASE-p11. |
Seems freezing occurs randomly. I ran 3 additional 8 core on my machine, and the latest output message in each frozen run is channels (3) | 14.01 | 1.10 | 7.8 | 347.42 | 0.81
misc (6) | 48.05 | 2.33 | 4.8 | 1514.21 | 0.67
libgit2 (7) | 67.62 | 0.71 | 1.1 | 452.90 | 1.21
ranges (4) | 92.71 | 4.86 | 5.2 | 7165.24 | 0.71
examples (9) | 27.80 | 0.38 | 1.4 | 614.00 | 0.80
distributed (8) | 113.42 | 0.02 | 0.0 | 20.62 | 0.56
cmdlineargs (2) | 142.23 | 0.31 | 0.2 | 71.36 | 0.55
^C
signal (2): Interrupt
while loading /usr/home/iblis/git/julia/test/runtests.jl, in expression starting on line 29
__sys_kevent at /lib/libc.so.7 (unknown line)
__thr_kevent at /usr/src/lib/libthr/thread/thr_syscalls.c:382
uv__io_poll at /usr/home/iblis/git/julia/deps/srccache/libuv-52d72a52cc7ccd570929990f010ed16e2ec604c8/
src/unix/kqueue.c:160
uv_run at /usr/home/iblis/git/julia/deps/srccache/libuv-52d72a52cc7ccd570929990f010ed16e2ec604c8/src/u
nix/core.c:354
process_events at ./libuv.jl:82 [inlined]
wait at ./event.jl:216
wait at ./event.jl:27
jlcall_wait_19639 at /usr/home/iblis/git/julia/usr/lib/julia/sys.so (unknown line)
wait at ./task.jl:181
jlcall_wait_19633 at /usr/home/iblis/git/julia/usr/lib/julia/sys.so (unknown line)
sync_end at ./task.jl:274
macro expansion at ./task.jl:303 [inlined]
#40 at /usr/home/iblis/git/julia/test/runtests.jl:49
cd at ./file.jl:70
unknown function (ip: 0x80229ac73)
do_call at /usr/home/iblis/git/julia/src/interpreter.c:66
eval at /usr/home/iblis/git/julia/src/interpreter.c:246
eval_body at /usr/home/iblis/git/julia/src/interpreter.c:544
jl_interpret_toplevel_thunk at /usr/home/iblis/git/julia/src/interpreter.c:697
jl_toplevel_eval_flex at /usr/home/iblis/git/julia/src/toplevel.c:597
jl_parse_eval_all at /usr/home/iblis/git/julia/src/ast.c:908
jl_load at /usr/home/iblis/git/julia/src/toplevel.c:620 [inlined]
jl_load_ at /usr/home/iblis/git/julia/src/toplevel.c:627
include_from_node1 at ./loading.jl:556
jlcall_include_from_node1_18748 at /usr/home/iblis/git/julia/usr/lib/julia/sys.so (unknown line)
include at ./sysimg.jl:14
jlcall_include_18691 at /usr/home/iblis/git/julia/usr/lib/julia/sys.so (unknown line)
process_options at ./client.jl:315
_start at ./client.jl:383
jlcall__start_18926 at /usr/home/iblis/git/julia/usr/lib/julia/sys.so (unknown line)
jl_stderr_obj at /usr/home/iblis/git/julia/usr/bin/julia (unknown line)
jl_stderr_obj at /usr/home/iblis/git/julia/usr/bin/julia (unknown line)
jl_stderr_obj at /usr/home/iblis/git/julia/usr/bin/julia (unknown line)
unknown function (ip: 0x800624fff)
unknown function (ip: 0xffffffffffffffff)
Allocations: 2349656 (Pool: 2348919; Big: 737); GC: 5
WARNING: ErrorException
atexit hook threw an error: ErrorException("schedule: Task not runnable")gmake[1]: *** [Makefile: 18: all] Error 130 Second frozen run: ...
WARNING: OutOfMemoryError
atexit hook threw an error: OutOfMemoryError()gmake[1]: *** [Makefile:18: all] Error 130
gmake: *** [Makefile:562: testall] Interrupt |
No it's not cmdlineargs, it finishes, it's whatever haven't run. |
Yes, cmdlineargs finishes. It's the latest output message before freezing. Any suspicious tests? I can try to repeated run them... |
You can compare the list of things that passed to the list of tests in test/choosetests.jl and see what didn't get executed. |
ok, I found a way to reproduce the freezing: ./julia test/runtests.jl repl examples Test (Worker) | Time (s) | GC (s) | GC % | Alloc (MB) | RSS (MB)
From worker 2: ERROR (unhandled task failure): write: broken pipe (EPIPE)
From worker 2: Stacktrace:
From worker 2: [1] try_yieldto at ./event.jl:189 [inlined]
From worker 2: [2] wait() at ./event.jl:234
From worker 2: [3] uv_write(::Base.PipeEndpoint, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:811
From worker 2: [4] unsafe_write(::Base.PipeEndpoint, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:832
From worker 2: [5] write(::Base.PipeEndpoint, ::String) at ./strings/string.jl:71
From worker 2: [6] enable_bracketed_paste(::TestHelpers.FakeTerminal) at ./repl/Terminals.jl:142
From worker 2: [7] prompt!(::TestHelpers.FakeTerminal, ::Base.LineEdit.ModalInterface, ::Base.LineEdit.MIState) at ./repl/LineEdit.jl:1608
From worker 2: [8] run_interface(::TestHelpers.FakeTerminal, ::Base.LineEdit.ModalInterface) at ./repl/LineEdit.jl:1580
From worker 2: [9] (::Test75Main_repl.##25#29)() at ./task.jl:335
examples (3) | 23.83 | 0.23 | 1.0 | 625.27 | 0.19 (This command works fine on master build -- Edit: reformatting the error message |
@iblis17 thanks so much, I will investigate. |
I removed the test which was seeming to cause the broken pipe error; to be honest, I don't really understand why the error (if I unroll manually the for-loop in this test, it seems to work, but it's also a kind of heisenbug I think), but I didn't really understand what the test was testing either (just wanted to check that it works with a function); but it was not caused by having a function instead of a string for prompt (AFAICT), but rather by being repeated twice in a raw. Thanks for your time all and sorry for the confusion. |
I will merge in a couple of days if no objection. |
Since #22809 a function can be used as the prompt, but the indentation of non-prompt lines was still determined by the first value of the prompt (usually "julia> "). Now, the indentation by is determined by the currently printed prompt, which can vary from one keypress to the next.
Since #22809 a function can be used as the prompt, but the indentation of non-prompt lines was still determined by the first value of the prompt (usually "julia> "). Now, the indentation is determined by the currently printed prompt, which can vary from one keypress to the next.
Since #22809 a function can be used as the prompt, but the indentation of non-prompt lines was still determined by the first value of the prompt (usually "julia> "). Now, the indentation is determined by the currently printed prompt, which can vary from one keypress to the next.
Cool! Is it documented how to use it? |
Not yet, I plan to document more some REPL changes by the next release, but some things are still in flux... basically you can just do what you wrote in #20692, except you replace the string by a thunk returning a string, e.g.
This is definitely too user-unfriendly to have to call |
I had this as an old branch, but since I know now of a way to change the repl from ".juliarc.jl", I'm more motivated to merge it. This allows to have a dynamic string for the prompt. On a daily basis, I would have for example this function called from ".juliarc.jl":
Then a sample julia session:
PS: I'm really not very familiar with REPL code, so I may have got something wrong.