Skip to content

Commit b446010

Browse files
authored
Merge pull request #210 from nikomatsakis/salsa-0.10.0
move to salsa 0.10.0
2 parents 63d5dad + cd6589c commit b446010

File tree

6 files changed

+97
-66
lines changed

6 files changed

+97
-66
lines changed

Cargo.lock

Lines changed: 37 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ itertools = "0.7.8"
2020
lalrpop-intern = "0.15.1"
2121
petgraph = "0.4.13"
2222
rustyline = "1.0"
23-
salsa = "0.9.1"
23+
salsa = "0.10.0"
2424
serde = "1.0"
2525
serde_derive = "1.0"
2626
stacker = "0.1.5"

chalk-ir/src/lib.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,45 @@ pub enum TypeSort {
225225

226226
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
227227
pub enum Ty {
228+
/// An "application" type is one that applies the set of type
229+
/// arguments to some base type. For example, `Vec<u32>` would be
230+
/// "applying" the parameters `[u32]` to the code type `Vec`.
231+
/// This type is also used for base types like `u32` (which just apply
232+
/// an empty list).
228233
Apply(ApplicationTy),
234+
235+
/// A "projection" type corresponds to an (unnormalized)
236+
/// projection like `<P0 as Trait<P1..Pn>>::Foo`. Note that the
237+
/// trait and all its parameters are fully known.
229238
Projection(ProjectionTy),
239+
240+
/// This is a variant of a projection in which the trait is
241+
/// **not** known. It corresponds to a case where people write
242+
/// `T::Item` without specifying the trait. We would then try to
243+
/// figure out the trait by looking at all the traits that are in
244+
/// scope.
230245
UnselectedProjection(UnselectedProjectionTy),
246+
247+
/// A "higher-ranked" type. In the Rust surface syntax, this can
248+
/// only be a funtion type (e.g., `for<'a> fn(&'a u32)`) or a dyn
249+
/// type (e.g., `dyn for<'a> SomeTrait<&'a u32>`). However, in
250+
/// Chalk's representation, we separate out the `for<'a>` part
251+
/// from the underlying type, so technically we can represent
252+
/// things like `for<'a> SomeStruct<'a>`, although that has no
253+
/// meaning in Rust.
231254
ForAll(Box<QuantifiedTy>),
232255

233-
/// References the binding at the given depth (deBruijn index
234-
/// style).
256+
/// References the binding at the given depth. The index is a [de
257+
/// Bruijn index], so it counts back through the in-scope biners,
258+
/// with 0 being the innermost binder. This is used in impls and
259+
/// the like. For example, if we had a rule like `for<T> { (T:
260+
/// Clone) :- (T: Copy) }`, then `T` would be represented as a
261+
/// `BoundVar(0)` (as the `for` is the innermost binder).
262+
///
263+
/// [de Bruijn index]: https://en.wikipedia.org/wiki/De_Bruijn_index
235264
BoundVar(usize),
236265

237-
/// Inference variable.
266+
/// Inference variable defined in the current inference context.
238267
InferenceVar(InferenceVar),
239268
}
240269

chalk-macros/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ authors = ["Rust Compiler Team", "Chalk developers"]
77
repository = "https://github.com/rust-lang/chalk"
88
readme = "README.md"
99
keywords = ["compiler", "traits", "prolog"]
10+
edition = "2018"
1011

1112
[dependencies]
1213
lazy_static = "1.1.0"

src/db.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#![allow(non_camel_case_types)]
22

3-
use crate::query::{self, ProgramSolverChoice, ProgramText};
3+
use crate::query::{Lowering, LoweringDatabase};
44
use chalk_solve::solve::SolverChoice;
55
use salsa::Database;
66
use std::sync::Arc;
77

8+
#[salsa::database(Lowering)]
89
#[derive(Default)]
910
pub struct ChalkDatabase {
1011
runtime: salsa::Runtime<ChalkDatabase>,
@@ -24,22 +25,9 @@ impl ChalkDatabase {
2425
) -> R {
2526
let mut db = ChalkDatabase::default();
2627

27-
db.query_mut(ProgramText).set((), program_text);
28-
db.query_mut(ProgramSolverChoice).set((), solver_choice);
28+
db.set_program_text(program_text);
29+
db.set_solver_choice(solver_choice);
2930

3031
f(&mut db)
3132
}
3233
}
33-
34-
salsa::database_storage! {
35-
pub struct DatabaseStorage for ChalkDatabase {
36-
impl query::LoweringDatabase {
37-
fn program_text() for query::ProgramText;
38-
fn solver_choice() for query::ProgramSolverChoice;
39-
fn program_ir() for query::ProgramIr;
40-
fn lowered_program() for query::LoweredProgram;
41-
fn checked_program() for query::CheckedProgram;
42-
fn environment() for query::Environment;
43-
}
44-
}
45-
}

src/query.rs

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,28 @@ use chalk_ir::ProgramEnvironment;
99
use chalk_solve::solve::SolverChoice;
1010
use std::sync::Arc;
1111

12-
salsa::query_group! {
13-
pub trait LoweringDatabase: salsa::Database {
14-
fn program_text() -> Arc<String> {
15-
type ProgramText;
16-
17-
storage input;
18-
}
19-
20-
fn solver_choice() -> SolverChoice {
21-
type ProgramSolverChoice;
22-
23-
storage input;
24-
}
25-
26-
// FIXME: Result<..., String> is only needed because the error type is not clone
27-
28-
/// The program IR before recording specialization priorities.
29-
/// Do not use this query directly.
30-
fn program_ir() -> Result<Arc<rust_ir::Program>, String> {
31-
type ProgramIr;
32-
}
33-
34-
/// The lowered IR.
35-
fn lowered_program() -> Result<Arc<rust_ir::Program>, String> {
36-
type LoweredProgram;
37-
}
38-
39-
/// The lowered IR, with checks performed.
40-
fn checked_program() -> Result<Arc<rust_ir::Program>, String> {
41-
type CheckedProgram;
42-
}
43-
44-
/// The program as logic.
45-
fn environment() -> Result<Arc<ProgramEnvironment>, String> {
46-
type Environment;
47-
}
48-
}
12+
#[salsa::query_group(Lowering)]
13+
pub trait LoweringDatabase {
14+
#[salsa::input]
15+
fn program_text(&self) -> Arc<String>;
16+
17+
#[salsa::input]
18+
fn solver_choice(&self) -> SolverChoice;
19+
20+
// FIXME: Result<..., String> is only needed because the error type is not clone
21+
22+
/// The program IR before recording specialization priorities.
23+
/// Do not use this query directly.
24+
fn program_ir(&self) -> Result<Arc<rust_ir::Program>, String>;
25+
26+
/// The lowered IR.
27+
fn lowered_program(&self) -> Result<Arc<rust_ir::Program>, String>;
28+
29+
/// The lowered IR, with checks performed.
30+
fn checked_program(&self) -> Result<Arc<rust_ir::Program>, String>;
31+
32+
/// The program as logic.
33+
fn environment(&self) -> Result<Arc<ProgramEnvironment>, String>;
4934
}
5035

5136
fn program_ir(db: &impl LoweringDatabase) -> Result<Arc<rust_ir::Program>, String> {

0 commit comments

Comments
 (0)