Skip to content

Conversation

@mdavis36
Copy link
Collaborator

Inlines registerVal, registerExpr, removeVal, and removeExpr logic directly into Fusion, eliminating the delegation to IrContainer. This consolidates the registration path after per-Fusion special values were moved from IrContainer to Fusion.

Also removes friend class StatementGuard from IrContainer (it only uses public Fusion API) and adds Fusion as a friend of IrContainerPasskey so it can construct passkeys for setName() calls.

Inlines registerVal, registerExpr, removeVal, and removeExpr logic
directly into Fusion, eliminating the delegation to IrContainer.
This consolidates the registration path after per-Fusion special
values were moved from IrContainer to Fusion.

Also removes vestigial friend class StatementGuard from IrContainer
(it only uses public Fusion API) and adds Fusion as a friend of
IrContainerPasskey so it can construct passkeys for setName() calls.
@github-actions
Copy link

Description

  • Inlines registerVal, registerExpr, removeVal, and removeExpr logic directly into Fusion class

  • Eliminates delegation to IrContainer for statement registration/removal operations

  • Consolidates registration path after per-Fusion special values were moved from IrContainer to Fusion

  • Removes vestigial friend class StatementGuard from IrContainer and adds Fusion as friend to IrContainerPasskey

Changes walkthrough

Relevant files
Enhancement
fusion.cpp
Inline registration/removal logic into Fusion methods       

csrc/fusion.cpp

  • Inlines removeExpr() logic directly into Fusion::removeExpr() method
  • Inlines removeVal() logic directly into Fusion::removeVal() method
  • Inlines registerVal() logic directly into Fusion::registerVal() method
  • Inlines registerExpr() logic directly into Fusion::registerExpr()
    method
  • +31/-4   
    container.cpp
    Remove registration/removal methods from IrContainer         

    csrc/ir/container.cpp

  • Removes IrContainer::removeExpr() method implementation
  • Removes IrContainer::removeVal() method implementation
  • Removes IrContainer::registerVal() method implementation
  • Removes IrContainer::registerExpr() method implementation
  • +0/-60   
    container.h
    Update IrContainer interface and friend declarations         

    csrc/ir/container.h

  • Removes method declarations for removeExpr, removeVal, registerVal,
    and registerExpr
  • Adds Fusion as friend class to IrContainerPasskey for setName() access
  • Removes StatementGuard as friend class from IrContainer
  • +1/-14   

    PR Reviewer Guide

    Here are some key observations to aid the review process:

    🧪 PR contains tests
    ⚡ Recommended focus areas for review
    Memory Management Safety

    The removeVal and removeExpr methods now contain duplicated logic for finding and erasing from both the set (vals_/exprs_) and deque (vals_up_/exprs_up_) containers. This creates potential for inconsistencies if the two containers become out of sync. Consider extracting this into a helper method or ensuring atomic operations.

      auto* c = ir_container();
      auto expr_in_deque = std::find_if(
          c->exprs_up_.begin(),
          c->exprs_up_.end(),
          [expr](std::unique_ptr<Expr>& expr_up) {
            return expr_up.get() == expr;
          });
      NVF_ERROR(
          expr_in_deque != c->exprs_up_.end(),
          "Wanted to remove an expression but its unique ptr is missing.");
      c->exprs_.erase(expr);
      c->exprs_up_.erase(expr_in_deque);
    }
    Error Handling Robustness

    The new inline registration logic includes NVF_ERROR checks for missing entries in both containers. Ensure these error conditions are properly tested and that the error messages provide sufficient context for debugging.

    NVF_ERROR(
        expr_in_deque != c->exprs_up_.end(),
        "Wanted to remove an expression but its unique ptr is missing.");
    Friend Class Removal Impact

    StatementGuard is removed as a friend class from IrContainer. Verify that StatementGuard can still function properly using only the public Fusion API, and ensure no functionality is broken by this change.

    std::unordered_set<Val*> vals_;
    
    // Deque of unique pointer is the memory owning data structure

    @mdavis36
    Copy link
    Collaborator Author

    !test

    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