Skip to content

Add type info interfaces motivated by numba#534

Closed
aaronj0 wants to merge 2 commits into
compiler-research:mainfrom
aaronj0:type-api
Closed

Add type info interfaces motivated by numba#534
aaronj0 wants to merge 2 commits into
compiler-research:mainfrom
aaronj0:type-api

Conversation

@aaronj0
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread lib/Interpreter/CppInterOp.cpp Outdated

TCppType_t GetUnqualifiedType(TCppType_t type) {
if (!type)
return 0;
Copy link
Copy Markdown
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;

Comment thread lib/Interpreter/CppInterOp.cpp Outdated
TCppType_t GetUnderlyingType(TCppType_t type)
{
if (!type)
return 0;
Copy link
Copy Markdown
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;

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 20, 2025

Codecov Report

❌ 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 (be38e08).
⚠️ Report is 167 commits behind head on main.

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
Copy Markdown
Contributor

We should add tests.

@jeaye
Copy link
Copy Markdown
Contributor

jeaye commented Apr 25, 2025

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

@aaronj0
Copy link
Copy Markdown
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

Comment thread include/clang/Interpreter/CppInterOp.h Outdated
CPPINTEROP_API bool IsPODType(TCppType_t type);

/// Checks if type has an integer representation
CPPINTEROP_API bool IsIntegerType(TCppType_t type);
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread lib/Interpreter/CppInterOp.cpp Outdated
Comment thread lib/Interpreter/CppInterOp.cpp Outdated
return QT->hasSignedIntegerRepresentation();
}

bool IsUnsignedIntegerType(TCppType_t type) {
Copy link
Copy Markdown
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);

Comment thread lib/Interpreter/CppInterOp.cpp Outdated
bool IsFloatingType(TCppType_t type) {
QualType QT = QualType::getFromOpaquePtr(type);
return QT->hasFloatingRepresentation();
}
Copy link
Copy Markdown
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;
              ^

Comment thread unittests/CppInterOp/TypeReflectionTest.cpp
Comment thread unittests/CppInterOp/TypeReflectionTest.cpp
Comment thread unittests/CppInterOp/TypeReflectionTest.cpp
Comment thread unittests/CppInterOp/TypeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/TypeReflectionTest.cpp Outdated
Copy link
Copy Markdown
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

Comment thread unittests/CppInterOp/TypeReflectionTest.cpp
Comment thread unittests/CppInterOp/TypeReflectionTest.cpp
Comment thread unittests/CppInterOp/TypeReflectionTest.cpp
Comment thread unittests/CppInterOp/TypeReflectionTest.cpp Outdated
Comment thread unittests/CppInterOp/TypeReflectionTest.cpp Outdated
@aaronj0 aaronj0 force-pushed the type-api branch 2 times, most recently from 897cfb3 to 05eb59c Compare May 15, 2025 11:38
Copy link
Copy Markdown
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

Comment thread include/clang/Interpreter/CppInterOp.h Outdated

/// Checks if type has an integer representation
CPPINTEROP_API bool IsIntegerType(TCppType_t type,
Signedness s = Signedness::kAny);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done, I've opened a fresh PR instead since this was hard to rebase: #913

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 2, 2025

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

Adds tests for IsSameType, IsIntegerType, IsFloatingType, GetUnqualifiedType, IsVoidPointerType
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 5, 2025

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

@aaronj0
Copy link
Copy Markdown
Collaborator Author

aaronj0 commented Apr 22, 2026

Closing in favour of #913

@aaronj0 aaronj0 closed this Apr 22, 2026
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