Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
merge_group:
types: [ checks_requested ]
types: [checks_requested]

jobs:
ensure-no_std:
Expand Down
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/cairo-lang-debug/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Debug utilities for types that need a salsa database for debug formatting.

pub mod debug;
pub use crate::debug::{DebugWithDb, helper};

pub use debug::{DebugWithDb, helper};
1 change: 1 addition & 0 deletions crates/cairo-lang-defs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cairo-lang-debug = { path = "../cairo-lang-debug", version = "~2.14.0" }
cairo-lang-diagnostics = { path = "../cairo-lang-diagnostics", version = "~2.14.0" }
cairo-lang-filesystem = { path = "../cairo-lang-filesystem", version = "~2.14.0" }
cairo-lang-parser = { path = "../cairo-lang-parser", version = "~2.14.0" }
cairo-lang-proc-macros = { path = "../cairo-lang-proc-macros", version = "~2.14.0" }
cairo-lang-syntax = { path = "../cairo-lang-syntax", version = "~2.14.0" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "~2.14.0", features = ["tracing"] }
itertools = { workspace = true, default-features = true }
Expand Down
3 changes: 2 additions & 1 deletion crates/cairo-lang-defs/src/diagnostic_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use std::fmt;
use cairo_lang_debug::DebugWithDb;
use cairo_lang_filesystem::ids::{FileId, SpanInFile};
use cairo_lang_filesystem::span::{TextSpan, TextWidth};
use cairo_lang_proc_macros::HeapSize;
use cairo_lang_syntax::node::ids::SyntaxStablePtrId;
use cairo_lang_syntax::node::{SyntaxNode, TypedSyntaxNode};
use salsa::Database;

/// A stable location of a real, concrete syntax.
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, salsa::Update)]
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, HeapSize, salsa::Update)]
pub struct StableLocation<'db> {
stable_ptr: SyntaxStablePtrId<'db>,
/// An optional inner span of the stable location. Useful for diagnostics caused by inline
Expand Down
13 changes: 7 additions & 6 deletions crates/cairo-lang-defs/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use cairo_lang_debug::debug::DebugWithDb;
use cairo_lang_diagnostics::Maybe;
pub use cairo_lang_filesystem::ids::UnstableSalsaId;
use cairo_lang_filesystem::ids::{CrateId, FileId, SmolStrId};
use cairo_lang_proc_macros::HeapSize;
use cairo_lang_syntax::node::ast::TerminalIdentifierGreen;
use cairo_lang_syntax::node::helpers::{GetIdentifier, HasName, NameGreen};
use cairo_lang_syntax::node::ids::SyntaxStablePtrId;
Expand Down Expand Up @@ -140,7 +141,7 @@ macro_rules! define_named_language_element_id {
/// Use for language elements that are not top level and don't have a name.
macro_rules! define_language_element_id_basic {
($short_id:ident, $long_id:ident, $ast_ty:ty) => {
#[derive(Clone, PartialEq, Eq, Hash, Debug, salsa::Update)]
#[derive(Clone, PartialEq, Eq, Hash, Debug, salsa::Update, HeapSize)]
pub struct $long_id<'db>(
pub ModuleId<'db>,
pub <$ast_ty as TypedSyntaxNode<'db>>::StablePtr,
Expand Down Expand Up @@ -198,7 +199,7 @@ macro_rules! define_language_element_id_as_enum {
}
) => {
$(#[doc = $doc])*
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, salsa::Update)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HeapSize, salsa::Update)]
pub enum $enum_name<$lifetime> {
$($variant($variant_ty),)*
}
Expand Down Expand Up @@ -286,7 +287,7 @@ macro_rules! toplevel_enum {

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

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

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

impl MacroPlugin for MacroPluginLongId {
Expand Down Expand Up @@ -412,7 +413,7 @@ impl Hash for MacroPluginLongId {
define_short_id!(MacroPluginId, MacroPluginLongId);

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

impl InlineMacroExprPlugin for InlineMacroExprPluginLongId {
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-diagnostics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description = "Diagnostic utilities."
[dependencies]
cairo-lang-debug = { path = "../cairo-lang-debug", version = "~2.14.0" }
cairo-lang-filesystem = { path = "../cairo-lang-filesystem", version = "~2.14.0" }
cairo-lang-proc-macros = { path = "../cairo-lang-proc-macros", version = "~2.14.0" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "~2.14.0", features = ["tracing"] }
itertools = { workspace = true, default-features = true }
salsa.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions crates/cairo-lang-diagnostics/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::Arc;
use cairo_lang_debug::debug::DebugWithDb;
use cairo_lang_filesystem::db::get_originating_location;
use cairo_lang_filesystem::ids::{FileId, SpanInFile};
use cairo_lang_proc_macros::HeapSize;
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
use itertools::Itertools;
use salsa::Database;
Expand Down Expand Up @@ -85,7 +86,7 @@ impl<'db> UserLocationWithPluginNotes<'db> for SpanInFile<'db> {

/// A note about a diagnostic.
/// May include a relevant diagnostic location.
#[derive(Clone, Debug, Eq, Hash, PartialEq, salsa::Update)]
#[derive(Clone, Debug, Eq, Hash, PartialEq, HeapSize, salsa::Update)]
pub struct DiagnosticNote<'a> {
pub text: String,
pub location: Option<SpanInFile<'a>>,
Expand Down Expand Up @@ -116,7 +117,7 @@ impl<'a> DebugWithDb<'a> for DiagnosticNote<'a> {
///
/// It must not be constructed directly. Instead, it is returned by [DiagnosticsBuilder::add]
/// when a diagnostic is reported.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq, salsa::Update)]
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq, HeapSize, salsa::Update)]
pub struct DiagnosticAdded;

pub fn skip_diagnostic() -> DiagnosticAdded {
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-filesystem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ description = "Virtual filesystem for the compiler."

[dependencies]
cairo-lang-debug = { path = "../cairo-lang-debug", version = "~2.14.0" }
cairo-lang-proc-macros = { path = "../cairo-lang-proc-macros", version = "~2.14.0" }
cairo-lang-utils = { path = "../cairo-lang-utils", version = "~2.14.0", features = ["serde"] }
itertools.workspace = true
path-clean.workspace = true
Expand Down
19 changes: 10 additions & 9 deletions crates/cairo-lang-filesystem/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::path::PathBuf;
use std::sync::Arc;

use cairo_lang_debug::DebugWithDb;
use cairo_lang_proc_macros::HeapSize;
use cairo_lang_utils::{Intern, define_short_id};
use itertools::Itertools;
use path_clean::PathClean;
Expand Down Expand Up @@ -59,7 +60,7 @@ impl CrateInput {
}

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

/// The long ID for a compilation flag.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, HeapSize)]
pub struct FlagLongId(pub String);
define_short_id!(FlagId, FlagLongId);

Expand All @@ -152,22 +153,22 @@ impl FileInput {

/// We use a higher level FileId struct, because not all files are on disk. Some might be online.
/// Some might be virtual/computed on demand.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, HeapSize)]
pub enum FileLongId<'db> {
OnDisk(PathBuf),
Virtual(VirtualFile<'db>),
External(salsa::Id),
}
/// Whether the file holds syntax for a module or for an expression.
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize, HeapSize)]
pub enum FileKind {
Module,
Expr,
StatementList,
}

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

/// The origin of a code mapping.
#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize, HeapSize)]
pub enum CodeOrigin {
/// The origin is a copied node starting at the given offset.
Start(TextOffset),
Expand Down Expand Up @@ -247,7 +248,7 @@ impl VirtualFileInput {
}
}

#[derive(Clone, Debug, Hash, PartialEq, Eq, salsa::Update)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, salsa::Update, HeapSize)]
pub struct VirtualFile<'db> {
pub parent: Option<SpanInFile<'db>>,
pub name: SmolStrId<'db>,
Expand Down Expand Up @@ -495,7 +496,7 @@ impl<'db> Directory<'db> {
}

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

/// A location within a file.
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, salsa::Update)]
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, salsa::Update, HeapSize)]
pub struct SpanInFile<'db> {
pub file_id: FileId<'db>,
pub span: TextSpan,
Expand Down
16 changes: 15 additions & 1 deletion crates/cairo-lang-filesystem/src/span.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::iter::Sum;
use std::ops::{Add, Range, Sub};

use cairo_lang_proc_macros::HeapSize;
use salsa::Database;
use serde::{Deserialize, Serialize};

Expand All @@ -26,6 +27,7 @@ mod test;
Serialize,
Deserialize,
salsa::Update,
HeapSize,
)]
pub struct TextWidth(u32);
impl TextWidth {
Expand Down Expand Up @@ -94,6 +96,7 @@ impl Sum for TextWidth {
Serialize,
Deserialize,
salsa::Update,
HeapSize,
)]
pub struct TextOffset(TextWidth);
impl TextOffset {
Expand Down Expand Up @@ -127,7 +130,18 @@ impl Sub for TextOffset {

/// A range of text offsets that form a span (like text selection).
#[derive(
Copy, Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize,
Copy,
Clone,
Debug,
Default,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
Serialize,
Deserialize,
HeapSize,
)]
pub struct TextSpan {
pub start: TextOffset,
Expand Down
14 changes: 7 additions & 7 deletions crates/cairo-lang-lowering/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cairo_lang_defs::ids::{
NamedLanguageElementId, TopLevelLanguageElementId, TraitFunctionId, UnstableSalsaId,
};
use cairo_lang_diagnostics::{DiagnosticAdded, DiagnosticNote, Maybe};
use cairo_lang_proc_macros::{DebugWithDb, SemanticObject};
use cairo_lang_proc_macros::{DebugWithDb, HeapSize, SemanticObject};
use cairo_lang_semantic::corelib::CorelibSemantic;
use cairo_lang_semantic::items::functions::{FunctionsSemantic, ImplGenericFunctionId};
use cairo_lang_semantic::items::imp::ImplLongId;
Expand All @@ -29,7 +29,7 @@ use crate::db::LoweringGroup;
use crate::ids::semantic::substitution::SemanticRewriter;
use crate::specialization::SpecializationArg;

#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, HeapSize)]
pub enum FunctionWithBodyLongId<'db> {
Semantic(defs::ids::FunctionWithBodyId<'db>),
Generated { parent: defs::ids::FunctionWithBodyId<'db>, key: GeneratedFunctionKey<'db> },
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<'db> SemanticFunctionWithBodyIdEx<'db> for cairo_lang_defs::ids::FunctionWi
}

/// Concrete function with body.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, HeapSize)]
pub enum ConcreteFunctionWithBodyLongId<'db> {
Semantic(semantic::ConcreteFunctionWithBodyId<'db>),
Generated(GeneratedFunction<'db>),
Expand Down Expand Up @@ -239,7 +239,7 @@ impl<'db> ConcreteFunctionWithBodyId<'db> {
}

/// Function.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, HeapSize)]
pub enum FunctionLongId<'db> {
/// An original function from the user code.
Semantic(semantic::FunctionId<'db>),
Expand Down Expand Up @@ -377,15 +377,15 @@ impl<'a> DebugWithDb<'a> for FunctionLongId<'a> {
}

/// A key for generated functions.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, salsa::Update)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HeapSize, salsa::Update)]
pub enum GeneratedFunctionKey<'db> {
/// Generated loop functions are identified by the loop expr_id.
Loop(ExprPtr<'db>),
TraitFunc(TraitFunctionId<'db>, StableLocation<'db>),
}

/// Generated function.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HeapSize)]
pub struct GeneratedFunction<'db> {
pub parent: semantic::ConcreteFunctionWithBodyId<'db>,
pub key: GeneratedFunctionKey<'db>,
Expand Down Expand Up @@ -443,7 +443,7 @@ impl<'a> DebugWithDb<'a> for GeneratedFunction<'a> {
/// than the original one.
///
/// Specialized functions are identified by the base function and the arguments.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, HeapSize)]
pub struct SpecializedFunction<'db> {
/// The base function.
pub base: crate::ids::ConcreteFunctionWithBodyId<'db>,
Expand Down
Loading