-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[sil-combine] Fix a bug in the convert_function peephole #12162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -417,6 +417,12 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI, | |
if (SubstCalleeTy->hasArchetype() || ConvertCalleeTy->hasArchetype()) | ||
return nullptr; | ||
|
||
// Bail if the result type of the converted callee is different from the callee's | ||
// result type of the apply instruction. | ||
if (SubstCalleeTy->getAllResultsType() != ConvertCalleeTy->getAllResultsType()) { | ||
return nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When parameter types don't match you emit an unchecked ref cast, you could do the same for the return value too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may result in introducing new BBs for the try_apply. And we don't want to generate new BBs in sil-combine. |
||
} | ||
|
||
// Ok, we can now perform our transformation. Grab AI's operands and the | ||
// relevant types from the ConvertFunction function type and AI. | ||
Builder.setCurrentDebugScope(AI.getDebugScope()); | ||
|
@@ -461,9 +467,13 @@ SILCombiner::optimizeApplyOfConvertFunctionInst(FullApplySite AI, | |
NAI = Builder.createTryApply(AI.getLoc(), FRI, | ||
SubstitutionList(), Args, | ||
TAI->getNormalBB(), TAI->getErrorBB()); | ||
else | ||
else { | ||
NAI = Builder.createApply(AI.getLoc(), FRI, SubstitutionList(), Args, | ||
cast<ApplyInst>(AI)->isNonThrowing()); | ||
assert(FullApplySite::isa(NAI).getSubstCalleeType()->getAllResultsType() == | ||
AI.getSubstCalleeType()->getAllResultsType() && | ||
"Function types should be the same"); | ||
} | ||
return NAI; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this restriction is completely unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be, but this is not the part of this bug-fix patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try removing it in another patch and see what breaks :-)