Skip to content
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

Iterating a tuple taints :terminates_locally #57097

Open
LilithHafner opened this issue Jan 19, 2025 · 1 comment
Open

Iterating a tuple taints :terminates_locally #57097

LilithHafner opened this issue Jan 19, 2025 · 1 comment
Labels
compiler:effects effect analysis feature Indicates new feature / enhancement requests

Comments

@LilithHafner
Copy link
Member

A for loop over a tuple of known length does not infer as "terminates" unless it is annotated with @assume_effects :terminates_locally. This seems like a reasonable thing for effect analysis to figure out.

julia> function f(x...)
           a = 0
           for i in x
               a += i
           end
           a
       end
f (generic function with 1 method)

julia> Base.infer_effects(f, NTuple{2, Int})
(+c,+e,!n,!t,+s,+m,+u,+o,+r)

julia> Base.@assume_effects :terminates_locally function g(x...)
           a = 0
           for i in x
               a += i
           end
           a
       end
g (generic function with 1 method)

julia> Base.infer_effects(g, NTuple{2, Int})
(+c,+e,!n,+t,+s,+m,+u,+o,+r)

julia> @b f(1,2,3)
1.984 ns

julia> @b g(1,2,3)
1.134 ns

Iterating a Vector is also typically guaranteed to terminate locally. However it will be harder to determine when it is not (e.g. push! in the loop), and it may take many more iterations than with a tuple.

@Keno
Copy link
Member

Keno commented Jan 19, 2025

We don't really have any SCEV capabilities at all on the julia side. As soon as a loop is involved, we taint termination conservatively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:effects effect analysis feature Indicates new feature / enhancement requests
Projects
None yet
Development

No branches or pull requests

2 participants