Skip to content

Commit 46d6581

Browse files
Internal sQuoteLabel() now outputs <unnamed-N> for futures without label set + it accepts a Future object
1 parent ba83cfb commit 46d6581

9 files changed

+41
-26
lines changed

R/backend_api-11.ClusterFutureBackend-class.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ resolved.ClusterFuture <- function(x, run = TRUE, timeout = NULL, ...) {
600600
## also the one that evaluates/resolves/queries it.
601601
assertOwner(future)
602602

603-
if (debug) mdebugf_push("resolved() for %s (%s) ...", class(future)[1], sQuoteLabel(future[["label"]]))
603+
if (debug) mdebugf_push("resolved() for %s (%s) ...", class(future)[1], sQuoteLabel(future))
604604

605605
node_idx <- future[["node"]]
606606
cl <- workers[node_idx]
@@ -947,7 +947,7 @@ receiveMessageFromWorker <- local({
947947
if (inherits(condition, "error")) {
948948
future[["result"]] <- msg
949949
future[["state"]] <- "failed"
950-
label <- sQuoteLabel(future[["label"]])
950+
label <- sQuoteLabel(future)
951951
stop(FutureError(sprintf("Received a %s condition from the %s worker for future (%s), which is not possible to relay because that would break the internal state of the future-worker communication. The condition message was: %s", class(condition)[1], class(future)[1], label, sQuote(conditionMessage(condition))), future = future))
952952
}
953953

@@ -1165,7 +1165,7 @@ requestNode <- function(await, backend, timeout, delta, alpha) {
11651165
for (kk in seq_along(futures)) {
11661166
future <- futures[[kk]]
11671167
if (node_idx == future[["node"]]) {
1168-
stop(FutureError(sprintf("[INTERNAL ERROR]: requestNode() found node #%d to be free, but it is used by future #%d (%s)", node_idx, kk, sQuoteLabel(future[["label"]]))))
1168+
stop(FutureError(sprintf("[INTERNAL ERROR]: requestNode() found node #%d to be free, but it is used by future #%d (%s)", node_idx, kk, sQuoteLabel(future))))
11691169
}
11701170
}
11711171

@@ -1260,7 +1260,7 @@ post_mortem_cluster_failure <- local({
12601260
stop_if_not(length(node_info) == 1L)
12611261

12621262
## (3) Information on the future
1263-
label <- sQuoteLabel(future[["label"]])
1263+
label <- sQuoteLabel(future)
12641264

12651265
## (4) POST-MORTEM ANALYSIS:
12661266
postmortem <- list()
@@ -1450,7 +1450,7 @@ handleInterruptedFuture <- local({
14501450
state <- future[["state"]]
14511451
stop_if_not(state %in% c("canceled", "interrupted", "running"))
14521452

1453-
label <- sQuoteLabel(future[["label"]])
1453+
label <- sQuoteLabel(future)
14541454
workers <- backend[["workers"]]
14551455
node_idx <- future[["node"]]
14561456
cl <- workers[node_idx]

R/backend_api-11.MulticoreFutureBackend-class.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ result.MulticoreFuture <- local({
413413
## turn into an error with a more informative error message, cf.
414414
## https://github.com/futureverse/future/issues/35
415415
if (is.null(result) || identical(result, structure("fatal error in wrapper code", class = "try-error"))) {
416-
label <- sQuoteLabel(future[["label"]])
416+
label <- sQuoteLabel(future)
417417

418418
if (future[["state"]] %in% c("canceled", "interrupted")) {
419419
if (debug) mdebugf("Detected interrupted %s whose result cannot be retrieved", sQuote(class(future)[1]))

R/backend_api-Future-class.R

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,21 @@ Future <- function(expr = NULL, envir = parent.frame(), substitute = TRUE, stdou
246246

247247

248248
sQuoteLabel <- function(label) {
249+
if (inherits(label, "Future")) {
250+
future <- label
251+
label <- future[["label"]]
252+
if (is.null(label)) {
253+
uuid <- future[["uuid"]]
254+
idx <- uuid[length(uuid)]
255+
label <- sprintf("<unnamed-%s>", idx)
256+
} else if (is.na(label)) {
257+
label <- "NA"
258+
} else {
259+
label <- sQuote(label)
260+
}
261+
return(label)
262+
}
263+
249264
if (is.null(label)) {
250265
"NULL"
251266
} else if (is.na(label)) {
@@ -261,7 +276,7 @@ print.Future <- function(x, ...) {
261276
future <- x
262277
class <- class(future)
263278
cat(sprintf("%s:\n", class[1]))
264-
label <- sQuoteLabel(future[["label"]])
279+
label <- sQuoteLabel(future)
265280
cat("Label: ", label, "\n", sep = "")
266281
cat("Expression:\n")
267282
print(future[["expr"]])
@@ -404,13 +419,13 @@ assertOwner <- local({
404419
run.Future <- function(future, ...) {
405420
debug <- isTRUE(getOption("future.debug"))
406421
if (debug) {
407-
mdebugf_push("run() for %s (%s) ...", sQuote(class(future)[1]), sQuoteLabel(future[["label"]]))
422+
mdebugf_push("run() for %s (%s) ...", sQuote(class(future)[1]), sQuoteLabel(future))
408423
mdebug("state: ", sQuote(future[["state"]]))
409424
on.exit(mdebugf_pop())
410425
}
411426

412427
if (future[["state"]] != "created") {
413-
label <- sQuoteLabel(future[["label"]])
428+
label <- sQuoteLabel(future)
414429
msg <- sprintf("A future (%s) can only be launched once", label)
415430
stop(FutureError(msg, future = future))
416431
}
@@ -459,7 +474,7 @@ run.Future <- function(future, ...) {
459474
}, error = function(ex) {
460475
## Unexpected error
461476
msg <- conditionMessage(ex)
462-
label <- sQuoteLabel(future[["label"]])
477+
label <- sQuoteLabel(future)
463478
msg <- sprintf("Caught an unexpected error of class %s when trying to launch future (%s) on backend of class %s. The reason was: %s", class(ex)[1], label, class(backend)[1], msg)
464479
stop(FutureLaunchError(msg, future = future))
465480
})
@@ -599,7 +614,7 @@ result <- function(future, ...) {
599614
## Signal FutureJournalCondition?
600615
if (!isTRUE(future[[".journal_signalled"]])) {
601616
journal <- journal(future)
602-
label <- sQuoteLabel(future[["label"]])
617+
label <- sQuoteLabel(future)
603618
msg <- sprintf("A future (%s) of class %s was resolved", label, class(future)[1])
604619
cond <- FutureJournalCondition(message = msg, journal = journal)
605620
signalCondition(cond)
@@ -628,7 +643,7 @@ result <- function(future, ...) {
628643
result.Future <- function(future, ...) {
629644
debug <- isTRUE(getOption("future.debug"))
630645
if (debug) {
631-
mdebugf_push("result() for %s (%s) ...", sQuote(class(future)[1]), sQuoteLabel(future[["label"]]))
646+
mdebugf_push("result() for %s (%s) ...", sQuote(class(future)[1]), sQuoteLabel(future))
632647
mdebug("state: ", sQuote(future[["state"]]))
633648
on.exit(mdebugf_pop())
634649
}
@@ -686,7 +701,7 @@ result.Future <- function(future, ...) {
686701
## Sanity check
687702
if (is.null(result) && version == "1.8") {
688703
if (inherits(future, "MulticoreFuture")) {
689-
label <- sQuoteLabel(future[["label"]])
704+
label <- sQuoteLabel(future)
690705
msg <- sprintf("A future (%s) of class %s did not produce a FutureResult object but NULL. This suggests that the R worker terminated (crashed?) before the future expression was resolved.", label, class(future)[1])
691706
stop(FutureError(msg, future = future))
692707
}
@@ -701,7 +716,7 @@ resolved.Future <- function(x, run = TRUE, ...) {
701716
future <- x
702717
debug <- isTRUE(getOption("future.debug"))
703718
if (debug) {
704-
mdebugf_push("resolved() for %s (%s) ...", class(future)[1], sQuoteLabel(future[["label"]]))
719+
mdebugf_push("resolved() for %s (%s) ...", class(future)[1], sQuoteLabel(future))
705720
on.exit(mdebug_pop())
706721
mdebug("state: ", sQuote(future[["state"]]))
707722
mdebug("run: ", run)

R/backend_api-UniprocessFuture-class.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ run.UniprocessFuture <- function(future, ...) {
2424
debug <- isTRUE(getOption("future.debug"))
2525

2626
if (future[["state"]] != 'created') {
27-
label <- sQuoteLabel(future[["label"]])
27+
label <- sQuoteLabel(future)
2828
stop(FutureError(sprintf("A future (%s) can only be launched once", label), future = future))
2929
}
3030

R/core_api-value.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ value <- function(...) UseMethod("value")
5454

5555
drop_future <- function(future) {
5656
class <- class(future)[1]
57-
label <- sQuoteLabel(future[["label"]])
57+
label <- sQuoteLabel(future)
5858
msg <- sprintf("Future (%s) of class %s is no longer valid, because its content has been minimized using value(..., drop = TRUE)", label, class)
5959
error <- FutureDroppedError(msg, future = future)
6060

@@ -76,7 +76,7 @@ drop_future <- function(future) {
7676
value.Future <- function(future, stdout = TRUE, signal = TRUE, drop = FALSE, ...) {
7777
debug <- isTRUE(getOption("future.debug"))
7878
if (debug) {
79-
mdebugf_push("value() for %s (%s) ...", class(future)[1], sQuoteLabel(future[["label"]]))
79+
mdebugf_push("value() for %s (%s) ...", class(future)[1], sQuoteLabel(future))
8080
on.exit(mdebugf_pop())
8181
}
8282

R/protected_api-FutureCondition-class.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ FutureError <- function(message, call = NULL, uuid = future[["uuid"]], future =
127127
#' @export
128128
RngFutureCondition <- function(message = NULL, call = NULL, uuid = future[["uuid"]], future = NULL) {
129129
if (is.null(message)) {
130-
label <- sQuoteLabel(future[["label"]])
130+
label <- sQuoteLabel(future)
131131
message <- sprintf("UNRELIABLE VALUE: Future (%s) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to \"ignore\".", label)
132132
}
133133
cond <- FutureCondition(message = message, call = call, uuid = uuid, future = future)
@@ -160,7 +160,7 @@ RngFutureError <- function(...) {
160160
#' @rdname FutureCondition
161161
#' @export
162162
UnexpectedFutureResultError <- function(future, hint = NULL) {
163-
label <- sQuoteLabel(future[["label"]])
163+
label <- sQuoteLabel(future)
164164
expr <- hexpr(future[["expr"]])
165165
result <- future[["result"]]
166166
result_string <- hpaste(as.character(result))
@@ -192,7 +192,7 @@ UnexpectedFutureResultError <- function(future, hint = NULL) {
192192
#' @export
193193
GlobalEnvMisuseFutureCondition <- function(message = NULL, call = NULL, differences = NULL, uuid = future[["uuid"]], future = NULL) {
194194
if (is.null(message)) {
195-
label <- sQuoteLabel(future[["label"]])
195+
label <- sQuoteLabel(future)
196196
message <- sprintf("%s (%s) added variables to the global environment. A future expression should never assign variables to the global environment - neither by assign() nor by <<-: [n=%d] %s", class(future)[1], label, length(differences[["added"]]), commaq(differences[["added"]]))
197197
message <- sprintf("%s. See also help(\"future.options\", package = \"future\")", message)
198198
}
@@ -226,7 +226,7 @@ GlobalEnvMisuseFutureError <- function(...) {
226226
#' @export
227227
ConnectionMisuseFutureCondition <- function(message = NULL, call = NULL, differences = NULL, uuid = future[["uuid"]], future = NULL) {
228228
if (is.null(message)) {
229-
label <- sQuoteLabel(future[["label"]])
229+
label <- sQuoteLabel(future)
230230
message <- sprintf("%s (%s) added, removed, or modified connections. A future expression must close any opened connections and must not close connections it did not open", class(future)[1], label)
231231
if (!is.null(differences)) {
232232
details <- lapply(differences, FUN = function(diffs) {
@@ -278,7 +278,7 @@ ConnectionMisuseFutureError <- function(...) {
278278
#' @export
279279
DeviceMisuseFutureCondition <- function(message = NULL, call = NULL, differences = NULL, uuid = future[["uuid"]], future = NULL) {
280280
if (is.null(message)) {
281-
label <- sQuoteLabel(future[["label"]])
281+
label <- sQuoteLabel(future)
282282
message <- sprintf("%s (%s) added, removed, or modified devices. A future expression must close any opened devices and must not close devices it did not open", class(future)[1], label)
283283
if (!is.null(differences)) {
284284
details <- character(0L)
@@ -323,7 +323,7 @@ DeviceMisuseFutureError <- function(...) {
323323
#' @export
324324
DefaultDeviceMisuseFutureCondition <- function(message = NULL, incidents = NULL, call = NULL, uuid = future[["uuid"]], future = NULL) {
325325
if (is.null(message)) {
326-
label <- sQuoteLabel(future[["label"]])
326+
label <- sQuoteLabel(future)
327327
message <- sprintf("%s (%s) opened the default graphics device", class(future)[1], label)
328328
if (length(incidents) > 0L) {
329329
calls <- lapply(incidents, FUN = lapply, deparse)

R/protected_api-FutureResult-class.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ assertFutureResult <- function(future, debug = FALSE) {
145145
if (debug) mdebug("identical; success")
146146
return(NULL)
147147
}
148-
label <- sQuoteLabel(future[["label"]])
148+
label <- sQuoteLabel(future)
149149
result_uuid <- paste(uuid, collapse = "-")
150150
future_uuid <- paste(future[["uuid"]], collapse = "-")
151151
msg <- sprintf("Result for future (%s) is from another future. UUIDs do not match: %s != %s", label, result_uuid, future_uuid)

R/protected_api-signalConditions.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ signalConditions <- function(future, include = "condition", exclude = NULL, resi
9595
stop(condition)
9696
} else if (inherits(condition, "interrupt")) {
9797
future[["state"]] <- "interrupted"
98-
label <- sQuoteLabel(future[["label"]])
98+
label <- sQuoteLabel(future)
9999
result <- future[["result"]]
100100
when <- result[["finished"]]
101101
session_uuid <- result[["session_uuid"]]

R/utils-connections.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ check_connection_details <- function(worker, future) {
1212
isValid <- isConnectionValid(con)
1313
if (isValid) return(NULL)
1414

15-
label <- sQuoteLabel(future[["label"]])
15+
label <- sQuoteLabel(future)
1616

1717
reason <- attr(isValid, "reason", exact = TRUE)
1818
reason <- gsub("[.]?[[:space:]]*$", "", reason)

0 commit comments

Comments
 (0)