Skip to content

Commit

Permalink
Add variable kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
detrumi committed Mar 11, 2021
1 parent 3206f10 commit 1f63b63
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
2 changes: 2 additions & 0 deletions chalk-integration/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ lower_param_map!(ClosureDefn, None);
lower_param_map!(Impl, None);
lower_param_map!(AssocTyDefn, None);
lower_param_map!(AssocTyValue, None);
lower_param_map!(AssocConstDefn, None);
lower_param_map!(AssocConstValue, None);
lower_param_map!(Clause, None);
lower_param_map!(
TraitDefn,
Expand Down
20 changes: 15 additions & 5 deletions chalk-integration/src/lowering/program_lowerer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,28 @@ impl ProgramLowerer {
AssocItemDefn::Const(assoc_const_defn) => {
let lookup = &self.associated_const_lookups
[&(trait_id, assoc_const_defn.name.str.clone())];

let mut variable_kinds = assoc_const_defn.all_parameters();
variable_kinds.extend(trait_defn.all_parameters());

let value = assoc_const_defn
.value
.as_ref()
.map(|value| {
empty_env.in_binders(variable_kinds, |env| {
Ok(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()?,
value,
}),
);
}
Expand Down
2 changes: 2 additions & 0 deletions chalk-parse/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ pub struct AssocTyDefn {
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct AssocConstDefn {
pub name: Identifier,
pub variable_kinds: Vec<VariableKind>,
pub ty: Ty,
pub value: Option<Const>,
}
Expand Down Expand Up @@ -341,6 +342,7 @@ pub struct AssocTyValue {
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct AssocConstValue {
pub name: Identifier,
pub variable_kinds: Vec<VariableKind>,
pub ty: Ty,
pub value: Const,
}
Expand Down
6 changes: 4 additions & 2 deletions chalk-parse/src/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,11 @@ AssocTyDefn: AssocTyDefn = {
};

AssocConstDefn: AssocConstDefn = {
"const" <name:Id> ":" <ty:Ty> <value:("=" <Const>)?> ";" =>
"const" <name:Id> <p:Angle<VariableKind>> ":" <ty:Ty> <value:("=" <Const>)?> ";" =>
{
AssocConstDefn {
name,
variable_kinds: p,
ty,
value
}
Expand Down Expand Up @@ -404,10 +405,11 @@ AssocTyValue: AssocTyValue = {
};

AssocConstValue: AssocConstValue = {
"const" <name:Id> ":" <ty:Ty> "=" <value: Const> ";" =>
"const" <name:Id> <a:Angle<VariableKind>> ":" <ty:Ty> "=" <value: Const> ";" =>
{
AssocConstValue {
name,
variable_kinds: a,
ty,
value,
}
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
10 changes: 8 additions & 2 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<Pn..Pm>: [type] (= [const]);
/// }
/// ```
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct AssociatedConstDatum<I: Interner> {
/// The trait this associated const is defined in.
Expand All @@ -530,7 +536,7 @@ pub struct AssociatedConstDatum<I: Interner> {
pub ty: Ty<I>,

/// Value of this associated const.
pub value: Option<Const<I>>,
pub value: Option<Binders<Const<I>>>,
}

// Manual implementation to avoid I::Identifier type.
Expand Down

0 comments on commit 1f63b63

Please sign in to comment.