Skip to content

Commit

Permalink
rustc: remove SelfSpace from ParamSpace.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Aug 17, 2016
1 parent 4158673 commit c1cfd58
Show file tree
Hide file tree
Showing 41 changed files with 276 additions and 357 deletions.
5 changes: 2 additions & 3 deletions src/librustc/hir/def.rs
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

use hir::def_id::DefId;
use ty::subst::ParamSpace;
use util::nodemap::NodeMap;
use syntax::ast;
use hir;
Expand All @@ -31,7 +30,7 @@ pub enum Def {
AssociatedTy(DefId /* trait */, DefId),
Trait(DefId),
PrimTy(hir::PrimTy),
TyParam(ParamSpace, u32, DefId, ast::Name),
TyParam(DefId),
Upvar(DefId, // def id of closed over local
ast::NodeId, // node id of closed over local
usize, // index in the freevars list of the closure
Expand Down Expand Up @@ -122,7 +121,7 @@ impl Def {
match *self {
Def::Fn(id) | Def::Mod(id) | Def::ForeignMod(id) | Def::Static(id, _) |
Def::Variant(_, id) | Def::Enum(id) | Def::TyAlias(id) | Def::AssociatedTy(_, id) |
Def::TyParam(_, _, id, _) | Def::Struct(id) | Def::Trait(id) |
Def::TyParam(id) | Def::Struct(id) | Def::Trait(id) |
Def::Method(id) | Def::Const(id) | Def::AssociatedConst(id) |
Def::Local(id, _) | Def::Upvar(id, _, _, _) => {
id
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dead.rs
Expand Up @@ -95,7 +95,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
Def::AssociatedTy(..) | Def::Method(_) | Def::AssociatedConst(_)
if self.tcx.trait_of_item(def.def_id()).is_some() => {
if let Some(substs) = self.tcx.tables.borrow().item_substs.get(&id) {
match substs.substs.types.get(subst::SelfSpace, 0).sty {
match substs.substs.types.get(subst::TypeSpace, 0).sty {
TyEnum(tyid, _) | TyStruct(tyid, _) => {
self.check_def_id(tyid.did)
}
Expand Down
6 changes: 1 addition & 5 deletions src/librustc/traits/coherence.rs
Expand Up @@ -14,7 +14,6 @@ use super::{SelectionContext, Obligation, ObligationCause};

use middle::cstore::LOCAL_CRATE;
use hir::def_id::DefId;
use ty::subst::TypeSpace;
use ty::{self, Ty, TyCtxt};
use infer::{InferCtxt, TypeOrigin};
use syntax_pos::DUMMY_SP;
Expand Down Expand Up @@ -160,12 +159,9 @@ fn orphan_check_trait_ref<'tcx>(tcx: TyCtxt,

// First, create an ordered iterator over all the type parameters to the trait, with the self
// type appearing first.
let input_tys = Some(trait_ref.self_ty());
let input_tys = input_tys.iter().chain(trait_ref.substs.types.get_slice(TypeSpace));

// Find the first input type that either references a type parameter OR
// some local type.
for input_ty in input_tys {
for input_ty in trait_ref.input_types() {
if ty_is_local(tcx, input_ty, infer_is_local) {
debug!("orphan_check_trait_ref: ty_is_local `{:?}`", input_ty);

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/traits/error_reporting.rs
Expand Up @@ -232,8 +232,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
if let Ok(..) = self.can_equate(&trait_self_ty, &impl_self_ty) {
self_match_impls.push(def_id);

if trait_ref.substs.types.get_slice(TypeSpace).iter()
.zip(impl_trait_ref.substs.types.get_slice(TypeSpace))
if trait_ref.substs.types.get_slice(TypeSpace)[1..].iter()
.zip(&impl_trait_ref.substs.types.get_slice(TypeSpace)[1..])
.all(|(u,v)| self.fuzzy_match_tys(u, v))
{
fuzzy_match_impls.push(def_id);
Expand Down
9 changes: 3 additions & 6 deletions src/librustc/traits/object_safety.rs
Expand Up @@ -20,7 +20,7 @@
use super::elaborate_predicates;

use hir::def_id::DefId;
use ty::subst::{self, SelfSpace, TypeSpace};
use ty::subst;
use traits;
use ty::{self, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable};
use std::rc::Rc;
Expand Down Expand Up @@ -146,10 +146,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
match predicate {
ty::Predicate::Trait(ref data) => {
// In the case of a trait predicate, we can skip the "self" type.
data.0.trait_ref.substs.types.get_slice(TypeSpace)
.iter()
.cloned()
.any(|t| t.has_self_ty())
data.0.trait_ref.input_types()[1..].iter().any(|t| t.has_self_ty())
}
ty::Predicate::Projection(..) |
ty::Predicate::WellFormed(..) |
Expand Down Expand Up @@ -325,7 +322,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
ty.maybe_walk(|ty| {
match ty.sty {
ty::TyParam(ref param_ty) => {
if param_ty.space == SelfSpace {
if param_ty.is_self() {
error = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/context.rs
Expand Up @@ -1353,7 +1353,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}

pub fn mk_self_type(self) -> Ty<'tcx> {
self.mk_param(subst::SelfSpace, 0, keywords::SelfType.name())
self.mk_param(subst::TypeSpace, 0, keywords::SelfType.name())
}

pub fn mk_param_from_def(self, def: &ty::TypeParameterDef) -> Ty<'tcx> {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/ty/error.rs
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

use hir::def_id::DefId;
use ty::subst;
use infer::type_variable;
use ty::{self, BoundRegion, Region, Ty, TyCtxt};

Expand Down Expand Up @@ -258,7 +257,7 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> {
ty::TyInfer(ty::FreshFloatTy(_)) => "skolemized floating-point type".to_string(),
ty::TyProjection(_) => "associated type".to_string(),
ty::TyParam(ref p) => {
if p.space == subst::SelfSpace {
if p.is_self() {
"Self".to_string()
} else {
"type parameter".to_string()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/flags.rs
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use ty::subst::{self, Substs};
use ty::subst::Substs;
use ty::{self, Ty, TypeFlags, TypeFoldable};

pub struct FlagComputation {
Expand Down Expand Up @@ -77,7 +77,7 @@ impl FlagComputation {

&ty::TyParam(ref p) => {
self.add_flags(TypeFlags::HAS_LOCAL_NAMES);
if p.space == subst::SelfSpace {
if p.is_self() {
self.add_flags(TypeFlags::HAS_SELF);
} else {
self.add_flags(TypeFlags::HAS_PARAMS);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/mod.rs
Expand Up @@ -1225,7 +1225,7 @@ impl<'tcx> TraitRef<'tcx> {
}

pub fn self_ty(&self) -> Ty<'tcx> {
*self.substs.types.get(subst::SelfSpace, 0)
*self.substs.types.get(subst::TypeSpace, 0)
}

pub fn input_types(&self) -> &[Ty<'tcx>] {
Expand Down
14 changes: 10 additions & 4 deletions src/librustc/ty/sty.rs
Expand Up @@ -305,7 +305,7 @@ pub struct TraitObject<'tcx> {
///
/// This would be represented by a trait-reference where the def-id is the
/// def-id for the trait `Foo` and the substs defines `T` as parameter 0 in the
/// `SelfSpace` and `U` as parameter 0 in the `TypeSpace`.
/// `TypeSpace` and `U` as parameter 1 in the `TypeSpace`.
///
/// Trait references also appear in object types like `Foo<U>`, but in
/// that case the `Self` parameter is absent from the substitutions.
Expand Down Expand Up @@ -512,7 +512,7 @@ impl<'a, 'gcx, 'tcx> ParamTy {
}

pub fn for_self() -> ParamTy {
ParamTy::new(subst::SelfSpace, 0, keywords::SelfType.name())
ParamTy::new(subst::TypeSpace, 0, keywords::SelfType.name())
}

pub fn for_def(def: &ty::TypeParameterDef) -> ParamTy {
Expand All @@ -524,7 +524,13 @@ impl<'a, 'gcx, 'tcx> ParamTy {
}

pub fn is_self(&self) -> bool {
self.space == subst::SelfSpace && self.idx == 0
if self.name == keywords::SelfType.name() {
assert_eq!(self.space, subst::TypeSpace);
assert_eq!(self.idx, 0);
true
} else {
false
}
}
}

Expand Down Expand Up @@ -954,7 +960,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {

pub fn is_self(&self) -> bool {
match self.sty {
TyParam(ref p) => p.space == subst::SelfSpace,
TyParam(ref p) => p.is_self(),
_ => false
}
}
Expand Down

0 comments on commit c1cfd58

Please sign in to comment.