We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
getfield
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
If possible, it would be ideal to perform constant folding before running inference on getfield. Here's a demo:
julia> abstract Container{N} julia> type Container1d <: Container{1} center1::Float32 child::Container1d end julia> type Container2d <: Container{2} center1::Float32 center2::Float32 child::Container2d end julia> getchild{N}(parent::Container{N}) = getfield(parent, N+1) getchild (generic function with 1 method) julia> function childpositive(c::Container) child = getchild(c) child.center1 > 0 end childpositive (generic function with 1 method) julia> code_typed(childpositive, (Container1d,)) 1-element Array{Any,1}: :($(Expr(:lambda, Any[:c], Any[Any[:child,:_var0,:_var3,:_var4],Any[Any[:c,Container1d,0],Any[:child,Union(Container1d,Float32),18],Any[:_var0,Float32,18],Any[:_var3,(Int64,),0],Any[:_var4,Float32,18]],Any[]], :(begin # none, line 2: child = getfield(c::Container1d,(top(box))(Int64,(top(add_int))(1,1))::Int64)::Union(Container1d,Float32) # line 3: _var4 = (top(getfield))(child::Union(Container1d,Float32),:center1)::Float32 _var0 = (top(box))(Float32,(top(sitofp))(Float32,0))::Float32 return (top(box))(Bool,(top(or_int))((top(lt_float))(_var0::Float32,_var4::Float32)::Bool,(top(box))(Bool,(top(and_int))((top(eq_float))(_var0::Float32,_var4::Float32)::Bool,(top(box))(Bool,(top(or_int))((top(eq_float))(_var0::Float32,9.223372f18)::Bool,(top(slt_int))(0,(top(box))(Int64,(top(fptosi))(Int64,_var0::Float32))::Int64)::Bool))::Bool))::Bool))::Bool end::Bool))))
Note the Union(Container1d,Float32) for the result of getchild(c), which arises presumably because add_int(1,1) isn't evaluated.
Union(Container1d,Float32)
getchild(c)
add_int(1,1)
For comparison,
julia> function centerpositive(c::Container) c.center1 > 0 end centerpositive (generic function with 1 method) julia> code_typed(centerpositive, (Container1d,)) 1-element Array{Any,1}: :($(Expr(:lambda, Any[:c], Any[Any[:_var0,:_var3,:_var4],Any[Any[:c,Container1d,0],Any[:_var0,Float32,18],Any[:_var3,(Int64,),0],Any[:_var4,Float32,18]],Any[]], :(begin # none, line 2: _var4 = (top(getfield))(c::Container1d,:center1)::Float32 _var0 = (top(box))(Float32,(top(sitofp))(Float32,0))::Float32 return (top(box))(Bool,(top(or_int))((top(lt_float))(_var0::Float32,_var4::Float32)::Bool,(top(box))(Bool,(top(and_int))((top(eq_float))(_var0::Float32,_var4::Float32)::Bool,(top(box))(Bool,(top(or_int))((top(eq_float))(_var0::Float32,9.223372f18)::Bool,(top(slt_int))(0,(top(box))(Int64,(top(fptosi))(Int64,_var0::Float32))::Int64)::Bool))::Bool))::Bool))::Bool end::Bool))))
is, of course, inferred beautifully.
Now that we have some parse-time constant folding in cartesian.jl, perhaps we could just use that?
cartesian.jl
The text was updated successfully, but these errors were encountered:
I think this is a dup of #5560.
Sorry, something went wrong.
Agreed. I did search, but used the term "fold."
No branches or pull requests
If possible, it would be ideal to perform constant folding before running inference on
getfield
. Here's a demo:Note the
Union(Container1d,Float32)
for the result ofgetchild(c)
, which arises presumably becauseadd_int(1,1)
isn't evaluated.For comparison,
is, of course, inferred beautifully.
Now that we have some parse-time constant folding in
cartesian.jl
, perhaps we could just use that?The text was updated successfully, but these errors were encountered: