cairo_lang_filesystem/
flag.rs

1use serde::{Deserialize, Serialize};
2
3use crate::db::FilesGroup;
4use crate::ids::{FlagId, FlagLongId};
5
6/// A compilation flag.
7#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize, Hash, salsa::Update)]
8pub enum Flag {
9    /// Whether to automatically add `withdraw_gas` calls in code cycles.
10    /// Default is true - automatically add.
11    ///
12    /// Additionally controls addition of `redeposit_gas` which happens on default.
13    AddWithdrawGas(bool),
14    NumericMatchOptimizationMinArmsThreshold(usize),
15    /// Whether to add panic backtrace handling to the generated code.
16    ///
17    /// Default is false - do not add, as it won't be used in production.
18    PanicBacktrace(bool),
19    /// Whether to use unsafe_panic in the generated code.
20    ///
21    /// Default is false as it makes panic unprovable.
22    UnsafePanic(bool),
23    /// Whether to use future_sierra in the generated code.
24    ///
25    /// Default is false.
26    FutureSierra(bool),
27}
28
29/// Returns the value of the `unsafe_panic` flag, or `false` if the flag is not set.
30pub fn flag_unsafe_panic(db: &dyn salsa::Database) -> bool {
31    let flag = FlagId::new(db, FlagLongId("unsafe_panic".into()));
32    if let Some(flag) = db.get_flag(flag) { *flag == Flag::UnsafePanic(true) } else { false }
33}
34
35/// Returns the value of the `future_sierra` flag, or `false` if the flag is not set.
36pub fn flag_future_sierra(db: &dyn salsa::Database) -> bool {
37    let flag = FlagId::new(db, FlagLongId("future_sierra".into()));
38    if let Some(flag) = db.get_flag(flag) { *flag == Flag::FutureSierra(true) } else { false }
39}