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

Inference (?) hang on recursive methods #17278

Closed
timholy opened this issue Jul 5, 2016 · 6 comments · Fixed by #21933
Closed

Inference (?) hang on recursive methods #17278

timholy opened this issue Jul 5, 2016 · 6 comments · Fixed by #21933
Labels
compiler:inference Type inference

Comments

@timholy
Copy link
Member

timholy commented Jul 5, 2016

Here's what I suspect is a second example of the problem noted in #17137, but which can be easily replicated on master:

julia> I = (CartesianIndex{1}(2), 3, CartesianIndex{1}(3))
(CartesianIndex{1}((2,)),3,CartesianIndex{1}((3,)))

julia> _flatten(out) = out
_flatten (generic function with 1 method)

julia> _flatten(out, i, I...)        = _flatten((out..., i), I...)
_flatten (generic function with 2 methods)

julia> _flatten(out, i::CartesianIndex, I...) = _flatten((out..., i.I...), I...)
_flatten (generic function with 3 methods)

julia> _flatten((), I...)
^C^C^C^C^C^C^CWARNING: Force throwing a SIGINT
WARNING: An error occured during inference. Type inference is now partially disabled.
InterruptException()
unknown function (ip: 0x7f7341157bdf)
^C^C^C^C

All those Ctrl-Cs come from the fact that this call hangs, at least for minutes.

Interestingly, change i to i::Int in the second _flatten method, and it works fine.

Discovered in the course of trying to fix #17275.

@timholy
Copy link
Member Author

timholy commented Jul 5, 2016

Sadly, git bisect fingers ba2e389, which isn't relevant anymore (it's now 15). I'd also love to imagine that we don't rely on such limits for this case.

@vtjnash
Copy link
Member

vtjnash commented Jul 5, 2016

15 is still a very high number for the permitted branching factor, and is strongly dependent on one of our other unreliable heuristics actually kicking in fast enough.

@timholy
Copy link
Member Author

timholy commented Jul 5, 2016

But in this case there's only one branch that's relevant: if the 2nd argument isn't a CartesianIndex, there's only one relevant method.

@timholy
Copy link
Member Author

timholy commented Jul 5, 2016

I don't really understand the inference machinery well, but perhaps it's also worth pointing out that there are also only 3 indexes---naively, it doesn't seem that the tuple length limit is relevant.

@timholy
Copy link
Member Author

timholy commented Jul 5, 2016

As an experiment, I checked out julia-0.4 (before your inference rewrite), bumped MAX_TUPLETYPE_LEN up to 15, and tested this example. It also hangs. So it's not a recent problem, suggesting it may indeed be more fundamental than I was guessing.

@timholy
Copy link
Member Author

timholy commented Jul 5, 2016

Interestingly, this implementation:

_flatten() = ()
_flatten(i, I...)                 = (i, _flatten(I...)...)
_flatten(i::CartesianIndex, I...) = (i.I..., _flatten(I...)...)

has no problem on master. Cross-ref #17126.

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

Successfully merging a pull request may close this issue.

2 participants