-
Notifications
You must be signed in to change notification settings - Fork 31
Stack the created interpreters. #607
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
Stack the created interpreters. #607
Conversation
There was a problem hiding this 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 14. Check the log or trigger a new build to see more.
struct InterpDeleter { | ||
~InterpDeleter() = default; | ||
} Deleter; | ||
struct InterpreterInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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::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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]
auto Args = std::make_unique<const char*[]>(NumArgs + 2);
^
return I; | ||
} | ||
|
||
TInterp_t GetInterpreter() { return sInterpreter; } | ||
bool DeleteInterpreter(TInterp_t I /*=nullptr*/) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this 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
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.
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;
^
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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::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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this 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
struct InterpDeleter { | ||
~InterpDeleter() = default; | ||
} Deleter; | ||
struct InterpreterInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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.