Skip to content

Conversation

kr-2003
Copy link
Contributor

@kr-2003 kr-2003 commented Sep 20, 2025

This PR enables Out-Of-Process Interpreter for CppInterOp.

Under the hood, it uses LLVM's llvm-jitlink-executor and lib ORC RT to delegate the JIT execution to different process. The user just needs to pass --use-oop-jit flag as ClangArgs while constructing the interpreter to use this feature.

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

There were too many comments to post at once. Showing the first 10 out of 16. Check the log or trigger a new build to see more.


inline std::unique_ptr<clang::Interpreter>
createClangInterpreter(std::vector<const char*>& args) {
createClangInterpreter(std::vector<const char*>& args, int stdin_fd = 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "std::vector" is directly included [misc-include-cleaner]

lib/CppInterOp/Compatibility.h:14:

+ #include <vector>

struct FileDeleter {
void operator()(FILE* f /* owns */) {
if (f)
fclose(f);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: calling legacy resource function without passing a 'gsl::owner<>' [cppcoreguidelines-owning-memory]

        fclose(f);
        ^

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

if (llvm::sys::RunningOnValgrind())
GTEST_SKIP() << "XFAIL due to Valgrind report";
TestUtils::CreateInterpreter();
pid_t pid = Cpp::GetExecutorPID();
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "pid_t" is directly included [misc-include-cleaner]

unittests/CppInterOp/FunctionReflectionTest.cpp:15:

- #include <string>
+ #include <sched.h>
+ #include <string>

}
}

TInterp_t
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "TInterp_t" is directly included [misc-include-cleaner]

unittests/CppInterOp/Utils.cpp:13:

- #include <string>
+ #include <clang-c/CXCppInterOp.h>
+ #include <string>

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

@mcbarton
Copy link
Collaborator

Before pushing commits to this PR please either ping me, or delete caches as they are made. This PR has caused a large number of llvm cached builds to be deleted on main, which in turn has required multiple PRs workflow runs to be stopped while the cache is rebuilt.

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

}

#ifndef _WIN32
pid_t getOutOfProcessExecutorPID() const {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function 'getOutOfProcessExecutorPID' should be marked [[nodiscard]] [modernize-use-nodiscard]

Suggested change
pid_t getOutOfProcessExecutorPID() const {
[[nodiscard]] pid_t getOutOfProcessExecutorPID() const {

}

#ifndef _WIN32
pid_t getOutOfProcessExecutorPID() const {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: method 'getOutOfProcessExecutorPID' can be made static [readability-convert-member-functions-to-static]

Suggested change
pid_t getOutOfProcessExecutorPID() const {
static pid_t getOutOfProcessExecutorPID() {

}

#ifndef _WIN32
pid_t getOutOfProcessExecutorPID() const {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "pid_t" is directly included [misc-include-cleaner]

lib/CppInterOp/CppInterOpInterpreter.h:25:

- #if CLANG_VERSION_MAJOR >= 19
+ #include <sched.h>
+ #if CLANG_VERSION_MAJOR >= 19

Copy link

codecov bot commented Oct 2, 2025

Codecov Report

❌ Patch coverage is 80.95238% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.98%. Comparing base (e1e07e0) to head (5621046).

Files with missing lines Patch % Lines
lib/CppInterOp/Compatibility.h 64.51% 11 Missing ⚠️
lib/CppInterOp/CppInterOpInterpreter.h 85.41% 7 Missing ⚠️
lib/CppInterOp/CppInterOp.cpp 92.30% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #717      +/-   ##
==========================================
- Coverage   81.03%   80.98%   -0.06%     
==========================================
  Files           9        9              
  Lines        4214     4308      +94     
==========================================
+ Hits         3415     3489      +74     
- Misses        799      819      +20     
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOp.h 95.55% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 88.82% <92.30%> (+0.01%) ⬆️
lib/CppInterOp/CppInterOpInterpreter.h 87.39% <85.41%> (-0.69%) ⬇️
lib/CppInterOp/Compatibility.h 85.71% <64.51%> (-6.33%) ⬇️
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOp.h 95.55% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 88.82% <92.30%> (+0.01%) ⬆️
lib/CppInterOp/CppInterOpInterpreter.h 87.39% <85.41%> (-0.69%) ⬇️
lib/CppInterOp/Compatibility.h 85.71% <64.51%> (-6.33%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Please look at the comments.

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

}
}

TInterp_t
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "TInterp_t" is directly included [misc-include-cleaner]

unittests/CppInterOp/Utils.cpp:15:

- #include <string>
+ #include <clang-c/CXCppInterOp.h>
+ #include <string>

@mcbarton
Copy link
Collaborator

mcbarton commented Oct 5, 2025

Codecov Report

❌ Patch coverage is 74.33628% with 29 lines in your changes missing coverage. Please review. ✅ Project coverage is 80.45%. Comparing base (fe3de3c) to head (cfbb303).
Files with missing lines Patch % Lines
lib/CppInterOp/CppInterOpInterpreter.h 67.39% 15 Missing ⚠️
lib/CppInterOp/Compatibility.h 58.62% 12 Missing ⚠️
lib/CppInterOp/CppInterOp.cpp 94.73% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #717      +/-   ##
==========================================
- Coverage   81.03%   80.45%   -0.59%     
==========================================
  Files           9        9              
  Lines        4214     4307      +93     
==========================================
+ Hits         3415     3465      +50     
- Misses        799      842      +43     

Files with missing lines Coverage Δ
include/CppInterOp/CppInterOp.h 95.55% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 88.67% <94.73%> (-0.13%) ⬇️
lib/CppInterOp/Compatibility.h 77.53% <58.62%> (-14.50%) ⬇️
lib/CppInterOp/CppInterOpInterpreter.h 83.89% <67.39%> (-4.19%) ⬇️
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOp.h 95.55% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 88.67% <94.73%> (-0.13%) ⬇️
lib/CppInterOp/Compatibility.h 77.53% <58.62%> (-14.50%) ⬇️
lib/CppInterOp/CppInterOpInterpreter.h 83.89% <67.39%> (-4.19%) ⬇️
🚀 New features to boost your workflow:

The tests are not covering over 1/4 of this patch. @kr-2003 can you improve the coverage?

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.

Sorry for the late code review. Please address the comments.

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

operator const clang::Interpreter&() const { return *inner; }
operator clang::Interpreter&() { return *inner; }

bool isOutOfProcess() const { return outOfProcess; }
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: function 'isOutOfProcess' should be marked [[nodiscard]] [modernize-use-nodiscard]

Suggested change
bool isOutOfProcess() const { return outOfProcess; }
[[nodiscard]] bool isOutOfProcess() const { return outOfProcess; }

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

std::string(LLVM_BUILD_LIB_DIR) + "/bin/llvm-jitlink-executor";
OutOfProcessConfig.UseSharedMemory = false;
OutOfProcessConfig.SlabAllocateSize = 0;
// LCOV_EXCL_START
Copy link
Collaborator

Choose a reason for hiding this comment

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

LCOV_EXCL_START and LCOV_EXCL_STOP are things I think we should be using. If something is not being covered, we need to know. Then we can make an informed decision if its not something expected to be covered. Excluding sections from the report is a bad idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can't test out this lambda. this block is run in the child process of oop interpreter. that's why ignored it during the coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am removing the comments. I realised that it's not good practice to ignore the coverage.

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

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

// Use interpreter-managed redirection file for out-of-process stdout
FILE* redirected = I.getRedirectionFileForOutOfProcess(FD);
if (redirected) {
m_TempFile.release(); // release ownership of current tmpfile
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the value returned by this function should not be disregarded; neglecting it may lead to errors [bugprone-unused-return-value]

        m_TempFile.release(); // release ownership of current tmpfile
        ^

m_OwnsFile = false;
}
} else {
m_TempFile.reset(tmpfile());
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: initializing non-owner argument of type 'pointer' (aka '_IO_FILE *') with a newly created 'gsl::owner<>' [cppcoreguidelines-owning-memory]

      m_TempFile.reset(tmpfile());
                       ^

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.

4 participants