cairo_lang_filesystem/flag.rs
1use serde::{Deserialize, Serialize};
2
3use crate::db::FilesGroup;
4use crate::ids::FlagId;
5
6/// A compilation flag.
7#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
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 make 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 FilesGroup) -> bool {
27 db.get_flag(FlagId::new(db, "unsafe_panic"))
28 .map(|flag| *flag == Flag::UnsafePanic(true))
29 .unwrap_or(false)
30}