# Why does julia have slots, rather than go full SSA?

**URL:** <https://discourse.julialang.org/t/why-does-julia-have-slots-rather-than-go-full-ssa/95649>\
**Category:** Internals & Design\
**Created:** [March 7, 2023, 7:44am UTC](https://discourse.julialang.org/t/why-does-julia-have-slots-rather-than-go-full-ssa/95649 "2023-03-07T07:44:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [March 7, 2023, 7:45am UTC](https://discourse.julialang.org/t/why-does-julia-have-slots-rather-than-go-full-ssa/95649/1 "2023-03-07T07:45:00Z")

</div>

More a question of history.  
though, it seems like going full SSA would remove some sources of within function type-instability.  
Since it would be impossible to assign different types to same variable, since you actually only assign once

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [March 7, 2023, 10:40am UTC](https://discourse.julialang.org/t/why-does-julia-have-slots-rather-than-go-full-ssa/95649/2 "2023-03-07T10:40:37Z")

</div>

Do you know about [Julia SSA-form IR · The Julia Language](https://docs.julialang.org/en/v1/devdocs/ssair/)?

---

<div class="post-metadata">

**Author:** ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)\
**Post date:** [March 7, 2023, 12:58pm UTC](https://discourse.julialang.org/t/why-does-julia-have-slots-rather-than-go-full-ssa/95649/3 "2023-03-07T12:58:26Z")

</div>

I think the question is more like. Why don’t we lower directly to SSA instead of slots then SSA.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [March 7, 2023, 3:01pm UTC](https://discourse.julialang.org/t/why-does-julia-have-slots-rather-than-go-full-ssa/95649/4 "2023-03-07T15:01:58Z")

</div>

I think it basically started as “add type annotations to lowered AST.”

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [March 8, 2023, 3:38am UTC](https://discourse.julialang.org/t/why-does-julia-have-slots-rather-than-go-full-ssa/95649/5 "2023-03-08T03:38:13Z")

</div>

yes, that talks about why we lower to (near) SSA.  
But it is an impure SSA, as it has slots.  
My question is why don’t we go all the way?

---

<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:** [March 8, 2023, 3:47am UTC](https://discourse.julialang.org/t/why-does-julia-have-slots-rather-than-go-full-ssa/95649/6 "2023-03-08T03:47:14Z")

</div>

We eliminate slots before going to the optimizer. When we added the SSA form IR, there was some talk of doing inference on the SSA form as well, but there was some concern around inference precision. We should probably revisit this at some point.

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [March 8, 2023, 4:03am UTC](https://discourse.julialang.org/t/why-does-julia-have-slots-rather-than-go-full-ssa/95649/7 "2023-03-08T04:03:11Z")

</div>

Ah cool.  
Is there a way to view the IR at that state?

---

<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:** [March 8, 2023, 4:10am UTC](https://discourse.julialang.org/t/why-does-julia-have-slots-rather-than-go-full-ssa/95649/8 "2023-03-08T04:10:46Z")

</div>

There isn’t a builtin way to see the IR post-ssa-conversion, but before the rest of the optimizer pipeline, but you can put a `Core.Main.Base.display(ir)` here: [julia/optimize.jl at a2912e2148b23601316b2b3135e223d9b3dd1c16 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/blob/a2912e2148b23601316b2b3135e223d9b3dd1c16/base/compiler/optimize.jl#L520) and then just do `@code_typed gcd(10, 20)` or something.
