-
Notifications
You must be signed in to change notification settings - Fork 39
Added undo command for CppInterOp #513
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
|
Hi, @kr-2003 and I were interested in supporting %undo through xeus-cpp/xeus-cpp-lite but we realize it is not being exposed through cppinterop. Hence I asked him to add the same here. |
|
Weird that we found it being exposed through the libclang inspired C API but not through the standard one. CppInterOp/lib/Interpreter/CXCppInterOp.cpp Lines 307 to 313 in 7caf10b
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #513 +/- ##
==========================================
+ Coverage 75.33% 75.46% +0.13%
==========================================
Files 9 9
Lines 3620 3628 +8
==========================================
+ Hits 2727 2738 +11
+ Misses 893 890 -3
... and 1 file with indirect coverage changes
🚀 New features to boost your workflow:
|
|
clang-tidy review says "All clean, LGTM! 👍" |
Vipul-Cariappa
left a comment
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.
@anutosh491 asked me to look at this.
LGTM! If you can just update the test with the changes I specified.
|
@vgvassilev I have included both cling and clang-REPL for undo feature. All tests are passing successfully. Is there any other work pending? |
|
I was actually hopeful we could have this before/in 1.6.0 (which was released on the same day we started discussing undo in xeus-cpp and lite 😅 . We actually made good progress here as xeus-cpp would just naturally have it and I was able to get undo to quite some extent for lite too) Can we have it through a patch release (1.6.1) or something ? |
We do not foresee a patch version for now. It will wait for the next shipping vehicle. |
No issues. Let's move it in if we consider it ready though ? Also hopefully till the next release, I shall have enough context on how to get this working through lite. I was able to implement it (and if you go through the video carefully you will see the flaw in the video) Screen.Recording.2025-02-28.at.12.02.54.PM.mp4Have been discussing why this goes wrong with Sam Clegg who says symbols from subsequent dlopen() operations don't override existing global symbols from previous dlopen() calls. So yeah an error in emscripten is what we think this is ! |
| enum CXErrorCode clang_Interpreter_undo(CXInterpreter I, unsigned int N) { | ||
| #ifdef CPPINTEROP_USE_CLING | ||
| return CXError_Failure; | ||
| auto* interp = getInterpreter(I); |
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.
If using clang_repl you can return CXError_Failure if it fails. With cling and the c api currently as it stands you cannot. Can you fix this @kr-2003
@kr-2003 can you update the tests so your tests cover the 2 missing lines from the patch? |
| #ifdef CPPINTEROP_USE_CLING | ||
| auto& I = getInterp(); | ||
| cling::Interpreter::PushTransactionRAII RAII(&I); | ||
| I.unload(N); |
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.
@vgvassilev How do I even check if unload function logs any errors, since its a void function? Should I use try-catch block(but it is disabled in the project) or use system level redirection of the output to stream using pipes(this might be an overkill for capturing)? unload function logs cling::errs(), if it fails to run.
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.
@vgvassilev Could you please guide me on how to proceed 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.
You should assume that the operation was successful.
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.
Hmmm, I think that's what is being done here https://github.com/compiler-research/CppInterOp/pull/513/files#diff-fb574ca9d2633ca33be71dfa5c0d9f437cfa98768f0e828d5eb789bfcfcef688R3624 so nothing to address here correct ?
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.
I think this looks okay to me.
Maybe the two lines that are not being covered (see comment below) can be addressed.
This demands for a negation case (testing a case where undo fails)
Probably can be done through trying undo(1000) when only few operations have taken place. Let's try something relevant out and then move this in ?
|
@mcbarton Test coverage review has been addressed. Can we take this in now? |
| Cpp::Process("int x = 5;"); | ||
| cerrs = testing::internal::GetCapturedStderr(); | ||
| EXPECT_STREQ(cerrs.c_str(), ""); | ||
| Cpp::Undo(); |
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.
I believe unloading this first transaction here is problematic for destructors, and is unsupported by Cling, which can be seen in the error thrown in the logs. We should drop this call to Cpp::Undo()
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.
@kr-2003 can you address this review comment?
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.
i added two more instructions before calling the first Cpp::Undo().
|
@kr-2003 can you rebase? Now that we have automated wasm tests we need to check that the new test passes for an Emscripten build. |
|
@anutosh491 Given you want this PR in can you help @kr-2003 fix the test which fails for the Emscripten case? |
|
Perfect. So undo isn't expected to work with clang-repl-lite untill emscripten supports dlclose correctly. Abhinav only run these tests when emscripten is not defined So or if you place this construct inside your test, you can do |
|
@mcbarton |
@kr-2003 I suspect (but won't know for sure until you skip the section of the test causing this message) that you are getting the error from here https://github.com/compiler-research/CppInterOp/actions/runs/13938614873/job/39011414822?pr=513#step:8:408 . Basically almost every test which causes the interpreter to write anything to the screen in Windows is currently skipped. Its a known issue, which we are hoping will get fixed soon. Whether this PR is acceptable with this test skipped on Windows will not be upto me though. You would need the approval of @vgvassilev or maybe @aaronj0 . |
So, should I skip these tests for windows? @vgvassilev @aaronj0 |
|
For now I have skipped these tests for windows. |
vgvassilev
left a comment
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.
Lgtm!
|
Make sure the ci passes and you squash on merge. |
Absolutely |
|
@kr-2003 Congratulations on getting your first PR merged 🚀. |
Thank you 😊 |
Description
Added
Undocommand for Clang-REPL. Reverts the last N operations performed by the interpreter.Type of change
Testing
unittests/CppInterOp/FunctionReflectionTest.cpp.Checklist