Skip to content

Commit dc12576

Browse files
committed
Unsafe changes to further reduce stack use
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.
1 parent 51357b9 commit dc12576

File tree

1 file changed

+24
-30
lines changed

1 file changed

+24
-30
lines changed

R/utils.R

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,38 +1549,32 @@ hybrid_chain <- function(expr, ..., catch = NULL, finally = NULL,
15491549
}
15501550
)
15511551

1552-
withCallingHandlers(
1553-
{
1554-
captureStackTraces({
1555-
result <- withVisible(force(expr))
1556-
if (promises::is.promising(result$value)) {
1557-
# Purposefully NOT including domain (nor replace), as we're already in
1558-
# the domain at this point
1559-
p <- promise_chain(valueWithVisible(result), ..., catch = catch, finally = finally)
1560-
runFinally <- FALSE
1561-
p
1552+
handlers <- list(error = function(e) { catch_e <<- e; do_catch })
1553+
classes <- names(handlers)
1554+
.Internal(.addCondHands(classes, handlers, parent.frame(), NULL, TRUE))
1555+
1556+
result <- withVisible(force(expr))
1557+
if (promises::is.promising(result$value)) {
1558+
# Purposefully NOT including domain (nor replace), as we're already in
1559+
# the domain at this point
1560+
p <- promise_chain(valueWithVisible(result), ..., catch = catch, finally = finally)
1561+
runFinally <- FALSE
1562+
p
1563+
} else {
1564+
result <- Reduce(
1565+
function(v, func) {
1566+
if (v$visible) {
1567+
withVisible(func(v$value))
15621568
} else {
1563-
result <- Reduce(
1564-
function(v, func) {
1565-
if (v$visible) {
1566-
withVisible(func(v$value))
1567-
} else {
1568-
withVisible(func(invisible(v$value)))
1569-
}
1570-
},
1571-
list(...),
1572-
result
1573-
)
1574-
1575-
valueWithVisible(result)
1569+
withVisible(func(invisible(v$value)))
15761570
}
1577-
})
1578-
},
1579-
error = function(e) {
1580-
catch_e <<- e
1581-
do_catch
1582-
}
1583-
)
1571+
},
1572+
list(...),
1573+
result
1574+
)
1575+
1576+
valueWithVisible(result)
1577+
}
15841578
}
15851579

15861580
if (!is.null(domain)) {

0 commit comments

Comments
 (0)