Skip to content

constant-propagation for @pure functions #14324

@stevengj

Description

@stevengj

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 which x===y ⟹ f(x)===f(y). Note that this is technically per-method rather than per-function, because e.g. sin(x) is pure if x is an immutable scalar, but not if x is an array or bigfloat.

Once constant-propagation is implemented, careful use of the @pure tag should allow expressions like log(2.0)^2, sin(3+4im), and convert(Float64, 1//2) to be evaluated at compile-time.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions