# What is grounded type in Julia?

**URL:** <https://discourse.julialang.org/t/what-is-grounded-type-in-julia/74579>\
**Category:** Internals & Design\
**Created:** [January 13, 2022, 10:05pm UTC](https://discourse.julialang.org/t/what-is-grounded-type-in-julia/74579 "2022-01-13T22:05:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![KZiemian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kziemian/32/9020_2.png) [@KZiemian](https://discourse.julialang.org/u/KZiemian)\
**Post date:** [January 13, 2022, 10:05pm UTC](https://discourse.julialang.org/t/what-is-grounded-type-in-julia/74579/1 "2022-01-13T22:05:39Z")

</div>

In prof. Jan Vitek JuliaCon 2021 [keynote](https://www.youtube.com/watch?v=LT4AP7CUMAw), he discussed type stability and grounded type (starting at 42:30). Short definitions given at this talk are as follow.  
Type is stable if we have clear relation between I/O types.  
Type is grounded when `@code_warntype` is green.

I make a quick search of Julia [1.6.5](https://docs.julialang.org/en/v1.6) and [1.7.1](https://docs.julialang.org/en/v1.7) documentation and it show that word “grounded” never appear in them. The closest match in both cases is “Rounding”.

I want to ask is “grounded type” prof. Vitek’s term for something know in community or is it some new concept that doesn’t take roots outside core team (who is core team can be sometimes blurry)?

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [January 13, 2022, 10:36pm UTC](https://discourse.julialang.org/t/what-is-grounded-type-in-julia/74579/2 "2022-01-13T22:36:51Z")

</div>

> **[Type Stability in Julia: Avoiding Performance Pathologies in JIT Compilation...](https://arxiv.org/abs/2109.01950)**
>
> As a scientific programming language, Julia strives for performance but also provides high-level productivity features. To avoid performance pathologies, Julia users are expected to adhere to a coding discipline that enables so-called type stability....

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [January 13, 2022, 10:42pm UTC](https://discourse.julialang.org/t/what-is-grounded-type-in-julia/74579/3 "2022-01-13T22:42:43Z")

</div>

[https://github.com/JuliaLang/julia/issues/39752](https://github.com/JuliaLang/julia/issues/39752)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 13, 2022, 11:30pm UTC](https://discourse.julialang.org/t/what-is-grounded-type-in-julia/74579/4 "2022-01-13T23:30:47Z")

</div>

> [@KZiemian](#):
>
> I want to ask is “grounded type” prof. Vitek term for something know in community or is it some new concept that doesn’t take roots outside core team (who is core team can be sometimes blurry)?

This seems to be a term introduced by Prof. Vitek in their paper on type stability (linked [above](https://discourse.julialang.org/t/what-is-grounded-type-in-julia/74579/2)), where they write:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/9/a91d1eb7c991d4755c8457016a3b4fb4dadc568c.png)  
That is, they are referring to a function where concrete types of all variables (not just the return value) can be inferred by an ideal compiler (which only knows the argument types), i.e. one where `@code_typed` is “green”.

It’s not a new _concept_ in general in the Julia community, but people have talked about in different ways, e.g. as “type stability” (of the variables, not the return value) or as “type inferability”, and Jan was pushing for more precise terminology.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 14, 2022, 3:30pm UTC](https://discourse.julialang.org/t/what-is-grounded-type-in-julia/74579/5 "2022-01-14T15:30:09Z")

</div>

It should be noted, however, that “variables” in that definition refers to variables in the simplified single static assignment lowering of Julia code introduced in the paper and not to Julia surface level variables. The requirement for groundedness translated back to surface Julia syntax is probably that the type of every expression is predictable from the types of the arguments. Otherwise you would get weird situations where whether a function is grounded or not depends on whether you pass a value directly to a function or assign it to a variable, which would be a bad definition.

---

<div class="post-metadata">

**Author:** ![KZiemian](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kziemian/32/9020_2.png) [@KZiemian](https://discourse.julialang.org/u/KZiemian)\
**Post date:** [January 14, 2022, 3:46pm UTC](https://discourse.julialang.org/t/what-is-grounded-type-in-julia/74579/6 "2022-01-14T15:46:33Z")

</div>

I understand what is lowered Julia code (I used `@code_lowered` few times), I have some understanding of “static” word in C++, but I can’t crack what it means “single static assignment lowering of Julia code”. Can you expand it a little bit?

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [January 14, 2022, 3:49pm UTC](https://discourse.julialang.org/t/what-is-grounded-type-in-julia/74579/7 "2022-01-14T15:49:52Z")

</div>

[Static single-assignment form - Wikipedia](https://en.wikipedia.org/wiki/Static_single_assignment_form), a particular intermediate form that has desirable properties

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [January 14, 2022, 4:19pm UTC](https://discourse.julialang.org/t/what-is-grounded-type-in-julia/74579/8 "2022-01-14T16:19:56Z")

</div>

They introduce a different lowering form in the paper that’s simpler and easier to prove things about. But the high-level take away is if you can predict the types of all expressions in a function from the types of its arguments, then there are a number of compiler optimizations that are provably guaranteed to work. This requirement is moving in the direction of static typing of Julia code, although the paper does not go as far as providing an algorithm for type checking Julia functions.
