grain icon indicating copy to clipboard operation
grain copied to clipboard

fix(compiler): Panic immediately when out of memory

Open ospencer opened this issue 3 years ago • 0 comments

This is a bit of a fun bug I discovered while working on refactoring constructors. When an OutOfMemory is thrown, if any memory is allocated during the chain of exception printer calls, we wind up in an infinite loop: we're out of memory, so trying to allocate something to report that we're out of memory ends up entering the out of memory flow again.

This PR adds Exception.panic in the runtime to print a string and immediately hit unreachable, and changes the implementation of morecore to immediately panic when out of memory instead of following the normal exception handling logic which could potentially try to allocate memory.

This seemed like a reasonable approach to me, since (in the future) users shouldn't be allowed to catch an OutOfMemory error.

I didn't consider this a breaking change because the API changes are only in the runtime.

ospencer avatar Oct 15 '22 22:10 ospencer