Skip to content

fix: pin the int-for-float checker and keep the folded negative power under test - #100

Merged
heyJordanParker merged 3 commits into
masterfrom
fix/int-to-float-sweep
Oct 11, 2026
Merged

heyJordanParker merged 3 commits into
masterfrom
fix/int-to-float-sweep

Conversation

@heyJordanParker

@heyJordanParker heyJordanParker commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Problem

heyJordanParker/mago-sharp#129 refuses an int where PHP# expects a float. It also reads the type of a ** exponent, so let b = -1; return 2 ** b; is refused at compile time.

Overflow::constantNegativePower and Overflow::zeroNegativePower held their exponent that way. That form made opcache fold a constant negative power, which is what proves the zend_binary_op_produces_error guard from #97. Under the new pin the two methods no longer compile.

docs/spec.md section 24 annotated the rule with "write 0.0, or convert with (float) n" and "same message". The checker prints one fix, chosen by the code written.

Solution

SHARP_MAGO_COMMIT pins 625c278, the merge of mago-sharp #153. It carries #129 and #118. #129 merged as 82593a4, which did not compile against #118, and #153 fixed that. The bridge sources the header is generated from are unchanged since #129's head bce91aa, whose generated header differs from this one only in the pin.

The branch merges master after #101, which pins #118 and holds Sets.sharp's copied Set in a local before add. Its Sets.sharp and Sets.inc are taken as they are.

The two methods hold the exponent as ~0. The checker types ~0 as plain int, and opcache still propagates it as the constant int(-1):

Demo\Overflow::constantNegativePower:     (opcache.opt_debug_level=0x20000, after optimizer)
0000 T0 = POW int(2) int(-1)
Demo\Overflow::zeroNegativePower:
0000 T0 = POW int(0) int(-1)

Each section 24 annotation of the rule now prints the message the checker prints:

-float total = 0;                     // compile error: `int` is not `float`: write 0.0, or convert with (float) n
+float total = 0;                     // compile error: `int` is not `float`: write 0.0
-float price = count;                 // compile error, same message
+float price = count;                 // compile error: `int` is not `float`: convert with (float) count
-cell.put(2);                         // compile error, same message
+cell.put(2);                         // compile error: `int` is not `float`: write 2.0

Decision 73 quoted the same old message on lines 5, 12, 14 and 17. It now says the error quotes the one fix for the code written, and its annotations print the lines above.

Verification

The fold guard still has a test that fails without it:

  • With the three guard lines in zend_binary_op_produces_error removed, sharp/bin/test --passes Zend/tests/sharp/overflow_pow.phpt fails under the tracing JIT and the function JIT. Each prints the extra line Deprecated: Power of base 0 and negative exponent is deprecated in .../overflow_pow.inc on line 7.
  • With the lines back, sharp/bin/test --opcache --repeat --passes on overflow_pow.phpt, overflow_pow_jit_function.phpt and overflow_pow_jit_tracing.phpt passes in all 22 modes.

At the final pin, 625c278:

  • php -n --ri sharp prints Mago commit => 625c278f8303ff004daa00d29a9a90ca4e56fd6c.
  • mago compile at that commit compiles all 99 PHP# fixtures.
  • sharp/bin/test --opcache --repeat --passes on the three overflow_pow*.phpt and the three set_methods*.phpt tests passes 6 of 6 in all 22 modes.
  • sharp/bin/test passes 171 of 171.

Files

Zend/tests/sharp/
└── Overflow.sharp    <- constantNegativePower and zeroNegativePower hold -1 as ~0
docs/
├── spec.md           <- the int-for-float annotations print the checker's message
└── decisions/
    └── 073-int-to-float.md  <- quotes the message the checker prints
ext/sharp/
└── sharp_unit.h      <- SHARP_MAGO_COMMIT pins 625c278f8, the merge of mago-sharp #153

… under test

Problem
- mago-sharp #129 now reads the exponent's type, so `let b = -1; 2 ** b` is
  refused at compile time. `Overflow::constantNegativePower` and
  `Overflow::zeroNegativePower` held their exponent that way to make opcache
  fold a constant negative power. Under the new pin they no longer compile, and
  the proof of the `zend_binary_op_produces_error` guard would be lost with them.
- docs/spec.md annotates the int-for-float rule with "write 0.0, or convert
  with (float) n" and "same message". The checker prints one fix, by the one
  reason the value was refused.

Solution
- Hold the exponent as `~0`. The checker types `~0` as plain `int`, and opcache
  SCCP still folds it to `int(-1)`, so the dump shows `POW int(2) int(-1)` and
  `POW int(0) int(-1)` as before. Without the three guard lines,
  overflow_pow.phpt fails under `sharp/bin/test --passes` in both JIT modes
  with "Deprecated: Power of base 0 and negative exponent is deprecated". With
  them, all 22 modes pass on the three overflow_pow*.phpt tests.
- Each spec annotation of the rule prints the exact message the checker prints.
- Pin SHARP_MAGO_COMMIT to mago-sharp #129's head. The header that commit
  generates differs from this one only in the pin.

Zend/tests/sharp/
  Overflow.sharp      constantNegativePower and zeroNegativePower hold -1 as ~0
docs/
  spec.md             the int-for-float annotations print the checker's message
ext/sharp/
  sharp_unit.h        SHARP_MAGO_COMMIT bce91aa
Problem
- master took #101, which pins Mago at #118 (90e8d64) and rewrites
  Sets.sharp:75 and Sets.inc:75 so a Set's changing method has a place.
- This branch pinned #129's head (bce91aa). Both sides changed the pin line.
  #129 merged as 82593a4, which did not compile, and mago-sharp #153 fixed it
  as 625c278.

Solution
- Take master's Sets.sharp and Sets.inc as they are.
- SHARP_MAGO_COMMIT pins 625c278, the merge of
  #153, which carries both #118 and #129. The bridge sources the header is
  generated from are unchanged since bce91aa, so the pin is the only line the
  generated header changes.

Zend/tests/sharp/
  Sets.sharp, Sets.inc   from master: the copied Set is held in a local before add
ext/sharp/
  sharp_unit.h           conflict: SHARP_MAGO_COMMIT is 625c278, the merge of mago-sharp #153
Problem
- Decision 73 quotes the int-for-float error as "`int` is not `float`: write
  0.0, or convert with (float) n", and says "same message" for `count` and
  `cell.put(2)`. The checker now prints one fix, for the code written, and
  spec section 24 already quotes it.

Solution
- The decision says the error quotes the one fix for the code written, with
  `0` and `count` as examples, and its annotations print the messages spec
  section 24 prints.

docs/decisions/
  073-int-to-float.md   lines 5, 12, 14 and 17 print the checker's message
@heyJordanParker
heyJordanParker merged commit 5484ddb into master Oct 11, 2026
10 checks passed
@heyJordanParker
heyJordanParker deleted the fix/int-to-float-sweep branch October 11, 2026 21:12
heyJordanParker added a commit that referenced this pull request Oct 11, 2026
… to Mago 9cb1a28

Problem:
Master gained #100, which pins Mago #129 and keeps `Overflow.constantNegativePower` and
`Overflow.zeroNegativePower` compiling under #129's negative-power refusal by writing each
exponent as `~0`. This branch had fixed the same two lines with `int b = -1;` and
`int n = -1;`, so `Overflow.sharp` and the pin in `ext/sharp/sharp_unit.h` conflicted.

Solution:
- `Overflow.sharp` takes master's `~0`, which owns the fix. This branch's typed locals
  are gone.
- `ext/sharp/sharp_unit.h` is the header Mago 9cb1a28 generates. `php -n --ri sharp` prints
  "Mago commit => 9cb1a28…".
- `sharp/bin/test` passes 202 of 202 tests, and `sharp/bin/test --passes
  Zend/tests/sharp/overflow_pow.phpt` passes in all 19 modes.

Zend/tests/sharp/Overflow.sharp   <- conflict: master's `~0`
ext/sharp/sharp_unit.h            <- conflict: pinned to Mago 9cb1a28
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