Skip to content

Commit 2e9fba5

Browse files
committed
---
yaml --- r: 273151 b: refs/heads/beta c: c1df41e h: refs/heads/master i: 273149: bc41291 273147: 176cccd 273143: 4e21196 273135: d67c8f6 273119: 574c651 273087: ae15197 273023: 7395535 272895: 0f5cbc5
1 parent bb9b3d5 commit 2e9fba5

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: ed8d059d8d49491b736ea88edd8f2b57a866c44a
26+
refs/heads/beta: c1df41e776c5a65ce8345d34a7e22296a99abd5e
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc/middle/traits/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,3 +428,43 @@ We used to try and draw finer-grained distinctions, but that led to a
428428
serious of annoying and weird bugs like #22019 and #18290. This simple
429429
rule seems to be pretty clearly safe and also still retains a very
430430
high hit rate (~95% when compiling rustc).
431+
432+
# Specialization
433+
434+
Defined in the `specialize` module.
435+
436+
The basic strategy is to build up a *specialization graph* during
437+
coherence checking. Insertion into the graph locates the right place
438+
to put an impl in the specialization hierarchy; if there is no right
439+
place (due to partial overlap but no containment), you get an overlap
440+
error. Specialization is consulted when selecting an impl (of course),
441+
and the graph is consulted when propagating defaults down the
442+
specialization hierarchy.
443+
444+
You might expect that the specialization graph would be used during
445+
selection -- i.e., when actually performing specialization. This is
446+
not done for two reasons:
447+
448+
- It's merely an optimization: given a set of candidates that apply,
449+
we can determine the most specialized one by comparing them directly
450+
for specialization, rather than consulting the graph. Given that we
451+
also cache the results of selection, the benefit of this
452+
optimization is questionable.
453+
454+
- To build the specialization graph in the first place, we need to use
455+
selection (because we need to determine whether one impl specializes
456+
another). Dealing with this reentrancy would require some additional
457+
mode switch for selection. Given that there seems to be no strong
458+
reason to use the graph anyway, we stick with a simpler approach in
459+
selection, and use the graph only for propagating default
460+
implementations.
461+
462+
Trait impl selection can succeed even when multiple impls can apply,
463+
as long as they are part of the same specialization family. In that
464+
case, it returns a *single* impl on success -- this is the most
465+
specialized impl *known* to apply. However, if there are any inference
466+
variables in play, the returned impl may not be the actual impl we
467+
will use at trans time. Thus, we take special care to avoid projecting
468+
associated types unless either (1) the associated type does not use
469+
`default` and thus cannot be overridden or (2) all input types are
470+
known concretely.

branches/beta/src/librustc/middle/traits/specialize.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
//
1414
// At the moment, this implementation support only the simple "chain" rule:
1515
// If any two impls overlap, one must be a strict subset of the other.
16+
//
17+
// See traits/README.md for a bit more detail on how specialization
18+
// fits together with the rest of the trait machinery.
1619

1720
use super::util;
1821
use super::SelectionContext;

0 commit comments

Comments
 (0)