Skip to content

Commit 8c3ba0f

Browse files
committed
Add self param to parameter_data
1 parent 4291e16 commit 8c3ba0f

File tree

18 files changed

+117
-87
lines changed

18 files changed

+117
-87
lines changed

chalk-integration/src/lowering.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ impl LowerTraitRef for TraitRef {
732732
.lower(env)?;
733733

734734
let self_parameter = self.args[0].lower(env)?;
735-
Ok(without_self.as_trait_ref(interner, self_parameter.assert_ty_ref().clone()))
735+
Ok(without_self.as_trait_ref(interner, self_parameter.assert_ty_ref(interner).clone()))
736736
}
737737
}
738738

@@ -1389,8 +1389,10 @@ impl<T, L> Kinded for chalk_ir::ParameterKind<T, L> {
13891389
}
13901390
}
13911391

1392+
#[allow(unreachable_code, unused_variables)]
13921393
impl Kinded for chalk_ir::Parameter<ChalkIr> {
13931394
fn kind(&self) -> Kind {
1394-
self.data().kind()
1395+
let interner = unimplemented!();
1396+
self.data(interner).kind()
13951397
}
13961398
}

chalk-integration/src/program.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl RustIrDatabase<ChalkIr> for Program {
216216
self.impl_data.values().any(|impl_datum| {
217217
let impl_trait_ref = &impl_datum.binders.value.trait_ref;
218218
impl_trait_ref.trait_id == auto_trait_id
219-
&& match impl_trait_ref.self_type_parameter().data(interner) {
219+
&& match impl_trait_ref.self_type_parameter(interner).data(interner) {
220220
TyData::Apply(apply) => match apply.name {
221221
TypeName::Struct(id) => id == struct_id,
222222
_ => false,

chalk-ir/src/debug.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,11 @@ impl<T: Debug, L: Debug> Debug for ParameterKind<T, L> {
386386
}
387387
}
388388

389+
#[allow(unreachable_code, unused_variables)]
389390
impl<I: Interner> Debug for Parameter<I> {
390391
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
391-
match self.data() {
392+
let interner = unimplemented!();
393+
match self.data(interner) {
392394
ParameterKind::Ty(n) => write!(fmt, "{:?}", n),
393395
ParameterKind::Lifetime(n) => write!(fmt, "{:?}", n),
394396
}

chalk-ir/src/fold/boring_impls.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,11 @@ impl<I: Interner, TI: TargetInterner<I>> Fold<I, TI> for Parameter<I> {
122122
I: 'i,
123123
TI: 'i,
124124
{
125-
let data = self.data().fold_with(folder, binders)?;
126-
Ok(Parameter::new(folder.target_interner(), data))
125+
let interner = folder.interner();
126+
let target_interner = folder.target_interner();
127+
128+
let data = self.data(interner).fold_with(folder, binders)?;
129+
Ok(Parameter::new(target_interner, data))
127130
}
128131
}
129132

chalk-ir/src/fold/subst.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,27 @@ impl<'i, I: Interner> Folder<'i, I> for Subst<'_, 'i, I> {
2929
}
3030

3131
fn fold_free_var_ty(&mut self, depth: usize, binders: usize) -> Fallible<Ty<I>> {
32+
let interner = self.interner();
3233
if depth >= self.parameters.len() {
33-
Ok(
34-
TyData::<I>::BoundVar(depth - self.parameters.len() + binders)
35-
.intern(self.interner()),
36-
)
34+
Ok(TyData::<I>::BoundVar(depth - self.parameters.len() + binders).intern(interner))
3735
} else {
38-
match self.parameters[depth].data() {
39-
ParameterKind::Ty(t) => Ok(t.shifted_in(self.interner(), binders)),
36+
match self.parameters[depth].data(interner) {
37+
ParameterKind::Ty(t) => Ok(t.shifted_in(interner, binders)),
4038
_ => panic!("mismatched kinds in substitution"),
4139
}
4240
}
4341
}
4442

4543
fn fold_free_var_lifetime(&mut self, depth: usize, binders: usize) -> Fallible<Lifetime<I>> {
44+
let interner = self.interner();
4645
if depth >= self.parameters.len() {
4746
Ok(
4847
LifetimeData::<I>::BoundVar(depth - self.parameters.len() + binders)
49-
.intern(self.interner()),
48+
.intern(interner),
5049
)
5150
} else {
52-
match self.parameters[depth].data() {
53-
ParameterKind::Lifetime(l) => Ok(l.shifted_in(self.interner(), binders)),
51+
match self.parameters[depth].data(interner) {
52+
ParameterKind::Lifetime(l) => Ok(l.shifted_in(interner, binders)),
5453
_ => panic!("mismatched kinds in substitution"),
5554
}
5655
}

chalk-ir/src/interner.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
179179
fn intern_parameter(&self, data: ParameterData<Self>) -> Self::InternedParameter;
180180

181181
/// Lookup the `LifetimeData` that was interned to create a `InternedLifetime`.
182-
fn parameter_data(lifetime: &Self::InternedParameter) -> &ParameterData<Self>;
182+
fn parameter_data<'a>(&self, lifetime: &'a Self::InternedParameter) -> &'a ParameterData<Self>;
183183

184184
/// Create an "interned" goal from `data`. This is not
185185
/// normally invoked directly; instead, you invoke
@@ -330,7 +330,10 @@ mod default {
330330
parameter
331331
}
332332

333-
fn parameter_data(parameter: &ParameterData<ChalkIr>) -> &ParameterData<ChalkIr> {
333+
fn parameter_data<'a>(
334+
&self,
335+
parameter: &'a ParameterData<ChalkIr>,
336+
) -> &'a ParameterData<ChalkIr> {
334337
parameter
335338
}
336339

chalk-ir/src/lib.rs

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -416,16 +416,19 @@ impl<I: Interner> ApplicationTy<I> {
416416
Ty::new(interner, self)
417417
}
418418

419-
pub fn type_parameters<'a>(&'a self) -> impl Iterator<Item = Ty<I>> + 'a {
420-
self.substitution.iter().filter_map(|p| p.ty()).cloned()
419+
pub fn type_parameters<'a>(&'a self, interner: &'a I) -> impl Iterator<Item = Ty<I>> + 'a {
420+
self.substitution
421+
.iter()
422+
.filter_map(move |p| p.ty(interner))
423+
.cloned()
421424
}
422425

423-
pub fn first_type_parameter(&self) -> Option<Ty<I>> {
424-
self.type_parameters().next()
426+
pub fn first_type_parameter(&self, interner: &I) -> Option<Ty<I>> {
427+
self.type_parameters(interner).next()
425428
}
426429

427-
pub fn len_type_parameters(&self) -> usize {
428-
self.type_parameters().count()
430+
pub fn len_type_parameters(&self, interner: &I) -> usize {
431+
self.type_parameters(interner).count()
429432
}
430433
}
431434

@@ -511,41 +514,41 @@ impl<I: Interner> Parameter<I> {
511514
Parameter(interned)
512515
}
513516

514-
pub fn data(&self) -> &ParameterData<I> {
515-
I::parameter_data(&self.0)
517+
pub fn data(&self, interner: &I) -> &ParameterData<I> {
518+
I::parameter_data(interner, &self.0)
516519
}
517520

518-
pub fn assert_ty_ref(&self) -> &Ty<I> {
519-
self.as_ref().ty().unwrap()
521+
pub fn assert_ty_ref(&self, interner: &I) -> &Ty<I> {
522+
self.as_ref(interner).ty().unwrap()
520523
}
521524

522-
pub fn assert_lifetime_ref(&self) -> &Lifetime<I> {
523-
self.as_ref().lifetime().unwrap()
525+
pub fn assert_lifetime_ref(&self, interner: &I) -> &Lifetime<I> {
526+
self.as_ref(interner).lifetime().unwrap()
524527
}
525528

526-
pub fn as_ref(&self) -> ParameterKind<&Ty<I>, &Lifetime<I>> {
527-
match self.data() {
529+
pub fn as_ref(&self, interner: &I) -> ParameterKind<&Ty<I>, &Lifetime<I>> {
530+
match self.data(interner) {
528531
ParameterKind::Ty(t) => ParameterKind::Ty(t),
529532
ParameterKind::Lifetime(l) => ParameterKind::Lifetime(l),
530533
}
531534
}
532535

533-
pub fn is_ty(&self) -> bool {
534-
match self.data() {
536+
pub fn is_ty(&self, interner: &I) -> bool {
537+
match self.data(interner) {
535538
ParameterKind::Ty(_) => true,
536539
ParameterKind::Lifetime(_) => false,
537540
}
538541
}
539542

540-
pub fn ty(&self) -> Option<&Ty<I>> {
541-
match self.data() {
543+
pub fn ty(&self, interner: &I) -> Option<&Ty<I>> {
544+
match self.data(interner) {
542545
ParameterKind::Ty(t) => Some(t),
543546
_ => None,
544547
}
545548
}
546549

547-
pub fn lifetime(&self) -> Option<&Lifetime<I>> {
548-
match self.data() {
550+
pub fn lifetime(&self, interner: &I) -> Option<&Lifetime<I>> {
551+
match self.data(interner) {
549552
ParameterKind::Lifetime(t) => Some(t),
550553
_ => None,
551554
}
@@ -580,12 +583,15 @@ pub struct TraitRef<I: Interner> {
580583
}
581584

582585
impl<I: Interner> TraitRef<I> {
583-
pub fn type_parameters<'a>(&'a self) -> impl Iterator<Item = Ty<I>> + 'a {
584-
self.substitution.iter().filter_map(|p| p.ty()).cloned()
586+
pub fn type_parameters<'a>(&'a self, interner: &'a I) -> impl Iterator<Item = Ty<I>> + 'a {
587+
self.substitution
588+
.iter()
589+
.filter_map(move |p| p.ty(interner))
590+
.cloned()
585591
}
586592

587-
pub fn self_type_parameter(&self) -> Ty<I> {
588-
self.type_parameters().next().unwrap()
593+
pub fn self_type_parameter(&self, interner: &I) -> Ty<I> {
594+
self.type_parameters(interner).next().unwrap()
589595
}
590596

591597
pub fn from_env(self) -> FromEnv<I> {
@@ -1297,7 +1303,7 @@ impl<I: Interner> Substitution<I> {
12971303
pub fn is_identity_subst(&self, interner: &I) -> bool {
12981304
self.iter()
12991305
.zip(0..)
1300-
.all(|(parameter, index)| match parameter.data() {
1306+
.all(|(parameter, index)| match parameter.data(interner) {
13011307
ParameterKind::Ty(ty) => match ty.data(interner) {
13021308
TyData::BoundVar(depth) => index == *depth,
13031309
_ => false,
@@ -1392,15 +1398,17 @@ impl<'i, I: Interner> Folder<'i, I> for &SubstFolder<'i, I> {
13921398
}
13931399

13941400
fn fold_free_var_ty(&mut self, depth: usize, binders: usize) -> Fallible<Ty<I>> {
1401+
let interner = self.interner();
13951402
let ty = self.at(depth);
1396-
let ty = ty.assert_ty_ref();
1397-
Ok(ty.shifted_in(self.interner(), binders))
1403+
let ty = ty.assert_ty_ref(interner);
1404+
Ok(ty.shifted_in(interner, binders))
13981405
}
13991406

14001407
fn fold_free_var_lifetime(&mut self, depth: usize, binders: usize) -> Fallible<Lifetime<I>> {
1408+
let interner = self.interner();
14011409
let l = self.at(depth);
1402-
let l = l.assert_lifetime_ref();
1403-
Ok(l.shifted_in(self.interner(), binders))
1410+
let l = l.assert_lifetime_ref(interner);
1411+
Ok(l.shifted_in(interner, binders))
14041412
}
14051413

14061414
fn interner(&self) -> &'i I {

chalk-ir/src/zip.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,10 @@ impl<T: Zip<I>, L: Zip<I>, I: Interner> Zip<I> for ParameterKind<T, L> {
320320
}
321321
}
322322

323+
#[allow(unreachable_code, unused_variables)]
323324
impl<I: Interner> Zip<I> for Parameter<I> {
324325
fn zip_with<Z: Zipper<I>>(zipper: &mut Z, a: &Self, b: &Self) -> Fallible<()> {
325-
Zip::zip_with(zipper, a.data(), b.data())
326+
let interner = unimplemented!();
327+
Zip::zip_with(zipper, a.data(interner), b.data(interner))
326328
}
327329
}

chalk-solve/src/clauses.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ fn program_clauses_that_could_match<I: Interner>(
160160
// the automatic impls for `Foo`.
161161
let trait_datum = db.trait_datum(trait_id);
162162
if trait_datum.is_auto_trait() {
163-
match trait_ref.self_type_parameter().data(interner) {
163+
match trait_ref.self_type_parameter(interner).data(interner) {
164164
TyData::Apply(apply) => {
165165
if let Some(struct_id) = db.as_struct_id(&apply.name) {
166166
push_auto_trait_impls(builder, trait_id, struct_id);
@@ -214,7 +214,7 @@ fn program_clauses_that_could_match<I: Interner>(
214214
// generated two clauses that are totally irrelevant to
215215
// that goal, because they let us prove other things but
216216
// not `Clone`.
217-
let self_ty = trait_ref.self_type_parameter();
217+
let self_ty = trait_ref.self_type_parameter(interner);
218218
if let TyData::Dyn(dyn_ty) = self_ty.data(interner) {
219219
// In this arm, `self_ty` is the `dyn Fn(&u8)`,
220220
// and `bounded_ty` is the `exists<T> { .. }`
@@ -350,7 +350,7 @@ fn match_ty<I: Interner>(
350350
TyData::Function(quantified_ty) => quantified_ty
351351
.parameters
352352
.iter()
353-
.map(|p| p.assert_ty_ref())
353+
.map(|p| p.assert_ty_ref(interner))
354354
.for_each(|ty| match_ty(builder, environment, &ty)),
355355
TyData::BoundVar(_) => {}
356356
TyData::InferenceVar(_) => panic!("should have floundered"),

chalk-solve/src/clauses/builder.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,18 @@ impl<'me, I: Interner> ClauseBuilder<'me, I> {
8686
where
8787
V: Fold<I> + HasInterner<Interner = I>,
8888
{
89+
let interner = self.interner();
8990
let old_len = self.binders.len();
9091
self.binders.extend(binders.binders.clone());
9192
let params: Vec<_> = binders
9293
.binders
9394
.iter()
9495
.zip(old_len..)
95-
.map(|p| p.to_parameter(self.interner()))
96+
.map(|p| p.to_parameter(interner))
9697
.collect();
9798
self.parameters.extend(params);
9899

99-
let value = binders.substitute(self.interner(), &self.parameters[old_len..]);
100+
let value = binders.substitute(interner, &self.parameters[old_len..]);
100101
op(self, value);
101102

102103
self.binders.truncate(old_len);
@@ -110,6 +111,7 @@ impl<'me, I: Interner> ClauseBuilder<'me, I> {
110111
/// argument.
111112
#[allow(dead_code)]
112113
pub fn push_bound_ty(&mut self, op: impl FnOnce(&mut Self, Ty<I>)) {
114+
let interner = self.interner();
113115
let binders = Binders {
114116
binders: vec![ParameterKind::Ty(())],
115117
value: PhantomData::<I>,
@@ -119,7 +121,7 @@ impl<'me, I: Interner> ClauseBuilder<'me, I> {
119121
.placeholders_in_scope()
120122
.last()
121123
.unwrap()
122-
.assert_ty_ref()
124+
.assert_ty_ref(interner)
123125
.clone();
124126
op(this, ty)
125127
});

0 commit comments

Comments
 (0)