@@ -5,6 +5,7 @@ use anyhow::{Context, Result};
5
5
use cairo_lang_compiler:: db:: RootDatabase ;
6
6
use cairo_lang_compiler:: diagnostics:: DiagnosticsReporter ;
7
7
use cairo_lang_compiler:: project:: setup_project;
8
+ use cairo_lang_debug:: debug:: DebugWithDb ;
8
9
use cairo_lang_filesystem:: cfg:: { Cfg , CfgSet } ;
9
10
use cairo_lang_filesystem:: ids:: CrateId ;
10
11
use cairo_lang_lowering:: ids:: ConcreteFunctionWithBodyId ;
@@ -141,13 +142,30 @@ pub fn compile_executable_function_in_prepared_db(
141
142
mut diagnostics_reporter : DiagnosticsReporter < ' _ > ,
142
143
) -> Result < CompiledFunction > {
143
144
diagnostics_reporter. ensure ( db) ?;
144
- let SierraProgramWithDebug { program : sierra_program, debug_info : _ } = Arc :: unwrap_or_clone (
145
+ let SierraProgramWithDebug { program : sierra_program, debug_info } = Arc :: unwrap_or_clone (
145
146
db. get_sierra_program_for_functions ( vec ! [ executable] )
146
147
. ok ( )
147
148
. with_context ( || "Compilation failed without any diagnostics." ) ?,
148
149
) ;
150
+
149
151
let executable_func = sierra_program. funcs [ 0 ] . clone ( ) ;
150
- let builder = RunnableBuilder :: new ( sierra_program, None ) ?;
152
+ let builder = RunnableBuilder :: new ( sierra_program, None ) . map_err ( |err| {
153
+ let mut locs = vec ! [ ] ;
154
+ for stmt_idx in err. stmt_indices ( ) {
155
+ if let Some ( loc) = debug_info
156
+ . statements_locations
157
+ . locations
158
+ . get ( & stmt_idx)
159
+ . and_then ( |stmt_locs| stmt_locs. first ( ) )
160
+ {
161
+ locs. push ( format ! ( "#{stmt_idx} {:?}" , loc. diagnostic_location( db) . debug( db) ) )
162
+ }
163
+ }
164
+
165
+ anyhow:: anyhow!( "Failed to create runnable builder: {}\n {}" , err, locs. join( "\n " ) )
166
+ }
167
+ ) ?;
168
+
151
169
let wrapper = builder. create_wrapper_info ( & executable_func, EntryCodeConfig :: executable ( ) ) ?;
152
170
Ok ( CompiledFunction { program : builder. casm_program ( ) . clone ( ) , wrapper } )
153
171
}
0 commit comments