Skip to content

Commit

Permalink
Add associated_const_data
Browse files Browse the repository at this point in the history
  • Loading branch information
detrumi committed Mar 10, 2021
1 parent 6d67275 commit 0e6865f
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 7 deletions.
20 changes: 14 additions & 6 deletions chalk-integration/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ use crate::{
tls, SolverChoice,
};
use chalk_ir::{
AdtId, AssocTypeId, Binders, Canonical, CanonicalVarKinds, ClosureId, ConstrainedSubst,
Environment, FnDefId, GeneratorId, GenericArg, Goal, ImplId, InEnvironment, OpaqueTyId,
ProgramClause, ProgramClauses, Substitution, TraitId, Ty, TyKind, UCanonical,
AdtId, AssocConstId, AssocTypeId, Binders, Canonical, CanonicalVarKinds, ClosureId,
ConstrainedSubst, Environment, FnDefId, GeneratorId, GenericArg, Goal, ImplId, InEnvironment,
OpaqueTyId, ProgramClause, ProgramClauses, Substitution, TraitId, Ty, TyKind, UCanonical,
UnificationDatabase, Variances,
};
use chalk_solve::rust_ir::{
AdtDatum, AdtRepr, AssociatedConstValue, AssociatedConstValueId, AssociatedTyDatum,
AssociatedTyValue, AssociatedTyValueId, ClosureKind, FnDefDatum, FnDefInputsAndOutputDatum,
GeneratorDatum, GeneratorWitnessDatum, ImplDatum, OpaqueTyDatum, TraitDatum, WellKnownTrait,
AdtDatum, AdtRepr, AssociatedConstDatum, AssociatedConstValue, AssociatedConstValueId,
AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId, ClosureKind, FnDefDatum,
FnDefInputsAndOutputDatum, GeneratorDatum, GeneratorWitnessDatum, ImplDatum, OpaqueTyDatum,
TraitDatum, WellKnownTrait,
};
use chalk_solve::{RustIrDatabase, Solution, SubstitutionResult};
use salsa::Database;
Expand Down Expand Up @@ -91,6 +92,13 @@ impl RustIrDatabase<ChalkIr> for ChalkDatabase {
self.program_ir().unwrap().associated_ty_data(ty)
}

fn associated_const_data(
&self,
ty: AssocConstId<ChalkIr>,
) -> Arc<AssociatedConstDatum<ChalkIr>> {
self.program_ir().unwrap().associated_const_data(ty)
}

fn trait_datum(&self, id: TraitId<ChalkIr>) -> Arc<TraitDatum<ChalkIr>> {
self.program_ir().unwrap().trait_datum(id)
}
Expand Down
1 change: 0 additions & 1 deletion chalk-integration/src/lowering/program_lowerer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ impl ProgramLowerer {
let lookup = &self.associated_const_lookups
[&(trait_id, acv.name.str.clone())];

// TODO handle parameters in scope like for atv above
let value = acv.value.lower(&empty_env)?;
associated_const_values.insert(
acv_id,
Expand Down
7 changes: 7 additions & 0 deletions chalk-integration/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,13 @@ impl RustIrDatabase<ChalkIr> for Program {
self.associated_ty_data[&ty].clone()
}

fn associated_const_data(
&self,
ty: AssocConstId<ChalkIr>,
) -> Arc<AssociatedConstDatum<ChalkIr>> {
self.associated_const_data[&ty].clone()
}

fn trait_datum(&self, id: TraitId<ChalkIr>) -> Arc<TraitDatum<ChalkIr>> {
self.trait_data[&id].clone()
}
Expand Down
8 changes: 8 additions & 0 deletions chalk-solve/src/display/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ impl<I: Interner, DB: RustIrDatabase<I>> RustIrDatabase<I> for StubWrapper<'_, D
Arc::new(v)
}

fn associated_const_data(
&self,
ty: chalk_ir::AssocConstId<I>,
) -> std::sync::Arc<crate::rust_ir::AssociatedConstDatum<I>> {
let v = (*self.db.associated_const_data(ty)).clone();
Arc::new(v)
}

fn trait_datum(
&self,
trait_id: chalk_ir::TraitId<I>,
Expand Down
3 changes: 3 additions & 0 deletions chalk-solve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub trait RustIrDatabase<I: Interner>: Debug {
/// Returns the datum for the associated type with the given id.
fn associated_ty_data(&self, ty: AssocTypeId<I>) -> Arc<AssociatedTyDatum<I>>;

/// Returns the datum for the associated conts with the given id.
fn associated_const_data(&self, ty: AssocConstId<I>) -> Arc<AssociatedConstDatum<I>>;

/// Returns the datum for the definition with the given id.
fn trait_datum(&self, trait_id: TraitId<I>) -> Arc<TraitDatum<I>>;

Expand Down
16 changes: 16 additions & 0 deletions chalk-solve/src/logging_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ where
ty_datum
}

fn associated_const_data(
&self,
ty: chalk_ir::AssocConstId<I>,
) -> Arc<crate::rust_ir::AssociatedConstDatum<I>> {
let ty_datum = self.ws.db().associated_const_data(ty);
self.record(ty_datum.trait_id);
ty_datum
}

fn trait_datum(&self, trait_id: TraitId<I>) -> Arc<TraitDatum<I>> {
self.record(trait_id);
self.ws.db().trait_datum(trait_id)
Expand Down Expand Up @@ -404,6 +413,13 @@ where
self.db.associated_ty_data(ty)
}

fn associated_const_data(
&self,
ty: chalk_ir::AssocConstId<I>,
) -> Arc<crate::rust_ir::AssociatedConstDatum<I>> {
self.db.associated_const_data(ty)
}

fn trait_datum(&self, trait_id: TraitId<I>) -> Arc<TraitDatum<I>> {
self.db.trait_datum(trait_id)
}
Expand Down
6 changes: 6 additions & 0 deletions tests/display/unique_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ where
) -> std::sync::Arc<chalk_solve::rust_ir::AssociatedTyDatum<I>> {
self.db.associated_ty_data(ty)
}
fn associated_const_data(
&self,
ty: chalk_ir::AssocConstId<I>,
) -> std::sync::Arc<chalk_solve::rust_ir::AssociatedConstDatum<I>> {
self.db.associated_const_data(ty)
}
fn trait_datum(
&self,
trait_id: chalk_ir::TraitId<I>,
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ impl RustIrDatabase<ChalkIr> for MockDatabase {
unimplemented!()
}

fn associated_const_data(
&self,
ty: AssocConstId<ChalkIr>,
) -> Arc<AssociatedConstDatum<ChalkIr>> {
unimplemented!()
}

// `trait Bar`, id `0`
fn trait_datum(&self, id: TraitId<ChalkIr>) -> Arc<TraitDatum<ChalkIr>> {
if let PanickingMethod::TraitDatum = self.panicking_method {
Expand Down

0 comments on commit 0e6865f

Please sign in to comment.