# Inline function returns tuple of mixed type, assigned to a tuple of variables in the caller

**URL:** <https://discourse.julialang.org/t/inline-function-returns-tuple-of-mixed-type-assigned-to-a-tuple-of-variables-in-the-caller/101598>\
**Category:** Performance\
**Created:** [July 14, 2023, 3:01am UTC](https://discourse.julialang.org/t/inline-function-returns-tuple-of-mixed-type-assigned-to-a-tuple-of-variables-in-the-caller/101598 "2023-07-14T03:01:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lian\_Yunlong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lian_yunlong/32/14437_2.png) [@Lian\_Yunlong](https://discourse.julialang.org/u/Lian_Yunlong)\
**Post date:** [July 14, 2023, 3:01am UTC](https://discourse.julialang.org/t/inline-function-returns-tuple-of-mixed-type-assigned-to-a-tuple-of-variables-in-the-caller/101598/1 "2023-07-14T03:01:56Z")

</div>

Dear Julia community,

I wish to learn the appropriate usage of Julia tuples.

Consider the following scenario. One needs to make an inline function to separate a block of code inside a very complicated function. Naturally, this block of code operates with several local variables. When making the inline function, these local variables are passed into the inline function as arguments. More importantly, the inline function returns several variables after some operations. Since the inline function has its own scope, inside the inline function one cannot directly assign values to the variables from the caller, but rather return some variables. For example, I have made the following inline function:

```julia
@inline function compute_something(v1, v2, v3, v4)
    #...
    # some computations
    return (r1, r2, r3, r4, r5)
end

```

This inline function `compute_something()` separates the code inside a complicated function `COMP()`, which has local variables `v1, v2, v3, v4, r1, r2, r3, r4, r5`. I hope to use it inside `COMP()` as following

```julia
function COMP()
    # ...
    # some computations that prepares v1, v2, v3, v4
    (u1, u2, u3, u4, u5) = compute_something(v1, v2, v3, v4)
    # continue ...
end

```

**Now the real question is performance:** does this tuple assignment actually create a tuple and assign? Or it just paste the code of inline function into `COMP()` and assign the results of `compute_something()` to the local variables `u1, u2, u3, u4, u5` inside `COMP()`, as if I write `u1 = r1`, `u2 = r2`, … ?

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 14, 2023, 6:26am UTC](https://discourse.julialang.org/t/inline-function-returns-tuple-of-mixed-type-assigned-to-a-tuple-of-variables-in-the-caller/101598/2 "2023-07-14T06:26:55Z")

</div>

> [@Lian\_Yunlong](#):
>
> as if I write `u1 = r1`, `u2 = r2`, … ?

I think so. Using the following example functions:

```julia
julia> @noinline function compute_something(v1, v2, v3, v4)
           return (v1/1, v2/2, v3/3, v4/4, (v1+v2)/5)
       end
compute_something (generic function with 1 method)

julia> function COMP(v1, v2, v3, v4)
         (u1, u2, u3, u4, u5) = compute_something(v1, v2, v3, v4)
         return u1+u2+u3+u4+u5
       end
COMP (generic function with 1 method)

```

`@code_llvm COMP(1,2,3,4)` shows `[5 x double]` everywhere, which would be a tuple. But when you change that to `@inline` like your example, then there’s no `[5 x double]` anywhere, only individual `double`s.

---

<div class="post-metadata">

**Author:** ![Lian\_Yunlong](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lian_yunlong/32/14437_2.png) [@Lian\_Yunlong](https://discourse.julialang.org/u/Lian_Yunlong)\
**Post date:** [July 14, 2023, 6:30am UTC](https://discourse.julialang.org/t/inline-function-returns-tuple-of-mixed-type-assigned-to-a-tuple-of-variables-in-the-caller/101598/3 "2023-07-14T06:30:46Z")

</div>

> [@Benny](#):
>
> @code\_llvm

Thank you @Benny ! I can use `@code_llvm` macro to inspect the actual code 😃
