-
-
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
Do some constant propagation before type inference runs #5560
Comments
The only problem I see is that you probably want:
|
+1 |
There is really no limit to this --- the more you iterate inference, inlining, and constant prop, the more cases you will optimize. You can construct examples that require arbitrary numbers of these passes. |
An alternative to inlining to consider is context-sensitive inter-procedural analysis. That enables a compiler to do "what if I inlined?" analyses without necessarily paying the full cost of inlining. Of course context-sensitive analysis also has the "when to stop?" issue. I'm wondering if there's a way to automatically generate the interpreter for the intrinsics from some kind of table. |
Just ran into this trying to pass a const computation to a generated function by means of a @generated function foobar{D}(::Type{Val{D}})
return :($D)
end
function working1()
const size = 12
return foobar(Val{size})
end
const size = 3*4
function working2()
return foobar(Val{size})
end
function broken()
const size = 3*4
return foobar(Val{size})
end
println(@code_typed working1())
@inferred working1()
println(@code_typed working2())
@inferred working2()
println(@code_typed broken())
@inferred broken() This broke some Julia/CUDA code where we can't perform the call to |
Might be worth pointing out that syntax like #22056 (esp. the first comment) might be a way for the programmer to specify exactly which kind of constant propagation should be performed. Presumably this makes it a finite problem. |
I'm pretty sure it doesn't. But with the new inference convergence, #21933 should do it. |
It would be good to run some constant propagation before type inference runs for cases in which a type parameter is really constant, but we don't know because we compute with it before. E.g:
For
id
, we get a nicewhereas for
inv
, we getThe text was updated successfully, but these errors were encountered: