Why `@code_lowered (1,2,3) .+ 1` returns error?

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.0.0 (2018-08-08)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> (1,2,3) .+ 1
(2, 3, 4)

julia> @code_lowered (1,2,3) .+ 1
ERROR: UndefVarError: .+ not defined
Stacktrace:
 [1] top-level scope at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/InteractiveUtils/src/macros.jl:118

https://github.com/JuliaLang/julia/issues/28992

Is there any walkaround to see the lowered form of this expression. In theory I should get object of type Broadcasted(+, (1,2,3), 1). Or perhaps a function broadcasted with the same arguments.

julia> Meta.lower(Main, :((1,2,3) .+ 1))
:($(Expr(:thunk, CodeInfo(
 1 ā”€ %1 = (Base.getproperty)(Base.Broadcast, :materialize)                                         ā”‚
 ā”‚   %2 = (Base.getproperty)(Base.Broadcast, :broadcasted)                                         ā”‚
 ā”‚   %3 = (Core.tuple)(1, 2, 3)                                                                    ā”‚
 ā”‚   %4 = (%2)(+, %3, 1)                                                                           ā”‚
 ā”‚   %5 = (%1)(%4)                                                                                 ā”‚
 ā””ā”€ā”€      return %5                                                                                ā”‚
))))

julia> f() = (1,2,3) .+ 1
f (generic function with 1 method)

julia> @code_lowered f()
CodeInfo(
1 1 ā”€ %1 = Base.Broadcast.materialize                                                              ā”‚
  ā”‚   %2 = Base.Broadcast.broadcasted                                                              ā”‚
  ā”‚   %3 = (Core.tuple)(1, 2, 3)                                                                   ā”‚
  ā”‚   %4 = (%2)(Main.:+, %3, 1)                                                                    ā”‚
  ā”‚   %5 = (%1)(%4)                                                                                ā”‚
  ā””ā”€ā”€      return %5                                                                               ā”‚
)
1 Like