@@ -106,6 +106,10 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
106106 SILVerifier (const SILVerifier&) = delete ;
107107 void operator =(const SILVerifier&) = delete ;
108108public:
109+ bool isSILOwnershipEnabled () const {
110+ return F.getModule ().getOptions ().EnableSILOwnership ;
111+ }
112+
109113 void _require (bool condition, const Twine &complaint,
110114 const std::function<void ()> &extraContext = nullptr) {
111115 if (condition) return ;
@@ -128,11 +132,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
128132 }
129133#define require (condition, complaint ) \
130134 _require (bool (condition), complaint " : " #condition)
131- #define requireTrueOrNone (condition, complaint ) \
132- _require (!condition.hasValue() || bool (condition.getValue()), \
133- complaint " : " #condition)
134- #define requireFalseOrNone (condition, complaint ) \
135- _require (!condition.hasValue() || !bool (condition.getValue()), \
135+ #define requireTrueAndSILOwnership (verifier, condition, complaint ) \
136+ _require (!verifier->isSILOwnershipEnabled () || bool(condition), \
136137 complaint ": " #condition)
137138
138139 template <class T > typename CanTypeWrapperTraits<T>::type
@@ -1122,23 +1123,23 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
11221123 case LoadOwnershipQualifier::Unqualified:
11231124 // We should not see loads with unqualified ownership when SILOwnership is
11241125 // enabled.
1125- requireFalseOrNone (
1126- F. hasQualifiedOwnership (),
1126+ requireTrueAndSILOwnership (
1127+ this , F. hasUnqualifiedOwnership (),
11271128 " Load with unqualified ownership in a qualified function" );
11281129 break ;
11291130 case LoadOwnershipQualifier::Copy:
11301131 case LoadOwnershipQualifier::Take:
1131- requireTrueOrNone (
1132- F.hasQualifiedOwnership (),
1132+ requireTrueAndSILOwnership (
1133+ this , F.hasQualifiedOwnership (),
11331134 " Load with qualified ownership in an unqualified function" );
11341135 // TODO: Could probably make this a bit stricter.
11351136 require (!LI->getType ().isTrivial (LI->getModule ()),
11361137 " load [copy] or load [take] can only be applied to non-trivial "
11371138 " types" );
11381139 break ;
11391140 case LoadOwnershipQualifier::Trivial:
1140- requireTrueOrNone (
1141- F.hasQualifiedOwnership (),
1141+ requireTrueAndSILOwnership (
1142+ this , F.hasQualifiedOwnership (),
11421143 " Load with qualified ownership in an unqualified function" );
11431144 require (LI->getType ().isTrivial (LI->getModule ()),
11441145 " A load with trivial ownership must load a trivial type" );
@@ -1147,8 +1148,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
11471148 }
11481149
11491150 void checkLoadBorrowInst (LoadBorrowInst *LBI) {
1150- requireTrueOrNone (
1151- F.hasQualifiedOwnership (),
1151+ requireTrueAndSILOwnership (
1152+ this , F.hasQualifiedOwnership (),
11521153 " Inst with qualified ownership in a function that is not qualified" );
11531154 require (LBI->getType ().isObject (), " Result of load must be an object" );
11541155 require (LBI->getType ().isLoadable (LBI->getModule ()),
@@ -1160,8 +1161,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
11601161 }
11611162
11621163 void checkEndBorrowInst (EndBorrowInst *EBI) {
1163- requireTrueOrNone (
1164- F.hasQualifiedOwnership (),
1164+ requireTrueAndSILOwnership (
1165+ this , F.hasQualifiedOwnership (),
11651166 " Inst with qualified ownership in a function that is not qualified" );
11661167 // We allow for end_borrow to express relationships in between addresses and
11671168 // values, but we require that the types are the same ignoring value
@@ -1187,22 +1188,22 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
11871188 case StoreOwnershipQualifier::Unqualified:
11881189 // We should not see loads with unqualified ownership when SILOwnership is
11891190 // enabled.
1190- requireFalseOrNone (F. hasQualifiedOwnership (),
1191- " Invalid load with unqualified ownership" );
1191+ requireTrueAndSILOwnership ( this , F. hasUnqualifiedOwnership (),
1192+ " Invalid load with unqualified ownership" );
11921193 break ;
11931194 case StoreOwnershipQualifier::Init:
11941195 case StoreOwnershipQualifier::Assign:
1195- requireTrueOrNone (
1196- F.hasQualifiedOwnership (),
1196+ requireTrueAndSILOwnership (
1197+ this , F.hasQualifiedOwnership (),
11971198 " Inst with qualified ownership in a function that is not qualified" );
11981199 // TODO: Could probably make this a bit stricter.
11991200 require (!SI->getSrc ()->getType ().isTrivial (SI->getModule ()),
12001201 " store [init] or store [assign] can only be applied to "
12011202 " non-trivial types" );
12021203 break ;
12031204 case StoreOwnershipQualifier::Trivial:
1204- requireTrueOrNone (
1205- F.hasQualifiedOwnership (),
1205+ requireTrueAndSILOwnership (
1206+ this , F.hasQualifiedOwnership (),
12061207 " Inst with qualified ownership in a function that is not qualified" );
12071208 require (SI->getSrc ()->getType ().isTrivial (SI->getModule ()),
12081209 " A store with trivial ownership must store a trivial type" );
@@ -1352,17 +1353,19 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
13521353 void checkCopyValueInst (CopyValueInst *I) {
13531354 require (I->getOperand ()->getType ().isObject (),
13541355 " Source value should be an object value" );
1355- requireTrueOrNone (F.hasQualifiedOwnership (),
1356- " copy_value is only valid in functions with qualified "
1357- " ownership" );
1356+ requireTrueAndSILOwnership (
1357+ this , F.hasQualifiedOwnership (),
1358+ " copy_value is only valid in functions with qualified "
1359+ " ownership" );
13581360 }
13591361
13601362 void checkDestroyValueInst (DestroyValueInst *I) {
13611363 require (I->getOperand ()->getType ().isObject (),
13621364 " Source value should be an object value" );
1363- requireTrueOrNone (F.hasQualifiedOwnership (),
1364- " destroy_value is only valid in functions with qualified "
1365- " ownership" );
1365+ requireTrueAndSILOwnership (
1366+ this , F.hasQualifiedOwnership (),
1367+ " destroy_value is only valid in functions with qualified "
1368+ " ownership" );
13661369 }
13671370
13681371 void checkReleaseValueInst (ReleaseValueInst *I) {
0 commit comments