Stack the created interpreters.#607
Conversation
| struct InterpDeleter { | ||
| ~InterpDeleter() = default; | ||
| } Deleter; | ||
| struct InterpreterInfo { |
There was a problem hiding this comment.
warning: class 'InterpreterInfo' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
struct InterpreterInfo {
^| // FIXME: For now we just leak the Interpreter. | ||
| ~InterpreterInfo() {} | ||
| }; | ||
| static llvm::SmallVector<InterpreterInfo, 8> sInterpreters; |
There was a problem hiding this comment.
warning: variable 'sInterpreters' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
static llvm::SmallVector<InterpreterInfo, 8> sInterpreters;
^| // assert(!sInterpreter && "Interpreter already set."); | ||
| sInterpreter = I; | ||
| // assert(sInterpreters.empty() && "Interpreter already set."); | ||
| sInterpreters.push_back({I, /*isOwned=*/true}); |
There was a problem hiding this comment.
warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]
auto Args = std::make_unique<const char*[]>(NumArgs + 2);
^| } | ||
|
|
||
| TInterp_t GetInterpreter() { return sInterpreter; } | ||
| bool DeleteInterpreter(TInterp_t I /*=nullptr*/) { |
There was a problem hiding this comment.
warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
^9c4439e to
4eeafdf
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #607 +/- ##
==========================================
+ Coverage 77.31% 77.48% +0.17%
==========================================
Files 9 9
Lines 3685 3713 +28
==========================================
+ Hits 2849 2877 +28
Misses 836 836
🚀 New features to boost your workflow:
|
|
@aaronj0 and @Vipul-Cariappa, do you understand the cppyy assertion for this PR? |
e01c641 to
3cb4164
Compare
lib/CppInterOp/CppInterOp.cpp
Outdated
| }; | ||
|
|
||
| // std::deque avoids relocations and calling the dtor of InterpreterInfo. | ||
| static llvm::ManagedStatic<std::deque<InterpreterInfo>> sInterpreters; |
There was a problem hiding this comment.
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;
^
lib/CppInterOp/CppInterOp.cpp
Outdated
| TInterp_t GetInterpreter() { return sInterpreter; } | ||
| bool DeleteInterpreter(TInterp_t I /*=nullptr*/) { | ||
| if (!I) { | ||
| sInterpreters->pop_back(); |
There was a problem hiding this comment.
warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
^| EXPECT_TRUE(Cpp::DeleteInterpreter(nullptr)); | ||
| EXPECT_EQ(I2, Cpp::GetInterpreter()); | ||
|
|
||
| auto* I4 = reinterpret_cast<void*>(static_cast<std::uintptr_t>(~0U)); |
There was a problem hiding this comment.
warning: do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast]
auto* I4 = reinterpret_cast<void*>(static_cast<std::uintptr_t>(~0U));
^| EXPECT_TRUE(Cpp::DeleteInterpreter(nullptr)); | ||
| EXPECT_EQ(I2, Cpp::GetInterpreter()); | ||
|
|
||
| auto* I4 = reinterpret_cast<void*>(static_cast<std::uintptr_t>(~0U)); |
There was a problem hiding this comment.
warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
auto* I4 = reinterpret_cast<void*>(static_cast<std::uintptr_t>(~0U));
^| EXPECT_TRUE(Cpp::DeleteInterpreter(nullptr)); | ||
| EXPECT_EQ(I2, Cpp::GetInterpreter()); | ||
|
|
||
| auto* I4 = reinterpret_cast<void*>(static_cast<std::uintptr_t>(~0U)); |
There was a problem hiding this comment.
warning: no header providing "std::uintptr_t" is directly included [misc-include-cleaner]
auto* I4 = reinterpret_cast<void*>(static_cast<std::uintptr_t>(~0U));
^| EXPECT_TRUE(Cpp::Evaluate("__cplusplus") == 201703L) | ||
| << "Failed to activate C++17"; | ||
|
|
||
| auto* UntrackedI = reinterpret_cast<void*>(static_cast<std::uintptr_t>(~0U)); |
There was a problem hiding this comment.
warning: do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast]
auto* UntrackedI = reinterpret_cast<void*>(static_cast<std::uintptr_t>(~0U));
^| EXPECT_TRUE(Cpp::Evaluate("__cplusplus") == 201703L) | ||
| << "Failed to activate C++17"; | ||
|
|
||
| auto* UntrackedI = reinterpret_cast<void*>(static_cast<std::uintptr_t>(~0U)); |
There was a problem hiding this comment.
warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]
auto* UntrackedI = reinterpret_cast<void*>(static_cast<std::uintptr_t>(~0U));
^
@vgvassilev, you want to look at https://github.com/compiler-research/cppyy-backend/blob/e1068109110344b63b1546c853862db9632ec737/clingwrapper/src/clingwrapper.cxx#L182C1-L212C10 We first check if an interpreter already exists; if so, we just continue using it. Otherwise, create a new interpreter. EDITED |
258c884 to
5179760
Compare
| struct InterpDeleter { | ||
| ~InterpDeleter() = default; | ||
| } Deleter; | ||
| struct InterpreterInfo { |
There was a problem hiding this comment.
warning: class 'InterpreterInfo' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
struct InterpreterInfo {
^| TInterp_t GetInterpreter() { return sInterpreter; } | ||
| bool DeleteInterpreter(TInterp_t I /*=nullptr*/) { | ||
| if (!I) { | ||
| sInterpreters.pop_back(); |
There was a problem hiding this comment.
warning: narrowing conversion from 'unsigned int' to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]
llvm::cl::ParseCommandLineOptions(NumArgs + 1, Args.get());
^5179760 to
e1c2c04
Compare
This patch offers an API to switch back and forth different interpreters which can come at handy in several occasions including research into implementing threading. Fixes compiler-research#302.
e1c2c04 to
c2d62be
Compare
This patch offers an API to switch back and forth different interpreters which can come at handy in several occasions including research into implementing threading.
Fixes #302.