Add rustc MIR output view#2795
Add rustc MIR output view#2795mattgodbolt merged 2 commits intocompiler-explorer:mainfrom junlarsen:rustc-mir-output
Conversation
| const rustcOptions = [ | ||
| inputFilename, | ||
| '-o', | ||
| this.getRustMirOutputFilename(inputFilename), | ||
| '--emit=mir', | ||
| '--crate-type', | ||
| 'rlib', | ||
| ]; |
There was a problem hiding this comment.
We might want to have some way to change these options? I don't know if other compiler options change the MIR so I hard coded them for now.
There was a problem hiding this comment.
Got it; I think this is OK for now! So long as if/when we add ways to change it, these are the defaults, so older URLs still work the same way.
| const content = await fs.readFile(mirPath, 'utf-8'); | ||
| // TODO: process the output | ||
| return content.split('\n').map((line) => ({ | ||
| text: line, | ||
| })); |
There was a problem hiding this comment.
Could potentially make a member function named processRustMirOutput to override transformation of the source code?
There was a problem hiding this comment.
Right - that could make sense.
| constructor(info, env) { | ||
| super(info, env); | ||
| this.compiler.supportsIrView = false; | ||
| this.compiler.supportsRustMirView = false; |
There was a problem hiding this comment.
Does this work? I don't have rustc-cg-gcc locally so I was unable to test.
There was a problem hiding this comment.
I should try it, but I don't see why it would not work, this "compiler" is only changing the backend, so MIR output should work correctly. I'll try this now and let you know!
There was a problem hiding this comment.
Okay, re-enabled it. Thank you for checking!
| button.dropdown-item.btn.btn-sm.btn-light.view-ir(title="Show IR output") | ||
| button.dropdown-item.btn.btn-sm.btn-light.view-ir(title="Show LLVM IR output") | ||
| span.dropdown-icon.fas.fa-align-center | ||
| | IR output | ||
| | LLVM IR output |
There was a problem hiding this comment.
I think being explicit is usually a positive -- and it is not too much text, so I guess it does not take too much space, no?
There was a problem hiding this comment.
Nearly all items in this dropdown menu are compiler specific. I remember mentioning this to @RubenRBS with the idea of hiding items not compatible with currently selected compiler but there was something against it. The same renaming should be done to AST (llvm), optim output (llvm) and graph output (gcc).
There was a problem hiding this comment.
So! My initial idea was to add subdropdowns or categorize the panes better, but that's more trouble than it's worth.
I thought it would be a bit tricky to add compatibility checks for all panes for every compiler, but we already do it! That's how we know when to disable to button itself, so the initial idea of hiding the buttons altoghether sounds good now.
So, what we can do is to merge this, and find a way to only show the supported panes instead of disabling them (Might not be as easy as substituting .prop('disabled', ...) by .toggle(...), but I might also be wrong)
There was a problem hiding this comment.
I'm happy to worry about this in a follow up PR: as Rubén's has suggested
|
Thanks a lot for working on this! |
| const rustcOptions = [ | ||
| inputFilename, | ||
| '-o', | ||
| this.getRustMirOutputFilename(inputFilename), | ||
| '--emit=mir', | ||
| '--crate-type', | ||
| 'rlib', | ||
| ]; |
There was a problem hiding this comment.
Got it; I think this is OK for now! So long as if/when we add ways to change it, these are the defaults, so older URLs still work the same way.
| const mirPath = this.getRustMirOutputFilename(inputFilename); | ||
| if (await fs.exists(mirPath)) { | ||
| const content = await fs.readFile(mirPath, 'utf-8'); | ||
| // TODO: process the output |
| const content = await fs.readFile(mirPath, 'utf-8'); | ||
| // TODO: process the output | ||
| return content.split('\n').map((line) => ({ | ||
| text: line, | ||
| })); |
There was a problem hiding this comment.
Right - that could make sense.
| }; | ||
| } | ||
|
|
||
| async generateRustMir(inputFilename) { |
There was a problem hiding this comment.
It's a bit unfortunate we have to put this in base-compiler, but then the alternative is to have a complex hierarchy of things... I think this is fine for now: we'll think about breaking this up another time.
| button.dropdown-item.btn.btn-sm.btn-light.view-ir(title="Show IR output") | ||
| button.dropdown-item.btn.btn-sm.btn-light.view-ir(title="Show LLVM IR output") | ||
| span.dropdown-icon.fas.fa-align-center | ||
| | IR output | ||
| | LLVM IR output |
There was a problem hiding this comment.
I'm happy to worry about this in a follow up PR: as Rubén's has suggested
|
This is live! Thanks again @supergrecko and ... re: tests...we are in a sorry state for this kind of front end testing, so - there aren't any so far. Me clicking about randomly in the staging before we deploy is the very poor setup... |
* Add Rustc MIR representation view * Enable MIR view for rust-cg-gcc

Adds a new pane and processor for generating and showing Rust's MIR. This is my first time hacking on the front end. Let me know if there's anything that's missing.
I do not have any tests for this at the moment. I would appreciate some help in how to set up testing for this.
Fixes #2566
/cc @ojeda