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

Compat interfers with dictionary type inference #242

Closed
cstjean opened this issue Jun 30, 2016 · 21 comments
Closed

Compat interfers with dictionary type inference #242

cstjean opened this issue Jun 30, 2016 · 21 comments

Comments

@cstjean
Copy link
Contributor

cstjean commented Jun 30, 2016

On 0.4, the Dict key-type is wrong after using Compat

julia> [Symbol(k) => v for (k,v) in Dict{Any, Any}(:x=>3)]
Dict{Symbol,Any} with 1 entry:
  :x => 3

julia> using Compat

julia> [Symbol(k) => v for (k,v) in Dict{Any, Any}(:x=>3)]
Dict{Any,Any} with 1 entry:
  :x => 3
@cstjean cstjean changed the title Compat messes up dictionary type inference Compat interfers with dictionary type inference Jun 30, 2016
@yuyichao
Copy link
Contributor

Dup of JuliaLang/julia#7258 Not really fixable.

@nalimilan
Copy link
Member

@yuyichao But why would using Compat change this? Sounds like an unexpected (and undocumented) outcome.

@yuyichao
Copy link
Contributor

Any method definition can change this. Type inference was just being nice about guessing Symbol(::Any).

@cstjean
Copy link
Contributor Author

cstjean commented Jun 30, 2016

The problem comes from this line. On Julia 0.4.5, Symbol is already defined, so if we lowered the version number it would solve the issue.

@yuyichao
Copy link
Contributor

No. The whole point of that line is to add method to Symbol.

@nalimilan
Copy link
Member

Maybe we could add methods with more specific signatures? On 0.4, only the default Symbol(::String) constructor is defined: looks like it's possible to avoid messing with it.

@nalimilan
Copy link
Member

More specifically, of the defined methods on 0.5, 0.4 already has the first. We only need to add the others:

Symbol(s::String) at coreimg.jl:52
Symbol(a::Array{UInt8,1}) at coreimg.jl:53
Symbol(s::AbstractString) at strings/basic.jl:77
Symbol(x...) at sysimg.jl:74

@yuyichao
Copy link
Contributor

No. As I said, the whole point is to add methods to Symbol (so that it matches the signature of Symbol on 0.5). For this particular one, you can add a type assertion but the issue of adding method inferring with type inf is not fixable in Compat.

@yuyichao
Copy link
Contributor

And therefore we added Symbol(x...) at sysimg.jl:74

@cstjean
Copy link
Contributor Author

cstjean commented Jun 30, 2016

Replacing the compat definition with

Base.Symbol(a, b, args...) = symbol(a, b, args...)

fixes the inference bug. It's ugly and might have other consequences, so I don't know if it's appropriate...

@yuyichao
Copy link
Contributor

fixes the inference bug

It's not a bug.

might have other consequences

It does

so I don't know if it's appropriate...

We shouldn't do that.

And as I said,

For this particular one, you can add a type assertion

@cstjean
Copy link
Contributor Author

cstjean commented Jun 30, 2016

Alright, alright. Thank you for the explanation.

@nalimilan
Copy link
Member

It's clearly a bug, as in "not intended, nor documented, and annoying". It may or may not be fixable/workaround-able, but that's a separate question. Why do you think we shouldn't do that?

@yuyichao
Copy link
Contributor

The bug is JuliaLang/julia#7258 and yes we should fix it.

@nalimilan
Copy link
Member

We won't fix it in 0.4 though, so the bug is in Compat.

@yuyichao
Copy link
Contributor

As a fact, adding any method makes type inference worse when the input is not inferenced as leaf type. If this counts as a bug in Compat, the only fix is to not add any methods in Compat at all.

@nalimilan
Copy link
Member

What's the problem with the workaround suggested by @cstjean?

@yuyichao
Copy link
Contributor

It's the wrong workaround (try Symbol("aaa".data)). And

For this particular one, you can add a type assertion

@nalimilan
Copy link
Member

Let's add a type assertion then?

@yuyichao
Copy link
Contributor

yuyichao commented Jun 30, 2016

That's what I'm saying. Note that you might get complaint if someone extends symbol, which is basically as undefined as (edit:) slightly less undefined than relying on the type inference result of Symbol(::Any)

@nalimilan
Copy link
Member

Extending symbol to return another type than Symbol sounds like a bad idea anyway. @cstjean Could you experiment with that solution and make a pull request?

cstjean added a commit to cstjean/Compat.jl that referenced this issue Jun 30, 2016
cstjean added a commit to cstjean/Compat.jl that referenced this issue Jun 30, 2016
tkelman pushed a commit that referenced this issue Jul 11, 2016
* Add type assertion to `Symbol` method. Fix #242

* Remove comprehension type inference test
dpsanders pushed a commit to dpsanders/Compat.jl that referenced this issue Feb 1, 2017
* Add type assertion to `Symbol` method. Fix JuliaLang#242

* Remove comprehension type inference test
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

3 participants