@@ -310,6 +310,8 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
310310 case SILInstructionKind::UnmanagedToRefInst:
311311 case SILInstructionKind::InitExistentialValueInst:
312312 case SILInstructionKind::UncheckedEnumDataInst:
313+ case SILInstructionKind::StructElementAddrInst:
314+ case SILInstructionKind::TupleElementAddrInst:
313315 return true ;
314316 case SILInstructionKind::MoveValueInst:
315317 // Look through if it isn't from a var decl.
@@ -334,9 +336,6 @@ static bool isLookThroughIfOperandAndResultNonSendable(SILInstruction *inst) {
334336 case SILInstructionKind::UncheckedTrivialBitCastInst:
335337 case SILInstructionKind::UncheckedBitwiseCastInst:
336338 case SILInstructionKind::UncheckedValueCastInst:
337- case SILInstructionKind::StructElementAddrInst:
338- case SILInstructionKind::TupleElementAddrInst:
339- case SILInstructionKind::UncheckedTakeEnumDataAddrInst:
340339 case SILInstructionKind::ConvertEscapeToNoEscapeInst:
341340 case SILInstructionKind::ConvertFunctionInst:
342341 case SILInstructionKind::RefToRawPointerInst:
@@ -735,6 +734,7 @@ TrackableValueLookupResult RegionAnalysisValueMap::getTrackableValue(
735734
736735 auto trackedValue =
737736 getTrackableValueHelper (value, isAddressCapturedByPartialApply);
737+
738738 std::optional<TrackableValue> trackedBase;
739739 if (base)
740740 trackedBase =
@@ -1130,6 +1130,17 @@ void TrackableValueLookupResult::print(llvm::raw_ostream &os) const {
11301130 }
11311131}
11321132
1133+ // ===----------------------------------------------------------------------===//
1134+ // MARK: UnderlyingTrackedValueInfo
1135+ // ===----------------------------------------------------------------------===//
1136+
1137+ void RegionAnalysisValueMap::UnderlyingTrackedValueInfo::print (
1138+ llvm::raw_ostream &os) const {
1139+ os << " RegionAnalysisValueMap.\n Value: " << value;
1140+ if (base)
1141+ os << " Base: " << base;
1142+ }
1143+
11331144// ===----------------------------------------------------------------------===//
11341145// MARK: Partial Apply Reachability
11351146// ===----------------------------------------------------------------------===//
@@ -3204,10 +3215,16 @@ void PartitionOpBuilder::addRequire(TrackableValueLookupResult value) {
32043215 if (!boxType->getLayout ()->isMutable ())
32053216 return ;
32063217
3218+ options |= PartitionOp::Flag::RequireOfMutableBaseOfSendableValue;
3219+ } else if (auto *asi = dyn_cast<AllocStackInst>(rep)) {
3220+ if (asi->isLet ())
3221+ return ;
3222+
32073223 options |= PartitionOp::Flag::RequireOfMutableBaseOfSendableValue;
32083224 }
3225+
3226+ addRequire (value.base , options);
32093227 }
3210- addRequire (value.base , options);
32113228 }
32123229}
32133230
@@ -3355,6 +3372,9 @@ CONSTANT_TRANSLATION(RefToUnmanagedInst, LookThrough)
33553372CONSTANT_TRANSLATION(UnmanagedToRefInst, LookThrough)
33563373CONSTANT_TRANSLATION(InitExistentialValueInst, LookThrough)
33573374CONSTANT_TRANSLATION(UncheckedEnumDataInst, LookThrough)
3375+ CONSTANT_TRANSLATION(TupleElementAddrInst, LookThrough)
3376+ CONSTANT_TRANSLATION(StructElementAddrInst, LookThrough)
3377+ CONSTANT_TRANSLATION(UncheckedTakeEnumDataAddrInst, LookThrough)
33583378
33593379// ===---
33603380// Store
@@ -3604,9 +3624,6 @@ IGNORE_IF_SENDABLE_RESULT_ASSIGN_OTHERWISE(StructExtractInst)
36043624LOOKTHROUGH_IF_NONSENDABLE_RESULT_AND_OPERAND (UncheckedTrivialBitCastInst)
36053625LOOKTHROUGH_IF_NONSENDABLE_RESULT_AND_OPERAND(UncheckedBitwiseCastInst)
36063626LOOKTHROUGH_IF_NONSENDABLE_RESULT_AND_OPERAND(UncheckedValueCastInst)
3607- LOOKTHROUGH_IF_NONSENDABLE_RESULT_AND_OPERAND(TupleElementAddrInst)
3608- LOOKTHROUGH_IF_NONSENDABLE_RESULT_AND_OPERAND(StructElementAddrInst)
3609- LOOKTHROUGH_IF_NONSENDABLE_RESULT_AND_OPERAND(UncheckedTakeEnumDataAddrInst)
36103627LOOKTHROUGH_IF_NONSENDABLE_RESULT_AND_OPERAND(ConvertEscapeToNoEscapeInst)
36113628LOOKTHROUGH_IF_NONSENDABLE_RESULT_AND_OPERAND(ConvertFunctionInst)
36123629
@@ -3701,20 +3718,42 @@ PartitionOpTranslator::visitBeginBorrowInst(BeginBorrowInst *bbi) {
37013718 return TranslationSemantics::LookThrough;
37023719}
37033720
3704- // / LoadInst is technically a statically look through instruction, but we want
3705- // / to handle it especially in the infrastructure, so we cannot mark it as
3706- // / such. This makes marking it as a normal lookthrough instruction impossible
3707- // / since the routine checks that invariant.
3708- TranslationSemantics PartitionOpTranslator::visitLoadInst (LoadInst *limvi) {
3721+ // / LoadInst has two different semantics:
3722+ // /
3723+ // / 1. If the load produces a non-Sendable value, we want to treat it as a
3724+ // / statically look through instruction, but we want to handle it especially in
3725+ // / the infrastructure, so we cannot mark it as such. This makes marking it as a
3726+ // / normal lookthrough instruction impossible since the routine checks that
3727+ // / invariant.
3728+ // /
3729+ // / 2. If the load produces a Sendable value, we want to perform a require on
3730+ // / the address so that if we have a load from a non-Sendable base, we properly
3731+ // / require the base.
3732+ TranslationSemantics PartitionOpTranslator::visitLoadInst (LoadInst *li) {
3733+ if (SILIsolationInfo::isSendableType (li->getOperand ())) {
3734+ translateSILRequire (li->getOperand ());
3735+ }
3736+
37093737 return TranslationSemantics::Special;
37103738}
37113739
3712- // / LoadBorrowInst is technically a statically look through instruction, but we
3713- // / want to handle it especially in the infrastructure, so we cannot mark it as
3714- // / such. This makes marking it as a normal lookthrough instruction impossible
3715- // / since the routine checks that invariant.
3740+ // / LoadBorrowInst has two different semantics:
3741+ // /
3742+ // / 1. If the load produces a non-Sendable value, we want to treat it as a
3743+ // / statically look through instruction, but we want to handle it especially in
3744+ // / the infrastructure, so we cannot mark it as such. This makes marking it as a
3745+ // / normal lookthrough instruction impossible since the routine checks that
3746+ // / invariant.
3747+ // /
3748+ // / 2. If the load produces a Sendable value, we want to perform a require on
3749+ // / the address so that if we have a load from a non-Sendable base, we properly
3750+ // / require the base.
37163751TranslationSemantics
37173752PartitionOpTranslator::visitLoadBorrowInst (LoadBorrowInst *lbi) {
3753+ if (SILIsolationInfo::isSendableType (lbi->getOperand ())) {
3754+ translateSILRequire (lbi->getOperand ());
3755+ }
3756+
37183757 return TranslationSemantics::Special;
37193758}
37203759
0 commit comments