Skip to content

Commit beb3f2c

Browse files
committed
refactor(TasmObject)!: Overhaul generated code
Previously, the derive macro `TasmObject` produced recursive code which generated the required Triton assembly. In order to do this, it used the trait function `TasmStruct::get_field_start_with_jump_distance` as an internal helper. Remove this function from the trait, produce non-recursive rust code instead. Support trailing commata in `where` clauses (fix #91). Support unit structs. Slightly improve efficiency of the generated Triton assembly. Document the limitation that ignoring fields in tuple structs is currently not supported. Adhere to maximum line length. BREAKING CHANGE: Remove function `get_field_start_with_jump_distance` from `TasmStruct`.
1 parent 9a2f8ac commit beb3f2c

12 files changed

+726
-715
lines changed

tasm-lib/benchmarks/tasmlib_structure_verify_nd_si_integrity___ProofCollectionLookalike.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
{
33
"name": "tasmlib_structure_verify_nd_si_integrity___ProofCollectionLookalike",
44
"benchmark_result": {
5-
"clock_cycle_count": 203,
6-
"hash_table_height": 228,
5+
"clock_cycle_count": 197,
6+
"hash_table_height": 222,
77
"u32_table_height": 150,
8-
"op_stack_table_height": 136,
8+
"op_stack_table_height": 132,
99
"ram_table_height": 16
1010
},
1111
"case": "CommonCase"
1212
},
1313
{
1414
"name": "tasmlib_structure_verify_nd_si_integrity___ProofCollectionLookalike",
1515
"benchmark_result": {
16-
"clock_cycle_count": 284,
17-
"hash_table_height": 228,
16+
"clock_cycle_count": 278,
17+
"hash_table_height": 222,
1818
"u32_table_height": 212,
19-
"op_stack_table_height": 190,
19+
"op_stack_table_height": 186,
2020
"ram_table_height": 22
2121
},
2222
"case": "WorstCase"

tasm-lib/benchmarks/tasmlib_structure_verify_nd_si_integrity___TransactionKernelLookalike.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
{
33
"name": "tasmlib_structure_verify_nd_si_integrity___TransactionKernelLookalike",
44
"benchmark_result": {
5-
"clock_cycle_count": 282,
6-
"hash_table_height": 390,
5+
"clock_cycle_count": 255,
6+
"hash_table_height": 342,
77
"u32_table_height": 240,
8-
"op_stack_table_height": 180,
8+
"op_stack_table_height": 168,
99
"ram_table_height": 15
1010
},
1111
"case": "CommonCase"
1212
},
1313
{
1414
"name": "tasmlib_structure_verify_nd_si_integrity___TransactionKernelLookalike",
1515
"benchmark_result": {
16-
"clock_cycle_count": 244,
17-
"hash_table_height": 390,
16+
"clock_cycle_count": 223,
17+
"hash_table_height": 342,
1818
"u32_table_height": 212,
19-
"op_stack_table_height": 160,
19+
"op_stack_table_height": 148,
2020
"ram_table_height": 14
2121
},
2222
"case": "WorstCase"

tasm-lib/benchmarks/tasmlib_verifier_collinearity_check_x.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
{
33
"name": "tasmlib_verifier_collinearity_check_x",
44
"benchmark_result": {
5-
"clock_cycle_count": 29,
6-
"hash_table_height": 36,
5+
"clock_cycle_count": 24,
6+
"hash_table_height": 30,
77
"u32_table_height": 38,
8-
"op_stack_table_height": 24,
8+
"op_stack_table_height": 18,
99
"ram_table_height": 2
1010
},
1111
"case": "CommonCase"
1212
},
1313
{
1414
"name": "tasmlib_verifier_collinearity_check_x",
1515
"benchmark_result": {
16-
"clock_cycle_count": 29,
17-
"hash_table_height": 36,
16+
"clock_cycle_count": 24,
17+
"hash_table_height": 30,
1818
"u32_table_height": 54,
19-
"op_stack_table_height": 24,
19+
"op_stack_table_height": 18,
2020
"ram_table_height": 2
2121
},
2222
"case": "WorstCase"

tasm-lib/benchmarks/tasmlib_verifier_fri_verify.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
{
33
"name": "tasmlib_verifier_fri_verify",
44
"benchmark_result": {
5-
"clock_cycle_count": 44149,
6-
"hash_table_height": 14790,
5+
"clock_cycle_count": 44059,
6+
"hash_table_height": 14712,
77
"u32_table_height": 17999,
8-
"op_stack_table_height": 42367,
9-
"ram_table_height": 17565
8+
"op_stack_table_height": 42255,
9+
"ram_table_height": 17563
1010
},
1111
"case": "CommonCase"
1212
},
1313
{
1414
"name": "tasmlib_verifier_fri_verify",
1515
"benchmark_result": {
16-
"clock_cycle_count": 44149,
17-
"hash_table_height": 14790,
16+
"clock_cycle_count": 44059,
17+
"hash_table_height": 14712,
1818
"u32_table_height": 17395,
19-
"op_stack_table_height": 42367,
20-
"ram_table_height": 17565
19+
"op_stack_table_height": 42255,
20+
"ram_table_height": 17563
2121
},
2222
"case": "WorstCase"
2323
}

tasm-lib/benchmarks/tasmlib_verifier_stark_verify_dynamic_inner_padded_height_256_fri_exp_4.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
{
33
"name": "tasmlib_verifier_stark_verify_dynamic_inner_padded_height_256_fri_exp_4",
44
"benchmark_result": {
5-
"clock_cycle_count": 188600,
6-
"hash_table_height": 139015,
5+
"clock_cycle_count": 188458,
6+
"hash_table_height": 138907,
77
"u32_table_height": 25078,
8-
"op_stack_table_height": 167574,
9-
"ram_table_height": 289172
8+
"op_stack_table_height": 167396,
9+
"ram_table_height": 289169
1010
},
1111
"case": "CommonCase"
1212
}

tasm-lib/benchmarks/tasmlib_verifier_stark_verify_dynamic_inner_padded_height_512_fri_exp_4.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
{
33
"name": "tasmlib_verifier_stark_verify_dynamic_inner_padded_height_512_fri_exp_4",
44
"benchmark_result": {
5-
"clock_cycle_count": 196126,
6-
"hash_table_height": 146707,
5+
"clock_cycle_count": 195969,
6+
"hash_table_height": 146599,
77
"u32_table_height": 33679,
8-
"op_stack_table_height": 172298,
9-
"ram_table_height": 290324
8+
"op_stack_table_height": 172110,
9+
"ram_table_height": 290320
1010
},
1111
"case": "CommonCase"
1212
}

tasm-lib/benchmarks/tasmlib_verifier_stark_verify_static_inner_padded_height_256_fri_exp_4.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
{
33
"name": "tasmlib_verifier_stark_verify_static_inner_padded_height_256_fri_exp_4",
44
"benchmark_result": {
5-
"clock_cycle_count": 176897,
6-
"hash_table_height": 124975,
5+
"clock_cycle_count": 176755,
6+
"hash_table_height": 124861,
77
"u32_table_height": 25078,
8-
"op_stack_table_height": 159768,
9-
"ram_table_height": 285273
8+
"op_stack_table_height": 159590,
9+
"ram_table_height": 285270
1010
},
1111
"case": "CommonCase"
1212
}

tasm-lib/benchmarks/tasmlib_verifier_stark_verify_static_inner_padded_height_512_fri_exp_4.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
{
33
"name": "tasmlib_verifier_stark_verify_static_inner_padded_height_512_fri_exp_4",
44
"benchmark_result": {
5-
"clock_cycle_count": 184423,
6-
"hash_table_height": 132667,
5+
"clock_cycle_count": 184266,
6+
"hash_table_height": 132553,
77
"u32_table_height": 33679,
8-
"op_stack_table_height": 164492,
9-
"ram_table_height": 286425
8+
"op_stack_table_height": 164304,
9+
"ram_table_height": 286421
1010
},
1111
"case": "CommonCase"
1212
}

tasm-lib/src/structure/auto_generated_tasm_object_implementations.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ macro_rules! derive_tasm_object_for {
4444
$fake::get_field_with_size(field_name)
4545
}
4646

47-
fn get_field_start_with_jump_distance(field_name: &str) -> Vec<LabelledInstruction> {
48-
$fake::get_field_start_with_jump_distance(field_name)
49-
}
50-
5147
fn destructure() -> Vec<LabelledInstruction> {
5248
$fake::destructure()
5349
}
@@ -120,10 +116,6 @@ impl TasmStruct for MmrAccumulator {
120116
FakeMmrAccumulator::get_field_with_size(field_name)
121117
}
122118

123-
fn get_field_start_with_jump_distance(field_name: &str) -> Vec<LabelledInstruction> {
124-
FakeMmrAccumulator::get_field_start_with_jump_distance(field_name)
125-
}
126-
127119
fn destructure() -> Vec<LabelledInstruction> {
128120
FakeMmrAccumulator::destructure()
129121
}

tasm-lib/src/structure/tasm_object.rs

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,21 @@ pub trait TasmObject: BFieldCodec {
6767
///
6868
/// [dyn-compatible]: https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility
6969
pub trait TasmStruct: TasmObject {
70-
/// Returns tasm code that returns a pointer the field of the object, assuming:
70+
/// Tasm code that returns a pointer to the field of the object, assuming:
7171
/// - that a pointer to the said object lives on top of the stack;
72-
/// - said object has a type that implements the TasmObject trait;
73-
/// - said object lives in memory encoded as BFieldCodec specifies.
72+
/// - said object has a type that implements the [`TasmObject`] trait;
73+
/// - said object lives in memory encoded as [`BFieldCodec`] specifies.
7474
///
7575
/// ```text
7676
/// BEFORE: _ *object
7777
/// AFTER: _ *field
7878
/// ```
7979
fn get_field(field_name: &str) -> Vec<LabelledInstruction>;
8080

81-
/// Returns tasm code that returns a pointer the field of the object, along with
82-
/// the size of that field in number of BFieldElements, assuming:
81+
/// Tasm code that returns a pointer to the field of the object, along with
82+
/// the size of that field in number of [`BFieldElement`]s, assuming:
8383
/// - that a pointer to the said object lives on top of the stack;
84-
/// - said object has a type that implements the TasmObject trait;
84+
/// - said object has a type that implements the [`TasmObject`] trait;
8585
/// - said object lives in memory encoded as [`BFieldCodec`] specifies.
8686
///
8787
/// ```text
@@ -92,23 +92,6 @@ pub trait TasmStruct: TasmObject {
9292
/// See also: `get_field` if you just want the field without the size.
9393
fn get_field_with_size(field_name: &str) -> Vec<LabelledInstruction>;
9494

95-
/// Returns tasm code that returns a pointer to the start of the field of the object,
96-
/// along with the jump distance to the next field. Note that:
97-
///
98-
/// - *field_start == *field if the size is statically known, but
99-
/// - *field_start == *field-1 if the size is not statically known.
100-
///
101-
/// ```text
102-
/// BEFORE: _ *object
103-
/// AFTER: _ *field_start field_jump_distance
104-
/// ```
105-
///
106-
/// This function is used internally for the derive macro. You probably want to use
107-
/// [`get_field`](TasmObject::get_field) or
108-
/// [`get_field_with_size`](TasmObject::get_field_with_size) instead.
109-
#[doc(hidden)]
110-
fn get_field_start_with_jump_distance(field_name: &str) -> Vec<LabelledInstruction>;
111-
11295
/// Destructure a struct into the pointers to its fields.
11396
///
11497
/// ```text

0 commit comments

Comments
 (0)