Skip to content

Commit

Permalink
Add binders to OpaqueTyDatumBound bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
detrumi committed Apr 6, 2020
1 parent beec5fc commit 3b368bb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 42 deletions.
46 changes: 26 additions & 20 deletions chalk-integration/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use chalk_ir::{self, AssocTypeId, BoundVar, DebruijnIndex, ImplId, OpaqueTyId, S
use chalk_parse::ast::*;
use chalk_rust_ir as rust_ir;
use chalk_rust_ir::{
Anonymize, AssociatedTyValueId, IntoWhereClauses, OpaqueTyBound, OpaqueTyDatum, ToParameter,
Anonymize, AssociatedTyValueId, IntoWhereClauses, OpaqueTyDatum, OpaqueTyDatumBound,
ToParameter,
};
use lalrpop_intern::intern;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -386,25 +387,30 @@ impl LowerProgram for Program {
let binders = empty_env.in_binders(parameter_kinds, |env| {
let hidden_ty = opaque_ty.ty.lower(&env)?;

let hidden_ty_bounds = env.in_binders(
Some(chalk_ir::ParameterKind::Ty(intern(FIXME_SELF))),
|env1| {
let interner = env1.interner();
Ok(opaque_ty
.bounds
.lower(&env1)?
.iter()
.flat_map(|qil| {
qil.into_where_clauses(interner, hidden_ty.clone())
})
.collect())
},
)?;

Ok(OpaqueTyBound {
hidden_ty,
bounds: hidden_ty_bounds.value,
})
let bounds: chalk_ir::Binders<Vec<chalk_ir::Binders<_>>> = env
.in_binders(
Some(chalk_ir::ParameterKind::Ty(intern(FIXME_SELF))),
|env1| {
let interner = env1.interner();
Ok(opaque_ty
.bounds
.lower(&env1)?
.iter()
.flat_map(|qil| {
qil.into_where_clauses(
interner,
chalk_ir::TyData::BoundVar(BoundVar::new(
DebruijnIndex::INNERMOST,
0,
))
.intern(interner),
)
})
.collect())
},
)?;

Ok(OpaqueTyDatumBound { hidden_ty, bounds })
})?;

opaque_ty_data.insert(
Expand Down
6 changes: 3 additions & 3 deletions chalk-rust-ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,16 @@ pub struct OpaqueTyDatum<I: Interner> {
pub opaque_ty_id: OpaqueTyId<I>,

/// The type bound to when revealed.
pub bound: Binders<OpaqueTyBound<I>>,
pub bound: Binders<OpaqueTyDatumBound<I>>,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, Fold, HasInterner)]
pub struct OpaqueTyBound<I: Interner> {
pub struct OpaqueTyDatumBound<I: Interner> {
/// The value for the "hidden type" for `opaque type Foo = ...`
pub hidden_ty: Ty<I>,

/// Trait bounds for the opaque type.
pub bounds: Vec<QuantifiedWhereClause<I>>,
pub bounds: Binders<Vec<QuantifiedWhereClause<I>>>,
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
Expand Down
44 changes: 25 additions & 19 deletions chalk-solve/src/clauses/program_clauses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,27 +166,33 @@ impl<I: Interner> ToProgramClauses<I> for OpaqueTyDatum<I> {
}
.cast(interner),
));
});

let opaque_ty_bound = &self.bound.value;
for bound in &opaque_ty_bound.bounds {
// Implemented(!T<..>: Bound).
builder.push_fact(bound.value.clone().into_well_formed_goal(interner));
}
for bound in &opaque_ty_bound.bounds {
// Implemented(!T<..>: Bound).
builder.push_binders(&bound, |builder, bound| {
builder.push_binders(&bound, |builder, bound| {
builder.push_fact(bound.into_well_formed_goal(interner));
});
});
}

for auto_trait_id in builder.db.auto_traits() {
// Implemented(!T<..>: AutoTrait) :- Implemented(HiddenTy: AutoTrait).
builder.push_clause(
TraitRef {
trait_id: auto_trait_id,
substitution: Substitution::from1(interner, alias_ty.clone()),
},
iter::once(TraitRef {
trait_id: auto_trait_id,
substitution: Substitution::from1(interner, opaque_ty_bound.hidden_ty.clone()),
}),
);
}
for auto_trait_id in builder.db.auto_traits() {
// Implemented(!T<..>: AutoTrait) :- Implemented(HiddenTy: AutoTrait).
builder.push_clause(
TraitRef {
trait_id: auto_trait_id,
substitution: Substitution::from1(interner, alias_ty.clone()),
},
iter::once(TraitRef {
trait_id: auto_trait_id,
substitution: Substitution::from1(
interner,
opaque_ty_bound.hidden_ty.clone(),
),
}),
);
}
});
}
}

Expand Down

0 comments on commit 3b368bb

Please sign in to comment.