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

stagedfunction called by a function gets staged twice #8886

Closed
mauro3 opened this issue Nov 3, 2014 · 4 comments
Closed

stagedfunction called by a function gets staged twice #8886

mauro3 opened this issue Nov 3, 2014 · 4 comments

Comments

@mauro3
Copy link
Contributor

mauro3 commented Nov 3, 2014

julia> stagedfunction f(x)
           @show "staged f here", x
           :(2*x)
       end
f (generic function with 1 method)

julia> # the staged part gets called once:
       f(5)
("staged f here",x) = ("staged f here",Int64)
10

julia> ff(x)  = f(x)
ff (generic function with 1 method)

julia> # Now the staged part gets called twice:
       ff(6)
("staged f here",x) = ("staged f here",Int64)
("staged f here",x) = ("staged f here",Int64)
12

I would have expected, that the staged part of f to be called only once in total. And for sure not twice in a row in ff(6).

@mauro3 mauro3 changed the title stagedfunction called by a function gets staged twice times stagedfunction called by a function gets staged twice Nov 3, 2014
@JeffBezanson
Copy link
Sponsor Member

Staged functions should definitely not have side effects. The compiler can
call them whenever and however many times it wants.

@mauro3
Copy link
Contributor Author

mauro3 commented Nov 3, 2014

Thanks for the clarification. Maybe something to put into the docs once they get written.

@mauro3 mauro3 closed this as completed Nov 3, 2014
@mlubin
Copy link
Member

mlubin commented Nov 3, 2014

It seems like this is just a performance issue.

@Keno
Copy link
Member

Keno commented Nov 4, 2014

Yes, a known performance issue. Related to type inference and the method cache being two separate caches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants