@@ -738,15 +738,19 @@ forwardIntoSubtree(SILGenFunction &SGF, SILLocation loc,
738
738
ManagedValue outerMV = outerCMV.getFinalManagedValue ();
739
739
if (!outerMV.hasCleanup ()) return outerCMV;
740
740
741
- assert (outerCMV.getFinalConsumption () != CastConsumptionKind::CopyOnSuccess
742
- && " copy-on-success value with cleanup?" );
741
+ auto consumptionKind = outerCMV.getFinalConsumption ();
742
+ (void )consumptionKind;
743
+ assert ((consumptionKind == CastConsumptionKind::TakeAlways ||
744
+ consumptionKind == CastConsumptionKind::TakeOnSuccess) &&
745
+ " non-+1 consumption with a cleanup?" );
743
746
scope.pushCleanupState (outerMV.getCleanup (),
744
747
CleanupState::PersistentlyActive);
745
748
746
- // If SILOwnership is enabled, we always forward down values as borrows that
747
- // are copied on success.
748
- if (SGF.F .getModule ().getOptions ().EnableSILOwnership ) {
749
- return {outerMV.borrow (SGF, loc), CastConsumptionKind::CopyOnSuccess};
749
+ // If SILOwnership is enabled and we have an object, borrow instead of take on
750
+ // success.
751
+ if (SGF.F .getModule ().getOptions ().EnableSILOwnership &&
752
+ outerMV.getType ().isObject ()) {
753
+ return {outerMV.borrow (SGF, loc), CastConsumptionKind::BorrowAlways};
750
754
}
751
755
752
756
// Success means that we won't end up in the other branch,
@@ -766,9 +770,6 @@ static void forwardIntoIrrefutableSubtree(SILGenFunction &SGF,
766
770
767
771
assert (outerCMV.getFinalConsumption () != CastConsumptionKind::CopyOnSuccess
768
772
&& " copy-on-success value with cleanup?" );
769
- assert ((!SGF.F .getModule ().getOptions ().EnableSILOwnership ||
770
- outerCMV.getFinalConsumption () == CastConsumptionKind::TakeAlways) &&
771
- " When semantic sil is enabled, we should never see TakeOnSuccess" );
772
773
scope.pushCleanupState (outerMV.getCleanup (),
773
774
CleanupState::PersistentlyActive);
774
775
@@ -899,7 +900,8 @@ class ArgUnforwarder {
899
900
900
901
static bool requiresUnforwarding (SILGenFunction &SGF,
901
902
ConsumableManagedValue operand) {
902
- if (SGF.F .getModule ().getOptions ().EnableSILOwnership ) {
903
+ if (SGF.F .getModule ().getOptions ().EnableSILOwnership &&
904
+ operand.getType ().isObject ()) {
903
905
assert (operand.getFinalConsumption () !=
904
906
CastConsumptionKind::TakeOnSuccess &&
905
907
" When compiling with sil ownership take on success is disabled" );
@@ -1356,9 +1358,6 @@ getManagedSubobject(SILGenFunction &SGF, SILValue value,
1356
1358
return {ManagedValue::forUnmanaged (value), consumption};
1357
1359
case CastConsumptionKind::TakeAlways:
1358
1360
case CastConsumptionKind::TakeOnSuccess:
1359
- assert ((!SGF.F .getModule ().getOptions ().EnableSILOwnership ||
1360
- consumption != CastConsumptionKind::TakeOnSuccess) &&
1361
- " TakeOnSuccess should never be used when sil ownership is enabled" );
1362
1361
return {SGF.emitManagedRValueWithCleanup (value, valueTL), consumption};
1363
1362
}
1364
1363
}
@@ -1882,8 +1881,6 @@ void PatternMatchEmission::emitEnumElementDispatch(
1882
1881
break ;
1883
1882
1884
1883
case CastConsumptionKind::TakeOnSuccess:
1885
- assert (!SGF.F .getModule ().getOptions ().EnableSILOwnership &&
1886
- " TakeOnSuccess is not supported when compiling with ownership" );
1887
1884
// If any of the specialization cases is refutable, we must copy.
1888
1885
if (!blocks.hasAnyRefutableCase ())
1889
1886
break ;
@@ -1966,8 +1963,6 @@ void PatternMatchEmission::emitEnumElementDispatch(
1966
1963
auto eltConsumption = src.getFinalConsumption ();
1967
1964
if (caseInfo.Irrefutable &&
1968
1965
eltConsumption == CastConsumptionKind::TakeOnSuccess) {
1969
- assert (!SGF.F .getModule ().getOptions ().EnableSILOwnership &&
1970
- " TakeOnSuccess is not supported when compiling with ownership" );
1971
1966
eltConsumption = CastConsumptionKind::TakeAlways;
1972
1967
}
1973
1968
@@ -2760,8 +2755,9 @@ void SILGenFunction::emitCatchDispatch(DoCatchStmt *S, ManagedValue exn,
2760
2755
// Set up an initial clause matrix.
2761
2756
ClauseMatrix clauseMatrix (clauseRows);
2762
2757
ConsumableManagedValue subject;
2763
- if (F.getModule ().getOptions ().EnableSILOwnership ) {
2764
- subject = {exn.borrow (*this , S), CastConsumptionKind::CopyOnSuccess};
2758
+ if (F.getModule ().getOptions ().EnableSILOwnership &&
2759
+ exn.getType ().isObject ()) {
2760
+ subject = {exn.borrow (*this , S), CastConsumptionKind::BorrowAlways};
2765
2761
} else {
2766
2762
subject = {exn, CastConsumptionKind::TakeOnSuccess};
2767
2763
}
0 commit comments