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

Inference suboptimality when using nested generators #45748

Closed
jonathan-laurent opened this issue Jun 19, 2022 · 0 comments · Fixed by #45789
Closed

Inference suboptimality when using nested generators #45748

jonathan-laurent opened this issue Jun 19, 2022 · 0 comments · Fixed by #45789
Labels
inference Type inference

Comments

@jonathan-laurent
Copy link

The following code does not infer using Julia 1.7.3:

f(n) = (i^2 for i in 1:n)
g(n) = sum(x^2 for x in f(n))
@code_warntype g(3)

Output:

MethodInstance for g(::Int64)
  from g(n) in Main at /home/jonathan/AlphaZero.jl/redesign/private/inference.jl:2
Arguments
  #self#::Core.Const(g)
  n::Int64
Locals
  #61::var"#61#62"
Body::Any
1 ─      (#61 = %new(Main.:(var"#61#62")))
│   %2 = #61::Core.Const(var"#61#62"())
│   %3 = Main.f(n)::Core.PartialStruct(Base.Generator{UnitRange{Int64}, var"#59#60"}, Any[Core.Const(var"#59#60"()), Core.PartialStruct(UnitRange{Int64}, Any[Core.Const(1), Int64])])
│   %4 = Base.Generator(%2, %3)::Core.PartialStruct(Base.Generator{Base.Generator{UnitRange{Int64}, var"#59#60"}, var"#61#62"}, Any[Core.Const(var"#61#62"()), Core.PartialStruct(Base.Generator{UnitRange{Int64}, var"#59#60"}, Any[Core.Const(var"#59#60"()), Core.PartialStruct(UnitRange{Int64}, Any[Core.Const(1), Int64])])])
│   %5 = Main.sum(%4)::Any
└──      return %5

This issue is crossposted from Discourse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inference Type inference
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants