[PR #14] [MERGED] feat(plan): modify a variable in functions with closures and ? elsewhere #18

Closed
opened 2026-11-02 15:32:32 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon-mixins/pull/14
Author: @reservedbytes
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @levzzz5154

Base: main ← Head: feat/modify-variable-closures


📝 Commits (2)

  • 4ad05ba feat(plan): modify a variable in functions with closures and ? elsewhere
  • 2145b5c Merge remote-tracking branch 'origin/main' into p14

📊 Changes

7 files changed (+202 additions, -6 deletions)

View changed files

📝 README.md (+2 -1)
➕ crates/horizon-mixins-cli/tests/cases/variables.rs (+152 -0)
📝 crates/horizon-mixins-cli/tests/integration.rs (+3 -0)
📝 crates/horizon-mixins-core/src/plan.rs (+31 -2)
📝 crates/horizon-mixins-core/src/scopes.rs (+3 -2)
📝 docs/mixin-api.md (+3 -1)
📝 docs/scopes-and-bridges.md (+8 -0)

📄 Description

What and why

#9 let RETURN plan in functions with closures and references to calls outside the values it moves, MODIFY_VARIABLE still refused the whole function

Horizon's Mob::damage_with has a closure (.then(|| golem::crackiness(self))), so a MODIFY_VARIABLE on its amount fails with E_UNSUPPORTED_CONTROL_FLOW even though the hook only touches one read or one store

MODIFY_VARIABLE now works like RETURN after #9: only the value it replaces is checked (a closure, a ? or a call beneath a reference there stays refused), and the rest of the body is left alone, ? included since it isn't an exit a variable hook could miss

A closure's own locals already stay out of ordinals (#9), and a read or write of the variable inside a closure still counts toward require but selecting it is E_UNSUPPORTED_LOCAL, since no hook runs there

Other hooks that rewrite inside the body keep the whole-body check

On Horizon main (70436b6) a MODIFY_VARIABLE on Mob::damage_with's amount (the parameter at LOAD, and the local at STORE) went from E_UNSUPPORTED_CONTROL_FLOW to planning, and the staged game compiles

Checks

cargo fmt --all --check
cargo clippy --workspace --all-targets --locked -- -D warnings
cargo test --workspace --locked (96 passed, new tests variable_hooks_leave_closures_question_marks_and_referenced_calls_outside_the_value_alone, which fails without the fix, and variable_hooks_still_refuse_closures_question_marks_and_referenced_calls_in_the_value)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon-mixins/pull/14 **Author:** [@reservedbytes](https://github.com/reservedbytes) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `feat/modify-variable-closures` --- ### 📝 Commits (2) - [`4ad05ba`](https://github.com/horizon-rust/horizon-mixins/commit/4ad05bae467a90b23acf630c75799278caca15c3) feat(plan): modify a variable in functions with closures and ? elsewhere - [`2145b5c`](https://github.com/horizon-rust/horizon-mixins/commit/2145b5c6f18e72184133bec443c2507b5ec21cdf) Merge remote-tracking branch 'origin/main' into p14 ### 📊 Changes **7 files changed** (+202 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+2 -1) ➕ `crates/horizon-mixins-cli/tests/cases/variables.rs` (+152 -0) 📝 `crates/horizon-mixins-cli/tests/integration.rs` (+3 -0) 📝 `crates/horizon-mixins-core/src/plan.rs` (+31 -2) 📝 `crates/horizon-mixins-core/src/scopes.rs` (+3 -2) 📝 `docs/mixin-api.md` (+3 -1) 📝 `docs/scopes-and-bridges.md` (+8 -0) </details> ### 📄 Description ## What and why #9 let RETURN plan in functions with closures and references to calls outside the values it moves, MODIFY_VARIABLE still refused the whole function Horizon's `Mob::damage_with` has a closure (`.then(|| golem::crackiness(self))`), so a MODIFY_VARIABLE on its `amount` fails with `E_UNSUPPORTED_CONTROL_FLOW` even though the hook only touches one read or one store MODIFY_VARIABLE now works like RETURN after #9: only the value it replaces is checked (a closure, a `?` or a call beneath a reference there stays refused), and the rest of the body is left alone, `?` included since it isn't an exit a variable hook could miss A closure's own locals already stay out of ordinals (#9), and a read or write of the variable inside a closure still counts toward `require` but selecting it is `E_UNSUPPORTED_LOCAL`, since no hook runs there Other hooks that rewrite inside the body keep the whole-body check On Horizon `main` (`70436b6`) a MODIFY_VARIABLE on `Mob::damage_with`'s `amount` (the parameter at LOAD, and the local at STORE) went from `E_UNSUPPORTED_CONTROL_FLOW` to planning, and the staged game compiles ## Checks `cargo fmt --all --check` `cargo clippy --workspace --all-targets --locked -- -D warnings` `cargo test --workspace --locked` (96 passed, new tests `variable_hooks_leave_closures_question_marks_and_referenced_calls_outside_the_value_alone`, which fails without the fix, and `variable_hooks_still_refuse_closures_question_marks_and_referenced_calls_in_the_value`) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:32:32 +07:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon-mixins#18
No description provided.