-
-
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-propagation for @pure functions #14324
Comments
Does Julia still have dynamic rounding modes? Is there a plan to deal with them somehow during constant propagation? |
@jwmerrill, other languages (C and Fortran) have dynamic control over the rounding mode, and I think they just do constant propagation in the default rounding mode. That is probably the only sane choice. |
Since we're not checking that
To me, the |
Dup of #5560. Like green-fairy, we should have a |
If the compiler does any automatic constant folding an annotation to tell it not to do so is going to be needed to allow changing rounding modes to have any effect. |
re: rounding modes, LLVM already does constant folding for basic arithmetic ops (e.g. define |
Note also that LLVM offers other properties such as CannotBeOrderedLessThanZero: it would be useful if there was a way we could hook into those as well. |
@StefanKarpinski, I agree that in practice a |
I agree that you probably only want to use the |
It seems as if
|
test() = true & false
@code_warntype test() |
This is a followup to #414 and #13555. Thanks to @vtjnash, we now have an (undocumented)
@pure
annotation that is an (unchecked) assertion that a function is "pure". However, we don't have the constant-propagation/folding compiler passes to actually exploit this.As @JeffBezanson suggested in #414, a pure function
f(x)
in Julia is one for whichx===y ⟹ f(x)===f(y)
. Note that this is technically per-method rather than per-function, because e.g.sin(x)
is pure ifx
is an immutable scalar, but not ifx
is an array or bigfloat.Once constant-propagation is implemented, careful use of the
@pure
tag should allow expressions likelog(2.0)^2
,sin(3+4im)
, andconvert(Float64, 1//2)
to be evaluated at compile-time.The text was updated successfully, but these errors were encountered: