You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ownership.md
+6-53Lines changed: 6 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
2
-
Last Updated 3 March 2025
2
+
Last Updated 5 December 2025
3
3
4
4
This is a work in progress. Cake source is currently being used to validate the concepts. It's in the process of transitioning to include annotated nullable checks, which was the last feature added.
5
5
@@ -159,42 +159,8 @@ If `is_empty` changes, it could potentially invalidate the assert on the caller'
159
159
Although a runtime check is in place, it is not as safe as a compile-time check because it may occur
160
160
within a rarely used branch, allowing the bug to remain inactive.
161
161
162
-
For this reason, a 'contract' approach is also being developed in Cake, *__although it
163
-
is still in the early stages of design__*.
164
-
165
-
We can specify the post-conditions for the results of true and false branches using `true` and `false`
166
-
at the function declaration, as well as for void functions using `post`
167
-
168
-
```c
169
-
#pragma safety enable
170
-
171
-
struct X {
172
-
int * _Opt data;
173
-
};
174
-
175
-
bool is_empty(const struct X * p)
176
-
true(p->data == 0),
177
-
false(p->data != 0)
178
-
{
179
-
return p->data == nullptr;
180
-
}
181
-
182
-
void clear(struct X * p)
183
-
post(p->data == 0)
184
-
{
185
-
p->data = nullptr;
186
-
}
187
-
188
-
void f(struct X * p)
189
-
{
190
-
if (!is_empty(p)) {
191
-
/*assert not required anymore*/
192
-
*p->data = 1;
193
-
}
194
-
}
195
-
```
196
-
197
-
<buttononclick="Try(this)">try</button>
162
+
For this reason, a 'contract' approach is also being developed in Cake with the objective of moving
163
+
the assert to function `is_empty` contract.
198
164
199
165
The advantage of contracts, as mentioned earlier, is that the postconditions are
200
166
located in a single place. This is useful not only to avoid code repetition but
@@ -203,9 +169,6 @@ which are assumed to be true and may be dangerous if they are out of sync
203
169
with the implementation.
204
170
On the other hand, placing the contracts alongside the function declaration
205
171
keeps the contract closer to its implementation.
206
-
Compilers (though Cake is not currently doing this yet) could create proxy
207
-
functions to check postconditions at runtime. (See C++ 26 contracts)
208
-
209
172
210
173
211
174
#### Non nullable members initialization
@@ -309,17 +272,7 @@ void f() {
309
272
310
273
<buttononclick="Try(this)">try</button>
311
274
312
-
We could remove this built-in some something like
313
-
314
-
```c
315
-
#pragma nullable enable
316
-
_Uninitialized void * _Opt malloc(unsigned int sz);
317
-
```
318
-
319
-
This is not implemented yet.
320
-
321
-
322
-
`calloc` has a built in semantics indicating the object is zero-initialized.
275
+
`calloc` has a built in semantics indicating the object is zero-initialized.
0 commit comments