i keep running into a particular breed of compiler crash, which all look like:
Begin Error in Function: '$s5Biome9EvolutionV8compound7contextAcA8CompoundV_AA7PackageV7ContextVtcfC'
Function: '$s5Biome9EvolutionV8compound7contextAcA8CompoundV_AA7PackageV7ContextVtcfC'
Found non consuming use outside of the lifetime being verified.
Value: %141 = load_borrow %140 : $*Branch.Buffer<Symbol> // users: %152, %143
User: end_borrow %143 : $*Branch.Buffer<Symbol> // id: %172
End Error in Function: '$s5Biome9EvolutionV8compound7contextAcA8CompoundV_AA7PackageV7ContextVtcfC'
Found ownership error?!
triggering standard assertion failure routine
UNREACHABLE executed at /home/build-user/swift/lib/SIL/Verifier/LinearLifetimeCheckerPrivate.h:211!
the first few times i encountered this crash, i reported each instance (1, 2) as a compiler bug, but over time i came to suspect this was actually the same compiler bug manifesting itself in different ways.
now, most compiler crashes are really user errors, and they only appear with code that never would have compiled in the first place. so they are annoying (because they crash sourcekit-lsp and the IDE highlighter) but beyond that they do not really get in the way of programming.
a lot of the remaining compiler crashes are narrow in impact and they usually have simple workarounds that just involve dropping down to older syntax.
but the “LinearLifetimeCheckerPrivate.h” crash is different. because:
-
the code that causes the crash is usually valid swift (or at least i would expect it to be)
-
it’s hard to work around the crash, because you can spend a lot of time refactoring and rearranging the code in the hopes that it will dodge the crash, but the crash happens nonetheless. so the crash is “robust” in the worst way possible.
-
it’s hard to evade the crash, because it seems to correlate with generics and the ARC optimizer, and i don’t have a deep understanding of how those are implemented in the compiler, so i don’t know which patterns to avoid in order to prevent myself from ending up in this situation to begin with.
has anyone else run into this crash, and what, if anything, were you able to do to mitigate its impact?