-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Latest at-view
macro changes break previously valid code ("invalid let syntax")
#53107
Comments
at-view
macro changes break previously valid code (at-view
macro changes break previously valid code ("invalid let syntax")
On one level, it seems like it should be an error to put a julia> @views transpose(M)[:,end] .+= M[1:3]
ERROR: syntax: invalid let syntax around REPL[6]:1 EDIT: Oh, interesting - it's the same error on 1.10, 1.9, and 1.6 (skipped others) when using |
Oh this is fascinating — I think the change itself was valid, but it's exposing a quirk in lowering of all places. Specifically, it's that lowering can handle the complicated julia> Meta.@lower (let x=x; x; end) .+= 1
:($(Expr(:error, "invalid let syntax around REPL[20]:1")))
julia> Meta.@lower (true && let x=x; x; end) .+= 1
:($(Expr(:thunk, CodeInfo(
@ none within `top-level scope`
1 ─ %1 = x
│ x = %1
│ @ REPL[24]:1 within `top-level scope`
│ %3 = x
└── goto #3 if not true
2 ─ @_2 = %3
└── goto #4
3 ─ @_2 = false
4 ┄ %8 = @_2
│ %9 = Base.broadcasted(+, %8, 1)
│ %10 = Base.materialize!(%8, %9)
└── return %10
))))
julia> Meta.@lower (nothing; let x=x; x; end) .+= 1
:($(Expr(:thunk, CodeInfo(
@ none within `top-level scope`
1 ─ %1 = x
│ x = %1
│ @ REPL[23]:1 within `top-level scope`
│ %3 = x
│ nothing
│ %5 = Base.broadcasted(+, %3, 1)
│ %6 = Base.materialize!(%3, %5)
└── return %6
)))) |
When the frontend lowers an expression like `lhs .+= rhs`, it needs to prevent evaluating the LHS more than once before re-writing to `lhs .= lhs .+ rhs`. If the LHS was a `let` block — commonly generated by `@views` and (since #53064) `@view` — the lowering pass had previously been emitting an invalid `let` temporary. This very directly addresses that case. Fixes #53107. Fixes #44356.
I noticed a possible breakage of the
at-view
macro in the current master (since 0588cd4) under very specific circumstances while tracking down a precompilation error of BioStructures.jl w/ Gihub CI and Julianightly
pointing to this particular line of code:https://github.com/BioJulia/BioStructures.jl/blob/69b48127811f0ec235bd17e25838af7ceffd4087/src/spatial.jl#L205
The associated error is:
Corresponding
versioninfo()
of the Github runner:Please find below a MWE to trigger the same error as above. A few conditions seem to be required for the error to trigger, particularly:
transpose
oradjoint
(working directly on the matrix, does not trigger the error)end
in some way (replacingend
by the corresponding column index in the example below does not trigger the error).+=
or.*=
(broadcast assignment.=
does not trigger the error)MWE
Expected behavior (before 0588cd4):
Since 0588cd4:
MWE output produced using Julia 1.11.0-DEV.1394 (dcb196e) before and after cherry-picking 0588cd4, respectively.
The text was updated successfully, but these errors were encountered: