Skip to content

[AUTOMATED] Render named Rust Option<&u64> conditions as patterns - #1807

Merged
mahaloz merged 1 commit into
mainfrom
automated/rust-named-reference-option-pattern
Nov 19, 2026
Merged

mahaloz merged 1 commit into
mainfrom
automated/rust-named-reference-option-pattern

Conversation

@mahaloz

@mahaloz mahaloz commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

[AUTOMATED] Kuna prints a named Rust Option<&u64> condition as a field access that Rust rejects. Run this on Linux x86-64 with Rust 1.90 and Kuna's processor specs available.

set -eu
tmp=$(mktemp -d)
cat > "$tmp/option.rs" <<'RS'
#![no_std]
#![no_main]
static mut MARK: [u64; 2] = [0; 2];
#[panic_handler] fn panic(_: &core::panic::PanicInfo<'_>) -> ! { loop {} }
#[no_mangle] pub fn _start() -> ! { loop {} }
#[no_mangle] #[inline(never)] pub fn on_some(x: u64) -> u64 {
    unsafe { core::ptr::write_volatile(core::ptr::addr_of_mut!(MARK[0]), x); } x
}
#[no_mangle] #[inline(never)] pub fn on_none(x: u64) -> u64 {
    unsafe { core::ptr::write_volatile(core::ptr::addr_of_mut!(MARK[1]), x); } x
}
#[no_mangle] #[inline(never)] pub fn named_some(value: Option<&u64>) -> u64 {
    if value.is_some() { on_some(17) } else { on_none(29) }
}
RS
rustc --edition=2021 -C opt-level=1 -C debuginfo=2 -C panic=abort \
  -C relocation-model=static -C link-dead-code=yes -C link-arg=-nostartfiles \
  "$tmp/option.rs" -o "$tmp/option"
chmod 444 "$tmp/option"
kuna decompile "$tmp/option" named_some --language rust | sed -n '/^  if /p'

Stock prints if value.Some != core::ptr::null_mut() {.

With this change, Kuna prints if let ::core::option::Option::Some(_) = value {.

The condition uses a qualified pattern on the declared option and preserves callback selection. Stage checks cover both branch directions, a consumed payload, a returned option, ordinary pointers and C output. The native replay checks None and Some(&0). Median CPU time moved by +0.19% and +0.29% for the positive Some and None comparisons.

Model: openai/gpt-6.2-sol

@mahaloz
mahaloz merged commit cc433aa into main Nov 19, 2026
9 checks passed
@mahaloz
mahaloz deleted the automated/rust-named-reference-option-pattern branch November 19, 2026 15:35
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