Skip to content

Commit 9187d52

Browse files
(feature): Created a Heapsize trait and a macro to derive it
1 parent 5e06538 commit 9187d52

File tree

41 files changed

+1269
-515
lines changed

Some content is hidden

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

41 files changed

+1269
-515
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: CI
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
77
merge_group:
8-
types: [ checks_requested ]
8+
types: [checks_requested]
99

1010
jobs:
1111
ensure-no_std:
@@ -201,6 +201,6 @@ jobs:
201201
steps:
202202
- uses: actions/checkout@v6
203203
with:
204-
fetch-depth: '0'
204+
fetch-depth: "0"
205205
- run: >
206206
scripts/sierra_update_check.sh origin/$GITHUB_BASE_REF origin/$GITHUB_HEAD_REF

Cargo.lock

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Debug utilities for types that need a salsa database for debug formatting.
22
33
pub mod debug;
4-
pub use crate::debug::{DebugWithDb, helper};
4+
5+
pub use debug::{DebugWithDb, helper};

crates/cairo-lang-defs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ cairo-lang-debug = { path = "../cairo-lang-debug", version = "~2.14.0" }
1212
cairo-lang-diagnostics = { path = "../cairo-lang-diagnostics", version = "~2.14.0" }
1313
cairo-lang-filesystem = { path = "../cairo-lang-filesystem", version = "~2.14.0" }
1414
cairo-lang-parser = { path = "../cairo-lang-parser", version = "~2.14.0" }
15+
cairo-lang-proc-macros = { path = "../cairo-lang-proc-macros", version = "~2.14.0" }
1516
cairo-lang-syntax = { path = "../cairo-lang-syntax", version = "~2.14.0" }
1617
cairo-lang-utils = { path = "../cairo-lang-utils", version = "~2.14.0", features = ["tracing"] }
1718
itertools = { workspace = true, default-features = true }

crates/cairo-lang-defs/src/diagnostic_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use std::fmt;
33
use cairo_lang_debug::DebugWithDb;
44
use cairo_lang_filesystem::ids::{FileId, SpanInFile};
55
use cairo_lang_filesystem::span::{TextSpan, TextWidth};
6+
use cairo_lang_proc_macros::HeapSize;
67
use cairo_lang_syntax::node::ids::SyntaxStablePtrId;
78
use cairo_lang_syntax::node::{SyntaxNode, TypedSyntaxNode};
89
use salsa::Database;
910

1011
/// A stable location of a real, concrete syntax.
11-
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, salsa::Update)]
12+
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, HeapSize, salsa::Update)]
1213
pub struct StableLocation<'db> {
1314
stable_ptr: SyntaxStablePtrId<'db>,
1415
/// An optional inner span of the stable location. Useful for diagnostics caused by inline

crates/cairo-lang-defs/src/ids.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use cairo_lang_debug::debug::DebugWithDb;
2828
use cairo_lang_diagnostics::Maybe;
2929
pub use cairo_lang_filesystem::ids::UnstableSalsaId;
3030
use cairo_lang_filesystem::ids::{CrateId, FileId, SmolStrId};
31+
use cairo_lang_proc_macros::HeapSize;
3132
use cairo_lang_syntax::node::ast::TerminalIdentifierGreen;
3233
use cairo_lang_syntax::node::helpers::{GetIdentifier, HasName, NameGreen};
3334
use cairo_lang_syntax::node::ids::SyntaxStablePtrId;
@@ -140,7 +141,7 @@ macro_rules! define_named_language_element_id {
140141
/// Use for language elements that are not top level and don't have a name.
141142
macro_rules! define_language_element_id_basic {
142143
($short_id:ident, $long_id:ident, $ast_ty:ty) => {
143-
#[derive(Clone, PartialEq, Eq, Hash, Debug, salsa::Update)]
144+
#[derive(Clone, PartialEq, Eq, Hash, Debug, salsa::Update, HeapSize)]
144145
pub struct $long_id<'db>(
145146
pub ModuleId<'db>,
146147
pub <$ast_ty as TypedSyntaxNode<'db>>::StablePtr,
@@ -198,7 +199,7 @@ macro_rules! define_language_element_id_as_enum {
198199
}
199200
) => {
200201
$(#[doc = $doc])*
201-
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, salsa::Update)]
202+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HeapSize, salsa::Update)]
202203
pub enum $enum_name<$lifetime> {
203204
$($variant($variant_ty),)*
204205
}
@@ -286,7 +287,7 @@ macro_rules! toplevel_enum {
286287

287288
/// Id for a module. Either the root module of a crate, or a submodule.
288289
// TODO(eytan-starkware): Track this type to improve performance.
289-
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, salsa::Update)]
290+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, salsa::Update, HeapSize)]
290291
pub enum ModuleId<'db> {
291292
CrateRoot(CrateId<'db>),
292293
Submodule(SubmoduleId<'db>),
@@ -345,7 +346,7 @@ impl<'db> DebugWithDb<'db> for ModuleId<'db> {
345346
}
346347

347348
/// An id for a file defined out of the filesystem crate, for files generated by plugins.
348-
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
349+
#[derive(Clone, Debug, Hash, PartialEq, Eq, HeapSize)]
349350
pub struct PluginGeneratedFileLongId<'db> {
350351
/// The module that the file was generated from.
351352
pub module_id: ModuleId<'db>,
@@ -357,7 +358,7 @@ pub struct PluginGeneratedFileLongId<'db> {
357358
define_short_id!(PluginGeneratedFileId, PluginGeneratedFileLongId<'db>);
358359

359360
/// An ID allowing for interning the [`MacroPlugin`] into Salsa database.
360-
#[derive(Clone, Debug)]
361+
#[derive(Clone, Debug, HeapSize)]
361362
pub struct MacroPluginLongId(pub Arc<dyn MacroPlugin>);
362363

363364
impl MacroPlugin for MacroPluginLongId {
@@ -412,7 +413,7 @@ impl Hash for MacroPluginLongId {
412413
define_short_id!(MacroPluginId, MacroPluginLongId);
413414

414415
/// An ID allowing for interning the [`InlineMacroExprPlugin`] into Salsa database.
415-
#[derive(Clone, Debug)]
416+
#[derive(Clone, Debug, HeapSize)]
416417
pub struct InlineMacroExprPluginLongId(pub Arc<dyn InlineMacroExprPlugin>);
417418

418419
impl InlineMacroExprPlugin for InlineMacroExprPluginLongId {

crates/cairo-lang-diagnostics/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ description = "Diagnostic utilities."
99
[dependencies]
1010
cairo-lang-debug = { path = "../cairo-lang-debug", version = "~2.14.0" }
1111
cairo-lang-filesystem = { path = "../cairo-lang-filesystem", version = "~2.14.0" }
12+
cairo-lang-proc-macros = { path = "../cairo-lang-proc-macros", version = "~2.14.0" }
1213
cairo-lang-utils = { path = "../cairo-lang-utils", version = "~2.14.0", features = ["tracing"] }
1314
itertools = { workspace = true, default-features = true }
1415
salsa.workspace = true

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::sync::Arc;
55
use cairo_lang_debug::debug::DebugWithDb;
66
use cairo_lang_filesystem::db::get_originating_location;
77
use cairo_lang_filesystem::ids::{FileId, SpanInFile};
8+
use cairo_lang_proc_macros::HeapSize;
89
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
910
use itertools::Itertools;
1011
use salsa::Database;
@@ -85,7 +86,7 @@ impl<'db> UserLocationWithPluginNotes<'db> for SpanInFile<'db> {
8586

8687
/// A note about a diagnostic.
8788
/// May include a relevant diagnostic location.
88-
#[derive(Clone, Debug, Eq, Hash, PartialEq, salsa::Update)]
89+
#[derive(Clone, Debug, Eq, Hash, PartialEq, HeapSize, salsa::Update)]
8990
pub struct DiagnosticNote<'a> {
9091
pub text: String,
9192
pub location: Option<SpanInFile<'a>>,
@@ -116,7 +117,7 @@ impl<'a> DebugWithDb<'a> for DiagnosticNote<'a> {
116117
///
117118
/// It must not be constructed directly. Instead, it is returned by [DiagnosticsBuilder::add]
118119
/// when a diagnostic is reported.
119-
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq, salsa::Update)]
120+
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq, HeapSize, salsa::Update)]
120121
pub struct DiagnosticAdded;
121122

122123
pub fn skip_diagnostic() -> DiagnosticAdded {

crates/cairo-lang-filesystem/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ description = "Virtual filesystem for the compiler."
88

99
[dependencies]
1010
cairo-lang-debug = { path = "../cairo-lang-debug", version = "~2.14.0" }
11+
cairo-lang-proc-macros = { path = "../cairo-lang-proc-macros", version = "~2.14.0" }
1112
cairo-lang-utils = { path = "../cairo-lang-utils", version = "~2.14.0", features = ["serde"] }
1213
itertools.workspace = true
1314
path-clean.workspace = true

crates/cairo-lang-filesystem/src/ids.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::path::PathBuf;
44
use std::sync::Arc;
55

66
use cairo_lang_debug::DebugWithDb;
7+
use cairo_lang_proc_macros::HeapSize;
78
use cairo_lang_utils::{Intern, define_short_id};
89
use itertools::Itertools;
910
use path_clean::PathClean;
@@ -59,7 +60,7 @@ impl CrateInput {
5960
}
6061

6162
/// A crate is a standalone file tree representing a single compilation unit.
62-
#[derive(Clone, Debug, Hash, PartialEq, Eq, salsa::Update)]
63+
#[derive(Clone, Debug, Hash, PartialEq, Eq, salsa::Update, HeapSize)]
6364
pub enum CrateLongId<'db> {
6465
/// A crate that appears in crate_roots(), and on the filesystem.
6566
Real { name: SmolStrId<'db>, discriminator: Option<String> },
@@ -127,7 +128,7 @@ impl UnstableSalsaId for CrateId<'_> {
127128
}
128129

129130
/// The long ID for a compilation flag.
130-
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
131+
#[derive(Clone, Debug, Hash, PartialEq, Eq, HeapSize)]
131132
pub struct FlagLongId(pub String);
132133
define_short_id!(FlagId, FlagLongId);
133134

@@ -152,22 +153,22 @@ impl FileInput {
152153

153154
/// We use a higher level FileId struct, because not all files are on disk. Some might be online.
154155
/// Some might be virtual/computed on demand.
155-
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
156+
#[derive(Clone, Debug, Hash, PartialEq, Eq, HeapSize)]
156157
pub enum FileLongId<'db> {
157158
OnDisk(PathBuf),
158159
Virtual(VirtualFile<'db>),
159160
External(salsa::Id),
160161
}
161162
/// Whether the file holds syntax for a module or for an expression.
162-
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
163+
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize, HeapSize)]
163164
pub enum FileKind {
164165
Module,
165166
Expr,
166167
StatementList,
167168
}
168169

169170
/// A mapping for a code rewrite.
170-
#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
171+
#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize, HeapSize)]
171172
pub struct CodeMapping {
172173
pub span: TextSpan,
173174
pub origin: CodeOrigin,
@@ -190,7 +191,7 @@ impl CodeMapping {
190191
}
191192

192193
/// The origin of a code mapping.
193-
#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
194+
#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize, HeapSize)]
194195
pub enum CodeOrigin {
195196
/// The origin is a copied node starting at the given offset.
196197
Start(TextOffset),
@@ -247,7 +248,7 @@ impl VirtualFileInput {
247248
}
248249
}
249250

250-
#[derive(Clone, Debug, Hash, PartialEq, Eq, salsa::Update)]
251+
#[derive(Clone, Debug, Hash, PartialEq, Eq, salsa::Update, HeapSize)]
251252
pub struct VirtualFile<'db> {
252253
pub parent: Option<SpanInFile<'db>>,
253254
pub name: SmolStrId<'db>,
@@ -495,7 +496,7 @@ impl<'db> Directory<'db> {
495496
}
496497

497498
/// A FileId for data that is not necessarily a valid UTF-8 string.
498-
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
499+
#[derive(Clone, Debug, Hash, PartialEq, Eq, HeapSize)]
499500
pub enum BlobLongId {
500501
OnDisk(PathBuf),
501502
Virtual(Vec<u8>),
@@ -519,7 +520,7 @@ impl<'db> BlobId<'db> {
519520
}
520521

521522
/// A location within a file.
522-
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, salsa::Update)]
523+
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, salsa::Update, HeapSize)]
523524
pub struct SpanInFile<'db> {
524525
pub file_id: FileId<'db>,
525526
pub span: TextSpan,

0 commit comments

Comments
 (0)