Skip to content

incorrect code generation for if_else when expression is used in condition and one of the branches. #94

Open
brianguenter wants to merge 2 commits intomainfrom
ifelsefix
Open

incorrect code generation for if_else when expression is used in condition and one of the branches. #94
brianguenter wants to merge 2 commits intomainfrom
ifelsefix

Conversation

@brianguenter
Copy link
Owner

@brianguenter brianguenter commented Sep 25, 2024

if an expression is used in condition of if_else and in one of the branches then code gen made that branch return nothing. Example:

julia>  h = make_function([if_else(sqrt(x) < 1, sqrt(x), 0.0)], [x])
RuntimeGeneratedFunction(#=in FastDifferentiation=#, #=using FastDifferentiation=#, :((input_variables,)->begin
          #= c:\Users\seatt\source\FastDifferentiation.jl\src\CodeGeneration.jl:229 =#
          #= c:\Users\seatt\source\FastDifferentiation.jl\src\CodeGeneration.jl:229 =# @inbounds begin
                  #= c:\Users\seatt\source\FastDifferentiation.jl\src\CodeGeneration.jl:230 =#
                  begin
                      result_element_type = promote_type(Float64, eltype(input_variables))
                      result = Array{result_element_type}(undef, (1,))
                      var"##319" = sqrt(input_variables[1])
                      var"##318" = var"##319" < 1
                      var"##317" = if var"##318"
                              #= c:\Users\seatt\source\FastDifferentiation.jl\src\CodeGeneration.jl:58 =#
                              begin #####ERROR here should return var"##319" in the true branch. But because this expression was used in the condition of if_else it was skipped as being already defined.
                              end
                          else
                              #= c:\Users\seatt\source\FastDifferentiation.jl\src\CodeGeneration.jl:60 =#
                              begin
                                  var"##s#320" = 0.0
                              end
                          end
                      result[1] = var"##317"
                      return result
                  end
              end
      end))

This PR fixes this bug.

…ndition of if_else and in on of the branches then code gen made that branch return nothing.
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

Successfully merging this pull request may close these issues.

1 participant