fix(compiler): Panic immediately when out of memory #1450
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 hitunreachable
, and changes the implementation ofmorecore
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.