Skip to content

Widen on the local iteration count, as the C++ iterator does - #33

Closed
arthaud wants to merge 1 commit into
meta:mainfrom
arthaud:fix-extrapolate-local-iterations
Closed

arthaud wants to merge 1 commit into
meta:mainfrom
arthaud:fix-extrapolate-local-iterations

Conversation

@arthaud

@arthaud arthaud commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

MonotonicFixpointIterator::extrapolate is documented to apply the join at the first iteration and the widening operator at every subsequent one, which is what MonotonicFixpointIteratorBase::extrapolate does in the C++ implementation:

if (context.get_local_iterations_for(node) == 0) {
  current_state->join_with(new_state);
} else {
  current_state->widen_with(new_state);
}

It read the global iteration count instead, which is never reset. run already calls reset_local_iteration_count_for whenever a component stabilizes, exactly as the C++ iterator does, but nothing read the count back, so a component that stabilized and was then entered again with a larger state was widened right away rather than joined once more.

The result is still a sound post-fixpoint, but it loses precision on nested loops, where the inner component is re-entered every time the outer one grows.

The new test covers this: its inner component stabilizes once before the outer one grows x, so its head is extrapolated with a local iteration count of 0 and a global one of 1. It fails before this change, with z widened to top instead of holding {0, 5}.

`MonotonicFixpointIterator::extrapolate` is documented to apply the join
at the first iteration and the widening operator at every subsequent one,
which is what `MonotonicFixpointIteratorBase::extrapolate` does in the
C++ implementation:

    if (context.get_local_iterations_for(node) == 0) {
      current_state->join_with(new_state);
    } else {
      current_state->widen_with(new_state);
    }

It read the global iteration count instead, which is never reset. `run`
already calls `reset_local_iteration_count_for` whenever a component
stabilizes, exactly as the C++ iterator does, but nothing read the count
back, so a component that stabilized and was then entered again with a
larger state was widened right away rather than joined once more.

The result is still a sound post-fixpoint, but it loses precision on
nested loops, where the inner component is re-entered every time the
outer one grows.

The new test covers this: its inner component stabilizes once before the
outer one grows `x`, so its head is extrapolated with a local iteration
count of 0 and a global one of 1. It fails before this change, with `z`
widened to top instead of holding {0, 5}.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FGo5pDipqSuWEHtiwYmxTx
@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Sep 6, 2026
@meta-codesync

meta-codesync Bot commented Sep 7, 2026

Copy link
Copy Markdown

@arthaud has imported this pull request. If you are a Meta employee, you can view this in D119057846.

meta-codesync Bot pushed a commit to meta/redex that referenced this pull request Sep 8, 2026
Summary:
`MonotonicFixpointIterator::extrapolate` is documented to apply the join at the first iteration and the widening operator at every subsequent one, which is what `MonotonicFixpointIteratorBase::extrapolate` does in the C++ implementation:

    if (context.get_local_iterations_for(node) == 0) {
      current_state->join_with(new_state);
    } else {
      current_state->widen_with(new_state);
    }

It read the global iteration count instead, which is never reset. `run` already calls `reset_local_iteration_count_for` whenever a component stabilizes, exactly as the C++ iterator does, but nothing read the count back, so a component that stabilized and was then entered again with a larger state was widened right away rather than joined once more.

The result is still a sound post-fixpoint, but it loses precision on nested loops, where the inner component is re-entered every time the outer one grows.

The new test covers this: its inner component stabilizes once before the outer one grows `x`, so its head is extrapolated with a local iteration count of 0 and a global one of 1. It fails before this change, with `z` widened to top instead of holding {0, 5}.

X-link: meta/SPARTA#33

Reviewed By: arnaudvenet

Differential Revision: D119057846

Pulled By: arthaud

fbshipit-source-id: d0997cefb4eda5056cb1b5dfa81ec3a7e6417ae4
meta-codesync Bot pushed a commit to meta/redex that referenced this pull request Sep 8, 2026
Summary:
`MonotonicFixpointIterator::extrapolate` is documented to apply the join at the first iteration and the widening operator at every subsequent one, which is what `MonotonicFixpointIteratorBase::extrapolate` does in the C++ implementation:

    if (context.get_local_iterations_for(node) == 0) {
      current_state->join_with(new_state);
    } else {
      current_state->widen_with(new_state);
    }

It read the global iteration count instead, which is never reset. `run` already calls `reset_local_iteration_count_for` whenever a component stabilizes, exactly as the C++ iterator does, but nothing read the count back, so a component that stabilized and was then entered again with a larger state was widened right away rather than joined once more.

The result is still a sound post-fixpoint, but it loses precision on nested loops, where the inner component is re-entered every time the outer one grows.

The new test covers this: its inner component stabilizes once before the outer one grows `x`, so its head is extrapolated with a local iteration count of 0 and a global one of 1. It fails before this change, with `z` widened to top instead of holding {0, 5}.

X-link: meta/SPARTA#33

Reviewed By: arnaudvenet

Differential Revision: D119057846

Pulled By: arthaud

fbshipit-source-id: d0997cefb4eda5056cb1b5dfa81ec3a7e6417ae4
@meta-codesync meta-codesync Bot closed this in 2b8f5db Sep 8, 2026
@meta-codesync meta-codesync Bot added the Merged label Sep 8, 2026
@meta-codesync

meta-codesync Bot commented Sep 8, 2026

Copy link
Copy Markdown

@arthaud merged this pull request in 2b8f5db.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity. Merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant