Skip to content

Commit a42e9c1

Browse files
committed
cleanup some imports
1 parent d4fbd08 commit a42e9c1

File tree

6 files changed

+20
-33
lines changed

6 files changed

+20
-33
lines changed

crates/lean_compiler/src/codegen/compiler.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::codegen::function::compile_function;
12
use crate::{ir::*, lang::*};
23
use lean_vm::*;
34
use std::collections::BTreeMap;
@@ -39,7 +40,7 @@ impl Compiler {
3940
let mut memory_sizes = BTreeMap::new();
4041

4142
for function in simple_program.functions.values() {
42-
let instructions = crate::codegen::function::compile_function(function, self)?;
43+
let instructions = compile_function(function, self)?;
4344
self.bytecode
4445
.insert(Label::function(&function.name), instructions);
4546
memory_sizes.insert(function.name.clone(), self.stack_size);
@@ -108,7 +109,7 @@ mod tests {
108109
n_returned_vars: 1,
109110
};
110111

111-
let result = crate::codegen::function::compile_function(&function, &mut compiler);
112+
let result = compile_function(&function, &mut compiler);
112113
assert!(result.is_ok());
113114

114115
assert_eq!(compiler.func_name, "test");

crates/lean_compiler/src/codegen/function.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::codegen::{instruction::compile_lines, memory::find_internal_vars};
12
use crate::{codegen::*, ir::*, lang::*};
23
use std::collections::{BTreeMap, BTreeSet};
34

@@ -9,7 +10,7 @@ pub fn compile_function(
910
function: &SimpleFunction,
1011
compiler: &mut Compiler,
1112
) -> Result<Vec<IntermediateInstruction>, String> {
12-
let mut internal_vars = crate::codegen::memory::find_internal_vars(&function.instructions);
13+
let mut internal_vars = find_internal_vars(&function.instructions);
1314
internal_vars.retain(|var| !function.arguments.contains(var));
1415

1516
// memory layout: pc, fp, args, return_vars, internal_vars
@@ -34,12 +35,7 @@ pub fn compile_function(
3435
compiler.args_count = function.arguments.len();
3536

3637
let mut declared_vars: BTreeSet<Var> = function.arguments.iter().cloned().collect();
37-
crate::codegen::instruction::compile_lines(
38-
&function.instructions,
39-
compiler,
40-
None,
41-
&mut declared_vars,
42-
)
38+
compile_lines(&function.instructions, compiler, None, &mut declared_vars)
4339
}
4440

4541
#[cfg(test)]

crates/lean_compiler/src/ir/conversion.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use super::{
2+
HighLevelOperation,
23
types::{
34
ArrayAccessType, ArrayManager, ConstMalloc, Counters, SimpleFunction, SimpleLine,
45
VarOrConstMallocAccess,
56
},
67
utilities::find_variable_usage,
78
};
8-
use crate::{
9-
ir::HighLevelOperation,
10-
lang::{Boolean, ConstExpression, Expression, Line, SimpleExpr, Var},
11-
};
9+
use crate::lang::{Boolean, ConstExpression, Expression, Line, SimpleExpr, Var};
1210
use std::collections::BTreeMap;
1311
use utils::ToUsize;
1412

@@ -764,8 +762,7 @@ fn create_recursive_function(
764762
#[cfg(test)]
765763
mod tests {
766764
use super::*;
767-
use crate::ir::types::*;
768-
use crate::{ir::HighLevelOperation, lang::*};
765+
use crate::lang::*;
769766

770767
fn create_test_counters() -> Counters {
771768
Counters::default()

crates/lean_compiler/src/ir/value.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::backend::evaluation::{CodeGenerator, eval_const_expression_usize, try_as_constant};
12
use crate::lang::{ConstExpression, SimpleExpr};
23
use lean_vm::Label;
34
use std::fmt::{Display, Formatter};
@@ -59,13 +60,10 @@ impl IntermediateValue {
5960
}
6061

6162
/// Converts this value to a MemOrFp for low-level code generation.
62-
pub fn try_into_mem_or_fp(
63-
&self,
64-
compiler: &crate::backend::evaluation::CodeGenerator,
65-
) -> Result<lean_vm::MemOrFp, String> {
63+
pub fn try_into_mem_or_fp(&self, compiler: &CodeGenerator) -> Result<lean_vm::MemOrFp, String> {
6664
match self {
6765
Self::MemoryAfterFp { offset } => Ok(lean_vm::MemOrFp::MemoryAfterFp {
68-
offset: crate::backend::evaluation::eval_const_expression_usize(offset, compiler),
66+
offset: eval_const_expression_usize(offset, compiler),
6967
}),
7068
Self::Fp => Ok(lean_vm::MemOrFp::Fp),
7169
_ => Err(format!("Cannot convert {self:?} to MemOrFp")),
@@ -75,14 +73,14 @@ impl IntermediateValue {
7573
/// Converts this value to a MemOrConstant for low-level code generation.
7674
pub fn try_into_mem_or_constant(
7775
&self,
78-
compiler: &crate::backend::evaluation::CodeGenerator,
76+
compiler: &CodeGenerator,
7977
) -> Result<lean_vm::MemOrConstant, String> {
80-
if let Some(cst) = crate::backend::evaluation::try_as_constant(self, compiler) {
78+
if let Some(cst) = try_as_constant(self, compiler) {
8179
return Ok(lean_vm::MemOrConstant::Constant(cst));
8280
}
8381
if let Self::MemoryAfterFp { offset } = self {
8482
return Ok(lean_vm::MemOrConstant::MemoryAfterFp {
85-
offset: crate::backend::evaluation::eval_const_expression_usize(offset, compiler),
83+
offset: eval_const_expression_usize(offset, compiler),
8684
});
8785
}
8886
Err(format!("Cannot convert {self:?} to MemOrConstant"))

crates/lean_compiler/src/lang/values/constant.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use p3_util::log2_ceil_usize;
44
use std::fmt::{Display, Formatter};
55
use utils::ToUsize;
66

7+
use crate::lang::ast::{Expression, SimpleExpr};
78
use crate::{F, ir::HighLevelOperation};
89

910
/// Constant value types for compile-time computation.
@@ -108,11 +109,10 @@ impl ConstExpression {
108109
}
109110
}
110111

111-
impl TryFrom<crate::lang::ast::Expression> for ConstExpression {
112+
impl TryFrom<Expression> for ConstExpression {
112113
type Error = ();
113114

114-
fn try_from(value: crate::lang::ast::Expression) -> Result<Self, Self::Error> {
115-
use crate::lang::ast::{Expression, SimpleExpr};
115+
fn try_from(value: Expression) -> Result<Self, Self::Error> {
116116
match value {
117117
Expression::Value(SimpleExpr::Constant(const_expr)) => Ok(const_expr),
118118
Expression::Value(_) => Err(()),
@@ -318,8 +318,6 @@ mod tests {
318318

319319
#[test]
320320
fn test_const_expression_try_from() {
321-
use crate::lang::ast::{Expression, SimpleExpr};
322-
323321
// Test successful conversion
324322
let const_expr = ConstExpression::scalar(10);
325323
let expr = Expression::Value(SimpleExpr::Constant(const_expr.clone()));

crates/lean_compiler/src/passes/ast_to_ir.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
//! ready for code generation.
88
99
use super::{Pass, PassResult};
10-
use crate::ir::{
11-
SimpleProgram, conversion,
12-
types::{ArrayManager, ConstMalloc, Counters},
13-
};
10+
use crate::ir::{ArrayManager, ConstMalloc, Counters, SimpleFunction, SimpleProgram, conversion};
1411
use crate::lang::Program;
1512
use std::collections::BTreeMap;
1613

@@ -71,7 +68,7 @@ impl AstToIrPass {
7168
.collect();
7269

7370
// Create the IR function
74-
let ir_function = crate::ir::types::SimpleFunction {
71+
let ir_function = SimpleFunction {
7572
name: name.clone(),
7673
arguments: ir_arguments,
7774
n_returned_vars: ast_function.n_returned_vars,

0 commit comments

Comments
 (0)