Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aaronj0
Copy link
Collaborator

@aaronj0 aaronj0 commented Mar 20, 2025

  • 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.

will add tests

@aaronj0 aaronj0 requested a review from vgvassilev March 20, 2025 23:26
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

@@ -1573,8 +1609,17 @@ namespace Cpp {
return QT.getNonReferenceType().getAsOpaquePtr();
}

TCppType_t GetUnqualifiedType(TCppType_t type) {
if (!type)
return 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: use nullptr [modernize-use-nullptr]

Suggested change
return 0;
return nullptr;

TCppType_t GetUnderlyingType(TCppType_t type)
{
if (!type)
return 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: use nullptr [modernize-use-nullptr]

Suggested change
return 0;
return nullptr;

Copy link

codecov bot commented Mar 20, 2025

Codecov Report

Attention: Patch coverage is 62.06897% with 11 lines in your changes missing coverage. Please review.

Project coverage is 79.08%. Comparing base (2585d0d) to head (c67507e).

Files with missing lines Patch % Lines
lib/CppInterOp/CppInterOp.cpp 62.06% 11 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #534      +/-   ##
==========================================
- Coverage   79.18%   79.08%   -0.11%     
==========================================
  Files           9        9              
  Lines        3853     3882      +29     
==========================================
+ Hits         3051     3070      +19     
- Misses        802      812      +10     
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOp.h 95.34% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 86.97% <62.06%> (-0.30%) ⬇️
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOp.h 95.34% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 86.97% <62.06%> (-0.30%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vgvassilev
Copy link
Contributor

We should add tests.

@jeaye
Copy link
Contributor

jeaye commented Apr 25, 2025

Would love to have this. What's needed before we can merge?

@aaronj0
Copy link
Collaborator Author

aaronj0 commented Apr 25, 2025

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);
Copy link
Contributor

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..

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

return QT->hasSignedIntegerRepresentation();
}

bool IsUnsignedIntegerType(TCppType_t type) {
Copy link
Contributor

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();
}
Copy link
Contributor

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;
              ^

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

@aaronj0 aaronj0 force-pushed the type-api branch 2 times, most recently from 897cfb3 to 05eb59c Compare May 15, 2025 11:38
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

aaronj0 added 2 commits July 2, 2025 12:22
Adds tests for IsSameType, IsIntegerType, IsFloatingType, GetUnqualifiedType, IsVoidPointerType
@@ -578,6 +579,22 @@ CPPINTEROP_API bool IsRecordType(TCppType_t type);
/// 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,
Signedness s = Signedness::kAny);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Signedness s = Signedness::kAny);
Signedness *s = nullptr);

We should probably take that as an output argument because you can have an integer type that's of different signedness and is still an int type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, what you describe will happen if the caller specifies signed or unsigned. I was of the opinion that if you call this by default (for kAny) it will return true if the qualtype has an integer representation which should cover the above scenario

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but if you don't know the underlying signedness you will get a false telling you that this is not an integral type. This assumes that you will call the function couple of times before you figure everything out. My proposal is to enable this in a single call.

Copy link
Contributor

github-actions bot commented Jul 2, 2025

clang-tidy review says "All clean, LGTM! 👍"

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.

3 participants