Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up[WIP] Add outlives suggestions for some lifetime errors #58281
Conversation
rust-highfive
assigned
estebank
Feb 8, 2019
rust-highfive
added
the
S-waiting-on-review
label
Feb 8, 2019
This comment has been minimized.
This comment has been minimized.
|
cc @lorisdanto |
mark-i-m
force-pushed the
mark-i-m:synthesis
branch
2 times, most recently
from
5e3e44a
to
3614f29
Feb 8, 2019
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
mark-i-m
force-pushed the
mark-i-m:synthesis
branch
from
d47b6b0
to
cfdce52
Feb 8, 2019
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
|
mark-i-m
force-pushed the
mark-i-m:synthesis
branch
from
18af6d4
to
3e4f544
Feb 9, 2019
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Thanks, I did come across that code and started to modify it allow emitting either a counter or a string as the region name. However, I don’t know how to choose a name that isn’t already used in the code.
… On Feb 11, 2019, at 8:04 PM, Esteban Kuber ***@***.***> wrote:
@estebank commented on this pull request.
In src/librustc_mir/borrow_check/nll/region_infer/error_reporting/outlives_suggestion.rs:
> + if let Some(ref mut outlived_frs) = self.constraints_to_add.get_mut(&fr) {
+ outlived_frs.push(outlived_fr);
+ } else {
+ self.constraints_to_add.insert(fr, vec![outlived_fr]);
+ }
+ }
+
+ /// Either get the existing user-define name of the given region or create one.
+ fn lookup_or_create_region_name(
+ &mut self,
+ fr: RegionVid,
+ rinfcx: &RegionInferenceContext<'tcx>,
+ tcx: TyCtxt<'_, '_, 'tcx>,
+ ) {
+ /// All generated names will be of the form `'PREFIXN`, where `N` is a unique integer.
+ const PREFIX: &str = "generatedl";
The NLL code that creates unused names is https://github.com/rust-lang/rust/blob/master/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs, but right now that only uses numbers to refer to unnamed lifetimes. I know that there was other code to create a sequence of named lifetimes that could be copy-pasted into code without being a syntax error (I think it was the g, h, i, j sequence), but don't recall where it was present.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
mark-i-m
force-pushed the
mark-i-m:synthesis
branch
2 times, most recently
from
6f864bc
to
da8e5de
Feb 12, 2019
This comment was marked as outdated.
This comment was marked as outdated.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment was marked as outdated.
This comment was marked as outdated.
|
|
mark-i-m
force-pushed the
mark-i-m:synthesis
branch
from
da8e5de
to
ba0374d
Feb 22, 2019
This comment was marked as outdated.
This comment was marked as outdated.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
So for now, I'm just going to simplify this:
My thought is that this will be a lot easier to implement and still useful. @estebank What do you think? Also do you know how I can check if a lifetime is |
This comment was marked as outdated.
This comment was marked as outdated.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
mark-i-m
reopened this
Feb 26, 2019
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
It makes me a bit sad that it is that hard to add, but I understand. Go ahead and once it is in we can clean it up to be fancier. I'm a strong proponent of worse-now is better that great-tomorrow, particularly when it affects learnability and discoverability of the language.
That should be ok for now, but it's not optimal in the long term. I would expect novices to attempt to use Edit: filed #58786 for the last point. |
This comment has been minimized.
This comment has been minimized.
|
Yes, I agree 100%. My current goal for this PR is for it to put the machinery in place. One technical change I have already come across is that we will need to mildly change the numbering scheme for regions in error messages. Currently, each error will get it's own set of numbered lifetimes (so that |
estebank
reviewed
Feb 27, 2019
|
Just saw that I had these old comments. Publishing just in case, but no need to act on them given that they are all marked as outdated. |
| let new_name = format!("'{}{}", PREFIX, self.new_name_counter); | ||
| debug!("Generate name {} for region {:?}", new_name, fr); | ||
| self.names_to_add.insert(fr, new_name); | ||
| self.new_name_counter += 1; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
mark-i-m
Feb 28, 2019
Author
Contributor
I switched to keeping a per def-id counter so that we get unique names across all errors for the mir def id.
| for (&fr, outlived_frs) in &self.constraints_to_add { | ||
| let mut constraint = String::new(); | ||
|
|
||
| constraint += &format!(" {}: ", self.get_region_name(rinfcx, tcx, fr)); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| name.to_string() | ||
| } else { | ||
| rinfcx | ||
| .give_name_from_error_region(tcx, self.mir_def_id, fr, &mut 0) |
This comment has been minimized.
This comment has been minimized.
estebank
Feb 27, 2019
Contributor
Shouldn't you be storing a map of DefIds to names, or at least DefId to counter? This will always give you the first generated name, but you might have two unnamed regions.
This comment has been minimized.
This comment has been minimized.
mark-i-m
Feb 28, 2019
Author
Contributor
Yes, in my most recent iteration, I am mapping from RegionVid to RegionName. Note that these errors are all within the same MIR def, so they would have the same def id.
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
@estebank I think I have a minimal prototype working. I still need to filter out bad suggestions, such as naming Also, it looks like when I buffer diagnostics they appear as the first diagnostic. Is there a way to make them the last diagnostic? Let me know what you think. |
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
I need to look at it more in depth, but I feel the output would be better if the help were attached to a lifetime error. As for this independent help being emitted last, I think if you append to |
This comment has been minimized.
This comment has been minimized.
@estebank The intent was that we can try to emit one suggestion that solves multiple lifetime errors at the same time. For example, consider the following code: fn foo<'a, 'b, 'c, 'd>(x: &'a usize, y: &'b usize) -> (&'c usize, &'d usize) {
(x, y)
}This would emit two lifetime errors, but we can emit one suggestion with the collected bounds: |
This comment has been minimized.
This comment has been minimized.
|
An update: I have added a field to The next thing that needs to get done is that I need to filter out bad suggestions, e.g. suggesting bounds on closure lifetimes or bounds on |
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
|
TimNN
added
S-waiting-on-author
and removed
S-waiting-on-review
labels
Mar 19, 2019
mark-i-m
force-pushed the
mark-i-m:synthesis
branch
from
8eb2067
to
9083ee9
Mar 30, 2019
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
@estebank update: I think I have an idea for how to get rid of unidiomatic suggestions. I will try to implement and test it soon... not 100% if it will work in all cases, but it seems plausible. I also rebased and squashed the earlier commits to avoid painful rebasing later... |
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
mark-i-m
added some commits
Nov 28, 2018
mark-i-m
force-pushed the
mark-i-m:synthesis
branch
from
4d14f94
to
b204a5c
Apr 1, 2019
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
This comment has been minimized.
This comment has been minimized.
|
@estebank at first glance, it looks like I have removed all of the bad suggestions. I still need to add some tests to explicitly exercise a few cases of the suggestion logic, though. But I think we have gotten far enough that maybe a perf run would be reasonable? |
This comment has been minimized.
This comment has been minimized.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
mark-i-m commentedFeb 8, 2019
•
edited
https://internals.rust-lang.org/t/mechanical-suggestions-for-some-borrow-checker-errors/9049/3
TL;DR Make suggestions to add a
where 'a: 'bconstraint for some lifetime errors. Details are in the paper linked from the internals thread above.r? @estebank
TODO
&'a self'a: 'static, suggest replacing'awith'static'a: 'b, 'b: 'a, suggest replacing'awith'bor vice versa