Skip to content

Commit

Permalink
Forbid inference vars when getting program clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
jackh726 committed Dec 9, 2020
1 parent d719618 commit 0b391f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
13 changes: 6 additions & 7 deletions chalk-engine/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,12 @@ impl<I: Interner> Forest<I> {
goal.canonical,
);
let mut infer = TruncatingInferenceTable::new(context.max_size(), infer);
// `canonical_goal` is a goal. We can simplify it
// into a series of *literals*, all of which must be
// true. Thus, in EWFS terms, we are effectively
// creating a single child of the `A :- A` goal that
// is like `A :- B, C, D` where B, C, and D are the
// simplified subgoals. You can think of this as
// applying built-in "meta program clauses" that
// The goal for this table is not a domain goal, so we instead
// simplify it into a series of *literals*, all of which must be
// true. Thus, in EWFS terms, we are effectively creating a
// single child of the `A :- A` goal that is like `A :- B, C, D`
// where B, C, and D are the simplified subgoals. You can think
// of this as applying built-in "meta program clauses" that
// reduce goals into Domain goals.
match Self::simplify_goal(context, &mut infer, subst, environment, goal) {
FallibleOrFloundered::Ok(ex_clause) => {
Expand Down
11 changes: 10 additions & 1 deletion chalk-solve/src/clauses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ fn program_clauses_that_could_match<I: Interner>(
let trait_datum = db.trait_datum(trait_id);

match self_ty.kind(interner) {
TyKind::InferenceVar(_, _) => {
panic!("Inference vars not allowed when getting program clauses")
}
TyKind::Alias(alias) => {
// An alias could normalize to anything, including `dyn trait`
// or an opaque type, so push a clause that asks for the
Expand Down Expand Up @@ -590,6 +593,9 @@ fn program_clauses_that_could_match<I: Interner>(
let trait_datum = db.trait_datum(trait_id);

let self_ty = alias.self_type_parameter(interner);
if let TyKind::InferenceVar(_, _) = self_ty.kind(interner) {
panic!("Inference vars not allowed when getting program clauses");
}

// Flounder if the self-type is unknown and the trait is non-enumerable.
//
Expand Down Expand Up @@ -847,6 +853,9 @@ fn match_ty<I: Interner>(
) -> Result<(), Floundered> {
let interner = builder.interner();
Ok(match ty.kind(interner) {
TyKind::InferenceVar(_, _) => {
panic!("Inference vars not allowed when getting program clauses")
}
TyKind::Adt(adt_id, _) => builder
.db
.adt_datum(*adt_id)
Expand Down Expand Up @@ -890,7 +899,7 @@ fn match_ty<I: Interner>(
TyKind::Function(_quantified_ty) => {
builder.push_fact(WellFormed::Ty(ty.clone()));
}
TyKind::BoundVar(_) | TyKind::InferenceVar(_, _) => return Err(Floundered),
TyKind::BoundVar(_) => return Err(Floundered),
TyKind::Dyn(dyn_ty) => {
// FIXME(#203)
// - Object safety? (not needed with RFC 2027)
Expand Down

0 comments on commit 0b391f8

Please sign in to comment.