Skip to content

Commit e5a69c7

Browse files
committed
Remove the --enable-dce option.
This option has been meaningless since the last release when DCE was enabled by default. Talking with users during the Leo dev call seems to indicate nobody minds if we just get rid of it. Also remove the analogous member from CompilerOptions and stop doing two cases (DCE enabled and disabled) for compiler tests. We should probably create a way to test individual passes, but I don't think we need to single out DCE specifically and run every test with it enabled and disabled.
1 parent 0ac8a24 commit e5a69c7

File tree

916 files changed

+32
-30571
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

916 files changed

+32
-30571
lines changed

compiler/compiler/src/compiler.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<N: Network> Compiler<N> {
8181
.into());
8282
}
8383

84-
if self.compiler_options.output.initial_ast {
84+
if self.compiler_options.initial_ast {
8585
self.write_ast_to_json("initial.json")?;
8686
self.write_ast("initial.ast")?;
8787
}
@@ -120,7 +120,7 @@ impl<N: Network> Compiler<N> {
120120
fn do_pass<P: Pass>(&mut self, input: P::Input) -> Result<P::Output> {
121121
let output = P::do_pass(input, &mut self.state)?;
122122

123-
let write = match &self.compiler_options.output.ast_snapshots {
123+
let write = match &self.compiler_options.ast_snapshots {
124124
AstSnapshots::All => true,
125125
AstSnapshots::Some(passes) => passes.contains(P::NAME),
126126
};
@@ -163,11 +163,9 @@ impl<N: Network> Compiler<N> {
163163

164164
self.do_pass::<FunctionInlining>(())?;
165165

166-
if self.compiler_options.build.dce_enabled {
167-
let output = self.do_pass::<DeadCodeEliminating>(())?;
168-
self.statements_before_dce = output.statements_before;
169-
self.statements_after_dce = output.statements_after;
170-
}
166+
let output = self.do_pass::<DeadCodeEliminating>(())?;
167+
self.statements_before_dce = output.statements_before;
168+
self.statements_after_dce = output.statements_after;
171169

172170
Ok(())
173171
}
@@ -194,7 +192,7 @@ impl<N: Network> Compiler<N> {
194192
/// Writes the AST to a JSON file.
195193
fn write_ast_to_json(&self, file_suffix: &str) -> Result<()> {
196194
// Remove `Span`s if they are not enabled.
197-
if self.compiler_options.output.ast_spans_enabled {
195+
if self.compiler_options.ast_spans_enabled {
198196
self.state.ast.to_json_file(
199197
self.output_directory.clone(),
200198
&format!("{}.{file_suffix}", self.program_name.as_ref().unwrap()),

compiler/compiler/src/options.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,14 @@
1818

1919
use std::collections::HashSet;
2020

21-
#[derive(Clone, Default)]
21+
#[derive(Clone, Debug, Default)]
2222
pub struct CompilerOptions {
23-
/// Build options.
24-
pub build: BuildOptions,
25-
/// Output options.
26-
pub output: OutputOptions,
27-
}
23+
/// Whether spans are enabled in the output ASTs.
24+
pub ast_spans_enabled: bool,
2825

29-
#[derive(Clone)]
30-
pub struct BuildOptions {
31-
/// Whether to enable dead code elimination.
32-
pub dce_enabled: bool,
33-
}
26+
pub ast_snapshots: AstSnapshots,
3427

35-
impl Default for BuildOptions {
36-
fn default() -> Self {
37-
Self { dce_enabled: true }
38-
}
28+
pub initial_ast: bool,
3929
}
4030

4131
#[derive(Clone, Debug)]
@@ -49,13 +39,3 @@ impl Default for AstSnapshots {
4939
AstSnapshots::Some(Default::default())
5040
}
5141
}
52-
53-
#[derive(Clone, Debug, Default)]
54-
pub struct OutputOptions {
55-
/// Whether spans are enabled in the output ASTs.
56-
pub ast_spans_enabled: bool,
57-
58-
pub ast_snapshots: AstSnapshots,
59-
60-
pub initial_ast: bool,
61-
}

compiler/compiler/src/test_compiler.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use crate::{BuildOptions, Compiler, CompilerOptions};
17+
use crate::Compiler;
1818

1919
use leo_ast::Stub;
2020
use leo_disassembler::disassemble_from_str;
@@ -35,18 +35,15 @@ pub const PROGRAM_DELIMITER: &str = "// --- Next Program --- //";
3535

3636
pub fn whole_compile(
3737
source: &str,
38-
dce_enabled: bool,
3938
handler: &Handler,
4039
import_stubs: IndexMap<Symbol, Stub>,
4140
) -> Result<(String, String), LeoError> {
42-
let options = CompilerOptions { build: BuildOptions { dce_enabled }, ..Default::default() };
43-
4441
let mut compiler = Compiler::<TestnetV0>::new(
4542
None,
4643
/* is_test (a Leo test) */ false,
4744
handler.clone(),
4845
"/fakedirectory-wont-use".into(),
49-
Some(options),
46+
None,
5047
import_stubs,
5148
);
5249

@@ -57,7 +54,7 @@ pub fn whole_compile(
5754
Ok((bytecode, compiler.program_name.unwrap()))
5855
}
5956

60-
fn run_test(test: &str, dce_enabled: bool, handler: &Handler) -> Result<String, ()> {
57+
fn run_test(test: &str, handler: &Handler) -> Result<String, ()> {
6158
// Initialize a `Process`. This should always succeed.
6259
let mut process = Process::<TestnetV0>::load().unwrap();
6360

@@ -67,8 +64,7 @@ fn run_test(test: &str, dce_enabled: bool, handler: &Handler) -> Result<String,
6764

6865
// Compile each source file separately.
6966
for source in test.split(PROGRAM_DELIMITER) {
70-
let (bytecode, program_name) =
71-
handler.extend_if_error(whole_compile(source, dce_enabled, handler, import_stubs.clone()))?;
67+
let (bytecode, program_name) = handler.extend_if_error(whole_compile(source, handler, import_stubs.clone()))?;
7268

7369
// Parse the bytecode as an Aleo program.
7470
// Note that this function checks that the bytecode is well-formed.
@@ -95,21 +91,13 @@ fn run_test(test: &str, dce_enabled: bool, handler: &Handler) -> Result<String,
9591
}
9692

9793
fn runner(source: &str) -> String {
98-
fn run(source: &str, dce_enabled: bool) -> String {
99-
let buf = BufferEmitter::new();
100-
let handler = Handler::new(buf.clone());
101-
102-
match run_test(source, dce_enabled, &handler) {
103-
Ok(x) => format!("{}{}", buf.extract_warnings(), x),
104-
Err(()) => format!("{}{}", buf.extract_errs(), buf.extract_warnings()),
105-
}
106-
}
107-
108-
let with_dce_enabled = create_session_if_not_set_then(|_| run(source, true));
109-
110-
let with_dce_disabled = create_session_if_not_set_then(|_| run(source, false));
94+
let buf = BufferEmitter::new();
95+
let handler = Handler::new(buf.clone());
11196

112-
format!("DCE_ENABLED:\n{with_dce_enabled}\nDCE_DISABLED:\n{with_dce_disabled}")
97+
create_session_if_not_set_then(|_| match run_test(source, &handler) {
98+
Ok(x) => format!("{}{}", buf.extract_warnings(), x),
99+
Err(()) => format!("{}{}", buf.extract_errs(), buf.extract_warnings()),
100+
})
113101
}
114102

115103
#[test]

leo/cli/commands/build.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use super::*;
1818

1919
use leo_ast::Stub;
20-
use leo_compiler::{AstSnapshots, Compiler, CompilerOptions, OutputOptions};
20+
use leo_compiler::{AstSnapshots, Compiler, CompilerOptions};
2121
use leo_errors::{CliError, UtilError};
2222
use leo_package::{Manifest, NetworkName, Package};
2323
use leo_span::Symbol;
@@ -31,16 +31,13 @@ use std::path::Path;
3131
impl From<BuildOptions> for CompilerOptions {
3232
fn from(options: BuildOptions) -> Self {
3333
Self {
34-
build: leo_compiler::BuildOptions { dce_enabled: options.enable_dce },
35-
output: OutputOptions {
36-
ast_spans_enabled: options.enable_ast_spans,
37-
ast_snapshots: if options.enable_all_ast_snapshots {
38-
AstSnapshots::All
39-
} else {
40-
AstSnapshots::Some(options.ast_snapshots.into_iter().collect())
41-
},
42-
initial_ast: options.enable_all_ast_snapshots | options.enable_initial_ast_snapshot,
34+
ast_spans_enabled: options.enable_ast_spans,
35+
ast_snapshots: if options.enable_all_ast_snapshots {
36+
AstSnapshots::All
37+
} else {
38+
AstSnapshots::Some(options.ast_snapshots.into_iter().collect())
4339
},
40+
initial_ast: options.enable_all_ast_snapshots | options.enable_initial_ast_snapshot,
4441
}
4542
}
4643
}
@@ -164,8 +161,6 @@ fn compile_leo_file<N: Network>(
164161
options: BuildOptions,
165162
stubs: IndexMap<Symbol, Stub>,
166163
) -> Result<String> {
167-
let enable_dce = options.enable_dce;
168-
169164
// Create a new instance of the Leo compiler.
170165
let mut compiler = Compiler::<N>::new(
171166
Some(program_name.to_string()),
@@ -179,10 +174,9 @@ fn compile_leo_file<N: Network>(
179174
// Compile the Leo program into Aleo instructions.
180175
let bytecode = compiler.compile_from_file(source_file_path)?;
181176

182-
if enable_dce {
183-
tracing::info!(" {} statements before dead code elimination.", compiler.statements_before_dce);
184-
tracing::info!(" {} statements after dead code elimination.", compiler.statements_after_dce);
185-
}
177+
tracing::info!(" {} statements before dead code elimination.", compiler.statements_before_dce);
178+
tracing::info!(" {} statements after dead code elimination.", compiler.statements_after_dce);
179+
186180
tracing::info!("✅ Compiled '{program_name}.aleo' into Aleo instructions");
187181
Ok(bytecode)
188182
}

leo/cli/commands/mod.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub trait Command {
133133

134134
/// Compiler Options wrapper for Build command. Also used by other commands which
135135
/// require Build command output as their input.
136-
#[derive(Parser, Clone, Debug)]
136+
#[derive(Parser, Clone, Debug, Default)]
137137
pub struct BuildOptions {
138138
#[clap(long, help = "Endpoint to retrieve network state from. Overrides setting in `.env`.")]
139139
pub endpoint: Option<String>,
@@ -145,8 +145,6 @@ pub struct BuildOptions {
145145
pub offline: bool,
146146
#[clap(long, help = "Enable spans in AST snapshots.")]
147147
pub enable_ast_spans: bool,
148-
#[clap(long, help = "Enables dead code elimination in the compiler.", default_value = "true")]
149-
pub enable_dce: bool,
150148
#[clap(long, help = "Write an AST snapshot immediately after parsing.")]
151149
pub enable_initial_ast_snapshot: bool,
152150
#[clap(long, help = "Writes all AST snapshots for the different compiler phases.")]
@@ -157,23 +155,6 @@ pub struct BuildOptions {
157155
pub build_tests: bool,
158156
}
159157

160-
impl Default for BuildOptions {
161-
fn default() -> Self {
162-
Self {
163-
endpoint: None,
164-
network: None,
165-
non_recursive: false,
166-
offline: false,
167-
enable_ast_spans: false,
168-
enable_dce: true,
169-
enable_initial_ast_snapshot: false,
170-
enable_all_ast_snapshots: false,
171-
ast_snapshots: Vec::new(),
172-
build_tests: false,
173-
}
174-
}
175-
}
176-
177158
/// On Chain Execution Options to set preferences for keys, fees and networks.
178159
/// Used by Execute and Deploy commands.
179160
#[derive(Parser, Clone, Debug, Default)]
Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
DCE_ENABLED:
21
program test.aleo;
32

43
function main:
54
input r0 as address.private;
65
is.neq r0 aleo1fj982yqchhy973kz7e9jk6er7t6qd6jm9anplnlprem507w6lv9spwvfxx into r1;
76
output r1 as boolean.private;
8-
9-
DCE_DISABLED:
10-
program test.aleo;
11-
12-
function main:
13-
input r0 as address.private;
14-
is.eq r0 aleo1fj982yqchhy973kz7e9jk6er7t6qd6jm9anplnlprem507w6lv9spwvfxx into r1;
15-
is.neq r0 aleo1fj982yqchhy973kz7e9jk6er7t6qd6jm9anplnlprem507w6lv9spwvfxx into r2;
16-
output r2 as boolean.private;

tests/expectations/compiler/address/branch.out

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
DCE_ENABLED:
2-
program test.aleo;
3-
4-
function main:
5-
input r0 as address.private;
6-
input r1 as boolean.private;
7-
ternary r1 aleo16s003g206rjms5pm4ak48340f7y4z4dsskuqfrd2gvqz6umh2qfq7lajfp aleo1fj982yqchhy973kz7e9jk6er7t6qd6jm9anplnlprem507w6lv9spwvfxx into r2;
8-
is.eq r2 aleo1drcl2g8zxhxjzjw63ajp067gzvl94am3z7m7wgrzmr2ecd5sdq8sy66l5k into r3;
9-
output r3 as boolean.private;
10-
11-
DCE_DISABLED:
121
program test.aleo;
132

143
function main:

tests/expectations/compiler/address/equal.out

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
DCE_ENABLED:
2-
program test.aleo;
3-
4-
function main:
5-
input r0 as address.private;
6-
is.eq r0 aleo10qerras5799u6k7rjtc9y3hcwxuykr45qra7x7dp6jgnc0923czqm0lgta into r1;
7-
output r1 as boolean.private;
8-
9-
DCE_DISABLED:
101
program test.aleo;
112

123
function main:

tests/expectations/compiler/address/gt_fail.out

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
DCE_ENABLED:
2-
Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found.
3-
--> compiler-test:6:16
4-
|
5-
6 | return x > sender;
6-
| ^
7-
Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found.
8-
--> compiler-test:6:20
9-
|
10-
6 | return x > sender;
11-
| ^^^^^^
12-
Error [ETYC0372083]: A program must have at least one transition function.
13-
--> compiler-test:2:9
14-
|
15-
2 | program test.aleo {
16-
| ^^^^^^^^^
17-
18-
DCE_DISABLED:
191
Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found.
202
--> compiler-test:6:16
213
|

tests/expectations/compiler/address/gte_fail.out

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
DCE_ENABLED:
2-
Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found.
3-
--> compiler-test:6:16
4-
|
5-
6 | return x >= sender;
6-
| ^
7-
Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found.
8-
--> compiler-test:6:21
9-
|
10-
6 | return x >= sender;
11-
| ^^^^^^
12-
Error [ETYC0372083]: A program must have at least one transition function.
13-
--> compiler-test:2:9
14-
|
15-
2 | program test.aleo {
16-
| ^^^^^^^^^
17-
18-
DCE_DISABLED:
191
Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found.
202
--> compiler-test:6:16
213
|

tests/expectations/compiler/address/lt_fail.out

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
DCE_ENABLED:
2-
Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found.
3-
--> compiler-test:6:16
4-
|
5-
6 | return x < sender;
6-
| ^
7-
Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found.
8-
--> compiler-test:6:20
9-
|
10-
6 | return x < sender;
11-
| ^^^^^^
12-
Error [ETYC0372083]: A program must have at least one transition function.
13-
--> compiler-test:2:9
14-
|
15-
2 | program test.aleo {
16-
| ^^^^^^^^^
17-
18-
DCE_DISABLED:
191
Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found.
202
--> compiler-test:6:16
213
|

tests/expectations/compiler/address/lte_fail.out

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
DCE_ENABLED:
2-
Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found.
3-
--> compiler-test:6:16
4-
|
5-
6 | return x <= sender;
6-
| ^
7-
Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found.
8-
--> compiler-test:6:21
9-
|
10-
6 | return x <= sender;
11-
| ^^^^^^
12-
Error [ETYC0372083]: A program must have at least one transition function.
13-
--> compiler-test:2:9
14-
|
15-
2 | program test.aleo {
16-
| ^^^^^^^^^
17-
18-
DCE_DISABLED:
191
Error [ETYC0372117]: Expected a field, scalar, or integer but type `address` was found.
202
--> compiler-test:6:16
213
|

0 commit comments

Comments
 (0)