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

Type inference of constructors with known marginals #10207

Closed
mschauer opened this issue Feb 15, 2015 · 4 comments
Closed

Type inference of constructors with known marginals #10207

mschauer opened this issue Feb 15, 2015 · 4 comments
Labels
compiler:inference Type inference types and dispatch Types, subtyping and method dispatch

Comments

@mschauer
Copy link
Contributor

In the following example, the constructor gets inferred as returning T{A, B}, and not T{Int, B} and the known type of the a-coordinate gets lost .

type T{A, B}
    a::A
    b::B
end
println(code_typed(T, (Int, Any)))
@vtjnash
Copy link
Member

vtjnash commented Feb 16, 2015

can you explain why this is a problem? actual dispatch on the type signature (Int,Any) is impossible since Any is not a concrete leaf type

@mschauer
Copy link
Contributor Author

A hopefully not too contrieved example, where f should be typestable

immutable BaseKVector{K, T}
    x::Vector{T}
end
BaseKVector{T}(v::Vector{T}, K) = BaseKVector{K, T}(v)
BaseKVector{K1,T}(v::BaseKVector{K1,T}, K2) = BaseKVector{K2, T}(v.x)
indexrange{K}(v::BaseKVector{K}) = K : length(v.x) + K

f(x) = indexrange(BaseKVector(x, 1))

println(code_typed(BaseKVector, (BaseKVector, Int)))
println(code_typed(f, (Vector{Int},)))

@ihnorton ihnorton added the types and dispatch Types, subtyping and method dispatch label Mar 4, 2015
@JeffBezanson
Copy link
Member

Similar to #5560, but more expensive since I think it would depend on re-running type inference after inlining. The problem is that, for obvious reasons, we have to generally avoid specializing functions for different values of arguments.

@JeffBezanson JeffBezanson added the compiler:inference Type inference label Jan 16, 2017
@JeffBezanson
Copy link
Member

The example in the OP is fixed now. We should add a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

4 participants