Repository navigation
Enable MIR-borrowck-only output #46097
Copy link
Copy link
Closed
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone
Description
Currently, if you pass -Zborrowck-mir, we output both the AST output (tagged with (Ast)) and the MIR output (tagged with (Mir)).
Example:
> cd src/test/compile-fail
> rustc -Zborrowck-mir borrowck/borrowck-unary-move.rs
error[E0505]: cannot move out of `x` because it is borrowed (Ast)
--> borrowck/borrowck-unary-move.rs:17:10
|
16 | let y = &*x;
| -- borrow of `*x` occurs here
17 | free(x); //[ast]~ ERROR cannot move out of `x` because it is borrowed
| ^ move out of `x` occurs here
error[E0505]: cannot move out of `x` because it is borrowed (Mir)
--> borrowck/borrowck-unary-move.rs:17:10
|
16 | let y = &*x;
| --- borrow of `(*x)` occurs here
17 | free(x); //[ast]~ ERROR cannot move out of `x` because it is borrowed
| ^ move out of `x` occurs here
error: aborting due to 2 previous errorsI would like to alter the switch to be one where there are three mores:
-Zborrowck=ast -- the default, emits only AST
-Zborrowck=mir -- emits only MIR errors (and doesn't write `(Mir)`)
-Zborrowck=compare -- emits both, like `-Zborrowck-mir` does today.
This will be useful as we progress towards our yearly goal of having a working "demo", since the demo isn't very good if people are seeing the old and new errors. It will also be less annoying for editing the unit tests, since we won't need three copies of each error. And if we want the current output when running by hand, it is still available.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
nikomatsakis commentedon Nov 19, 2017
Mentoring instructions
This is where the
-Zborrowck-mirflag is defined:rust/src/librustc/session/config.rs
Lines 976 to 977 in 5f1c37a
That is part of a macro that ultimately defines the
DebuggingOptsstruct. We could change that line to something like this:This will change from a
borrowck_mir: boolfield to aborrowck: Option<String>field. One problem is that this will also accept nonsense like-Zborrowck=foo. I think what we ought to do is to add an enumBorrowckModecomparable toPrintRequestand the others that exist already:Then we will add a field in the
Optionsstruct by inserting a line around here like this:(The setup here is that there is an
Optionsstruct, which we just edited, which contains adebugging_opts: DebuggingOptsfield that has the "raw" debugging options; thatDebuggingOptsstruct is the one that is auto-generated by the macro above.)Then we can add some code around here that will parse the
debugging_opts.borrowckdata and create aBorrowckModeenum, or else report an error (using a call toearly_errorlike so). Theincrementalfield is sort of roughly the model we want, except that it doesn't report any errors:PathBufOptionsstruct hereOK, once we've done that, we should get a few compilation errors because the field
tcx.sess.opts.debugging_opts.borrowck_mirno longer exists. You can convert those to examine thetcx.sess.opts.borrowck_modefield. I think I would add some methods toBorrowckMode:and so on so that we can convert to
tcx.sess.opts.borrowck_mode.use_ast()or whatever.Finally, we have to make the AST-based borrow checker not execute (or at least not report errors) unless we are in the right mode. It's actually easier to just make it not report errors: this is because the AST-based borrowck is still used for giving "unused mut" warnings, so if we just skip it altogether we'll get a bunch of weird warnings. To make it not report errors, though, we just have to modify the functions in this file, having them check the origin and just do nothing if it is wrong.
nikomatsakis commentedon Nov 19, 2017
Oh, one last thing. We have to edit all the tests! They can be changed from having
-Zborrowck-mirat the top to-Zborrowck=mir, and then removing the extra, duplicate comments from the[mir]revision.est31 commentedon Nov 19, 2017
I want to work on this!
est31 commentedon Nov 19, 2017
@LooMaclin there seems to be a conflict here!
est31 commentedon Nov 19, 2017
Especially, I'm almost done with my PR, the only thing that remains is updating the tests which is a bit time intensive...
LooMaclin commentedon Nov 19, 2017
@est31 no problem. im stop working on that
Auto merge of #46106 - est31:master, r=nikomatsakis