@@ -59,6 +59,9 @@ use super::{
59
59
} ;
60
60
use crate :: types:: instance_definitions:: mod_instance_def:: ModInstanceDef ;
61
61
62
+ type ProcessBuiltinSegmentClosure =
63
+ fn ( usize , Option < usize > , BuiltinName ) -> Result < Option < ( usize , usize ) > , RunnerError > ;
64
+
62
65
#[ derive( Clone , Debug , Eq , PartialEq ) ]
63
66
pub enum CairoArg {
64
67
Single ( MaybeRelocatable ) ,
@@ -1012,15 +1015,30 @@ impl CairoRunner {
1012
1015
// Returns a map from builtin base's segment index to stop_ptr offset
1013
1016
// Aka the builtin's segment number and its maximum offset
1014
1017
pub fn get_builtin_segments_info ( & self ) -> Result < Vec < ( usize , usize ) > , RunnerError > {
1015
- let mut builtin_segment_info = Vec :: new ( ) ;
1018
+ let proof_mode = self . is_proof_mode ( ) ;
1019
+
1020
+ // Closure to process each builtin's segment info based on whether we are in proof mode or not.
1021
+ let process: ProcessBuiltinSegmentClosure = if proof_mode {
1022
+ // In proof‐mode there are builtin runners for all builtins in the layout, but only the ones
1023
+ // that are in the program point to a segment (so `stop_ptr` is set).
1024
+ // Only collect those and silently ignore the rest.
1025
+ |index, stop_ptr, _| Ok ( stop_ptr. map ( |sp| ( index, sp) ) )
1026
+ } else {
1027
+ // If non proof-mode, only builtins in the program are present and they must
1028
+ // point to a segment (so `stop_ptr` must be set). Throw an error if not.
1029
+ |index, stop_ptr, name| {
1030
+ let sp = stop_ptr
1031
+ . ok_or_else ( || RunnerError :: NoStopPointer ( Box :: new ( name. to_owned ( ) ) ) ) ?;
1032
+ Ok ( Some ( ( index, sp) ) )
1033
+ }
1034
+ } ;
1016
1035
1036
+ let mut builtin_segment_info = Vec :: new ( ) ;
1017
1037
for builtin in & self . vm . builtin_runners {
1018
1038
let ( index, stop_ptr) = builtin. get_memory_segment_addresses ( ) ;
1019
-
1020
- builtin_segment_info. push ( (
1021
- index,
1022
- stop_ptr. ok_or_else ( || RunnerError :: NoStopPointer ( Box :: new ( builtin. name ( ) ) ) ) ?,
1023
- ) ) ;
1039
+ if let Some ( pair) = process ( index, stop_ptr, builtin. name ( ) ) ? {
1040
+ builtin_segment_info. push ( pair) ;
1041
+ }
1024
1042
}
1025
1043
1026
1044
Ok ( builtin_segment_info)
0 commit comments