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

PSA: don't use ifelse unless you are careful that you have a leaf bitstype #15494

Closed
vtjnash opened this issue Mar 14, 2016 · 4 comments
Closed

Comments

@vtjnash
Copy link
Member

vtjnash commented Mar 14, 2016

PSA: try to avoid ifelse. Otherwise, you cause bugs.

action required: revert #14493

symptom: coverage buildbots are broken (https://build.julialang.org/builders/coverage_ubuntu14.04-x64/builds/89/steps/Run%20non-inlined%20tests/logs/stdio)

$ ./julia -q --inline=no
srand(123);
A1 = Base.LinAlg.UnitUpperTriangular(convert(Matrix{BigFloat}, randn(9,9) |> (t -> chol(t't))));
using Base.Test

julia> similar(A1)
9x9 Base.LinAlg.UnitUpperTriangular{BigFloat,Array{BigFloat,2}}:
 #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef
 #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef  #undef

julia> copy!(B, A1);

julia> @test B == A1

Error During Test
  Test threw an exception of type UndefRefError
  Expression: B == A1
  UndefRefError: access to undefined reference
   in getindex(::Array{BigFloat,2}, ::Int64, ::Int64) at array.jl:241
   in getindex(::Base.LinAlg.UnitUpperTriangular{BigFloat,Array{BigFloat,2}}, ::Int64, ::Int64) at linalg/triangular.jl:114
   in _getindex(::Base.LinearSlow, ::Base.LinAlg.UnitUpperTriangular{BigFloat,Array{BigFloat,2}}, ::CartesianIndex{2}) at multidimensional.jl:359
   in getindex(::Base.LinAlg.UnitUpperTriangular{BigFloat,Array{BigFloat,2}}, ::CartesianIndex{2}) at abstractarray.jl:476
   in next(::Base.LinAlg.UnitUpperTriangular{BigFloat,Array{BigFloat,2}}, ::Tuple{CartesianRange{CartesianIndex{2}},CartesianIndex{2}}) at abstractarray.jl:400
   in next(::Base.Zip2{Base.LinAlg.UnitUpperTriangular{BigFloat,Array{BigFloat,2}},Base.LinAlg.UnitUpperTriangular{BigFloat,Array{BigFloat,2}}}, ::Tuple{Tuple{CartesianRange{CartesianIndex{2}},CartesianIndex{2}},Tuple{CartesianRange{CartesianIndex{2}},CartesianIndex{2}}}) at iterator.jl:48
   in ==(::Base.LinAlg.UnitUpperTriangular{BigFloat,Array{BigFloat,2}}, ::Base.LinAlg.UnitUpperTriangular{BigFloat,Array{BigFloat,2}}) at abstractarray.jl:990
   in eval(::Module, ::Any) at ./boot.jl:243
   in eval(::Module, ::Expr) at REPL.jl:3
ERROR: There was an error during testing
 in error(::ASCIIString) at error.jl:21
 in record(::Base.Test.FallbackTestSet, ::Base.Test.Error) at test.jl:317
 in do_test(::Base.Test.Threw, ::Expr) at test.jl:215
 in eval(::Module, ::Any) at ./boot.jl:243
 in eval(::Module, ::Expr) at REPL.jl:3
@yuyichao
Copy link
Contributor

More like especially avoid ifelse with side-effect? Is llvm (and possibly our inliner) smart enough to turn the branch into a select when it's beneficial?

@JeffBezanson
Copy link
Member

There aren't supposed to be any restrictions on when you can use ifelse. It simply uses function call semantics; arguments are evaluated eagerly. That seems to be the issue here, not bits types. Am I missing something?

@tkelman
Copy link
Contributor

tkelman commented Mar 14, 2016

duplicate of #15466

@JeffBezanson
Copy link
Member

Closing as dup.

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

4 participants