Skip to content

Commit d0ae195

Browse files
Moving to new Salsa version using query-group repo (DRAFT)
This is a WIP * Using an updated version of query-group to better support lifetimes. * Embedded query-group in cairo-lang-proc-macros. * cairo-lang-proc-macro's derive debug with db now supprots generics better. * Using salsa::Update on non salsa structs to get the db to work correctly. * Moved some SmolStr and Arc<str> to use be interned for salsa::Update support. * Implemented Ord for SmolStrId to have BTreeMap's salsa::Update work. * Removing upcasting and 'static where applicable * Upgraded cairo-lang-debug by: 1. saying Db has the salsa::Database trait 2. making Dummy in test not use shortid 3. Debug with Db can make some trouble but using .long where needed fixes it. * cairo-lang-utils: 1 .The short_id macro is not really needed so I gutted it and have short_id double interned 1.1. I made short_id have a single long field that is returned by ref. 2. Implemented salsa::Update for OrderedHashMap. 3. Implemented salsa::Update for OrderedHashSet. 4. Added an as_intern_id and from_intern_id using asid and fromid 5. No need for upcast to be static * cairo-lang-filesystem 1. Removed all interned valued from input. 2. Updated code with lifetimes to better support <'db> interned values. 3. Tests needed updating as set methods are a bit more tricky now with lifetimes. 4. Added utility function for setting input values with using lifetimed objects. 5. Added macro_rules! to set_crate_config and override_file_content so they still accept a short id. * cairo-lang-syntax: * Updated all code to use lifetimes. * Updated all code to use the new query-group. * Updated codegen. * Updated ast. * cairo-lang-diagnostics: * Updated all code to use lifetimes. * Updated all code to use the new query-group. * cairo-lang-parser: * Updated all code to use lifetimes. * Updated all code to use the new query-group. * Removed the references to empty data structs as they are no longer needed. * Using long to turn StrId into a ref for the parser. * cairo-lang-sierra * No need for internkey (as query group will use #[salsa::interned] instead) * cairo-lang-defs * Added lifetime to db * Added lifetime to diagnostic_utils * Added lifetime to ids * Fixing macros in ids to support lifetimes * Using self.long(db) instead of lookup_intern to get a ref with a 'db lifetime * Change from Arc<[T]> to Arc<Vec<T>> which allows for salsa::Update. * Tests to use macro_rules! to get lifetimes right. * Updated tests to work with all the changes * Fixed debug print formatting. commit-id:9e4ac020
1 parent 6202450 commit d0ae195

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+18457
-16118
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ opt-level = 3
1818
[profile.ci-dev.package."bimap"]
1919

2020
opt-level = 3
21-
[profile.ci-dev.package."rust-analyzer-salsa"]
21+
[profile.ci-dev.package."salsa"]
2222
opt-level = 3
2323

2424
[workspace]
@@ -101,7 +101,9 @@ derivative = "2.2.0"
101101
diffy = "0.4.2"
102102
env_logger = "0.11.6"
103103
genco = "0.17.10"
104-
good_lp = { version = "1.11.0", features = ["minilp"], default-features = false }
104+
good_lp = { version = "1.11.0", features = [
105+
"minilp",
106+
], default-features = false }
105107
hashbrown = "0.15.2"
106108
id-arena = "2.2.1"
107109
ignore = "0.4.23"
@@ -125,10 +127,13 @@ quote = "1.0.38"
125127
rand = "0.9.0"
126128
rayon = "1.10.0"
127129
rstest = "0.25.0"
128-
salsa = { package = "rust-analyzer-salsa", version = "0.17.0-pre.6" }
130+
salsa = "0.22.0"
129131
schemars = { version = "0.8.21", features = ["preserve_order"] }
130132
semver = { version = "1.0.25", features = ["serde"] }
131-
serde = { version = "1.0.217", default-features = false, features = ["derive","rc"] }
133+
serde = { version = "1.0.217", default-features = false, features = [
134+
"derive",
135+
"rc",
136+
] }
132137
serde_json = "1.0.138"
133138
typetag = "0.2"
134139
sha2 = "0.10.8"

crates/cairo-lang-debug/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ description = "Debug utilities for query objects."
88

99
[dependencies]
1010
cairo-lang-utils = { path = "../cairo-lang-utils", version = "~2.11.4" }
11+
salsa.workspace = true
1112

1213
[dev-dependencies]
13-
cairo-lang-proc-macros = { path = "../cairo-lang-proc-macros"}
14+
cairo-lang-proc-macros = { path = "../cairo-lang-proc-macros" }
1415
env_logger.workspace = true
15-
salsa.workspace = true
1616
test-log.workspace = true

crates/cairo-lang-debug/src/debug.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ pub mod helper {
228228
use std::fmt;
229229
use std::marker::PhantomData;
230230

231+
use salsa::Database;
232+
231233
use super::{DebugWith, DebugWithDb};
232234

233235
pub trait Fallback<T: fmt::Debug, Db: ?Sized> {
@@ -238,12 +240,12 @@ pub mod helper {
238240

239241
pub struct HelperDebug<T, Db: ?Sized>(PhantomData<T>, PhantomData<Db>);
240242

241-
impl<T: DebugWithDb<Db>, Db: ?Sized> HelperDebug<T, Db> {
243+
impl<T: DebugWithDb<Db>, Db: Database + ?Sized> HelperDebug<T, Db> {
242244
#[allow(dead_code)]
243245
pub fn helper_debug<'a, 'b: 'a>(a: &'a T, db: &'b Db) -> DebugWith<'a, Db> {
244246
a.debug(db)
245247
}
246248
}
247249

248-
impl<Everything, Db: ?Sized, T: fmt::Debug> Fallback<T, Db> for Everything {}
250+
impl<Everything, Db: Database + ?Sized, T: fmt::Debug> Fallback<T, Db> for Everything {}
249251
}
Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
1-
use std::fmt::Debug;
2-
31
use cairo_lang_proc_macros::DebugWithDb;
4-
use cairo_lang_utils::{Intern, Upcast, define_short_id};
2+
use cairo_lang_utils::Upcast;
3+
use salsa::{Database, Storage};
54
use test_log::test;
65

7-
use crate::debug as cairo_lang_debug;
86
use crate::debug::DebugWithDb;
97

108
// Test database query group.
11-
#[salsa::query_group(TestDatabase)]
12-
trait TestGroup {
13-
#[salsa::interned]
14-
fn intern_b(&self, crt: DummyLongId) -> DummyShortId;
9+
#[cairo_lang_proc_macros::query_group]
10+
trait TestGroup: salsa::Database {}
11+
12+
// Structs.
13+
#[salsa::interned]
14+
struct Dummy {
15+
id: usize,
1516
}
16-
// Database impl.
17-
#[salsa::database(TestDatabase)]
18-
#[derive(Default)]
19-
pub struct DatabaseForTesting {
20-
storage: salsa::Storage<DatabaseForTesting>,
17+
18+
#[salsa::db]
19+
#[derive(Clone, Default)]
20+
struct DummyDb {
21+
storage: Storage<Self>,
2122
}
22-
impl salsa::Database for DatabaseForTesting {}
2323

24-
impl Upcast<dyn TestGroup> for DatabaseForTesting {
25-
fn upcast(&self) -> &(dyn TestGroup + 'static) {
26-
self
24+
#[salsa::db]
25+
impl Database for DummyDb {}
26+
27+
impl<T: Database + ?Sized> DebugWithDb<T> for Dummy<'_> {
28+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &T) -> std::fmt::Result {
29+
write!(f, "Dummy({})", self.id(db))
2730
}
2831
}
2932

30-
// Structs.
31-
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
32-
struct DummyLongId(usize);
33-
34-
define_short_id!(DummyShortId, DummyLongId, TestGroup, lookup_intern_b, intern_b);
33+
impl Upcast<dyn TestGroup> for DummyDb {
34+
fn upcast(&self) -> &dyn TestGroup {
35+
self
36+
}
37+
}
3538

3639
#[derive(DebugWithDb)]
37-
#[debug_db(dyn TestGroup + 'static)]
38-
struct ComplexStruct {
40+
#[debug_db(dyn TestGroup)]
41+
struct ComplexStruct<'db> {
3942
a: Option<usize>,
40-
b: DummyShortId,
43+
b: Dummy<'db>,
4144
#[hide_field_debug_with_db]
4245
c: usize,
4346
#[hide_field_debug_with_db]
@@ -46,7 +49,8 @@ struct ComplexStruct {
4649

4750
#[test]
4851
fn test_debug() {
49-
let db = DatabaseForTesting::default();
50-
let a = ComplexStruct { a: Some(5), b: DummyLongId(6).intern(&db), c: 7, d: 8 };
51-
assert_eq!(format!("{:?}", a.debug(&db)), "ComplexStruct { a: Some(5), b: DummyLongId(6) }");
52+
let db = DummyDb::default();
53+
let db_ref: &dyn TestGroup = &db;
54+
let a = ComplexStruct { a: Some(5), b: Dummy::new(db_ref, 6), c: 7, d: 8 };
55+
assert_eq!(format!("{:?}", a.debug(&db_ref)), "ComplexStruct { a: Some(5), b: Dummy(6) }");
5256
}

crates/cairo-lang-defs/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cairo-lang-filesystem = { path = "../cairo-lang-filesystem", version = "~2.11.4"
1313
cairo-lang-parser = { path = "../cairo-lang-parser", version = "~2.11.4" }
1414
cairo-lang-syntax = { path = "../cairo-lang-syntax", version = "~2.11.4" }
1515
cairo-lang-utils = { path = "../cairo-lang-utils", version = "~2.11.4" }
16+
cairo-lang-proc-macros = { path = "../cairo-lang-proc-macros", version = "~2.11.4" }
1617
itertools = { workspace = true, default-features = true }
1718
salsa.workspace = true
1819
serde = { workspace = true, default-features = true }
@@ -22,7 +23,9 @@ bincode.workspace = true
2223
xxhash-rust.workspace = true
2324

2425
[dev-dependencies]
25-
cairo-lang-test-utils = { path = "../cairo-lang-test-utils", features = ["testing"] }
26+
cairo-lang-test-utils = { path = "../cairo-lang-test-utils", features = [
27+
"testing",
28+
] }
2629
env_logger.workspace = true
2730
indoc.workspace = true
2831
pretty_assertions.workspace = true

0 commit comments

Comments
 (0)