compReturnType | R Documentation |
This function examines an native/IR (LLVM intermediate representation) Function that returns an R
object (SEXP
).
It examines the native code to find the possible R types that
are returned and returns a description for each of these possible types.
These types are currently described as scalars, vectors, lists,
matrices, NULL,
and where possible, the length/dimensions of the vectors/matrices
and also from which parameters these were computed.
Note that while the approach is reasonably general, the current
implementation works with IR code that has been generated
with an optimization level of 1 or higher, not -O0
.
With -O0
, we currently recover some of the information but not
necessarily the class and element names. This can be fixed, but just
requires some additional steps to be added to the existing code.
compReturnType(fun, toc = NULL, blocks = getBlocks(fun))
fun |
the IR Function object whose return type is to be computed |
toc |
a table-of-contents of different modules so that we can find called functions that might be in other modules |
blocks |
the basic blocks for the |
What we are moving towards is being able to find native code that
for example calls ScalarReal and identifying this as a scalar.
This works, at least for some cases.
When we find native code of the form
Rf_allocVector(REALSXP, n)
,
we capture how n is calculated.
If this is Rf_nrows(x), we record that this
is the number of rows of a data.frame/matrix computed from x.
The function also detects lists and determines the types of the
elements and also the names of the elements if they are set.
A list with elements for each of the different return paths. The elements describe the R types. These can be scalars, vectors, matrices, NULL, ....
S4 objects are represented by S4Instance
.
We will change the nature of the R representations of the type descriptions in the future. For now, this is more proof-of-concept.
DTL
getRReturnTypes
which will probably be removed.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.