From c0940415e30cf230fbabfc4292d64feb4e243599 Mon Sep 17 00:00:00 2001 From: dawn <78233879+dawnofmidnight@users.noreply.github.com> Date: Thu, 18 Aug 2022 17:52:51 -0400 Subject: [PATCH 1/2] fix: typos in tutorial ir chapter --- book/src/tutorial/ir.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/book/src/tutorial/ir.md b/book/src/tutorial/ir.md index 27319034..cbc35197 100644 --- a/book/src/tutorial/ir.md +++ b/book/src/tutorial/ir.md @@ -34,7 +34,7 @@ Inputs are defined as Rust structs with a `#[salsa::input]` annotation: {{#include ../../../calc-example/calc/src/ir.rs:input}} ``` -In our compiler, we have just one simple input, the `ProgramSource`, which has a `text` field (the string). +In our compiler, we have just one simple input, the `SourceProgram`, which has a `text` field (the string). ### The data lives in the database @@ -43,18 +43,18 @@ The values of their fields are stored in the salsa database, and the struct itse This means that the struct instances are copy (no matter what fields they contain). Creating instances of the struct and accessing fields is done by invoking methods like `new` as well as getters and setters. -More concretely, the `#[salsa::input]` annotation will generate a struct for `ProgramSource` like this: +More concretely, the `#[salsa::input]` annotation will generate a struct for `SourceProgram` like this: ```rust -#[define(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct ProgramSource(salsa::Id); +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +pub struct SourceProgram(salsa::Id); ``` -It will also generate a method `new` that lets you create a `ProgramSource` in the database. +It will also generate a method `new` that lets you create a `SourceProgram` in the database. For an input, a `&mut db` reference is required, along with the values for each field: ```rust -let source = ProgramSource::new(&mut db, "print 11 + 11".to_string()); +let source = SourceProgram::new(&mut db, "print 11 + 11".to_string()); ``` You can read the value of the field with `source.text(&db)`, From 738dc3f8783ee3af848318e1b599caadffddaf23 Mon Sep 17 00:00:00 2001 From: XFFXFF <1247714429@qq.com> Date: Fri, 19 Aug 2022 07:13:03 +0800 Subject: [PATCH 2/2] test for compile failure: lru can not be used with specify --- salsa-2022-tests/Cargo.toml | 1 + .../lru_can_not_be_used_with_specify.rs | 16 ++++++++++++++++ .../lru_can_not_be_used_with_specify.stderr | 11 +++++++++++ salsa-2022-tests/tests/compile_fail.rs | 5 +++++ 4 files changed, 33 insertions(+) create mode 100644 salsa-2022-tests/tests/compile-fail/lru_can_not_be_used_with_specify.rs create mode 100644 salsa-2022-tests/tests/compile-fail/lru_can_not_be_used_with_specify.stderr create mode 100644 salsa-2022-tests/tests/compile_fail.rs diff --git a/salsa-2022-tests/Cargo.toml b/salsa-2022-tests/Cargo.toml index d703b211..6fb25b97 100644 --- a/salsa-2022-tests/Cargo.toml +++ b/salsa-2022-tests/Cargo.toml @@ -11,3 +11,4 @@ expect-test = "1.4.0" parking_lot = "0.12.1" test-log = "0.2.11" env_logger = "*" +trybuild = "1.0" diff --git a/salsa-2022-tests/tests/compile-fail/lru_can_not_be_used_with_specify.rs b/salsa-2022-tests/tests/compile-fail/lru_can_not_be_used_with_specify.rs new file mode 100644 index 00000000..e025b002 --- /dev/null +++ b/salsa-2022-tests/tests/compile-fail/lru_can_not_be_used_with_specify.rs @@ -0,0 +1,16 @@ +#[salsa::jar(db = Db)] +struct Jar(MyInput, lru_can_not_be_used_with_specify); + +trait Db: salsa::DbWithJar {} + +#[salsa::input(jar = Jar)] +struct MyInput { + field: u32, +} + +#[salsa::tracked(jar = Jar, lru = 3, specify)] +fn lru_can_not_be_used_with_specify(db: &dyn Db, input: MyInput) -> u32 { + input.field(db) +} + +fn main() {} diff --git a/salsa-2022-tests/tests/compile-fail/lru_can_not_be_used_with_specify.stderr b/salsa-2022-tests/tests/compile-fail/lru_can_not_be_used_with_specify.stderr new file mode 100644 index 00000000..5f1be267 --- /dev/null +++ b/salsa-2022-tests/tests/compile-fail/lru_can_not_be_used_with_specify.stderr @@ -0,0 +1,11 @@ +error: `specify` and `lru` cannot be used together + --> tests/compile-fail/lru_can_not_be_used_with_specify.rs:11:38 + | +11 | #[salsa::tracked(jar = Jar, lru = 3, specify)] + | ^^^^^^^ + +error[E0412]: cannot find type `lru_can_not_be_used_with_specify` in this scope + --> tests/compile-fail/lru_can_not_be_used_with_specify.rs:2:21 + | +2 | struct Jar(MyInput, lru_can_not_be_used_with_specify); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope diff --git a/salsa-2022-tests/tests/compile_fail.rs b/salsa-2022-tests/tests/compile_fail.rs new file mode 100644 index 00000000..db50dfda --- /dev/null +++ b/salsa-2022-tests/tests/compile_fail.rs @@ -0,0 +1,5 @@ +#[test] +fn compile_fail() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/compile-fail/*.rs"); +}