Skip to content

Commit 0cde1a5

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 * Adding alot of <'_> for a happy clippy. * Debug with db now supports lifetimes. Fixed implementations across the codebase. * 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. + Added lifetime to DiagnosticEntry and DiagnosticBuilder as it was necessary by plugin tests. * 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. * cairo-lang-plugins: + Updated all code to use lifetimes. Added preparation for semantic db. Debug lifetime fixes. Cycle support for queries More salsa::Update support. More lifetimes. Update for unordered_hash_map and unordered_hash_set. Deque wrapper and Update for it. Some rewriter macro support. Moved priv queries back to salsa db - using update on FunctionBodyData - Update assumes that ExprId and PatternId are from the FunctionBody in the struct. AI helped a bit: Core Upgrade Migrated to a new Salsa version with better lifetime support by embedding an updated query-group implementation directly into cairo-lang-proc-macros Added comprehensive lifetime annotations (<'db>, <'_>) throughout the codebase to support the new Salsa architecture Key Technical Changes Salsa Integration Improvements: Implemented salsa::Update trait for non-Salsa structs (OrderedHashMap, OrderedHashSet, Deque wrapper) Converted SmolStr and Arc<str> to interned values for Salsa compatibility Added Ord implementation for SmolStrId to support BTreeMap's salsa::Update Database & Query System: Removed static lifetime requirements and upcasting where possible Added cycle support for queries Improved generic support in proc-macro's derive debug with db Major Crate Updates: cairo-lang-proc-macros: Added 11 new test files and embedded query-group functionality cairo-lang-utils: Gutted short_id macro, added Deque wrapper, intern conversion utilities cairo-lang-filesystem: Removed interned values from input, added utility functions for lifetime-aware inputs All syntax/parser/semantic crates: Updated to use explicit lifetimes throughout New Functionality Added preparation for semantic database Improved macro support for lifetimes in test utilities Changed from Arc<[T]> to Arc<Vec<T>> for salsa::Update compatibility This is a foundational change that modernizes the entire Cairo compiler's incremental computation infrastructure to better handle borrowed data and lifetimes. commit-id:9e4ac020
1 parent 4fb8893 commit 0cde1a5

File tree

161 files changed

+26300
-22465
lines changed

Some content is hidden

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

161 files changed

+26300
-22465
lines changed

Cargo.lock

Lines changed: 133 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: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,28 @@ use std::sync::Arc;
1111
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
1212
use cairo_lang_utils::ordered_hash_set::OrderedHashSet;
1313

14-
pub trait DebugWithDb<Db: ?Sized> {
15-
fn debug<'me, 'db>(&'me self, db: &'me Db) -> DebugWith<'me, Db>
14+
pub trait DebugWithDb<'db, Db: ?Sized> {
15+
fn debug<'me>(&'me self, db: &'db Db) -> DebugWith<'me, 'db, Db>
1616
where
1717
Self: Sized + 'me,
1818
{
1919
DebugWith { value: BoxRef::Ref(self), db }
2020
}
2121

2222
#[allow(dead_code)]
23-
fn into_debug<'me, 'db>(self, db: &'me Db) -> DebugWith<'me, Db>
23+
fn into_debug<'me>(self, db: &'db Db) -> DebugWith<'me, 'db, Db>
2424
where
2525
Self: Sized + 'me,
2626
{
2727
DebugWith { value: BoxRef::Box(Box::new(self)), db }
2828
}
2929

30-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result;
30+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result;
3131
}
3232

33-
pub struct DebugWith<'me, Db: ?Sized> {
34-
value: BoxRef<'me, dyn DebugWithDb<Db> + 'me>,
35-
db: &'me Db,
33+
pub struct DebugWith<'me, 'db, Db: ?Sized> {
34+
value: BoxRef<'me, dyn DebugWithDb<'db, Db> + 'me>,
35+
db: &'db Db,
3636
}
3737

3838
enum BoxRef<'me, T: ?Sized> {
@@ -51,137 +51,137 @@ impl<T: ?Sized> std::ops::Deref for BoxRef<'_, T> {
5151
}
5252
}
5353

54-
impl<D: ?Sized> std::fmt::Debug for DebugWith<'_, D> {
54+
impl<D: ?Sized> std::fmt::Debug for DebugWith<'_, '_, D> {
5555
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5656
DebugWithDb::fmt(&*self.value, f, self.db)
5757
}
5858
}
5959

60-
impl<Db: ?Sized, T: ?Sized> DebugWithDb<Db> for &T
60+
impl<'db, Db: ?Sized, T: ?Sized> DebugWithDb<'db, Db> for &T
6161
where
62-
T: DebugWithDb<Db>,
62+
T: DebugWithDb<'db, Db>,
6363
{
64-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
64+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
6565
T::fmt(self, f, db)
6666
}
6767
}
6868

69-
impl<Db: ?Sized, T: ?Sized> DebugWithDb<Db> for Box<T>
69+
impl<'db, Db: ?Sized, T: ?Sized> DebugWithDb<'db, Db> for Box<T>
7070
where
71-
T: DebugWithDb<Db>,
71+
T: DebugWithDb<'db, Db>,
7272
{
73-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
73+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
7474
T::fmt(self, f, db)
7575
}
7676
}
7777

78-
impl<Db: ?Sized, T> DebugWithDb<Db> for Rc<T>
78+
impl<'db, Db: ?Sized, T> DebugWithDb<'db, Db> for Rc<T>
7979
where
80-
T: DebugWithDb<Db>,
80+
T: DebugWithDb<'db, Db>,
8181
{
82-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
82+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
8383
T::fmt(self, f, db)
8484
}
8585
}
8686

87-
impl<Db: ?Sized, T: ?Sized> DebugWithDb<Db> for Arc<T>
87+
impl<'db, Db: ?Sized, T: ?Sized> DebugWithDb<'db, Db> for Arc<T>
8888
where
89-
T: DebugWithDb<Db>,
89+
T: DebugWithDb<'db, Db>,
9090
{
91-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
91+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
9292
T::fmt(self, f, db)
9393
}
9494
}
9595

96-
impl<Db: ?Sized, T> DebugWithDb<Db> for [T]
96+
impl<'db, Db: ?Sized, T> DebugWithDb<'db, Db> for [T]
9797
where
98-
T: DebugWithDb<Db>,
98+
T: DebugWithDb<'db, Db>,
9999
{
100-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
100+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
101101
let elements = self.iter().map(|e| e.debug(db));
102102
f.debug_list().entries(elements).finish()
103103
}
104104
}
105105

106-
impl<Db: ?Sized, T> DebugWithDb<Db> for Vec<T>
106+
impl<'db, Db: ?Sized, T> DebugWithDb<'db, Db> for Vec<T>
107107
where
108-
T: DebugWithDb<Db>,
108+
T: DebugWithDb<'db, Db>,
109109
{
110-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
110+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
111111
let elements = self.iter().map(|e| e.debug(db));
112112
f.debug_list().entries(elements).finish()
113113
}
114114
}
115115

116-
impl<Db: ?Sized, T> DebugWithDb<Db> for Option<T>
116+
impl<'db, Db: ?Sized, T> DebugWithDb<'db, Db> for Option<T>
117117
where
118-
T: DebugWithDb<Db>,
118+
T: DebugWithDb<'db, Db>,
119119
{
120-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
120+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
121121
let me = self.as_ref().map(|v| v.debug(db));
122122
std::fmt::Debug::fmt(&me, f)
123123
}
124124
}
125125

126-
impl<Db: ?Sized, K, V, S> DebugWithDb<Db> for HashMap<K, V, S>
126+
impl<'db, Db: ?Sized, K, V, S> DebugWithDb<'db, Db> for HashMap<K, V, S>
127127
where
128-
K: DebugWithDb<Db>,
129-
V: DebugWithDb<Db>,
128+
K: DebugWithDb<'db, Db>,
129+
V: DebugWithDb<'db, Db>,
130130
{
131-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
131+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
132132
let elements = self.iter().map(|(k, v)| (k.debug(db), v.debug(db)));
133133
f.debug_map().entries(elements).finish()
134134
}
135135
}
136136

137-
impl<Db: ?Sized, K, V> DebugWithDb<Db> for BTreeMap<K, V>
137+
impl<'db, Db: ?Sized, K, V> DebugWithDb<'db, Db> for BTreeMap<K, V>
138138
where
139-
K: DebugWithDb<Db>,
140-
V: DebugWithDb<Db>,
139+
K: DebugWithDb<'db, Db>,
140+
V: DebugWithDb<'db, Db>,
141141
{
142-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
142+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
143143
let elements = self.iter().map(|(k, v)| (k.debug(db), v.debug(db)));
144144
f.debug_map().entries(elements).finish()
145145
}
146146
}
147147

148-
impl<Db: ?Sized, K: Hash + Eq, V> DebugWithDb<Db> for OrderedHashMap<K, V>
148+
impl<'db, Db: ?Sized, K: Hash + Eq, V> DebugWithDb<'db, Db> for OrderedHashMap<K, V>
149149
where
150-
K: DebugWithDb<Db>,
151-
V: DebugWithDb<Db>,
150+
K: DebugWithDb<'db, Db>,
151+
V: DebugWithDb<'db, Db>,
152152
{
153-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
153+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
154154
let elements = self.iter().map(|(k, v)| (k.debug(db), v.debug(db)));
155155
f.debug_map().entries(elements).finish()
156156
}
157157
}
158158

159-
impl<Db: ?Sized, A> DebugWithDb<Db> for (A,)
159+
impl<'db, Db: ?Sized, A> DebugWithDb<'db, Db> for (A,)
160160
where
161-
A: DebugWithDb<Db>,
161+
A: DebugWithDb<'db, Db>,
162162
{
163-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
163+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
164164
f.debug_tuple("").field(&self.0.debug(db)).finish()
165165
}
166166
}
167167

168-
impl<Db: ?Sized, A, B> DebugWithDb<Db> for (A, B)
168+
impl<'db, Db: ?Sized, A, B> DebugWithDb<'db, Db> for (A, B)
169169
where
170-
A: DebugWithDb<Db>,
171-
B: DebugWithDb<Db>,
170+
A: DebugWithDb<'db, Db>,
171+
B: DebugWithDb<'db, Db>,
172172
{
173-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
173+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
174174
f.debug_tuple("").field(&self.0.debug(db)).field(&self.1.debug(db)).finish()
175175
}
176176
}
177177

178-
impl<Db: ?Sized, A, B, C> DebugWithDb<Db> for (A, B, C)
178+
impl<'db, Db: ?Sized, A, B, C> DebugWithDb<'db, Db> for (A, B, C)
179179
where
180-
A: DebugWithDb<Db>,
181-
B: DebugWithDb<Db>,
182-
C: DebugWithDb<Db>,
180+
A: DebugWithDb<'db, Db>,
181+
B: DebugWithDb<'db, Db>,
182+
C: DebugWithDb<'db, Db>,
183183
{
184-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
184+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
185185
f.debug_tuple("")
186186
.field(&self.0.debug(db))
187187
.field(&self.1.debug(db))
@@ -190,31 +190,31 @@ where
190190
}
191191
}
192192

193-
impl<Db: ?Sized, V, S> DebugWithDb<Db> for HashSet<V, S>
193+
impl<'db, Db: ?Sized, V, S> DebugWithDb<'db, Db> for HashSet<V, S>
194194
where
195-
V: DebugWithDb<Db>,
195+
V: DebugWithDb<'db, Db>,
196196
{
197-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
197+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
198198
let elements = self.iter().map(|e| e.debug(db));
199199
f.debug_list().entries(elements).finish()
200200
}
201201
}
202202

203-
impl<Db: ?Sized, V> DebugWithDb<Db> for BTreeSet<V>
203+
impl<'db, Db: ?Sized, V> DebugWithDb<'db, Db> for BTreeSet<V>
204204
where
205-
V: DebugWithDb<Db>,
205+
V: DebugWithDb<'db, Db>,
206206
{
207-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
207+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
208208
let elements = self.iter().map(|e| e.debug(db));
209209
f.debug_list().entries(elements).finish()
210210
}
211211
}
212212

213-
impl<Db: ?Sized, V: Hash + Eq> DebugWithDb<Db> for OrderedHashSet<V>
213+
impl<'db, Db: ?Sized, V: Hash + Eq> DebugWithDb<'db, Db> for OrderedHashSet<V>
214214
where
215-
V: DebugWithDb<Db>,
215+
V: DebugWithDb<'db, Db>,
216216
{
217-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &Db) -> std::fmt::Result {
217+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &'db Db) -> std::fmt::Result {
218218
let elements = self.iter().map(|e| e.debug(db));
219219
f.debug_list().entries(elements).finish()
220220
}
@@ -238,9 +238,9 @@ pub mod helper {
238238

239239
pub struct HelperDebug<T, Db: ?Sized>(PhantomData<T>, PhantomData<Db>);
240240

241-
impl<T: DebugWithDb<Db>, Db: ?Sized> HelperDebug<T, Db> {
241+
impl<'db, T: DebugWithDb<'db, Db>, Db: ?Sized> HelperDebug<T, Db> {
242242
#[allow(dead_code)]
243-
pub fn helper_debug<'a, 'b: 'a>(a: &'a T, db: &'b Db) -> DebugWith<'a, Db> {
243+
pub fn helper_debug<'a>(a: &'a T, db: &'db Db) -> DebugWith<'a, 'db, Db> {
244244
a.debug(db)
245245
}
246246
}

0 commit comments

Comments
 (0)