Skip to content

Commit 3a3840e

Browse files
Use x[["name"]] instead of x$name through the code; consistency + slightly faster
1 parent d96ded9 commit 3a3840e

34 files changed

+226
-226
lines changed

R/000.bquote.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ bquote_apply <- function(tmpl, envir = parent.frame()) {
9595

9696
for (kk in seq_along(tmpl)) {
9797
entry <- tmpl[[kk]]
98-
value <- eval(entry$expression, envir = envir)
99-
at <- entry$at
98+
value <- eval(entry[["expression"]], envir = envir)
99+
at <- entry[["at"]]
100100

101101
## Special case: Result becomes just a value
102102
nat <- length(at)

R/backend_api-ClusterFuture-class.R

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ getSocketSelectTimeout <- function(future, timeout = NULL) {
121121
## in infinite waiting (PR17203). Fixed in R devel r73470 (2017-10-05)
122122
## and R 3.4.3
123123
## Source: https://github.com/HenrikBengtsson/Wishlist-for-R/issues/35
124-
if (.Platform$OS.type != "windows" && getRversion() < "3.4.3") {
124+
if (.Platform[["OS.type"]] != "windows" && getRversion() < "3.4.3") {
125125
timeout <- round(timeout, digits = 0L)
126126
}
127127
attr(timeout, "validated") <- TRUE
@@ -143,8 +143,8 @@ resolved.ClusterFuture <- function(x, run = TRUE, timeout = NULL, ...) {
143143
future <- x
144144
backend <- future[["backend"]]
145145
stop_if_not(inherits(backend, "FutureBackend"))
146-
workers <- backend$workers
147-
reg <- backend$reg
146+
workers <- backend[["workers"]]
147+
reg <- backend[["reg"]]
148148

149149
## A lazy future not even launched?
150150
if (future[["state"]] == "created") {
@@ -157,7 +157,7 @@ resolved.ClusterFuture <- function(x, run = TRUE, timeout = NULL, ...) {
157157
## Find which nodes are available
158158
avail <- rep(TRUE, times = length(workers))
159159
futures <- FutureRegistry(reg, action = "list", earlySignal = FALSE)
160-
nodes <- unlist(lapply(futures, FUN = function(f) f$node), use.names = FALSE)
160+
nodes <- unlist(lapply(futures, FUN = function(f) f[["node"]]), use.names = FALSE)
161161
avail[nodes] <- FALSE
162162
if (debug) mdebug(" - avail: [n=%d] %s", length(avail), commaq(avail))
163163

@@ -185,7 +185,7 @@ resolved.ClusterFuture <- function(x, run = TRUE, timeout = NULL, ...) {
185185
node <- cl[[1]]
186186

187187
## Check if workers socket connection is available for reading
188-
if (!is.null(con <- node$con)) {
188+
if (!is.null(con <- node[["con"]])) {
189189
## AD HOC/SPECIAL CASE: Skip if connection has been serialized and lacks
190190
## internal representation. /HB 2018-10-27
191191
connId <- connectionId(con)
@@ -200,7 +200,7 @@ resolved.ClusterFuture <- function(x, run = TRUE, timeout = NULL, ...) {
200200
## n infinite waiting (PR17203). Fixed in R devel r73470 (2017-10-05)
201201
## and R 3.4.3
202202
## Source: https://github.com/HenrikBengtsson/Wishlist-for-R/issues/35
203-
if (!isTRUE(attr(timeout, "validated", exact = TRUE)) && .Platform$OS.type != "windows" && getRversion() < "3.4.3") {
203+
if (!isTRUE(attr(timeout, "validated", exact = TRUE)) && .Platform[["OS.type"]] != "windows" && getRversion() < "3.4.3") {
204204
timeout <- round(timeout, digits = 0L)
205205
}
206206
}
@@ -296,8 +296,8 @@ receiveMessageFromWorker <- function(future, ...) {
296296
if (!inherits(backend, "FutureBackend") && !is.list(backend)) {
297297
stop(sprintf("[INTERNAL ERROR] receiveMessageFromWorker(): the 'backend' element of the %s object is neither a FutureBackend object nor a list: %s", class(future)[1], class(backend)[1]))
298298
}
299-
workers <- backend$workers
300-
reg <- backend$reg
299+
workers <- backend[["workers"]]
300+
reg <- backend[["reg"]]
301301

302302
node_idx <- future[["node"]]
303303
if (debug) mdebugf(" - cluster node index: %d", node_idx)
@@ -318,7 +318,7 @@ receiveMessageFromWorker <- function(future, ...) {
318318
if (inherits(ack, "error")) {
319319
if (debug) mdebugf("- parallel:::recvResult() produced an error: %s", conditionMessage(ack))
320320
msg <- post_mortem_cluster_failure(ack, when = "receive message results from", node = node, future = future)
321-
ex <- FutureError(msg, call = ack$call, future = future)
321+
ex <- FutureError(msg, call = ack[["call"]], future = future)
322322
future[["result"]] <- ex
323323
stop(ex)
324324
}
@@ -367,7 +367,7 @@ receiveMessageFromWorker <- function(future, ...) {
367367
## they will be resignaled each time value() is called.
368368
signaled <- future[[".signaledConditions"]]
369369
if (length(signaled) > 0) {
370-
result$conditions <- c(future[[".signaledConditions"]], result$conditions)
370+
result[["conditions"]] <- c(future[[".signaledConditions"]], result[["conditions"]])
371371
future[[".signaledConditions"]] <- NULL
372372
}
373373

@@ -430,9 +430,9 @@ receiveMessageFromWorker <- function(future, ...) {
430430
}
431431

432432
## Increment signal count
433-
signaled <- condition$signaled
433+
signaled <- condition[["signaled"]]
434434
if (is.null(signaled)) signaled <- 0L
435-
condition$signaled <- signaled + 1L
435+
condition[["signaled"]] <- signaled + 1L
436436

437437
## Record condition as signaled
438438
signaled <- future[[".signaledConditions"]]
@@ -562,13 +562,13 @@ post_mortem_cluster_failure <- function(ex, when, node, future) {
562562
## (2) Information on the cluster node
563563

564564
## (a) Process information on the worker, if available
565-
pid <- node$session_info$process$pid
565+
pid <- node[["session_info"]][["process"]][["pid"]]
566566
pid_info <- if (is.numeric(pid)) sprintf("PID %.0f", pid) else NULL
567567

568568
## (b) Host information on the worker, if available
569569
## AD HOC: This assumes that the worker has a hostname, which is not
570570
## the case for MPI workers. /HB 2017-03-07
571-
host <- node$host
571+
host <- node[["host"]]
572572
localhost <- isTRUE(attr(host, "localhost", exact = TRUE))
573573
host_info <- if (!is.null(host)) {
574574
sprintf("on %s%s", if (localhost) "localhost " else "", sQuote(host))
@@ -589,7 +589,7 @@ post_mortem_cluster_failure <- function(ex, when, node, future) {
589589

590590
## (a) Inspect the 'reason' for known clues
591591
if (grepl("ignoring SIGPIPE signal", reason)) {
592-
postmortem$sigpipe <- "The SIGPIPE error suggests that the R socket connection to the parallel worker broke, which can happen for different reasons, e.g. the parallel worker crashed"
592+
postmortem[["sigpipe"]] <- "The SIGPIPE error suggests that the R socket connection to the parallel worker broke, which can happen for different reasons, e.g. the parallel worker crashed"
593593
}
594594

595595
## (a) Did the worker process terminate?
@@ -615,20 +615,20 @@ post_mortem_cluster_failure <- function(ex, when, node, future) {
615615
msg2 <- "No process exists with this PID on the remote host, i.e. the remote worker is no longer alive"
616616
}
617617
}
618-
postmortem$alive <- msg2
618+
postmortem[["alive"]] <- msg2
619619
}
620620

621621
## (b) Did the worker use a connection that changed?
622-
if (inherits(node$con, "connection")) {
623-
postmortem$connection <- check_connection_details(node, future = future)
622+
if (inherits(node[["con"]], "connection")) {
623+
postmortem[["connection"]] <- check_connection_details(node, future = future)
624624
}
625625

626626
## (c) Any non-exportable globals?
627627
globals <- future[["globals"]]
628-
postmortem$non_exportable <- assert_no_references(globals, action = "string")
628+
postmortem[["non_exportable"]] <- assert_no_references(globals, action = "string")
629629

630630
## (d) Size of globals
631-
postmortem$global_sizes <- summarize_size_of_globals(globals)
631+
postmortem[["global_sizes"]] <- summarize_size_of_globals(globals)
632632

633633
## (5) The final error message
634634
msg <- sprintf("%s (%s) failed to %s %s. The reason reported was %s",
@@ -701,11 +701,11 @@ assertValidConnection <- function(future) {
701701
node_idx <- future[["node"]]
702702
if (debug) mdebugf(" - cluster node index: %d", node_idx)
703703

704-
cl <- backend$workers[node_idx]
704+
cl <- backend[["workers"]][node_idx]
705705
node <- cl[[1]]
706706

707707
## Nothing to do?
708-
if (is.null(con <- node$con)) return()
708+
if (is.null(con <- node[["con"]])) return()
709709

710710
## AD HOC/SPECIAL CASE: Skip if connection has been serialized and lacks internal representation. /HB 2018-10-27
711711
connId <- connectionId(con)

R/backend_api-Future-class.R

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ Future <- function(expr = NULL, envir = parent.frame(), substitute = TRUE, stdou
132132
## Global objects?
133133
## 'persistent' is only allowed for ClusterFuture:s, which will be
134134
## asserted when run() is called /HB 2023-01-17
135-
gp <- getGlobalsAndPackages(expr, envir = envir, tweak = tweakExpression, globals = globals, persistent = isTRUE(args$persistent))
136-
globals <- gp$globals
137-
expr <- gp$expr
135+
gp <- getGlobalsAndPackages(expr, envir = envir, tweak = tweakExpression, globals = globals, persistent = isTRUE(args[["persistent"]]))
136+
globals <- gp[["globals"]]
137+
expr <- gp[["expr"]]
138138

139139
## Record packages?
140-
if (length(packages) > 0 || (length(gp$packages) > 0 && lazy)) {
141-
packages <- c(gp$packages, packages)
140+
if (length(packages) > 0 || (length(gp[["packages"]]) > 0 && lazy)) {
141+
packages <- c(gp[["packages"]], packages)
142142
}
143143

144144
gp <- NULL
@@ -202,7 +202,7 @@ Future <- function(expr = NULL, envir = parent.frame(), substitute = TRUE, stdou
202202
core <- new.env(parent = emptyenv())
203203

204204
## Version of future
205-
version <- args$version
205+
version <- args[["version"]]
206206
if (is.null(version)) version <- "1.8"
207207
core[["version"]] <- version
208208

@@ -331,16 +331,16 @@ print.Future <- function(x, ...) {
331331

332332
if (hasResult) {
333333
if (inherits(result, "FutureResult")) {
334-
value <- result$value
334+
value <- result[["value"]]
335335
} else if ("value" %in% names(future)) {
336336
.Defunct(msg = sprintf("Detected a %s object that rely on the defunct 'value' field of format version 1.7 or before.", class(future)[1]), package = .packageName)
337337
} else {
338338
stop(FutureError(sprintf("The %s object does not have a 'results' field", class(future)[1]), future = future))
339339
}
340340
cat(sprintf("Value: %s of class %s\n", asIEC(objectSize(value)), sQuote(class(value)[1])))
341341
if (inherits(result, "FutureResult")) {
342-
conditions <- result$conditions
343-
conditionClasses <- vapply(conditions, FUN = function(c) class(c$condition)[1], FUN.VALUE = NA_character_)
342+
conditions <- result[["conditions"]]
343+
conditionClasses <- vapply(conditions, FUN = function(c) class(c[["condition"]])[1], FUN.VALUE = NA_character_)
344344
cat(sprintf("Conditions captured: [n=%d] %s\n", length(conditionClasses), hpaste(sQuote(conditionClasses))))
345345
}
346346
} else {
@@ -358,8 +358,8 @@ assertOwner <- local({
358358
hpid <- function(uuid) {
359359
info <- attr(uuid, "source", exact = TRUE)
360360
if (is.null(info)) info <- list(pid = NA_integer_, host = NA_character_)
361-
stop_if_not(is.list(info), length(info$pid) == 1L, length(info$host) == 1L)
362-
pid <- sprintf("%s; pid %d on %s", uuid, info$pid, info$host)
361+
stop_if_not(is.list(info), length(info[["pid"]]) == 1L, length(info[["host"]]) == 1L)
362+
pid <- sprintf("%s; pid %d on %s", uuid, info[["pid"]], info[["host"]])
363363
stop_if_not(length(pid) == 1L)
364364
pid
365365
}
@@ -466,7 +466,7 @@ run.Future <- function(future, ...) {
466466

467467
## SPECIAL: 'cluster' takes argument 'persistent' for now /HB 2023-01-17
468468
has_persistent <- ("persistent" %in% names(future))
469-
if (has_persistent) args$persistent <- future[["persistent"]]
469+
if (has_persistent) args[["persistent"]] <- future[["persistent"]]
470470

471471
tmpFuture <- do.call(evaluator, args = args)
472472

@@ -812,7 +812,7 @@ getFutureContext <- function(future, mc.cores = NULL, local = TRUE, ..., debug =
812812
)
813813

814814
if (!is.null(mc.cores)) {
815-
forwardOptions$mc.cores <- mc.cores
815+
forwardOptions[["mc.cores"]] <- mc.cores
816816
}
817817

818818
reset <- future[["reset"]]
@@ -930,7 +930,7 @@ getFutureBackendConfigs.ClusterFuture <- function(future, ..., debug = isTRUE(ge
930930
stop_if_not(inherits(cl, "cluster"))
931931
node <- cl[[1L]]
932932
stop_if_not(inherits(node, c("SOCK0node", "SOCKnode")))
933-
con <- node$con
933+
con <- node[["con"]]
934934
if (is.null(con)) return(list())
935935

936936
capture <- list(
@@ -957,7 +957,7 @@ getFutureData <- function(future, ..., debug = isTRUE(getOption("future.debug"))
957957
data <- list(
958958
core = getFutureCore(future, debug = debug),
959959
capture = getFutureCapture(future, debug = debug),
960-
context = getFutureContext(future, mc.cores = args$mc.cores, local = args$local, debug = debug)
960+
context = getFutureContext(future, mc.cores = args[["mc.cores"]], local = args[["local"]], debug = debug)
961961
)
962962

963963
## Tweak per backend?

R/backend_api-FutureBackend-class.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ makeFutureBackend <- function(evaluator, ...) {
5959
args <- attr(evaluator, "tweaks")
6060
if (is.null(args)) args <- list()
6161
args2 <- formals(evaluator)
62-
args2$`...` <- NULL
63-
args2$envir <- NULL
62+
args2[["..."]] <- NULL
63+
args2[["envir"]] <- NULL
6464
args2$lazy <- NULL ## bc multisession; should be removed
6565
for (name in names(args2)) {
6666
args[[name]] <- args2[[name]]

R/backend_api-FutureRegistry.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ FutureRegistry <- local({
9494
## Early signaling of conditions?
9595
if (earlySignal && length(futures) > 0L) {
9696
## Which futures have early signaling enabled?
97-
idxs <- lapply(futures, FUN = function(f) f$earlySignal)
97+
idxs <- lapply(futures, FUN = function(f) f[["earlySignal"]])
9898
idxs <- which(unlist(idxs, use.names = FALSE))
9999

100100
## Any futures to be scanned for early signaling?

R/backend_api-MulticoreFuture-class.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ result.MulticoreFuture <- function(future, ...) {
114114
if (!inherits(result, "FutureResult")) {
115115
if (debug) mdebugf("Detected non-FutureResult result ...")
116116
alive <- NA
117-
pid <- job$pid
117+
pid <- job[["pid"]]
118118
if (is.numeric(pid)) {
119119
pid_exists <- import_parallelly("pid_exists")
120120
alive <- pid_exists(pid)
121121
}
122122

123123
## AD HOC: Record whether the forked process is alive or not
124-
job$alive <- alive
124+
job[["alive"]] <- alive
125125
future[["job"]] <- job
126126

127127
## SPECIAL: Check for fallback 'fatal error in wrapper code'
@@ -152,14 +152,14 @@ result.MulticoreFuture <- function(future, ...) {
152152
} else {
153153
msg2 <- "No process exists with this PID, i.e. the forked localhost worker is no longer alive"
154154
}
155-
postmortem$alive <- msg2
155+
postmortem[["alive"]] <- msg2
156156
}
157157

158158
## (c) Any non-exportable globals?
159-
postmortem$non_exportable <- assert_no_references(future, action = "string")
159+
postmortem[["non_exportable"]] <- assert_no_references(future, action = "string")
160160

161161
## (d) Size of globals
162-
postmortem$global_sizes <- summarize_size_of_globals(future[["globals"]])
162+
postmortem[["global_sizes"]] <- summarize_size_of_globals(future[["globals"]])
163163

164164
postmortem <- unlist(postmortem, use.names = FALSE)
165165
if (!is.null(postmortem)) {
@@ -199,7 +199,7 @@ result.MulticoreFuture <- function(future, ...) {
199199
future[[".signaledConditions"]] <- signaled
200200

201201
## Record conditions
202-
result$conditions <- c(result$conditions, signaled)
202+
result[["conditions"]] <- c(result[["conditions"]], signaled)
203203
signaled <- NULL
204204

205205
future[["result"]] <- result

R/backend_api-SequentialFutureBackend-class.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ launchFuture.SequentialFutureBackend <- function(backend, future, ...) {
2929

3030
## Apply backend tweaks
3131
split <- backend[["split"]]
32-
if (!is.null(split)) data$capture$split <- split
32+
if (!is.null(split)) data[["capture"]][["split"]] <- split
3333
earlySignal <- backend[["earlySignal"]]
3434
if (!is.null(earlySignal)) future[["earlySignal"]] <- earlySignal
3535

0 commit comments

Comments
 (0)