@@ -1868,37 +1868,44 @@ void PatternMatchEmission::emitEnumElementObjectDispatch(
1868
1868
// instruction to receive the enum case data if it has any.
1869
1869
1870
1870
SILType eltTy;
1871
- bool hasElt = false ;
1872
- if (elt->hasAssociatedValues ()) {
1871
+ bool hasNonVoidAssocValue = false ;
1872
+ bool hasAssocValue = elt->hasAssociatedValues ();
1873
+ if (hasAssocValue) {
1873
1874
eltTy = src.getType ().getEnumElementType (elt, SGF.SGM .M );
1874
- hasElt = !eltTy.getASTType ()->isVoid ();
1875
+ hasNonVoidAssocValue = !eltTy.getASTType ()->isVoid ();
1875
1876
}
1876
1877
1877
1878
ConsumableManagedValue eltCMV, origCMV;
1878
1879
1879
- // Empty cases. Try to avoid making an empty tuple value if it's
1880
- // obviously going to be ignored. This assumes that we won't even
1881
- // try to touch the value in such cases, although we may touch the
1882
- // cleanup (enough to see that it's not present).
1883
- if (!hasElt) {
1884
- bool hasNonAny = false ;
1885
- for (auto &specRow : specializedRows) {
1886
- auto pattern = specRow.Patterns [0 ];
1887
- if (pattern &&
1888
- !isa<AnyPattern>(pattern->getSemanticsProvidingPattern ())) {
1889
- hasNonAny = true ;
1890
- break ;
1880
+ // Void (i.e. empty) cases.
1881
+ //
1882
+ if (!hasNonVoidAssocValue) {
1883
+ // Inline constructor.
1884
+ eltCMV = [&]() -> ConsumableManagedValue {
1885
+ // If we have an associated value, rather than no payload at all, we
1886
+ // still need to create the argument. So do that instead of creating the
1887
+ // empty-tuple. Otherwise, we need to create undef or the empty-tuple.
1888
+ if (hasAssocValue) {
1889
+ return {SGF.B .createOwnedPhiArgument (eltTy),
1890
+ CastConsumptionKind::TakeAlways};
1891
1891
}
1892
- }
1893
1892
1894
- SILValue result;
1895
- if (hasNonAny) {
1896
- result = SGF.emitEmptyTuple (loc);
1897
- } else {
1898
- result = SILUndef::get (SGF.SGM .Types .getEmptyTupleType (), SGF.F );
1899
- }
1900
- origCMV = ConsumableManagedValue::forUnmanaged (result);
1901
- eltCMV = origCMV;
1893
+ // Otherwise, try to avoid making an empty tuple value if it's obviously
1894
+ // going to be ignored. This assumes that we won't even try to touch the
1895
+ // value in such cases, although we may touch the cleanup (enough to see
1896
+ // that it's not present).
1897
+ bool hasNonAny =
1898
+ llvm::any_of (specializedRows, [&](const SpecializedRow &row) {
1899
+ auto *p = row.Patterns [0 ];
1900
+ return p && !isa<AnyPattern>(p->getSemanticsProvidingPattern ());
1901
+ });
1902
+ if (hasNonAny) {
1903
+ return ConsumableManagedValue::forUnmanaged (SGF.emitEmptyTuple (loc));
1904
+ }
1905
+
1906
+ return ConsumableManagedValue::forUnmanaged (
1907
+ SILUndef::get (SGF.SGM .Types .getEmptyTupleType (), SGF.F ));
1908
+ }();
1902
1909
1903
1910
// Okay, specialize on the argument.
1904
1911
} else {
0 commit comments