-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathnames.ml
145 lines (120 loc) · 3.12 KB
/
names.ml
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
(* TEST_BELOW
(* Blank lines added here to preserve locations. *)
*)
let id x = Sys.opaque_identity x
let[@inline never] bang () = raise Exit
let[@inline never] fn_multi _ _ f = f 42 + 1
let[@inline never] fn_function = function
| f -> f 42 + 1
let[@inline never] fn_poly : 'a . 'a -> ('a -> int) -> int = fun x f ->
f x + 1
module Mod1 = struct
module Nested = struct
let[@inline never] apply f = f 42 + 1
end
end
let[@inline never] anon f =
let fn = id (fun () -> f 42 + 1) in
fn ()
let[@inline never] double_anon f =
let fn = id (fun () ->
let fn = id (fun () ->
f 42 + 1) in
fn ()) in
fn ()
let[@inline never] local f =
let[@inline never] inner () = f 42 + 1 in
(id inner) () + 1
let[@inline never] double_local f =
let inner1 () =
let inner2 () = f 42 + 1 in
(id inner2) () + 1 in
(id inner1) () + 1
let local_no_arg =
let inner f = f 42 + 1 in
fun[@inline never] f -> (id inner) f + 1
let[@inline never] curried () =
let inner () f = f 42 in
id (inner ())
let[@inline never] local_module f =
let module N = struct
let[@inline never] foo () =
f 42 + 1
let r = ref 0 let () = r := id (id foo ())
end in
!N.r
module Functor (X : sig end) = struct
let[@inline never] fn f = f 42 + 1
end
module Inst = Functor (struct end)
module rec Rec1 : sig
val fn : (int -> int) -> int
end = struct
module M = Rec2 (struct end)
let[@inline never] fn f = M.fn f + 1
end
and Rec2 : functor (X : sig end) -> sig
val fn : (int -> int) -> int
end = functor (X : sig end) -> struct
let[@inline never] fn f = f 42 + 1
end
let[@inline never] (+@+) n f = f 42 + 1
(* [nested] shows up in the backtrace as [nested.(fun)] because
it creates an inner lambda. In contrast, [flat]'s arity is syntactically
2 and does not create an inner lambda.
*)
let[@inline never] flat = fun x f -> f x + 1
let[@inline never] nested x = fun[@inline never] f -> f x + 1
class klass = object (self)
val other = new klass2 "asdf"
method meth f : int =
other#othermeth 1 1 f 1 + 1
end
and klass2 _v = object (self)
method othermeth _ _ f _ =
(id (fun g -> g 42 + 1) f) + 1
end
let inline_object f =
let obj = object (self)
method meth : int =
self#othermeth 1 f 1 + 1
method othermeth _ _ _ =
f 42 + 1
end in
obj#meth
let[@inline never] lazy_ f =
let x = Sys.opaque_identity (lazy (1 + f ())) in
Lazy.force x
let[@inline never] nontailcall f =
f () [@nontail]
let () =
Printexc.record_backtrace true;
match
fn_multi 1 1 @@ fun _ ->
fn_function @@ fun _ ->
fn_poly 42 @@ fun _ ->
Mod1.Nested.apply @@ fun _ ->
anon @@ fun _ ->
double_anon @@ fun _ ->
local @@ fun _ ->
double_local @@ fun _ ->
local_no_arg @@ fun _ ->
curried () @@ fun _ ->
local_module @@ fun _ ->
Inst.fn @@ fun _ ->
Rec1.fn @@ fun _ ->
42 +@+ fun _ ->
flat 7 @@ fun _ ->
nested 5 @@ fun _ ->
(new klass)#meth @@ fun _ ->
inline_object @@ fun _ ->
lazy_ @@ fun _ ->
nontailcall @@ fun _ ->
bang ()
with
| _ -> assert false
| exception Exit ->
Printexc.print_backtrace stdout
(* TEST
flags = "-g";
*)