10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
+ #include " swift/SIL/ApplySite.h"
13
14
#include " swift/SIL/SILVisitor.h"
14
15
#include " swift/SIL/SILBuiltinVisitor.h"
15
16
#include " swift/SIL/SILModule.h"
@@ -346,14 +347,18 @@ ValueOwnershipKind ValueOwnershipKindClassifier::visitSILFunctionArgument(
346
347
return Arg->getOwnershipKind ();
347
348
}
348
349
349
- ValueOwnershipKind ValueOwnershipKindClassifier::visitApplyInst (ApplyInst *ai) {
350
- auto *f = ai->getFunction ();
351
- bool isTrivial = ai->getType ().isTrivial (*f);
350
+ // We have to separate out ResultType here as `begin_apply` does not produce
351
+ // normal results, `end_apply` does and there might be multiple `end_apply`'s
352
+ // that correspond to a single `begin_apply`.
353
+ static ValueOwnershipKind visitFullApplySite (FullApplySite fai,
354
+ SILType ResultType) {
355
+ auto *f = fai->getFunction ();
356
+ bool isTrivial = ResultType.isTrivial (*f);
352
357
// Quick is trivial check.
353
358
if (isTrivial)
354
359
return OwnershipKind::None;
355
360
356
- SILFunctionConventions fnConv (ai-> getSubstCalleeType (), f->getModule ());
361
+ SILFunctionConventions fnConv (fai. getSubstCalleeType (), f->getModule ());
357
362
auto results = fnConv.getDirectSILResults ();
358
363
// No results => None.
359
364
if (results.empty ())
@@ -362,7 +367,7 @@ ValueOwnershipKind ValueOwnershipKindClassifier::visitApplyInst(ApplyInst *ai) {
362
367
// Otherwise, map our results to their ownership kinds and then merge them!
363
368
auto resultOwnershipKinds =
364
369
makeTransformRange (results, [&](const SILResultInfo &info) {
365
- return info.getOwnershipKind (*f, ai-> getSubstCalleeType ());
370
+ return info.getOwnershipKind (*f, fai. getSubstCalleeType ());
366
371
});
367
372
auto mergedOwnershipKind = ValueOwnershipKind::merge (resultOwnershipKinds);
368
373
if (!mergedOwnershipKind) {
@@ -372,31 +377,12 @@ ValueOwnershipKind ValueOwnershipKindClassifier::visitApplyInst(ApplyInst *ai) {
372
377
return mergedOwnershipKind;
373
378
}
374
379
375
- ValueOwnershipKind ValueOwnershipKindClassifier::visitEndApplyInst (EndApplyInst *eai) {
376
- auto *bai = eai->getBeginApply ();
377
- auto *f = bai->getFunction ();
378
- bool isTrivial = eai->getType ().isTrivial (*f);
379
- // Quick is trivial check.
380
- if (isTrivial)
381
- return OwnershipKind::None;
382
-
383
- SILFunctionConventions fnConv (bai->getSubstCalleeType (), f->getModule ());
384
- auto results = fnConv.getDirectSILResults ();
385
- // No results => None.
386
- if (results.empty ())
387
- return OwnershipKind::None;
388
-
389
- // Otherwise, map our results to their ownership kinds and then merge them!
390
- auto resultOwnershipKinds =
391
- makeTransformRange (results, [&](const SILResultInfo &info) {
392
- return info.getOwnershipKind (*f, bai->getSubstCalleeType ());
393
- });
394
- auto mergedOwnershipKind = ValueOwnershipKind::merge (resultOwnershipKinds);
395
- if (!mergedOwnershipKind) {
396
- llvm_unreachable (" Forwarding inst with mismatching ownership kinds?!" );
397
- }
380
+ ValueOwnershipKind ValueOwnershipKindClassifier::visitApplyInst (ApplyInst *ai) {
381
+ return visitFullApplySite (ai, ai->getType ());
382
+ }
398
383
399
- return mergedOwnershipKind;
384
+ ValueOwnershipKind ValueOwnershipKindClassifier::visitEndApplyInst (EndApplyInst *eai) {
385
+ return visitFullApplySite (eai->getBeginApply (), eai->getType ());
400
386
}
401
387
402
388
ValueOwnershipKind ValueOwnershipKindClassifier::visitLoadInst (LoadInst *LI) {
0 commit comments