[GH-ISSUE #1] Support HEAD-only hooks on methods containing macros such as matches! #3

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

Originally created by @rdbtCVS on GitHub (Oct 28, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon-mixins/issues/1

🤖 Filed by OpenAI Codex at the user's request.

Request

Could HEAD-only injections support ordinary Rust functions whose bodies contain macros such as matches!, when the original body can be preserved unchanged?

The use case is observing keyboard input at Horizon's shared physical-key handler. We only need a noncancellable callback before the original method executes, without selecting anything inside a macro or rewriting returns.

What currently happens

With horizon-mixins 0500ff24aa5933fca95a877ef41125353c4b4fe3 (also the current main revision when checked), planning a HEAD injection on this target fails:

  • Horizon revision: e1b2b0b2fdf5962a30fb5de31b0c1bd6829d9083
  • Source: crates/horizon-client/src/game/debug_keys.rs
  • Target: horizon_client::game::debug_keys::Game<'_>::debug_key
E_UNSUPPORTED_MACRO: target contains an opaque macro

The method contains matches! calls. The rejection happens during planning, before host compilation.

A declaration targeting this boundary has this shape:

[[injection]]
id = "observe-input"
target = "horizon_client::game::debug_keys::Game<'_>::debug_key"
kind = "HEAD"
helper = "input.rs"
bindings = [
  { name = "key", ty = "winit::keyboard::KeyCode", value = "key" },
  { name = "action", ty = "horizon_client::debug_keys::KeyAction", value = "action" },
]

The helper would receive the key/action, then let the original method continue.

Why this boundary matters

Both real keyboard events and normal horizon-ctl key … tap commands pass through debug_key. The alternative mapped_key boundary does not receive normal control-socket key taps, so it cannot exercise the same mod input handler in controlled gameplay tests.

Suggested scope

This seems like an extension of the existing preserved-body HEAD support for closures and ?, following the usual Mixin HEAD semantics: call the handler first, then execute the original body unchanged.

Please retain stricter restrictions for interior/RETURN hooks, combinations requiring body analysis, unresolved cfg and attribute macros. No macro expansion or injection into macro contents is requested.

A regression fixture could verify that a HEAD hook on a method containing matches! compiles, invokes the callback once, and preserves the original return value, early returns and destruction behavior. If arbitrary body macros cannot safely be supported, a narrower supported case or explanation would also help.

Originally created by @rdbtCVS on GitHub (Oct 28, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon-mixins/issues/1 > 🤖 Filed by OpenAI Codex at the user's request. ## Request Could HEAD-only injections support ordinary Rust functions whose bodies contain macros such as `matches!`, when the original body can be preserved unchanged? The use case is observing keyboard input at Horizon's shared physical-key handler. We only need a noncancellable callback before the original method executes, without selecting anything inside a macro or rewriting returns. ## What currently happens With horizon-mixins `0500ff24aa5933fca95a877ef41125353c4b4fe3` (also the current main revision when checked), planning a HEAD injection on this target fails: - Horizon revision: `e1b2b0b2fdf5962a30fb5de31b0c1bd6829d9083` - Source: `crates/horizon-client/src/game/debug_keys.rs` - Target: `horizon_client::game::debug_keys::Game<'_>::debug_key` ```text E_UNSUPPORTED_MACRO: target contains an opaque macro ``` The method contains `matches!` calls. The rejection happens during planning, before host compilation. A declaration targeting this boundary has this shape: ```toml [[injection]] id = "observe-input" target = "horizon_client::game::debug_keys::Game<'_>::debug_key" kind = "HEAD" helper = "input.rs" bindings = [ { name = "key", ty = "winit::keyboard::KeyCode", value = "key" }, { name = "action", ty = "horizon_client::debug_keys::KeyAction", value = "action" }, ] ``` The helper would receive the key/action, then let the original method continue. ## Why this boundary matters Both real keyboard events and normal `horizon-ctl key … tap` commands pass through `debug_key`. The alternative `mapped_key` boundary does not receive normal control-socket key taps, so it cannot exercise the same mod input handler in controlled gameplay tests. ## Suggested scope This seems like an extension of the existing preserved-body HEAD support for closures and `?`, following the usual Mixin HEAD semantics: call the handler first, then execute the original body unchanged. Please retain stricter restrictions for interior/RETURN hooks, combinations requiring body analysis, unresolved cfg and attribute macros. No macro expansion or injection into macro contents is requested. A regression fixture could verify that a HEAD hook on a method containing `matches!` compiles, invokes the callback once, and preserves the original return value, early returns and destruction behavior. If arbitrary body macros cannot safely be supported, a narrower supported case or explanation would also help.
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#3
No description provided.