-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrimOp-WeakPtr.dl
91 lines (82 loc) · 3.01 KB
/
PrimOp-WeakPtr.dl
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
HINT: is interpreted -/+
primop effectful
+ "mkWeak#" :: %o -> %b -> ({"State#" {RealWorld}} -> {"GHC.Prim.Unit#" %c}) -> {"State#" {RealWorld}} -> {"GHC.Prim.Unit#" {"Weak#" %b}}
+ "mkWeakNoFinalizer#" :: %o -> %b -> {"State#" {RealWorld}} -> {"GHC.Prim.Unit#" {"Weak#" %b}}
- "addCFinalizerToWeak#" :: T_Addr -> T_Addr -> T_Int64 -> T_Addr -> {"Weak#" %b} -> {"State#" {RealWorld}} -> {"GHC.Prim.Unit#" T_Int64}
+ "deRefWeak#" :: {"Weak#" %a} -> {"State#" {RealWorld}} -> {"GHC.Prim.(#,#)" T_Int64 %a}
+ "finalizeWeak#" :: {"Weak#" %a} -> {"State#" {RealWorld}} -> {"GHC.Prim.(#,#)" T_Int64 ({"State#" {RealWorld}} -> {"GHC.Prim.Unit#" %b})}
- "touch#" :: %o -> {"State#" {RealWorld}} -> {"GHC.Prim.(##)"}
*/
.decl WeakPtr(ext_result:Variable, ty_node:Variable, item:Variable)
.output WeakPtr
.decl WeakFinalizer(ext_result:Variable, finalizer:Variable)
.output WeakFinalizer
// workaround for reachability calculation
HasInst("mkWeak#", "mkWeak#-finalizer-ignored-result").
// "mkWeak#" :: %o -> %b -> ({"State#" {RealWorld}} -> {"GHC.Prim.Unit#" %c}) -> {"State#" {RealWorld}} -> {"GHC.Prim.Unit#" {"Weak#" %b}}
// new weak ptr
USED("PrimOp-WeakPtr-01")
//Called(r, op),
CallPNode1(r, "mkWeak#-finalizer-ignored-result", finalizer, v3_state), // TRICK: swap name space and result var in order to ignore the result value
WeakFinalizer(r, finalizer),
WeakPtr(r, ty_node, item) :-
op = "mkWeak#",
Call(r, op, _),
// value
CallArgument(r, 1, item),
// finalizer
CallArgument(r, 2, finalizer),
// state
CallArgument(r, 3, v3_state),
// extract result node
RetTup1Node0(op, ty_node),
NEW_REACHABLE(r)
.
// CHECKED
// "mkWeakNoFinalizer#" :: %o -> %b -> {"State#" {RealWorld}} -> {"GHC.Prim.Unit#" {"Weak#" %b}}
// new weak ptr
USED("PrimOp-WeakPtr-02")
//Called(r, op),
WeakPtr(r, ty_node, item) :-
op = "mkWeakNoFinalizer#",
Call(r, op, _),
// value
CallArgument(r, 1, item),
// extract result node
RetTup1Node0(op, ty_node),
NEW_REACHABLE(r)
.
// CHECKED
// "deRefWeak#" :: {"Weak#" %a} -> {"State#" {RealWorld}} -> {"GHC.Prim.(#,#)" T_Int64 %a}
USED("PrimOp-WeakPtr-03")
//Called(r, op),
TypeVarPointsTo(r, ty_node, item) :-
op = "deRefWeak#",
Call(r, op, _),
// lookup weak ptr items
CallArgument(r, 0, arr),
ExternalOrigin(arr, ext_result, arr_node),
WeakPtr(ext_result, arr_node, item),
// lookup result node
RetTup(op, "GHC.Prim.(#,#)", 1, ty_node),
NEW_REACHABLE(r)
.
// CHECKED
// "finalizeWeak#" :: {"Weak#" %a}
// -> {"State#" {RealWorld}}
// -> {"GHC.Prim.(#,#)" T_Int64 ({"State#" {RealWorld}} -> {"GHC.Prim.Unit#" %b})}
USED("PrimOp-WeakPtr-04")
//Called(r, op),
TypeVarPointsTo(r, ty_node, finalizer) :-
op = "finalizeWeak#",
Call(r, op, _),
// lookup weak ptr items
CallArgument(r, 0, arr),
ExternalOrigin(arr, ext_result, _),
WeakFinalizer(ext_result, finalizer),
// lookup result node
RetTup(op, "GHC.Prim.(#,#)", 1, ty_node),
NEW_REACHABLE(r)
.
// CHECKED