Skip to content
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

Fix check NOTE: non-API calls to SET_BODY, SET_CLOENV, SET_FORMALS #587

Merged
merged 8 commits into from
Nov 22, 2024

Conversation

t-kalinowski
Copy link
Member

This PR is an unsavory but pragmatic and expedient solution to the current R CMD check NOTE
https://cran.r-project.org/web/checks/check_results_covr.html

Result: NOTE 
  File ‘covr/libs/covr.so’:
    Found non-API calls to R: ‘SET_BODY’, ‘SET_CLOENV’, ‘SET_FORMALS’
  
  Compiled code should not call non-API entry points in R.

This can be a “temporary” solution until the internal layout of a CLOSXP changes, closure modifiers become part of R’s C API, or we decide to undertake a larger refactor of covr to avoid needing this workaround.

@jimhester
Copy link
Member

I wonder if we could explain this use case to Luke Tierney and see if we could get a API function for this. There is Rf_mkClosure which almost does what we need, but always allocates a new closure rather than swapping in place.

Making us dependent on the internal CLOSEXP memory layout seems like moving in the wrong direction from what R core intended with the extra checks.

Though if they are not going to change we may have to do this for now.

If we also captured the environment that the original function was stored in I guess we could just replace the function with the new version in that environment and avoid the in place swapping, but it would take some refactoring of covr to accomplish.

@t-kalinowski
Copy link
Member Author

t-kalinowski commented Nov 12, 2024

seems like moving in the wrong direction from what R core intended

That may be true. However, the usage in covr is unique, and I don’t anticipate an API endpoint to make this straightforward anytime soon. I understand and sympathize with R Core's desire to proceed cautiously and intentionally here. With this approach, the risks and assumptions are clearly defined and managed within covr, with the understanding that we’ll stay responsive to any upstream changes. Perhaps that aligns somewhat with R Core’s goal of distinguishing between what's officially supported and what's not?

If we also captured the environment that the original function was stored in

This would be a relatively involved refactoring, since not all functions are resolved via a binding in an environment. E.g., an S7 property setter is resolved from a list, and an S7 class validator from an attribute.

@jimhester
Copy link
Member

Can we add a note to news about this change, then I can merge it. I appreciate you looking into it and coming up with a solution, even if it is not ideal, we have to work with what CRAN allows us to do.

src/reassign.c Outdated Show resolved Hide resolved
Copy link
Contributor

@mcol mcol left a comment

Choose a reason for hiding this comment

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

Just two typos in the comments.

src/reassign.c Outdated Show resolved Hide resolved
src/reassign.c Outdated Show resolved Hide resolved
@jimhester jimhester merged commit 57f9fc8 into main Nov 22, 2024
12 checks passed
@jimhester
Copy link
Member

Thanks again for working on this!

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.

4 participants