# Composing types with non-concrete fields

**URL:** https://discourse.julialang.org/t/composing-types-with-non-concrete-fields/10678
**Category:** Internals & Design
**Tags:** question
**Created:** [May 3, 2018, 9:39am UTC](https://discourse.julialang.org/t/composing-types-with-non-concrete-fields/10678 "2018-05-03T09:39:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [May 3, 2018, 9:39am UTC](https://discourse.julialang.org/t/composing-types-with-non-concrete-fields/10678/1 "2018-05-03T09:39:50Z")

</div>

Consider the MWE

```julia
struct Foo
    x::Any # NOT CONCRETE
end

struct Bar{Ty, Tz}
    y::Ty
    z::Tz # but fully parametrized here
end

f(b::Bar) = b.y + 1 # this function only uses the concrete field

b = Bar(1, Foo(9.0))

@code_warntype f(b) # I get no warnings on v0.6.2

```

which composes a type `Foo` with an abstract field (ie violating [the performance recommendation](https://docs.julialang.org/en/latest/manual/performance-tips/#Avoid-fields-with-abstract-type-1)) into `Bar`.

Questions:

1. if I then use _only the concrete fields_ of `Bar`, do I still get the performance benefits? (ie avoid the performance penalties?)
2. is there a constraint, eg the type with abstract fields being the last field?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [May 3, 2018, 10:51am UTC](https://discourse.julialang.org/t/composing-types-with-non-concrete-fields/10678/2 "2018-05-03T10:51:08Z")

</div>

Any use of concrete fields should be fully optimizable no matter what is in the other fields.

```julia
julia> struct F
       a::Int
       b
       c
       d
       e
       end

julia> b = F(1,2,3,4,5)
F(1, 2, 3, 4, 5)

julia> f(A::F, B::F) = A.a + B.a
f (generic function with 1 method)

julia> @code_native f(b,b)
        .section __TEXT,__ text,regular,pure_instructions
; Function f {
; Location: REPL[33]:1
; Function +; {
; Location: REPL[33]:1
        movq (%rsi), %rax
        addq (%rdi), %rax
;}
        retq
        nopw (%rax,%rax)
;}

```
