Skip to content

Commit b060a08

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 b3c8697 commit b060a08

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
@@ -1527,38 +1527,32 @@ hybrid_chain <- function(expr, ..., catch = NULL, finally = NULL,
15271527
}
15281528
)
15291529

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

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

0 commit comments

Comments
 (0)