-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
[NLL] extend mir-dump to dump out the values of each region #44872
Comments
@chrisvittal has been working on this. During discussion in WG-compiler-nll, we came up with some nice ideas. For example, the callback ought to be invoked many times, with an argument indicating where in the control-flow graph we are located. I am imagining:
This way we can also dump information about liveness, showing for example what is live on entry to each block, what is considered borrowed, and other information like that. |
I imagine that before/after CFG would be invoked before and after this line, respectively. Before block would be invoked right before this line, which starts the basic block, and the statement callback would be called before this line, which prints a statement and before this line, which prints the terminator. |
…akis Extend mir dump to dump each region Building on #44878, implement the feature discussed in #44872. Through discussions on the WG-nll-gitter, @nikomatsakis and I decided to implement this by extending `dump_mir` and all functions that it calls to take a callback of signature `FnMut(PassWhere, &mut Write) -> io::Result<()>` where `PassWhere` is an enum that represents possible locations that we may want to print out extra data in the process of dumping the MIR. I'm not particularly wedded to the name `PassWhere`, but I felt that simply calling the enum `Where` wasn't the right thing to name it. This work depends strongly on #44878, and should be rebased on the final version of that tree, whatever that may be.
asdasd |
Done. |
Building on #44870, once we have a vector of values, we will want to know what they are. I think the best idea is to include that information in the MIR dump. The MIR pretty-printing code is found in
pretty.rs
.Currently, this is invoked by the "Dump MIR" code found in
dump_mir.rs
. This is part of the MIR pass setup -- basically this visitor gets invoked in between every MIR pass. However, we don't really want to touch this "Dump MIR" code -- this is because it runs in between passes, and the intention with the NLL inference is that the non-lexical lifetime information will be allocated and destroyed by the NLL pass itself, and hence it will be freed by the time this code runs.Instead, what I think we ought to do is invoke the pretty-printer directly from within the NLL pass itself. This is easy enough, we just have to invoke the
dump_mir()
function independently from the pass infrastructure, much like the mir-builder function does. Basically inserting a line like the following right in between line 142 and line 143 in NLL:However, this still won't do anything particularly interesting right now, because it doesn't have access to the region values! So I think we should extend
dump_mir
to take an extra argument, or perhaps a callback, that lets us add extra information into the dump. Let's suppose we take the callback approach. Then we might do something like:and we would modify
dump_mir()
to say something like:this callback
extra_data
would be threaded down to the code that actually does the writing and invoked at the end or something.One minor annoyance I see is that
dump_mir
also iterates over the "promoted" values associated withMir
. These are basically constant expressions that got extracted. We probably don't want to be dumping those. We could add a flag to disable this loop. But I think better yet would be to remove the loop altogether, and move it to this caller here, since I think that is the only one that actually wants this loop. That is, we would tranformat that code from:to something like:
The text was updated successfully, but these errors were encountered: