-
Notifications
You must be signed in to change notification settings - Fork 28.9k
SPARK-571: forbid return statements in cleaned closures #717
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
Conversation
This commit ensures that ClosureCleaner.clean will identify toplevel return statements in closures and raise an exception if they are encountered. This is intended to fix SPARK-571.
|
Merged build triggered. |
|
Merged build started. |
|
Merged build finished. |
|
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/14858/ |
|
Merged build triggered. |
|
Merged build started. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This function is pretty simple. Mind moving it into run() directly?
|
Merged build finished. |
|
Refer to this link for build results: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/14859/ |
|
Thanks for the quick feedback, @andrewor14! I'll make those changes. I'll also look to see if I can figure out why that repartition test is failing; oddly, it's working for me locally. |
|
@willb the re-partition issue is not related to your patch. There was an inadvertent check-in in master that caused it. It has been fixed. |
|
Thanks for the clarification, @pwendell. @andrewor14, I've grouped my imports and collapsed that function. Thanks again. |
|
Merged build triggered. |
|
Merged build started. |
|
Why do closures with return fail? |
|
Ah never mind my quesiton. "return" exits the outer level function instead of the closure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a space after if (also for the if below)
|
I left couple comments on style. Thanks for leading this. |
|
@rxin, yes! (I was firing up a debugger in case you wanted to know exactly where it was returning to.) |
|
Merged build triggered. |
|
Merged build started. |
|
Merged build finished. All automated tests passed. |
|
All automated tests passed. |
|
@willb can you also add a test case where an inline function is using return statement in its closure to make sure that is allowed? e.g. sc.parallelize(1 to 100).map { i =>
def foo(): Int = { return 1; 2 }
foo()
} |
|
Merged build triggered. |
|
Merged build started. |
|
@rxin, the latest commit adds such a test. I'll note that the code I have only finds toplevel nums.map {x =>
// this return is invalid since it will transfer control outside the closure
val foo = {y: Int => return 2; 1 }
foo(x)
}I thought identifying toplevel |
|
Merged build finished. All automated tests passed. |
|
All automated tests passed. |
|
I think the current approach is fine. I'm going to merge this. |
|
Thanks, @rxin! |
|
BTW I am merging this only into master (not branch-1.0) since it is too late for changes into Spark core for 1.0 unless they are critical bug fixes. |
This patch checks top-level closure arguments to `ClosureCleaner.clean` for `return` statements and raises an exception if it finds any. This is mainly a user-friendliness addition, since programs with return statements in closure arguments will currently fail upon RDD actions with a less-than-intuitive error message. Author: William Benton <[email protected]> Closes apache#717 from willb/spark-571 and squashes the following commits: c41eb7d [William Benton] Another test case for SPARK-571 30c42f4 [William Benton] Stylistic cleanups 559b16b [William Benton] Stylistic cleanups from review de13b79 [William Benton] Style fixes 295b6a5 [William Benton] Forbid return statements in closure arguments. b017c47 [William Benton] Added a test for SPARK-571
This patch checks top-level closure arguments to
ClosureCleaner.cleanforreturnstatements and raises an exception if it finds any. This is mainly a user-friendliness addition, since programs with return statements in closure arguments will currently fail upon RDD actions with a less-than-intuitive error message.