Skip to content

Commit

Permalink
Unsafe changes to further reduce stack use
Browse files Browse the repository at this point in the history
The internal function `.addCondHands` is used in place of
`withConditionHandlers` to avoid adding a call to the stack. This
generates a warning during `R CMD check`.

The `captureStackTraces` function is removed from `hybrid_chain`.
Instead stack traces are captured and annotated by a `captureStackTraces`
invoked by `runApp` higher up the call stack.
  • Loading branch information
georgestagg committed Nov 22, 2023
1 parent 713aa33 commit b742edf
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1523,38 +1523,32 @@ hybrid_chain <- function(expr, ..., catch = NULL, finally = NULL,
}
)

withCallingHandlers(
{
captureStackTraces({
result <- withVisible(force(expr))
if (promises::is.promising(result$value)) {
# Purposefully NOT including domain (nor replace), as we're already in
# the domain at this point
p <- promise_chain(valueWithVisible(result), ..., catch = catch, finally = finally)
runFinally <- FALSE
p
handlers <- list(error = function(e) { catch_e <<- e; do_catch })
classes <- names(handlers)
.Internal(.addCondHands(classes, handlers, parent.frame(), NULL, TRUE))

result <- withVisible(force(expr))
if (promises::is.promising(result$value)) {
# Purposefully NOT including domain (nor replace), as we're already in
# the domain at this point
p <- promise_chain(valueWithVisible(result), ..., catch = catch, finally = finally)
runFinally <- FALSE
p
} else {
result <- Reduce(
function(v, func) {
if (v$visible) {
withVisible(func(v$value))
} else {
result <- Reduce(
function(v, func) {
if (v$visible) {
withVisible(func(v$value))
} else {
withVisible(func(invisible(v$value)))
}
},
list(...),
result
)

valueWithVisible(result)
withVisible(func(invisible(v$value)))
}
})
},
error = function(e) {
catch_e <<- e
do_catch
}
)
},
list(...),
result
)

valueWithVisible(result)
}
}

if (!is.null(domain)) {
Expand Down

0 comments on commit b742edf

Please sign in to comment.