-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
Cannot specify type of list comprehension #1343
Comments
julia> Meta.@lower Int[i+1 for i in 1:10]
:($(Expr(:thunk, CodeInfo(
@ none within `top-level scope`
1 ─ %1 = 1:10
│ %2 = Base.IteratorSize(%1)
│ %3 = %2 isa Base.SizeUnknown
│ %4 = Base._array_for(Int, %1, %2)
│ %5 = Base.LinearIndices(%4)
│ @_2 = Base.first(%5)
│ #s1 = Base.iterate(%1)
│ %8 = #s1 === nothing
│ %9 = Base.not_int(%8)
└── goto #7 if not %9
2 ┄ %11 = #s1
│ i = Core.getfield(%11, 1)
│ %13 = Core.getfield(%11, 2)
│ %14 = i + 1
│ nothing
└── goto #4 if not %3
3 ─ Base.push!(%4, %14)
└── goto #5
4 ─ Base.setindex!(%4, %14, @_2)
5 ┄ nothing
│ @_2 = Base.add_int(@_2, 1)
│ #s1 = Base.iterate(%1, %13)
│ %23 = #s1 === nothing
│ %24 = Base.not_int(%23)
└── goto #7 if not %24
6 ─ goto #2
7 ┄ return %4
)))) Not much we can do when the compiler unconditionally lowers to code using mutation, unfortunately. |
#75 would be a great fix :) |
There's also an infinitesimally small chance it'll happen as things stand with Zygote development. The only reason I haven't added the wontfix label here is in the off change the lowering for that syntax might change in some future Julia version. For now, we can use GitHub's suggested verbiage and say this is "not planned". |
Is the plan to not add support for mutation? (duplicate of #75 (comment)) |
There are no plans until someone comes up with a proposal/PR that overcomes everything mentioned in #1228 (comment). Thus far this has not happened, and so nothing is planned. |
Zygote can differentiate list comprehensions with automatically generated types (
[i+1 for i in 1:10]
), but not for explicitly specified types (Int[i+1 for i in 1:10]
orFloat64[i+1 for i in 1:10]
).MWE
The text was updated successfully, but these errors were encountered: