Skip to content

Remove the ElementType from DeallocBoxInst's representation. #6037

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
merged 2 commits into from
Dec 2, 2016
Merged
Show file tree
Hide file tree
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
10 changes: 2 additions & 8 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1239,16 +1239,10 @@ class SILBuilder {
return insert(new (F.getModule()) DeallocPartialRefInst(
getSILDebugLocation(Loc), operand, metatype));
}
DeallocBoxInst *createDeallocBox(SILLocation Loc, SILType eltType,
DeallocBoxInst *createDeallocBox(SILLocation Loc,
SILValue operand) {
return insert(new (F.getModule()) DeallocBoxInst(
getSILDebugLocation(Loc), eltType, operand));
}
DeallocBoxInst *createDeallocBox(SILLocation Loc, SILValue operand) {
auto eltType =
operand->getType().castTo<SILBoxType>()->getBoxedAddressType();
return insert(new (F.getModule()) DeallocBoxInst(
getSILDebugLocation(Loc), eltType, operand));
getSILDebugLocation(Loc), operand));
}
DeallocExistentialBoxInst *createDeallocExistentialBox(SILLocation Loc,
CanType concreteType,
Expand Down
1 change: 0 additions & 1 deletion include/swift/SIL/SILCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,6 @@ SILCloner<ImplClass>::visitDeallocBoxInst(DeallocBoxInst *Inst) {
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
doPostProcess(Inst,
getBuilder().createDeallocBox(getOpLocation(Inst->getLoc()),
getOpType(Inst->getElementType()),
getOpValue(Inst->getOperand())));
}

Expand Down
11 changes: 2 additions & 9 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -4337,15 +4337,8 @@ class DeallocBoxInst :
{
friend SILBuilder;

// TODO: The element type can be derived from a typed box.
SILType ElementType;

DeallocBoxInst(SILDebugLocation DebugLoc, SILType elementType,
SILValue operand)
: UnaryInstructionBase(DebugLoc, operand), ElementType(elementType) {}

public:
SILType getElementType() const { return ElementType; }
DeallocBoxInst(SILDebugLocation DebugLoc, SILValue operand)
: UnaryInstructionBase(DebugLoc, operand) {}
};

/// Deallocate memory allocated for a boxed existential container created by
Expand Down
7 changes: 5 additions & 2 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,11 @@ bool TypeBase::isUnspecializedGeneric() {
return cast<SILBlockStorageType>(this)->getCaptureType()
->isUnspecializedGeneric();
case TypeKind::SILBox:
return cast<SILBoxType>(this)->getBoxedType()
->isUnspecializedGeneric();
for (auto &arg : cast<SILBoxType>(this)->getGenericArgs()) {
if (arg.getReplacement()->isUnspecializedGeneric())
return true;
}
return false;
}
llvm_unreachable("bad TypeKind");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Parse/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2690,7 +2690,7 @@ bool SILParser::parseSILInstruction(SILBasicBlock *BB, SILBuilder &B) {
ResultVal = B.createExistentialMetatype(InstLoc, Ty, Val);
break;
case ValueKind::DeallocBoxInst:
ResultVal = B.createDeallocBox(InstLoc, Ty, Val);
ResultVal = B.createDeallocBox(InstLoc, Val);
break;
}
break;
Expand Down
14 changes: 3 additions & 11 deletions lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1409,10 +1409,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
void checkProjectBoxInst(ProjectBoxInst *I) {
require(I->getOperand()->getType().isObject(),
"project_box operand should be a value");
require(I->getOperand()->getType().is<SILBoxType>(),
"project_box operand should be a @box type");
require(I->getType() == I->getOperand()->getType().castTo<SILBoxType>()
->getBoxedAddressType(),
auto boxTy = I->getOperand()->getType().getAs<SILBoxType>();
require(boxTy, "project_box operand should be a @box type");
require(I->getType() == boxTy->getFieldType(I->getFieldIndex()),
"project_box result should be address of boxed type");
}

Expand Down Expand Up @@ -1724,8 +1723,6 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
}

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

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

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

void checkDestroyAddrInst(DestroyAddrInst *DI) {
Expand Down
3 changes: 1 addition & 2 deletions lib/SILGen/SILGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,8 +1332,7 @@ void SILGenFunction::deallocateUninitializedLocalVariable(SILLocation silLoc,
if (!loc.value->getType().isAddress()) return;

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

namespace {
Expand Down
4 changes: 1 addition & 3 deletions lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1809,9 +1809,7 @@ void LifetimeChecker::processUninitializedRelease(SILInstruction *Release,

// dealloc_box the self box if necessary.
if (ABI) {
auto DB = B.createDeallocBox(Loc,
ABI->getElementType(),
ABI);
auto DB = B.createDeallocBox(Loc, ABI);
Releases.push_back(DB);
}
}
Expand Down
10 changes: 9 additions & 1 deletion lib/Serialization/DeserializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,14 +804,22 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
getSILType(MF->getType(TyID2), \
(SILValueCategory)TyCategory2))); \
break;
ONETYPE_ONEOPERAND_INST(DeallocBox)
ONETYPE_ONEOPERAND_INST(ValueMetatype)
ONETYPE_ONEOPERAND_INST(ExistentialMetatype)
ONETYPE_ONEOPERAND_INST(AllocValueBuffer)
ONETYPE_ONEOPERAND_INST(ProjectValueBuffer)
ONETYPE_ONEOPERAND_INST(ProjectExistentialBox)
ONETYPE_ONEOPERAND_INST(DeallocValueBuffer)
#undef ONETYPE_ONEOPERAND_INST
case ValueKind::DeallocBoxInst:
assert(RecordKind == SIL_ONE_TYPE_ONE_OPERAND &&
"Layout should be OneTypeOneOperand.");
ResultVal = Builder.createDeallocBox(Loc,
getLocalValue(ValID,
getSILType(MF->getType(TyID2),
(SILValueCategory)TyCategory2)));
break;

#define ONEOPERAND_ONETYPE_INST(ID) \
case ValueKind::ID##Inst: \
assert(RecordKind == SIL_ONE_TYPE_ONE_OPERAND && \
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/SerializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
case ValueKind::DeallocBoxInst: {
auto DBI = cast<DeallocBoxInst>(&SI);
writeOneTypeOneOperandLayout(DBI->getKind(), 0,
DBI->getElementType(),
DBI->getOperand()->getType(),
DBI->getOperand());
break;
}
Expand Down