Skip to content

Commit bcb18ea

Browse files
authored
Merge pull request swiftlang#29606 from gottesmm/pr-9f47b4f61d7482fa90b57ac220aa75baadd14cfc
[ownership] Trivial/Any have both been merged in ValueOwnershipKind::None for a long time so these code paths are unnecessary.
2 parents 7148108 + 1ed9f7f commit bcb18ea

File tree

1 file changed

+10
-63
lines changed

1 file changed

+10
-63
lines changed

lib/SIL/OperandOwnership.cpp

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ class OperandOwnershipKindClassifier
8787
return visitForwardingInst(i, i->getAllOperands());
8888
}
8989

90-
OperandOwnershipKindMap
91-
visitEnumArgument(ValueOwnershipKind requiredConvention);
9290
OperandOwnershipKindMap
9391
visitApplyParameter(ValueOwnershipKind requiredConvention,
9492
UseLifetimeConstraint requirement);
@@ -409,17 +407,9 @@ OperandOwnershipKindClassifier::checkTerminatorArgumentMatchesDestBB(
409407
// Grab the ownership kind of the destination block.
410408
ValueOwnershipKind destBlockArgOwnershipKind =
411409
destBB->getArgument(opIndex)->getOwnershipKind();
412-
413-
// Then if we do not have an enum, make sure that the conventions match.
414-
if (!getType().getEnumOrBoundGenericEnum()) {
415-
auto lifetimeConstraint =
416-
destBlockArgOwnershipKind.getForwardingLifetimeConstraint();
417-
return Map::compatibilityMap(destBlockArgOwnershipKind, lifetimeConstraint);
418-
}
419-
420-
// Otherwise, we need to properly handle the sum type nature of enum
421-
// arguments.
422-
return visitEnumArgument(destBlockArgOwnershipKind);
410+
auto lifetimeConstraint =
411+
destBlockArgOwnershipKind.getForwardingLifetimeConstraint();
412+
return Map::compatibilityMap(destBlockArgOwnershipKind, lifetimeConstraint);
423413
}
424414

425415
OperandOwnershipKindMap
@@ -548,12 +538,6 @@ OperandOwnershipKindClassifier::visitReturnInst(ReturnInst *ri) {
548538
return Map();
549539

550540
auto base = *mergedBase;
551-
552-
// TODO: This may not be needed once trivial is any.
553-
if (getType().getEnumOrBoundGenericEnum()) {
554-
return visitEnumArgument(base);
555-
}
556-
557541
return Map::compatibilityMap(base, base.getForwardingLifetimeConstraint());
558542
}
559543

@@ -641,57 +625,20 @@ OperandOwnershipKindMap OperandOwnershipKindClassifier::visitCallee(
641625
llvm_unreachable("Unhandled ParameterConvention in switch.");
642626
}
643627

644-
// Visit an enum value that is passed at argument position, including block
645-
// arguments, apply arguments, and return values.
646-
//
647-
// The operand definition's ownership kind may be known to be "trivial",
648-
// but it is still valid to pass that enum to a argument nontrivial type.
649-
// For example:
650-
//
651-
// %val = enum $Optional<SomeClass>, #Optional.none // trivial ownership
652-
// apply %f(%val) : (@owned Optional<SomeClass>) // owned argument
653-
OperandOwnershipKindMap OperandOwnershipKindClassifier::visitEnumArgument(
654-
ValueOwnershipKind requiredKind) {
655-
// Begin with an empty map.
656-
OperandOwnershipKindMap map;
657-
658-
// The operand has a non-trivial ownership kind. It must match the argument
659-
// convention.
660-
if (requiredKind != ValueOwnershipKind::Owned) {
661-
map.addCompatibilityConstraint(ValueOwnershipKind::Owned,
662-
UseLifetimeConstraint::MustBeLive);
663-
} else {
664-
map.addCompatibilityConstraint(ValueOwnershipKind::Owned,
665-
UseLifetimeConstraint::MustBeInvalidated);
666-
}
667-
map.addCompatibilityConstraint(ValueOwnershipKind::Guaranteed,
668-
UseLifetimeConstraint::MustBeLive);
669-
map.addCompatibilityConstraint(ValueOwnershipKind::Unowned,
670-
UseLifetimeConstraint::MustBeLive);
671-
return map;
672-
}
673-
674628
// We allow for trivial cases of enums with non-trivial cases to be passed in
675629
// non-trivial argument positions. This fits with modeling of a
676630
// SILFunctionArgument as a phi in a global program graph.
677631
OperandOwnershipKindMap OperandOwnershipKindClassifier::visitApplyParameter(
678632
ValueOwnershipKind kind, UseLifetimeConstraint requirement) {
679633

680-
// Check if we have an enum. If not, then we just check against the passed in
681-
// convention.
682-
if (!getType().getEnumOrBoundGenericEnum()) {
683-
// We allow for owned to be passed to apply parameters.
684-
if (kind != ValueOwnershipKind::Owned) {
685-
return Map::compatibilityMap(
686-
{{kind, requirement},
687-
{ValueOwnershipKind::Owned, UseLifetimeConstraint::MustBeLive}});
688-
}
689-
return Map::compatibilityMap(kind, requirement);
634+
// Check against the passed in convention. We allow for owned to be passed to
635+
// apply parameters.
636+
if (kind != ValueOwnershipKind::Owned) {
637+
return Map::compatibilityMap(
638+
{{kind, requirement},
639+
{ValueOwnershipKind::Owned, UseLifetimeConstraint::MustBeLive}});
690640
}
691-
692-
// Otherwise consider that we may have a payload with a trivial case
693-
// that has other non-trivial cases.
694-
return visitEnumArgument(kind);
641+
return Map::compatibilityMap(kind, requirement);
695642
}
696643

697644
// Handle Apply and TryApply.

0 commit comments

Comments
 (0)