Skip to content

Prune consumed nodes and recompute mappings in fold legalization. - #5407

Draft
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1019698616
Draft

copybara-service[bot] wants to merge 1 commit into
mainfrom
test_1019698616

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Prune consumed nodes and recompute mappings in fold legalization.

ResourceSharingPass::LegalizeSequenceOfFolding previously missed two
node-deletion cases enforced by PerformFoldingActions
(renaming_done_by_previous_folding): (1) a later fold whose destination was
already folded as a source was kept during legalization (poisoning its own
sources from subsequent legal folds) and then skipped at execution, and (2) a
node replaced via a prior fold's destination EquivalenceMapping remained
inside downstream folding batches, causing PerformFoldingActions to abort the
entire downstream batch rather than folding its remaining legal sources. In
addition, when sources were pruned during N-ary action construction or
legalization, pre-pruning mappings were retained (leaving stale destination
widenings) and modified remained false when a multi-source batch lost a
duplicate source.

  • Track consumed_nodes ({accepted sources} ∪ {accepted mapped destinations})
    in LegalizeSequenceOfFolding: drop any fold targeting a consumed or
    already-targeted destination, prune consumed sources from downstream batches,
    and set modified = true whenever a fold or source is dropped.
  • Recompute compatible N-ary EquivalenceMappings via eq_mapper whenever a
    fold loses sources in MakeNaryFoldingAction or LegalizeSequenceOfFolding.
  • Require eq_mapper explicitly on MakeNaryFoldingAction and
    LegalizeSequenceOfFolding rather than defaulting to the global equivalence
    mapper.

@copybara-service
copybara-service Bot force-pushed the test_1019698616 branch 2 times, most recently from 4a7958d to 6155541 Compare November 17, 2026 00:44
@copybara-service copybara-service Bot changed the title Prune replaced destinations and recompute mappings in fold legalization. Prune consumed nodes and recompute mappings in fold legalization. Nov 17, 2026
`ResourceSharingPass::LegalizeSequenceOfFolding` previously missed two
node-deletion cases enforced by `PerformFoldingActions`
(`renaming_done_by_previous_folding`): (1) a later fold whose destination was
already folded as a source was kept during legalization (poisoning its own
sources from subsequent legal folds) and then skipped at execution, and (2) a
node replaced via a prior fold's destination `EquivalenceMapping` remained
inside downstream folding batches, causing `PerformFoldingActions` to abort the
entire downstream batch rather than folding its remaining legal sources. In
addition, when sources were pruned during N-ary action construction or
legalization, pre-pruning mappings were retained (leaving stale destination
widenings) and `modified` remained `false` when a multi-source batch lost a
duplicate source.

- Track `consumed_nodes` (`{accepted sources} ∪ {accepted mapped destinations}`)
  in `LegalizeSequenceOfFolding`: drop any fold targeting a consumed or
  already-targeted destination, prune consumed sources from downstream batches,
  and set `modified = true` whenever a fold or source is dropped.
- Recompute compatible N-ary `EquivalenceMapping`s via `eq_mapper` whenever a
  fold loses sources in `MakeNaryFoldingAction` or `LegalizeSequenceOfFolding`.
- Require `eq_mapper` explicitly on `MakeNaryFoldingAction` and
  `LegalizeSequenceOfFolding` rather than defaulting to the global equivalence
  mapper.

PiperOrigin-RevId: 1019698616

This branch has not been deployed

No deployments
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