Skip to content
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

Replace the obligation forest with a graph #33491

Merged
merged 5 commits into from
May 17, 2016

Conversation

arielb1
Copy link
Contributor

@arielb1 arielb1 commented May 8, 2016

In the presence of caching, arbitrary nodes in the obligation forest can be merged, which makes it a general graph. Handle it as such, using cycle-detection algorithms in the processing.

I should do performance measurements sometime.

This was pretty much written as a proof-of-concept. Please help me write this in a less-ugly way. I should also add comments explaining what is going on.

r? @nikomatsakis

@bors
Copy link
Contributor

bors commented May 11, 2016

☔ The latest upstream changes (presumably #33425) made this pull request unmergeable. Please resolve the merge conflicts.

.or_insert(index);
}
self.populated = true;
fn process_backedge<'c, I>(&mut self, cycle: I)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is nice

Copy link
Contributor

Choose a reason for hiding this comment

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

also 'c is unused here

@nikomatsakis
Copy link
Contributor

@arielb1 r=me but travis says:

/home/travis/build/rust-lang/rust/src/librustc/traits/fulfill.rs:541: line longer than 100 chars

@arielb1
Copy link
Contributor Author

arielb1 commented May 13, 2016

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented May 13, 2016

📌 Commit fea78bf has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented May 13, 2016

⌛ Testing commit fea78bf with merge 5e3f3f0...

@bors
Copy link
Contributor

bors commented May 13, 2016

💔 Test failed - auto-linux-64-opt-rustbuild

@arielb1
Copy link
Contributor Author

arielb1 commented May 14, 2016

@bors r-

@arielb1
Copy link
Contributor Author

arielb1 commented May 14, 2016

@nikomatsakis - awaiting review.

let trait_self_ty = tcx.erase_late_bound_regions(&trait_ref).self_ty();

self.tcx.lookup_trait_def(trait_ref.def_id())
.for_each_relevant_impl(self.tcx, trait_self_ty, |def_id| {
Copy link
Contributor

Choose a reason for hiding this comment

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

so, while I do prefer this simplified approach, it seems like it would mean that vec[3_i32] will fail to get the "helpful message" we were shooting for? (I could be confused; I'll kick off a local build and check it out)

Copy link
Contributor Author

@arielb1 arielb1 May 15, 2016

Choose a reason for hiding this comment

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

I'm not sure how the earlier approach worked for that. EDIT: that never worked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

both approaches do not report a helpful error message when a Vec is involved. Unless we are willing to add a "useless" impl Index<usize> for Vec, I don't see how this can be solved.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I just mean slice, then. There is this test: check_on_unimplemented_on_slice.rs which fails.

The fact that this doesn't work for vec (if indeed true) suggests that we may want to tie the hint to the use of the [] syntax rather than having a more generic mechanism, honestly.

I tend to think that the "on unimplemented" mechanism may need some work in any case. For example, I think the hint would be a bit confusing when you have X: Index<u32> and you supply a slice. (I have often found the "on unimplemented" messages from other traits confusing for this reason.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's just my logic being stupid. I have a fix to that.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 16, 2016

📌 Commit 65ad935 has been approved by nikomatsakis

@nikomatsakis
Copy link
Contributor

Ah, it seems only polite to cc @pnkfelix @GuillaumeGomez -- this PR encountered some ICEs centered on the "fuzzy matching" logic used to report errors for index operations, and replaces it with a simpler operation -- basically matching the self-type and looking for exactly one impl that has #[on_error] attached. This still achieves the original end. That said, I sort of think we should revisit the mechanism as a whole, and try to see if we can get something a bit more tailored (and more flexible, I think), so that one can give different messages based not only on the trait/types involved, but on the context (e.g., foo[3] is maybe different from T: Index<usize>, and the right message for the latter probably varies depending on which fn it is attached to).

@GuillaumeGomez
Copy link
Member

But why removing all the code I just added? Did it bother in any way? I'm not sure to understand. :-/ It's far from perfect but very easy to make evolve. Such a disappointment...

@nikomatsakis
Copy link
Contributor

I think the primary motivator was that it was causing ICEs due to getting
some details of higher-ranked regions incorrect, which led to arielb1 also
simplifying the overall heuristics. I guess one question is whether this
version actually triggers all the cases you were interested in?

(I'm still interesting in finding some mechanism that takes into account
more information overall.)

On Mon, May 16, 2016 at 6:25 PM, Guillaume Gomez notifications@github.com
wrote:

But why removing all the code I just added? Did it bother in any way? I'm
not sure to understand. :-/ It's far from perfect but very easy to make
evolve. Such a disappointment...


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#33491 (comment)

@GuillaumeGomez
Copy link
Member

Let's take a simple example:

let v = vec!();

v[2i32];

It's incorrect, but Index trait is implemented on Vec three times: usize, RangeTo, RangeFull. In this case, it is easy to find out that usize is the closest one to i32. However, if we used a struct, RangeTo and RangeFull would have been returned and their "on_rustc_unimplemented" message would have displayed. This is not just to find out that i32 is closer to usize and that's where my incomprehension comes from.

@nikomatsakis
Copy link
Contributor

@GuillaumeGomez right, so is this not the logic covered by check_on_unimplemented_on_slice.rs?

@nikomatsakis
Copy link
Contributor

nikomatsakis commented May 16, 2016

@arielb1 was the fuzzy logic in particular causing any issues, or you were simply concerned that it was overkill for the problem at hand?

@GuillaumeGomez
Copy link
Member

@GuillaumeGomez right, so is this not the logic covered by check_on_unimplemented_on_slice.rs?

No, this PR's algorithm is way too simple. We're going back on this feature.

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented May 16, 2016

I still think that this is the code change that made my code crash but whatever...

@nikomatsakis
Copy link
Contributor

@GuillaumeGomez so, I thought the conclusion from IRC was:

  • land this change (because the rest of this PR is really imp't and we don't want to block it);
  • @arielb1 agreed to add in the "fuzzy type" variant in a follow-up PR, where the extra arguments are converted into their "fuzzy" equivalents -- this should be roughly as expressive as your old logic

@bors
Copy link
Contributor

bors commented May 17, 2016

⌛ Testing commit 65ad935 with merge 786b26d...

bors added a commit that referenced this pull request May 17, 2016
Replace the obligation forest with a graph

In the presence of caching, arbitrary nodes in the obligation forest can be merged, which makes it a general graph. Handle it as such, using cycle-detection algorithms in the processing.

I should do performance measurements sometime.

This was pretty much written as a proof-of-concept. Please help me write this in a less-ugly way. I should also add comments explaining what is going on.

r? @nikomatsakis
@@ -27,12 +27,14 @@ fn f<T>(val: T) {
let t: S<T> = S(marker::PhantomData);
let a = &t as &Gettable<T>;
//~^ ERROR : std::marker::Send` is not satisfied
//~^^ ERROR : std::marker::Copy` is not satisfied
Copy link
Member

Choose a reason for hiding this comment

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

FYI it can be nice to use the "arrow form" here for successive lines, ie //~| ... instead of //~^^ ...

@bors bors merged commit 65ad935 into rust-lang:master May 17, 2016
@@ -247,7 +247,8 @@ pub const tag_rustc_version: usize = 0x10f;
pub fn rustc_version() -> String {
format!(
"rustc {}",
option_env!("CFG_VERSION").unwrap_or("unknown version")
// option_env!("CFG_VERSION").unwrap_or("unknown version")
"nightly edition"
Copy link
Member

Choose a reason for hiding this comment

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

Is this an intentional change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No.

On Tue, May 17, 2016 at 3:34 PM, bluss notifications@github.com wrote:

In src/librustc_metadata/common.rs
#33491 (comment):

@@ -247,7 +247,8 @@ pub const tag_rustc_version: usize = 0x10f;
pub fn rustc_version() -> String {
format!(
"rustc {}",

  •    option_env!("CFG_VERSION").unwrap_or("unknown version")
    
    +// option_env!("CFG_VERSION").unwrap_or("unknown version")
  •    "nightly edition"
    

Is this an intentional change?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/rust-lang/rust/pull/33491/files/65ad935737138eb307fdd01279ba5553a047bb6c#r63513124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants