-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29777][SparkR] SparkR::cleanClosure aggressively removes a function required by user function #26429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-29777][SparkR] SparkR::cleanClosure aggressively removes a function required by user function #26429
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -546,8 +546,11 @@ processClosure <- function(node, oldEnv, defVars, checkedFuncs, newEnv) { | |
| ifelse(identical(func, obj), TRUE, FALSE) | ||
| }) | ||
| if (sum(found) > 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed offline. The change would lead to dead loop. We should make sure
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the dead loop case when the same function with the same environments is recursively called in the closure? |
||
| # If function has been examined, ignore. | ||
| break | ||
| # If function has been examined | ||
| if (identical(parent.env(environment(funcList[found][[1]])), func.env)) { | ||
HyukjinKwon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # If the parent environment is identical to current parent | ||
| break | ||
| } | ||
| } | ||
| # Function has not been examined, record it and recursively clean its closure. | ||
| assign(nodeChar, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,15 @@ test_that("cleanClosure on R functions", { | |
| actual <- get("y", envir = env, inherits = FALSE) | ||
| expect_equal(actual, y) | ||
|
|
||
| # Test for combination for nested and sequenctial functions in a closure | ||
| f1 <- function(x) x + 1 | ||
| f2 <- function(x) f1(x) + 2 | ||
| user_func <- function(x) { f1(x); f2(x) } | ||
| c_user_func_env <- environment(cleanClosure(user_func)) | ||
|
||
| expect_equal(length(c_user_func_env), 2) | ||
| inner_c_user_func_env <- environment(c_user_func_env$f2) | ||
| expect_equal(length(inner_c_user_func_env), 1) | ||
|
|
||
| # Test for function (and variable) definitions. | ||
| f <- function(x) { | ||
| g <- function(y) { y * 2 } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.