Skip to content

Develop#20

Merged
TheUncharted merged 3 commits intomasterfrom
develop
Mar 12, 2026
Merged

Develop#20
TheUncharted merged 3 commits intomasterfrom
develop

Conversation

@TheUncharted
Copy link
Copy Markdown
Owner

@TheUncharted TheUncharted commented Mar 12, 2026

Summary

Changes

Test plan

  • Unit tests pass (cargo test)
  • CI passes

Related issues

Summary by CodeRabbit

  • Bug Fixes

    • Fixed method mutations to this. Changes made to instance state within methods are now properly persisted and written back to the original receiver, ensuring mutations remain consistent across method calls.
  • Chores

    • Updated package dependencies to latest versions in example projects.

The VM uses value semantics for objects, so calling a method like
c.increment() would clone the receiver. Mutations to this.count
inside the method modified the clone but never wrote back to the
original variable, causing repeated calls to always see the same
initial state (e.g. [11, 11, 11] instead of [11, 12, 13]).

Track receiver provenance (global/local slot) through the
LoadGlobal/LoadLocal -> GetProperty -> Call chain, and on Return
write the mutated this back to the source variable.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 12, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0a9149dd-ca2c-4bd4-b82f-527305bbec83

📥 Commits

Reviewing files that changed from the base of the PR and between fdcdb59 and cbec58c.

📒 Files selected for processing (5)
  • crates/zapcode-core/src/vm/mod.rs
  • crates/zapcode-core/tests/classes.rs
  • examples/ai-bedrock/package.json
  • examples/python/pyproject.toml
  • examples/typescript/package.json

📝 Walkthrough

Walkthrough

The changes implement method receiver source tracking and mutation persistence across VM frames. A new ReceiverSource enum tracks whether a method receiver originates from global or local variables. The VM preserves receiver source through frame transitions and writes back mutations to the original source upon method return. Tests validate this behavior. Package dependencies are updated to latest versions across example projects.

Changes

Cohort / File(s) Summary
Core VM Receiver Tracking
crates/zapcode-core/src/vm/mod.rs
Introduces ReceiverSource enum to track receiver origin (Global or Local frame slot). Extends CallFrame and Vm with receiver_source and last_load_source fields. Implements propagation of receiver source through frame setups and write-back of mutated this to the original source variable upon method return. Clears receiver_source appropriately for constructors and certain super calls.
Method Mutation Tests
crates/zapcode-core/tests/classes.rs
Adds three new tests validating that mutations to this within methods persist to the receiver object: single instance repeated mutations, local scope mutations, and multi-instance isolation. Test blocks appear duplicated in the file.
Dependency Updates
examples/ai-bedrock/package.json, examples/python/pyproject.toml, examples/typescript/package.json
Updates package dependency versions to use "latest" pins for zapcode and zapcode-ai packages. Removes [tool.uv] and [build-system] sections from Python configuration.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant VM
    participant CallFrame
    participant Store

    Client->>VM: Load receiver object (Global/Local)
    VM->>VM: Capture receiver source (ReceiverSource)
    Client->>VM: Call method on receiver
    VM->>CallFrame: Push new frame<br/>(with receiver_source)
    CallFrame->>CallFrame: Execute method body<br/>(mutate this)
    Client->>VM: Return from method
    VM->>Store: Write mutated this back<br/>to original source<br/>(Global or Local)
    VM->>VM: Clear receiver_source
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop

Comment @coderabbitai help to get the list of available commands and usage tips.

@TheUncharted TheUncharted merged commit 206961b into master Mar 12, 2026
11 of 12 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

Benchmark Results

    Updating crates.io index
 Downloading crates ...
  Downloaded cfg-if v1.0.4
  Downloaded castaway v0.2.4
  Downloaded byteorder v1.5.0
  Downloaded clap v4.5.60
  Downloaded clap_builder v4.5.60
  Downloaded embedded-io v0.4.0
  Downloaded siphasher v1.0.2
  Downloaded unicode-id-start v1.4.0
  Downloaded rustc_version v0.4.1
  Downloaded phf_shared v0.13.1
  Downloaded terminal_size v0.4.3
  Downloaded oxc_str v0.117.0
  Downloaded unicode-linebreak v0.1.5
  Downloaded scopeguard v1.2.0
  Downloaded thiserror-impl v2.0.18
  Downloaded oxc_span v0.117.0
  Downloaded spin v0.9.8
  Downloaded tempfile v3.27.0
  Downloaded unicode-ident v1.0.24
  Downloaded oxc_regular_expression v0.117.0
  Downloaded unicode-segmentation v1.12.0
  Downloaded regex-lite v0.1.9
  Downloaded insta v1.46.3
  Downloaded oxc_ast v0.117.0
  Downloaded oxc_parser v0.117.0
  Downloaded oxc_allocator v0.117.0
  Downloaded memchr v2.8.0
  Downloaded indexmap v2.13.0
  Downloaded serde v1.0.228
  Downloaded unicode-width v0.2.2
  Downloaded oxc-miette v2.7.0
  Downloaded syn v2.0.117
  Downloaded dragonbox_ecma v0.1.12
  Downloaded divan v0.1.21
  Downloaded hashbrown v0.16.1
  Downloaded getrandom v0.4.2
  Downloaded thiserror v2.0.18
  Downloaded rustix v1.1.4
  Downloaded textwrap v0.16.2
  Downloaded similar v2.7.0
  Downloaded serde_derive v1.0.228
  Downloaded proc-macro2 v1.0.106
  Downloaded num-traits v0.2.19
  Downloaded serde_core v1.0.228
  Downloaded ryu v1.0.23
  Downloaded num-bigint v0.4.6
  Downloaded console v0.15.11
  Downloaded semver v1.0.27
  Downloaded rustc-hash v2.1.1
  Downloaded postcard v1.1.3
  Downloaded oxc_ecmascript v0.117.0
  Downloaded oxc_data_structures v0.117.0
  Downloaded once_cell v1.21.3
  Downloaded oxc_diagnostics v0.117.0
  Downloaded oxc-miette-derive v2.7.0
  Downloaded owo-colors v4.3.0
  Downloaded static_assertions v1.1.0
  Downloaded rustversion v1.0.22
  Downloaded quote v1.0.45
  Downloaded phf_macros v0.13.1
  Downloaded libc v0.2.183
  Downloaded phf v0.13.1
  Downloaded oxc_index v4.1.0
  Downloaded oxc_estree v0.117.0
  Downloaded lock_api v0.4.14
  Downloaded oxc_syntax v0.117.0
  Downloaded stable_deref_trait v1.2.1
  Downloaded seq-macro v0.3.6
  Downloaded compact_str v0.9.0
  Downloaded smawk v0.3.2
  Downloaded nonmax v0.5.5
  Downloaded fastrand v2.3.0
  Downloaded equivalent v1.0.2
  Downloaded oxc_ast_macros v0.117.0
  Downloaded hash32 v0.2.1
  Downloaded embedded-io v0.6.1
  Downloaded percent-encoding v2.3.2
  Downloaded errno v0.3.14
  Downloaded phf_generator v0.13.1
  Downloaded num-integer v0.1.46
  Downloaded itoa v1.0.17
  Downloaded heapless v0.7.17
  Downloaded cow-utils v0.1.3
  Downloaded cobs v0.3.0
  Downloaded divan-macros v0.1.21
  Downloaded condtype v1.3.0
  Downloaded clap_lex v1.0.0
  Downloaded bitflags v2.11.0
  Downloaded autocfg v1.5.0
  Downloaded anstyle v1.0.13
  Downloaded allocator-api2 v0.2.21
  Downloaded linux-raw-sys v0.12.1
   Compiling proc-macro2 v1.0.106
   Compiling unicode-ident v1.0.24
   Compiling quote v1.0.45
   Compiling cfg-if v1.0.4
   Compiling siphasher v1.0.2
   Compiling bitflags v2.11.0
   Compiling thiserror v2.0.18
   Compiling serde_core v1.0.228
   Compiling phf_shared v0.13.1
   Compiling rustversion v1.0.22
   Compiling allocator-api2 v0.2.21
   Compiling owo-colors v4.3.0
   Compiling serde v1.0.228
   Compiling hashbrown v0.16.1
   Compiling syn v2.0.117
   Compiling unicode-width v0.2.2
   Compiling unicode-linebreak v0.1.5
   Compiling smawk v0.3.2
   Compiling textwrap v0.16.2
   Compiling castaway v0.2.4
   Compiling itoa v1.0.17
   Compiling unicode-segmentation v1.12.0
   Compiling ryu v1.0.23
   Compiling rustc-hash v2.1.1
   Compiling fastrand v2.3.0
   Compiling oxc_data_structures v0.117.0
   Compiling static_assertions v1.1.0
   Compiling compact_str v0.9.0
   Compiling phf_generator v0.13.1
   Compiling oxc_allocator v0.117.0
   Compiling phf v0.13.1
   Compiling oxc_estree v0.117.0
   Compiling rustix v1.1.4
   Compiling autocfg v1.5.0
   Compiling num-traits v0.2.19
   Compiling oxc_str v0.117.0
   Compiling thiserror-impl v2.0.18
   Compiling serde_derive v1.0.228
   Compiling oxc-miette-derive v2.7.0
   Compiling phf_macros v0.13.1
   Compiling oxc_ast_macros v0.117.0
   Compiling linux-raw-sys v0.12.1
   Compiling cow-utils v0.1.3
   Compiling oxc-miette v2.7.0
   Compiling dragonbox_ecma v0.1.12
   Compiling libc v0.2.183
   Compiling percent-encoding v2.3.2
   Compiling oxc_span v0.117.0
   Compiling nonmax v0.5.5
   Compiling unicode-id-start v1.4.0
   Compiling semver v1.0.27
   Compiling rustc_version v0.4.1
   Compiling oxc_diagnostics v0.117.0
   Compiling oxc_index v4.1.0
   Compiling scopeguard v1.2.0
   Compiling num-integer v0.1.46
   Compiling lock_api v0.4.14
   Compiling oxc_syntax v0.117.0
   Compiling oxc_regular_expression v0.117.0
   Compiling heapless v0.7.17
   Compiling byteorder v1.5.0
   Compiling getrandom v0.4.2
   Compiling hash32 v0.2.1
   Compiling num-bigint v0.4.6
   Compiling spin v0.9.8
   Compiling terminal_size v0.4.3
   Compiling once_cell v1.21.3
   Compiling oxc_ast v0.117.0
   Compiling clap_lex v1.0.0
   Compiling stable_deref_trait v1.2.1
   Compiling anstyle v1.0.13
   Compiling clap_builder v4.5.60
   Compiling cobs v0.3.0
   Compiling memchr v2.8.0
   Compiling equivalent v1.0.2
   Compiling seq-macro v0.3.6
   Compiling indexmap v2.13.0
   Compiling tempfile v3.27.0
   Compiling postcard v1.1.3
   Compiling oxc_ecmascript v0.117.0
   Compiling clap v4.5.60
   Compiling console v0.15.11
   Compiling oxc_parser v0.117.0
   Compiling divan-macros v0.1.21
   Compiling regex-lite v0.1.9
   Compiling similar v2.7.0
   Compiling condtype v1.3.0
   Compiling divan v0.1.21
   Compiling insta v1.46.3
   Compiling zapcode-core v1.1.4 (/home/runner/work/zapcode/zapcode/crates/zapcode-core)
    Finished `bench` profile [optimized] target(s) in 37.40s
     Running unittests src/lib.rs (target/release/deps/zapcode_core-a6fd40b7a86354d6)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running benches/execution.rs (target/release/deps/execution-b1a2720cf270f553)
Timer precision: 20 ns
execution               fastest       │ slowest       │ median        │ mean          │ samples │ iters
├─ array_creation       3.135 µs      │ 81.02 µs      │ 3.315 µs      │ 4.451 µs      │ 100     │ 100
├─ fibonacci_10         176.5 µs      │ 213.3 µs      │ 178.3 µs      │ 181.1 µs      │ 100     │ 100
├─ function_call        6.06 µs       │ 11.01 µs      │ 6.291 µs      │ 6.372 µs      │ 100     │ 100
├─ loop_100             101.3 µs      │ 137.1 µs      │ 102.1 µs      │ 103.4 µs      │ 100     │ 100
├─ object_creation      6.821 µs      │ 18.21 µs      │ 7.022 µs      │ 7.289 µs      │ 100     │ 100
├─ simple_expression    2.774 µs      │ 4.998 µs      │ 2.844 µs      │ 2.886 µs      │ 100     │ 100
├─ string_concat        3.385 µs      │ 6.461 µs      │ 3.535 µs      │ 3.589 µs      │ 100     │ 100
├─ template_literal     3.787 µs      │ 14.98 µs      │ 3.906 µs      │ 4.114 µs      │ 100     │ 100
╰─ variable_arithmetic  3.896 µs      │ 6.091 µs      │ 4.006 µs      │ 4.04 µs       │ 100     │ 100


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