-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New restrictions on generated functions in 1.12? #57701
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
Comments
This was undefined behavior before, the compiler just didn't have the ability to check. E.g. something like:
would give you type confusion and segfaults. In fact, with the new 1.12 semantics, this is no longer UB (so it actually removes a restriction on generated functions), you just always get the value (or error of |
In addition, 1.12 gives you the ability to actually write a legal version of that function that does what the authors want, although you do have to manually declare your world bounds and edges, which is a bit tricky and there's likely simpler versions to achieve what that package wants, but at least it's possible, which it wasn't before. |
It may still be likely UB, since they are using the generated function to bypass the otherwise detected incorrectness of doing egal structural queries on a merely type-equal operator. I think they want |
Sure, the particular code in the issue may still be UB due to that issue. I was referring specifically to the access to a possibly undefined constant |
Working on a fix for the package here: JuliaObjects/ConstructionBase.jl#99 |
Consider the following generated function:
This should (at least from what I can see) be an ok generated function considering the current restrictions the docs places on them. It only calls functions defined before the function and it only reads global constants. However, it currently gives a warning
So it seems that there is an additional restriction to generated functions now in that it is only allowed to read a global constant defined before the generated function. If that is the case, the documentation should be updated.
A lot of code in e.g. ConstructionBase uses this pattern:
https://github.com/JuliaObjects/ConstructionBase.jl/blob/72bb19dad11695fd94de66c738db534f89b23878/src/ConstructionBase.jl#L29-L31
https://github.com/JuliaObjects/ConstructionBase.jl/blob/72bb19dad11695fd94de66c738db534f89b23878/src/functions.jl#L11
The text was updated successfully, but these errors were encountered: