@@ -196,11 +196,13 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
196
196
case SILInstructionKind::CopyableToMoveOnlyWrapperValueInst:
197
197
case SILInstructionKind::DestructureStructInst:
198
198
case SILInstructionKind::DestructureTupleInst:
199
+ case SILInstructionKind::DifferentiableFunctionExtractInst:
199
200
case SILInstructionKind::DropDeinitInst:
200
201
case SILInstructionKind::EndCOWMutationInst:
201
202
case SILInstructionKind::EndInitLetRefInst:
202
203
case SILInstructionKind::ExplicitCopyValueInst:
203
204
case SILInstructionKind::InitEnumDataAddrInst:
205
+ case SILInstructionKind::LinearFunctionExtractInst:
204
206
case SILInstructionKind::MarkDependenceInst:
205
207
case SILInstructionKind::MarkUninitializedInst:
206
208
case SILInstructionKind::MarkUnresolvedNonCopyableValueInst:
@@ -210,6 +212,7 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
210
212
case SILInstructionKind::MoveOnlyWrapperToCopyableValueInst:
211
213
case SILInstructionKind::MoveValueInst:
212
214
case SILInstructionKind::OpenExistentialAddrInst:
215
+ case SILInstructionKind::OpenExistentialValueInst:
213
216
case SILInstructionKind::ProjectBlockStorageInst:
214
217
case SILInstructionKind::ProjectBoxInst:
215
218
case SILInstructionKind::RefToBridgeObjectInst:
@@ -220,6 +223,12 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
220
223
case SILInstructionKind::UnownedToRefInst:
221
224
case SILInstructionKind::UpcastInst:
222
225
case SILInstructionKind::ValueToBridgeObjectInst:
226
+ case SILInstructionKind::WeakCopyValueInst:
227
+ case SILInstructionKind::StrongCopyWeakValueInst:
228
+ case SILInstructionKind::StrongCopyUnmanagedValueInst:
229
+ case SILInstructionKind::RefToUnmanagedInst:
230
+ case SILInstructionKind::UnmanagedToRefInst:
231
+ case SILInstructionKind::InitExistentialValueInst:
223
232
return true ;
224
233
case SILInstructionKind::UnconditionalCheckedCastInst: {
225
234
auto cast = SILDynamicCastInst::getAs (inst);
@@ -1157,9 +1166,12 @@ enum class TranslationSemantics {
1157
1166
// / handle every instruction to ensure we cover the IR.
1158
1167
Asserting,
1159
1168
1160
- // / An instruction that we do not handle yet. Just for now during bring
1161
- // / up. Will be removed.
1162
- Unhandled,
1169
+ // / An instruction that the checker thinks it can ignore as long as all of its
1170
+ // / operands are Sendable. If we see that such an instruction has a
1171
+ // / non-Sendable parameter, then someone added an instruction to the compiler
1172
+ // / without updating this code correctly. This is most likely driver error and
1173
+ // / should be caught in testing when we assert.
1174
+ AssertingIfNonSendable,
1163
1175
};
1164
1176
1165
1177
} // namespace
@@ -1199,8 +1211,8 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
1199
1211
case TranslationSemantics::Asserting:
1200
1212
os << " asserting" ;
1201
1213
return os;
1202
- case TranslationSemantics::Unhandled :
1203
- os << " unhandled " ;
1214
+ case TranslationSemantics::AssertingIfNonSendable :
1215
+ os << " asserting_if_nonsendable " ;
1204
1216
return os;
1205
1217
}
1206
1218
@@ -2101,8 +2113,15 @@ class PartitionOpTranslator {
2101
2113
" transfer-non-sendable: Found banned instruction?!" );
2102
2114
return ;
2103
2115
2104
- case TranslationSemantics::Unhandled:
2105
- LLVM_DEBUG (llvm::dbgs () << " Unhandled inst: " << *inst);
2116
+ case TranslationSemantics::AssertingIfNonSendable:
2117
+ // Do not error if all of our operands are sendable.
2118
+ if (llvm::none_of (inst->getOperandValues (), [&](SILValue value) {
2119
+ return ::isNonSendableType (value->getType (), inst->getFunction ());
2120
+ }))
2121
+ return ;
2122
+ llvm::report_fatal_error (
2123
+ " transfer-non-sendable: Found instruction that is not allowed to "
2124
+ " have non-Sendable parameters with such parameters?!" );
2106
2125
return ;
2107
2126
}
2108
2127
@@ -2170,8 +2189,11 @@ void PartitionOpBuilder::print(llvm::raw_ostream &os) const {
2170
2189
assert (trackableValue);
2171
2190
llvm::dbgs () << " State: %%" << opArg << " . " ;
2172
2191
trackableValue->getValueState ().print (llvm::dbgs ());
2173
- llvm::dbgs () << " \n Value: "
2192
+ llvm::dbgs () << " \n Rep Value: "
2174
2193
<< trackableValue->getRepresentative ();
2194
+ if (auto value = trackableValue->getRepresentative ().maybeGetValue ()) {
2195
+ llvm::dbgs () << " Type: " << value->getType () << ' \n ' ;
2196
+ }
2175
2197
}
2176
2198
#endif
2177
2199
}
@@ -2218,6 +2240,9 @@ CONSTANT_TRANSLATION(WitnessMethodInst, AssignFresh)
2218
2240
CONSTANT_TRANSLATION(IntegerLiteralInst, AssignFresh)
2219
2241
CONSTANT_TRANSLATION(FloatLiteralInst, AssignFresh)
2220
2242
CONSTANT_TRANSLATION(StringLiteralInst, AssignFresh)
2243
+ // Metatypes are Sendable, but AnyObject isn't
2244
+ CONSTANT_TRANSLATION(ObjCMetatypeToObjectInst, AssignFresh)
2245
+ CONSTANT_TRANSLATION(ObjCExistentialMetatypeToObjectInst, AssignFresh)
2221
2246
2222
2247
// ===---
2223
2248
// Assign
@@ -2236,6 +2261,7 @@ CONSTANT_TRANSLATION(ClassMethodInst, Assign)
2236
2261
CONSTANT_TRANSLATION(ObjCMethodInst, Assign)
2237
2262
CONSTANT_TRANSLATION(SuperMethodInst, Assign)
2238
2263
CONSTANT_TRANSLATION(ObjCSuperMethodInst, Assign)
2264
+ CONSTANT_TRANSLATION(LoadUnownedInst, Assign)
2239
2265
2240
2266
// These instructions are in between look through and a true assign. We should
2241
2267
// probably eventually treat them as look through but we haven't done the work
@@ -2253,14 +2279,12 @@ CONSTANT_TRANSLATION(InitExistentialAddrInst, Assign)
2253
2279
CONSTANT_TRANSLATION(InitExistentialRefInst, Assign)
2254
2280
CONSTANT_TRANSLATION(OpenExistentialBoxInst, Assign)
2255
2281
CONSTANT_TRANSLATION(OpenExistentialRefInst, Assign)
2256
- CONSTANT_TRANSLATION(RefToUnmanagedInst, Assign)
2257
2282
CONSTANT_TRANSLATION(TailAddrInst, Assign)
2258
2283
CONSTANT_TRANSLATION(ThickToObjCMetatypeInst, Assign)
2259
2284
CONSTANT_TRANSLATION(ThinToThickFunctionInst, Assign)
2260
2285
CONSTANT_TRANSLATION(UncheckedAddrCastInst, Assign)
2261
2286
CONSTANT_TRANSLATION(UncheckedEnumDataInst, Assign)
2262
2287
CONSTANT_TRANSLATION(UncheckedOwnershipConversionInst, Assign)
2263
- CONSTANT_TRANSLATION(UnmanagedToRefInst, Assign)
2264
2288
CONSTANT_TRANSLATION(IndexRawPointerInst, Assign)
2265
2289
2266
2290
// These are used by SIL to aggregate values together in a gep like way. We
@@ -2311,6 +2335,13 @@ CONSTANT_TRANSLATION(UnownedCopyValueInst, LookThrough)
2311
2335
CONSTANT_TRANSLATION(DropDeinitInst, LookThrough)
2312
2336
CONSTANT_TRANSLATION(ValueToBridgeObjectInst, LookThrough)
2313
2337
CONSTANT_TRANSLATION(BeginCOWMutationInst, LookThrough)
2338
+ CONSTANT_TRANSLATION(OpenExistentialValueInst, LookThrough)
2339
+ CONSTANT_TRANSLATION(WeakCopyValueInst, LookThrough)
2340
+ CONSTANT_TRANSLATION(StrongCopyWeakValueInst, LookThrough)
2341
+ CONSTANT_TRANSLATION(StrongCopyUnmanagedValueInst, LookThrough)
2342
+ CONSTANT_TRANSLATION(RefToUnmanagedInst, LookThrough)
2343
+ CONSTANT_TRANSLATION(UnmanagedToRefInst, LookThrough)
2344
+ CONSTANT_TRANSLATION(InitExistentialValueInst, LookThrough)
2314
2345
2315
2346
// ===---
2316
2347
// Store
@@ -2352,6 +2383,7 @@ CONSTANT_TRANSLATION(DestroyValueInst, Ignored)
2352
2383
CONSTANT_TRANSLATION(EndAccessInst, Ignored)
2353
2384
CONSTANT_TRANSLATION(EndBorrowInst, Ignored)
2354
2385
CONSTANT_TRANSLATION(EndLifetimeInst, Ignored)
2386
+ CONSTANT_TRANSLATION(EndUnpairedAccessInst, Ignored)
2355
2387
CONSTANT_TRANSLATION(HopToExecutorInst, Ignored)
2356
2388
CONSTANT_TRANSLATION(InjectEnumAddrInst, Ignored)
2357
2389
CONSTANT_TRANSLATION(IsEscapingClosureInst, Ignored)
@@ -2371,6 +2403,26 @@ CONSTANT_TRANSLATION(FixLifetimeInst, Require)
2371
2403
CONSTANT_TRANSLATION(ClassifyBridgeObjectInst, Require)
2372
2404
CONSTANT_TRANSLATION(BridgeObjectToWordInst, Require)
2373
2405
CONSTANT_TRANSLATION(IsUniqueInst, Require)
2406
+ CONSTANT_TRANSLATION(MarkFunctionEscapeInst, Require)
2407
+ CONSTANT_TRANSLATION(UnmanagedRetainValueInst, Require)
2408
+ CONSTANT_TRANSLATION(UnmanagedReleaseValueInst, Require)
2409
+ CONSTANT_TRANSLATION(UnmanagedAutoreleaseValueInst, Require)
2410
+ CONSTANT_TRANSLATION(RebindMemoryInst, Require)
2411
+ CONSTANT_TRANSLATION(BindMemoryInst, Require)
2412
+ CONSTANT_TRANSLATION(BeginUnpairedAccessInst, Require)
2413
+ // Require of the value we extract the metatype from.
2414
+ CONSTANT_TRANSLATION(ValueMetatypeInst, Require)
2415
+ // Require of the value we extract the metatype from.
2416
+ CONSTANT_TRANSLATION(ExistentialMetatypeInst, Require)
2417
+
2418
+ // ===---
2419
+ // Asserting If Non Sendable Parameter
2420
+ //
2421
+
2422
+ // Takes metatypes as parameters and metatypes today are always sendable.
2423
+ CONSTANT_TRANSLATION(InitExistentialMetatypeInst, AssertingIfNonSendable)
2424
+ CONSTANT_TRANSLATION(OpenExistentialMetatypeInst, AssertingIfNonSendable)
2425
+ CONSTANT_TRANSLATION(ObjCToThickMetatypeInst, AssertingIfNonSendable)
2374
2426
2375
2427
// ===---
2376
2428
// Terminators
@@ -2383,6 +2435,8 @@ CONSTANT_TRANSLATION(CondFailInst, Ignored)
2383
2435
CONSTANT_TRANSLATION(SwitchValueInst, Ignored)
2384
2436
CONSTANT_TRANSLATION(UnreachableInst, Ignored)
2385
2437
CONSTANT_TRANSLATION(UnwindInst, Ignored)
2438
+ // Doesn't take a parameter.
2439
+ CONSTANT_TRANSLATION(ThrowAddrInst, Ignored)
2386
2440
2387
2441
// Terminators that only need require.
2388
2442
CONSTANT_TRANSLATION(ReturnInst, Require)
@@ -2396,6 +2450,13 @@ CONSTANT_TRANSLATION(CondBranchInst, TerminatorPhi)
2396
2450
CONSTANT_TRANSLATION(CheckedCastBranchInst, TerminatorPhi)
2397
2451
CONSTANT_TRANSLATION(DynamicMethodBranchInst, TerminatorPhi)
2398
2452
2453
+ // Today, await_async_continuation just takes Sendable values
2454
+ // (UnsafeContinuation and UnsafeThrowingContinuation).
2455
+ CONSTANT_TRANSLATION(AwaitAsyncContinuationInst, AssertingIfNonSendable)
2456
+ CONSTANT_TRANSLATION(GetAsyncContinuationInst, AssertingIfNonSendable)
2457
+ CONSTANT_TRANSLATION(GetAsyncContinuationAddrInst, AssertingIfNonSendable)
2458
+ CONSTANT_TRANSLATION(ExtractExecutorInst, AssertingIfNonSendable)
2459
+
2399
2460
// ===---
2400
2461
// Existential Box
2401
2462
//
@@ -2409,54 +2470,25 @@ CONSTANT_TRANSLATION(OpenExistentialBoxValueInst, Assign)
2409
2470
CONSTANT_TRANSLATION(DeallocExistentialBoxInst, Ignored)
2410
2471
2411
2472
// ===---
2412
- // Unhandled Instructions
2473
+ // Differentiable
2474
+ //
2475
+
2476
+ CONSTANT_TRANSLATION(DifferentiabilityWitnessFunctionInst, AssignFresh)
2477
+ CONSTANT_TRANSLATION(DifferentiableFunctionExtractInst, LookThrough)
2478
+ CONSTANT_TRANSLATION(LinearFunctionExtractInst, LookThrough)
2479
+ CONSTANT_TRANSLATION(LinearFunctionInst, Assign)
2480
+ CONSTANT_TRANSLATION(DifferentiableFunctionInst, Assign)
2481
+
2482
+ // ===---
2483
+ // Packs
2413
2484
//
2414
2485
2415
- CONSTANT_TRANSLATION(ObjCToThickMetatypeInst, Unhandled)
2416
- CONSTANT_TRANSLATION(ObjCMetatypeToObjectInst, Unhandled)
2417
- CONSTANT_TRANSLATION(ObjCExistentialMetatypeToObjectInst, Unhandled)
2418
- CONSTANT_TRANSLATION(WeakCopyValueInst, Unhandled)
2419
- CONSTANT_TRANSLATION(StrongCopyWeakValueInst, Unhandled)
2420
- CONSTANT_TRANSLATION(StrongCopyUnmanagedValueInst, Unhandled)
2421
- CONSTANT_TRANSLATION(LoadUnownedInst, Unhandled)
2422
- CONSTANT_TRANSLATION(ValueMetatypeInst, Unhandled)
2423
- CONSTANT_TRANSLATION(ExistentialMetatypeInst, Unhandled)
2424
- CONSTANT_TRANSLATION(VectorInst, Unhandled)
2425
- CONSTANT_TRANSLATION(TuplePackElementAddrInst, Unhandled)
2426
- CONSTANT_TRANSLATION(TuplePackExtractInst, Unhandled)
2427
- CONSTANT_TRANSLATION(PackElementGetInst, Unhandled)
2428
- CONSTANT_TRANSLATION(InitExistentialValueInst, Unhandled)
2429
- CONSTANT_TRANSLATION(InitExistentialMetatypeInst, Unhandled)
2430
- CONSTANT_TRANSLATION(OpenExistentialMetatypeInst, Unhandled)
2431
- CONSTANT_TRANSLATION(OpenExistentialValueInst, Unhandled)
2432
- CONSTANT_TRANSLATION(OpenPackElementInst, Unhandled)
2433
- CONSTANT_TRANSLATION(PackLengthInst, Unhandled)
2434
- CONSTANT_TRANSLATION(DynamicPackIndexInst, Unhandled)
2435
- CONSTANT_TRANSLATION(PackPackIndexInst, Unhandled)
2436
- CONSTANT_TRANSLATION(ScalarPackIndexInst, Unhandled)
2437
- CONSTANT_TRANSLATION(DifferentiableFunctionInst, Unhandled)
2438
- CONSTANT_TRANSLATION(LinearFunctionInst, Unhandled)
2439
- CONSTANT_TRANSLATION(DifferentiableFunctionExtractInst, Unhandled)
2440
- CONSTANT_TRANSLATION(LinearFunctionExtractInst, Unhandled)
2441
- CONSTANT_TRANSLATION(DifferentiabilityWitnessFunctionInst, Unhandled)
2442
- CONSTANT_TRANSLATION(GetAsyncContinuationInst, Unhandled)
2443
- CONSTANT_TRANSLATION(GetAsyncContinuationAddrInst, Unhandled)
2444
- CONSTANT_TRANSLATION(ExtractExecutorInst, Unhandled)
2445
- CONSTANT_TRANSLATION(BindMemoryInst, Unhandled)
2446
- CONSTANT_TRANSLATION(RebindMemoryInst, Unhandled)
2447
- CONSTANT_TRANSLATION(ThrowAddrInst, Unhandled)
2448
- CONSTANT_TRANSLATION(AwaitAsyncContinuationInst, Unhandled)
2449
- CONSTANT_TRANSLATION(DeallocPackInst, Unhandled)
2450
- CONSTANT_TRANSLATION(UnmanagedRetainValueInst, Unhandled)
2451
- CONSTANT_TRANSLATION(UnmanagedReleaseValueInst, Unhandled)
2452
- CONSTANT_TRANSLATION(UnmanagedAutoreleaseValueInst, Unhandled)
2453
- CONSTANT_TRANSLATION(BeginUnpairedAccessInst, Unhandled)
2454
- CONSTANT_TRANSLATION(EndUnpairedAccessInst, Unhandled)
2455
- CONSTANT_TRANSLATION(AssignInst, Unhandled)
2456
- CONSTANT_TRANSLATION(AssignByWrapperInst, Unhandled)
2457
- CONSTANT_TRANSLATION(AssignOrInitInst, Unhandled)
2458
- CONSTANT_TRANSLATION(MarkFunctionEscapeInst, Unhandled)
2459
- CONSTANT_TRANSLATION(PackElementSetInst, Unhandled)
2486
+ CONSTANT_TRANSLATION(DeallocPackInst, Ignored)
2487
+ CONSTANT_TRANSLATION(DynamicPackIndexInst, Ignored)
2488
+ CONSTANT_TRANSLATION(OpenPackElementInst, Ignored)
2489
+ CONSTANT_TRANSLATION(PackLengthInst, Ignored)
2490
+ CONSTANT_TRANSLATION(PackPackIndexInst, Ignored)
2491
+ CONSTANT_TRANSLATION(ScalarPackIndexInst, Ignored)
2460
2492
2461
2493
// ===---
2462
2494
// Apply
@@ -2488,6 +2520,16 @@ CONSTANT_TRANSLATION(UnownedRetainInst, Asserting)
2488
2520
CONSTANT_TRANSLATION(AllocPackMetadataInst, Asserting)
2489
2521
CONSTANT_TRANSLATION(DeallocPackMetadataInst, Asserting)
2490
2522
2523
+ // All of these instructions should be removed by DI which runs before us in the
2524
+ // pass pipeline.
2525
+ CONSTANT_TRANSLATION(AssignInst, Asserting)
2526
+ CONSTANT_TRANSLATION(AssignByWrapperInst, Asserting)
2527
+ CONSTANT_TRANSLATION(AssignOrInitInst, Asserting)
2528
+
2529
+ // We should never hit this since it can only appear as a final instruction in a
2530
+ // global variable static initializer list.
2531
+ CONSTANT_TRANSLATION(VectorInst, Asserting)
2532
+
2491
2533
#undef CONSTANT_TRANSLATION
2492
2534
2493
2535
#ifdef LOOKTHROUGH_IF_NONSENDABLE_RESULT_REQUIRE_OTHERWISE
@@ -2572,6 +2614,46 @@ CAST_WITH_MAYBE_SENDABLE_NONSENDABLE_OP_AND_RESULT(UncheckedValueCastInst)
2572
2614
// Custom Handling
2573
2615
//
2574
2616
2617
+ TranslationSemantics
2618
+ PartitionOpTranslator::visitPackElementGetInst (PackElementGetInst *r) {
2619
+ if (!isNonSendableType (r->getType ()))
2620
+ return TranslationSemantics::Require;
2621
+ translateSILAssign (SILValue (r), r->getPack ());
2622
+ return TranslationSemantics::Special;
2623
+ }
2624
+
2625
+ TranslationSemantics PartitionOpTranslator::visitTuplePackElementAddrInst (
2626
+ TuplePackElementAddrInst *r) {
2627
+ if (!isNonSendableType (r->getType ())) {
2628
+ translateSILRequire (r->getTuple ());
2629
+ } else {
2630
+ translateSILAssign (SILValue (r), r->getTuple ());
2631
+ }
2632
+ return TranslationSemantics::Special;
2633
+ }
2634
+
2635
+ TranslationSemantics
2636
+ PartitionOpTranslator::visitTuplePackExtractInst (TuplePackExtractInst *r) {
2637
+ if (!isNonSendableType (r->getType ())) {
2638
+ translateSILRequire (r->getTuple ());
2639
+ } else {
2640
+ translateSILAssign (SILValue (r), r->getTuple ());
2641
+ }
2642
+ return TranslationSemantics::Special;
2643
+ }
2644
+
2645
+ TranslationSemantics
2646
+ PartitionOpTranslator::visitPackElementSetInst (PackElementSetInst *r) {
2647
+ // If the value we are storing is sendable, treat this as a require.
2648
+ if (!isNonSendableType (r->getValue ()->getType ())) {
2649
+ return TranslationSemantics::Require;
2650
+ }
2651
+
2652
+ // Otherwise, this is a store.
2653
+ translateSILStore (r->getPackOperand (), r->getValueOperand ());
2654
+ return TranslationSemantics::Special;
2655
+ }
2656
+
2575
2657
TranslationSemantics
2576
2658
PartitionOpTranslator::visitRawPointerToRefInst (RawPointerToRefInst *r) {
2577
2659
assert (isLookThroughIfResultNonSendable (r) && " Out of sync" );
0 commit comments