Skip to content

Commit a329f5d

Browse files
authored
Merge pull request #320 from detrumi/rename-projection-to-alias
Rename projection to alias
2 parents 010ef6b + 0c89f42 commit a329f5d

File tree

25 files changed

+183
-205
lines changed

25 files changed

+183
-205
lines changed

chalk-integration/src/lowering.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ trait LowerWhereClause<T> {
563563
/// Lower from an AST `where` clause to an internal IR.
564564
/// Some AST `where` clauses can lower to multiple ones, this is why we return a `Vec`.
565565
/// As for now, this is the only the case for `where T: Foo<Item = U>` which lowers to
566-
/// `Implemented(T: Foo)` and `ProjectionEq(<T as Foo>::Item = U)`.
566+
/// `Implemented(T: Foo)` and `AliasEq(<T as Foo>::Item = U)`.
567567
fn lower(&self, env: &Env) -> LowerResult<Vec<T>>;
568568
}
569569

@@ -573,12 +573,12 @@ impl LowerWhereClause<chalk_ir::WhereClause<ChalkIr>> for WhereClause {
573573
WhereClause::Implemented { trait_ref } => {
574574
vec![chalk_ir::WhereClause::Implemented(trait_ref.lower(env)?)]
575575
}
576-
WhereClause::ProjectionEq { projection, ty } => vec![
577-
chalk_ir::WhereClause::ProjectionEq(chalk_ir::ProjectionEq {
578-
projection: projection.lower(env)?,
576+
WhereClause::AliasEq { alias, ty } => vec![
577+
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
578+
alias: alias.lower(env)?,
579579
ty: ty.lower(env)?,
580580
}),
581-
chalk_ir::WhereClause::Implemented(projection.trait_ref.lower(env)?),
581+
chalk_ir::WhereClause::Implemented(alias.trait_ref.lower(env)?),
582582
],
583583
};
584584
Ok(where_clauses)
@@ -602,9 +602,9 @@ impl LowerDomainGoal for DomainGoal {
602602
DomainGoal::Holds { where_clause } => {
603603
where_clause.lower(env)?.into_iter().casted().collect()
604604
}
605-
DomainGoal::Normalize { projection, ty } => {
605+
DomainGoal::Normalize { alias, ty } => {
606606
vec![chalk_ir::DomainGoal::Normalize(chalk_ir::Normalize {
607-
projection: projection.lower(env)?,
607+
alias: alias.lower(env)?,
608608
ty: ty.lower(env)?,
609609
})]
610610
}
@@ -763,12 +763,12 @@ impl LowerTraitBound for TraitBound {
763763
}
764764
}
765765

766-
trait LowerProjectionEqBound {
767-
fn lower(&self, env: &Env) -> LowerResult<rust_ir::ProjectionEqBound<ChalkIr>>;
766+
trait LowerAliasEqBound {
767+
fn lower(&self, env: &Env) -> LowerResult<rust_ir::AliasEqBound<ChalkIr>>;
768768
}
769769

770-
impl LowerProjectionEqBound for ProjectionEqBound {
771-
fn lower(&self, env: &Env) -> LowerResult<rust_ir::ProjectionEqBound<ChalkIr>> {
770+
impl LowerAliasEqBound for AliasEqBound {
771+
fn lower(&self, env: &Env) -> LowerResult<rust_ir::AliasEqBound<ChalkIr>> {
772772
let trait_bound = self.trait_bound.lower(env)?;
773773
let lookup = match env
774774
.associated_ty_lookups
@@ -801,7 +801,7 @@ impl LowerProjectionEqBound for ProjectionEqBound {
801801
}
802802
}
803803

804-
Ok(rust_ir::ProjectionEqBound {
804+
Ok(rust_ir::AliasEqBound {
805805
trait_bound,
806806
associated_ty_id: lookup.id,
807807
parameters: args,
@@ -818,9 +818,7 @@ impl LowerInlineBound for InlineBound {
818818
fn lower(&self, env: &Env) -> LowerResult<rust_ir::InlineBound<ChalkIr>> {
819819
let bound = match self {
820820
InlineBound::TraitBound(b) => rust_ir::InlineBound::TraitBound(b.lower(&env)?),
821-
InlineBound::ProjectionEqBound(b) => {
822-
rust_ir::InlineBound::ProjectionEqBound(b.lower(&env)?)
823-
}
821+
InlineBound::AliasEqBound(b) => rust_ir::InlineBound::AliasEqBound(b.lower(&env)?),
824822
};
825823
Ok(bound)
826824
}
@@ -891,13 +889,13 @@ impl LowerTraitFlags for TraitFlags {
891889
}
892890
}
893891

894-
trait LowerProjectionTy {
895-
fn lower(&self, env: &Env) -> LowerResult<chalk_ir::ProjectionTy<ChalkIr>>;
892+
trait LowerAliasTy {
893+
fn lower(&self, env: &Env) -> LowerResult<chalk_ir::AliasTy<ChalkIr>>;
896894
}
897895

898-
impl LowerProjectionTy for ProjectionTy {
899-
fn lower(&self, env: &Env) -> LowerResult<chalk_ir::ProjectionTy<ChalkIr>> {
900-
let ProjectionTy {
896+
impl LowerAliasTy for AliasTy {
897+
fn lower(&self, env: &Env) -> LowerResult<chalk_ir::AliasTy<ChalkIr>> {
898+
let AliasTy {
901899
ref trait_ref,
902900
ref name,
903901
ref args,
@@ -935,7 +933,7 @@ impl LowerProjectionTy for ProjectionTy {
935933

936934
args.extend(trait_substitution.iter().cloned());
937935

938-
Ok(chalk_ir::ProjectionTy {
936+
Ok(chalk_ir::AliasTy {
939937
associated_ty_id: lookup.id,
940938
substitution: chalk_ir::Substitution::from(args),
941939
})
@@ -1021,9 +1019,7 @@ impl LowerTy for Ty {
10211019
.intern())
10221020
}
10231021

1024-
Ty::Projection { ref proj } => {
1025-
Ok(chalk_ir::TyData::Projection(proj.lower(env)?).intern())
1026-
}
1022+
Ty::Alias { ref alias } => Ok(chalk_ir::TyData::Alias(alias.lower(env)?).intern()),
10271023

10281024
Ty::ForAll {
10291025
ref lifetime_names,

chalk-integration/src/program.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use chalk_ir::debug::Angle;
33
use chalk_ir::family::ChalkIr;
44
use chalk_ir::tls;
55
use chalk_ir::{
6-
AssocTypeId, Identifier, ImplId, Parameter, ProgramClause, ProjectionTy, StructId, TraitId,
7-
TyData, TypeName,
6+
AliasTy, AssocTypeId, Identifier, ImplId, Parameter, ProgramClause, StructId, TraitId, TyData,
7+
TypeName,
88
};
99
use chalk_rust_ir::{
1010
AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId, ImplDatum, ImplType, StructDatum,
@@ -103,12 +103,12 @@ impl tls::DebugContext for Program {
103103
}
104104
}
105105

106-
fn debug_projection(
106+
fn debug_alias(
107107
&self,
108-
projection_ty: &ProjectionTy<ChalkIr>,
108+
alias_ty: &AliasTy<ChalkIr>,
109109
fmt: &mut fmt::Formatter<'_>,
110110
) -> Result<(), fmt::Error> {
111-
let (associated_ty_data, trait_params, other_params) = self.split_projection(projection_ty);
111+
let (associated_ty_data, trait_params, other_params) = self.split_projection(alias_ty);
112112
write!(
113113
fmt,
114114
"<{:?} as {:?}{:?}>::{}{:?}",

chalk-ir/src/cast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ impl<TF: TypeFamily> CastTo<WhereClause<TF>> for TraitRef<TF> {
8686
}
8787
}
8888

89-
impl<TF: TypeFamily> CastTo<WhereClause<TF>> for ProjectionEq<TF> {
89+
impl<TF: TypeFamily> CastTo<WhereClause<TF>> for AliasEq<TF> {
9090
fn cast_to(self) -> WhereClause<TF> {
91-
WhereClause::ProjectionEq(self)
91+
WhereClause::AliasEq(self)
9292
}
9393
}
9494

@@ -151,9 +151,9 @@ impl<TF: TypeFamily> CastTo<TyData<TF>> for ApplicationTy<TF> {
151151
}
152152
}
153153

154-
impl<TF: TypeFamily> CastTo<TyData<TF>> for ProjectionTy<TF> {
154+
impl<TF: TypeFamily> CastTo<TyData<TF>> for AliasTy<TF> {
155155
fn cast_to(self) -> TyData<TF> {
156-
TyData::Projection(self)
156+
TyData::Alias(self)
157157
}
158158
}
159159

chalk-ir/src/debug.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<TF: TypeFamily> Debug for TyData<TF> {
6161
TyData::Dyn(clauses) => write!(fmt, "{:?}", clauses),
6262
TyData::InferenceVar(var) => write!(fmt, "{:?}", var),
6363
TyData::Apply(apply) => write!(fmt, "{:?}", apply),
64-
TyData::Projection(proj) => write!(fmt, "{:?}", proj),
64+
TyData::Alias(alias) => write!(fmt, "{:?}", alias),
6565
TyData::Placeholder(index) => write!(fmt, "{:?}", index),
6666
TyData::Function(function) => write!(fmt, "{:?}", function),
6767
}
@@ -166,9 +166,9 @@ impl<TF: TypeFamily> Debug for SeparatorTraitRef<'_, TF> {
166166
}
167167
}
168168

169-
impl<TF: TypeFamily> Debug for ProjectionTy<TF> {
169+
impl<TF: TypeFamily> Debug for AliasTy<TF> {
170170
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
171-
TF::debug_projection(self, fmt).unwrap_or_else(|| {
171+
TF::debug_alias(self, fmt).unwrap_or_else(|| {
172172
write!(
173173
fmt,
174174
"({:?}){:?}",
@@ -200,21 +200,21 @@ impl<'a, T: Debug> Debug for Angle<'a, T> {
200200

201201
impl<TF: TypeFamily> Debug for Normalize<TF> {
202202
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
203-
write!(fmt, "Normalize({:?} -> {:?})", self.projection, self.ty)
203+
write!(fmt, "Normalize({:?} -> {:?})", self.alias, self.ty)
204204
}
205205
}
206206

207-
impl<TF: TypeFamily> Debug for ProjectionEq<TF> {
207+
impl<TF: TypeFamily> Debug for AliasEq<TF> {
208208
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
209-
write!(fmt, "ProjectionEq({:?} = {:?})", self.projection, self.ty)
209+
write!(fmt, "AliasEq({:?} = {:?})", self.alias, self.ty)
210210
}
211211
}
212212

213213
impl<TF: TypeFamily> Debug for WhereClause<TF> {
214214
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
215215
match self {
216216
WhereClause::Implemented(tr) => write!(fmt, "Implemented({:?})", tr.with_colon()),
217-
WhereClause::ProjectionEq(p) => write!(fmt, "{:?}", p),
217+
WhereClause::AliasEq(a) => write!(fmt, "{:?}", a),
218218
}
219219
}
220220
}

chalk-ir/src/family.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::tls;
2+
use crate::AliasTy;
23
use crate::AssocTypeId;
34
use crate::GoalData;
45
use crate::LifetimeData;
56
use crate::Parameter;
67
use crate::ParameterData;
7-
use crate::ProjectionTy;
88
use crate::RawId;
99
use crate::StructId;
1010
use crate::TraitId;
@@ -111,17 +111,14 @@ pub trait TypeFamily: Debug + Copy + Eq + Ord + Hash {
111111
fmt: &mut fmt::Formatter<'_>,
112112
) -> Option<fmt::Result>;
113113

114-
/// Prints the debug representation of a projection. To get good
114+
/// Prints the debug representation of an alias. To get good
115115
/// results, this requires inspecting TLS, and is difficult to
116116
/// code without reference to a specific type-family (and hence
117117
/// fully known types).
118118
///
119119
/// Returns `None` to fallback to the default debug output (e.g.,
120120
/// if no info about current program is available from TLS).
121-
fn debug_projection(
122-
projection: &ProjectionTy<Self>,
123-
fmt: &mut fmt::Formatter<'_>,
124-
) -> Option<fmt::Result>;
121+
fn debug_alias(alias: &AliasTy<Self>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result>;
125122

126123
/// Create an "interned" type from `ty`. This is not normally
127124
/// invoked directly; instead, you invoke `TyData::intern` (which
@@ -225,11 +222,8 @@ impl TypeFamily for ChalkIr {
225222
tls::with_current_program(|prog| Some(prog?.debug_assoc_type_id(id, fmt)))
226223
}
227224

228-
fn debug_projection(
229-
projection: &ProjectionTy<ChalkIr>,
230-
fmt: &mut fmt::Formatter<'_>,
231-
) -> Option<fmt::Result> {
232-
tls::with_current_program(|prog| Some(prog?.debug_projection(projection, fmt)))
225+
fn debug_alias(alias: &AliasTy<ChalkIr>, fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
226+
tls::with_current_program(|prog| Some(prog?.debug_alias(alias, fmt)))
233227
}
234228

235229
fn intern_ty(ty: TyData<ChalkIr>) -> Arc<TyData<ChalkIr>> {

chalk-ir/src/fold.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,7 @@ where
321321
TyData::InferenceVar(var) => folder.fold_inference_ty(*var, binders),
322322
TyData::Apply(apply) => Ok(TyData::Apply(apply.fold_with(folder, binders)?).intern()),
323323
TyData::Placeholder(ui) => Ok(folder.fold_free_placeholder_ty(*ui, binders)?),
324-
TyData::Projection(proj) => {
325-
Ok(TyData::Projection(proj.fold_with(folder, binders)?).intern())
326-
}
324+
TyData::Alias(alias) => Ok(TyData::Alias(alias.fold_with(folder, binders)?).intern()),
327325
TyData::Function(fun) => Ok(TyData::Function(fun.fold_with(folder, binders)?).intern()),
328326
}
329327
}

chalk-ir/src/lib.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ impl<TF: TypeFamily> Ty<TF> {
216216
}
217217
}
218218

219-
pub fn is_projection(&self) -> bool {
219+
pub fn is_alias(&self) -> bool {
220220
match self.data() {
221-
TyData::Projection(..) => true,
221+
TyData::Alias(..) => true,
222222
_ => false,
223223
}
224224
}
@@ -255,10 +255,11 @@ pub enum TyData<TF: TypeFamily> {
255255
/// binders here.
256256
Dyn(DynTy<TF>),
257257

258-
/// A "projection" type corresponds to an (unnormalized)
259-
/// projection like `<P0 as Trait<P1..Pn>>::Foo`. Note that the
260-
/// trait and all its parameters are fully known.
261-
Projection(ProjectionTy<TF>),
258+
/// An "alias" type represents some form of type alias, such as:
259+
/// - An associated type projection like `<T as Iterator>::Item`
260+
/// - `impl Trait` types
261+
/// - Named type aliases like `type Foo<X> = Vec<X>`
262+
Alias(AliasTy<TF>),
262263

263264
/// A function type such as `for<'a> fn(&'a u32)`.
264265
/// Note that "higher-ranked" types (starting with `for<>`) are either
@@ -569,12 +570,12 @@ impl<TF: TypeFamily> ParameterData<TF> {
569570
}
570571

571572
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Fold, HasTypeFamily)]
572-
pub struct ProjectionTy<TF: TypeFamily> {
573+
pub struct AliasTy<TF: TypeFamily> {
573574
pub associated_ty_id: AssocTypeId<TF>,
574575
pub substitution: Substitution<TF>,
575576
}
576577

577-
impl<TF: TypeFamily> ProjectionTy<TF> {
578+
impl<TF: TypeFamily> AliasTy<TF> {
578579
pub fn intern(self) -> Ty<TF> {
579580
Ty::new(self)
580581
}
@@ -608,7 +609,7 @@ impl<TF: TypeFamily> TraitRef<TF> {
608609
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Fold, HasTypeFamily)]
609610
pub enum WhereClause<TF: TypeFamily> {
610611
Implemented(TraitRef<TF>),
611-
ProjectionEq(ProjectionEq<TF>),
612+
AliasEq(AliasEq<TF>),
612613
}
613614

614615
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Fold, HasTypeFamily)]
@@ -741,7 +742,7 @@ pub type QuantifiedWhereClause<TF> = Binders<WhereClause<TF>>;
741742
impl<TF: TypeFamily> WhereClause<TF> {
742743
/// Turn a where clause into the WF version of it i.e.:
743744
/// * `Implemented(T: Trait)` maps to `WellFormed(T: Trait)`
744-
/// * `ProjectionEq(<T as Trait>::Item = Foo)` maps to `WellFormed(<T as Trait>::Item = Foo)`
745+
/// * `AliasEq(<T as Trait>::Item = Foo)` maps to `WellFormed(<T as Trait>::Item = Foo)`
745746
/// * any other clause maps to itself
746747
pub fn into_well_formed_goal(self) -> DomainGoal<TF> {
747748
match self {
@@ -794,26 +795,26 @@ pub struct EqGoal<TF: TypeFamily> {
794795
pub b: Parameter<TF>,
795796
}
796797

797-
/// Proves that the given projection **normalizes** to the given
798+
/// Proves that the given type alias **normalizes** to the given
798799
/// type. A projection `T::Foo` normalizes to the type `U` if we can
799800
/// **match it to an impl** and that impl has a `type Foo = V` where
800801
/// `U = V`.
801802
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Fold)]
802803
pub struct Normalize<TF: TypeFamily> {
803-
pub projection: ProjectionTy<TF>,
804+
pub alias: AliasTy<TF>,
804805
pub ty: Ty<TF>,
805806
}
806807

807808
/// Proves **equality** between a projection `T::Foo` and a type
808809
/// `U`. Equality can be proven via normalization, but we can also
809810
/// prove that `T::Foo = V::Foo` if `T = V` without normalizing.
810811
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Fold)]
811-
pub struct ProjectionEq<TF: TypeFamily> {
812-
pub projection: ProjectionTy<TF>,
812+
pub struct AliasEq<TF: TypeFamily> {
813+
pub alias: AliasTy<TF>,
813814
pub ty: Ty<TF>,
814815
}
815816

816-
impl<TF: TypeFamily> HasTypeFamily for ProjectionEq<TF> {
817+
impl<TF: TypeFamily> HasTypeFamily for AliasEq<TF> {
817818
type TypeFamily = TF;
818819
}
819820

chalk-ir/src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ macro_rules! ty {
2323
}).intern()
2424
};
2525

26-
(projection (item $n:tt) $($arg:tt)*) => {
27-
$crate::TyData::Projection(ProjectionTy {
26+
(alias (item $n:tt) $($arg:tt)*) => {
27+
$crate::TyData::Alias(AliasTy {
2828
associated_ty_id: AssocTypeId(RawId { index: $n }),
2929
substitution: $crate::Substitution::from(vec![$(arg!($arg)),*] as Vec<$crate::Parameter<_>>),
3030
}).intern()

chalk-ir/src/tls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::family::ChalkIr;
2-
use crate::{AssocTypeId, ProjectionTy, StructId, TraitId};
2+
use crate::{AliasTy, AssocTypeId, StructId, TraitId};
33
use std::cell::RefCell;
44
use std::fmt;
55
use std::sync::Arc;
@@ -27,9 +27,9 @@ pub trait DebugContext {
2727
fmt: &mut fmt::Formatter,
2828
) -> Result<(), fmt::Error>;
2929

30-
fn debug_projection(
30+
fn debug_alias(
3131
&self,
32-
projection: &ProjectionTy<ChalkIr>,
32+
alias: &AliasTy<ChalkIr>,
3333
fmt: &mut fmt::Formatter,
3434
) -> Result<(), fmt::Error>;
3535
}

0 commit comments

Comments
 (0)