Skip to content

Commit c06ee6c

Browse files
authored
Exit early in compile_witgen_function. (#2379)
Uses the `?` operator to reduce indentation.
1 parent 60e9567 commit c06ee6c

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

Diff for: executor/src/witgen/jit/function_cache.rs

+36-34
Original file line numberDiff line numberDiff line change
@@ -100,45 +100,47 @@ impl<'a, T: FieldElement> FunctionCache<'a, T> {
100100
cache_key.known_args
101101
);
102102

103-
self.processor
103+
let code = self
104+
.processor
104105
.generate_code(can_process, cache_key.identity_id, &cache_key.known_args)
105106
.map_err(|e| {
106107
// These errors can be pretty verbose and are quite common currently.
107-
let e = e.to_string().lines().take(5).join("\n");
108-
log::debug!("=> Error generating JIT code: {e}\n...");
109-
e
108+
log::debug!(
109+
"=> Error generating JIT code: {}\n...",
110+
e.to_string().lines().take(5).join("\n")
111+
);
110112
})
111-
.ok()
112-
.map(|code| {
113-
log::debug!("=> Success!");
114-
let is_in_bounds = code
115-
.iter()
116-
.flat_map(|effect| effect.referenced_variables())
117-
.filter_map(|var| match var {
118-
Variable::Cell(cell) => Some(cell.row_offset),
119-
_ => None,
120-
})
121-
.all(|row_offset| row_offset >= -1 && row_offset < self.block_size as i32);
122-
assert!(is_in_bounds, "Expected JITed code to only reference cells in the block + the last row of the previous block.");
123-
124-
log::trace!("Generated code ({} steps)", code.len());
125-
let known_inputs = cache_key
126-
.known_args
127-
.iter()
128-
.enumerate()
129-
.filter_map(|(i, b)| if b { Some(Variable::Param(i)) } else { None })
130-
.collect::<Vec<_>>();
131-
132-
log::trace!("Compiling effects...");
133-
134-
compile_effects(
135-
self.column_layout.first_column_id,
136-
self.column_layout.column_count,
137-
&known_inputs,
138-
&code,
139-
)
140-
.unwrap()
113+
.ok()?;
114+
115+
log::debug!("=> Success!");
116+
let is_in_bounds = code
117+
.iter()
118+
.flat_map(|effect| effect.referenced_variables())
119+
.filter_map(|var| match var {
120+
Variable::Cell(cell) => Some(cell.row_offset),
121+
_ => None,
141122
})
123+
.all(|row_offset| row_offset >= -1 && row_offset < self.block_size as i32);
124+
assert!(is_in_bounds, "Expected JITed code to only reference cells in the block + the last row of the previous block.");
125+
126+
log::trace!("Generated code ({} steps)", code.len());
127+
let known_inputs = cache_key
128+
.known_args
129+
.iter()
130+
.enumerate()
131+
.filter_map(|(i, b)| if b { Some(Variable::Param(i)) } else { None })
132+
.collect::<Vec<_>>();
133+
134+
log::trace!("Compiling effects...");
135+
let effects = compile_effects(
136+
self.column_layout.first_column_id,
137+
self.column_layout.column_count,
138+
&known_inputs,
139+
&code,
140+
)
141+
.unwrap();
142+
log::trace!("Compilation done.");
143+
Some(effects)
142144
}
143145

144146
pub fn process_lookup_direct<'c, 'd, Q: QueryCallback<T>>(

0 commit comments

Comments
 (0)