-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Constant folding/propagation of functions #11159
Comments
const global is actually almost always better than a local, by nature of it being constant yes, this is covered by #3440: "handle more constant conditions in inference" |
The case of a single assigment local where the assignment is to a toplevel const is probably easy to hack into the compiler right now. If you want to do it, look for various kinds of static_eval in inference and codegen. The fact that a local is SA is already noted somewhere in the varinfo flags so it's just a matter of finding the assignment and static_evaling it. It's only a special case though. |
Thanks for the info and I might have a look at it when I want to do sth for fun =).
Does this mean a static checking version of #5148 should be almost trivial to implement? |
test(x) = if first((true, true, false))
x
else
"a"
end
@code_warntype test(1) |
Not sure if there's already an issue for this or if this is covered by #3440 somehow. I brought it up here because this break type inference once I made
invoke
a generic function. This also affect other functions that take a function as a parameter (e.g.map
). I can understand why it is impossible to do type inference on such a function as parameter, but maybe it can be done better when the function is inlined.The constant folding doesn't even happen for user defined local variables (i.e. assign a generic function to a local variable) and for once a constant global is better than a local variable..... (This kind of code probably won't happen in user written code but it can probably be introduced in macros to avoid multiple evaluation of an argument)
Output
The text was updated successfully, but these errors were encountered: