Skip to content
Draft
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
87 changes: 84 additions & 3 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ itertools = { version = "0.14.0", default-features = false }
keccak = "0.1.5"
lalrpop-util = { version = "0.23.1", features = ["lexer"] }
log = "0.4.27"
dhat = "0.3"
mimalloc = { version = "0.1.48" }
num-bigint = { version = "0.4.6", default-features = false }
num-integer = "0.1.46"
Expand Down
2 changes: 2 additions & 0 deletions crates/bin/cairo-compile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description = "Cairo compiler executable for the Cairo programming language"
[dependencies]
anyhow.workspace = true
clap.workspace = true
dhat = { workspace = true, optional = true }
log.workspace = true
mimalloc = { workspace = true, optional = true }
tracing.workspace = true
Expand All @@ -18,4 +19,5 @@ cairo-lang-lowering = { path = "../../cairo-lang-lowering", version = "=2.16.1"
cairo-lang-utils = { path = "../../cairo-lang-utils", version = "=2.16.1", features = ["tracing"] }

[features]
dhat = ["dep:dhat"]
mimalloc = ["dep:mimalloc"]
9 changes: 8 additions & 1 deletion crates/bin/cairo-compile/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ use cairo_lang_compiler::{CompilerConfig, compile_cairo_project_at_path};
use cairo_lang_utils::logging::init_logging;
use clap::Parser;

#[cfg(feature = "mimalloc")]
#[cfg(all(feature = "mimalloc", not(feature = "dhat")))]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[cfg(feature = "dhat")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;

/// Options for the `inlining-strategy` arguments.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, clap::ValueEnum)]
pub enum InliningStrategy {
Expand Down Expand Up @@ -51,6 +55,9 @@ struct Args {
}

fn main() -> anyhow::Result<()> {
#[cfg(feature = "dhat")]
let _profiler = dhat::Profiler::new_heap();

init_logging(tracing::Level::ERROR);
log::info!("Starting Cairo compilation.");

Expand Down
2 changes: 2 additions & 0 deletions crates/bin/starknet-compile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ description = "Compiler executable for the Cairo programming language with the S
[dependencies]
anyhow.workspace = true
clap.workspace = true
dhat = { workspace = true, optional = true }
mimalloc = { workspace = true, optional = true }

cairo-lang-compiler = { path = "../../cairo-lang-compiler", version = "=2.16.1" }
cairo-lang-starknet = { path = "../../cairo-lang-starknet", version = "=2.16.1" }
cairo-lang-starknet-classes = { path = "../../cairo-lang-starknet-classes", version = "=2.16.1" }

[features]
dhat = ["dep:dhat"]
mimalloc = ["dep:mimalloc"]
9 changes: 8 additions & 1 deletion crates/bin/starknet-compile/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ use cairo_lang_starknet::compile::starknet_compile;
use cairo_lang_starknet_classes::allowed_libfuncs::ListSelector;
use clap::Parser;

#[cfg(feature = "mimalloc")]
#[cfg(all(feature = "mimalloc", not(feature = "dhat")))]
#[global_allocator]
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[cfg(feature = "dhat")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;

/// Compiles the specified contract from a Cairo project into a contract class file.
/// Exits with 0/1 if the compilation succeeds/fails.
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -43,6 +47,9 @@ struct Args {
}

fn main() -> anyhow::Result<()> {
#[cfg(feature = "dhat")]
let _profiler = dhat::Profiler::new_heap();

let args = Args::parse();

// Check if args.path is a file or a directory.
Expand Down
8 changes: 4 additions & 4 deletions crates/cairo-lang-lowering/src/add_withdraw_gas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn add_withdraw_gas_to_function<'db>(
let new_root_block = Block {
statements: vec![],
end: BlockEnd::Match {
info: MatchInfo::Extern(MatchExternInfo {
info: Box::new(MatchInfo::Extern(MatchExternInfo {
function: get_function_id(
db,
core_submodule(db, SmolStrId::from(db, "gas")),
Expand Down Expand Up @@ -77,7 +77,7 @@ fn add_withdraw_gas_to_function<'db>(
},
],
location,
}),
})),
},
};

Expand Down Expand Up @@ -126,12 +126,12 @@ fn create_panic_block<'db>(
is_specialization_base_call: false,
})],
end: BlockEnd::Match {
info: MatchInfo::Enum(MatchEnumInfo {
info: Box::new(MatchInfo::Enum(MatchEnumInfo {
concrete_enum_id: *never_enum_id,
input: VarUsage { var_id: never_var, location },
arms: vec![],
location,
}),
})),
},
})
}
16 changes: 9 additions & 7 deletions crates/cairo-lang-lowering/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ struct VariableCached {
}
impl VariableCached {
fn new<'db>(variable: Variable<'db>, ctx: &mut CacheSavingContext<'db>) -> Self {
let TypeInfo { droppable, copyable, destruct_impl, panic_destruct_impl } = variable.info;
let TypeInfo { droppable, copyable, destruct_impl, panic_destruct_impl } = *variable.info;
Self {
droppable: droppable
.map(|impl_id| ImplIdCached::new(impl_id, &mut ctx.semantic_ctx))
Expand All @@ -567,7 +567,7 @@ impl VariableCached {
Variable {
ty: self.ty.get_embedded(&ctx.semantic_loading_data),
location: self.location.embed(ctx),
info: TypeInfo {
info: Box::new(TypeInfo {
droppable: self
.droppable
.map(|impl_id| impl_id.get_embedded(&ctx.semantic_loading_data))
Expand All @@ -584,7 +584,7 @@ impl VariableCached {
.panic_destruct_impl
.map(|impl_id| impl_id.get_embedded(&ctx.semantic_loading_data))
.ok_or(InferenceError::Reported(skip_diagnostic())),
},
}),
}
}
}
Expand Down Expand Up @@ -665,7 +665,7 @@ impl BlockEndCached {
}
BlockEnd::NotSet => BlockEndCached::NotSet,
BlockEnd::Match { info } => {
BlockEndCached::Match { info: MatchInfoCached::new(info, ctx) }
BlockEndCached::Match { info: MatchInfoCached::new(*info, ctx) }
}
}
}
Expand All @@ -680,7 +680,7 @@ impl BlockEndCached {
BlockEnd::Goto(BlockId(block_id), remapping.embed(ctx))
}
BlockEndCached::NotSet => BlockEnd::NotSet,
BlockEndCached::Match { info } => BlockEnd::Match { info: info.embed(ctx) },
BlockEndCached::Match { info } => BlockEnd::Match { info: Box::new(info.embed(ctx)) },
}
}
}
Expand Down Expand Up @@ -918,7 +918,7 @@ impl StatementCached {
StatementCached::StructDestructure(StatementStructDestructureCached::new(stmt, ctx))
}
Statement::EnumConstruct(stmt) => {
StatementCached::EnumConstruct(StatementEnumConstructCached::new(stmt, ctx))
StatementCached::EnumConstruct(StatementEnumConstructCached::new(*stmt, ctx))
}
Statement::Snapshot(stmt) => {
StatementCached::Snapshot(StatementSnapshotCached::new(stmt, ctx))
Expand All @@ -940,7 +940,9 @@ impl StatementCached {
StatementCached::StructDestructure(stmt) => {
Statement::StructDestructure(stmt.embed(ctx))
}
StatementCached::EnumConstruct(stmt) => Statement::EnumConstruct(stmt.embed(ctx)),
StatementCached::EnumConstruct(stmt) => {
Statement::EnumConstruct(Box::new(stmt.embed(ctx)))
}
StatementCached::Snapshot(stmt) => Statement::Snapshot(stmt.embed(ctx)),
StatementCached::Desnap(stmt) => Statement::Desnap(stmt.embed(ctx)),
StatementCached::IntoBox(stmt) => Statement::IntoBox(stmt.embed(ctx)),
Expand Down
4 changes: 2 additions & 2 deletions crates/cairo-lang-lowering/src/concretize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn concretize_lowered<'db>(
// Substitute all types.
for (_, var) in lowered.variables.iter_mut() {
var.ty = substitution.substitute(db, var.ty)?;
let TypeInfo { destruct_impl, panic_destruct_impl, .. } = &mut var.info;
let TypeInfo { destruct_impl, panic_destruct_impl, .. } = &mut *var.info;
for impl_id in [destruct_impl, panic_destruct_impl].into_iter().flatten() {
*impl_id = substitution.substitute(db, *impl_id)?;
}
Expand All @@ -68,7 +68,7 @@ pub fn concretize_lowered<'db>(
}
}
if let BlockEnd::Match { info } = &mut block.end {
for MatchArm { arm_selector: selector, .. } in match info {
for MatchArm { arm_selector: selector, .. } in match &mut **info {
crate::MatchInfo::Enum(s) => s.arms.iter_mut(),
crate::MatchInfo::Extern(s) => {
s.function = concretize_function(db, substitution, s.function)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/cairo-lang-lowering/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ pub(crate) fn get_direct_callees<'db>(
BlockEnd::Goto(next, _) => stack.push(*next),
BlockEnd::Match { info } => {
let mut arms = info.arms().iter();
if let MatchInfo::Extern(s) = info {
if let MatchInfo::Extern(s) = &**info {
direct_callees.push(s.function);
if DependencyType::Cost == dependency_type
&& withdraw_gas_fns.contains(&s.function)
Expand Down
Loading
Loading