Skip to content

Support new features and improve semantic analysis#15

Open
gabearro wants to merge 8 commits intomainfrom
adkg-support
Open

Support new features and improve semantic analysis#15
gabearro wants to merge 8 commits intomainfrom
adkg-support

Conversation

@gabearro
Copy link
Contributor

Summary

This pull request introduces several key enhancements and optimizations:

  • Feature Flags: Made ClientStore and Share.mul methods conditional under the honeybadger feature flag. Added Mpc methods for protocol capabilities.
  • Chain Module: Added chain/base.stfl for basic operations and updated bytecode for integration tests.
  • Integration Tests: Built comprehensive end-to-end tests for object definitions, secret fields, and method calls, covering user-defined objects, UFCS transformation, and bytecode generation.
  • Improved Import Structure: Removed old multi-file import tests and restructured imports to align with the stfl directory. Added tests for object syntax and compound assignments.
  • Pythonic Syntax for Arrays: Implemented support for Pythonic array aliases (append, length, len, and push) and refined object-related syntax.
  • Compound Assignment Operators: Added support for compound assignment operators like +=, -=, etc., along with desugaring and test cases.
  • Type Annotations Validation (STO-334): Validated type annotations in semantic analysis to ensure correct usage and added support for recursive type validation.
  • Type Inference Enhancements: Improved type inference for loop variables based on iterable types and updated support for generic collections.

Checklist

  • Feature additions have been documented.
  • Tests have been added or updated for all new changes.
  • Code has been reviewed for quality and maintainability.

Additional Notes

This PR also includes optimizations in parsing, code generation, and semantic analysis. Extensive testing ensures that new features and changes integrate smoothly with existing functionality.

…ns. Replace fixed `Int64` loop variable type with inferred type from iterable. Update suggestions, parsing, and test modules to support additional iterable types and generic type improvements.
Ensure annotations reference valid types, checking for undefined or incorrect usage (e.g., functions or variables as types). Add support for recursive validation of nested types.
…in lexer and parser. Update semantic analysis, add desugaring, and include extensive tests.
…h`) for arrays. Update parser, codegen, and symbol table to handle method-style syntax via UFCS. Add object definition parsing and related semantic analysis handling. Extend tests for Pythonic array syntax and object-related features.
…, nested, alias, and circular patterns. Update remaining imports and test paths to use the new `stfl` directory structure. Add new tests for object syntax and compound assignments.
…s, and method calls. Include comprehensive scenarios for user-defined objects, field access, secret types, UFCS transformation, and bytecode generation.
…r` feature flag. Add `Mpc` methods for protocol capabilities. Update tests and optimizations to align with conditional features and batching improvements.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the Stoffel-Lang compiler’s language surface area and semantic analysis, adding object/type features, Pythonic collection conveniences, compound assignments, richer for-loop typing, and optimization improvements, alongside substantial new integration fixtures/tests.

Changes:

  • Added parsing + semantic handling for user-defined object definitions and generic types, and improved type annotation validation.
  • Implemented Pythonic array aliases (append/push, length/len) via UFCS + codegen mapping, enabled empty list literals ([]), and added compound assignment operators.
  • Enhanced for-loop support (range + collection iteration) and extended optimization logic for reveal batching/reordering; added extensive .stfl fixtures and Rust integration tests plus updated bytecode fixtures.

Reviewed changes

Copilot reviewed 24 out of 73 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Cargo.toml Adds feature flags and test targets; changes dependency configuration.
src/ast.rs Adds GenericType AST node and updates helpers to recognize it.
src/parser.rs Implements object parsing, generic type parsing (List/Dict + general generics), empty list literals, compound assignments, and broader for iterable parsing.
src/semantic.rs Adds generic compatibility, validates type annotations, registers object types, improves for-loop type inference, and routes method-suggestion lookups through the symbol table.
src/symbol_table.rs Adds Generic symbol types, Display impl for types, feature-gates certain builtins, and registers Pythonic alias functions + method suggestions.
src/suggestions.rs Moves method-to-function suggestions to be driven by SymbolTable.
src/lexer.rs Tokenizes compound assignment operators (notably -=) instead of rejecting them.
src/codegen.rs Maps Pythonic alias calls to VM builtins and adds collection-iteration codegen for for loops; adds no-op codegen for object definitions.
src/optimizations.rs Expands reveal batching docs and refines reordering to model PendingReveal flush lifecycle; adds helpers and tests.
src/bytecode.rs Switches to re-exporting ResolvedInstruction from stoffel_vm_types.
src/binary_converter.rs Removes unused ResolvedInstruction import and updates disassembler typing for PendingReveal.
tests/rust/import_integration_tests.rs Updates import test root to tests/stfl/imports.
tests/rust/suggestion_integration_tests.rs Updates tests to reflect Pythonic aliases now compiling successfully.
tests/rust/object_syntax_tests.rs Adds lexer/parser coverage for dot access, method calls, chaining, indexing + method calls.
tests/rust/object_integration_tests.rs Adds full-pipeline integration tests for builtin objects, UFCS, bytecode, and error cases.
tests/rust/user_defined_object_tests.rs Adds end-to-end tests for user-defined object definitions and compiling to .stflb.
tests/stfl/valid_basics.stfl Adds basic language feature sample fixture.
tests/stfl/valid_indentation.stfl Adds indentation fixture.
tests/stfl/valid_for_loop.stfl Adds for-loop fixture.
tests/stfl/valid_ufcs.stfl Adds UFCS showcase fixture.
tests/stfl/valid_public_comparisons.stfl Adds public comparisons fixture.
tests/stfl/valid_public_comparison_minimal.stfl Adds minimal public comparison fixture.
tests/stfl/valid_public_mixed_width_comparisons.stfl Adds mixed-width comparison fixture.
tests/stfl/valid_nim_functions.stfl Adds Nim-style function syntax fixture.
tests/stfl/secret_usage_valid.stfl Adds valid secret-typing usage fixture.
tests/stfl/secret_usage_invalid.stfl Adds invalid secret-branching fixture.
tests/stfl/error_secret_comparison_in_if.stfl Adds negative test for secret comparison in conditional.
tests/stfl/error_integer_ranges.stfl Adds integer width/range negative tests.
tests/stfl/error_indentation.stfl Adds indentation negative tests.
tests/stfl/error_syntax.stfl Adds syntax negative tests (let, secret let).
tests/stfl/compound_assignment.stfl Adds compound assignment integration fixture.
tests/stfl/reveal_batching_demo.stfl Adds fixture demonstrating reveal batching optimization intent.
tests/stfl/nested_generics_test.stfl Adds nested generics fixture.
tests/stfl/objects.stfl Adds object syntax + builtin object method call fixture.
tests/stfl/client_store_valid.stfl Adds valid ClientStore usage fixture.
tests/stfl/client_store_invalid.stfl Adds invalid ClientStore usage fixture.
tests/stfl/client_store_comprehensive.stfl Adds comprehensive ClientStore fixture.
tests/stfl/knapsack_greedy.stfl Updates fixture to List[...] spelling.
tests/stfl/knapsack_pythonic.stfl Adds Pythonic-array-syntax knapsack fixture.
tests/stfl/knapsack_invalid.stfl Adds invalid knapsack program fixture for error messages.
tests/stfl/matrix_average_fixed_point.stfl Updates collection type spelling to List[...].
tests/stfl/fizzbuzz.stfl Adds VM-friendly fizzbuzz fixture.
tests/stfl/fibonacci.stfl Adds iterative fibonacci fixture.
tests/stfl/fibonacci_recursive.stfl Adds recursive fibonacci fixture.
tests/stfl/factorial.stfl Adds factorial fixture.
tests/stfl/imports/main_with_import.stfl Adds simple import fixture.
tests/stfl/imports/main_with_import.stflb Adds compiled-bytecode fixture for import test.
tests/stfl/imports/missing_import.stfl Adds missing-import negative fixture.
tests/stfl/imports/utils/math.stfl Adds utilities module fixture.
tests/stfl/imports/multi/main_multi.stfl Adds multiple-imports fixture.
tests/stfl/imports/multi/helpers.stfl Adds helper module fixture.
tests/stfl/imports/multi/constants.stfl Adds constants module fixture.
tests/stfl/imports/chain/base.stfl Adds base module for chain import fixture.
tests/stfl/imports/chain/middle.stfl Adds middle module for chain import fixture.
tests/stfl/imports/chain/main_chain.stfl Adds main module for chain import fixture.
tests/stfl/imports/diamond/shared.stfl Adds shared module for diamond import fixture.
tests/stfl/imports/diamond/left.stfl Adds left module for diamond import fixture.
tests/stfl/imports/diamond/right.stfl Adds right module for diamond import fixture.
tests/stfl/imports/diamond/main_diamond.stfl Adds main module for diamond import fixture.
tests/stfl/imports/nested/main_nested.stfl Adds nested import fixture entry.
tests/stfl/imports/nested/level1/mid.stfl Adds nested import fixture mid module.
tests/stfl/imports/nested/level1/level2/deep.stfl Adds nested import fixture deep module.
tests/stfl/imports/circular_a.stfl Adds circular import negative fixture (A).
tests/stfl/imports/circular_b.stfl Adds circular import negative fixture (B).
tests/stfl/imports/alias/math_lib.stfl Adds alias import fixture library.
tests/stfl/imports/alias/main_alias.stfl Adds alias import fixture entry.
tests/bytecode/matrix_average_fixed_point.stflb Adds/updates compiled bytecode fixture.
tests/bytecode/fizzbuzz.stflb Adds compiled bytecode fixture.
tests/bytecode/compound_assignment.stflb Adds compiled bytecode fixture.
tests/bytecode/client_store_valid.stflb Adds compiled bytecode fixture.
tests/bytecode/client_store_comprehensive.stflb Adds compiled bytecode fixture.
bytecode.txt Adds compiler output/bytecode dump artifact.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


[dependencies]
stoffel-vm-types = { version = "0.1.0", git = "https://github.com/Stoffel-Labs/StoffelVM.git"}
stoffel-vm-types = { version = "0.1.0", path = "../StoffelVM/crates/stoffel-vm-types" }
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stoffel-vm-types is switched from a git dependency to a relative path = "../StoffelVM/...". This makes builds non-reproducible outside your local workspace (and will break in CI / for downstream users unless that sibling repo exists). Prefer keeping the git dependency (optionally pinning a rev) and use [patch] or a workspace override for local development.

Copilot uses AI. Check for mistakes.
self.emit(Instruction::MOV(index_vr.0, zero_vr.0));

// Allocate the loop element variable
let elem_vr = self.allocate_virtual_register(collection_is_secret);
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In collection-based for loops, elem_vr secrecy is derived from collection_is_secret, but a clear List[secret T] will still yield secret elements. Allocating a clear register for elem_vr can cause an implicit reveal when the element is fetched, which is a security/correctness issue. Consider carrying element type/secrecy into codegen (e.g., annotate the ForLoop/IndexAccess node during semantic analysis) and allocate/move the element into a secret register when the element type is secret.

Suggested change
let elem_vr = self.allocate_virtual_register(collection_is_secret);
// Use a secret register for elements to avoid implicitly revealing secret data
let elem_vr = self.allocate_virtual_register(true);

Copilot uses AI. Check for mistakes.

// =============================================================================
// INSTRUCTION REORDERING FOR IMPLICIT REVEAL BATCHING
// INSTRUCTION REORDERING FOR PENDINGREVIEW BATCHING
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header comment says "PENDINGREVIEW" but the rest of the file refers to "PendingReveal". This looks like a typo and can be confusing when searching/docs reference this pass; rename to "PendingReveal" for consistency.

Suggested change
// INSTRUCTION REORDERING FOR PENDINGREVIEW BATCHING
// INSTRUCTION REORDERING FOR PendingReveal BATCHING

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant