From 0e6865f2d0554836d203d986948f333545eacd47 Mon Sep 17 00:00:00 2001 From: Wilco Kusee Date: Sat, 27 Feb 2021 17:19:39 +0100 Subject: [PATCH] Add associated_const_data --- chalk-integration/src/db.rs | 20 +++++++++++++------ .../src/lowering/program_lowerer.rs | 1 - chalk-integration/src/program.rs | 7 +++++++ chalk-solve/src/display/stub.rs | 8 ++++++++ chalk-solve/src/lib.rs | 3 +++ chalk-solve/src/logging_db.rs | 16 +++++++++++++++ tests/display/unique_names.rs | 6 ++++++ tests/integration/panic.rs | 7 +++++++ 8 files changed, 61 insertions(+), 7 deletions(-) diff --git a/chalk-integration/src/db.rs b/chalk-integration/src/db.rs index b777f5e9eda..d846fdf2ddb 100644 --- a/chalk-integration/src/db.rs +++ b/chalk-integration/src/db.rs @@ -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; @@ -91,6 +92,13 @@ impl RustIrDatabase for ChalkDatabase { self.program_ir().unwrap().associated_ty_data(ty) } + fn associated_const_data( + &self, + ty: AssocConstId, + ) -> Arc> { + self.program_ir().unwrap().associated_const_data(ty) + } + fn trait_datum(&self, id: TraitId) -> Arc> { self.program_ir().unwrap().trait_datum(id) } diff --git a/chalk-integration/src/lowering/program_lowerer.rs b/chalk-integration/src/lowering/program_lowerer.rs index 4dfeae8c68f..e00ae08bd18 100644 --- a/chalk-integration/src/lowering/program_lowerer.rs +++ b/chalk-integration/src/lowering/program_lowerer.rs @@ -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, diff --git a/chalk-integration/src/program.rs b/chalk-integration/src/program.rs index a5e6d7b9776..4d4ec07beb3 100644 --- a/chalk-integration/src/program.rs +++ b/chalk-integration/src/program.rs @@ -396,6 +396,13 @@ impl RustIrDatabase for Program { self.associated_ty_data[&ty].clone() } + fn associated_const_data( + &self, + ty: AssocConstId, + ) -> Arc> { + self.associated_const_data[&ty].clone() + } + fn trait_datum(&self, id: TraitId) -> Arc> { self.trait_data[&id].clone() } diff --git a/chalk-solve/src/display/stub.rs b/chalk-solve/src/display/stub.rs index 7d6e9fe9cf3..0b6fa43afcd 100644 --- a/chalk-solve/src/display/stub.rs +++ b/chalk-solve/src/display/stub.rs @@ -56,6 +56,14 @@ impl> RustIrDatabase for StubWrapper<'_, D Arc::new(v) } + fn associated_const_data( + &self, + ty: chalk_ir::AssocConstId, + ) -> std::sync::Arc> { + let v = (*self.db.associated_const_data(ty)).clone(); + Arc::new(v) + } + fn trait_datum( &self, trait_id: chalk_ir::TraitId, diff --git a/chalk-solve/src/lib.rs b/chalk-solve/src/lib.rs index d91b49581cd..1ccf0a4f7c5 100644 --- a/chalk-solve/src/lib.rs +++ b/chalk-solve/src/lib.rs @@ -49,6 +49,9 @@ pub trait RustIrDatabase: Debug { /// Returns the datum for the associated type with the given id. fn associated_ty_data(&self, ty: AssocTypeId) -> Arc>; + /// Returns the datum for the associated conts with the given id. + fn associated_const_data(&self, ty: AssocConstId) -> Arc>; + /// Returns the datum for the definition with the given id. fn trait_datum(&self, trait_id: TraitId) -> Arc>; diff --git a/chalk-solve/src/logging_db.rs b/chalk-solve/src/logging_db.rs index 634d6560140..5fc9eb29c87 100644 --- a/chalk-solve/src/logging_db.rs +++ b/chalk-solve/src/logging_db.rs @@ -128,6 +128,15 @@ where ty_datum } + fn associated_const_data( + &self, + ty: chalk_ir::AssocConstId, + ) -> Arc> { + 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) -> Arc> { self.record(trait_id); self.ws.db().trait_datum(trait_id) @@ -404,6 +413,13 @@ where self.db.associated_ty_data(ty) } + fn associated_const_data( + &self, + ty: chalk_ir::AssocConstId, + ) -> Arc> { + self.db.associated_const_data(ty) + } + fn trait_datum(&self, trait_id: TraitId) -> Arc> { self.db.trait_datum(trait_id) } diff --git a/tests/display/unique_names.rs b/tests/display/unique_names.rs index 6f149480a9c..5ec613527bc 100644 --- a/tests/display/unique_names.rs +++ b/tests/display/unique_names.rs @@ -64,6 +64,12 @@ where ) -> std::sync::Arc> { self.db.associated_ty_data(ty) } + fn associated_const_data( + &self, + ty: chalk_ir::AssocConstId, + ) -> std::sync::Arc> { + self.db.associated_const_data(ty) + } fn trait_datum( &self, trait_id: chalk_ir::TraitId, diff --git a/tests/integration/panic.rs b/tests/integration/panic.rs index 4106bc2aae8..a6ccd87da2c 100644 --- a/tests/integration/panic.rs +++ b/tests/integration/panic.rs @@ -58,6 +58,13 @@ impl RustIrDatabase for MockDatabase { unimplemented!() } + fn associated_const_data( + &self, + ty: AssocConstId, + ) -> Arc> { + unimplemented!() + } + // `trait Bar`, id `0` fn trait_datum(&self, id: TraitId) -> Arc> { if let PanickingMethod::TraitDatum = self.panicking_method {