blob: c987aab172e80420229c1921c332b200711ade82 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
Typestates
==========
Simple typestates
-----------------
(Copied from syntaxtest.txt)
type Lock = struct { ... }
# only one type state in a typestate group can be active at a time.
typestate Lock { noforget Locked, Available }
# it is still a void return type
func var threaded Lock.lock() [[Available]] -> [[Locked]]
func var threaded Lock.release() [[Locked]] -> [[Available]]
Or maybe this syntax:
type Lock = struct { ... }
# only one type state in a typestate group can be active at a time.
typestate Lock { noforget Locked, Available }
func var threaded Lock.lock()
from Available
to Locked
func var threaded Lock.release()
from Locked
to Available
"Coupled-object" typestates
---------------------------
E.g. for allocations, if de-allocation has to be done with the
same allocator as allocation.
Typestate-preserving functions
------------------------------
typestate string { ValidUtf8 }
func arena string.reverse() -> string
?[[ValidUtf8]] -> [[ValidUtf8]]
func arena string.reverse() -> string
preserves ValidUtf8
|