Skip to content

[semantic-sil] Rename EndBorrowInst::get{Src,Dest} => get{BorrowedValue,OriginalValue}. #6869

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 1 commit into from
Jan 18, 2017
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
8 changes: 4 additions & 4 deletions include/swift/SIL/SILBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,10 @@ class SILBuilder {
return lowering.emitStore(*this, Loc, Src, DestAddr, Qualifier);
}

EndBorrowInst *createEndBorrow(SILLocation Loc, SILValue Src,
SILValue DestAddr) {
return insert(new (F.getModule())
EndBorrowInst(getSILDebugLocation(Loc), Src, DestAddr));
EndBorrowInst *createEndBorrow(SILLocation Loc, SILValue BorrowedValue,
SILValue OriginalValue) {
return insert(new (F.getModule()) EndBorrowInst(
getSILDebugLocation(Loc), BorrowedValue, OriginalValue));
}

AssignInst *createAssign(SILLocation Loc, SILValue Src, SILValue DestAddr) {
Expand Down
8 changes: 4 additions & 4 deletions include/swift/SIL/SILCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,10 @@ void SILCloner<ImplClass>::visitStoreBorrowInst(StoreBorrowInst *Inst) {
template <typename ImplClass>
void SILCloner<ImplClass>::visitEndBorrowInst(EndBorrowInst *Inst) {
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
doPostProcess(Inst,
getBuilder().createEndBorrow(getOpLocation(Inst->getLoc()),
getOpValue(Inst->getSrc()),
getOpValue(Inst->getDest())));
doPostProcess(
Inst, getBuilder().createEndBorrow(getOpLocation(Inst->getLoc()),
getOpValue(Inst->getBorrowedValue()),
getOpValue(Inst->getOriginalValue())));
}

template <typename ImplClass>
Expand Down
15 changes: 8 additions & 7 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1811,20 +1811,21 @@ class EndBorrowInst : public SILInstruction {

public:
enum {
/// The source of the value being borrowed.
Src,
/// The destination of the borrowed value.
Dest
/// The borrowed value.
BorrowedValue,
/// The original value that was borrowed from.
OriginalValue
};

private:
FixedOperandList<2> Operands;
EndBorrowInst(SILDebugLocation DebugLoc, SILValue Src, SILValue Dest);
EndBorrowInst(SILDebugLocation DebugLoc, SILValue BorrowedValue,
SILValue OriginalValue);

public:
SILValue getSrc() const { return Operands[Src].get(); }
SILValue getBorrowedValue() const { return Operands[BorrowedValue].get(); }

SILValue getDest() const { return Operands[Dest].get(); }
SILValue getOriginalValue() const { return Operands[OriginalValue].get(); }

ArrayRef<Operand> getAllOperands() const { return Operands.asArray(); }
MutableArrayRef<Operand> getAllOperands() { return Operands.asArray(); }
Expand Down
22 changes: 11 additions & 11 deletions lib/Parse/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2420,32 +2420,32 @@ bool SILParser::parseSILInstruction(SILBasicBlock *BB, SILBuilder &B) {
}

case ValueKind::EndBorrowInst: {
UnresolvedValueName BorrowDestName, BorrowSourceName;
UnresolvedValueName BorrowedFromName, BorrowedValueName;
SourceLoc ToLoc;
Identifier ToToken;
SILType BorrowDestTy, BorrowSourceTy;
SILType BorrowedFromTy, BorrowedValueTy;

if (parseValueName(BorrowDestName) ||
if (parseValueName(BorrowedValueName) ||
parseSILIdentifier(ToToken, ToLoc, diag::expected_tok_in_sil_instr,
"from") ||
parseValueName(BorrowSourceName) ||
parseValueName(BorrowedFromName) ||
P.parseToken(tok::colon, diag::expected_sil_colon_value_ref) ||
parseSILType(BorrowDestTy) ||
parseSILType(BorrowedValueTy) ||
P.parseToken(tok::comma, diag::expected_tok_in_sil_instr, ",") ||
parseSILType(BorrowSourceTy) || parseSILDebugLocation(InstLoc, B))
parseSILType(BorrowedFromTy) || parseSILDebugLocation(InstLoc, B))
return true;

if (ToToken.str() != "from") {
P.diagnose(ToLoc, diag::expected_tok_in_sil_instr, "from");
return true;
}

SILValue BorrowDest =
getLocalValue(BorrowDestName, BorrowDestTy, InstLoc, B);
SILValue BorrowSource =
getLocalValue(BorrowSourceName, BorrowSourceTy, InstLoc, B);
SILValue BorrowedValue =
getLocalValue(BorrowedValueName, BorrowedValueTy, InstLoc, B);
SILValue BorrowedFrom =
getLocalValue(BorrowedFromName, BorrowedFromTy, InstLoc, B);

ResultVal = B.createEndBorrow(InstLoc, BorrowDest, BorrowSource);
ResultVal = B.createEndBorrow(InstLoc, BorrowedValue, BorrowedFrom);
break;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/SIL/SILOwnershipVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,11 @@ OwnershipCompatibilityUseChecker::visitReturnInst(ReturnInst *RI) {

OwnershipUseCheckerResult
OwnershipCompatibilityUseChecker::visitEndBorrowInst(EndBorrowInst *I) {
// We do not consider the source to be a verified use for now.
if (getOperandIndex() == EndBorrowInst::Src)
// We do not consider the original value to be a verified use. But the value
// does need to be alive.
if (getOperandIndex() == EndBorrowInst::OriginalValue)
return {true, false};
// The borrowed value is a verified use though of the begin_borrow.
return {compatibleWithOwnership(ValueOwnershipKind::Guaranteed), true};
}

Expand Down
6 changes: 4 additions & 2 deletions lib/SIL/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,10 @@ class SILPrinter : public SILVisitor<SILPrinter> {
}

void visitEndBorrowInst(EndBorrowInst *EBI) {
*this << getID(EBI->getDest()) << " from " << getID(EBI->getSrc()) << " : "
<< EBI->getDest()->getType() << ", " << EBI->getSrc()->getType();
*this << getID(EBI->getBorrowedValue()) << " from "
<< getID(EBI->getOriginalValue()) << " : "
<< EBI->getBorrowedValue()->getType() << ", "
<< EBI->getOriginalValue()->getType();
}

void visitAssignInst(AssignInst *AI) {
Expand Down
4 changes: 2 additions & 2 deletions lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,8 +1184,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
// We allow for end_borrow to express relationships in between addresses and
// values, but we require that the types are the same ignoring value
// category.
require(EBI->getDest()->getType().getObjectType() ==
EBI->getSrc()->getType().getObjectType(),
require(EBI->getBorrowedValue()->getType().getObjectType() ==
EBI->getOriginalValue()->getType().getObjectType(),
"end_borrow can only relate the same types ignoring value "
"category");
}
Expand Down
12 changes: 6 additions & 6 deletions lib/SILGen/SILGenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ void TemporaryInitialization::finishInitialization(SILGenFunction &gen) {

namespace {
class EndBorrowCleanup : public Cleanup {
SILValue borrowee;
SILValue original;
SILValue borrowed;

public:
EndBorrowCleanup(SILValue borrowee, SILValue borrowed)
: borrowee(borrowee), borrowed(borrowed) {}
EndBorrowCleanup(SILValue original, SILValue borrowed)
: original(original), borrowed(borrowed) {}

void emit(SILGenFunction &gen, CleanupLocation l) override {
gen.B.createEndBorrow(l, borrowee, borrowed);
gen.B.createEndBorrow(l, borrowed, original);
}
};
} // end anonymous namespace
Expand Down Expand Up @@ -1159,9 +1159,9 @@ CleanupHandle SILGenFunction::enterDestroyCleanup(SILValue valueOrAddr) {
return Cleanups.getTopCleanup();
}

CleanupHandle SILGenFunction::enterEndBorrowCleanup(SILValue borrowee,
CleanupHandle SILGenFunction::enterEndBorrowCleanup(SILValue original,
SILValue borrowed) {
Cleanups.pushCleanup<EndBorrowCleanup>(borrowee, borrowed);
Cleanups.pushCleanup<EndBorrowCleanup>(original, borrowed);
return Cleanups.getTopCleanup();
}

Expand Down
16 changes: 9 additions & 7 deletions lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,24 @@ SILGenFunction::emitManagedBeginBorrow(SILLocation loc, SILValue v,
}

ManagedValue
SILGenFunction::emitManagedBorrowedRValueWithCleanup(SILValue borrowee,
SILGenFunction::emitManagedBorrowedRValueWithCleanup(SILValue original,
SILValue borrowed) {
assert(borrowee->getType().getObjectType() ==
assert(original->getType().getObjectType() ==
borrowed->getType().getObjectType());
auto &lowering = getTypeLowering(borrowee->getType());
return emitManagedBorrowedRValueWithCleanup(borrowee, borrowed, lowering);
auto &lowering = getTypeLowering(original->getType());
return emitManagedBorrowedRValueWithCleanup(original, borrowed, lowering);
}

ManagedValue SILGenFunction::emitManagedBorrowedRValueWithCleanup(
SILValue borrowee, SILValue borrowed, const TypeLowering &lowering) {
SILValue original, SILValue borrowed, const TypeLowering &lowering) {
assert(lowering.getLoweredType().getObjectType() ==
borrowee->getType().getObjectType());
original->getType().getObjectType());
if (lowering.isTrivial())
return ManagedValue::forUnmanaged(borrowed);

return ManagedValue(borrowed, enterEndBorrowCleanup(borrowee, borrowed));
if (borrowed->getType().isObject())
enterEndBorrowCleanup(original, borrowed);
return ManagedValue(borrowed, CleanupHandle::invalid());
}

ManagedValue SILGenFunction::emitManagedRValueWithCleanup(SILValue v) {
Expand Down
13 changes: 6 additions & 7 deletions lib/SILGen/SILGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -1173,11 +1173,10 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
const TypeLowering &lowering);
ManagedValue emitManagedBeginBorrow(SILLocation loc, SILValue v);

ManagedValue emitManagedBorrowedRValueWithCleanup(SILValue borrowee,
SILValue borrower);
ManagedValue
emitManagedBorrowedRValueWithCleanup(SILValue borrowee, SILValue borrower,
const TypeLowering &lowering);
ManagedValue emitManagedBorrowedRValueWithCleanup(SILValue original,
SILValue borrowedValue);
ManagedValue emitManagedBorrowedRValueWithCleanup(
SILValue original, SILValue borrowedValue, const TypeLowering &lowering);

ManagedValue emitManagedRValueWithCleanup(SILValue v);
ManagedValue emitManagedRValueWithCleanup(SILValue v,
Expand Down Expand Up @@ -1624,9 +1623,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
ExistentialRepresentation repr);

/// Enter a cleanup to emit an EndBorrow stating that \p borrowed (the
/// borrowed entity) is no longer borrowed from \p borrowee, the original
/// borrowed entity) is no longer borrowed from \p original, the original
/// value.
CleanupHandle enterEndBorrowCleanup(SILValue borrowee, SILValue borrowed);
CleanupHandle enterEndBorrowCleanup(SILValue original, SILValue borrowed);

/// Evaluate an Expr as an lvalue.
LValue emitLValue(Expr *E, AccessKind accessKind);
Expand Down
14 changes: 8 additions & 6 deletions lib/Serialization/SerializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,15 +1301,17 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
unsigned abbrCode = SILAbbrCodes[SILTwoOperandsLayout::Code];
unsigned Attr = 0;
auto *EBI = cast<EndBorrowInst>(&SI);
SILValue Src = EBI->getSrc();
SILValue Dest = EBI->getDest();
SILValue BorrowedValue = EBI->getBorrowedValue();
SILValue OriginalValue = EBI->getOriginalValue();

SILTwoOperandsLayout::emitRecord(
Out, ScratchRecord, abbrCode, (unsigned)SI.getKind(), Attr,
S.addTypeRef(Src->getType().getSwiftRValueType()),
(unsigned)Src->getType().getCategory(), addValueRef(Src),
S.addTypeRef(Dest->getType().getSwiftRValueType()),
(unsigned)Dest->getType().getCategory(), addValueRef(Dest));
S.addTypeRef(BorrowedValue->getType().getSwiftRValueType()),
(unsigned)BorrowedValue->getType().getCategory(),
addValueRef(BorrowedValue),
S.addTypeRef(OriginalValue->getType().getSwiftRValueType()),
(unsigned)OriginalValue->getType().getCategory(),
addValueRef(OriginalValue));
break;
}

Expand Down