# What are those magic variables in lowered code?

**URL:** https://discourse.julialang.org/t/what-are-those-magic-variables-in-lowered-code/29083
**Category:** General Usage
**Created:** [September 23, 2019, 5:18pm UTC](https://discourse.julialang.org/t/what-are-those-magic-variables-in-lowered-code/29083 "2019-09-23T17:18:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)
#### Post date: [September 23, 2019, 5:18pm UTC](https://discourse.julialang.org/t/what-are-those-magic-variables-in-lowered-code/29083/1 "2019-09-23T17:18:50Z")

</div>

I’m trying to understand the result of `@code_lowered` macro. Consider this simple example:

```julia
julia> mutable struct Foo
           value
       end

julia> foo = Foo(1)
Foo(1)

julia> @code_lowered(foo.value = 2)
CodeInfo(
1 ─ %1 = (Base.typeof)(x)
│ %2 = (Base.fieldtype)(%1, f)
│ %3 = (Base.convert)(%2, v)
│ %4 = (Base.setfield!)(x, f, %3)
└── return %4
)

```

I can largely follow the logic but got really confused with `x`, `f`, and `v`. If I match to the original code, I can derive that:

- `x = foo` so `%1 = Foo`
- `f = :value` so `%2 = Any`
- `v = 2` so `%3 = 2`
- `%4 = 2`

Is there any reason why these values are not just displayed as-is? Ideally something like this:

```julia
CodeInfo(
1 ─ %1 = (Base.typeof)(foo)
│ %2 = (Base.fieldtype)(%1, :value)
│ %3 = (Base.convert)(%2, Int64(2))
│ %4 = (Base.setfield!)(foo, :value, %3)
└── return %4
)

```

Also, is there a naming convention for these variables?

---

<div class="post-metadata">

### Author: ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)
#### Post date: [September 23, 2019, 5:37pm UTC](https://discourse.julialang.org/t/what-are-those-magic-variables-in-lowered-code/29083/2 "2019-09-23T17:37:23Z")

</div>

The various `@code_` macros operate on function calls **NOT** expressions. In particular, everything, but the outermost call is evaluated. Now, in your example, there’s an extra bit of confusion, because `a.b = c` is syntactic sugar for `setproperty!(a, :b, c)`. As a result, the what you’re asking for is

```julia
julia> @code_lowered setproperty!(a, :b, c)

```

which then does faithfully show you the lowered code of the setproperty! function: [https://github.com/JuliaLang/julia/blob/4f17558e4c71908e8ba40d24e37bdacd5e2f2e5e/base/Base.jl#L34](https://github.com/JuliaLang/julia/blob/4f17558e4c71908e8ba40d24e37bdacd5e2f2e5e/base/Base.jl#L34). If you want to see the lowering of an expression, an easy way to do so is to put it in an anonymous function:

```julia
julia> @code_lowered((()->foo.value = 2)())
CodeInfo(
1 ─ Base.setproperty!(Main.foo, :value, 2)
└── return 2
)

```

or by asking the lowering code directly (if you happen to care about scoping differences):

```julia
Meta.lower(Main, :(foo.value = 2))
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope'
1 ─ Base.setproperty!(foo, :value, 2)
└── return 2
))))

```
