PR #5961 Review Fixes — Per-Fusion Statement Tracking#6015
PR #5961 Review Fixes — Per-Fusion Statement Tracking#6015mdavis36 merged 4 commits intomd/phase2-per-fusionfrom
Conversation
Replace manual iterate-and-erase loops in removeStatementsOwnedBy with std::erase_if, which does single-pass partition-and-truncate instead of repeated O(n) deque shifts. This fixes O(n²) performance when a Fusion with many statements is destroyed.
…ortcuts Change Fusion::numExprs() and Fusion::numVals() to return counts from per_fusion_exprs_/per_fusion_vals_ (filtered to this Fusion) instead of global container counts. This is necessary for correct StatementGuard behavior with shared containers. Add numValsExcludingShortcuts() helper that subtracts active shortcut val pointers (zero_val_, one_val_, etc.) from the per-Fusion count. These singletons should persist across guard scopes, so the count must exclude them for LIFO pop-back consistency in removeStatementsCreatedAfter.
…tainers Update Fusion::removeStatementsCreatedAfter to compare per-Fusion counts (from exprsOwnedBy(this) and numValsExcludingShortcuts()) instead of global deque sizes. This correctly handles shared containers where other Fusions' statements would inflate the global counts. Add NVF_ERROR assertions to verify the LIFO invariant: the tail element of the global deque must belong to this Fusion. If violated, another Fusion appended concurrently (should be prevented by PR #5971 locking). Remove now-unnecessary deque size validation checks.
Change StatementGuard constructor to snapshot numExprs() (already per-Fusion) and numValsExcludingShortcuts() instead of numVals() (now also per-Fusion). This ensures the snapshot is consistent with the LIFO rollback logic in removeStatementsCreatedAfter, which correctly handles shortcut singletons.
|
!test |
Description
|
| Relevant files | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Enhancement |
|
PR Reviewer Guide
Here are some key observations to aid the review process:
| 🧪 PR contains tests |
| ⚡ Recommended focus areas for review |
LIFO Invariant Validation
|
Greptile SummaryApplies review fixes from PR #5961 for per-Fusion statement tracking in shared containers:
All changes are well-implemented with defensive assertions to catch violations of the LIFO invariant. The optimizations are algorithmically sound and the per-Fusion counting ensures correct behavior when multiple Fusions share an Confidence Score: 5/5
Important Files Changed
Last reviewed commit: 0abaf11 |
## Summary Review fixes for PR #5961 (Per-Fusion statement tracking): - **O(n²) → O(n)**: Optimize `removeStatementsOwnedBy` with `std::erase_if` - **Per-Fusion counts**: Convert `numExprs()`/`numVals()` to return per-Fusion counts instead of global - **StatementGuard fixes**: Snapshot and compare per-Fusion counts for correct LIFO rollback in shared containers - **LIFO assertions**: Verify tail elements belong to this Fusion before popping ## Tests All tests pass: - ✅ StatementGuardTest.ExecuteAfterGuard - ✅ StatementGuardTest.LazySpecialValsNotDangling - ✅ FusionCopy_CUDA - ✅ FusionMove_CUDA
## Summary Review fixes for PR #5961 (Per-Fusion statement tracking): - **O(n²) → O(n)**: Optimize `removeStatementsOwnedBy` with `std::erase_if` - **Per-Fusion counts**: Convert `numExprs()`/`numVals()` to return per-Fusion counts instead of global - **StatementGuard fixes**: Snapshot and compare per-Fusion counts for correct LIFO rollback in shared containers - **LIFO assertions**: Verify tail elements belong to this Fusion before popping ## Tests All tests pass: - ✅ StatementGuardTest.ExecuteAfterGuard - ✅ StatementGuardTest.LazySpecialValsNotDangling - ✅ FusionCopy_CUDA - ✅ FusionMove_CUDA
## Summary Review fixes for PR #5961 (Per-Fusion statement tracking): - **O(n²) → O(n)**: Optimize `removeStatementsOwnedBy` with `std::erase_if` - **Per-Fusion counts**: Convert `numExprs()`/`numVals()` to return per-Fusion counts instead of global - **StatementGuard fixes**: Snapshot and compare per-Fusion counts for correct LIFO rollback in shared containers - **LIFO assertions**: Verify tail elements belong to this Fusion before popping ## Tests All tests pass: - ✅ StatementGuardTest.ExecuteAfterGuard - ✅ StatementGuardTest.LazySpecialValsNotDangling - ✅ FusionCopy_CUDA - ✅ FusionMove_CUDA
## Summary Review fixes for PR #5961 (Per-Fusion statement tracking): - **O(n²) → O(n)**: Optimize `removeStatementsOwnedBy` with `std::erase_if` - **Per-Fusion counts**: Convert `numExprs()`/`numVals()` to return per-Fusion counts instead of global - **StatementGuard fixes**: Snapshot and compare per-Fusion counts for correct LIFO rollback in shared containers - **LIFO assertions**: Verify tail elements belong to this Fusion before popping ## Tests All tests pass: - ✅ StatementGuardTest.ExecuteAfterGuard - ✅ StatementGuardTest.LazySpecialValsNotDangling - ✅ FusionCopy_CUDA - ✅ FusionMove_CUDA
Summary
Review fixes for PR #5961 (Per-Fusion statement tracking):
removeStatementsOwnedBywithstd::erase_ifnumExprs()/numVals()to return per-Fusion counts instead of globalTests
All tests pass: