Adding entry and exit hooks for functions#9
Merged
programLyrique merged 119 commits intomainfrom Mar 6, 2026
Merged
Conversation
…he package, not the inner ones It might miss some interesting functions, for instance, in package fastmap, creating a fastmap actually returns a list containing closures performing operations on the map, and those closures won't be traced, although they will be directly called by a user of the library.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 57 out of 64 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (4)
rcp/tests/smoketest/basic.R:1
- These assertions are incorrect and will fail: (1)
test_null()returns NULL but is compared to 42; useis.null(test_null())(or change the function to return 42 if that’s intended). (2) After definingtest_call, the compiled check assertstest_addinstead oftest_call. (3)stopifnot(test_call(2) == c(2, 1))evaluates to a logical vector (andstopifnot()expects a single TRUE); useidentical(test_call(2), c(2, 1))orall(...).
rcp/tests/smoketest/basic.R:1 - These assertions are incorrect and will fail: (1)
test_null()returns NULL but is compared to 42; useis.null(test_null())(or change the function to return 42 if that’s intended). (2) After definingtest_call, the compiled check assertstest_addinstead oftest_call. (3)stopifnot(test_call(2) == c(2, 1))evaluates to a logical vector (andstopifnot()expects a single TRUE); useidentical(test_call(2), c(2, 1))orall(...).
rcp/src/stencils/stencils.c:1 - The
realloc()result is assigned directly totrace->typeswithout checking for allocation failure. On failure, this will settrace->typesto NULL and immediately lead to memory corruption/crashes when writingrec. Use a temporary pointer, validate it, and only then updatetrace->types/capacity(and consider how to handle OOM—e.g., disable tracing for that call).
rcp/tests/smoketest/ggplot2-unwinding.R:1 - This smoketest now hard-depends on
ggplot2being installed;library(ggplot2)will error and fail the whole suite in minimal environments. If ggplot2 isn’t guaranteed by the test image, gate the test withif (!requireNamespace('ggplot2', quietly=TRUE)) quit(status=0)(or similar) or ensure the CI/docker images install ggplot2 explicitly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…f dep not installed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It makes it possible to look at the environment (and the return value) of a function at entry and exit.
Eventually, we can reproduce the instrumentation performed with R-dyntrace (but without having to modify the R codebase), or with
inject(but much faster).It now uses the new plugin stencils.
The plugin stencils take a
dataparameter but that must be a pointer that always points to the same address.The type tracer needs to store an unknown number of elements in its trace so the design uses a manually allocated growable array with
mallocto store them, and this is then put into a R external pointer type.Limitations
<unknown>are not traced for types, as we would mix the types of many different functions.Some outputs
There are 2 helpers to get the types at the end:
rcp_get_types_df: returns a data frame with the argument names as columns, plus the number of arguments in dots, and the return value for a given functionrcp_get_types: returns an environment where keys are function names and the value is a list of type results per calls. A type result itself is a named lists with 3 elements,arguments(a named list of the argument types),dots_count, andretOrder of arguments does not matter
Output:
Dot argument is correctly handled
Output:
dots_countis the number of arguments in...for the call. For those arguments, the displayed name is its tag name if it exists, and then its position (with the..iconvention).TODO
injectr