rustc-dev-guide icon indicating copy to clipboard operation
rustc-dev-guide copied to clipboard

Guide mentions trait evaluation (as part of selection), but does not explain it

Open orium opened this issue 7 years ago • 4 comments

orium avatar Jul 30 '18 18:07 orium

@orium Thanks :) Could you point out where this is? A search for the term "trait evaluation" doesn't seem to bring up results for me.

mark-i-m avatar Aug 20 '18 16:08 mark-i-m

In https://rust-lang-nursery.github.io/rustc-guide/traits/resolution.html#overview:

Selection: Deciding how to resolve a specific obligation. For example, selection might decide that a specific obligation can be resolved by employing an impl which matches the Self type, or by using a parameter bound (e.g. T: Trait). In the case of an impl, selecting one obligation can create nested obligations because of where clauses on the impl itself. It may also require evaluating those nested obligations to resolve ambiguities.

Maybe this "evaluating nested obligations" is the winnowing? In that case it is already covered in https://rust-lang-nursery.github.io/rustc-guide/traits/resolution.html#winnowing-resolving-ambiguities, but it should be made clear that it is referring to winnowing.

orium avatar Aug 20 '18 18:08 orium

I believe it refers to the whole selection process all over again. For example, consider the following:

T: Trait<F>
   where F: Ord

Resolving T: Trait<F> requires resolving the nested obligation F: Ord, which in turn requires F: PartialOrd.

I think winnowing is specifically for getting rid of ambiguities, which is only a part of the process of doing a query.

Does that make sense?

mark-i-m avatar Sep 05 '18 14:09 mark-i-m

I believe it refers to the whole selection process all over again. For example, consider the following:

T: Trait<F>
  where F: Ord

Resolving T: Trait requires resolving the nested obligation F: Ord, which in turn requires F: PartialOrd.

It doesn't seem to be just that. SelectionContext::select() would return F: Ord as a nested obligation and it would be added to the obligation forest.

Trait evaluation seems to be something that tells you that some trait obligation holds for sure, or it never holds, or it might hold, etc:

https://github.com/rust-lang/rust/blob/727eabd68143e968d8826ee29b8ea7792d29fa96/src/librustc/traits/select.rs#L325-L388

As it seems to go recursively through the nested obligations to figure this out. Maybe it is just an optimization to solve traits faster in some cases (when evaluation gives EvaluatedToOk or EvaluatedToErr)?

orium avatar Sep 05 '18 18:09 orium