Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8e373b4

Browse files
authoredNov 30, 2016
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), } ```
2 parents fa0005f + 8b82fd7 commit 8e373b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+896
-904
lines changed
 

‎mk/crates.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \
140140
DEPS_rustc_incremental := rustc syntax_pos serialize rustc_data_structures
141141
DEPS_rustc_save_analysis := rustc log syntax syntax_pos serialize
142142
DEPS_rustc_typeck := rustc syntax syntax_pos rustc_platform_intrinsics rustc_const_math \
143-
rustc_const_eval rustc_errors
143+
rustc_const_eval rustc_errors rustc_data_structures
144144

145145
DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts test \
146146
rustc_lint rustc_const_eval syntax_pos rustc_data_structures

‎src/librustc/infer/freshen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
165165
ty::TyRef(..) |
166166
ty::TyFnDef(..) |
167167
ty::TyFnPtr(_) |
168-
ty::TyTrait(..) |
168+
ty::TyDynamic(..) |
169169
ty::TyClosure(..) |
170170
ty::TyNever |
171171
ty::TyTuple(..) |

0 commit comments

Comments
 (0)
Please sign in to comment.