Skip to content

Replace string comparison with AST check in IsBuiltin for std::complex#842

Merged
Vipul-Cariappa merged 2 commits intocompiler-research:mainfrom
tryh4rd-26:fix-isbuiltin-string-comparison
Mar 13, 2026
Merged

Replace string comparison with AST check in IsBuiltin for std::complex#842
Vipul-Cariappa merged 2 commits intocompiler-research:mainfrom
tryh4rd-26:fix-isbuiltin-string-comparison

Conversation

@tryh4rd-26
Copy link
Copy Markdown
Contributor

Description

Replace the fragile string-based check for std::complex in IsBuiltin() with a proper Clang AST query.

he old code was checking if a type's name contained the word "complex" as a string, which is pretty hacky cuz any random user class with "complex" in the name would get wrongly treated as a builtin. I swapped it out for a proper AST check that looks at whether the type is actually a std::complex<T>specialization by walking the Clang AST. Same approach that's already used in other parts of the codebase, so it fits right in.

Resolves the FIXME at line 411: // FIXME: Figure out how to avoid the string comparison.

Type of change

  • Bug fix
  • New feature
  • Requires documentation updates

Testing

  • Ran the existing ScopeReflection_IsBuiltin test which covers:
    • Builtin types (bool, char, signed char, void)
    • C _Complex types (_Complex float, _Complex double, _Complex long double, _Complex __float128)
    • std::complex<T> template specializations (via #include <complex> and iterating over specializations)
  • Full test suite: 100% tests passed, 0 tests failed out of 3
$ CppInterOpTests --gtest_filter="*IsBuiltin*"
[ RUN      ] CppInterOpTest/InProcessJIT.ScopeReflection_IsBuiltin
[       OK ] CppInterOpTest/InProcessJIT.ScopeReflection_IsBuiltin (290 ms)
[  PASSED  ] 1 test.

Checklist

  • I have read the contribution guide recently

@tryh4rd-26 tryh4rd-26 force-pushed the fix-isbuiltin-string-comparison branch from 4bfa493 to 0c8daee Compare March 7, 2026 12:20
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.75%. Comparing base (4e3e4c2) to head (af15f8b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #842      +/-   ##
==========================================
+ Coverage   79.72%   79.75%   +0.03%     
==========================================
  Files          11       11              
  Lines        4025     4031       +6     
==========================================
+ Hits         3209     3215       +6     
  Misses        816      816              
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOp.cpp 87.98% <100.00%> (+0.03%) ⬆️
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOp.cpp 87.98% <100.00%> (+0.03%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 7, 2026

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

Copy link
Copy Markdown
Collaborator

@Vipul-Cariappa Vipul-Cariappa left a comment

Choose a reason for hiding this comment

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

Looks good to me!
Could you add a test case that covers the uncovered line for the test coverage.

if (const auto* RD = Ty->getAsCXXRecordDecl()) {
if (const auto* CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
IdentifierInfo* II = CTSD->getSpecializedTemplate()->getIdentifier();
if (II && II->isStr("complex") &&
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There is still some string comparison, but I guess this is a better approach.

@tryh4rd-26
Copy link
Copy Markdown
Contributor Author

tryh4rd-26 commented Mar 9, 2026

Looks good to me! Could you add a test case that covers the uncovered line for the test coverage.

Hi I am Done

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2026

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

@aaronj0
Copy link
Copy Markdown
Collaborator

aaronj0 commented Mar 9, 2026

Hi I am Done

Can you rebase on latest main to fix the CI failures? (and squash into a single commit)

@tryh4rd-26 tryh4rd-26 force-pushed the fix-isbuiltin-string-comparison branch from ba65476 to 434eabc Compare March 9, 2026 19:05
@tryh4rd-26
Copy link
Copy Markdown
Contributor Author

Can you rebase on latest main to fix the CI failures? (and squash into a single commit)

Yup done!

@mcbarton
Copy link
Copy Markdown
Collaborator

mcbarton commented Mar 9, 2026

Hi I am Done

Can you rebase on latest main to fix the CI failures? (and squash into a single commit)

@aaronj0 Rebasing will not fix the Emscripten ci failures. xeus-cpp not expects xeus 6.0 and above, so you need this PR to go in #845 and then rebase to fix the Emscripten ci.

@tryh4rd-26
Copy link
Copy Markdown
Contributor Author

Hi I am Done

Can you rebase on latest main to fix the CI failures? (and squash into a single commit)

@aaronj0 Rebasing will not fix the Emscripten ci failures. xeus-cpp not expects xeus 6.0 and above, so you need this PR to go in #845 and then rebase to fix the Emscripten ci.

Will I do this or will the maintainers?

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2026

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

Copy link
Copy Markdown
Collaborator

@Vipul-Cariappa Vipul-Cariappa left a comment

Choose a reason for hiding this comment

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

LGTM!

I am approving this, but will defer merging for now. As the CI is failing, I believe the CI failures are unrelated to these changes.

@Vipul-Cariappa
Copy link
Copy Markdown
Collaborator

Will I do this or will the maintainers?

We are looking into the failures in the CI. For now, I don't think it is caused by your changes, therefore we will take care of it. Unless we find out there is some change in this PR that is the cause. You will have to fix things. Will inform you 😄.

if (const auto* RD = Ty->getAsCXXRecordDecl()) {
if (const auto* CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
IdentifierInfo* II = CTSD->getSpecializedTemplate()->getIdentifier();
if (II && II->isStr("complex") &&
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.

What about Type::isAnyComplexType?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

isAnyComplexType() is already called on line 409 ... but std::complex<T> is a class temp record type and , not a Clang ComplexType, so the func should be returning false for it. The AST check below is specifically to handle standard complex typpa specialisations.

@tryh4rd-26
Copy link
Copy Markdown
Contributor Author

Will I do this or will the maintainers?

We are looking into the failures in the CI. For now, I don't think it is caused by your changes, therefore we will take care of it. Unless we find out there is some change in this PR that is the cause. You will have to fix things. Will inform you 😄.

Understood thank you!

@tryh4rd-26 tryh4rd-26 force-pushed the fix-isbuiltin-string-comparison branch from 434eabc to 210eee9 Compare March 12, 2026 14:40
@github-actions
Copy link
Copy Markdown
Contributor

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

@tryh4rd-26
Copy link
Copy Markdown
Contributor Author

Hi @Vipul-Cariappa , I rebased it to the latest fix and seems all CI errors have been resolves

@github-actions
Copy link
Copy Markdown
Contributor

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

@Vipul-Cariappa Vipul-Cariappa merged commit 9e51622 into compiler-research:main Mar 13, 2026
36 checks passed
@tryh4rd-26 tryh4rd-26 deleted the fix-isbuiltin-string-comparison branch March 13, 2026 08:34
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.

5 participants