Skip to content

Commit a200192

Browse files
committed
Fully compiling but with unimplemented
1 parent 52f4151 commit a200192

File tree

13 files changed

+85
-55
lines changed

13 files changed

+85
-55
lines changed

chalk-engine/src/context.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ pub trait Context: Clone + Debug {
144144

145145
fn canonical(u_canon: &Self::UCanonicalGoalInEnvironment) -> &Self::CanonicalGoalInEnvironment;
146146

147-
fn is_trivial_substitution(
148-
u_canon: &Self::UCanonicalGoalInEnvironment,
149-
canonical_subst: &Self::CanonicalAnswerSubst,
150-
) -> bool;
151-
152147
fn has_delayed_subgoals(canonical_subst: &Self::CanonicalAnswerSubst) -> bool;
153148

154149
fn num_universes(_: &Self::UCanonicalGoalInEnvironment) -> usize;
@@ -265,6 +260,13 @@ pub trait ContextOps<C: Context>: Sized + Clone + Debug + AggregateOps<C> {
265260

266261
/// Upcast this domain goal into a more general goal.
267262
fn into_goal(&self, domain_goal: C::DomainGoal) -> C::Goal;
263+
264+
fn is_trivial_substitution(
265+
&self,
266+
u_canon: &C::UCanonicalGoalInEnvironment,
267+
canonical_subst: &C::CanonicalAnswerSubst,
268+
) -> bool;
269+
268270
}
269271

270272
/// Methods for combining solutions to yield an aggregate solution.

chalk-engine/src/logic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ impl<'forest, C: Context + 'forest, CO: ContextOps<C> + 'forest> SolveState<'for
14091409
// must be backed by an impl *eventually*).
14101410
let is_trivial_answer = {
14111411
!answer.ambiguous
1412-
&& C::is_trivial_substitution(&self.forest.tables[table].table_goal, &answer.subst)
1412+
&& self.context.is_trivial_substitution(&self.forest.tables[table].table_goal, &answer.subst)
14131413
&& C::empty_constraints(&answer.subst)
14141414
};
14151415

chalk-integration/src/program.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,13 @@ impl RustIrDatabase<ChalkIr> for Program {
193193
auto_trait_id: TraitId<ChalkIr>,
194194
struct_id: StructId<ChalkIr>,
195195
) -> bool {
196+
let interner = self.interner();
196197
// Look for an impl like `impl Send for Foo` where `Foo` is
197198
// the struct. See `push_auto_trait_impls` for more.
198199
self.impl_data.values().any(|impl_datum| {
199200
let impl_trait_ref = &impl_datum.binders.value.trait_ref;
200201
impl_trait_ref.trait_id == auto_trait_id
201-
&& match impl_trait_ref.self_type_parameter().data() {
202+
&& match impl_trait_ref.self_type_parameter().data(interner) {
202203
TyData::Apply(apply) => match apply.name {
203204
TypeName::Struct(id) => id == struct_id,
204205
_ => false,

chalk-ir/src/could_match.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ pub trait CouldMatch<T: ?Sized> {
77
fn could_match(&self, other: &T) -> bool;
88
}
99

10+
#[allow(unreachable_code, unused_variables)]
1011
impl<T, I> CouldMatch<T> for T
1112
where
1213
T: Zip<I> + ?Sized + HasInterner<Interner = I>,
1314
I: Interner,
1415
{
1516
fn could_match(&self, other: &T) -> bool {
16-
return Zip::zip_with(&mut MatchZipper, self, other).is_ok();
17+
let interner = unimplemented!();
18+
return Zip::zip_with(&mut MatchZipper{ interner }, self, other).is_ok();
1719

1820
struct MatchZipper<'i, I> {
1921
interner: &'i I,

chalk-ir/src/debug.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ impl<I: Interner> Debug for TypeName<I> {
4242
}
4343
}
4444
}
45+
46+
#[allow(unreachable_code, unused_variables)]
4547
impl<I: Interner> Debug for Ty<I> {
4648
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
47-
write!(fmt, "{:?}", self.data())
49+
let interner = unimplemented!();
50+
write!(fmt, "{:?}", self.data(interner))
4851
}
4952
}
5053

chalk-solve/src/clauses.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn push_auto_trait_impls<I: Interner>(
7777
name: struct_id.cast(interner),
7878
substitution: builder.substitution_in_scope(),
7979
}
80-
.intern(builder.interner());
80+
.intern(interner);
8181

8282
// trait_ref = `MyStruct<...>: MyAutoTrait`
8383
let auto_trait_ref = TraitRef {
@@ -138,6 +138,7 @@ fn program_clauses_that_could_match<I: Interner>(
138138
goal: &DomainGoal<I>,
139139
clauses: &mut Vec<ProgramClause<I>>,
140140
) {
141+
let interner = db.interner();
141142
let builder = &mut ClauseBuilder::new(db, clauses);
142143

143144
match goal {
@@ -158,7 +159,7 @@ fn program_clauses_that_could_match<I: Interner>(
158159
// the automatic impls for `Foo`.
159160
let trait_datum = db.trait_datum(trait_id);
160161
if trait_datum.is_auto_trait() {
161-
match trait_ref.self_type_parameter().data() {
162+
match trait_ref.self_type_parameter().data(interner) {
162163
TyData::Apply(apply) => {
163164
if let Some(struct_id) = db.as_struct_id(&apply.name) {
164165
push_auto_trait_impls(builder, trait_id, struct_id);
@@ -213,7 +214,7 @@ fn program_clauses_that_could_match<I: Interner>(
213214
// that goal, because they let us prove other things but
214215
// not `Clone`.
215216
let self_ty = trait_ref.self_type_parameter();
216-
if let TyData::Dyn(dyn_ty) = self_ty.data() {
217+
if let TyData::Dyn(dyn_ty) = self_ty.data(interner) {
217218
// In this arm, `self_ty` is the `dyn Fn(&u8)`,
218219
// and `bounded_ty` is the `exists<T> { .. }`
219220
// clauses shown above.
@@ -226,7 +227,7 @@ fn program_clauses_that_could_match<I: Interner>(
226227
// forall<'a> { Implemented(dyn Fn(&u8): Fn<(&'a u8)>) }
227228
// ```
228229
let qwc = exists_qwc
229-
.substitute(db.interner(), &[self_ty.clone().cast(builder.interner())]);
230+
.substitute(interner, &[self_ty.clone().cast(interner)]);
230231

231232
builder.push_binders(&qwc, |builder, wc| {
232233
builder.push_fact(wc);
@@ -338,7 +339,8 @@ fn match_ty<I: Interner>(
338339
environment: &Environment<I>,
339340
ty: &Ty<I>,
340341
) {
341-
match ty.data() {
342+
let interner = builder.interner();
343+
match ty.data(interner) {
342344
TyData::Apply(application_ty) => match_type_name(builder, application_ty.name),
343345
TyData::Placeholder(_) => {}
344346
TyData::Alias(alias_ty) => builder

chalk-solve/src/clauses/env_elaborator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ impl<'me, I: Interner> EnvElaborator<'me, I> {
5050
}
5151

5252
fn visit_ty(&mut self, ty: &Ty<I>) {
53-
match ty.data() {
53+
let interner = self.db.interner();
54+
match ty.data(interner) {
5455
TyData::Apply(application_ty) => {
5556
match_type_name(&mut self.builder, application_ty.name)
5657
}

chalk-solve/src/infer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<I: Interner> InferenceTable<I> {
130130
/// the return value will also be shifted accordingly so that it
131131
/// can appear under that same number of binders.
132132
pub(crate) fn normalize_shallow(&mut self, interner: &I, leaf: &Ty<I>) -> Option<Ty<I>> {
133-
let var = EnaVariable::from(leaf.inference_var()?);
133+
let var = EnaVariable::from(leaf.inference_var(interner)?);
134134
match self.unify.probe_value(var) {
135135
InferenceValue::Unbound(_) => None,
136136
InferenceValue::Bound(ref val) => {

chalk-solve/src/infer/unify.rs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ impl<'t, I: Interner> Unifier<'t, I> {
8484
}
8585

8686
fn unify_ty_ty<'a>(&mut self, a: &'a Ty<I>, b: &'a Ty<I>) -> Fallible<()> {
87+
let interner = self.interner;
8788
// ^^ ^^ ^^ FIXME rustc bug
88-
if let Some(n_a) = self.table.normalize_shallow(self.interner, a) {
89+
if let Some(n_a) = self.table.normalize_shallow(interner, a) {
8990
return self.unify_ty_ty(&n_a, b);
90-
} else if let Some(n_b) = self.table.normalize_shallow(self.interner, b) {
91+
} else if let Some(n_b) = self.table.normalize_shallow(interner, b) {
9192
return self.unify_ty_ty(a, &n_b);
9293
}
9394

@@ -98,7 +99,7 @@ impl<'t, I: Interner> Unifier<'t, I> {
9899
b
99100
);
100101

101-
match (a.data(), b.data()) {
102+
match (a.data(interner), b.data(interner)) {
102103
// Unifying two inference variables: unify them in the underlying
103104
// ena table.
104105
(&TyData::InferenceVar(var1), &TyData::InferenceVar(var2)) => {
@@ -203,20 +204,21 @@ impl<'t, I: Interner> Unifier<'t, I> {
203204
// for<'b...> exists<'a...> T == U
204205

205206
debug!("unify_binders({:?}, {:?})", a, b);
207+
let interner = self.interner;
206208

207209
{
208-
let a_universal = self.table.instantiate_binders_universally(self.interner, a);
210+
let a_universal = self.table.instantiate_binders_universally(interner, a);
209211
let b_existential = self
210212
.table
211-
.instantiate_binders_existentially(self.interner, b);
213+
.instantiate_binders_existentially(interner, b);
212214
Zip::zip_with(self, &a_universal, &b_existential)?;
213215
}
214216

215217
{
216-
let b_universal = self.table.instantiate_binders_universally(self.interner, b);
218+
let b_universal = self.table.instantiate_binders_universally(interner, b);
217219
let a_existential = self
218220
.table
219-
.instantiate_binders_existentially(self.interner, a);
221+
.instantiate_binders_existentially(interner, a);
220222
Zip::zip_with(self, &a_existential, &b_universal)
221223
}
222224
}
@@ -228,13 +230,14 @@ impl<'t, I: Interner> Unifier<'t, I> {
228230
/// AliasEq(<T as Trait>::Item = U)
229231
/// ```
230232
fn unify_alias_ty(&mut self, alias: &AliasTy<I>, ty: &Ty<I>) -> Fallible<()> {
233+
let interner = self.interner;
231234
Ok(self.goals.push(InEnvironment::new(
232235
self.environment,
233236
AliasEq {
234237
alias: alias.clone(),
235238
ty: ty.clone(),
236239
}
237-
.cast(self.interner),
240+
.cast(interner),
238241
)))
239242
}
240243

@@ -247,6 +250,7 @@ impl<'t, I: Interner> Unifier<'t, I> {
247250
fn unify_var_ty(&mut self, var: InferenceVar, ty: &Ty<I>) -> Fallible<()> {
248251
debug!("unify_var_ty(var={:?}, ty={:?})", var, ty);
249252

253+
let interner = self.interner;
250254
let var = EnaVariable::from(var);
251255

252256
// Determine the universe index associated with this
@@ -260,14 +264,16 @@ impl<'t, I: Interner> Unifier<'t, I> {
260264

261265
self.table
262266
.unify
263-
.unify_var_value(var, InferenceValue::from_ty(self.interner, ty1.clone()))
267+
.unify_var_value(var, InferenceValue::from_ty(interner, ty1.clone()))
264268
.unwrap();
265269
debug!("unify_var_ty: var {:?} set to {:?}", var, ty1);
266270

267271
Ok(())
268272
}
269273

270274
fn unify_lifetime_lifetime(&mut self, a: &Lifetime<I>, b: &Lifetime<I>) -> Fallible<()> {
275+
let interner = self.interner;
276+
271277
if let Some(n_a) = self.table.normalize_lifetime(a) {
272278
return self.unify_lifetime_lifetime(&n_a, b);
273279
} else if let Some(n_b) = self.table.normalize_lifetime(b) {
@@ -297,10 +303,10 @@ impl<'t, I: Interner> Unifier<'t, I> {
297303
"unify_lifetime_lifetime: {:?} in {:?} can see {:?}; unifying",
298304
var, var_ui, idx.ui
299305
);
300-
let v = LifetimeData::Placeholder(idx).intern(self.interner);
306+
let v = LifetimeData::Placeholder(idx).intern(interner);
301307
self.table
302308
.unify
303-
.unify_var_value(var, InferenceValue::from_lifetime(self.interner, v))
309+
.unify_var_value(var, InferenceValue::from_lifetime(interner, v))
304310
.unwrap();
305311
Ok(())
306312
} else {
@@ -398,10 +404,11 @@ where
398404
universe: PlaceholderIndex,
399405
_binders: usize,
400406
) -> Fallible<Ty<I>> {
407+
let interner = self.interner();
401408
if self.universe_index < universe.ui {
402409
Err(NoSolution)
403410
} else {
404-
Ok(universe.to_ty(self.interner())) // no need to shift, not relative to depth
411+
Ok(universe.to_ty(interner)) // no need to shift, not relative to depth
405412
}
406413
}
407414

@@ -410,6 +417,7 @@ where
410417
ui: PlaceholderIndex,
411418
_binders: usize,
412419
) -> Fallible<Lifetime<I>> {
420+
let interner = self.interner();
413421
if self.universe_index < ui.ui {
414422
// Scenario is like:
415423
//
@@ -426,25 +434,26 @@ where
426434

427435
let tick_x = self.unifier.table.new_variable(self.universe_index);
428436
self.unifier.push_lifetime_eq_constraint(
429-
tick_x.to_lifetime(self.interner()),
430-
ui.to_lifetime(self.interner()),
437+
tick_x.to_lifetime(interner),
438+
ui.to_lifetime(interner),
431439
);
432-
Ok(tick_x.to_lifetime(self.interner()))
440+
Ok(tick_x.to_lifetime(interner))
433441
} else {
434442
// If the `ui` is higher than `self.universe_index`, then we can name
435443
// this lifetime, no problem.
436-
Ok(ui.to_lifetime(self.interner())) // no need to shift, not relative to depth
444+
Ok(ui.to_lifetime(interner)) // no need to shift, not relative to depth
437445
}
438446
}
439447

440448
fn fold_inference_ty(&mut self, var: InferenceVar, _binders: usize) -> Fallible<Ty<I>> {
449+
let interner = self.interner();
441450
let var = EnaVariable::from(var);
442451
match self.unifier.table.unify.probe_value(var) {
443452
// If this variable already has a value, fold over that value instead.
444453
InferenceValue::Bound(normalized_ty) => {
445454
let normalized_ty = normalized_ty.ty().unwrap();
446455
let normalized_ty = normalized_ty.fold_with(self, 0)?;
447-
assert!(!normalized_ty.needs_shift(self.interner()));
456+
assert!(!normalized_ty.needs_shift(interner));
448457
Ok(normalized_ty)
449458
}
450459

@@ -470,7 +479,7 @@ where
470479
.unwrap();
471480
}
472481

473-
Ok(var.to_ty(self.interner()))
482+
Ok(var.to_ty(interner))
474483
}
475484
}
476485
}
@@ -482,6 +491,7 @@ where
482491
) -> Fallible<Lifetime<I>> {
483492
// a free existentially bound region; find the
484493
// inference variable it corresponds to
494+
let interner = self.interner();
485495
let var = EnaVariable::from(var);
486496
match self.unifier.table.unify.probe_value(var) {
487497
InferenceValue::Unbound(ui) => {
@@ -498,7 +508,7 @@ where
498508
.unify_var_value(var, InferenceValue::Unbound(self.universe_index))
499509
.unwrap();
500510
}
501-
Ok(var.to_lifetime(self.interner()))
511+
Ok(var.to_lifetime(interner))
502512
}
503513

504514
InferenceValue::Bound(l) => {

0 commit comments

Comments
 (0)