mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Carry the formal types of the arguments in the indirect-cast
instructions. Swift SVN r18934
This commit is contained in:
@@ -419,12 +419,14 @@ public:
|
||||
}
|
||||
|
||||
UnconditionalCheckedCastAddrInst *
|
||||
createUnconditionalCheckedCastAddr(SILLocation loc, CheckedCastKind kind,
|
||||
createUnconditionalCheckedCastAddr(SILLocation loc,
|
||||
CastConsumptionKind consumption,
|
||||
SILValue src, SILValue dest) {
|
||||
SILValue src, CanType sourceType,
|
||||
SILValue dest, CanType targetType) {
|
||||
return insert(new (F.getModule())
|
||||
UnconditionalCheckedCastAddrInst(loc, kind, consumption,
|
||||
src, dest));
|
||||
UnconditionalCheckedCastAddrInst(loc, consumption,
|
||||
src, sourceType,
|
||||
dest, targetType));
|
||||
}
|
||||
|
||||
RetainValueInst *createRetainValue(SILLocation loc, SILValue operand) {
|
||||
@@ -910,15 +912,17 @@ public:
|
||||
}
|
||||
|
||||
CheckedCastAddrBranchInst *createCheckedCastAddrBranch(SILLocation loc,
|
||||
CheckedCastKind kind,
|
||||
CastConsumptionKind consumption,
|
||||
SILValue src,
|
||||
CanType sourceType,
|
||||
SILValue dest,
|
||||
CanType targetType,
|
||||
SILBasicBlock *successBB,
|
||||
SILBasicBlock *failureBB) {
|
||||
return insertTerminator(new (F.getModule())
|
||||
CheckedCastAddrBranchInst(loc, kind, consumption,
|
||||
src, dest,
|
||||
CheckedCastAddrBranchInst(loc, consumption,
|
||||
src, sourceType,
|
||||
dest, targetType,
|
||||
successBB, failureBB));
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ protected:
|
||||
// called afterwards on the result.
|
||||
SILLocation remapLocation(SILLocation Loc) { return Loc; }
|
||||
SILType remapType(SILType Ty) { return Ty; }
|
||||
CanType remapASTType(CanType Ty) { return Ty; }
|
||||
ProtocolConformance *remapConformance(SILType Ty, ProtocolConformance *C) {
|
||||
return C;
|
||||
}
|
||||
@@ -95,6 +96,16 @@ protected:
|
||||
|
||||
return asImpl().remapType(Ty);
|
||||
}
|
||||
CanType getOpASTType(CanType ty) {
|
||||
// Substitute opened existential types, if we have any.
|
||||
if (!OpenedExistentialSubs.empty()) {
|
||||
auto &F = getBuilder().getFunction();
|
||||
ty = ty.subst(F.getModule().getSwiftModule(), OpenedExistentialSubs,
|
||||
/*ignore missing*/ false, nullptr)->getCanonicalType();
|
||||
}
|
||||
|
||||
return asImpl().remapASTType(ty);
|
||||
}
|
||||
ProtocolConformance *getOpConformance(SILType Ty,
|
||||
ProtocolConformance *Conformance) {
|
||||
return asImpl().remapConformance(Ty, Conformance);
|
||||
@@ -634,12 +645,13 @@ SILCloner<ImplClass>::visitUnconditionalCheckedCastAddrInst(
|
||||
SILLocation OpLoc = getOpLocation(Inst->getLoc());
|
||||
SILValue SrcValue = getOpValue(Inst->getSrc());
|
||||
SILValue DestValue = getOpValue(Inst->getDest());
|
||||
CanType SrcType = getOpASTType(Inst->getSourceType());
|
||||
CanType TargetType = getOpASTType(Inst->getTargetType());
|
||||
doPostProcess(Inst,
|
||||
getBuilder().createUnconditionalCheckedCastAddr(OpLoc,
|
||||
Inst->getCastKind(),
|
||||
Inst->getConsumptionKind(),
|
||||
SrcValue,
|
||||
DestValue));
|
||||
SrcValue, SrcType,
|
||||
DestValue, TargetType));
|
||||
}
|
||||
|
||||
template<typename ImplClass>
|
||||
@@ -1161,11 +1173,13 @@ void SILCloner<ImplClass>::visitCheckedCastAddrBranchInst(
|
||||
SILBasicBlock *OpFailBB = getOpBasicBlock(Inst->getFailureBB());
|
||||
SILValue SrcValue = getOpValue(Inst->getSrc());
|
||||
SILValue DestValue = getOpValue(Inst->getDest());
|
||||
CanType SrcType = getOpASTType(Inst->getSourceType());
|
||||
CanType TargetType = getOpASTType(Inst->getTargetType());
|
||||
doPostProcess(Inst,
|
||||
getBuilder().createCheckedCastAddrBranch(getOpLocation(Inst->getLoc()),
|
||||
Inst->getCastKind(),
|
||||
Inst->getConsumptionKind(),
|
||||
SrcValue, DestValue,
|
||||
SrcValue, SrcType,
|
||||
DestValue, TargetType,
|
||||
OpSuccBB, OpFailBB));
|
||||
}
|
||||
|
||||
|
||||
@@ -1410,21 +1410,26 @@ class UnconditionalCheckedCastAddrInst : public SILInstruction
|
||||
Dest
|
||||
};
|
||||
FixedOperandList<2> Operands;
|
||||
CheckedCastKind CastKind;
|
||||
CastConsumptionKind ConsumptionKind;
|
||||
CanType SourceType;
|
||||
CanType TargetType;
|
||||
public:
|
||||
UnconditionalCheckedCastAddrInst(SILLocation loc,
|
||||
CheckedCastKind kind,
|
||||
CastConsumptionKind consumption,
|
||||
SILValue src,
|
||||
SILValue dest);
|
||||
SILValue src, CanType sourceType,
|
||||
SILValue dest, CanType targetType);
|
||||
|
||||
CheckedCastKind getCastKind() const { return CastKind; }
|
||||
CastConsumptionKind getConsumptionKind() const { return ConsumptionKind; }
|
||||
|
||||
SILValue getSrc() const { return Operands[Src].get(); }
|
||||
SILValue getDest() const { return Operands[Dest].get(); }
|
||||
|
||||
/// Returns the formal type of the source value.
|
||||
CanType getSourceType() const { return SourceType; }
|
||||
|
||||
/// Returns the formal target type.
|
||||
CanType getTargetType() const { return TargetType; }
|
||||
|
||||
ArrayRef<Operand> getAllOperands() const { return Operands.asArray(); }
|
||||
MutableArrayRef<Operand> getAllOperands() { return Operands.asArray(); }
|
||||
|
||||
@@ -2921,7 +2926,6 @@ public:
|
||||
/// Perform a checked cast operation and branch on whether the cast succeeds.
|
||||
/// The result of the checked cast is left in the destination address.
|
||||
class CheckedCastAddrBranchInst : public TermInst {
|
||||
CheckedCastKind CastKind;
|
||||
CastConsumptionKind ConsumptionKind;
|
||||
|
||||
enum {
|
||||
@@ -2933,29 +2937,33 @@ class CheckedCastAddrBranchInst : public TermInst {
|
||||
FixedOperandList<2> Operands;
|
||||
SILSuccessor DestBBs[2];
|
||||
|
||||
CanType SourceType;
|
||||
CanType TargetType;
|
||||
|
||||
public:
|
||||
CheckedCastAddrBranchInst(SILLocation loc,
|
||||
CheckedCastKind castKind,
|
||||
CastConsumptionKind consumptionKind,
|
||||
SILValue src,
|
||||
SILValue dest,
|
||||
SILValue src, CanType srcType,
|
||||
SILValue dest, CanType targetType,
|
||||
SILBasicBlock *successBB,
|
||||
SILBasicBlock *failureBB)
|
||||
: TermInst(ValueKind::CheckedCastAddrBranchInst, loc),
|
||||
CastKind(castKind), ConsumptionKind(consumptionKind),
|
||||
Operands{this, src, dest},
|
||||
DestBBs{{this, successBB}, {this, failureBB}}
|
||||
{
|
||||
assert(CastKind >= CheckedCastKind::First_Resolved
|
||||
&& "cannot create a cast instruction with an unresolved cast kind");
|
||||
ConsumptionKind(consumptionKind), Operands{this, src, dest},
|
||||
DestBBs{{this, successBB}, {this, failureBB}},
|
||||
SourceType(srcType), TargetType(targetType) {
|
||||
}
|
||||
|
||||
CheckedCastKind getCastKind() const { return CastKind; }
|
||||
CastConsumptionKind getConsumptionKind() const { return ConsumptionKind; }
|
||||
|
||||
SILValue getSrc() const { return Operands[Src].get(); }
|
||||
SILValue getDest() const { return Operands[Dest].get(); }
|
||||
|
||||
/// Returns the formal type of the source value.
|
||||
CanType getSourceType() const { return SourceType; }
|
||||
|
||||
/// Returns the formal target type.
|
||||
CanType getTargetType() const { return TargetType; }
|
||||
|
||||
ArrayRef<Operand> getAllOperands() const { return Operands.asArray(); }
|
||||
MutableArrayRef<Operand> getAllOperands() { return Operands.asArray(); }
|
||||
|
||||
|
||||
@@ -56,6 +56,10 @@ protected:
|
||||
return SILType::substType(Original.getModule(), SwiftMod, SubsMap, Ty);
|
||||
}
|
||||
|
||||
CanType remapASTType(CanType ty) {
|
||||
return ty.subst(SwiftMod, SubsMap, false, nullptr)->getCanonicalType();
|
||||
}
|
||||
|
||||
ProtocolConformance *remapConformance(SILType Ty, ProtocolConformance *C) {
|
||||
// If Ty does not have unbound generic types, we did not specialize it so
|
||||
// just return C. This relies on the fact that we do not partially
|
||||
|
||||
Reference in New Issue
Block a user