diff --git a/Cargo.lock b/Cargo.lock index 50485ca101b..3fa97c4856e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -512,9 +512,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.72" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701" +checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9" [[package]] name = "lock_api" @@ -673,9 +673,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" dependencies = [ "unicode-xid", ] @@ -825,9 +825,9 @@ checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] name = "salsa" -version = "0.14.4" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4ca1c656054666a642affbbc86ab95ed7541125a89f032483d34ee56c0f5390" +checksum = "885b4b99dde959decc84e85dd943bd140b4aabd62db2f8206ef5270f77ec20b9" dependencies = [ "crossbeam-utils", "indexmap", @@ -842,9 +842,9 @@ dependencies = [ [[package]] name = "salsa-macros" -version = "0.14.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038a09b6271446f1123f142fe7e5bef6d4687c4cf82e6986be574c2af3745530" +checksum = "2c280ac85b15ac214b86ac4b407626a48e6a1c4f90769a582fec74aa57942b9f" dependencies = [ "heck", "proc-macro2", @@ -943,9 +943,9 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" [[package]] name = "syn" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b" +checksum = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0" dependencies = [ "proc-macro2", "quote", @@ -1005,9 +1005,9 @@ dependencies = [ [[package]] name = "tracing" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e2a2de6b0d5cbb13fc21193a2296888eaab62b6044479aafb3c54c01c29fcd" +checksum = "dbdf4ccd1652592b01286a5dbe1e2a77d78afaa34beadd9872a5f7396f92aaa9" dependencies = [ "cfg-if", "tracing-attributes", diff --git a/Cargo.toml b/Cargo.toml index d2243955744..57e88deb679 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ bench = [] docopt = "1.1.0" itertools = "0.9.0" rustyline = "6.2.0" -salsa = "0.14.0" +salsa = "0.15.0" serde = "1.0" serde_derive = "1.0" diff --git a/chalk-integration/Cargo.toml b/chalk-integration/Cargo.toml index e7fdd13c890..e478c40abe1 100644 --- a/chalk-integration/Cargo.toml +++ b/chalk-integration/Cargo.toml @@ -11,7 +11,7 @@ publish = false [dependencies] string_cache = "0.8.0" -salsa = "0.14.0" +salsa = "0.15.0" tracing = "0.1" chalk-derive = { version = "0.20.0-dev.0", path = "../chalk-derive" } diff --git a/chalk-integration/src/db.rs b/chalk-integration/src/db.rs index e9ab6664410..359acda71f9 100644 --- a/chalk-integration/src/db.rs +++ b/chalk-integration/src/db.rs @@ -17,22 +17,16 @@ use chalk_solve::rust_ir::{ }; use chalk_solve::{RustIrDatabase, Solution, Solver, SubstitutionResult}; use salsa::Database; +use std::fmt; use std::sync::Arc; #[salsa::database(Lowering)] -#[derive(Debug, Default)] +#[derive(Default)] pub struct ChalkDatabase { - runtime: salsa::Runtime, + storage: salsa::Storage, } -impl Database for ChalkDatabase { - fn salsa_runtime(&self) -> &salsa::Runtime { - &self.runtime - } - fn salsa_runtime_mut(&mut self) -> &mut salsa::Runtime { - &mut self.runtime - } -} +impl Database for ChalkDatabase {} impl ChalkDatabase { pub fn with(program_text: &str, solver_choice: SolverChoice) -> Self { @@ -222,3 +216,9 @@ impl RustIrDatabase for ChalkDatabase { self.program_ir().unwrap().fn_def_name(fn_def_id) } } + +impl fmt::Debug for ChalkDatabase { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "ChalkDatabase {{ }}") + } +} diff --git a/chalk-integration/src/query.rs b/chalk-integration/src/query.rs index 88eb2eb393b..5982c3c7de3 100644 --- a/chalk-integration/src/query.rs +++ b/chalk-integration/src/query.rs @@ -25,7 +25,9 @@ use std::sync::Arc; use std::sync::Mutex; #[salsa::query_group(Lowering)] -pub trait LoweringDatabase: RustIrDatabase + Database { +pub trait LoweringDatabase: + RustIrDatabase + Database + Upcast> +{ #[salsa::input] fn program_text(&self) -> Arc; @@ -58,6 +60,31 @@ pub trait LoweringDatabase: RustIrDatabase + Database { fn solver(&self) -> ArcEq>; } +// Needed to go from dyn LoweringDatabase -> dyn RustIrDatabase +// These traits are basically vendored (slightly modified) from https://github.com/connicpu/upcast +pub trait Upcast { + fn upcast(&self) -> &U; +} + +pub trait UpcastFrom { + fn upcast_from(val: &T) -> &Self; +} + +impl<'a, T: RustIrDatabase + 'a> UpcastFrom for dyn RustIrDatabase + 'a { + fn upcast_from(val: &T) -> &(dyn RustIrDatabase + 'a) { + val + } +} + +impl Upcast for T +where + U: UpcastFrom, +{ + fn upcast(&self) -> &U { + U::upcast_from(self) + } +} + #[derive(Debug)] #[repr(transparent)] pub struct ArcEq(Arc); @@ -95,19 +122,19 @@ impl Clone for ArcEq { } } -fn program_ir(db: &impl LoweringDatabase) -> Result, ChalkError> { +fn program_ir(db: &dyn LoweringDatabase) -> Result, ChalkError> { let text = db.program_text(); Ok(Arc::new(chalk_parse::parse_program(&text)?.lower()?)) } -fn orphan_check(db: &impl LoweringDatabase) -> Result<(), ChalkError> { +fn orphan_check(db: &dyn LoweringDatabase) -> Result<(), ChalkError> { let program = db.program_ir()?; tls::set_current_program(&program, || -> Result<(), ChalkError> { let local_impls = program.local_impl_ids(); for impl_id in local_impls { orphan::perform_orphan_check::( - db, + db.upcast(), db.solver_choice(), impl_id, )?; @@ -117,7 +144,7 @@ fn orphan_check(db: &impl LoweringDatabase) -> Result<(), ChalkError> { } fn coherence( - db: &impl LoweringDatabase, + db: &dyn LoweringDatabase, ) -> Result, Arc>>, ChalkError> { let program = db.program_ir()?; @@ -127,7 +154,7 @@ fn coherence( .keys() .map(|&trait_id| { let solver: CoherenceSolver = - CoherenceSolver::new(db, db.solver_choice(), trait_id); + CoherenceSolver::new(db.upcast(), db.solver_choice(), trait_id); let priorities = solver.specialization_priorities()?; Ok((trait_id, priorities)) }) @@ -139,14 +166,14 @@ fn coherence( priorities_map } -fn checked_program(db: &impl LoweringDatabase) -> Result, ChalkError> { +fn checked_program(db: &dyn LoweringDatabase) -> Result, ChalkError> { let program = db.program_ir()?; db.coherence()?; let () = tls::set_current_program(&program, || -> Result<(), ChalkError> { let solver: wf::WfSolver = - wf::WfSolver::new(db, db.solver_choice()); + wf::WfSolver::new(db.upcast(), db.solver_choice()); for &id in program.adt_data.keys() { solver.verify_adt_decl(id)?; } @@ -161,7 +188,7 @@ fn checked_program(db: &impl LoweringDatabase) -> Result, ChalkErro Ok(program) } -fn environment(db: &impl LoweringDatabase) -> Result, ChalkError> { +fn environment(db: &dyn LoweringDatabase) -> Result, ChalkError> { let program = db.program_ir()?; // Construct the set of *clauses*; these are sort of a compiled form @@ -170,7 +197,7 @@ fn environment(db: &impl LoweringDatabase) -> Result, Ch // forall P0...Pn. Something :- Conditions let mut program_clauses = program.custom_clauses.clone(); - let builder = &mut ClauseBuilder::new(db, &mut program_clauses); + let builder = &mut ClauseBuilder::new(db.upcast(), &mut program_clauses); let env = chalk_ir::Environment::new(builder.interner()); @@ -215,7 +242,7 @@ fn environment(db: &impl LoweringDatabase) -> Result, Ch Ok(Arc::new(ProgramEnvironment::new(program_clauses))) } -fn solver(db: &impl LoweringDatabase) -> ArcEq> { +fn solver(db: &dyn LoweringDatabase) -> ArcEq> { db.salsa_runtime().report_untracked_read(); let choice = db.solver_choice(); ArcEq::new(Mutex::new(choice.into()))