Skip to content

[silgenpattern] When emitting a switch_enum with ownership, pass in t… #15284

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/SILGen/SILGenPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ class PatternMatchEmission {
const FailureHandler &failure);
void emitEnumElementDispatchWithOwnership(
ArrayRef<RowToSpecialize> rows, ConsumableManagedValue src,
const SpecializationHandler &handleSpec, const FailureHandler &failure);
const SpecializationHandler &handleSpec, const FailureHandler &failure,
ProfileCounter defaultCaseCount);
void emitEnumElementDispatch(ArrayRef<RowToSpecialize> rows,
ConsumableManagedValue src,
const SpecializationHandler &handleSpec,
Expand Down Expand Up @@ -1795,8 +1796,8 @@ static void generateEnumCaseBlocks(
/// OptionalSomePattern.
void PatternMatchEmission::emitEnumElementDispatchWithOwnership(
ArrayRef<RowToSpecialize> rows, ConsumableManagedValue src,
const SpecializationHandler &handleCase,
const FailureHandler &outerFailure) {
const SpecializationHandler &handleCase, const FailureHandler &outerFailure,
ProfileCounter defaultCastCount) {
assert(src.getFinalConsumption() != CastConsumptionKind::TakeOnSuccess &&
"SIL ownership does not support TakeOnSuccess");

Expand All @@ -1821,7 +1822,9 @@ void PatternMatchEmission::emitEnumElementDispatchWithOwnership(
SILValue srcValue = src.getFinalManagedValue().copy(SGF, loc).forward(SGF);
// FIXME: Pass caseCounts in here as well, as it is in
// emitEnumElementDispatch.
SGF.B.createSwitchEnum(loc, srcValue, defaultBB, caseBBs);
ArrayRef<ProfileCounter> caseCountsArrayRef = caseCounts;
SGF.B.createSwitchEnum(loc, srcValue, defaultBB, caseBBs, caseCountsArrayRef,
defaultCastCount);

// Okay, now emit all the cases.
for (unsigned i = 0, e = caseInfos.size(); i != e; ++i) {
Expand Down Expand Up @@ -1940,7 +1943,7 @@ void PatternMatchEmission::emitEnumElementDispatch(
// use the dispatch code path.
if (SGF.getOptions().EnableSILOwnership && src.getType().isObject()) {
return emitEnumElementDispatchWithOwnership(rows, src, handleCase,
outerFailure);
outerFailure, defaultCaseCount);
}

CanType sourceType = rows[0].Pattern->getType()->getCanonicalType();
Expand Down