File tree Expand file tree Collapse file tree 4 files changed +44
-35
lines changed Expand file tree Collapse file tree 4 files changed +44
-35
lines changed Original file line number Diff line number Diff line change @@ -1969,7 +1969,7 @@ class SILBuilder {
1969
1969
1970
1970
ReturnInst *createReturn (SILLocation Loc, SILValue ReturnValue) {
1971
1971
return insertTerminator (new (getModule ()) ReturnInst (
1972
- getSILDebugLocation (Loc), ReturnValue));
1972
+ getFunction (), getSILDebugLocation (Loc), ReturnValue));
1973
1973
}
1974
1974
1975
1975
ThrowInst *createThrow (SILLocation Loc, SILValue errorValue) {
Original file line number Diff line number Diff line change @@ -7366,16 +7366,25 @@ class ReturnInst
7366
7366
{
7367
7367
friend SILBuilder;
7368
7368
7369
+ // / We store the ownership kind in the return inst, but we do not consider the
7370
+ // / underlying return inst to be forwarding. This is because its ownership is
7371
+ // / tied to the function signature and thus should be static.
7372
+ ValueOwnershipKind ownershipKind;
7373
+
7369
7374
// / Constructs a ReturnInst representing a return.
7370
7375
// /
7371
- // / \param DebugLoc The backing AST location.
7372
- // /
7373
- // / \param ReturnValue The value to be returned .
7374
- // /
7375
- ReturnInst (SILDebugLocation DebugLoc, SILValue ReturnValue)
7376
- : UnaryInstructionBase(DebugLoc, ReturnValue) {}
7376
+ // / \param func The function we are returning from. Used to compute the
7377
+ // / preferred ownership kind.
7378
+ // / \param debugLoc The backing AST location .
7379
+ // / \param returnValue The value to be returned.
7380
+ ReturnInst (SILFunction &func, SILDebugLocation debugLoc,
7381
+ SILValue returnValue);
7377
7382
7378
7383
public:
7384
+ // / Return the ownership kind for this instruction if we had any direct
7385
+ // / results.
7386
+ ValueOwnershipKind getOwnershipKind () const { return ownershipKind; }
7387
+
7379
7388
SuccessorListTy getSuccessors () {
7380
7389
// No Successors.
7381
7390
return SuccessorListTy ();
Original file line number Diff line number Diff line change @@ -433,36 +433,11 @@ OperandOwnershipKindClassifier::visitCheckedCastBranchInst(
433
433
return Map::compatibilityMap (kind, lifetimeConstraint);
434
434
}
435
435
436
- // // FIX THIS HERE
437
436
OperandOwnershipKindMap
438
437
OperandOwnershipKindClassifier::visitReturnInst (ReturnInst *ri) {
439
- auto *f =ri->getFunction ();
440
-
441
- // If we have a trivial value, return allLive().
442
- bool isTrivial = ri->getOperand ()->getType ().isTrivial (*f);
443
- if (isTrivial) {
444
- return Map::allLive ();
445
- }
446
-
447
- SILFunctionConventions fnConv = f->getConventions ();
448
-
449
- auto results = fnConv.getDirectSILResults ();
450
- if (results.empty ())
451
- return Map ();
452
-
453
- auto ownershipKindRange = makeTransformRange (results,
454
- [&](const SILResultInfo &info) {
455
- return info.getOwnershipKind (*f, f->getLoweredFunctionType ());
456
- });
457
-
458
- // Then merge all of our ownership kinds. If we fail to merge, return an empty
459
- // map so we fail on all operands.
460
- auto mergedBase = ValueOwnershipKind::merge (ownershipKindRange);
461
- if (!mergedBase)
462
- return Map ();
463
-
464
- auto base = *mergedBase;
465
- return Map::compatibilityMap (base, base.getForwardingLifetimeConstraint ());
438
+ auto kind = ri->getOwnershipKind ();
439
+ auto lifetimeConstraint = kind.getForwardingLifetimeConstraint ();
440
+ return Map::compatibilityMap (kind, lifetimeConstraint);
466
441
}
467
442
468
443
OperandOwnershipKindMap
Original file line number Diff line number Diff line change @@ -2863,3 +2863,28 @@ bool GetAsyncContinuationInstBase::throws() const {
2863
2863
return getType ().castTo <BoundGenericType>()->getDecl ()
2864
2864
== getFunction ()->getASTContext ().getUnsafeThrowingContinuationDecl ();
2865
2865
}
2866
+
2867
+ ReturnInst::ReturnInst (SILFunction &func, SILDebugLocation debugLoc,
2868
+ SILValue returnValue)
2869
+ : UnaryInstructionBase(debugLoc, returnValue),
2870
+ ownershipKind(ValueOwnershipKind::None) {
2871
+ // If we have a trivial value, leave our ownership kind as none.
2872
+ if (returnValue->getType ().isTrivial (func))
2873
+ return ;
2874
+
2875
+ SILFunctionConventions fnConv = func.getConventions ();
2876
+
2877
+ // If we do not have any direct SIL results, we should accept a tuple
2878
+ // argument, meaning that we should have a none ownership kind.
2879
+ auto results = fnConv.getDirectSILResults ();
2880
+ if (results.empty ())
2881
+ return ;
2882
+
2883
+ auto ownershipKindRange =
2884
+ makeTransformRange (results, [&](const SILResultInfo &info) {
2885
+ return info.getOwnershipKind (func, func.getLoweredFunctionType ());
2886
+ });
2887
+
2888
+ // Then merge all of our ownership kinds. Assert if we fail to merge.
2889
+ ownershipKind = *ValueOwnershipKind::merge (ownershipKindRange);
2890
+ }
You can’t perform that action at this time.
0 commit comments