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

all/any return the wrong result when reducing over infinite iterators #47664

Closed
Seelengrab opened this issue Nov 22, 2022 · 2 comments
Closed
Labels
design Design of APIs or of the language itself iteration Involves iteration or the iteration protocol

Comments

@Seelengrab
Copy link
Contributor

Seelengrab commented Nov 22, 2022

This is a bit of an odd one:

julia> f() = any(isone, Iterators.repeated(0))

should clearly return false or loop infinitely, yet:

julia> @code_typed f()
CodeInfo(
1return true
) => Bool

The inverse happens with all:

julia> f() = all(iszero, Iterators.repeated(0))
f (generic function with 1 method)

julia> @code_lowered f()
CodeInfo(
1%1 = Main.iszero
│   %2 = Base.Iterators.repeated
│   %3 = (%2)(0)
│   %4 = Main.all(%1, %3)
└──      return %4
)

julia> @code_typed f()
CodeInfo(
1return false
) => Bool

which should (if anything) return true.

Seems like an issue in inference:

julia> @code_warntype f()
MethodInstance for f()
  from f() @ Main REPL[1]:1
Arguments
  #self#::Core.Const(f)
Body::Bool
1%1 = Main.iszero::Core.Const(iszero)
│   %2 = Base.getproperty(Main.Iterators, :repeated)::Core.Const(Base.Iterators.repeated)
│   %3 = (%2)(0)::Core.Const(Base.Iterators.Repeated{Int64}(0))
│   %4 = Main.all(%1, %3)::Core.Const(false)
└──      return %4
@KristofferC
Copy link
Member

Ref #40009

@brenhinkeller brenhinkeller added bug Indicates an unexpected problem or unintended behavior iteration Involves iteration or the iteration protocol design Design of APIs or of the language itself and removed bug Indicates an unexpected problem or unintended behavior labels Nov 22, 2022
@JeffBezanson
Copy link
Member

Yes, this is a duplicate of #40009. I do really think we should change it, and Keno seems to agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design of APIs or of the language itself iteration Involves iteration or the iteration protocol
Projects
None yet
Development

No branches or pull requests

4 participants