Skip to content

Commit ab25299

Browse files
committed
remove "partially quantified" methods
1 parent f319d6d commit ab25299

File tree

2 files changed

+20
-89
lines changed

2 files changed

+20
-89
lines changed

chalk-solve/src/goal_builder.rs

Lines changed: 18 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -83,88 +83,31 @@ impl<'i, I: Interner> GoalBuilder<'i, I> {
8383
&mut self,
8484
binders: &Binders<B>,
8585
passthru: P,
86-
body: fn(&mut Self, Substitution<I>, B::Result, P::Result) -> G,
86+
body: fn(&mut Self, Substitution<I>, &B, P::Result) -> G,
8787
) -> Goal<I>
8888
where
8989
B: Fold<I> + HasInterner<Interner = I>,
9090
P: Fold<I>,
9191
B::Result: std::fmt::Debug,
9292
G: CastTo<Goal<I>>,
9393
{
94-
self.partially_quantified(QuantifierKind::ForAll, binders, &[], passthru, body)
94+
self.quantified(QuantifierKind::ForAll, binders, passthru, body)
9595
}
9696

9797
/// Like [`GoalBuilder::forall`], but for a `exists<Q0..Qn> { G }` goal.
9898
pub(crate) fn exists<G, B, P>(
9999
&mut self,
100100
binders: &Binders<B>,
101101
passthru: P,
102-
body: fn(&mut Self, Substitution<I>, B::Result, P::Result) -> G,
102+
body: fn(&mut Self, Substitution<I>, &B, P::Result) -> G,
103103
) -> Goal<I>
104104
where
105105
B: Fold<I> + HasInterner<Interner = I>,
106106
P: Fold<I>,
107107
B::Result: std::fmt::Debug,
108108
G: CastTo<Goal<I>>,
109109
{
110-
self.partially_quantified(QuantifierKind::Exists, binders, &[], passthru, body)
111-
}
112-
113-
/// Like `[GoalBuilder::forall`], except that it also takes
114-
/// a (partial) substitution `S0..Sm` that provides some
115-
/// suffix of the values for the bound value `<P0..Pn> V`.
116-
///
117-
/// The resulting goal will be `forall<Q0..Q(n-m)> { G }`,
118-
/// and the resulting substitution for the bound value `V`
119-
/// will be `[Q0, .., Q(n-m), S0, .., Sm]`.
120-
///
121-
/// This is useful for associated items within traits and impls:
122-
/// the binders on such items contain both the binders from the trait
123-
/// and impl as well as from the associated item itself. Here, the
124-
/// "partial substitution" would be the values from the trait/impl.
125-
pub(crate) fn partially_forall<G, B, P>(
126-
&mut self,
127-
binders: &Binders<B>,
128-
partial_substitution: &Substitution<I>,
129-
passthru: P,
130-
body: fn(&mut Self, Substitution<I>, B::Result, P::Result) -> G,
131-
) -> Goal<I>
132-
where
133-
B: Fold<I> + HasInterner<Interner = I>,
134-
P: Fold<I>,
135-
B::Result: std::fmt::Debug,
136-
G: CastTo<Goal<I>>,
137-
{
138-
self.partially_quantified(
139-
QuantifierKind::ForAll,
140-
binders,
141-
partial_substitution.parameters(self.interner()),
142-
passthru,
143-
body,
144-
)
145-
}
146-
147-
/// Like [`GoalBuilder::partially_forall`], but for a `exists` goal.
148-
pub(crate) fn partially_exists<G, B, P>(
149-
&mut self,
150-
binders: &Binders<B>,
151-
partial_substitution: &Substitution<I>,
152-
passthru: P,
153-
body: fn(&mut Self, Substitution<I>, B::Result, P::Result) -> G,
154-
) -> Goal<I>
155-
where
156-
B: Fold<I> + HasInterner<Interner = I>,
157-
P: Fold<I>,
158-
B::Result: std::fmt::Debug,
159-
G: CastTo<Goal<I>>,
160-
{
161-
self.partially_quantified(
162-
QuantifierKind::Exists,
163-
binders,
164-
partial_substitution.parameters(self.interner()),
165-
passthru,
166-
body,
167-
)
110+
self.quantified(QuantifierKind::Exists, binders, passthru, body)
168111
}
169112

170113
/// A combined helper functon for the various methods
@@ -174,13 +117,12 @@ impl<'i, I: Interner> GoalBuilder<'i, I> {
174117
/// * [`GoalBuilder::partially_forall`]
175118
///
176119
/// for details.
177-
pub(crate) fn partially_quantified<G, B, P>(
120+
pub(crate) fn quantified<G, B, P>(
178121
&mut self,
179122
quantifier_kind: QuantifierKind,
180123
binders: &Binders<B>,
181-
partial_substitution: &[Parameter<I>],
182124
passthru: P,
183-
body: fn(&mut Self, Substitution<I>, B::Result, P::Result) -> G,
125+
body: fn(&mut Self, Substitution<I>, &B, P::Result) -> G,
184126
) -> Goal<I>
185127
where
186128
B: Fold<I> + HasInterner<Interner = I>,
@@ -189,30 +131,19 @@ impl<'i, I: Interner> GoalBuilder<'i, I> {
189131
G: CastTo<Goal<I>>,
190132
{
191133
let interner = self.interner();
192-
assert!(binders.binders.len() >= partial_substitution.len());
193-
let split_point = binders.binders.len() - partial_substitution.len();
194-
let (quantified_binders, _) = binders.binders.split_at(split_point);
195-
let combined_values: Substitution<I> = Substitution::from(
196-
interner,
197-
quantified_binders
198-
.iter()
199-
.zip(0..)
200-
.map(|p| p.to_parameter(interner))
201-
.chain(
202-
// Note that the values from the partial substitution must be shifted
203-
// in by one to account for the new binder we are introducing.
204-
partial_substitution.iter().map(|p| p.shifted_in(interner)),
205-
),
206-
);
207-
let bound_goal = {
208-
let bound_value = binders.substitute(interner, &combined_values);
134+
let bound_goal = binders.map_ref(|bound_value| {
135+
let substitution: Substitution<I> = Substitution::from(
136+
interner,
137+
binders
138+
.binders
139+
.iter()
140+
.zip(0..)
141+
.map(|p| p.to_parameter(interner)),
142+
);
209143
let passthru_shifted = passthru.shifted_in(self.interner());
210-
let result = body(self, combined_values, bound_value, passthru_shifted);
211-
Binders {
212-
binders: quantified_binders.to_vec(),
213-
value: result.cast(self.interner()),
214-
}
215-
};
144+
let result = body(self, substitution, bound_value, passthru_shifted);
145+
result.cast(self.interner())
146+
});
216147
GoalData::Quantified(quantifier_kind, bound_goal).intern(self.interner())
217148
}
218149
}

chalk-solve/src/wf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ fn impl_header_wf_goal<I: Interner>(
300300
let goals = input_types
301301
.into_iter()
302302
.map(|ty| ty.well_formed().cast(interner))
303-
.chain(Some(trait_ref.clone().well_formed().cast(interner)));
303+
.chain(Some((*trait_ref).clone().well_formed().cast(interner)));
304304

305305
gb.all::<_, Goal<I>>(goals)
306306
})
@@ -456,7 +456,7 @@ fn compute_assoc_ty_goal<I: Interner>(
456456
let bound_goals = defn_bounds
457457
.iter()
458458
.cloned()
459-
.flat_map(|qb| qb.into_where_clauses(interner, value_ty.clone()))
459+
.flat_map(|qb| qb.into_where_clauses(interner, (*value_ty).clone()))
460460
.map(|qwc| qwc.into_well_formed_goal(interner))
461461
.casted(interner);
462462

0 commit comments

Comments
 (0)