Skip to content

Re: Adding API functions for detecting interpreter language and standard#839

Merged
Vipul-Cariappa merged 1 commit intocompiler-research:mainfrom
keremsahn:lang-detection-fix
Mar 12, 2026
Merged

Re: Adding API functions for detecting interpreter language and standard#839
Vipul-Cariappa merged 1 commit intocompiler-research:mainfrom
keremsahn:lang-detection-fix

Conversation

@keremsahn
Copy link
Copy Markdown
Contributor

Two API functions; InterpreterLanguage GetLanguage(), InterpreterLanguageStandard GetLanguageStandard() and enums for interpreter language, standard added.

Fixes #744

@Vipul-Cariappa Vipul-Cariappa self-requested a review March 6, 2026 08:21
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

/**
* Enum to represent the programming language of the interpreter.
*/
typedef enum {
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: enum 'CXInterpreterLanguage' uses a larger base type ('unsigned int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]

typedef enum {
        ^

CXInterpreterLanguage_CUDA,
CXInterpreterLanguage_HIP,
CXInterpreterLanguage_HLSL
} CXInterpreterLanguage;
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 'using' instead of 'typedef' [modernize-use-using]

Suggested change
} CXInterpreterLanguage;
using CXInterpreterLanguage = enum {
CXInterpreterLanguage_Unknown,
CXInterpreterLanguage_Asm,
CXInterpreterLanguage_CIR,
CXInterpreterLanguage_LLVM_IR,
CXInterpreterLanguage_C,
CXInterpreterLanguage_CPlusPlus,
CXInterpreterLanguage_ObjC,
CXInterpreterLanguage_ObjCPlusPlus,
CXInterpreterLanguage_OpenCL,
CXInterpreterLanguage_OpenCLCXX,
CXInterpreterLanguage_CUDA,
CXInterpreterLanguage_HIP,
CXInterpreterLanguage_HLSL
};

/**
* Enum to represent the language standard of the interpreter.
*/
typedef enum {
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: enum 'CXInterpreterLanguageStandard' uses a larger base type ('unsigned int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]

typedef enum {
        ^

CXInterpreterLanguageStandard_hlsl202x,
CXInterpreterLanguageStandard_hlsl202y,
CXInterpreterLanguageStandard_lang_unspecified
} CXInterpreterLanguageStandard;
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 'using' instead of 'typedef' [modernize-use-using]

Suggested change
} CXInterpreterLanguageStandard;
using CXInterpreterLanguageStandard = enum {
CXInterpreterLanguageStandard_c89,
CXInterpreterLanguageStandard_c94,
CXInterpreterLanguageStandard_gnu89,
CXInterpreterLanguageStandard_c99,
CXInterpreterLanguageStandard_gnu99,
CXInterpreterLanguageStandard_c11,
CXInterpreterLanguageStandard_gnu11,
CXInterpreterLanguageStandard_c17,
CXInterpreterLanguageStandard_gnu17,
CXInterpreterLanguageStandard_c23,
CXInterpreterLanguageStandard_gnu23,
CXInterpreterLanguageStandard_c2y,
CXInterpreterLanguageStandard_gnu2y,
CXInterpreterLanguageStandard_cxx98,
CXInterpreterLanguageStandard_gnucxx98,
CXInterpreterLanguageStandard_cxx11,
CXInterpreterLanguageStandard_gnucxx11,
CXInterpreterLanguageStandard_cxx14,
CXInterpreterLanguageStandard_gnucxx14,
CXInterpreterLanguageStandard_cxx17,
CXInterpreterLanguageStandard_gnucxx17,
CXInterpreterLanguageStandard_cxx20,
CXInterpreterLanguageStandard_gnucxx20,
CXInterpreterLanguageStandard_cxx23,
CXInterpreterLanguageStandard_gnucxx23,
CXInterpreterLanguageStandard_cxx26,
CXInterpreterLanguageStandard_gnucxx26,
CXInterpreterLanguageStandard_opencl10,
CXInterpreterLanguageStandard_opencl11,
CXInterpreterLanguageStandard_opencl12,
CXInterpreterLanguageStandard_opencl20,
CXInterpreterLanguageStandard_opencl30,
CXInterpreterLanguageStandard_openclcpp10,
CXInterpreterLanguageStandard_openclcpp2021,
CXInterpreterLanguageStandard_hlsl,
CXInterpreterLanguageStandard_hlsl2015,
CXInterpreterLanguageStandard_hlsl2016,
CXInterpreterLanguageStandard_hlsl2017,
CXInterpreterLanguageStandard_hlsl2018,
CXInterpreterLanguageStandard_hlsl2021,
CXInterpreterLanguageStandard_hlsl202x,
CXInterpreterLanguageStandard_hlsl202y,
CXInterpreterLanguageStandard_lang_unspecified
};

@keremsahn keremsahn force-pushed the lang-detection-fix branch from 69221b4 to 4fb2f71 Compare March 6, 2026 18:45
@keremsahn keremsahn marked this pull request as draft March 6, 2026 18:47
@keremsahn keremsahn force-pushed the lang-detection-fix branch from 4fb2f71 to 6853b9c Compare March 6, 2026 18:48
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 6, 2026

Codecov Report

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

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #839      +/-   ##
==========================================
+ Coverage   79.56%   79.75%   +0.18%     
==========================================
  Files          11       11              
  Lines        4013     4035      +22     
==========================================
+ Hits         3193     3218      +25     
+ Misses        820      817       -3     
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOp.h 95.12% <ø> (ø)
include/CppInterOp/Dispatch.h 89.18% <ø> (ø)
lib/CppInterOp/CXCppInterOp.cpp 50.14% <100.00%> (+0.57%) ⬆️
lib/CppInterOp/CppInterOp.cpp 87.96% <100.00%> (+0.09%) ⬆️

... and 1 file with indirect coverage changes

Files with missing lines Coverage Δ
include/CppInterOp/CppInterOp.h 95.12% <ø> (ø)
include/CppInterOp/Dispatch.h 89.18% <ø> (ø)
lib/CppInterOp/CXCppInterOp.cpp 50.14% <100.00%> (+0.57%) ⬆️
lib/CppInterOp/CppInterOp.cpp 87.96% <100.00%> (+0.09%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

@keremsahn keremsahn marked this pull request as ready for review March 6, 2026 21:56
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.

Minor things

Copy link
Copy Markdown
Collaborator

@aaronj0 aaronj0 left a comment

Choose a reason for hiding this comment

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

minor reordering

Copy link
Copy Markdown
Collaborator

@mcbarton mcbarton left a comment

Choose a reason for hiding this comment

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

Can the tests we expanded to cover c23 and c++23? That way we cover all the standards we use for c/c++ kernels in xeus-cpp.

@keremsahn
Copy link
Copy Markdown
Contributor Author

Can the tests we expanded to cover c23 and c++23? That way we cover all the standards we use for c/c++ kernels in xeus-cpp.

Sure, I will add one after this test session is completed

@Vipul-Cariappa
Copy link
Copy Markdown
Collaborator

@aaronj0, why do we have random cppyy tests failing?
The failing tests are not related to these changes.

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

Cpp::InterpreterLanguageStandard::gnucxx17);
}

TYPED_TEST(CPPINTEROP_TEST_MODE, Interpreter_ExternalInterpreter) {
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: no header providing "llvm::ExitOnError" is directly included [misc-include-cleaner]

unittests/CppInterOp/InterpreterTest.cpp:2:

+ #include <llvm/Support/Error.h>

@aaronj0
Copy link
Copy Markdown
Collaborator

aaronj0 commented Mar 11, 2026

@aaronj0, why do we have random cppyy tests failing? The failing tests are not related to these changes.

They have been fixed on main, rerunning should fix the jobs

@aaronj0 aaronj0 force-pushed the lang-detection-fix branch from 6991527 to 802d29a Compare March 11, 2026 07:57
Copy link
Copy Markdown
Collaborator

@aaronj0 aaronj0 left a comment

Choose a reason for hiding this comment

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

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!
Nice work. Thank you.

@Vipul-Cariappa Vipul-Cariappa merged commit a0d70b5 into compiler-research:main Mar 12, 2026
36 checks passed
@Vipul-Cariappa
Copy link
Copy Markdown
Collaborator

Congratulations on your first PR to CppInterOp.

@keremsahn
Copy link
Copy Markdown
Contributor Author

LGTM! Nice work. Thank you.

Thanks for guidance, I have learned a lot

@keremsahn keremsahn deleted the lang-detection-fix branch March 12, 2026 20:34
@mcbarton
Copy link
Copy Markdown
Collaborator

mcbarton commented Mar 24, 2026

@keremsahn I am currently trying to update CppInterOp to llvm 22. I am now down to one failing test (Interpreter_GetLanguageStandardC). As you added this test, I was wondering if you knew why I get this error for llvm 22 https://github.com/compiler-research/CppInterOp/actions/runs/23491010379/job/68359063882?pr=812#step:13:889 .

Here is the llvm 22 compatibility PR #812

@keremsahn
Copy link
Copy Markdown
Contributor Author

@keremsahn I am currently trying to update CppInterOp to llvm 22. I am now down to one failing test (Interpreter_GetLanguageStandardC). As you added this test, I was wondering if you knew why I get this error for llvm 22 https://github.com/compiler-research/CppInterOp/actions/runs/23491010379/job/68359063882?pr=812#step:13:889 .

Here is the llvm 22 compatibility PR #812

I am checking

@keremsahn
Copy link
Copy Markdown
Contributor Author

keremsahn commented Mar 24, 2026

@keremsahn I am currently trying to update CppInterOp to llvm 22. I am now down to one failing test (Interpreter_GetLanguageStandardC). As you added this test, I was wondering if you knew why I get this error for llvm 22 https://github.com/compiler-research/CppInterOp/actions/runs/23491010379/job/68359063882?pr=812#step:13:889 .

Here is the llvm 22 compatibility PR #812

Check the llvm/llvm-project#148701
The problem is in:

    EXTERN_C void *memcpy(void *restrict dst, const void *restrict src, __SIZE_TYPE__ n);
    EXTERN_C inline void __clang_Interpreter_SetValueCopyArr(const void* Src, void* Placement, unsigned long Size) {
      memcpy(Placement, Src, Size);
    }

This is injected into the code and since the tests do not include c89 which restrict and inline keywords are not available the PR was not failed.

@mcbarton
Copy link
Copy Markdown
Collaborator

@keremsahn I am currently trying to update CppInterOp to llvm 22. I am now down to one failing test (Interpreter_GetLanguageStandardC). As you added this test, I was wondering if you knew why I get this error for llvm 22 https://github.com/compiler-research/CppInterOp/actions/runs/23491010379/job/68359063882?pr=812#step:13:889 .
Here is the llvm 22 compatibility PR #812

Check the llvm/llvm-project#148701 The problem is in:

    EXTERN_C void *memcpy(void *restrict dst, const void *restrict src, __SIZE_TYPE__ n);
    EXTERN_C inline void __clang_Interpreter_SetValueCopyArr(const void* Src, void* Placement, unsigned long Size) {
      memcpy(Placement, Src, Size);
    }

This is injected into the code and since the tests do not include c89 which restrict and inline keywords are not available the PR was not failed.

Thanks for the speedy reply. Do you have an idea for a patch which might fix the llvm 22 PR, either to CppInterOp or upstream in llvm?

@keremsahn
Copy link
Copy Markdown
Contributor Author

keremsahn commented Mar 24, 2026

@keremsahn I am currently trying to update CppInterOp to llvm 22. I am now down to one failing test (Interpreter_GetLanguageStandardC). As you added this test, I was wondering if you knew why I get this error for llvm 22 https://github.com/compiler-research/CppInterOp/actions/runs/23491010379/job/68359063882?pr=812#step:13:889 .
Here is the llvm 22 compatibility PR #812

Check the llvm/llvm-project#148701 The problem is in:

    EXTERN_C void *memcpy(void *restrict dst, const void *restrict src, __SIZE_TYPE__ n);
    EXTERN_C inline void __clang_Interpreter_SetValueCopyArr(const void* Src, void* Placement, unsigned long Size) {
      memcpy(Placement, Src, Size);
    }

This is injected into the code and since the tests do not include c89 which restrict and inline keywords are not available the PR was not failed.

Thanks for the speedy reply. Do you have an idea for a patch which might fix the llvm 22 PR, either to CppInterOp or upstream in llvm?

I think it is better to directly fix the original PR instead of a patch. We can use Clang extensions __restrict__ and __inline__ instead of actual keywords. I can create a PR regarding this but since I have midterms right now I may not be able to tackle with possible problems of PR so that it would slow down your llvm 22 integration.

@Vipul-Cariappa
Copy link
Copy Markdown
Collaborator

Not sure if I am replying too late. But we can just drop C89 test in CppInterOp. The inline function specifier was introduced in C99 (ref: https://en.cppreference.com/w/c/language/inline.html & https://en.cppreference.com/w/c/language/restrict.html). So let's just keep tests from C99.

@keremsahn could you please open an issue in LLVM about this incompatible code injection for C89 at interpreter startup. Please ping Vassil and me.

@keremsahn
Copy link
Copy Markdown
Contributor Author

Not sure if I am replying too late. But we can just drop C89 test in CppInterOp. The inline function specifier was introduced in C99 (ref: https://en.cppreference.com/w/c/language/inline.html & https://en.cppreference.com/w/c/language/restrict.html). So let's just keep tests from C99.

@keremsahn could you please open an issue in LLVM about this incompatible code injection for C89 at interpreter startup. Please ping Vassil and me.

Tomorrow I will try the thing I suggested above, if it will not work it is just better to delete the C89 test as you said. And sure I will open the issue tonight or tomorrow.

@keremsahn
Copy link
Copy Markdown
Contributor Author

Not sure if I am replying too late. But we can just drop C89 test in CppInterOp. The inline function specifier was introduced in C99 (ref: https://en.cppreference.com/w/c/language/inline.html & https://en.cppreference.com/w/c/language/restrict.html). So let's just keep tests from C99.

@keremsahn could you please open an issue in LLVM about this incompatible code injection for C89 at interpreter startup. Please ping Vassil and me.

Sorry about the delay, I were not available. llvm/llvm-project#189088 here is the issue. I will tackle with it tomorrow if it still remains unsolved.

@keremsahn
Copy link
Copy Markdown
Contributor Author

@keremsahn I am currently trying to update CppInterOp to llvm 22. I am now down to one failing test (Interpreter_GetLanguageStandardC). As you added this test, I was wondering if you knew why I get this error for llvm 22 https://github.com/compiler-research/CppInterOp/actions/runs/23491010379/job/68359063882?pr=812#step:13:889 .

Here is the llvm 22 compatibility PR #812

The problem is solved but in the main branch, not in the release/22.x. Here is the PR llvm/llvm-project#189432

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.

[Feature Request]: Add an interface to determine if c or c++ code

4 participants