Skip to content

Add rustc MIR output view#2795

Merged
mattgodbolt merged 2 commits intocompiler-explorer:mainfrom
junlarsen:rustc-mir-output
Jul 24, 2021
Merged

Add rustc MIR output view#2795
mattgodbolt merged 2 commits intocompiler-explorer:mainfrom
junlarsen:rustc-mir-output

Conversation

@junlarsen
Copy link
Copy Markdown
Member

@junlarsen junlarsen commented Jul 20, 2021

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.

image

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

Comment thread lib/base-compiler.js
Comment on lines +575 to +582
const rustcOptions = [
inputFilename,
'-o',
this.getRustMirOutputFilename(inputFilename),
'--emit=mir',
'--crate-type',
'rlib',
];
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/base-compiler.js
Comment on lines +591 to +595
const content = await fs.readFile(mirPath, 'utf-8');
// TODO: process the output
return content.split('\n').map((line) => ({
text: line,
}));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could potentially make a member function named processRustMirOutput to override transformation of the source code?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - that could make sense.

Comment thread lib/compilers/rustc-cg-gcc.js Outdated
constructor(info, env) {
super(info, env);
this.compiler.supportsIrView = false;
this.compiler.supportsRustMirView = false;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? I don't have rustc-cg-gcc locally so I was unable to test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkm may know about this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As expected, it works fine, so you can revert this change :)
Screenshot_2021-07-21 Compiler Explorer

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, re-enabled it. Thank you for checking!

Comment thread views/templates.pug
Comment on lines -92 to +98
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
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on renaming this tab item to LLVM IR to indicate that it's specifically the LLVM IR? This list will probably get crowded with other compilers' IR representations further down the road. @ojeda mentions this in #2565

Copy link
Copy Markdown
Contributor

@ojeda ojeda Jul 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Member

@AbrilRBS AbrilRBS Jul 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to worry about this in a follow up PR: as Rubén's has suggested

@ojeda
Copy link
Copy Markdown
Contributor

ojeda commented Jul 21, 2021

Thanks a lot for working on this!

Copy link
Copy Markdown
Member

@mattgodbolt mattgodbolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks so much!

Comment thread lib/base-compiler.js
Comment on lines +575 to +582
const rustcOptions = [
inputFilename,
'-o',
this.getRustMirOutputFilename(inputFilename),
'--emit=mir',
'--crate-type',
'rlib',
];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/base-compiler.js
const mirPath = this.getRustMirOutputFilename(inputFilename);
if (await fs.exists(mirPath)) {
const content = await fs.readFile(mirPath, 'utf-8');
// TODO: process the output
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What processing is needed?

Comment thread lib/base-compiler.js
Comment on lines +591 to +595
const content = await fs.readFile(mirPath, 'utf-8');
// TODO: process the output
return content.split('\n').map((line) => ({
text: line,
}));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - that could make sense.

Comment thread lib/base-compiler.js
};
}

async generateRustMir(inputFilename) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread views/templates.pug
Comment on lines -92 to +98
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to worry about this in a follow up PR: as Rubén's has suggested

@mattgodbolt mattgodbolt merged commit aa431e1 into compiler-explorer:main Jul 24, 2021
@mattgodbolt
Copy link
Copy Markdown
Member

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...

mattgodbolt pushed a commit that referenced this pull request Aug 2, 2021
* Add Rustc MIR representation view
* Enable MIR view for rust-cg-gcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REQUEST] MIR output for Rust

5 participants