# "A Tragedy of Julia’s Type System"

**URL:** <https://discourse.julialang.org/t/a-tragedy-of-julia-s-type-system/124619>\
**Category:** Offtopic\
**Created:** [January 10, 2025, 3:12am UTC](https://discourse.julialang.org/t/a-tragedy-of-julia-s-type-system/124619 "2025-01-10T03:12:02Z")\
**Posts on this page:** 1\
**Showing post:** 30

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [January 13, 2025, 3:52pm UTC](https://discourse.julialang.org/t/a-tragedy-of-julia-s-type-system/124619/30 "2025-01-13T15:52:49Z")

</div>

> [@giordano](#):
>
> Also, I think everyone agrees that’s a quirk (or bug) but it doesn’t have to be that way.

> [@Benny](#):
>
> Stupid, but not _trivially_. Fundamentally a call-wise compiler can only go so far for variables that exist across multiple calls

So, at least @Benny is of the opinion that it _has_ to be that way, i.e. that inference of non-SSA captures will always and unavoidable suck.

But additionally, it sucks extra hard, because the lowering is dumb. E.g.

```julia
function f()
x = 0
if false x = 1 end
g()=x
g()
end

```

gleefully infers as Any. This is because lowering is dumb and only sees the AST, and neither CFG nor const-prop nor escape analysis nor anything!

I tend to agree with @Benny, the problem is hard, and it will always suck. But it doesn’t need to suck _that_ badly.

Regardless, it has been that way for 8+ years. I think it is disingeneous to pretend that boxing of captures will be solved “with the attack Keno”.

Even if we somehow got much better optimization, by deferring boxing decisions to later optimization stages that have CFG, type inference and escape analysis available, the semantics of captures mean that we will box a lot.

I see a much brighter future for a command-line switch that emits warnings for all boxed captures – i.e. for everything that is not capture-by-value.

And then a slow community shift to always enable that switch, and thus transition to a julia dialect / subset that has capture-by-value.

(due to macros and generated functions, boxing cannot be statically decided / linted, you really _must_ hook the compiler in order to be able to warn users that they wrote really bad code)

---

_[View the full topic](https://discourse.julialang.org/t/a-tragedy-of-julia-s-type-system/124619)._
