engine: detect self-indexing in subscript polarity analyzer#499
engine: detect self-indexing in subscript polarity analyzer#499
Conversation
The Expr2::Subscript arm in analyze_expr_polarity_with_context returned current_polarity whenever the subscripted array's identifier matched from_var, regardless of whether the index expressions also referenced from_var. For arr[INT(arr[i])] (and similar self-indexing patterns) the relationship is non-monotone: changing arr shifts both the lookup target and the index. Walk the index expressions with expr_references_var and return Unknown when any index also references from_var. The dominant SUM(arr[*]) / arr[Region] cases are unaffected since their indices don't reference from_var. Surfaced by code review on PR #491 after merge.
|
@codex review |
ReviewI reviewed the diff and don't see any blocking issues. The change is a strict refinement of the prior The inline index match correctly mirrors how Test coverage exercises literal, wildcard, other-var, direct Overall correctness: correct. The patch addresses the docstring-claim gap without altering any pre-existing behavior outside the self-indexing case. |
|
Codex Review: Didn't find any major issues. Keep them coming! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #499 +/- ##
==========================================
- Coverage 82.44% 82.43% -0.01%
==========================================
Files 243 243
Lines 61887 61893 +6
==========================================
+ Hits 51021 51022 +1
- Misses 10866 10871 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
The
Expr2::Subscriptarm inanalyze_expr_polarity_with_context(added in #491) returned
current_polaritywhenever the array'sidentifier matched
from_var, without inspecting the indexexpressions. For self-indexing patterns like
arr[INT(arr[i])],the relationship between
arrand the subscripted value isnon-monotone -- changing
arrshifts both the lookup target ANDthe index. The arm now walks index expressions via
expr_references_varand returnsUnknownwhen any indexreferences
from_var.The dominant cases (
SUM(arr[*]),arr[Region], indices thatreference other variables) are unaffected -- those indices do not
reference
from_var, so the existing behavior of returningcurrent_polarityis preserved.Why now
Surfaced by a code review on #491 (the array reducer polarity PR)
after that PR merged. The reviewer flagged it as non-blocking but
worth generalizing because the arm's docstring claimed the case was
fully handled. This PR follows up to make the docstring's claim
true.
Test plan
var-from_var (NEW), nested self-indexing (NEW), other-array.