Skip to content

Commit 9b858a7

Browse files
committed
SIL: Remove the ElementType from DeallocBoxInst's representation.
This was made redundant by typed boxes, and the type operand was already removed from textual SIL, but the field was never removed from the instruction's in memory representation. It becomes wrong in the face of compound boxes with layout.
1 parent 68b2cb7 commit 9b858a7

File tree

9 files changed

+20
-37
lines changed

9 files changed

+20
-37
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,16 +1239,10 @@ class SILBuilder {
12391239
return insert(new (F.getModule()) DeallocPartialRefInst(
12401240
getSILDebugLocation(Loc), operand, metatype));
12411241
}
1242-
DeallocBoxInst *createDeallocBox(SILLocation Loc, SILType eltType,
1242+
DeallocBoxInst *createDeallocBox(SILLocation Loc,
12431243
SILValue operand) {
12441244
return insert(new (F.getModule()) DeallocBoxInst(
1245-
getSILDebugLocation(Loc), eltType, operand));
1246-
}
1247-
DeallocBoxInst *createDeallocBox(SILLocation Loc, SILValue operand) {
1248-
auto eltType =
1249-
operand->getType().castTo<SILBoxType>()->getBoxedAddressType();
1250-
return insert(new (F.getModule()) DeallocBoxInst(
1251-
getSILDebugLocation(Loc), eltType, operand));
1245+
getSILDebugLocation(Loc), operand));
12521246
}
12531247
DeallocExistentialBoxInst *createDeallocExistentialBox(SILLocation Loc,
12541248
CanType concreteType,

include/swift/SIL/SILCloner.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,6 @@ SILCloner<ImplClass>::visitDeallocBoxInst(DeallocBoxInst *Inst) {
17001700
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
17011701
doPostProcess(Inst,
17021702
getBuilder().createDeallocBox(getOpLocation(Inst->getLoc()),
1703-
getOpType(Inst->getElementType()),
17041703
getOpValue(Inst->getOperand())));
17051704
}
17061705

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4337,15 +4337,8 @@ class DeallocBoxInst :
43374337
{
43384338
friend SILBuilder;
43394339

4340-
// TODO: The element type can be derived from a typed box.
4341-
SILType ElementType;
4342-
4343-
DeallocBoxInst(SILDebugLocation DebugLoc, SILType elementType,
4344-
SILValue operand)
4345-
: UnaryInstructionBase(DebugLoc, operand), ElementType(elementType) {}
4346-
4347-
public:
4348-
SILType getElementType() const { return ElementType; }
4340+
DeallocBoxInst(SILDebugLocation DebugLoc, SILValue operand)
4341+
: UnaryInstructionBase(DebugLoc, operand) {}
43494342
};
43504343

43514344
/// Deallocate memory allocated for a boxed existential container created by

lib/Parse/ParseSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2690,7 +2690,7 @@ bool SILParser::parseSILInstruction(SILBasicBlock *BB, SILBuilder &B) {
26902690
ResultVal = B.createExistentialMetatype(InstLoc, Ty, Val);
26912691
break;
26922692
case ValueKind::DeallocBoxInst:
2693-
ResultVal = B.createDeallocBox(InstLoc, Ty, Val);
2693+
ResultVal = B.createDeallocBox(InstLoc, Val);
26942694
break;
26952695
}
26962696
break;

lib/SIL/SILVerifier.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,10 +1409,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
14091409
void checkProjectBoxInst(ProjectBoxInst *I) {
14101410
require(I->getOperand()->getType().isObject(),
14111411
"project_box operand should be a value");
1412-
require(I->getOperand()->getType().is<SILBoxType>(),
1413-
"project_box operand should be a @box type");
1414-
require(I->getType() == I->getOperand()->getType().castTo<SILBoxType>()
1415-
->getBoxedAddressType(),
1412+
auto boxTy = I->getOperand()->getType().getAs<SILBoxType>();
1413+
require(boxTy, "project_box operand should be a @box type");
1414+
require(I->getType() == boxTy->getFieldType(I->getFieldIndex()),
14161415
"project_box result should be address of boxed type");
14171416
}
14181417

@@ -1724,8 +1723,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
17241723
}
17251724

17261725
void checkAllocBoxInst(AllocBoxInst *AI) {
1727-
// TODO: Allow the box to be typed, but for staging purposes, only require
1728-
// it when -sil-enable-typed-boxes is enabled.
17291726
auto boxTy = AI->getType().getAs<SILBoxType>();
17301727
require(boxTy, "alloc_box must have a @box type");
17311728

@@ -1735,15 +1732,10 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
17351732
}
17361733

17371734
void checkDeallocBoxInst(DeallocBoxInst *DI) {
1738-
// TODO: Allow the box to be typed, but for staging purposes, only require
1739-
// it when -sil-enable-typed-boxes is enabled.
17401735
auto boxTy = DI->getOperand()->getType().getAs<SILBoxType>();
17411736
require(boxTy, "operand must be a @box type");
17421737
require(DI->getOperand()->getType().isObject(),
17431738
"operand must be an object");
1744-
requireSameType(boxTy->getBoxedAddressType().getObjectType(),
1745-
DI->getElementType().getObjectType(),
1746-
"element type of dealloc_box must match box element type");
17471739
}
17481740

17491741
void checkDestroyAddrInst(DestroyAddrInst *DI) {

lib/SILGen/SILGenDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,8 +1332,7 @@ void SILGenFunction::deallocateUninitializedLocalVariable(SILLocation silLoc,
13321332
if (!loc.value->getType().isAddress()) return;
13331333

13341334
assert(loc.box && "captured var should have been given a box");
1335-
B.createDeallocBox(silLoc, loc.value->getType().getObjectType(),
1336-
loc.box);
1335+
B.createDeallocBox(silLoc, loc.box);
13371336
}
13381337

13391338
namespace {

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,9 +1809,7 @@ void LifetimeChecker::processUninitializedRelease(SILInstruction *Release,
18091809

18101810
// dealloc_box the self box if necessary.
18111811
if (ABI) {
1812-
auto DB = B.createDeallocBox(Loc,
1813-
ABI->getElementType(),
1814-
ABI);
1812+
auto DB = B.createDeallocBox(Loc, ABI);
18151813
Releases.push_back(DB);
18161814
}
18171815
}

lib/Serialization/DeserializeSIL.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,14 +804,22 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
804804
getSILType(MF->getType(TyID2), \
805805
(SILValueCategory)TyCategory2))); \
806806
break;
807-
ONETYPE_ONEOPERAND_INST(DeallocBox)
808807
ONETYPE_ONEOPERAND_INST(ValueMetatype)
809808
ONETYPE_ONEOPERAND_INST(ExistentialMetatype)
810809
ONETYPE_ONEOPERAND_INST(AllocValueBuffer)
811810
ONETYPE_ONEOPERAND_INST(ProjectValueBuffer)
812811
ONETYPE_ONEOPERAND_INST(ProjectExistentialBox)
813812
ONETYPE_ONEOPERAND_INST(DeallocValueBuffer)
814813
#undef ONETYPE_ONEOPERAND_INST
814+
case ValueKind::DeallocBoxInst:
815+
assert(RecordKind == SIL_ONE_TYPE_ONE_OPERAND &&
816+
"Layout should be OneTypeOneOperand.");
817+
ResultVal = Builder.createDeallocBox(Loc,
818+
getLocalValue(ValID,
819+
getSILType(MF->getType(TyID2),
820+
(SILValueCategory)TyCategory2)));
821+
break;
822+
815823
#define ONEOPERAND_ONETYPE_INST(ID) \
816824
case ValueKind::ID##Inst: \
817825
assert(RecordKind == SIL_ONE_TYPE_ONE_OPERAND && \

lib/Serialization/SerializeSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
616616
case ValueKind::DeallocBoxInst: {
617617
auto DBI = cast<DeallocBoxInst>(&SI);
618618
writeOneTypeOneOperandLayout(DBI->getKind(), 0,
619-
DBI->getElementType(),
619+
DBI->getOperand()->getType(),
620620
DBI->getOperand());
621621
break;
622622
}

0 commit comments

Comments
 (0)