-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
implement a proper REPL #9898
Comments
not sure why this (seemingly) isn't in higher demand. I would love to have a REPL. |
This would be very nice. When developing scala, I really enjoy trying out language features in the REPL. It does not have to be perfect. |
Posting comments on an issue saying you want it fixed isn't going to make it happen any faster. It just decreases the signal to noise ratio on the bug tracker. |
Would it be a good idea to implement this using the existing lexer/parser? I've had a look at mod.rs in libsyntax/parse and it seems to me that it wouldn't be too hard to build something that reads tokens from stdin and emitting tokens as they arrive. Actually, looking at driver.rs (librustc/driver/driver.rs) it looks like this is sort of already possible at a higher level through compile_input, though perhaps that doesn't provide quite the flexibility you'd want in a REPL - not sure. I'd love to play around with this some (provided I can find the time), but I'd really appreciate if some of the more experienced devs would chime in and warn me off if it's a terrible idea or if there are other plans on how this should be done. Any other hints or suggestions would of course also be highly appreciated. |
Could we make use of lli to interpret/JIT LLVM bitcode? |
There's no point in shelling out to a command-line utility when it can be done with the same library functions |
+1 for ease of adoption. I've learned most languages with the help of an interpreter (python, C#, JS, Haskell all have good ones). |
I too agree with alexchandel, is there any work being done on this? |
I also like to see the missing bindings for LLVMs |
Yes, ExecutionEngine seems to be needed. Are there any plans to implement full LLVM bindings in rust? |
Implementing a REPL is a complex project, and exposing / using MCJIT is a trivial piece of that puzzle. There's no point of getting side tracked on that issue here. |
This issue is a feature request, and needs an approved RFC to be implemented (*). It should be moved to the rust-lang/rfcs repo. (As per the issues policy) cc @nick29581 (*) I think it makes sense to develop the REPL out of tree (it would still be able to link to librustc, libsyntax or whatever is needed), if it needs more rustc internals/llvm bindings exposed, those bits can be requested via RFCs. (Note that I've no experience writing REPLs/compilers (the closest thing I've worked with are syntax extensions!) so I could be speaking nosense) |
I do not think this warrants an RFC because it is not a change to the language or the standard libraries. I am personally OK with keeping |
Yeah, RFCs are only for language features or far-reaching changes to the libs. Leaving here. |
One option for implementing a REPL that I find interesting would be to implement an IPython Kernel for Rust, which would allow you to make use of not only the terminal based frontend, but also other existing IPython (or Jupyter) frontends like the notebook, QT console, or emacs notebook. |
👍 would be a huge gain for the language! |
I'm not yet familiar with |
MCJIT just allows machine code to be directly generated and run without a temporary file. It's not the right way to get started on this. The hard part is the logic of the REPL itself, and it could just start off by outputting an object file with MCJIT usage added as an unimportant refinement later. |
Oh. I thought MCJIT might have been a part of managing persistent memory state of the execution environment. I guess I'm not exactly sure what it does and doesn't do yet. |
MCJIT allows you to generate the machine code for functions in-memory and then call into them. It would be the basis of a solid REPL but it is really only an optimization. |
The same thing can be accomplished by progressively generating object files in a temporary directory and linking them together repeatedly. I think it would be easier to build the REPL around the existing backend and then switch over to MCJIT as an optimization, but of course the person implementing it can do it however they want. |
You're probably right about MCJIT. I'm looking exclusively at
(Also, if this isn't the place to discuss implementation, I'll gladly take it elsewhere.) |
Status update (in case anyone is interested):
|
Good job @murarth! Really looking forward to see this! |
Sounds promising, @murarth! Can we use |
@murarth: where is your repo with code? I would like to look at it and may be join you in working on it, if you need any help. |
@hastebrot: Some C++ wrapper code in @jauhien: I don't have any public code right now. I want to get to a point of minimal working functionality before publishing anything, so it doesn't look like it's broken. |
Sounds great! Really looking forward to this. Eventually, one thing I'd like to have in Rust is some sort of interface that we can build fancier editor modes and tools on top of, where the REPL would be a part of that. I'm thinking something llike what the Idris folks have done with the emacs-mode. They provide an interface (editor agnostic) with some commands which hook into parts of the compiler to provide some very cool functionality. Would it be within the scope of this project to support such functionality? If not, would it be possible to re-use some of what you're putting together now for something like that? |
The above mentioned problems still exist, but I have made a public release with basic functionality. |
Very nice, thanks! For reference, the PR that brings LLVM's |
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized. This issue has been moved to the RFCs repo: rust-lang/rfcs#655 |
It shouldn't re-compile and re-run the entire input so far with each new addition, and should be able to recover from a compilation error or failure. This should likely be implemented in a separate repository until it's solid and has a working test suite.
A good basis for the design would be the cling REPL for C++ built on top of libclang using LLVM's JIT compiler.
The text was updated successfully, but these errors were encountered: