Infer int[N] and bool[N] literal types in debug_value_types#167
Open
oskrcl wants to merge 3 commits into
Open
Conversation
The literal-inference path for ExprKind::Array only matched ExprKind::Byte, causing int[N] and bool[N] literals to fall through to the catch-all "byte[]" type. This breaks validateOutputState state-region size computation for non-byte array literals. - Add ExprKind::Int inference branch (returns "int[N]") - Add ExprKind::Bool inference branch (returns "bool[N]") - Handle empty arrays explicitly (return "byte[]" for legacy compat) Also adds a #[cfg(test)] unit test pinning all three new behaviors.
Regression fixture for the literal-inference bug fixed in the previous commit. Demonstrates int[4] literal [1,2,3,4] in validateOutputState. Note: b3c_field_ref_spike.sil and b3c_bool_* removed from this branch -- field-ref path is pre-existing (not the fixed code path); bool[N] ctor-binding is a separate bug filed in the issue tracker.
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
infer_debug_expr_value_typeonly recognizesbyte[N]array literals.int[N]andbool[N]literals fall through to the catch-all"byte[]"type, which causes
validateOutputStateto reject state fields writtenwith array literals. A field passed by reference (
{ winners: winners })compiles fine because the declared type from the
typesmap bypassesliteral inference; a field passed by literal (
{ winners: [1,2,3,4] })fails until this fix lands.
Changes
silverscript-lang/src/compiler/debug_value_types.rs— in theExprKind::Arrayarm ofinfer_debug_expr_value_type, inferint[N]for all-
Intliterals andbool[N]for all-Boolliterals, alongsidethe existing
byte[N]case. Empty literals now infer"byte[]"explicitly (previously
"byte[0]"via vacuous.all()on an emptyiterator).
silverscript-lang/tests/compiler_tests.rs— new testcompiles_validate_output_state_with_int_array_literalexercisesvalidateOutputState(0, { x: x + 1, winners: [1,2,3,4] }).silverscript-lang/tests/examples/b3c_array_spike.sil— showcasefixture mirroring the inline test.
silverscript-lang/src/compiler/debug_value_types.rs#[cfg(test)]unit test
infers_fixed_array_literal_value_typespins all three newinference branches (
int[N],bool[N], empty).Test Evidence
cargo test -p silverscript-lang— 305 passed, 0 failed.[1,2,3,4]infers as"byte[]",compile_encoded_state_objectrejects unsized field typewith
validateOutputState does not support field type byte[].b3c_array_spike.sil(literal) compiles only after the patch.declared type); verified empirically.
Notes
bool[N]ctor-binding from Rust (Expr::From<Vec<bool>>) is aseparate bug filed in the upstream issue tracker; not addressed here.
state {}declarations blockpatched.