Skip to content

Destroy the interpreters when they are owned. #610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025

Conversation

vgvassilev
Copy link
Contributor

This should fix a longstanding issue with resource deallocation in CppInterOp.

Copy link

codecov bot commented May 30, 2025

Codecov Report

Attention: Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.

Project coverage is 77.58%. Comparing base (27d762d) to head (caeddd5).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lib/CppInterOp/CppInterOp.cpp 91.66% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #610      +/-   ##
==========================================
+ Coverage   77.48%   77.58%   +0.09%     
==========================================
  Files           9        9              
  Lines        3713     3734      +21     
==========================================
+ Hits         2877     2897      +20     
- Misses        836      837       +1     
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOp.cpp 84.98% <91.66%> (+0.10%) ⬆️
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOp.cpp 84.98% <91.66%> (+0.10%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

static llvm::SmallVector<InterpreterInfo, 8> sInterpreters;

// std::deque avoids relocations and calling the dtor of InterpreterInfo.
static llvm::ManagedStatic<std::deque<InterpreterInfo>> sInterpreters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'sInterpreters' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

static llvm::ManagedStatic<std::deque<InterpreterInfo>> sInterpreters;
                                                        ^

assert(sInterpreters.empty() && "sInterpreter already in use!");
sInterpreters.push_back(
assert(sInterpreters->empty() && "sInterpreter already in use!");
sInterpreters->push_back(
{static_cast<compat::Interpreter*>(I), /*isOwned=*/false});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: argument name 'isOwned' in comment does not match parameter name 'O' [bugprone-argument-comment]

      {static_cast<compat::Interpreter*>(I), /*isOwned=*/false});
                                             ^
Additional context

lib/CppInterOp/CppInterOp.cpp:88: 'O' declared here

  InterpreterInfo(compat::Interpreter* I, bool O)
                                               ^

assert(sInterpreters.empty() && "sInterpreter already in use!");
sInterpreters.push_back(
assert(sInterpreters->empty() && "sInterpreter already in use!");
sInterpreters->push_back(
{static_cast<compat::Interpreter*>(I), /*isOwned=*/false});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use emplace_back instead of push_back [modernize-use-emplace]

Suggested change
{static_cast<compat::Interpreter*>(I), /*isOwned=*/false});
sInterpreters->emplace_back(static_cast<compat::Interpreter*>(I), /*isOwned=*/false);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth looking at this.

Copy link
Collaborator

@Vipul-Cariappa Vipul-Cariappa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

assert(sInterpreters.empty() && "sInterpreter already in use!");
sInterpreters.push_back(
assert(sInterpreters->empty() && "sInterpreter already in use!");
sInterpreters->push_back(
{static_cast<compat::Interpreter*>(I), /*isOwned=*/false});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth looking at this.

This should fix a longstanding issue with resource deallocation in CppInterOp.
@vgvassilev vgvassilev merged commit aeb6137 into compiler-research:main Jun 2, 2025
78 checks passed
@vgvassilev vgvassilev deleted the fix-lifetime branch June 2, 2025 10:43
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.

2 participants