-
Notifications
You must be signed in to change notification settings - Fork 33
[WIP] Things required to get Python Type-Hints to work with cppyy #708
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
base: main
Are you sure you want to change the base?
[WIP] Things required to get Python Type-Hints to work with cppyy #708
Conversation
We need to identify which interpreter a Decl belongs to, when using multiple interpreter. We do it by checking which `clang::ASTContext` the `clang::Decl` belongs We maintain a map: `clang::ASTContext -> Cpp::InterpreterInfo`. Using this map, be identify the correct interpreter. There are 2 usecases for this: 1. We can now lock the correct interpreter making it thread safe. 2. User of `libCppInterOp` need not set the correct active interpreter using `Cpp::ActivateInterpreter`, this information can be retrived using the map.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #708 +/- ##
==========================================
- Coverage 79.83% 79.17% -0.66%
==========================================
Files 9 9
Lines 3962 4178 +216
==========================================
+ Hits 3163 3308 +145
- Misses 799 870 +71
🚀 New features to boost your workflow:
|
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.
@@ -12,6 +12,7 @@ | |||
#include "Compatibility.h" | |||
|
|||
#include "clang/AST/Attrs.inc" | |||
#include "clang/AST/Comment.h" | |||
#include "clang/AST/CXXInheritance.h" |
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: #includes are not sorted properly [llvm-include-order]
#include "clang/AST/CXXInheritance.h" | |
#include "clang/AST/CXXInheritance.h" | |
#include "clang/AST/Comment.h" |
@@ -130,15 +140,54 @@ | |||
}; | |||
|
|||
// std::deque avoids relocations and calling the dtor of InterpreterInfo. | |||
static llvm::ManagedStatic<std::deque<InterpreterInfo>> sInterpreters; | |||
static llvm::ManagedStatic<std::deque<std::shared_ptr<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]
sInterpreters;
^
sInterpreters; | ||
static llvm::ManagedStatic< | ||
std::unordered_map<clang::ASTContext*, std::weak_ptr<InterpreterInfo>>> | ||
sInterpreterASTMap; |
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 'sInterpreterASTMap' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
sInterpreterASTMap;
^
static llvm::ManagedStatic< | ||
std::unordered_map<clang::ASTContext*, std::weak_ptr<InterpreterInfo>>> | ||
sInterpreterASTMap; | ||
static std::mutex InterpreterStackLock; |
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 'InterpreterStackLock' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
static std::mutex InterpreterStackLock;
^
@@ -375,6 +438,11 @@ | |||
return llvm::StringRef(Ty.getAsString()).contains("complex"); | |||
} | |||
|
|||
bool IsTemplateClass(TCppScope_t handle) { | |||
auto* D = (clang::Decl*)handle; |
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 C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]
auto* D = (clang::Decl*)handle;
^
std::string GetDocString(TCppScope_t scope) { | ||
auto *D = static_cast<Decl*>(scope); | ||
auto &AST = getASTContext(D); | ||
const clang::RawComment *Comment = AST.getRawCommentForAnyRedecl(D); |
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 "clang::RawComment" is directly included [misc-include-cleaner]
lib/CppInterOp/CppInterOp.cpp:42:
- #if CLANG_VERSION_MAJOR >= 19
+ #include <clang/AST/RawCommentList.h>
+ #if CLANG_VERSION_MAJOR >= 19
D = GetUnderlyingScope(D); | ||
Within = llvm::dyn_cast<clang::DeclContext>(D); | ||
} | ||
|
||
auto* ND = Cpp_utils::Lookup::Named(&getSema(), name, Within); | ||
auto* ND = Cpp_utils::Lookup::Named(&getSema(D), name, Within); |
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 "Cpp::utils::Lookup::Named" is directly included [misc-include-cleaner]
lib/CppInterOp/CppInterOp.cpp:12:
+ #include "CppInterOpInterpreter.h"
if (!ns) | ||
return; | ||
|
||
auto* D = (clang::Decl*)ns; |
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 C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]
auto* D = (clang::Decl*)ns;
^
} | ||
|
||
// FIXME: This lookup is broken, and should no longer be used in favour of | ||
// `GetClassTemplatedMethods` If the candidate set returned is =1, that means | ||
// the template function exists and >1 means overloads | ||
bool ExistsFunctionTemplate(const std::string& name, TCppScope_t parent) { | ||
DeclContext* Within = 0; | ||
auto* D = (Decl*)parent; |
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 C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]
auto* D = (Decl*)parent;
^
@@ -1329,7 +1503,11 @@ | |||
|
|||
bool IsStaticMethod(TCppConstFunction_t method) { | |||
const auto* D = static_cast<const Decl*>(method); | |||
if (auto *FTD = llvm::dyn_cast_or_null<FunctionTemplateDecl>(D)) { |
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: 'auto *FTD' can be declared as 'const auto *FTD' [readability-qualified-auto]
if (auto *FTD = llvm::dyn_cast_or_null<FunctionTemplateDecl>(D)) { | |
if (const auto *FTD = llvm::dyn_cast_or_null<FunctionTemplateDecl>(D)) { |
Description
Please include a summary of changes, motivation and context for this PR.
Fixes # (issue)
Type of change
Please tick all options which are relevant.
Testing
Please describe the test(s) that you added and ran to verify your changes.
Checklist