Skip to content

Do some constant propagation before type inference runs #5560

@Keno

Description

@Keno

It would be good to run some constant propagation before type inference runs for cases in which a type parameter is really constant, but we don't know because we compute with it before. E.g:

type foo{m}; end
inv{m}(x::foo{m}) = foo{-m}()
id{m}{x::foo{m}) = foo{m}()

For id, we get a nice

julia> code_typed(id,(foo{1},))
1-element Array{Any,1}:
 :($(Expr(:lambda, {:x}, {{},{{:x,foo{1},0}},{}}, quote  # /Users/kfischer/.julia/REPL/scripts/repl.jl, line 1:
        return $(Expr(:new, foo{1}))::foo{1}
    end)))

whereas for inv, we get

julia> code_typed(inv,(foo{1},))
1-element Array{Any,1}:
 :($(Expr(:lambda, {:x}, {{},{{:x,foo{1},0}},{}}, quote  # /Users/kfischer/.julia/REPL/scripts/repl.jl, line 1:
        return top(apply_type)(foo,top(box)(Int64,top(neg_int)(1))::Int64)::Type{_<:foo{m}}()::foo{m}
    end)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions