blob: 4b3a9bd36c5563cae66b4fa6f40e01d93cf4949d (
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
Assign operation checks
=======================
Also applies to "writeonly" ref parameters.
Internal type states:
* var/const
* readable/writeonly
* known-uninitialized/maybe-initialized/initialized
* ownerless/arena-allocated/unowned/owned/ownership-returned/ownership-seeking
* tracked/untracked
(const + known-uninitialized/maybe-initialized are forbidden combinations)
Target mutability check
-----------------------
Ok if:
* target is var, or
* target is known-uninitialized
Source read possibility check
-----------------------------
Ok if:
* source if initialized and readable
Disappearing reference check
----------------------------
Ok if:
* target is ownerless/unowned, or
* target is arena-allocated (any arena), or
* target is ownership-returned
Appearing reference check
-------------------------
Ok if:
* source is ownerless, or
* target-variable is tracked, or
* target-variable is ownership-seeking
Tracked variables
=================
* Local variables
From these we can determine when the variable is first assinged and when it
is last read from.
Variable state and exceptions
=============================
"longjmp" exceptions make variable state tracking difficult.
We would need to track which functions can throw/longjmp
(or assume that all functions in external modules can throw/longjmp)
(or use jmpbuf's that we pass around)
try FatalErrorHandler jmpbuf1 {
# jmpbuf1 is owned by the try-block, during its whole execution,
# so ownership of it may not be transferred
# - should arenas still be valid when a fatal error occurs?
own ref List<TransformedElem> otherlist = .prealloc(list)
for ElemType elem in list {
own ref TransformedElem transformed = transform(elem, jmpbuff1)
otherlist.add(list)
}
} catch error {
# What is the status of otherlist and its elements here?
# Can we solve this be restricting exceptions:
# - No stack-owned variables at least
# - Arenas could be OK if the arena outlives the try-catch block
switch error { # open enum!
case .OutOfMemory:
# ...
default:
# ...
}
}
|