@@ -1112,39 +1112,31 @@ class CopyLikeInstruction {
11121112// / initializes the kind field on our object is run before our constructor runs.
11131113class OwnershipForwardingMixin {
11141114 ValueOwnershipKind ownershipKind;
1115- bool directlyForwards ;
1115+ bool preservesOwnershipFlag ;
11161116
11171117protected:
11181118 OwnershipForwardingMixin (SILInstructionKind kind,
11191119 ValueOwnershipKind ownershipKind,
1120- bool isDirectlyForwarding = true )
1121- : ownershipKind(ownershipKind), directlyForwards(isDirectlyForwarding) {
1120+ bool preservesOwnership = true )
1121+ : ownershipKind(ownershipKind),
1122+ preservesOwnershipFlag (preservesOwnership) {
11221123 assert (isa (kind) && " Invalid subclass?!" );
11231124 assert (ownershipKind && " invalid forwarding ownership" );
1124- assert ((directlyForwards || ownershipKind != OwnershipKind::Guaranteed) &&
1125+ assert ((preservesOwnershipFlag
1126+ || ownershipKind != OwnershipKind::Guaranteed) &&
11251127 " Non directly forwarding instructions can not forward guaranteed "
11261128 " ownership" );
11271129 }
11281130
11291131public:
1130- // / If an instruction is directly forwarding, then any operand op whose
1131- // / ownership it forwards into a result r must have the property that op and r
1132- // / are "rc identical". This means that they are representing the same set of
1133- // / underlying lifetimes (plural b/c of aggregates).
1132+ // / A forwarding instruction preserved ownership if it has a
1133+ // / dynamically non-trivial result in which all references are forwarded from
1134+ // / the operand.
11341135 // /
1135- // / An instruction that is not directly forwarding, can not have guaranteed
1136- // / ownership since without direct forwarding, there isn't necessarily any
1137- // / connection in between the operand's lifetime and the value's lifetime.
1138- // /
1139- // / An example of this is checked_cast_br where when performing the following:
1140- // /
1141- // / __SwiftValue(AnyHashable(Klass())) to OtherKlass()
1142- // /
1143- // / we will look through the __SwiftValue(AnyHashable(X)) any just cast Klass
1144- // / to OtherKlass. This means that the result argument would no longer be
1145- // / rc-identical to the operand and default case and thus we can not propagate
1146- // / forward any form of guaranteed ownership.
1147- bool isDirectlyForwarding () const { return directlyForwards; }
1136+ // / A cast can only forward guaranteed values if it preserves ownership. Such
1137+ // / casts cannot release any references within their operand's value and
1138+ // / cannot retain any references owned by their result.
1139+ bool preservesOwnership () const { return preservesOwnershipFlag; }
11481140
11491141 // / Forwarding ownership is determined by the forwarding instruction's
11501142 // / constant ownership attribute. If forwarding ownership is owned, then the
@@ -1160,7 +1152,7 @@ class OwnershipForwardingMixin {
11601152 return ownershipKind;
11611153 }
11621154 void setForwardingOwnershipKind (ValueOwnershipKind newKind) {
1163- assert ((isDirectlyForwarding () || newKind != OwnershipKind::Guaranteed) &&
1155+ assert ((preservesOwnership () || newKind != OwnershipKind::Guaranteed) &&
11641156 " Non directly forwarding instructions can not forward guaranteed "
11651157 " ownership" );
11661158 ownershipKind = newKind;
@@ -8083,9 +8075,9 @@ class OwnershipForwardingTermInst : public TermInst,
80838075 OwnershipForwardingTermInst (SILInstructionKind kind,
80848076 SILDebugLocation debugLoc,
80858077 ValueOwnershipKind ownershipKind,
8086- bool isDirectlyForwarding = true )
8078+ bool preservesOwnership = true )
80878079 : TermInst(kind, debugLoc),
8088- OwnershipForwardingMixin (kind, ownershipKind, isDirectlyForwarding ) {
8080+ OwnershipForwardingMixin (kind, ownershipKind, preservesOwnership ) {
80898081 assert (classof (kind));
80908082 }
80918083
@@ -9062,16 +9054,12 @@ class CheckedCastBranchInst final
90629054 SILBasicBlock *SuccessBB, SILBasicBlock *FailureBB,
90639055 ProfileCounter Target1Count,
90649056 ProfileCounter Target2Count,
9065- ValueOwnershipKind forwardingOwnershipKind)
9057+ ValueOwnershipKind forwardingOwnershipKind,
9058+ bool preservesOwnership)
90669059 : UnaryInstructionWithTypeDependentOperandsBase(
90679060 DebugLoc, Operand, TypeDependentOperands, SuccessBB, FailureBB,
90689061 Target1Count, Target2Count, forwardingOwnershipKind,
9069- // We are always directly forwarding unless we are casting an
9070- // AnyObject. This is b/c an AnyObject could contain a boxed
9071- // AnyObject(Class()) that we unwrap as part of the cast. In such a
9072- // case, we would return a different value and potentially end the
9073- // lifetime of the operand value.
9074- !Operand->getType ().isAnyObject()),
9062+ preservesOwnership),
90759063 DestLoweredTy (DestLoweredTy), DestFormalTy(DestFormalTy),
90769064 IsExact(IsExact) {}
90779065
0 commit comments