fix(optimizer): keep argument side effects when folding is_int/is_float/is_bool - #21
Open
AlessioGiacobbe wants to merge 1 commit into
Open
fix(optimizer): keep argument side effects when folding is_int/is_float/is_bool#21AlessioGiacobbe wants to merge 1 commit into
AlessioGiacobbe wants to merge 1 commit into
Conversation
…at/is_bool doFoldSsaType folded a statically type-known is_int()/is_float()/ is_bool() call to the literal `true`, discarding the argument entirely. With `function f(): int`, `if (is_int(f()))` compiled to `if (true)` and f() was never invoked — its side effects silently vanished. Fold to a bare `true` only for plain variables and scalar literals; for any other argument emit `((void)(expr), true)` so the operand is still evaluated, mirroring how genIsNull already handles native scalar operands.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
doFoldSsaTypefolds a statically type-knownis_int()/is_float()/is_bool()call to the literaltrue, discarding the argument expression entirely:The compiled binary skips the call and its side effects silently vanish (verified:
int-called/float-called/bool-calledall missing from the compiled output, present under PHP).Fix
Fold to a bare
trueonly when the argument is a plain variable or scalar literal. For any other argument emit((void)(expr), true)so the operand is still evaluated — the same patterngenIsNullalready uses for native scalar operands a few lines below.Tests
tests/compiler/optimizations/is-type-fold-side-effects.phpt: typed function calls as arguments to all three predicates plus the plain-variable fold. Expected output generated from PHP 8.4; compiled output diffs clean.tests/compiler/optimizations/suite: 35 pass, the 2 failing SSA float-narrowing tests fail identically on master (pre-existing). No new PHPStan errors.