1818//!
1919//! The [`Compiler`] type compiles Leo programs into R1CS circuits.
2020
21- use crate :: { AstSnapshots , CompilerOptions , errors} ;
21+ use crate :: { CompilerOptions , errors} ;
2222
2323use leo_ast:: { AleoProgram , FunctionStub , Identifier , Library , NetworkName , NodeBuilder , ProgramId , Stub } ;
2424pub use leo_ast:: { Ast , DiGraph , Program } ;
@@ -92,8 +92,6 @@ pub struct Compiled {
9292
9393/// The primary entry point of the Leo compiler.
9494pub struct Compiler {
95- /// The path to where the compiler outputs all generated files.
96- output_directory : PathBuf ,
9795 /// The name of the compilation unit (program or library).
9896 pub unit_name : Option < String > ,
9997 /// When set, recompile under this on-chain name instead of the one the source
@@ -178,11 +176,6 @@ impl Compiler {
178176
179177 self . state . ast = Ast :: Program ( program) ;
180178
181- if self . compiler_options . initial_ast {
182- self . write_ast_to_json ( "initial.json" ) ?;
183- self . write_ast ( "initial.ast" ) ?;
184- }
185-
186179 Ok ( ( ) )
187180 }
188181
@@ -253,11 +246,6 @@ impl Compiler {
253246 self . unit_name = Some ( library_name. to_string ( ) ) ;
254247 }
255248
256- if self . compiler_options . initial_ast {
257- self . write_ast_to_json ( "initial.json" ) ?;
258- self . write_ast ( "initial.ast" ) ?;
259- }
260-
261249 Ok ( ( ) )
262250 }
263251
@@ -329,7 +317,6 @@ impl Compiler {
329317 is_test : bool ,
330318 handler : Handler ,
331319 node_builder : Rc < NodeBuilder > ,
332- output_directory : PathBuf ,
333320 compiler_options : Option < CompilerOptions > ,
334321 import_stubs : IndexMap < Symbol , Stub > ,
335322 network : NetworkName ,
@@ -342,7 +329,6 @@ impl Compiler {
342329 network,
343330 ..Default :: default ( )
344331 } ,
345- output_directory,
346332 unit_name : expected_unit_name,
347333 rename : None ,
348334 compiler_options : compiler_options. unwrap_or_default ( ) ,
@@ -356,23 +342,13 @@ impl Compiler {
356342 }
357343
358344 /// Runs a compiler pass and checks whether the caller still wants the
359- /// result once the pass and any requested snapshots have completed.
345+ /// result once the pass has completed.
360346 fn do_pass_with_check < P : Pass , C > ( & mut self , input : P :: Input , should_continue : & mut C ) -> Result < P :: Output >
361347 where
362348 C : FnMut ( ) -> Result < ( ) > ,
363349 {
364350 let output = P :: do_pass ( input, & mut self . state ) ?;
365351
366- let write = match & self . compiler_options . ast_snapshots {
367- AstSnapshots :: All => true ,
368- AstSnapshots :: Some ( passes) => passes. contains ( P :: NAME ) ,
369- } ;
370-
371- if write {
372- self . write_ast_to_json ( & format ! ( "{}.json" , P :: NAME ) ) ?;
373- self . write_ast ( & format ! ( "{}.ast" , P :: NAME ) ) ?;
374- }
375-
376352 should_continue ( ) ?;
377353 Ok ( output)
378354 }
@@ -738,48 +714,6 @@ impl Compiler {
738714 }
739715 }
740716
741- /// Writes the AST to a JSON file under the unit's snapshots directory.
742- fn write_ast_to_json ( & self , filename : & str ) -> Result < ( ) > {
743- // No snapshots directory configured (parse-only preflight or LSP); skip rather than dump into the CWD.
744- if self . output_directory . as_os_str ( ) . is_empty ( ) {
745- return Ok ( ( ) ) ;
746- }
747- // Snapshots are opt-in; create the directory lazily on first write.
748- fs:: create_dir_all ( & self . output_directory )
749- . map_err ( |e| crate :: errors:: failed_ast_file ( self . output_directory . display ( ) , e) ) ?;
750- let dir = self . output_directory . clone ( ) ;
751- if self . compiler_options . ast_spans_enabled {
752- match & self . state . ast {
753- Ast :: Program ( program) => leo_ast:: write_ast_json ( program, dir, filename) ?,
754- Ast :: Library ( library) => leo_ast:: write_ast_json ( library, dir, filename) ?,
755- }
756- } else {
757- match & self . state . ast {
758- Ast :: Program ( program) => leo_ast:: write_ast_json_filtered ( program, dir, filename, & [ "_span" , "span" ] ) ?,
759- Ast :: Library ( library) => leo_ast:: write_ast_json_filtered ( library, dir, filename, & [ "_span" , "span" ] ) ?,
760- }
761- }
762- Ok ( ( ) )
763- }
764-
765- /// Writes the AST to a file (Leo syntax, not JSON) under the unit's snapshots directory.
766- fn write_ast ( & self , filename : & str ) -> Result < ( ) > {
767- // No snapshots directory configured (parse-only preflight or LSP); skip rather than dump into the CWD.
768- if self . output_directory . as_os_str ( ) . is_empty ( ) {
769- return Ok ( ( ) ) ;
770- }
771- // Snapshots are opt-in; create the directory lazily on first write.
772- fs:: create_dir_all ( & self . output_directory )
773- . map_err ( |e| crate :: errors:: failed_ast_file ( self . output_directory . display ( ) , e) ) ?;
774- let full_filename = self . output_directory . join ( filename) ;
775-
776- let contents = self . state . ast . to_string ( ) ;
777-
778- fs:: write ( & full_filename, contents) . map_err ( |e| crate :: errors:: failed_ast_file ( full_filename. display ( ) , e) ) ?;
779-
780- Ok ( ( ) )
781- }
782-
783717 /// Resolves and registers all import stubs for the current program.
784718 ///
785719 /// This method performs a graph traversal over the program’s import relationships to:
@@ -914,11 +848,9 @@ impl Compiler {
914848 false ,
915849 handler,
916850 node_builder,
917- PathBuf :: new ( ) ,
918851 Some ( CompilerOptions {
919852 // avoid infinite recursion
920853 no_std : true ,
921- ..CompilerOptions :: default ( )
922854 } ) ,
923855 IndexMap :: new ( ) ,
924856 network,
@@ -1228,7 +1160,6 @@ fn load_source_dependency_stub(
12281160 false ,
12291161 handler,
12301162 node_builder,
1231- PathBuf :: default ( ) ,
12321163 Some ( CompilerOptions :: default ( ) ) ,
12331164 IndexMap :: new ( ) ,
12341165 network,
@@ -1351,16 +1282,8 @@ mod tests {
13511282
13521283 let handler = Handler :: default ( ) ;
13531284 let node_builder = Rc :: new ( NodeBuilder :: default ( ) ) ;
1354- let mut compiler = Compiler :: new (
1355- None ,
1356- false ,
1357- handler,
1358- node_builder,
1359- PathBuf :: from ( "/unused" ) ,
1360- None ,
1361- IndexMap :: new ( ) ,
1362- NetworkName :: TestnetV0 ,
1363- ) ;
1285+ let mut compiler =
1286+ Compiler :: new ( None , false , handler, node_builder, None , IndexMap :: new ( ) , NetworkName :: TestnetV0 ) ;
13641287
13651288 let library = compiler
13661289 . parse_library_from_directory_with_file_source (
@@ -1402,7 +1325,6 @@ mod tests {
14021325 false ,
14031326 handler,
14041327 node_builder,
1405- PathBuf :: from ( "/unused" ) ,
14061328 None ,
14071329 IndexMap :: new ( ) ,
14081330 NetworkName :: TestnetV0 ,
@@ -1447,7 +1369,6 @@ mod tests {
14471369 false ,
14481370 handler,
14491371 node_builder,
1450- PathBuf :: from ( "/unused" ) ,
14511372 None ,
14521373 IndexMap :: new ( ) ,
14531374 NetworkName :: TestnetV0 ,
@@ -1479,7 +1400,6 @@ mod tests {
14791400 false ,
14801401 handler,
14811402 node_builder,
1482- PathBuf :: from ( "/unused" ) ,
14831403 None ,
14841404 IndexMap :: new ( ) ,
14851405 NetworkName :: TestnetV0 ,
@@ -1528,9 +1448,8 @@ mod tests {
15281448 false ,
15291449 handler,
15301450 node_builder,
1531- PathBuf :: new ( ) ,
15321451 // `no_std` avoids injecting `std` into itself.
1533- Some ( crate :: CompilerOptions { no_std : true , .. Default :: default ( ) } ) ,
1452+ Some ( crate :: CompilerOptions { no_std : true } ) ,
15341453 IndexMap :: new ( ) ,
15351454 NetworkName :: TestnetV0 ,
15361455 ) ;
0 commit comments