Merge pull request #12411 from shajrawi/silcombine_bugfix #12412
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.
radar rdar://problem/34966696
• Explanation: Fixes an infinite loop. The infinite loop was there for over a year but it got exposed by the following bug fix: rdar://problem/34753633
• Scope of Issue: Fixes an infinite loop in SILCombiner: we should not create a new witness method instruction if it exactly the same as the old one: doing so might cause the transformation to go into an infinite loop: The new method instruction will be added to the Builder’s tracker list. SILCombine, in turn, uses the tracker list to populate the worklist. As such, if we don’t remove the witness method later on in the pass, we are stuck: We will re-create the same instruction and re-populate the worklist with it. This SILCombiner bug was always there, we just never hit it before because we always removed the witness method instruction later on in the transformation (creating the new apply / making the witness instruction dead). Since we now bail on creating new apply instructions, which is the right thing to do as seen in rdar://problem/34753633, it got exposed.
• Origination: This was discovered while debugging rdar://problem/34966696 Swift CI: 2. Swift Source Compatibility Suite (master)
• Risk: Low - The bug fix is a very simple if statement: if we are trying to replace a witness method instruction with itself (exact same conformance and lookup type) bail. Don’t do so. There’s no point in creating the exact same instruction, replacing all uses with the new one, and deleting the old one. The old one should do the job. That way we are not adding a new instruction to the builder’s tracker list.
• Reviewed By: @eeckstein