Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 92 lines (73 sloc) 2.774 kb
936d60a [feature] closure serialisation: adding closure instrumentation (compile...
Valentin Gatien-Baron authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18
2536662 @OpaOnWindowsNow [feature] closure serialisation: restrict to new @public_env directive
OpaOnWindowsNow authored
19 val warning_set : WarningClass.Set.t
20
21 val process_code : QmlTypes.gamma -> QmlAst.annotmap -> QmlAst.code -> QmlTypes.gamma * QmlAst.annotmap * QmlAst.code * IdentSet.t
936d60a [feature] closure serialisation: adding closure instrumentation (compile...
Valentin Gatien-Baron authored
22
23 (*
24 The transformation related to closure serialization is as follows:
25
26 --- Source code
27 f(x:list) =
28 g(y) = (x,y)
29 (g,g(1))
30
31 --- After the early lambda lifting
32 g(x,y) = (x,y)
33 f(x) =
34 (@partial_apply(g(x)),g(x,1))
35
36 --- After instrumentation by this pass
37 g(x,y) = (x,y)
38 g'(x) = @partial_apply(g(x),@typeof(x))
39 f(x) =
40 (g'(x),g(x,1))
41
42 --- After ei
43 g(x,y) = (x,y)
44 g'(ty,x) = @partial_apply(g(x),list(ty))
45 f(ty,x) =
46 (g'(ty,x),g(x,1))
47
48 --- After closures, assuming no cps:
49 g(x,y) = (x,y)
50 clos_g = %%closure_create%%(g,2,true)
51 g'(ty,x) = %%closure_apply_env_with_ty%%(clos_g,@llarray(x),@llarray(list(ty)))
52 // no need to create a closure for g', it is the code that creates the closures
53 f(ty,x) =
54 (g'(ty,x),g(x,1))
55 clos_f = %%closure_create%%(f,2,true)
56
57
58 And the more complicated case, where the lifted function is recursive through its closure:
59 --- Source code
60 id(x) = x
61 f(x:list) =
62 rec g(y) = if true then x else id(g)(y)
63 g
64
65 --- After early ll
66 id(x) = x
67 rec g(x,y) = if true then x else id(@partial_apply(g(x)))(y)
68 f(x) =
69 @partial_apply(g(x))
70
71 --- After instrumentation
72 id(x) = x
73 rec g(x,y) = if true then x else id(g'(x))(y)
74 and g'(x) = @partial_apply(g(x),OpaType.ty,@typeof(x)) // tricky case, we must anticipate
75 // the addition of a typevar by ei
76 f(x) = g'(x)
77
78 --- After ei
79 id(x) = x
80 rec g(ty,x,y) = if true then x else id(g'(ty,x))(y)
81 and g'(ty,x) = @partial_apply(g(ty,x),OpaType.ty,list(ty))
82 f(ty,x) = g'(ty,x)
83
84 --- After closures:
85 id(x) = x
86 clos_id(x) = %%closure_create%%(id,1,true)
87 clos_g = %% closure_create_no_function%%(3,true)
88 rec g(ty,x,y) = if true then x else @clos_apply(id(g'(ty,x)),y)
89 and g'(ty,x) = %%closure_apply_env_with_ty%%(clos_g,@llarray(ty,x),@llarray(OpaType.ty,list(ty)))
90 f(ty,x) = g'(ty,x)
91 *)
Something went wrong with that request. Please try again.