From 991a658950691523f4f48f570c10c1b8a0650770 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu Date: Mon, 20 Sep 2021 18:12:03 -0700 Subject: [PATCH] Added build option to leo build --- compiler/src/compiler.rs | 24 ++++++++++++++++++++---- compiler/src/option.rs | 2 ++ compiler/src/test.rs | 1 + leo/commands/build.rs | 5 +++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index f09fead1ef..66bbe102c7 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -246,7 +246,11 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { let mut ast: leo_ast::Ast = parse_ast(self.main_file_path.to_str().unwrap_or_default(), program_string)?; if self.ast_snapshot_options.initial { - ast.to_json_file(self.output_directory.clone(), "initial_ast.json")?; + if !self.ast_snapshot_options.spans_enabled { + //TODO: Implement + } else { + ast.to_json_file(self.output_directory.clone(), "initial_ast.json")?; + } } // Preform import resolution. @@ -256,14 +260,22 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { )?; if self.ast_snapshot_options.imports_resolved { - ast.to_json_file(self.output_directory.clone(), "imports_resolved_ast.json")?; + if !self.ast_snapshot_options.spans_enabled { + //TODO: Implement + } else { + ast.to_json_file(self.output_directory.clone(), "imports_resolved_ast.json")?; + } } // Preform canonicalization of AST always. ast = leo_ast_passes::Canonicalizer::do_pass(ast.into_repr())?; if self.ast_snapshot_options.canonicalized { - ast.to_json_file(self.output_directory.clone(), "canonicalization_ast.json")?; + if !self.ast_snapshot_options.spans_enabled { + //TODO: Implement + } else { + ast.to_json_file(self.output_directory.clone(), "canonicalization_ast.json")?; + } } // Store the main program file. @@ -279,7 +291,11 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { let new_ast = TypeInferencePhase::default() .phase_ast(&self.program, &asg.clone().into_repr()) .expect("Failed to produce type inference ast."); - new_ast.to_json_file(self.output_directory.clone(), "type_inferenced_ast.json")?; + if self.ast_snapshot_options.spans_enabled { + //TODO: Implement + } else { + new_ast.to_json_file(self.output_directory.clone(), "type_inferenced_ast.json")?; + } } tracing::debug!("ASG generation complete"); diff --git a/compiler/src/option.rs b/compiler/src/option.rs index 024726c456..6daf13b16d 100644 --- a/compiler/src/option.rs +++ b/compiler/src/option.rs @@ -37,6 +37,7 @@ impl Default for CompilerOptions { #[derive(Clone)] pub struct AstSnapshotOptions { + pub spans_enabled: bool, pub initial: bool, pub imports_resolved: bool, pub canonicalized: bool, @@ -46,6 +47,7 @@ pub struct AstSnapshotOptions { impl Default for AstSnapshotOptions { fn default() -> Self { Self { + spans_enabled: false, initial: false, imports_resolved: false, canonicalized: false, diff --git a/compiler/src/test.rs b/compiler/src/test.rs index 89fd7b1fb2..c228b9f355 100644 --- a/compiler/src/test.rs +++ b/compiler/src/test.rs @@ -118,6 +118,7 @@ impl Namespace for CompileNamespace { let parsed = parse_program( &test.content, Some(AstSnapshotOptions { + spans_enabled: true, initial: true, imports_resolved: true, canonicalized: true, diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 7f377af9d2..a086684055 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -43,6 +43,8 @@ pub struct BuildOptions { pub disable_code_elimination: bool, #[structopt(long, help = "Disable all compiler optimizations")] pub disable_all_optimizations: bool, + #[structopt(long, help = "Enable spans in AST snapshots.")] + pub enable_spans: bool, #[structopt(long, help = "Writes all AST snapshots for the different compiler phases.")] pub enable_all_ast_snapshots: bool, #[structopt(long, help = "Writes AST snapshot of the initial parse.")] @@ -61,6 +63,7 @@ impl Default for BuildOptions { disable_constant_folding: false, disable_code_elimination: false, disable_all_optimizations: false, + enable_spans: false, enable_all_ast_snapshots: false, enable_initial_ast_snapshot: false, enable_imports_resolved_ast_snapshot: false, @@ -90,6 +93,7 @@ impl From for AstSnapshotOptions { fn from(options: BuildOptions) -> Self { if options.enable_all_ast_snapshots { AstSnapshotOptions { + spans_enabled: options.enable_spans, initial: true, imports_resolved: true, canonicalized: true, @@ -97,6 +101,7 @@ impl From for AstSnapshotOptions { } } else { AstSnapshotOptions { + spans_enabled: options.enable_spans, initial: options.enable_initial_ast_snapshot, imports_resolved: options.enable_imports_resolved_ast_snapshot, canonicalized: options.enable_canonicalized_ast_snapshot,