-
Notifications
You must be signed in to change notification settings - Fork 31
Add error propagation to interpreter creation logic #553
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
Conversation
Hence, we had a couple approaches to go ahead here i) Introduce a isValid for ii) What Vipul and I liked was propagating the error all the way to that top, so that a half broken interpreter can't be put to use and a utility function like parse/declare would only work if CreateInterpreter doesn't return null along with an error message saying Interpreter creation failed. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #553 +/- ##
==========================================
+ Coverage 75.93% 76.16% +0.23%
==========================================
Files 9 9
Lines 3644 3655 +11
==========================================
+ Hits 2767 2784 +17
+ Misses 877 871 -6
🚀 New features to boost your workflow:
|
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
There were too many comments to post at once. Showing the first 10 out of 11. Check the log or trigger a new build to see more.
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.
Can we figure out how to write tests?
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
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
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
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
1bb5c43
to
764d551
Compare
Okay I think the codecov says that 3 patches are not being tested. All of them are directly based out of the changes in I tried adding tests but was quick to realize that I am not really doing just justice as I might not be the best one to goto for adding tests for the C API (hence I reverted them and squashed the commits 😅) cc @Gnimuc Would be great if you could help me out with the tests here. The PR description (#553 (comment)) should be good to get you started on the changed made in the C-API (the changes are not too concerning, simple ones !) So we need to test
Thanks in advance ;) |
I'll give it a look this weekend. |
Thanks a lot for the help. This change ends up being critical now that we'll soon be moving to llvm 20 ! |
The C API CppInterOp/lib/Interpreter/CppInterOp.cpp Lines 2924 to 2958 in 98a57b4
It's a bit tricky to set up a successful test environment because we need to know the path of system headers for each test platform. (Although most of the arguments are excluded in the C API, |
Given BTW, I think the changes in the PR look good. |
Thanks for the reply @Gnimuc
Also thanks for going through the changes ! Much appreciated :) Hey @vgvassilev , do you think it's okay if we move ahead with this ? As said above there's some discussion that needs to be done on testing the C API. And although some simple dummy tests can possibly be added as I wrote above, those won't probably be meaningful enough. So yeah the changes introduce 4 lines of untested code in the C API but we can probably get to it in the future. The main reason for this Pr is to help @mcbarton 's PR moving to llvm 20 (as his Pr should benefit with these changes after a rebase) |
Can we make the new header optional? |
I think this should be possible isn't it ! The include new header would be required for tests like these CppInterOp/unittests/CppInterOp/FunctionReflectionTest.cpp Lines 1361 to 1375 in 98a57b4
Now on line CppInterOp/unittests/CppInterOp/Utils.cpp Lines 21 to 23 in 98a57b4
So technically if we can improve But yeah that would mean changing the function definition of the utility function |
Ahh the 3 failing checks are due to this compiler-research/xeus-cpp#286 Making the same change here too ! I think we should be good after that ! |
I think this change should be made as a separate PR, and this PR rebased on it, given this pinning change has nothing to do with the goal of this PR. I will approve and merge this pinning PR, as soon as I see its been put in.
If making this header option would allow this PR to be tested, then should probably be done first, and then this PR should be rebased this on it. Otherwise we risk tests never been made to cover these lines. I know its just a few lines, but its because due to not insisting all lines be covered by tests, we have ended up in a situation where CppInterOps coverage has dropped by approximately 13% in the last 12 months (I made an issue about this here #541). |
Hi,
I've taken care of this here #559
Hmmm, I get it but shouldn't higher priority be moving to LLVM 20 now (it was out on FEB 2 and its high time we move) . The purpose of this PR was to help with that. Also I am not a huge fan of nobody officially taking responsibility for covering the C API. It shouldn't have been added in the first place if that was the case ! Most of my focus since the past 2-3 weeks is around getting a good build (native/emscripten) for cppinterop around llvm 20 and technically this PR is also tested well on our C++ API. But for the C-API But this shouldn't slow any development on C++ API side is what I'm trying to convey. I'm just going by Gnimuc 's word who added the C-API (he says "BTW, I think the changes in the PR look good." #553 (comment)) so I am just hoping we would be in a good enough state to test it in the near future. But if something as simple as a "create interpreter" function is not tested in the C API do we really stop other work due to that ? I don't know. I just think handling error propagation while creating the interpreter is much more important that all of the above (but those might just be my views) |
@anutosh491 Maybe it's a good idea to add this failure test for now. It will improve the coverage a bit. |
I'm wondering what's the original purpose of adding this header. Is it related to the hard-coded code in |
We did not have a trampoline in the past. I think maybe now we can drop it for llvm20? |
Hey @Gnimuc, we just dropped the header through #561 Does this put you in a better position to add some basic tests for Would be great if yes, cause then we can have some initial set of tests like very simple ones. Move that in and then rebase this PR on top of those changes if that makes sense ! |
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
@@ -167,6 +167,22 @@ TEST(InterpreterTest, CreateInterpreter) { | |||
#endif | |||
} | |||
|
|||
#ifndef CPPINTEROP_USE_CLING |
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.
Is there a reason why we are not doing this test for Cling?
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.
No clue,
I see no C-API tests done through cling and that's what I am trying to replicate. Maybe @Gnimuc can educate us here.
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.
The original purpose of adding the C API is to support multiple instances. REPL and Cling are two backends for creating compiler instances. REPL is based on clang::Interpreter
from the upstream llvm-project.
I think there is no plan to upstream Cling to the llvm-project, and I didn't check Cling's compatibility when I added those C-API tests.
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.
You can build, CppInterOp by providing cling and it will embed cling in it. If that’s not too much of work maybe we can support that, shouldn’t hurt.
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.
Can we have a dedicated PR for that ?
I'll say the purpose of this PR is complete now.
If that’s not too much of work maybe we can support that, shouldn’t hurt.
@Gnimuc would you like to give this an attempt ?
Hey @Gnimuc @vgvassilev I have added some simple tests and ensured codecov doesn't complain about changes atleast with regard to this PR. All tests pass no clue why the windows CI fail (don't look like a direct outcome of my tests) Shall try looking into it for a bit (or shall skip If I am helpless cause I don't have a windows machine :\ ) |
Tests which write something on screen fails on Windows. Here, in this comment @mcbarton explained this: |
To refine this comment from before. I think anything which makes the interpreter write an error message in Windows, will be picked up as an error in the overall running of the tests. Tests which seem to write a warning message are ok. I believe it is ok for you skip this test on Windows for this reason. |
Alternatively, we can suppress the error message and retain this test on windows too. It should pass now.
|
Not entirely sure testing::internal::CaptureStderr() will work to resolve this issue. Its probably better to skip for now on Windows. We do however want to make use of GTEST_SKIP(), instead of the way its done currently in the PR. |
Yeah I think we can just skip it for now. |
I think this is ready from my side now that all the checks pass. |
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.
Please also address the missing includes suggested by clang-tidy before merging.
Addressed all reviews. I think this should be ready now. Thanks everyone for the reviews. Squashing and Merging! |
- update source to test compiler-research/CppInterOp#553 - remove wasm link flags in the cmake patch
- update source to test compiler-research/CppInterOp#553 - remove wasm link flags in the cmake patch
Description
@Vipul-Cariappa and I were discussing a use case yesterday (especially while building with repl) and this is what we realized
The function responsible for creating
clang::Interpreter
iscreateClangInterpreter
which can return a nullptr, for egCppInterOp/lib/Interpreter/Compatibility.h
Line 277 in c3384fb
This is assigned to
inner
while the constructor forcompat::Interpreter
is calledCppInterOp/lib/Interpreter/CppInterOpInterpreter.h
Line 153 in c3384fb
which means
inner
can benullptr
CreateInterpreter
from the top, we're creating thecompat::Interpreter
hereCppInterOp/lib/Interpreter/CppInterOp.cpp
Line 2960 in c3384fb
Which means
compat::Interpreter
can exist even when the underlyingclang::Interpreter
is not existing. So we can say that the Interpreter from the top is half brokenWe would hit the following finally
CppInterOp/lib/Interpreter/CppInterOpInterpreter.h
Lines 174 to 176 in c3384fb
And although the call is made to
compat::Interpreter
, we end up using the underlyingclang::Interpreter
without checking if it is valid.Type of change
Please tick all options which are relevant.
Testing
Please describe the test(s) that you added and ran to verify your changes.
Checklist