Skip to content

Destroy the interpreters when they are owned.#610

Merged
vgvassilev merged 1 commit into
compiler-research:mainfrom
vgvassilev:fix-lifetime
Jun 2, 2025
Merged

Destroy the interpreters when they are owned.#610
vgvassilev merged 1 commit into
compiler-research:mainfrom
vgvassilev:fix-lifetime

Conversation

@vgvassilev
Copy link
Copy Markdown
Contributor

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

@codecov
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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;
                                                        ^

Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
sInterpreters.push_back(
assert(sInterpreters->empty() && "sInterpreter already in use!");
sInterpreters->push_back(
{static_cast<compat::Interpreter*>(I), /*isOwned=*/false});
Copy link
Copy Markdown
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)
                                               ^

Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
sInterpreters.push_back(
assert(sInterpreters->empty() && "sInterpreter already in use!");
sInterpreters->push_back(
{static_cast<compat::Interpreter*>(I), /*isOwned=*/false});
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!

Comment thread lib/CppInterOp/CppInterOp.cpp Outdated
sInterpreters.push_back(
assert(sInterpreters->empty() && "sInterpreter already in use!");
sInterpreters->push_back(
{static_cast<compat::Interpreter*>(I), /*isOwned=*/false});
Copy link
Copy Markdown
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