Skip to content

Commit 3b202c1

Browse files
committed
Use 'hasAssociatedValues'
Use 'hasAssociatedValues' instead of computing and discarding the interface type of an enum element decl. This change has specifically not been made in conditions that use the presence or absence of the interface type, only conditions that depend on the presence or absence of associated values in the enum element decl.
1 parent e92805f commit 3b202c1

20 files changed

+38
-39
lines changed

Diff for: lib/IRGen/GenType.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ namespace {
13721372
return false;
13731373

13741374
for (auto elt : decl->getAllElements()) {
1375-
if (elt->getArgumentInterfaceType() &&
1375+
if (elt->hasAssociatedValues() &&
13761376
!elt->isIndirect() &&
13771377
visit(elt->getArgumentInterfaceType()->getCanonicalType()))
13781378
return true;
@@ -1773,7 +1773,7 @@ SILType irgen::getSingletonAggregateFieldType(IRGenModule &IGM, SILType t,
17731773

17741774
auto theCase = allCases.begin();
17751775
if (!allCases.empty() && std::next(theCase) == allCases.end()
1776-
&& (*theCase)->getArgumentInterfaceType())
1776+
&& (*theCase)->hasAssociatedValues())
17771777
return t.getEnumElementType(*theCase, IGM.getSILModule());
17781778

17791779
return SILType();

Diff for: lib/SIL/AbstractionPattern.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ AbstractionPattern TypeConverter::getAbstractionPattern(VarDecl *var) {
9191
}
9292

9393
AbstractionPattern TypeConverter::getAbstractionPattern(EnumElementDecl *decl) {
94-
assert(decl->getArgumentInterfaceType());
94+
assert(decl->hasAssociatedValues());
9595
assert(!decl->hasClangNode());
9696

9797
// This cannot be implemented correctly for Optional.Some.

Diff for: lib/SIL/SILDeclRef.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ unsigned swift::getNaturalUncurryLevel(ValueDecl *vd) {
236236
} else if (isa<ConstructorDecl>(vd)) {
237237
return 1;
238238
} else if (auto *ed = dyn_cast<EnumElementDecl>(vd)) {
239-
return ed->getArgumentInterfaceType() ? 1 : 0;
239+
return ed->hasAssociatedValues() ? 1 : 0;
240240
} else if (isa<DestructorDecl>(vd)) {
241241
return 0;
242242
} else if (isa<ClassDecl>(vd)) {

Diff for: lib/SIL/SILOwnershipVerifier.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ OwnershipUseCheckerResult OwnershipCompatibilityUseChecker::visitNonTrivialEnum(
846846
// Check if this enum has at least one case that is non-trivially typed.
847847
bool HasNonTrivialCase =
848848
llvm::any_of(E->getAllElements(), [this](EnumElementDecl *E) -> bool {
849-
if (!E->getArgumentInterfaceType())
849+
if (!E->hasAssociatedValues())
850850
return false;
851851
SILType EnumEltType = getType().getEnumElementType(E, Mod);
852852
return !EnumEltType.isTrivial(Mod);

Diff for: lib/SIL/SILType.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static bool canUnsafeCastEnum(SILType fromType, EnumDecl *fromEnum,
185185
if (EnumDecl *toEnum = toType.getEnumOrBoundGenericEnum()) {
186186
for (auto toElement : toEnum->getAllElements()) {
187187
++numToElements;
188-
if (!toElement->getArgumentInterfaceType())
188+
if (!toElement->hasAssociatedValues())
189189
continue;
190190
// Bail on multiple payloads.
191191
if (!toElementTy.isNull())
@@ -209,7 +209,7 @@ static bool canUnsafeCastEnum(SILType fromType, EnumDecl *fromEnum,
209209
// If any of the fromElements can be cast by value to the singleton toElement,
210210
// then the overall enum can be cast by value.
211211
for (auto fromElement : fromElements) {
212-
if (!fromElement->getArgumentInterfaceType())
212+
if (!fromElement->hasAssociatedValues())
213213
continue;
214214

215215
auto fromElementTy = fromType.getEnumElementType(fromElement, M);
@@ -317,7 +317,7 @@ SILType SILType::getFieldType(VarDecl *field, SILModule &M) const {
317317

318318
SILType SILType::getEnumElementType(EnumElementDecl *elt, SILModule &M) const {
319319
assert(elt->getDeclContext() == getEnumOrBoundGenericEnum());
320-
assert(elt->getArgumentInterfaceType());
320+
assert(elt->hasAssociatedValues());
321321

322322
if (auto objectType = getSwiftRValueType().getAnyOptionalObjectType()) {
323323
assert(elt == M.getASTContext().getOptionalSomeDecl());
@@ -413,7 +413,7 @@ bool SILType::aggregateContainsRecord(SILType Record, SILModule &Mod) const {
413413
// Then if we have an enum...
414414
if (EnumDecl *E = Ty.getEnumOrBoundGenericEnum()) {
415415
for (auto Elt : E->getAllElements())
416-
if (Elt->getArgumentInterfaceType())
416+
if (Elt->hasAssociatedValues())
417417
Worklist.push_back(Ty.getEnumElementType(Elt, Mod));
418418
continue;
419419
}

Diff for: lib/SIL/SILVerifier.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1695,10 +1695,10 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
16951695
"EnumInst case must be a case of the result enum type");
16961696
require(UI->getType().isObject(),
16971697
"EnumInst must produce an object");
1698-
require(UI->hasOperand() == !!UI->getElement()->getArgumentInterfaceType(),
1698+
require(UI->hasOperand() == UI->getElement()->hasAssociatedValues(),
16991699
"EnumInst must take an argument iff the element does");
17001700

1701-
if (UI->getElement()->getArgumentInterfaceType()) {
1701+
if (UI->getElement()->hasAssociatedValues()) {
17021702
require(UI->getOperand()->getType().isObject(),
17031703
"EnumInst operand must be an object");
17041704
SILType caseTy = UI->getType().getEnumElementType(UI->getElement(),
@@ -1713,7 +1713,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
17131713
require(ud, "InitEnumDataAddrInst must take an enum operand");
17141714
require(UI->getElement()->getParentEnum() == ud,
17151715
"InitEnumDataAddrInst case must be a case of the enum operand type");
1716-
require(UI->getElement()->getArgumentInterfaceType(),
1716+
require(UI->getElement()->hasAssociatedValues(),
17171717
"InitEnumDataAddrInst case must have a data type");
17181718
require(UI->getOperand()->getType().isAddress(),
17191719
"InitEnumDataAddrInst must take an address operand");
@@ -3431,7 +3431,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
34313431

34323432
// The destination BB can take the argument payload, if any, as a BB
34333433
// arguments, or it can ignore it and take no arguments.
3434-
if (elt->getArgumentInterfaceType()) {
3434+
if (elt->hasAssociatedValues()) {
34353435
if (isSILOwnershipEnabled() && F.hasQualifiedOwnership()) {
34363436
require(dest->getArguments().size() == 1,
34373437
"switch_enum destination for case w/ args must take 1 "

Diff for: lib/SIL/TypeLowering.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ namespace {
13161316
bool trivial = true;
13171317
for (auto elt : D->getAllElements()) {
13181318
// No-payload elements do not affect address-only-ness.
1319-
if (!elt->getArgumentInterfaceType())
1319+
if (!elt->hasAssociatedValues())
13201320
continue;
13211321

13221322
// Indirect elements make the type nontrivial, but don't affect

Diff for: lib/SILGen/SILGenApply.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4366,7 +4366,7 @@ RValue CallEmission::applyEnumElementConstructor(
43664366

43674367
// Get the payload argument.
43684368
ArgumentSource payload;
4369-
if (element->getArgumentInterfaceType()) {
4369+
if (element->hasAssociatedValues()) {
43704370
assert(uncurriedSites.size() == 2);
43714371
formalResultType = formalType.getResult();
43724372
claimNextParamClause(origFormalType.getValue());

Diff for: lib/SILGen/SILGenBuilder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ void SwitchEnumBuilder::emit() && {
708708
builder.emitBlock(caseBlock);
709709

710710
ManagedValue input;
711-
if (decl->getArgumentInterfaceType()) {
711+
if (decl->hasAssociatedValues()) {
712712
// Pull the payload out if we have one.
713713
SILType inputType =
714714
optional.getType().getEnumElementType(decl, builder.getModule());

Diff for: lib/SILGen/SILGenConstructor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ void SILGenFunction::emitEnumConstructor(EnumElementDecl *element) {
385385

386386
// Emit the exploded constructor argument.
387387
ArgumentSource payload;
388-
if (element->getArgumentInterfaceType()) {
388+
if (element->hasAssociatedValues()) {
389389
RValue arg = emitImplicitValueConstructorArg
390390
(*this, Loc, element->getArgumentInterfaceType()->getCanonicalType(),
391391
element->getDeclContext());

Diff for: lib/SILGen/SILGenDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ void EnumElementPatternInitialization::emitEnumMatch(
792792
[&SGF, &loc, &eltDecl, &subInit, &value](ManagedValue mv,
793793
SwitchCaseFullExpr &expr) {
794794
// If the enum case has no bound value, we're done.
795-
if (!eltDecl->getArgumentInterfaceType()) {
795+
if (!eltDecl->hasAssociatedValues()) {
796796
assert(
797797
subInit == nullptr &&
798798
"Cannot have a subinit when there is no value to match against");

Diff for: lib/SILGen/SILGenPattern.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ void PatternMatchEmission::emitEnumElementDispatchWithOwnership(
17671767

17681768
SILType eltTy;
17691769
bool hasElt = false;
1770-
if (elt->getArgumentInterfaceType()) {
1770+
if (elt->hasAssociatedValues()) {
17711771
eltTy = src.getType().getEnumElementType(elt, SGF.SGM.M);
17721772
hasElt = !eltTy.getSwiftRValueType()->isVoid();
17731773
}
@@ -2025,7 +2025,7 @@ void PatternMatchEmission::emitEnumElementDispatch(
20252025

20262026
SILType eltTy;
20272027
bool hasElt = false;
2028-
if (elt->getArgumentInterfaceType()) {
2028+
if (elt->hasAssociatedValues()) {
20292029
eltTy = src.getType().getEnumElementType(elt, SGF.SGM.M);
20302030
hasElt = !eltTy.getSwiftRValueType()->isVoid();
20312031
}

Diff for: lib/SILOptimizer/Analysis/EscapeAnalysis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ static bool isOrContainsReference(SILType Ty, SILModule *Mod) {
10231023
}
10241024
if (auto En = Ty.getEnumOrBoundGenericEnum()) {
10251025
for (auto *ElemDecl : En->getAllElements()) {
1026-
if (ElemDecl->getArgumentInterfaceType() &&
1026+
if (ElemDecl->hasAssociatedValues() &&
10271027
isOrContainsReference(Ty.getEnumElementType(ElemDecl, *Mod), Mod))
10281028
return true;
10291029
}

Diff for: lib/SILOptimizer/Analysis/RCIdentityAnalysis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static llvm::Optional<bool> proveNonPayloadedEnumCase(SILBasicBlock *BB,
182182
NullablePtr<EnumElementDecl> Decl = SEI->getUniqueCaseForDestination(BB);
183183
if (Decl.isNull())
184184
return None;
185-
return !Decl.get()->getArgumentInterfaceType();
185+
return !Decl.get()->hasAssociatedValues();
186186
}
187187

188188
bool RCIdentityFunctionInfo::

Diff for: lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ SILCombiner::visitInjectEnumAddrInst(InjectEnumAddrInst *IEAI) {
848848

849849
// If the enum does not have a payload create the enum/store since we don't
850850
// need to worry about payloads.
851-
if (!IEAI->getElement()->getArgumentInterfaceType()) {
851+
if (!IEAI->getElement()->hasAssociatedValues()) {
852852
EnumInst *E =
853853
Builder.createEnum(IEAI->getLoc(), SILValue(), IEAI->getElement(),
854854
IEAI->getOperand()->getType().getObjectType());

Diff for: lib/SILOptimizer/Transforms/SILCodeMotion.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace {
4949
static void createRefCountOpForPayload(SILBuilder &Builder, SILInstruction *I,
5050
EnumElementDecl *EnumDecl,
5151
SILValue DefOfEnum = SILValue()) {
52-
assert(EnumDecl->getArgumentInterfaceType() &&
52+
assert(EnumDecl->hasAssociatedValues() &&
5353
"We assume enumdecl has an argument type");
5454

5555
SILModule &Mod = I->getModule();
@@ -755,7 +755,7 @@ static bool tryToSinkRefCountAcrossSwitch(SwitchEnumInst *Switch,
755755
EnumElementDecl *Enum = Case.first;
756756
SILBasicBlock *Succ = Case.second;
757757
Builder.setInsertionPoint(&*Succ->begin());
758-
if (Enum->getArgumentInterfaceType())
758+
if (Enum->hasAssociatedValues())
759759
createRefCountOpForPayload(Builder, &*RV, Enum, Switch->getOperand());
760760
}
761761

@@ -841,7 +841,7 @@ static bool tryToSinkRefCountAcrossSelectEnum(CondBranchInst *CondBr,
841841
EnumElementDecl *Enum = Elts[i];
842842
SILBasicBlock *Succ = i == 0 ? CondBr->getTrueBB() : CondBr->getFalseBB();
843843
Builder.setInsertionPoint(&*Succ->begin());
844-
if (Enum->getArgumentInterfaceType())
844+
if (Enum->hasAssociatedValues())
845845
createRefCountOpForPayload(Builder, &*I, Enum, SEI->getEnumOperand());
846846
}
847847

@@ -1304,7 +1304,7 @@ bool BBEnumTagDataflowState::visitRetainValueInst(RetainValueInst *RVI) {
13041304
return false;
13051305

13061306
// If we do not have any argument, kill the retain_value.
1307-
if (!(*FindResult)->second->getArgumentInterfaceType()) {
1307+
if (!(*FindResult)->second->hasAssociatedValues()) {
13081308
RVI->eraseFromParent();
13091309
return true;
13101310
}
@@ -1324,7 +1324,7 @@ bool BBEnumTagDataflowState::visitReleaseValueInst(ReleaseValueInst *RVI) {
13241324
return false;
13251325

13261326
// If we do not have any argument, just delete the release value.
1327-
if (!(*FindResult)->second->getArgumentInterfaceType()) {
1327+
if (!(*FindResult)->second->hasAssociatedValues()) {
13281328
RVI->eraseFromParent();
13291329
return true;
13301330
}
@@ -1415,7 +1415,7 @@ BBEnumTagDataflowState::hoistDecrementsIntoSwitchRegions(AliasAnalysis *AA) {
14151415
for (auto P : EnumBBCaseList) {
14161416
// If we don't have an argument for this case, there is nothing to
14171417
// do... continue...
1418-
if (!P.second->getArgumentInterfaceType())
1418+
if (!P.second->hasAssociatedValues())
14191419
continue;
14201420

14211421
// Otherwise create the release_value before the terminator of the
@@ -1480,7 +1480,7 @@ findRetainsSinkableFromSwitchRegionForEnum(
14801480

14811481
// If the case does not have an argument type, skip the predecessor since
14821482
// there will not be a retain to sink.
1483-
if (!Decl->getArgumentInterfaceType())
1483+
if (!Decl->hasAssociatedValues())
14841484
continue;
14851485

14861486
// Ok, we found a payloaded predecessor. Look backwards through the

Diff for: lib/SILOptimizer/Transforms/SimplifyCFG.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static SILInstruction *createEnumElement(SILBuilder &Builder,
397397
auto EnumVal = SEI->getOperand();
398398
// Do we have a payload.
399399
auto EnumTy = EnumVal->getType();
400-
if (EnumElement->getArgumentInterfaceType()) {
400+
if (EnumElement->hasAssociatedValues()) {
401401
auto Ty = EnumTy.getEnumElementType(EnumElement, SEI->getModule());
402402
SILValue UED(Builder.createUncheckedEnumData(SEI->getLoc(), EnumVal,
403403
EnumElement, Ty));
@@ -1628,7 +1628,7 @@ bool SimplifyCFG::simplifySwitchEnumUnreachableBlocks(SwitchEnumInst *SEI) {
16281628
return true;
16291629
}
16301630

1631-
if (!Element || !Element->getArgumentInterfaceType() || Dest->args_empty()) {
1631+
if (!Element || !Element->hasAssociatedValues() || Dest->args_empty()) {
16321632
assert(Dest->args_empty() && "Unexpected argument at destination!");
16331633

16341634
SILBuilderWithScope(SEI).createBranch(SEI->getLoc(), Dest);

Diff for: lib/Sema/CSRanking.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ static bool isDeclAsSpecializedAs(TypeChecker &tc, DeclContext *dc,
548548
if (isa<AbstractFunctionDecl>(decl1) || isa<EnumElementDecl>(decl1)) {
549549
// Nothing to do: these have the curried 'self' already.
550550
if (auto elt = dyn_cast<EnumElementDecl>(decl1)) {
551-
checkKind = elt->getArgumentInterfaceType() ? CheckInput : CheckAll;
551+
checkKind = elt->hasAssociatedValues() ? CheckInput : CheckAll;
552552
} else {
553553
checkKind = CheckInput;
554554
}

Diff for: lib/Sema/TypeCheckDecl.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -3071,7 +3071,7 @@ static void checkEnumRawValues(TypeChecker &TC, EnumDecl *ED) {
30713071
continue;
30723072

30733073
// We don't yet support raw values on payload cases.
3074-
if (elt->getArgumentInterfaceType()) {
3074+
if (elt->hasAssociatedValues()) {
30753075
TC.diagnose(elt->getLoc(),
30763076
diag::enum_with_raw_type_case_with_argument);
30773077
TC.diagnose(ED->getInherited().front().getSourceRange().Start,
@@ -6570,10 +6570,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
65706570
return;
65716571

65726572
// Require the carried type to be materializable.
6573-
if (EED->getArgumentInterfaceType() &&
6574-
!EED->getArgumentInterfaceType()->isMaterializable()) {
6575-
TC.diagnose(EED->getLoc(), diag::enum_element_not_materializable,
6576-
EED->getArgumentInterfaceType());
6573+
auto IFacTy = EED->getArgumentInterfaceType();
6574+
if (IFacTy && !IFacTy->isMaterializable()) {
6575+
TC.diagnose(EED->getLoc(), diag::enum_element_not_materializable, IFacTy);
65776576
EED->setInterfaceType(ErrorType::get(TC.Context));
65786577
EED->setInvalid();
65796578
}

Diff for: lib/Serialization/Serialization.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2958,7 +2958,7 @@ void Serializer::writeDecl(const Decl *D) {
29582958
addIdentifierRef(elem->getName()),
29592959
contextID,
29602960
addTypeRef(elem->getInterfaceType()),
2961-
!!elem->getArgumentInterfaceType(),
2961+
elem->hasAssociatedValues(),
29622962
elem->isImplicit(),
29632963
(unsigned)RawValueKind,
29642964
Negative,

0 commit comments

Comments
 (0)