# Check that all fields are concrete types?

**URL:** https://discourse.julialang.org/t/check-that-all-fields-are-concrete-types/10225
**Category:** General Usage
**Created:** [April 7, 2018, 6:17pm UTC](https://discourse.julialang.org/t/check-that-all-fields-are-concrete-types/10225 "2018-04-07T18:17:09Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)
#### Post date: [April 7, 2018, 6:17pm UTC](https://discourse.julialang.org/t/check-that-all-fields-are-concrete-types/10225/1 "2018-04-07T18:17:09Z")

</div>

I’ve discovered that I may have introduced some performance-sapping code into my project because of the following issue. I have two structs `A` and `B` like this:

```julia
    struct A
        field1::Int
    end
    struct B
        containedA::A
    end

```

Later I decide to rewrite `A` with a parameter:

```julia
    struct A{T}
        field1::T  
    end

```

According to my understanding of the language, I should now also parametrize `B` with `T`, else the contained field `A` is an abstract type and anything that uses `B` will involve run-time dispatch. However, in many places in my code, I forgot to do this and am just now noticing the issue.

First, is my understanding correct? Is there a performance hit for not parameterizing `B`?

Second, if this is indeed the case, is there a technique to discover this problem (i.e., a technique to confirm that all fields of a `struct` are concrete) aside from running `code_warntype` and poring over the output?

---

<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: [April 7, 2018, 6:43pm UTC](https://discourse.julialang.org/t/check-that-all-fields-are-concrete-types/10225/2 "2018-04-07T18:43:53Z")

</div>

> [@Stephen\_Vavasis](#):
>
> First, is my understanding correct? Is there a performance hit for not parameterizing B?

Yes,

you could use a macro (only tested on 0.7):

```julia
macro concrete(expr)
    @assert expr.head == :struct
    S = expr.args[2]
    return quote
        $(esc(expr))

        for n in fieldnames($S)
            if !isconcretetype(fieldtype($S, n))
                error("field $n is not concrete")
            end
        end
    end
end

```

```julia
julia> @concrete struct Foo
           v::Array{Int}
       end
ERROR: field v is not concrete
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] top-level scope at REPL[1]:9

julia> struct Bar{Int} end

julia> @concrete struct Foob
           v::Bar
       end
ERROR: field v is not concrete
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] top-level scope at REPL[1]:9

julia> @concrete struct Foobar
           v::Bar{Float64}
       end

```

---

<div class="post-metadata">

### Author: ![Stephen\_Vavasis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephen_vavasis/32/3389_2.png) [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)
#### Post date: [April 14, 2018, 1:52pm UTC](https://discourse.julialang.org/t/check-that-all-fields-are-concrete-types/10225/3 "2018-04-14T13:52:18Z")

</div>

A quick question about this macro: could it be simplified by invoking `isconcretetype` on S itself instead of on the fields?

---

<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: [April 14, 2018, 2:45pm UTC](https://discourse.julialang.org/t/check-that-all-fields-are-concrete-types/10225/4 "2018-04-14T14:45:40Z")

</div>

```julia
struct S
  ...
end

```

is always concrete.

---

<div class="post-metadata">

### Author: ![kapple](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kapple/32/218915_2.png) [@kapple](https://discourse.julialang.org/u/kapple)
#### Post date: [April 23, 2021, 12:50am UTC](https://discourse.julialang.org/t/check-that-all-fields-are-concrete-types/10225/5 "2021-04-23T00:50:52Z")

</div>

Resurrecting this old topic.

`isabstract` and `isconcrete` and with their `Base.` prefixes are not defined for me in Julia 1.6, has it been deprecated?

> [@kristoffer.carlsson](#):
>
> ```julia
> struct S
> ...
> end
> 
> ```

Can I confirm that, I thought the idea of personalising structs was that the struct is concrete only if all of its properties are concrete types?

---

<div class="post-metadata">

### Author: ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)
#### Post date: [April 23, 2021, 3:31am UTC](https://discourse.julialang.org/t/check-that-all-fields-are-concrete-types/10225/6 "2021-04-23T03:31:06Z")

</div>

> [@kapple](#):
>
> `isabstract` and `isconcrete` and with their `Base.` prefixes are not defined for me in Julia 1.6, has it been deprecated?

`Base.isconcretetype` is in 1.5

---

<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: [April 23, 2021, 8:55am UTC](https://discourse.julialang.org/t/check-that-all-fields-are-concrete-types/10225/7 "2021-04-23T08:55:18Z")

</div>

> [@kapple](#):
>
> `isabstract` and `isconcrete` and with their `Base.` prefixes are not defined for me in Julia 1.6

Maybe you are looking for `isabstracttype` and `isconcretetype`?

---

<div class="post-metadata">

### Author: ![kapple](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kapple/32/218915_2.png) [@kapple](https://discourse.julialang.org/u/kapple)
#### Post date: [April 23, 2021, 2:25pm UTC](https://discourse.julialang.org/t/check-that-all-fields-are-concrete-types/10225/8 "2021-04-23T14:25:21Z")

</div>

Yes, thanks guys.

I kicked myself when, after reading your two replies, I tried `?isconcrete` and it suggested `isconcretetype`.
