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

Detected issues when assigning a matrix to a submatrix, rooted in Base abstractarray.jl #374

Closed
Krastanov opened this issue Jul 4, 2022 · 2 comments

Comments

@Krastanov
Copy link

Not sure whether this is a false positive from JET or an issue in base. On JET master from today and Julia nightly from today this happens:

This seems like a pretty innocent piece of code but JET reports a possible issue.

julia> function f1(n) # Vectors work fine
           m = zeros(2n)
           sub = zeros(n)
           m[n+1:2n] .= sub
           m
       end
       @report_call f1(10)
No errors detected


julia> function f2(n) # Matrices have issues
           m = zeros(2n, 2n)
           sub = zeros(n, n) # this needs to be a matrix to trigger the issue
           m[n+1:2n, n+1:2n] .= sub
           m
       end
       @report_call f2(10)
═════ 2 possible errors found ═════
┌ @ REPL[31]:4 Base.materialize!(Base.dotview(m, n + 1 : 2 * n, n + 1 : 2 * n), Base.broadcasted(identity, sub))
│┌ @ broadcast.jl:881 Base.Broadcast.materialize!(Base.Broadcast.combine_styles(dest, bc), dest, bc)
││┌ @ broadcast.jl:884 Base.Broadcast.copyto!(dest, Base.Broadcast.instantiate(Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2}}(bc.f, bc.args, Base.Broadcast.axes(dest))))
│││┌ @ broadcast.jl:926 Base.Broadcast.copyto!(dest, Base.Broadcast.convert(Base.Broadcast.Broadcasted{Nothing}, bc))
││││┌ @ broadcast.jl:967 Base.Broadcast.copyto!(dest, A)
│││││┌ @ abstractarray.jl:1039 Base.copyto_unaliased!(IndexStyle(dest), dest, IndexStyle(src′), src′)
││││││┌ @ abstractarray.jl:1079 Base.indexed_iterate(ret, 1)
│││││││┌ @ tuple.jl:91 x = iterate(I)
││││││││ no matching method found `iterate(::Nothing)`: x = iterate(I::Nothing)::Union{}
│││││││└───────────────
││││││┌ @ abstractarray.jl:1079 Base.indexed_iterate(ret, 2, _26)
│││││││┌ @ tuple.jl:96 x = iterate(I, state)
││││││││ no matching method found `iterate(::Nothing, ::Int64)`: x = iterate(I::Nothing, state::Int64)::Union{}
│││││││└───────────────

Here are the lines that JET is complaining about: https://github.com/JuliaLang/julia/blob/05eb1530bbfe2db0dd6c9a13ea065f17cb9730cf/base/abstractarray.jl#L1077-L1082=

version info:

julia> versioninfo()
Julia Version 1.9.0-DEV.875
Commit 05eb1530bbf (2022-07-01 22:42 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 1700 Eight-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.5 (ORCJIT, znver1)
  Threads: 8 on 16 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 8

(clifford) pkg> st JET
Status `~/Documents/ScratchSpace/clifford/Project.toml`
  [c3a54625] JET v0.5.16 `https://github.com/aviatesk/JET.jl.git#master`

Started as a discussion on discourse: https://discourse.julialang.org/t/jet-is-unhappy-with-broadcast-assigning-a-matrix-to-a-submatrix-rooted-in-abstractarray-jl/83750

@aviatesk
Copy link
Owner

aviatesk commented Jul 5, 2022

Thanks! This kind of report is a typical case where we need to improve the implementation of Julia Base. Let's just improve it and makes JET happier with Base.

aviatesk added a commit to JuliaLang/julia that referenced this issue Jul 5, 2022
This change makes static analysis happier.
xref: <aviatesk/JET.jl#374>
aviatesk added a commit to JuliaLang/julia that referenced this issue Jul 5, 2022
This change makes static analysis happier.
xref: <aviatesk/JET.jl#374>
@aviatesk
Copy link
Owner

aviatesk commented Jul 5, 2022

Solved in upstream.

@aviatesk aviatesk closed this as completed Jul 5, 2022
ffucci pushed a commit to ffucci/julia that referenced this issue Aug 11, 2022
This change makes static analysis happier.
xref: <aviatesk/JET.jl#374>
pcjentsch pushed a commit to pcjentsch/julia that referenced this issue Aug 18, 2022
This change makes static analysis happier.
xref: <aviatesk/JET.jl#374>
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

2 participants