Skip to content

Commit 5f5370f

Browse files
committed
Rename Visit to TypeVisitable
1 parent 9a7feef commit 5f5370f

File tree

16 files changed

+122
-116
lines changed

16 files changed

+122
-116
lines changed

chalk-derive/src/lib.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ enum DeriveKind {
118118
}
119119

120120
decl_derive!([HasInterner, attributes(has_interner)] => derive_has_interner);
121-
decl_derive!([Visit, attributes(has_interner)] => derive_visit);
121+
decl_derive!([TypeVisitable, attributes(has_interner)] => derive_type_visitable);
122122
decl_derive!([SuperVisit, attributes(has_interner)] => derive_super_visit);
123123
decl_derive!([TypeFoldable, attributes(has_interner)] => derive_type_foldable);
124124
decl_derive!([Zip, attributes(has_interner)] => derive_zip);
@@ -136,24 +136,28 @@ fn derive_has_interner(mut s: synstructure::Structure) -> TokenStream {
136136
)
137137
}
138138

139-
/// Derives Visit for structs and enums for which one of the following is true:
139+
/// Derives TypeVisitable for structs and enums for which one of the following is true:
140140
/// - It has a `#[has_interner(TheInterner)]` attribute
141141
/// - There is a single parameter `T: HasInterner` (does not have to be named `T`)
142142
/// - There is a single parameter `I: Interner` (does not have to be named `I`)
143-
fn derive_visit(s: synstructure::Structure) -> TokenStream {
144-
derive_any_visit(s, parse_quote! { Visit }, parse_quote! { visit_with })
143+
fn derive_type_visitable(s: synstructure::Structure) -> TokenStream {
144+
derive_any_type_visitable(
145+
s,
146+
parse_quote! { TypeVisitable },
147+
parse_quote! { visit_with },
148+
)
145149
}
146150

147-
/// Same as Visit, but derives SuperVisit instead
151+
/// Same as TypeVisitable, but derives SuperVisit instead
148152
fn derive_super_visit(s: synstructure::Structure) -> TokenStream {
149-
derive_any_visit(
153+
derive_any_type_visitable(
150154
s,
151155
parse_quote! { SuperVisit },
152156
parse_quote! { super_visit_with },
153157
)
154158
}
155159

156-
fn derive_any_visit(
160+
fn derive_any_type_visitable(
157161
mut s: synstructure::Structure,
158162
trait_name: Ident,
159163
method_name: Ident,
@@ -164,13 +168,13 @@ fn derive_any_visit(
164168

165169
let body = s.each(|bi| {
166170
quote! {
167-
::chalk_ir::try_break!(::chalk_ir::visit::Visit::visit_with(#bi, visitor, outer_binder));
171+
::chalk_ir::try_break!(::chalk_ir::visit::TypeVisitable::visit_with(#bi, visitor, outer_binder));
168172
}
169173
});
170174

171175
if kind == DeriveKind::FromHasInterner {
172176
let param = get_generic_param_name(input).unwrap();
173-
s.add_where_predicate(parse_quote! { #param: ::chalk_ir::visit::Visit<#interner> });
177+
s.add_where_predicate(parse_quote! { #param: ::chalk_ir::visit::TypeVisitable<#interner> });
174178
}
175179

176180
s.add_bounds(synstructure::AddBounds::None);

chalk-engine/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
use std::cmp::min;
5757
use std::usize;
5858

59-
use chalk_derive::{HasInterner, TypeFoldable, Visit};
59+
use chalk_derive::{HasInterner, TypeFoldable, TypeVisitable};
6060
use chalk_ir::interner::Interner;
6161
use chalk_ir::{
6262
AnswerSubst, Canonical, ConstrainedSubst, Constraint, DebruijnIndex, Goal, InEnvironment,
@@ -84,7 +84,7 @@ index_struct! {
8484
}
8585

8686
/// The paper describes these as `A :- D | G`.
87-
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner)]
87+
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)]
8888
pub struct ExClause<I: Interner> {
8989
/// The substitution which, applied to the goal of our table,
9090
/// would yield A.
@@ -168,7 +168,7 @@ impl TimeStamp {
168168
///
169169
/// trying to solve `?T: Foo` would immediately require solving `?T:
170170
/// Sized`, and hence would flounder.
171-
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, Visit)]
171+
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)]
172172
pub struct FlounderedSubgoal<I: Interner> {
173173
/// Literal that floundered.
174174
pub floundered_literal: Literal<I>,
@@ -209,7 +209,7 @@ pub struct CompleteAnswer<I: Interner> {
209209
}
210210

211211
/// Either `A` or `~A`, where `A` is a `Env |- Goal`.
212-
#[derive(Clone, Debug, TypeFoldable, Visit)]
212+
#[derive(Clone, Debug, TypeFoldable, TypeVisitable)]
213213
pub enum Literal<I: Interner> {
214214
// FIXME: pub b/c fold
215215
Positive(InEnvironment<Goal<I>>),

chalk-ir/src/lib.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ extern crate self as chalk_ir;
99
use crate::cast::{Cast, CastTo, Caster};
1010
use crate::fold::shift::Shift;
1111
use crate::fold::{Folder, Subst, TypeFoldable, TypeSuperFoldable};
12-
use crate::visit::{SuperVisit, Visit, VisitExt, Visitor};
13-
use chalk_derive::{HasInterner, SuperVisit, TypeFoldable, Visit, Zip};
12+
use crate::visit::{SuperVisit, TypeVisitable, VisitExt, Visitor};
13+
use chalk_derive::{HasInterner, SuperVisit, TypeFoldable, TypeVisitable, Zip};
1414
use std::marker::PhantomData;
1515
use std::ops::ControlFlow;
1616

@@ -147,7 +147,7 @@ impl Variance {
147147
}
148148
}
149149

150-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner)]
150+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)]
151151
/// The set of assumptions we've made so far, and the current number of
152152
/// universal (forall) quantifiers we're within.
153153
pub struct Environment<I: Interner> {
@@ -197,7 +197,7 @@ impl<I: Interner> Environment<I> {
197197
}
198198

199199
/// A goal with an environment to solve it in.
200-
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, Visit)]
200+
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)]
201201
#[allow(missing_docs)]
202202
pub struct InEnvironment<G: HasInterner> {
203203
pub environment: Environment<G::Interner>,
@@ -1021,7 +1021,7 @@ impl DebruijnIndex {
10211021
/// known. It is referenced within the type using `^1.0`, indicating
10221022
/// a bound type with debruijn index 1 (i.e., skipping through one
10231023
/// level of binder).
1024-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner)]
1024+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)]
10251025
pub struct DynTy<I: Interner> {
10261026
/// The unknown self type.
10271027
pub bounds: Binders<QuantifiedWhereClauses<I>>,
@@ -1084,7 +1084,7 @@ pub struct FnSig<I: Interner> {
10841084
pub variadic: bool,
10851085
}
10861086
/// A wrapper for the substs on a Fn.
1087-
#[derive(Clone, PartialEq, Eq, Hash, HasInterner, TypeFoldable, Visit)]
1087+
#[derive(Clone, PartialEq, Eq, Hash, HasInterner, TypeFoldable, TypeVisitable)]
10881088
pub struct FnSubst<I: Interner>(pub Substitution<I>);
10891089

10901090
impl<I: Interner> Copy for FnSubst<I> where I::InternedSubstitution: Copy {}
@@ -1516,7 +1516,7 @@ impl<I: Interner> GenericArg<I> {
15161516
}
15171517

15181518
/// Generic arguments data.
1519-
#[derive(Clone, PartialEq, Eq, Hash, Visit, TypeFoldable, Zip)]
1519+
#[derive(Clone, PartialEq, Eq, Hash, TypeVisitable, TypeFoldable, Zip)]
15201520
pub enum GenericArgData<I: Interner> {
15211521
/// Type argument
15221522
Ty(Ty<I>),
@@ -1601,7 +1601,7 @@ impl<I: Interner, T> WithKind<I, T> {
16011601
pub type CanonicalVarKind<I: Interner> = WithKind<I, UniverseIndex>;
16021602

16031603
/// An alias, which is a trait indirection such as a projection or opaque type.
1604-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner, Zip)]
1604+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)]
16051605
pub enum AliasTy<I: Interner> {
16061606
/// An associated type projection.
16071607
Projection(ProjectionTy<I>),
@@ -1631,7 +1631,7 @@ impl<I: Interner> AliasTy<I> {
16311631
}
16321632

16331633
/// A projection `<P0 as TraitName<P1..Pn>>::AssocItem<Pn+1..Pm>`.
1634-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner)]
1634+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)]
16351635
pub struct ProjectionTy<I: Interner> {
16361636
/// The id for the associated type member.
16371637
pub associated_ty_id: AssocTypeId<I>,
@@ -1653,7 +1653,7 @@ impl<I: Interner> ProjectionTy<I> {
16531653
}
16541654

16551655
/// An opaque type `opaque type T<..>: Trait = HiddenTy`.
1656-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner)]
1656+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)]
16571657
pub struct OpaqueTy<I: Interner> {
16581658
/// The id for the opaque type.
16591659
pub opaque_ty_id: OpaqueTyId<I>,
@@ -1669,7 +1669,7 @@ impl<I: Interner> Copy for OpaqueTy<I> where I::InternedSubstitution: Copy {}
16691669
/// implements the trait.
16701670
/// - `<P0 as Trait<P1..Pn>>` (e.g. `i32 as Copy`), which casts the type to
16711671
/// that specific trait.
1672-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner)]
1672+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)]
16731673
pub struct TraitRef<I: Interner> {
16741674
/// The trait id.
16751675
pub trait_id: TraitId<I>,
@@ -1706,7 +1706,7 @@ impl<I: Interner> TraitRef<I> {
17061706

17071707
/// Lifetime outlives, which for `'a: 'b`` checks that the lifetime `'a`
17081708
/// is a superset of the value of `'b`.
1709-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner, Zip)]
1709+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)]
17101710
#[allow(missing_docs)]
17111711
pub struct LifetimeOutlives<I: Interner> {
17121712
pub a: Lifetime<I>,
@@ -1717,7 +1717,7 @@ impl<I: Interner> Copy for LifetimeOutlives<I> where I::InternedLifetime: Copy {
17171717

17181718
/// Type outlives, which for `T: 'a` checks that the type `T`
17191719
/// lives at least as long as the lifetime `'a`
1720-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner, Zip)]
1720+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)]
17211721
pub struct TypeOutlives<I: Interner> {
17221722
/// The type which must outlive the given lifetime.
17231723
pub ty: Ty<I>,
@@ -1754,7 +1754,7 @@ where
17541754
}
17551755

17561756
/// Checks whether a type or trait ref is well-formed.
1757-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner, Zip)]
1757+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)]
17581758
pub enum WellFormed<I: Interner> {
17591759
/// A predicate which is true when some trait ref is well-formed.
17601760
/// For example, given the following trait definitions:
@@ -1792,7 +1792,7 @@ where
17921792
}
17931793

17941794
/// Checks whether a type or trait ref can be derived from the contents of the environment.
1795-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner, Zip)]
1795+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)]
17961796
pub enum FromEnv<I: Interner> {
17971797
/// A predicate which enables deriving everything which should be true if we *know* that
17981798
/// some trait ref is well-formed. For example given the above trait definitions, we can use
@@ -1990,7 +1990,7 @@ impl<I: Interner> DomainGoal<I> {
19901990
}
19911991

19921992
/// Equality goal: tries to prove that two values are equal.
1993-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, Zip)]
1993+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, Zip)]
19941994
#[allow(missing_docs)]
19951995
pub struct EqGoal<I: Interner> {
19961996
pub a: GenericArg<I>,
@@ -2000,7 +2000,7 @@ pub struct EqGoal<I: Interner> {
20002000
impl<I: Interner> Copy for EqGoal<I> where I::InternedGenericArg: Copy {}
20012001

20022002
/// Subtype goal: tries to prove that `a` is a subtype of `b`
2003-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, Zip)]
2003+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, Zip)]
20042004
#[allow(missing_docs)]
20052005
pub struct SubtypeGoal<I: Interner> {
20062006
pub a: Ty<I>,
@@ -2013,7 +2013,7 @@ impl<I: Interner> Copy for SubtypeGoal<I> where I::InternedType: Copy {}
20132013
/// type. A projection `T::Foo` normalizes to the type `U` if we can
20142014
/// **match it to an impl** and that impl has a `type Foo = V` where
20152015
/// `U = V`.
2016-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, Zip)]
2016+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, Zip)]
20172017
#[allow(missing_docs)]
20182018
pub struct Normalize<I: Interner> {
20192019
pub alias: AliasTy<I>,
@@ -2028,7 +2028,7 @@ where
20282028
}
20292029

20302030
/// Proves **equality** between an alias and a type.
2031-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, Zip)]
2031+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, Zip)]
20322032
#[allow(missing_docs)]
20332033
pub struct AliasEq<I: Interner> {
20342034
pub alias: AliasTy<I>,
@@ -2291,7 +2291,7 @@ where
22912291
/// Represents one clause of the form `consequence :- conditions` where
22922292
/// `conditions = cond_1 && cond_2 && ...` is the conjunction of the individual
22932293
/// conditions.
2294-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner, Zip)]
2294+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)]
22952295
pub struct ProgramClauseImplication<I: Interner> {
22962296
/// The consequence of the clause, which holds if the conditions holds.
22972297
pub consequence: DomainGoal<I>,
@@ -2571,7 +2571,7 @@ where
25712571
}
25722572
}
25732573

2574-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner, Zip)]
2574+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)]
25752575
/// A general goal; this is the full range of questions you can pose to Chalk.
25762576
pub enum GoalData<I: Interner> {
25772577
/// Introduces a binding at depth 0, shifting other bindings up
@@ -2654,7 +2654,7 @@ pub enum QuantifierKind {
26542654
/// lifetime constraints, instead gathering them up to return with our solution
26552655
/// for later checking. This allows for decoupling between type and region
26562656
/// checking in the compiler.
2657-
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner, Zip)]
2657+
#[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner, Zip)]
26582658
pub enum Constraint<I: Interner> {
26592659
/// Outlives constraint `'a: 'b`, indicating that the value of `'a` must be
26602660
/// a superset of the value of `'b`.
@@ -3037,7 +3037,7 @@ impl<I: Interner> Variances<I> {
30373037
/// substitution stores the values for the query's unknown variables,
30383038
/// and the constraints represents any region constraints that must
30393039
/// additionally be solved.
3040-
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner)]
3040+
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)]
30413041
pub struct ConstrainedSubst<I: Interner> {
30423042
/// The substitution that is being constrained.
30433043
///
@@ -3049,7 +3049,7 @@ pub struct ConstrainedSubst<I: Interner> {
30493049
}
30503050

30513051
/// The resulting substitution after solving a goal.
3052-
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, Visit, HasInterner)]
3052+
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable, HasInterner)]
30533053
pub struct AnswerSubst<I: Interner> {
30543054
/// The substitution result.
30553055
///

chalk-ir/src/visit.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ macro_rules! try_break {
3030
/// such as a `Goal`, and computes a value as a result.
3131
///
3232
///
33-
/// To **apply** a visitor, use the `Visit::visit_with` method, like so
33+
/// To **apply** a visitor, use the `TypeVisitable::visit_with` method, like so
3434
///
3535
/// ```rust,ignore
3636
/// let result = x.visit_with(&mut visitor, 0);
@@ -188,7 +188,7 @@ pub trait Visitor<I: Interner> {
188188

189189
/// Applies the given `visitor` to a value, producing a visited result
190190
/// of type `Visitor::Result`.
191-
pub trait Visit<I: Interner>: Debug {
191+
pub trait TypeVisitable<I: Interner>: Debug {
192192
/// Apply the given visitor `visitor` to `self`; `binders` is the
193193
/// number of binders that are in scope when beginning the
194194
/// visitor. Typically `binders` starts as 0, but is adjusted when
@@ -204,7 +204,7 @@ pub trait Visit<I: Interner>: Debug {
204204
/// For types where "visit" invokes a callback on the `visitor`, the
205205
/// `SuperVisit` trait captures the recursive behavior that visits all
206206
/// the contents of the type.
207-
pub trait SuperVisit<I: Interner>: Visit<I> {
207+
pub trait SuperVisit<I: Interner>: TypeVisitable<I> {
208208
/// Recursively visits the type contents.
209209
fn super_visit_with<B>(
210210
&self,
@@ -216,7 +216,7 @@ pub trait SuperVisit<I: Interner>: Visit<I> {
216216
/// "visiting" a type invokes the `visit_ty` method on the visitor; this
217217
/// usually (in turn) invokes `super_visit_ty` to visit the individual
218218
/// parts.
219-
impl<I: Interner> Visit<I> for Ty<I> {
219+
impl<I: Interner> TypeVisitable<I> for Ty<I> {
220220
fn visit_with<B>(
221221
&self,
222222
visitor: &mut dyn Visitor<I, BreakTy = B>,
@@ -301,7 +301,7 @@ where
301301
}
302302
}
303303

304-
impl<I: Interner> Visit<I> for Lifetime<I> {
304+
impl<I: Interner> TypeVisitable<I> for Lifetime<I> {
305305
fn visit_with<B>(
306306
&self,
307307
visitor: &mut dyn Visitor<I, BreakTy = B>,
@@ -338,7 +338,7 @@ impl<I: Interner> SuperVisit<I> for Lifetime<I> {
338338
}
339339
}
340340

341-
impl<I: Interner> Visit<I> for Const<I> {
341+
impl<I: Interner> TypeVisitable<I> for Const<I> {
342342
fn visit_with<B>(
343343
&self,
344344
visitor: &mut dyn Visitor<I, BreakTy = B>,
@@ -372,7 +372,7 @@ impl<I: Interner> SuperVisit<I> for Const<I> {
372372
}
373373
}
374374

375-
impl<I: Interner> Visit<I> for Goal<I> {
375+
impl<I: Interner> TypeVisitable<I> for Goal<I> {
376376
fn visit_with<B>(
377377
&self,
378378
visitor: &mut dyn Visitor<I, BreakTy = B>,
@@ -393,7 +393,7 @@ impl<I: Interner> SuperVisit<I> for Goal<I> {
393393
}
394394
}
395395

396-
impl<I: Interner> Visit<I> for ProgramClause<I> {
396+
impl<I: Interner> TypeVisitable<I> for ProgramClause<I> {
397397
fn visit_with<B>(
398398
&self,
399399
visitor: &mut dyn Visitor<I, BreakTy = B>,
@@ -403,7 +403,7 @@ impl<I: Interner> Visit<I> for ProgramClause<I> {
403403
}
404404
}
405405

406-
impl<I: Interner> Visit<I> for WhereClause<I> {
406+
impl<I: Interner> TypeVisitable<I> for WhereClause<I> {
407407
fn visit_with<B>(
408408
&self,
409409
visitor: &mut dyn Visitor<I, BreakTy = B>,
@@ -413,7 +413,7 @@ impl<I: Interner> Visit<I> for WhereClause<I> {
413413
}
414414
}
415415

416-
impl<I: Interner> Visit<I> for DomainGoal<I> {
416+
impl<I: Interner> TypeVisitable<I> for DomainGoal<I> {
417417
fn visit_with<B>(
418418
&self,
419419
visitor: &mut dyn Visitor<I, BreakTy = B>,

0 commit comments

Comments
 (0)