One of the most common complaints arising in this group is issue 15276, https://github.com/JuliaLang/julia/issues/15276, which seems to cause all kinds of baffling performance hits. I’m wondering whether this issue could be solved by adding the following restriction to the language: any variable captured in a closure must have the same concrete type for its lifetime.
First, does this restriction solve the issue? In other words, if this restriction were added to the language, is there still a case when a variable whose type can be inferred in the outer scope would cause type instability in the closure?
Second, if this restriction were imposed, how much useful language functionality is lost?