rust/src/librustc_metadata
bors 8e373b4787 Auto merge of #37965 - Mark-Simulacrum:trait-obj-to-exis-predicate, r=eddyb
Refactor TraitObject to Slice<ExistentialPredicate>

For reference, the primary types changes in this PR are shown below. They may add in the understanding of what is discussed below, though they should not be required.

We change `TraitObject` into a list of `ExistentialPredicate`s to allow for a couple of things:
 - Principal (ExistentialPredicate::Trait) is now optional.
 - Region bounds are moved out of `TraitObject` into `TyDynamic`. This permits wrapping only the `ExistentialPredicate` list in `Binder`.
 - `BuiltinBounds` and `BuiltinBound` are removed entirely from the codebase, to permit future non-constrained auto traits. These are replaced with `ExistentialPredicate::AutoTrait`, which only requires a `DefId`. For the time being, only `Send` and `Sync` are supported; this constraint can be lifted in a future pull request.
 - Binder-related logic is extracted from `ExistentialPredicate` into the parent (`Binder<Slice<EP>>`), so `PolyX`s are inside `TraitObject` are replaced with `X`.

The code requires a sorting order for `ExistentialPredicate`s in the interned `Slice`. The sort order is asserted to be correct during interning, but the slices are not sorted at that point.

1. `ExistentialPredicate::Trait` are defined as always equal; **This may be wrong; should we be comparing them and sorting them in some way?**
1. `ExistentialPredicate::Projection`: Compared by `ExistentialProjection::sort_key`.
1. `ExistentialPredicate::AutoTrait`: Compared by `TraitDef.def_path_hash`.

Construction of `ExistentialPredicate`s is conducted through `TyCtxt::mk_existential_predicates`, which interns a passed iterator as a `Slice`. There are no convenience functions to construct from a set of separate iterators; callers must pass an iterator chain. The lack of convenience functions is primarily due to few uses and the relative difficulty in defining a nice API due to optional parts and difficulty in recognizing which argument goes where. It is also true that the current situation isn't significantly better than 4 arguments to a constructor function; but the extra work is deemed unnecessary as of this time.

```rust
// before this PR
struct TraitObject<'tcx> {
    pub principal: PolyExistentialTraitRef<'tcx>,
    pub region_bound: &'tcx ty::Region,
    pub builtin_bounds: BuiltinBounds,
    pub projection_bounds: Vec<PolyExistentialProjection<'tcx>>,
}

// after
pub enum ExistentialPredicate<'tcx> {
    // e.g. Iterator
    Trait(ExistentialTraitRef<'tcx>),
    // e.g. Iterator::Item = T
    Projection(ExistentialProjection<'tcx>),
    // e.g. Send
    AutoTrait(DefId),
}
```
2016-11-29 20:41:38 -06:00
..
astencode.rs revamp Visitor with a single method for controlling nested visits 2016-11-29 13:04:27 +01:00
Cargo.toml
creader.rs Avoid loading needless proc-macro dependencies. 2016-11-28 03:37:02 +00:00
cstore_impl.rs Save bodies of functions for inlining into other crates 2016-11-29 13:04:27 +01:00
cstore.rs Avoid loading needless proc-macro dependencies. 2016-11-28 03:37:02 +00:00
decoder.rs Auto merge of #37965 - Mark-Simulacrum:trait-obj-to-exis-predicate, r=eddyb 2016-11-29 20:41:38 -06:00
diagnostics.rs Fix error explanation formatting 2016-11-26 21:20:20 +03:00
encoder.rs revamp Visitor with a single method for controlling nested visits 2016-11-29 13:04:27 +01:00
index_builder.rs Improve macro reexports. 2016-11-10 10:04:24 +00:00
index.rs
lib.rs Stabilize .. in tuple (struct) patterns 2016-11-03 01:38:15 +03:00
locator.rs Delay error reporting of filename mismatch. 2016-11-24 22:26:35 +00:00
schema.rs rustc_metadata: don't break the version check when CrateRoot changes. 2016-11-22 14:51:55 +02:00