-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(TasmObject)!: Move checks to compile time #153
Conversation
On the topic of design decisions: I'm a little unsure about function Maybe there's some complication with |
I'm missing a answer to "why?" -- what benefits does this change generate? (Or is the runtime / compile-time shift the only one?)
How? |
Primitive types (like
Of this PR: yes. In my opinion, this is a worthy benefit by itself. Extended motivationI have the suspicion, and @Sword-Smith has confirmed this suspicion, that many tasm snippets access most or all fields of some struct. To reduce the use of field getters in such cases, I want to add a function to destructure an object into pointers to all its fields. I want that function to look something like this: [derive(BFieldCodec, TasmObject)]
struct Foo {
bar: u32,
baz: XFieldElement,
}
let foo = Foo { bar: 13, baz: xfe!(0) };
let foo_ptr = bfe!(42);
let mut non_determinism = NonDeterminism::default();
encode_to_memory(&mut non_determinism.ram, foo_ptr, &foo);
let program = triton_program! {
read_io 1 // _ *foo
{&Foo::destructure()} // _ *bar *baz
pop 1 // _ *bar
read_mem 1 // _ bar (*bar - 1)
pop 1 // _ bar
write_io 1 // _
halt
};
let output = VM::run(program, PublicInput::new(vec![foo_ptr]), non_determinism).unwrap();
let [bar] = output[..] else { panic!() };
assert_eq!(bfe!(foo.bar), bar); I don't want to provide the |
Add trait `TasmStruct`, moving struct-only capabilities out of `TasmObject`. This change neither adds nor removes functionality, it only moves checks from runtime to compile time.
14eb075
to
bc6c301
Compare
Previously, the implementations of `TasmObject`'s function `compute_size_and_assert_valid_size_indicator` for “primitive types” like `u32`, `Digest`, etc., panicked, claiming a statically known size as the reason. Now, the statically know length is produced. Also, improve code formatting and a tiny bit of assembly.
Add trait
TasmStruct
, moving struct-only capabilities out ofTasmObject
. This change neither adds nor removes functionality, it only moves checks from runtime to compile time.It is possible that this is not the cleanest design yet. I'm happy about opinions and suggestions.