Skip to content

fix: reconstruct attacker, victim and removeFromArray value calls in convert --target opy - #758

Closed
e54-bot wants to merge 3 commits into
mainfrom
fix-744b-reconstruct-value-calls
Closed

e54-bot wants to merge 3 commits into
mainfrom
fix-744b-reconstruct-value-calls

Conversation

@e54-bot

@e54-bot e54-bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Refs #724
Refs #744

Change

convert --target opy now reconstructs these value calls (in reconstruct/value_literals.rs):

  • attacker, victim, healer, healee (no arguments) as the bare OPY keyword;
  • removeFromArray(array, value) as (array).exclude(value).

A Set whose removeFromArray operand is its own target (Set Global Variable(g, Remove From Array(g, v))) is refused with unsupported-value-call naming removeFromArray: g = g.exclude(v) recompiles to the Modify form, so it cannot round-trip.

Tests in tests/reconstruction_value_calls.rs: OPY round trips in en-US and zh-CN, and the self-referential Set form given as Workshop text (global and player variable) in en-US and zh-CN, which fails on main. The recorded mysteryUltimates classification drops unsupported-value-call.

Reproduction (wright 0.44.0)

Validation

fmt, clippy (stable and 1.88.0, -D warnings), cargo test --workspace --all-targets --all-features, tools/overpy/tests, run_oracle.py, run_native.py: all pass after rebase on origin/main.

@Teakowa

Teakowa commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

NOT VERIFIED on head ecb7ea29ab5778ffa79442c910788116fece884a. One finding.

  1. removeFromArray reconstructs to OPY that recompiles to a canonically different program when the Workshop input is the self-referential Set form.

    Input (Workshop text, workshop_rs::parser::parse accepts it):

    Set Global Variable(g, Remove From Array(Global.g, Victim));
    

    wright convert --target opy now succeeds and emits g = (g).exclude(victim). Recompiling it gives Modify Global Variable(g, Remove From Array By Value, Victim);, because self_modification in compiler/operator_optimization.rs rewrites Set x = removeFromArray(x, y) into the modify form. workshop_rs::compare::equivalent(first, recompiled) is false: Difference { path: [Action(1), Value(0)], kind: Operation { first: "removeFromArray", second: "removeFromArrayByValue" } }. I reproduced it with a global variable; the player-variable form takes the same lowering path, but I did not run it. The same shape with Add(Global.g, 1) compares equal, so only this call is affected. On main the input was refused; with the PR it silently produces a non-equal program, which breaks the fix: reconstruct array and workshop setting value calls in convert --target opy #744 acceptance (reconstructed OPY recompiles to a canonically equal program) for a common Workshop pattern. The new tests only use sources the compiler already normalized, so they do not reach it.

    Required correction, smallest useful level: make the self-referential Set form of removeFromArray either round-trip (the owner of the comparison or of the reconstruction picks one) or refuse with a typed unsupported-value-call diagnostic naming removeFromArray, and add a test whose Workshop input is the Set form (not compiled from OPY first). The Modify form already reconstructs through g.remove(x).

Verified otherwise:

  • Round trips from OPY (en-US and zh-CN, byte-equal): attacker, victim, healer, healee in playerDealtDamage and playerDealtHealing rules, in conditions, assignments, member access victim.P, call arguments, arrays and if conditions; .exclude on literals, variables, nested .exclude(...).exclude(...), vectors, getPlayers, an empty array and an array-valued argument.
  • Pinned OverPy 9.7.17 (pnpm exec overpy compile) accepts the reconstructed OPY and its output equals the oracle output for the original, except for the existing //Strict optimizations enabled header.
  • A native global-rule input with Attacker and Remove From Array(Global.g, Victim) fails the same way as finding 1 only for the Set form; the attacker part round trips.
  • Still refused with a typed diagnostic naming the construct: __ambiguous_enum (unsupported-value-call ... '__ambiguous_enum'), and appendToArray.
  • The two new event_player_and_exclude_value_calls_* tests fail on main (value call 'attacker' has no OPY source form) and pass on the head.
  • Gates on this head: cargo fmt --check, clippy --workspace --all-targets --all-features -D warnings, cargo test --workspace --all-targets --all-features (857 passed, 0 failed), run_oracle.py (exit 0, 209 PASS), run_native.py (193 match), tools/overpy/tests (OK).
  • Refs #744 / Refs #724 and the remaining-scope statement for __ambiguous_enum are accurate. No unrelated churn (+53/−11 in two files).

The reconstructed 'x = x.exclude(v)' recompiles to the Modify form, so the Set form cannot round-trip. Refs #744
@Teakowa
Teakowa force-pushed the fix-744b-reconstruct-value-calls branch from ecb7ea2 to dd99684 Compare November 18, 2026 14:00
@Teakowa

Teakowa commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

NOT VERIFIED on head dd99684d257c473db48ed110a0b041d27ffcd575. One finding; round 1's finding is fixed.

  1. The indexed self-referential Set of removeFromArray is not refused and reconstructs to a canonically different program.

    Input (Workshop text): Set Global Variable At Index(g, 1, Remove From Array(Value In Array(Global.g, 1), 5));. convert --target opy succeeds and emits g[1] = ((g)[1]).exclude(5). Recompiling gives Modify Global Variable At Index(g, 1, Remove From Array, 5);. workshop_rs::compare::equivalent is false: path: [Action(0)], kind: Scalar { first: "setGlobalVariableAtIndex", second: "modifyGlobalVariableAtIndex" }. The player form Set Player Variable At Index(Event Player, P, 1, Remove From Array(Value In Array(Event Player.P, 1), 5)) fails the same way (setPlayerVariableAtIndex vs modifyPlayerVariableAtIndex). On main these inputs were refused; with the PR they succeed with a non-equal result. This is the same defect class as round 1, in the shape set_rhs does not reach: the guard sits only in emit_source_set_form and compares the rendered operand with the plain target string, so an indexed target g[1] is never matched.

    Required correction: refuse the indexed self-referential shape the same way, with unsupported-value-call naming removeFromArray, and add an indexed Set-form test.

    Scope note for the owner: Set Global Variable At Index(g, 1, Add(Value In Array(Global.g, 1), 5)) is non-equal in the same way on this head (g[1] = ((g)[1] + 5)), so the indexed Set-to-Modify gap is wider than this PR and already exists for arithmetic. If the owner decides to track the indexed gap in one separate Issue, finding 1 can move there; I report it because the PR states that a self-referential Set cannot round-trip and refuses only the non-indexed form.

Checked and holding:

  • Non-indexed self-referential Set, global and player forms (Event Player.P, (Victim).P, with the nested Remove From Array(g, Remove From Array(g, 1)), inside If and While bodies, and with a parenthesized operand): refused with unsupported-value-call: value call 'removeFromArray' on its own assignment target '<target>'.
  • Not wrongly refused and byte-equal after a round trip: a different target (h = g.exclude(...)), (attacker).P = (victim.P).exclude(1), eventPlayer.P = (attacker.P).exclude(1), the Modify form (g.remove(victim)), g = h.exclude(1).exclude(g), g = [g.exclude(1), 2], g = g.exclude(1).exclude(2).
  • The new tests use the Workshop Set text as input. With the guard disabled (name == "zzz"), both self_referential_remove_from_array_set_is_refused_* tests fail and the other four still pass.
  • Round-1 positives hold after the rebase: attacker, victim, healer, healee, .exclude in conditions, assignments, arguments, nested and with vectors and getPlayers; en-US and zh-CN byte-equal.
  • Gates: cargo fmt --check, clippy --workspace --all-targets --all-features -D warnings, cargo test --workspace --all-targets --all-features (861 passed, 0 failed), run_oracle.py (exit 0, 209 PASS), run_native.py (209 fixtures), tools/overpy/tests (OK).
  • PR body: Refs #724 / Refs #744, and the __ambiguous_enum note is accurate.

…lement

x[i] = x[i].exclude(v) recompiles to the Modify-at-index form. Refs #744
@Teakowa

Teakowa commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

NOT VERIFIED on head 5eb95abd79a95147b8d55b53a2a879b5cff709f8. One finding; round 2's finding is fixed.

  1. set_rhs compares the operand and the target after deleting (, ) and spaces, so two different elements can match and a valid program is refused.

    Source (compiles with wright compile):

    g[(h + i) * 2] = g[h + i * 2].exclude(5)
    

    It lowers to Set Global Variable At Index(g, Multiply(Add(Global.h, Global.i), 2), Remove From Array(Value In Array(Global.g, Add(Global.h, Multiply(Global.i, 2))), 5)). The target index is (h + i) * 2 and the operand index is h + i * 2; they are different elements, so the Set does not modify itself and the lowering keeps it as a Set. convert --target opy on the compiled output now refuses: unsupported-value-call: value call 'removeFromArray' on its own assignment target 'g[((h + i) * 2)]' recompiles to a modify action. Head dd99684 reconstructed this input byte-equal, so this is a regression from the previous head. The cause is let strip = |text| text.replace(['(', ')', ' '], "") in reconstruct/value_literals.rs: g[((h + i) * 2)] and g[h + (i * 2)] both strip to g[h+i*2].

    Required correction: compare the target and the operand structurally or by the identical rendering, without stripping parentheses, so that only a real self reference is refused. Add a test with a pair of indexes that differ only in grouping.

Checked and holding:

  • Both indexed self-referential forms are refused naming removeFromArray: Set Global Variable At Index(g, 1, ...) (target g[1]), Set Player Variable At Index(Event Player, P, 1, ...) (eventPlayer.P[1]), (Victim).P[2], a variable index g[h], and an operand that also appears as the removed value (Remove From Array(g[1], g[1])).
  • Still round-trip byte-equal: other array (g[1] = h[1].exclude(5), g[1] = g[2].exclude(5), g[h] = g[i].exclude(5)), whole array operand (g[1] = g.exclude(5)), nested (g[1] = g[1].exclude(5).exclude(6), g[1][1].exclude(5)), wrapped (g[1] = [g[1].exclude(5)]), another player (eventPlayer.P[1] = attacker.P[1].exclude(5)), the Modify forms (g.remove(x), g[1].remove(5)), and the non-indexed shapes from round 2.
  • The new indexed tests use Workshop Set text as input. With the guard disabled both self_referential_remove_from_array_set_is_refused_* tests fail and the other four pass.
  • Round-1 and round-2 positives (attacker, victim, healer, healee, .exclude in conditions, assignments, arguments, nested): en-US and zh-CN byte-equal.
  • Gates: cargo fmt --check, clippy --workspace --all-targets --all-features -D warnings, cargo test --workspace --all-targets --all-features (861 passed, 0 failed), run_oracle.py (exit 0, 209 PASS), run_native.py (209 fixtures), tools/overpy/tests (OK).
  • PR body: Refs #724 / Refs #744. The arithmetic indexed gap is tracked in fix: reconstruct or refuse indexed self-referential Set forms in convert --target opy #761 and not part of this review.

@Teakowa

Teakowa commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Closing after three review rounds that each found a distinct defect in the self-reference guard (text comparison of rendered operand and target). The Issue is redone from scratch in a new PR that compares structurally and carries the review findings as input. Refs #744.

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.

2 participants