Skip to content
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

detect errors in generated function declarations early #18605

Merged
merged 1 commit into from
Sep 20, 2016

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Sep 20, 2016

this would have detected #18577 before it was merged

this would have detected #18577 before it was merged
@@ -156,7 +156,7 @@ end
@generated function _g_f_with_inner(x)
:(y->y)
end
@test (_g_f_with_inner(1))(8) == 8
@test_throws ErrorException _g_f_with_inner(1)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added by @JeffBezanson in b43c5e0 - presumably this was needed for something?

I hate to backport new restrictions, even if it's just an earlier error on code that may be invalid. Will have to see how many packages are actually doing this. What's allowed in generated functions is starting to become a pretty restrictive subset of the language, and I don't think people have been aware of that or writing them that way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point, we likely may want to reintroduce this, but right now it gets handled incorrectly by the runtime system and will likely require not-backportable changes to fix.

What's allowed in generated functions is starting to become a pretty restrictive subset of the language

It's not "starting to become" because it's really not a new restriction, it's just better at enforcing correctness up-front now. On the other hand, the fix for #265 will add significant new restrictions to them, although it shouldn't affect anyone who's been fully observant of their definition.

and I don't think people have been aware of that or writing them that way.

That's too bad, but the manual does repeat several times that "you should /never/ write a generated function with side effects" [emphasis original] http://docs.julialang.org/en/latest/manual/metaprogramming/#generated-functions (unfortunately interspersed with various buggy examples). I can repeat it a few more times, but I consider it better just to enforce the restrictions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we please fix and elaborate on the docs while we're at it then? Most people likely don't think of using closures or comprehensions as having side effects in this way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixed into the same PR or on its own?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either, as long as it gets done promptly. considering this is newly enforced, it should probably be documented here though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's not reasonable to consider a generated function with a closure to have side effects --- the side effects there are in our implementation, not in the user's code.

For backporting, it doesn't matter how "new restriction" is defined. All that matters is whether code can break.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I wouldn't have made this an error if that code wasn't already broken, so that this was just adding a clearer error than "segfault", corruption of precompiled files, or other errors in which method gets called.

I look forward to having anonymous functions again, so that they are uniquely defined by content rather than by name.

@vtjnash vtjnash merged commit 1f478e1 into master Sep 20, 2016
@vtjnash vtjnash deleted the jn/generated-detect-18577 branch September 20, 2016 22:26
@vtjnash
Copy link
Member Author

vtjnash commented Sep 23, 2016

e61ac9d should be backport along with this (which should also eventually make it onto master instead of waiting for #17057)

@tkelman
Copy link
Contributor

tkelman commented Sep 24, 2016

make it its own pr now?

@tkelman
Copy link
Contributor

tkelman commented Sep 24, 2016

this isn't going into a release until the docs get updated for it as well, so you still need to do that - separately from the #265 fix, please

@tkelman
Copy link
Contributor

tkelman commented Sep 24, 2016

Though if it breaks working user code it's not getting backported at all, so that will need to be tested.

@vtjnash
Copy link
Member Author

vtjnash commented Sep 24, 2016

Just to reiterate, the user code would have worked on v0.4 (because we couldn't infer it), but is broken on v0.5 (because we can). This adds an explicit error message for the broken case, since the failure happens in rather unexpected circumstances and the symptoms are not straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants