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

Constant propogation through slurping #26050

Closed
bramtayl opened this issue Feb 14, 2018 · 5 comments
Closed

Constant propogation through slurping #26050

bramtayl opened this issue Feb 14, 2018 · 5 comments
Labels
compiler:inference Type inference

Comments

@bramtayl
Copy link
Contributor

bramtayl commented Feb 14, 2018

Recurring through tuples with first and Base.tail is incredibly useful but tail doesn't do constant propagation. I tracked the issue down to argtail in Base, which needs a pure annotation to do constant propagation correctly.

Base.@pure argtail(x, rest...) = rest

In fact, constant propagation never seems to survive slurping without pure annotations. This seems like a useful feature to have.

@JeffBezanson JeffBezanson added the compiler:inference Type inference label Feb 16, 2018
@JeffBezanson
Copy link
Member

It would be useful to post a complete test case here.

@bramtayl
Copy link
Contributor Author

bramtayl commented Feb 16, 2018

Base.@pure argtail(x, rest...) = rest
tail(x) = argtail(x...)

getindex_unrolled(into::Tuple{}, switch::Tuple{}) = ()
getindex_unrolled(into, switch::Tuple{}) = ()
getindex_unrolled(into::Tuple{}, switch) = ()

function getindex_unrolled(into, switch)
    next = getindex_unrolled(tail(into), tail(switch))
    if first(switch)
        (first(into), next...)
    else
        next
    end
end

test() = getindex_unrolled((1, "b", 3.0), (true, false, true))
Test.@inferred test()

This only works if argtail is marked as pure.

@bramtayl
Copy link
Contributor Author

bramtayl commented May 5, 2018

Solved by #26826?

@vtjnash
Copy link
Member

vtjnash commented May 5, 2018

No, that PR doesn't include detection that all(isa(Const), result.vargs) implies args[nargs] = Const(tuple((x.var for x in result.vargs)...))

@vtjnash
Copy link
Member

vtjnash commented Sep 19, 2018

Closed by #29264.

@vtjnash vtjnash closed this as completed Sep 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

No branches or pull requests

3 participants