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 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}
24
25/// Returns the value of the `unsafe_panic` flag, or `false` if the flag is not set.
26pub fn flag_unsafe_panic(db: &dyn salsa::Database) -> bool {
27 let flag = FlagId::new(db, FlagLongId("unsafe_panic".into()));
28 if let Some(flag) = db.get_flag(flag) { *flag == Flag::UnsafePanic(true) } else { false }
29}