-
Notifications
You must be signed in to change notification settings - Fork 31
Add type info interfaces motivated by numba #534
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?
Conversation
- Add `IsSameType` used for matching arg types between numba inferred signatures and CppOverloads in cppyy. - Add type info reflection interfaces for integer, void pointer, signed and unsigned types. - Also added interfaces `IsIntegral` and `IsFloating` that check if types have the respective representations. Used in the case of Numba where scoring based on reflection is required.
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/Interpreter/CppInterOp.cpp
Outdated
@@ -1573,8 +1609,17 @@ namespace Cpp { | |||
return QT.getNonReferenceType().getAsOpaquePtr(); | |||
} | |||
|
|||
TCppType_t GetUnqualifiedType(TCppType_t type) { | |||
if (!type) | |||
return 0; |
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: use nullptr [modernize-use-nullptr]
return 0; | |
return nullptr; |
lib/Interpreter/CppInterOp.cpp
Outdated
TCppType_t GetUnderlyingType(TCppType_t type) | ||
{ | ||
if (!type) | ||
return 0; |
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: use nullptr [modernize-use-nullptr]
return 0; | |
return nullptr; |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #534 +/- ##
==========================================
- Coverage 72.71% 72.16% -0.56%
==========================================
Files 9 9
Lines 3618 3647 +29
==========================================
+ Hits 2631 2632 +1
- Misses 987 1015 +28
🚀 New features to boost your workflow:
|
We should add tests. |
Would love to have this. What's needed before we can merge? |
Hi! I have some unittests that I haven't pushed yet, and this PR should be ready to go. Will do in the next few hours once I have access to a laptop |
@@ -509,15 +509,40 @@ namespace Cpp { | |||
/// Checks if the provided parameter is a Plain Old Data Type (POD). | |||
CPPINTEROP_API bool IsPODType(TCppType_t type); | |||
|
|||
/// Checks if type has an integer representation | |||
CPPINTEROP_API bool IsIntegerType(TCppType_t type); |
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.
Probably we should have an enum instead of many interfaces..
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
bool IsSignedIntegerType(TCppType_t type) { | ||
QualType QT = QualType::getFromOpaquePtr(type); | ||
return QT->hasSignedIntegerRepresentation(); | ||
} |
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 *) var;
^
return QT->hasSignedIntegerRepresentation(); | ||
} | ||
|
||
bool IsUnsignedIntegerType(TCppType_t type) { |
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: redundant boolean literal in conditional return statement [readability-simplify-boolean-expr]
lib/Interpreter/CppInterOp.cpp:1565:
- if (llvm::isa_and_nonnull<VarDecl>(D)) {
- return true;
- }
-
- return false;
+ return llvm::isa_and_nonnull<VarDecl>(D);
bool IsFloatingType(TCppType_t type) { | ||
QualType QT = QualType::getFromOpaquePtr(type); | ||
return QT->hasFloatingRepresentation(); | ||
} |
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 *) var;
^
std::vector<Decl*> Decls; | ||
std::string code = R"( | ||
int a; | ||
int *b; |
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: function 'TEST' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
int *b; | |
TESTstatic (TypeReflectionTest, IntegerTypes) { |
std::vector<Decl*> Decls; | ||
std::string code = R"( | ||
class A {}; | ||
using VoidPtrType = void*; |
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: function 'TEST' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
using VoidPtrType = void*; | |
TESTstatic (TypeReflectionTest, VoidPtrType) { |
std::vector<Decl*> Decls; | ||
|
||
std::string code = R"( | ||
#include <cstdarg> |
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: function 'TEST' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
#include <cstdarg> | |
TESTstatic (TypeReflectionTest, IsSameType) { |
|
||
Decls.assign(Decls.end() - 8, Decls.end()); | ||
|
||
EXPECT_TRUE(Cpp::IsSameType(Cpp::GetType("bool"), Ctxt.BoolTy.getAsOpaquePtr())); |
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: included header iostream is not used directly [misc-include-cleaner]
EXPECT_TRUE(Cpp::IsSameType(Cpp::GetType("bool"), Ctxt.BoolTy.getAsOpaquePtr())); |
std::vector<Decl*> Decls; | ||
std::string code = R"( | ||
class A {}; | ||
int a; |
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: function 'TEST' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
int a; | |
TESTstatic (VariableReflectionTest, Is_Get_Reference) { |
IsSameType
used for matching arg types between numba inferred signatures and CppOverloads in cppyy.IsIntegral
andIsFloating
that check if types have the respective representations. Used in the case of Numba where scoring based on reflection is required.will add tests