compiler: add bool[N] ctor binding via Expr::bool_array and From<Vec<bool>> - #170
Open
oskrcl wants to merge 4 commits into
Open
compiler: add bool[N] ctor binding via Expr::bool_array and From<Vec<bool>>#170oskrcl wants to merge 4 commits into
oskrcl wants to merge 4 commits into
Conversation
…bool>> The Expr API has helpers for int, bool, byte, bytes, string, but no bool_array helper nor From<Vec<bool>> impl. This blocks Rust test code from constructing bool[N] ctor params for silverscript contracts. - Add Expr::bool_array(Vec<bool>) parallel to Expr::bytes(Vec<u8>) - Add From<Vec<bool>> for Expr - Unit tests pin both
Integration test uses bool[2] param initW and field ref initW in validateOutputState. Uses field ref (not literal) to stay independent from PR kaspanet#1's literal inference fix.
fixed_type_size in compile.rs handles arrays for byte[] and int[] but not bool[], causing fixed_state_payload_len to return None for bool[N] fields. This propagates to compile_encoded_state_object and compile_encoded_flat_state_fields, rejecting bool[N] in validateOutputState/validateNextState. Fix by adding is_bool() branch: bool is 1 byte per element, same layout as byte[N]. Adds: - Unit test fixed_type_size_accepts_bool_array in compile.rs - Integration test compiles_validate_output_state_with_bool_array_field in compiler_tests.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds helper and trait impl, enabling construction of array values in (VOS) bodies.
Motivation
Covenant contracts using need to construct fields for next-state encoding. Without these helpers, there is no idiomatic way to build expressions programmatically (e.g., from test harnesses or VOS body generation).
Changes
**** (+39 lines):
**** (+16 lines):
Verification
cargo build --release -p silverscript-lang✅cargo test -p silverscript-lang --release— 499 passed, 0 failed ✅2a3961c(upstream master HEAD at time of branch)API Consistency
Follows existing patterns exactly:
bool_arraymirrorsbytes()constructorFrom<Vec<bool>>mirrorsFrom<Vec<u8>>From<Vec<i64>>(int arrays) unaffected — different trait parameter, zero ambiguityDepends on: nothing (standalone). Pairs with #PR3 (bool[N] VOS encoding preservation) for full VOS round-trip.