Fix stack overflow when asking for an AOT operand's type. #1397
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.
Requires ykjit/ykllvm#200
When adding more passes to the AOT pipeline we found that the mere act of printing the AOT module can cause stack overflows.
If you have IR like:
Asking the type of %3 causes infinite recursion.
This is because an operation often asks its operands for their type to determine their own type.
Here, %3 asks %2, who asks %3, who asks %2, who asks... forever. Each "ask" is a function call, so this blows the stack.
This change breaks the cycle by putting a PHI's type into the instruction explicitly, so it doesn't have to search further afield to know it's type.
We haven't seen this before because usually the first operand to a PHI is from earlier (not later) in the module, so there is no cycle.