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 && and || chains #5090

Closed
StefanKarpinski opened this issue Dec 10, 2013 · 1 comment
Closed

type inference of && and || chains #5090

StefanKarpinski opened this issue Dec 10, 2013 · 1 comment
Assignees
Labels
performance Must go faster types and dispatch Types, subtyping and method dispatch

Comments

@StefanKarpinski
Copy link
Member

Although I fixed #5084 by using a trinary operator (which is better style anyway, imo), type inference on the short-circuit && and || operators could be tighter:

julia> f(b::Bool) = b && error("nope") || 1
f (generic function with 1 method)

julia> code_typed(f,(Bool,))
1-element Array{Any,1}:
 :($(Expr(:lambda, {:b}, {{:#s2},{{:b,Bool,0},{:#s2,Bool,2}},{}}, quote  # none, line 1:
        unless b::Bool goto 0
        #s2 = throw($(Expr(:new, :(top(getfield)($(Base),:ErrorException)::Type{ErrorException}), "nope"))::ErrorException)::None
        goto 1
        0:
        #s2 = false
        1:
        unless #s2::Bool goto 2
        return #s2::Bool
        2:
        return 1
    end)))

julia> f(true)
ERROR: nope
 in f at none:1

julia> f(false)
1

This can only ever return an Int and we could definitely infer that.

@ghost ghost assigned JeffBezanson Dec 15, 2013
@ihnorton ihnorton added the types and dispatch Types, subtyping and method dispatch label Mar 25, 2015
@JeffBezanson
Copy link
Member

should be helped by #5560

JeffBezanson added a commit that referenced this issue Apr 7, 2016
this simplifies some of the code, and gives sharper type information.
fixes #5090, type inference of `&&` and `||` chains
also makes it easy to fix #5560 and #14324
JeffBezanson added a commit that referenced this issue Apr 7, 2016
this simplifies some of the code, and gives sharper type information.
fixes #5090, type inference of `&&` and `||` chains
also makes it easy to fix #5560 and #14324
JeffBezanson added a commit that referenced this issue Apr 7, 2016
this simplifies some of the code, and gives sharper type information.
fixes #5090, type inference of `&&` and `||` chains
also makes it easy to fix #5560 and #14324
JeffBezanson added a commit that referenced this issue Apr 7, 2016
this simplifies some of the code, and gives sharper type information.
fixes #5090, type inference of `&&` and `||` chains
also makes it easy to fix #5560 and #14324
JeffBezanson added a commit that referenced this issue Apr 8, 2016
this simplifies some of the code, and gives sharper type information.
fixes #5090, type inference of `&&` and `||` chains
also makes it easy to fix #5560 and #14324
JeffBezanson added a commit that referenced this issue Apr 10, 2016
this simplifies some of the code, and gives sharper type information.
fixes #5090, type inference of `&&` and `||` chains
also makes it easier to deal with #5560 and #14324
JeffBezanson added a commit that referenced this issue Apr 15, 2016
this simplifies some of the code, and gives sharper type information.
fixes #5090, type inference of `&&` and `||` chains
also makes it easier to deal with #5560 and #14324
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

3 participants