-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[R-package] Move error handling into C++ side #4163
Conversation
Just wondering about the next step after this PR. Does that mean we need to replace every |
Next, every |
Then I have no question about this PR. But it seems that checks on macOS failed. |
Looks like this was similar to the issue that briefly blocked the most recent release (#4169 (comment)). https://github.com/microsoft/LightGBM/pull/4163/checks?check_run_id=2325957398
I'll merge in the latest If you're ok with the change @shiyu1994 , could you approve the PR? |
/gha run r-valgrind Workflow R valgrind tests has been triggered! 🚀 Status: failure ❌. |
Hey cool example of failing valgrind tests blocking a merge! Nice job @StrikerRUS ! I'll fix this tonight. |
Ok I just pushed a change that, based on running valgrind locally, I think will test this PR without triggering any issues from valgrind. I originally wanted to test that errors are raised correctly by constructing a Dataset where the size of
I think that has something to do with how this vector is filled: LightGBM/R-package/src/lightgbm_R.cpp Lines 220 to 224 in 211ef78
I suspect that that issue might be fixed as part of #3016. Either way, it's not directly related to this PR. I changed the unit test in this PR to use an LightGBM/R-package/src/lightgbm_R.cpp Line 218 in 211ef78
|
/gha run r-valgrind Workflow R valgrind tests has been triggered! 🚀 Status: success ✔️. |
Sorry, realized I still had the label "in progress" on this! This is ready for review. |
@shiyu1994 sorry to bother you, could you look at this PR again and approve it if you agree with the changes? Some of the discussion from #4207 and #4216 are giving new urgency to #3016, and I'd like to handle this PR and #4155 as steps towards that. |
@jameslamb Sorry for the delay. I've checked and already approved. |
No problem, thanks very much for the help! |
This pull request has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this. |
Short description
#4155 fixes a critical issue facing Windows users of the R package, but to implement it the R package needs to switch from using wrapper function
lgb.call()
to directly using the builtin.Call()
. This PR is a first step in that refactoring.Longer description
Today, the interaction between R code in
{lightgbm}
and C++ code inlib_lightgbm
works like this:call_state
.Call()
call_state
is updated to a non-0 value, and an error message is stored in the place thatLGBM_GetLastError()
can find itcall_state
. If it is non-0, R callslgb.last_error()
, which calls C++ functionLGBM_GetLastError()
, then raises an R exception usingstop()
.This back-and-forth is the reason that almost all of
{lightgbm}
's calls to C++ code use an internal wrapper functionlgb.call()
.LightGBM/R-package/R/utils.R
Lines 62 to 91 in d517ba1
It seems that the use of that function (not calling
.Call()
directly with a name that matches a symbol exported from the library) is not allowed if you use R's native routine registration, which is blocking the bugfix in #4155 (see that PR's description for more background).This is a first step towards factoring out
lgb.call()
, as described in #4155 (comment). This PR proposes just raising errors directly from the C++ side. UsingRf_error()
from R, those still become regular R exceptions. So this change does not have any user-facing impact. I've added a unit test to make that expectation explicit.If
call_state
isn't necessary for raising errors, why doesn't this PR just remove it from all the interfaces defined inLightGBM_R.h
?I did spent a while trying this, but unfortunately it can result in this warning every time code
.Call()
is used:This comes from
Rinternals.h
, at https://github.com/wch/r-source/blob/d22ee2fc0dc8142b23eed9f46edf76ea9d3ca69a/src/main/dotcode.c#L538-L541. I think those now-unnecessary uses ofcall_state
can be cleaned up as part of #3016.