Skip to content

Commit 19422c7

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 7d77362 commit 19422c7

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
@@ -1523,38 +1523,32 @@ hybrid_chain <- function(expr, ..., catch = NULL, finally = NULL,
15231523
}
15241524
)
15251525

1526-
withCallingHandlers(
1527-
{
1528-
captureStackTraces({
1529-
result <- withVisible(force(expr))
1530-
if (promises::is.promising(result$value)) {
1531-
# Purposefully NOT including domain (nor replace), as we're already in
1532-
# the domain at this point
1533-
p <- promise_chain(valueWithVisible(result), ..., catch = catch, finally = finally)
1534-
runFinally <- FALSE
1535-
p
1526+
handlers <- list(error = function(e) { catch_e <<- e; do_catch })
1527+
classes <- names(handlers)
1528+
.Internal(.addCondHands(classes, handlers, parent.frame(), NULL, TRUE))
1529+
1530+
result <- withVisible(force(expr))
1531+
if (promises::is.promising(result$value)) {
1532+
# Purposefully NOT including domain (nor replace), as we're already in
1533+
# the domain at this point
1534+
p <- promise_chain(valueWithVisible(result), ..., catch = catch, finally = finally)
1535+
runFinally <- FALSE
1536+
p
1537+
} else {
1538+
result <- Reduce(
1539+
function(v, func) {
1540+
if (v$visible) {
1541+
withVisible(func(v$value))
15361542
} else {
1537-
result <- Reduce(
1538-
function(v, func) {
1539-
if (v$visible) {
1540-
withVisible(func(v$value))
1541-
} else {
1542-
withVisible(func(invisible(v$value)))
1543-
}
1544-
},
1545-
list(...),
1546-
result
1547-
)
1548-
1549-
valueWithVisible(result)
1543+
withVisible(func(invisible(v$value)))
15501544
}
1551-
})
1552-
},
1553-
error = function(e) {
1554-
catch_e <<- e
1555-
do_catch
1556-
}
1557-
)
1545+
},
1546+
list(...),
1547+
result
1548+
)
1549+
1550+
valueWithVisible(result)
1551+
}
15581552
}
15591553

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

0 commit comments

Comments
 (0)