Skip to content

Commit 2b7a9b4

Browse files
committed
feat: Disable debug symbols
1 parent 818f017 commit 2b7a9b4

File tree

4 files changed

+46
-16
lines changed

4 files changed

+46
-16
lines changed

src/compile.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct Scope {
6666
call_tracker: Arc<CallTracker>,
6767
/// Values for parameters inside the Simfony program.
6868
arguments: Arguments,
69+
include_debug_symbols: bool,
6970
}
7071

7172
impl Scope {
@@ -77,12 +78,17 @@ impl Scope {
7778
///
7879
/// The supplied `arguments` are consistent with the program's parameters.
7980
/// Call [`Arguments::is_consistent`] before calling this method!
80-
pub fn new(call_tracker: Arc<CallTracker>, arguments: Arguments) -> Self {
81+
pub fn new(
82+
call_tracker: Arc<CallTracker>,
83+
arguments: Arguments,
84+
include_debug_symbols: bool,
85+
) -> Self {
8186
Self {
8287
variables: vec![vec![Pattern::Ignore]],
8388
ctx: simplicity::types::Context::new(),
8489
call_tracker,
8590
arguments,
91+
include_debug_symbols,
8692
}
8793
}
8894

@@ -93,6 +99,7 @@ impl Scope {
9399
ctx: self.ctx.shallow_clone(),
94100
call_tracker: Arc::clone(&self.call_tracker),
95101
arguments: self.arguments.clone(),
102+
include_debug_symbols: self.include_debug_symbols,
96103
}
97104
}
98105

@@ -193,12 +200,12 @@ impl Scope {
193200
span: &S,
194201
) -> Result<PairBuilder<ProgNode>, RichError> {
195202
match self.call_tracker.get_cmr(span.as_ref()) {
196-
Some(cmr) => {
203+
Some(cmr) if self.include_debug_symbols => {
197204
let false_and_args = ProgNode::bit(self.ctx(), false).pair(args);
198205
let nop_assert = ProgNode::assertl_drop(body, cmr);
199206
false_and_args.comp(&nop_assert).with_span(span)
200207
}
201-
None => args.comp(body).with_span(span),
208+
_ => args.comp(body).with_span(span),
202209
}
203210
}
204211

@@ -246,8 +253,16 @@ impl Program {
246253
///
247254
/// The supplied `arguments` are consistent with the program's parameters.
248255
/// Call [`Arguments::is_consistent`] before calling this method!
249-
pub fn compile(&self, arguments: Arguments) -> Result<ProgNode, RichError> {
250-
let mut scope = Scope::new(Arc::clone(self.call_tracker()), arguments);
256+
pub fn compile(
257+
&self,
258+
arguments: Arguments,
259+
include_debug_symbols: bool,
260+
) -> Result<ProgNode, RichError> {
261+
let mut scope = Scope::new(
262+
Arc::clone(self.call_tracker()),
263+
arguments,
264+
include_debug_symbols,
265+
);
251266
self.main().compile(&mut scope).map(PairBuilder::build)
252267
}
253268
}

src/lib.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,19 @@ impl TemplateProgram {
7171
///
7272
/// The arguments are not consistent with the parameters of the program.
7373
/// Use [`TemplateProgram::parameters`] to see which parameters the program has.
74-
pub fn instantiate(&self, arguments: Arguments) -> Result<CompiledProgram, String> {
74+
pub fn instantiate(
75+
&self,
76+
arguments: Arguments,
77+
include_debug_symbols: bool,
78+
) -> Result<CompiledProgram, String> {
7579
arguments
7680
.is_consistent(self.simfony.parameters())
7781
.map_err(|error| error.to_string())?;
7882
Ok(CompiledProgram {
7983
debug_symbols: self.simfony.debug_symbols(self.file.as_ref()),
8084
simplicity: self
8185
.simfony
82-
.compile(arguments)
86+
.compile(arguments, include_debug_symbols)
8387
.with_file(Arc::clone(&self.file))?,
8488
witness_types: self.simfony.witness_types().shallow_clone(),
8589
})
@@ -112,8 +116,13 @@ impl CompiledProgram {
112116
///
113117
/// - [`TemplateProgram::new`]
114118
/// - [`TemplateProgram::instantiate`]
115-
pub fn new<Str: Into<Arc<str>>>(s: Str, arguments: Arguments) -> Result<Self, String> {
116-
TemplateProgram::new(s).and_then(|template| template.instantiate(arguments))
119+
pub fn new<Str: Into<Arc<str>>>(
120+
s: Str,
121+
arguments: Arguments,
122+
include_debug_symbols: bool,
123+
) -> Result<Self, String> {
124+
TemplateProgram::new(s)
125+
.and_then(|template| template.instantiate(arguments, include_debug_symbols))
117126
}
118127

119128
/// Access the debug symbols for the Simplicity target code.
@@ -166,8 +175,9 @@ impl SatisfiedProgram {
166175
s: Str,
167176
arguments: Arguments,
168177
witness_values: WitnessValues,
178+
include_debug_symbols: bool,
169179
) -> Result<Self, String> {
170-
let compiled = CompiledProgram::new(s, arguments)?;
180+
let compiled = CompiledProgram::new(s, arguments, include_debug_symbols)?;
171181
compiled.satisfy(witness_values)
172182
}
173183

@@ -295,7 +305,7 @@ mod tests {
295305
}
296306

297307
pub fn with_arguments(self, arguments: Arguments) -> TestCase<CompiledProgram> {
298-
let program = match self.program.instantiate(arguments) {
308+
let program = match self.program.instantiate(arguments, true) {
299309
Ok(x) => x,
300310
Err(error) => panic!("{error}"),
301311
};
@@ -585,7 +595,12 @@ fn main() {
585595
assert!(my_true());
586596
}
587597
"#;
588-
match SatisfiedProgram::new(prog_text, Arguments::default(), WitnessValues::default()) {
598+
match SatisfiedProgram::new(
599+
prog_text,
600+
Arguments::default(),
601+
WitnessValues::default(),
602+
false,
603+
) {
589604
Ok(_) => panic!("Accepted faulty program"),
590605
Err(error) => {
591606
if !error.contains("Expected expression of type `bool`, found type `()`") {

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn run() -> Result<(), String> {
2929
let prog_file = &args[1];
3030
let prog_path = std::path::Path::new(prog_file);
3131
let prog_text = std::fs::read_to_string(prog_path).map_err(|e| e.to_string())?;
32-
let compiled = CompiledProgram::new(prog_text, Arguments::default())?;
32+
let compiled = CompiledProgram::new(prog_text, Arguments::default(), false)?;
3333

3434
if args.len() >= 3 {
3535
let wit_file = &args[2];
@@ -73,7 +73,7 @@ fn run() -> Result<(), String> {
7373
let prog_file = &args[1];
7474
let prog_path = std::path::Path::new(prog_file);
7575
let prog_text = std::fs::read_to_string(prog_path).map_err(|e| e.to_string())?;
76-
let compiled = CompiledProgram::new(prog_text, Arguments::default())?;
76+
let compiled = CompiledProgram::new(prog_text, Arguments::default(), false)?;
7777

7878
let program_bytes = compiled.commit().encode_to_vec();
7979
println!(

src/witness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ mod tests {
236236
WitnessName::from_str_unchecked("A"),
237237
Value::u16(42),
238238
)]));
239-
match SatisfiedProgram::new(s, Arguments::default(), witness) {
239+
match SatisfiedProgram::new(s, Arguments::default(), witness, false) {
240240
Ok(_) => panic!("Ill-typed witness assignment was falsely accepted"),
241241
Err(error) => assert_eq!(
242242
"Witness `A` was declared with type `u32` but its assigned value is of type `u16`",
@@ -255,7 +255,7 @@ fn main() {
255255
assert!(jet::is_zero_32(f()));
256256
}"#;
257257

258-
match CompiledProgram::new(s, Arguments::default()) {
258+
match CompiledProgram::new(s, Arguments::default(), false) {
259259
Ok(_) => panic!("Witness outside main was falsely accepted"),
260260
Err(error) => {
261261
assert!(error

0 commit comments

Comments
 (0)