Skip to content

Commit 990a95e

Browse files
committed
Merge branch 'remove-vec-alloc' into lean-vm-simple
2 parents 85e887b + b2d59e5 commit 990a95e

File tree

25 files changed

+261
-540
lines changed

25 files changed

+261
-540
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ RUSTFLAGS='-C target-cpu=native' cargo run --release -- recursion --count 18
5656
### XMSS aggregation
5757

5858
```console
59-
RUSTFLAGS='-C target-cpu=native' cargo run --release -- xmss --n-signatures 1200
59+
RUSTFLAGS='-C target-cpu=native' cargo run --release -- xmss --n-signatures 1250
6060
```
6161

6262
[Trivial encoding](docs/XMSS_trivial_encoding.pdf) (for now).

crates/lean_compiler/src/a_simplify_lang.rs

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ pub enum SimpleLine {
135135
HintMAlloc {
136136
var: Var,
137137
size: SimpleExpr,
138-
vectorized: bool,
139-
vectorized_len: SimpleExpr,
140138
},
141139
ConstMalloc {
142140
// always not vectorized
@@ -308,11 +306,8 @@ fn check_block_scoping(block: &[Line], ctx: &mut Context) {
308306
Line::MAlloc {
309307
var,
310308
size,
311-
vectorized: _,
312-
vectorized_len,
313309
} => {
314310
check_expr_scoping(size, ctx);
315-
check_expr_scoping(vectorized_len, ctx);
316311
let last_scope = ctx.scopes.last_mut().unwrap();
317312
assert!(
318313
!last_scope.vars.contains(var),
@@ -808,17 +803,10 @@ fn simplify_lines(
808803
assert!(in_a_loop, "Break statement outside of a loop");
809804
res.push(SimpleLine::FunctionRet { return_data: vec![] });
810805
}
811-
Line::MAlloc {
812-
var,
813-
size,
814-
vectorized,
815-
vectorized_len,
816-
} => {
806+
Line::MAlloc { var, size } => {
817807
let simplified_size = simplify_expr(size, &mut res, counters, array_manager, const_malloc);
818-
let simplified_vectorized_len =
819-
simplify_expr(vectorized_len, &mut res, counters, array_manager, const_malloc);
820808
match simplified_size {
821-
SimpleExpr::Constant(const_size) if !*vectorized => {
809+
SimpleExpr::Constant(const_size) => {
822810
let label = const_malloc.counter;
823811
const_malloc.counter += 1;
824812
const_malloc.map.insert(var.clone(), label);
@@ -832,8 +820,6 @@ fn simplify_lines(
832820
res.push(SimpleLine::HintMAlloc {
833821
var: var.clone(),
834822
size: simplified_size,
835-
vectorized: *vectorized,
836-
vectorized_len: simplified_vectorized_len,
837823
});
838824
}
839825
}
@@ -1537,16 +1523,10 @@ fn replace_vars_for_unroll(
15371523
replace_vars_for_unroll_in_expr(var, iterator, unroll_index, iterator_value, internal_vars);
15381524
}
15391525
}
1540-
Line::MAlloc {
1541-
var,
1542-
size,
1543-
vectorized: _,
1544-
vectorized_len,
1545-
} => {
1526+
Line::MAlloc { var, size } => {
15461527
assert!(var != iterator, "Weird");
15471528
*var = format!("@unrolled_{unroll_index}_{iterator_value}_{var}");
15481529
replace_vars_for_unroll_in_expr(size, iterator, unroll_index, iterator_value, internal_vars);
1549-
replace_vars_for_unroll_in_expr(vectorized_len, iterator, unroll_index, iterator_value, internal_vars);
15501530
}
15511531
Line::DecomposeBits { var, to_decompose } => {
15521532
assert!(var != iterator, "Weird");
@@ -2170,17 +2150,8 @@ impl SimpleLine {
21702150
let content_str = content.iter().map(|c| format!("{c}")).collect::<Vec<_>>().join(", ");
21712151
format!("print({content_str})")
21722152
}
2173-
Self::HintMAlloc {
2174-
var,
2175-
size,
2176-
vectorized,
2177-
vectorized_len,
2178-
} => {
2179-
if *vectorized {
2180-
format!("{var} = malloc_vec({size}, {vectorized_len})")
2181-
} else {
2182-
format!("{var} = malloc({size})")
2183-
}
2153+
Self::HintMAlloc { var, size } => {
2154+
format!("{var} = malloc({size})")
21842155
}
21852156
Self::ConstMalloc { var, size, label: _ } => {
21862157
format!("{var} = malloc({size})")

crates/lean_compiler/src/b_compile_intermediate.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,6 @@ fn compile_lines(
486486
SimpleLine::HintMAlloc {
487487
var,
488488
size,
489-
vectorized,
490-
vectorized_len,
491489
} => {
492490
if !compiler.is_in_scope(var) {
493491
let current_scope_layout = compiler.stack_frame_layout.scopes.last_mut().unwrap();
@@ -499,8 +497,6 @@ fn compile_lines(
499497
instructions.push(IntermediateInstruction::RequestMemory {
500498
offset: compiler.get_offset(&var.clone().into()),
501499
size: IntermediateValue::from_simple_expr(size, compiler),
502-
vectorized: *vectorized,
503-
vectorized_len: IntermediateValue::from_simple_expr(vectorized_len, compiler),
504500
});
505501
}
506502
SimpleLine::ConstMalloc { var, size, label } => {
@@ -620,8 +616,6 @@ fn setup_function_call(
620616
IntermediateInstruction::RequestMemory {
621617
offset: new_fp_pos.into(),
622618
size: ConstExpression::function_size(Label::function(func_name)).into(),
623-
vectorized: false,
624-
vectorized_len: IntermediateValue::Constant(ConstExpression::zero()),
625619
},
626620
IntermediateInstruction::Deref {
627621
shift_0: new_fp_pos.into(),

crates/lean_compiler/src/c_compile_final.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,12 @@ fn compile_block(
337337
IntermediateInstruction::RequestMemory {
338338
offset,
339339
size,
340-
vectorized,
341-
vectorized_len,
342340
} => {
343341
let size = try_as_mem_or_constant(&size).unwrap();
344-
let vectorized_len = try_as_constant(&vectorized_len, compiler).unwrap().to_usize();
345342
let hint = Hint::RequestMemory {
346343
function_name: function_name.clone(),
347344
offset: eval_const_expression_usize(&offset, compiler),
348-
vectorized,
349345
size,
350-
vectorized_len,
351346
};
352347
hints.entry(pc).or_default().push(hint);
353348
}

crates/lean_compiler/src/ir/instruction.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ pub enum IntermediateInstruction {
4444
RequestMemory {
4545
offset: ConstExpression, // m[fp + offset] where the hint will be stored
4646
size: IntermediateValue, // the hint
47-
vectorized: bool, // if true, will be (2^vectorized_len)-alligned, and the returned pointer will be "divied" by 2^vectorized_len
48-
vectorized_len: IntermediateValue,
4947
},
5048
DecomposeBits {
5149
res_offset: usize, // m[fp + res_offset..fp + res_offset + 31 * len(to_decompose)] will contain the decomposed bits
@@ -171,14 +169,8 @@ impl Display for IntermediateInstruction {
171169
Self::RequestMemory {
172170
offset,
173171
size,
174-
vectorized,
175-
vectorized_len,
176172
} => {
177-
if *vectorized {
178-
write!(f, "m[fp + {offset}] = request_memory_vec({size}, {vectorized_len})")
179-
} else {
180-
write!(f, "m[fp + {offset}] = request_memory({size})")
181-
}
173+
write!(f, "m[fp + {offset}] = request_memory({size})")
182174
}
183175
Self::DecomposeBits {
184176
res_offset,

crates/lean_compiler/src/lang.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,6 @@ pub enum Line {
359359
MAlloc {
360360
var: Var,
361361
size: Expression,
362-
vectorized: bool,
363-
vectorized_len: Expression,
364362
},
365363
DecomposeBits {
366364
var: Var, // a pointer to 31 * len(to_decompose) field elements, containing the bits of "to_decompose"
@@ -551,14 +549,8 @@ impl Line {
551549
Self::MAlloc {
552550
var,
553551
size,
554-
vectorized,
555-
vectorized_len,
556552
} => {
557-
if *vectorized {
558-
format!("{var} = malloc_vec({size}, {vectorized_len})")
559-
} else {
560-
format!("{var} = malloc({size})")
561-
}
553+
format!("{var} = malloc({size})")
562554
}
563555
Self::DecomposeBits { var, to_decompose } => {
564556
format!(

crates/lean_compiler/src/lib.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,9 @@ pub fn compile_program(program: String) -> Bytecode {
3030
// compiled
3131
}
3232

33-
pub fn compile_and_run(
34-
program: String,
35-
(public_input, private_input): (&[F], &[F]),
36-
no_vec_runtime_memory: usize, // size of the "non-vectorized" runtime memory
37-
profiler: bool,
38-
) {
33+
pub fn compile_and_run(program: String, (public_input, private_input): (&[F], &[F]), profiler: bool) {
3934
let bytecode = compile_program(program);
40-
let summary = execute_bytecode(
41-
&bytecode,
42-
(public_input, private_input),
43-
no_vec_runtime_memory,
44-
profiler,
45-
&vec![],
46-
)
47-
.summary;
35+
let summary = execute_bytecode(&bytecode, (public_input, private_input), profiler, &vec![]).summary;
4836
println!("{summary}");
4937
}
5038

crates/lean_compiler/src/parser/parsers/function.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
grammar::{ParsePair, Rule},
1111
},
1212
};
13-
use lean_vm::{ALL_TABLES, LOG_VECTOR_LEN, Table, TableT};
13+
use lean_vm::{ALL_TABLES, Table, TableT};
1414

1515
/// Parser for complete function definitions.
1616
pub struct FunctionParser;
@@ -160,24 +160,6 @@ impl FunctionCallParser {
160160
Ok(Line::MAlloc {
161161
var: return_data[0].clone(),
162162
size: args[0].clone(),
163-
vectorized: false,
164-
vectorized_len: Expression::zero(),
165-
})
166-
}
167-
"malloc_vec" => {
168-
let vectorized_len = if args.len() == 1 {
169-
Expression::scalar(LOG_VECTOR_LEN)
170-
} else if args.len() == 2 {
171-
args[1].clone()
172-
} else {
173-
return Err(SemanticError::new("Invalid malloc_vec call").into());
174-
};
175-
176-
Ok(Line::MAlloc {
177-
var: return_data[0].clone(),
178-
size: args[0].clone(),
179-
vectorized: true,
180-
vectorized_len,
181163
})
182164
}
183165
"print" => {

0 commit comments

Comments
 (0)