@@ -416,10 +416,11 @@ end
416416 inbounds:: Bool
417417 arr
418418 elems # Either iterator of Pairs or just an iterator
419+ return_arr:: Bool
419420end
420421
421422"""
422- SetArray(inbounds, arr, elems)
423+ SetArray(inbounds::Bool , arr, elems[, return_arr::Bool] )
423424
424425An expression representing setting of elements of `arr`.
425426
@@ -430,9 +431,14 @@ is performed in its place.
430431
431432`inbounds` is a boolean flag, `true` surrounds the resulting expression
432433in an `@inbounds`.
434+
435+ `return_arr` is a flag which controls whether the generated `begin..end` block
436+ returns the `arr`. Defaults to `false`, in which case the block returns `nothing`.
433437"""
434438SetArray
435439
440+ SetArray (inbounds, arr, elems) = SetArray (inbounds, arr, elems, false )
441+
436442@matchable struct AtIndex <: CodegenPrimitive
437443 i
438444 elem
@@ -446,7 +452,7 @@ function toexpr(s::SetArray, st)
446452 ex = quote
447453 $ ([:($ (toexpr (s. arr, st))[$ (ex isa AtIndex ? toexpr (ex. i, st) : i)] = $ (toexpr (ex, st)))
448454 for (i, ex) in enumerate (s. elems)]. .. )
449- nothing
455+ $ (s . return_arr ? toexpr (s . arr, st) : nothing )
450456 end
451457 s. inbounds ? :(@inbounds $ ex) : ex
452458end
@@ -906,7 +912,7 @@ function cse!(x::MakeArray, state::CSEState)
906912end
907913
908914function cse! (x:: SetArray , state:: CSEState )
909- return SetArray (x. inbounds, x. arr, cse! (x. elems, state))
915+ return SetArray (x. inbounds, x. arr, cse! (x. elems, state), x . return_arr )
910916end
911917
912918function cse! (x:: MakeSparseArray , state:: CSEState )
0 commit comments