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

Apply type depth limit to :new results #14059

Closed
wants to merge 1 commit into from
Closed

Conversation

carnaval
Copy link
Contributor

Should fix #14009.

@yuyichao
Copy link
Contributor

👍 =)

type A14009{T}
end
A14009{T}(a::T) = A14009{T}()
f14009(a) = ? ? f14009(A14009(a)) : a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any less confusing way of specifying a condition that type inference cannot reason about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I happen to really like this but I think I'm alone on this one. I somewhat remember convincing Jeff that it made question-mark-as-a-global a feature but maybe he was just being nice.

@JeffBezanson
Copy link
Member

I'm not sure this is a good way to fix this, since new itself is not responsible for any growth in the type. This will penalize all code that might allocate deeply-nested types, even without recursion.

We should try to do the limiting during function calls, perhaps in abstract_call, and ideally only if we detect recursion might be happening.

@carnaval
Copy link
Contributor Author

Agreed, but I think the quick fix in the PR is analogous to how we do the tuple depth limit

julia> f() = ((((((1,),),),),),)
julia> Base.return_types(f,())[1]
Tuple{Tuple{Tuple{Tuple{Tuple{Tuple}}}}}

since tuple() and new() play the same role ?

edit: actually making it analogous would be to enforce the limit in apply_type which is what this patch should have been. f(a) = f(A{a}) also keeps inference busy.

@JeffBezanson
Copy link
Member

Yes, if we want a quick fix then I'd much rather do this in apply_type than in new.

@JeffBezanson
Copy link
Member

I will submit a different version of this.

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

Successfully merging this pull request may close these issues.

Avoid infinite type recursion in type inference
3 participants