Skip to content

Commit

Permalink
Add binders from trait
Browse files Browse the repository at this point in the history
  • Loading branch information
detrumi committed Mar 11, 2021
1 parent 3206f10 commit ff4d73b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
20 changes: 14 additions & 6 deletions chalk-integration/src/lowering/program_lowerer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,24 @@ impl ProgramLowerer {
AssocItemDefn::Const(assoc_const_defn) => {
let lookup = &self.associated_const_lookups
[&(trait_id, assoc_const_defn.name.str.clone())];

let variable_kinds = trait_defn.all_parameters();
let binders = assoc_const_defn
.value
.as_ref()
.map(|value| {
empty_env
.in_binders(variable_kinds, |env| value.lower(&env))
})
.transpose()?;
associated_const_data.insert(
lookup.id,
Arc::new(rust_ir::AssociatedConstDatum {
trait_id: TraitId(raw_id),
id: lookup.id,
name: assoc_const_defn.name.str.clone(),
ty: assoc_const_defn.ty.lower(&empty_env)?,
value: assoc_const_defn
.value
.clone()
.map(|v| v.lower(&empty_env))
.transpose()?,
binders,
}),
);
}
Expand Down Expand Up @@ -409,7 +415,9 @@ impl ProgramLowerer {
let lookup = &self.associated_const_lookups
[&(trait_id, acv.name.str.clone())];

let value = acv.value.lower(&empty_env)?;
let variable_kinds = impl_defn.all_parameters();
let value = empty_env
.in_binders(variable_kinds, |env| acv.value.lower(env))?;
associated_const_values.insert(
acv_id,
Arc::new(rust_ir::AssociatedConstValue {
Expand Down
2 changes: 1 addition & 1 deletion chalk-solve/src/display/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ impl<I: Interner> RenderAsRust<I> for AssociatedConstValue<I> {

write!(f, "{}const {}", s.indent(), assoc_const_data.id.display(s))?;
write!(f, ": {}", assoc_const_data.ty.display(s))?;
write!(f, " = {};", self.value.display(s))?;
write!(f, " = {};", self.value.skip_binders().display(s))?;
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion chalk-solve/src/logging_db/id_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use chalk_ir::{
use std::collections::BTreeSet;

/// Collects the identifiers needed to resolve all the names for a given
/// set of identifers, excluding identifiers we already have.
/// set of identifiers, excluding identifiers we already have.
///
/// When recording identifiers to print, the `LoggingRustIrDatabase` only
/// records identifiers the solver uses. But the solver assumes well-formedness,
Expand Down
17 changes: 12 additions & 5 deletions chalk-solve/src/rust_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,13 @@ impl<I: Interner> Visit<I> for AssociatedTyDatum<I> {
}
}

/// Represents an associated const declaration found inside of a trait.
/// Represents an associated const declaration found inside of a trait:
///
/// ```notrust
/// trait Foo<P1..Pn> { // P0 is Self
/// const Bar: [type] (= [const]);
/// }
/// ```
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct AssociatedConstDatum<I: Interner> {
/// The trait this associated const is defined in.
Expand All @@ -529,8 +535,9 @@ pub struct AssociatedConstDatum<I: Interner> {
/// Type of this associated const.
pub ty: Ty<I>,

/// Value of this associated const.
pub value: Option<Const<I>>,
/// Value of this associated const with variables `P0...Pn`
/// from the trait the assoc const is in.
pub binders: Option<Binders<Const<I>>>,
}

// Manual implementation to avoid I::Identifier type.
Expand All @@ -546,7 +553,7 @@ impl<I: Interner> Visit<I> for AssociatedConstDatum<I> {
try_break!(self.trait_id.visit_with(visitor, outer_binder));
try_break!(self.id.visit_with(visitor, outer_binder));
try_break!(self.ty.visit_with(visitor, outer_binder));
self.value.visit_with(visitor, outer_binder)
self.binders.visit_with(visitor, outer_binder)
}
}

Expand Down Expand Up @@ -663,7 +670,7 @@ pub struct AssociatedTyValueBound<I: Interner> {
pub struct AssociatedConstValue<I: Interner> {
pub impl_id: ImplId<I>,
pub associated_const_id: AssocConstId<I>,
pub value: Const<I>,
pub value: Binders<Const<I>>,
}

/// Represents the bounds for an `impl Trait` type.
Expand Down

0 comments on commit ff4d73b

Please sign in to comment.