Skip to content

Commit dc6680b

Browse files
committed
Automatic changes done with ciao-lwt
1 parent d988477 commit dc6680b

File tree

81 files changed

+3630
-3595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3630
-3595
lines changed

src/lib/client/eliommod_dom.ml

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open Lwt.Syntax
1+
open Eio.Std
22

33
(* Ocsigen
44
* http://www.ocsigen.org
@@ -479,7 +479,7 @@ let fetch_linked_css e =
479479
let css =
480480
Eliom_request.http_get href [] Eliom_request.string_result
481481
in
482-
acc @ [e, (e##.media, href, css >|= snd)]
482+
acc @ [e, (e##.media, href, snd css)]
483483
| Dom.Element e ->
484484
let c = e##.childNodes in
485485
let acc = ref acc in
@@ -578,26 +578,25 @@ let rewrite_css_url ~prefix css pos =
578578
let import_re = Regexp.regexp "@import\\s*"
579579

580580
let rec rewrite_css ~max (media, href, css) =
581-
Lwt.catch
582-
(fun () ->
583-
css >>= function
584-
| None -> Lwt.return_nil
585-
| Some css ->
586-
if !Eliom_config.debug_timings
587-
then Console.console##(time (Js.string ("rewrite_CSS: " ^ href)));
588-
let* imports, css =
589-
rewrite_css_import ~max ~prefix:(basedir href) ~media css 0
590-
in
591-
if !Eliom_config.debug_timings
592-
then Console.console##(timeEnd (Js.string ("rewrite_CSS: " ^ href)));
593-
Lwt.return (imports @ [media, css]))
594-
(fun _ -> Lwt.return [media, Printf.sprintf "@import url(%s);" href])
581+
try
582+
match css with
583+
| None -> []
584+
| Some css ->
585+
if !Eliom_config.debug_timings
586+
then Console.console##(time (Js.string ("rewrite_CSS: " ^ href)));
587+
let imports, css =
588+
rewrite_css_import ~max ~prefix:(basedir href) ~media css 0
589+
in
590+
if !Eliom_config.debug_timings
591+
then Console.console##(timeEnd (Js.string ("rewrite_CSS: " ^ href)));
592+
imports @ [media, css]
593+
with _ -> [media, Printf.sprintf "@import url(%s);" href]
595594

596595
and rewrite_css_import ?(charset = "") ~max ~prefix ~media css pos =
597596
match Regexp.search import_re css pos with
598597
| None ->
599598
(* No @import anymore, rewrite url. *)
600-
Lwt.return ([], rewrite_css_url ~prefix css pos)
599+
[], rewrite_css_url ~prefix css pos
601600
| Some (i, res) -> (
602601
(* Found @import rule, try to preload. *)
603602
let init = String.sub css pos (i - pos) in
@@ -606,45 +605,46 @@ and rewrite_css_import ?(charset = "") ~max ~prefix ~media css pos =
606605
let i = i + String.length (Regexp.matched_string res) in
607606
let i, href = parse_url ~prefix css i in
608607
let i, media' = parse_media css i in
609-
let* import =
610-
if max = 0
611-
then
612-
(* Maximum imbrication of @import reached, rewrite url. *)
613-
Lwt.return
614-
[media, Printf.sprintf "@import url('%s') %s;\n" href media']
615-
else if media##.length > 0 && String.length media' > 0
616-
then
617-
(* TODO combine media if possible...
608+
let (imports, css), import =
609+
Fiber.pair
610+
(fun () -> rewrite_css_import ~charset ~max ~prefix ~media css i)
611+
(fun () ->
612+
if
613+
(* TODO: lwt-to-direct-style: This computation might not be suspended correctly. *)
614+
max = 0
615+
then
616+
(* Maximum imbrication of @import reached, rewrite url. *)
617+
[media, Printf.sprintf "@import url('%s') %s;\n" href media']
618+
else if media##.length > 0 && String.length media' > 0
619+
then
620+
(* TODO combine media if possible...
618621
in the mean time keep explicit import. *)
619-
Lwt.return
620-
[media, Printf.sprintf "@import url('%s') %s;\n" href media']
621-
else
622-
let media =
623-
if media##.length > 0 then media else Js.string media'
624-
in
625-
let css =
626-
Eliom_request.http_get href [] Eliom_request.string_result
627-
in
628-
rewrite_css ~max:(max - 1) (media, href, css >|= snd)
629-
and* imports, css =
630-
rewrite_css_import ~charset ~max ~prefix ~media css i
622+
[media, Printf.sprintf "@import url('%s') %s;\n" href media']
623+
else
624+
let media =
625+
if media##.length > 0 then media else Js.string media'
626+
in
627+
let css =
628+
Eliom_request.http_get href [] Eliom_request.string_result
629+
in
630+
rewrite_css ~max:(max - 1) (media, href, snd css))
631631
in
632-
Lwt.return (import @ imports, css)
632+
import @ imports, css
633633
with
634-
| Incorrect_url -> Lwt.return ([], rewrite_css_url ~prefix css pos)
634+
| Incorrect_url -> [], rewrite_css_url ~prefix css pos
635635
| exn ->
636636
Logs.info ~src:section (fun fmt ->
637637
fmt
638638
("Error while importing css" ^^ "@\n%s")
639639
(Printexc.to_string exn));
640-
Lwt.return ([], rewrite_css_url ~prefix css pos))
640+
[], rewrite_css_url ~prefix css pos)
641641

642642
let max_preload_depth = ref 4
643643

644644
let build_style (e, css) =
645-
let* css = rewrite_css ~max:!max_preload_depth css in
646-
(* lwt css = *)
647-
Lwt_list.map_p
645+
let css = rewrite_css ~max:!max_preload_depth css in
646+
Fiber.List.map
647+
(* lwt css = *)
648648
(fun (media, css) ->
649649
let style = Dom_html.createStyle Dom_html.document in
650650
style##._type := Js.string "text/css";
@@ -655,7 +655,7 @@ let build_style (e, css) =
655655
if Js.Optdef.test styleSheet
656656
then Js.Unsafe.(set styleSheet (Js.string "cssText") (Js.string css))
657657
else style##.innerHTML := Js.string css;
658-
Lwt.return (e, (style :> Dom.node Js.t)))
658+
e, (style :> Dom.node Js.t))
659659
css
660660

661661
(* IE8 doesn't allow appendChild on noscript-elements *)
@@ -669,7 +669,7 @@ let build_style (e, css) =
669669
let preload_css (doc : Dom_html.element Js.t) =
670670
if !Eliom_config.debug_timings
671671
then Console.console##(time (Js.string "preload_css (fetch+rewrite)"));
672-
let* css = Lwt_list.map_p build_style (fetch_linked_css (get_head doc)) in
672+
let css = Fiber.List.map build_style (fetch_linked_css (get_head doc)) in
673673
let css = List.concat css in
674674
List.iter
675675
(fun (e, css) ->
@@ -682,8 +682,7 @@ let preload_css (doc : Dom_html.element Js.t) =
682682
section (fun fmt -> fmt "Unique CSS skipped..."))
683683
css;
684684
if !Eliom_config.debug_timings
685-
then Console.console##(timeEnd (Js.string "preload_css (fetch+rewrite)"));
686-
Lwt.return_unit
685+
then Console.console##(timeEnd (Js.string "preload_css (fetch+rewrite)"))
687686

688687
(** Window scrolling *)
689688

src/lib/client/eliommod_dom.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ val html_document :
7171
(** Assuming [d] has a body and head element, [html_document d] will
7272
return the same document as html *)
7373

74-
val preload_css : Dom_html.element Js.t -> unit Lwt.t
74+
val preload_css : Dom_html.element Js.t -> unit
7575
(** [preload_css e] downloads every css included in every link
7676
elements that is a descendant of [e] and replace it and its linked
7777
css by inline [<style>] elements *)

src/lib/eliom_bus.client.ml

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
open Lwt.Syntax
1+
open Eio.Std
22

33
(* Ocsigen
44
* http://www.ocsigen.org
@@ -32,31 +32,48 @@ type ('a, 'b) t =
3232
; stream : 'b Lwt_stream.t Lazy.t
3333
; queue : 'a Queue.t
3434
; mutable max_size : int
35-
; write : 'a list -> unit Lwt.t
36-
; mutable waiter : unit -> unit Lwt.t
37-
; mutable last_wait : unit Lwt.t
35+
; write : 'a list -> unit
36+
; mutable waiter : unit -> unit
37+
; mutable last_wait : unit Promise.t
3838
; mutable original_stream_available : bool
39-
; error_h : 'b option Lwt.t * exn Lwt.u }
39+
; error_h : 'b option Promise.t * exn Promise.u }
4040

4141
(* clone streams such that each clone of the original stream raise the same exceptions *)
4242
let consume (t, u) s =
4343
let t' =
44-
Lwt.catch
45-
(fun () -> Lwt_stream.iter (fun _ -> ()) s)
46-
(fun e ->
47-
(match Lwt.state t with Lwt.Sleep -> Lwt.wakeup_exn u e | _ -> ());
48-
Lwt.fail e)
44+
try Lwt_stream.iter (fun _ -> ()) s
45+
with e ->
46+
(match Promise.peek t with
47+
| None ->
48+
Promise.resolve_error
49+
(* TODO: lwt-to-direct-style: This used to be a ['a Lwt.t] is now a [('a, exn) result Promise.t]. Use [resolve_ok] and [await_exn] instead of [resolve] and [await]. *)
50+
u e
51+
| _ -> ());
52+
raise e
4953
in
50-
Lwt.choose [Lwt.bind t (fun _ -> Lwt.return_unit); t']
54+
Lwt.choose
55+
(* TODO: lwt-to-direct-style: [Lwt.choose] can't be automatically translated.Use Eio.Promise instead. *)
56+
(* TODO: lwt-to-direct-style: [Lwt.choose] can't be automatically translated.Use Eio.Promise instead. *)
57+
[ (let _ = t in
58+
())
59+
; t' ]
5160

5261
let clone_exn (t, u) s =
5362
let s' = Lwt_stream.clone s in
5463
Lwt_stream.from (fun () ->
55-
Lwt.catch
56-
(fun () -> Lwt.choose [Lwt_stream.get s'; t])
57-
(fun e ->
58-
(match Lwt.state t with Lwt.Sleep -> Lwt.wakeup_exn u e | _ -> ());
59-
Lwt.fail e))
64+
try
65+
Lwt.choose
66+
(* TODO: lwt-to-direct-style: [Lwt.choose] can't be automatically translated.Use Eio.Promise instead. *)
67+
(* TODO: lwt-to-direct-style: [Lwt.choose] can't be automatically translated.Use Eio.Promise instead. *)
68+
[Lwt_stream.get s'; t]
69+
with e ->
70+
(match Promise.peek t with
71+
| None ->
72+
Promise.resolve_error
73+
(* TODO: lwt-to-direct-style: This used to be a ['a Lwt.t] is now a [('a, exn) result Promise.t]. Use [resolve_ok] and [await_exn] instead of [resolve] and [await]. *)
74+
u e
75+
| _ -> ());
76+
raise e)
6077

6178
type ('a, 'att, 'co, 'ext, 'reg) callable_bus_service =
6279
( unit
@@ -74,25 +91,25 @@ type ('a, 'att, 'co, 'ext, 'reg) callable_bus_service =
7491

7592
let create service channel waiter =
7693
let write x =
77-
Lwt.catch
78-
(fun () ->
79-
let* _ =
80-
Eliom_client.call_service
81-
~service:(service :> ('a, _, _, _, _) callable_bus_service)
82-
() x
83-
in
84-
Lwt.return_unit)
85-
(function
86-
| Eliom_request.Failed_request 204 -> Lwt.return_unit
87-
| exc -> Lwt.reraise exc)
94+
try
95+
let _ =
96+
Eliom_client.call_service
97+
~service:(service :> ('a, _, _, _, _) callable_bus_service)
98+
() x
99+
in
100+
()
101+
with Eliom_request.Failed_request 204 -> ()
88102
in
89103
let error_h =
90-
let t, u = Lwt.wait () in
91-
( Lwt.catch
92-
(fun () ->
93-
let* _ = t in
94-
assert false)
95-
(fun e -> Lwt.fail e)
104+
let t, u =
105+
Promise.create
106+
(* TODO: lwt-to-direct-style: Translation is incomplete, [Promise.await] must be called on the promise when it's part of control-flow. *)
107+
()
108+
in
109+
( (try
110+
let _ = t in
111+
assert false
112+
with e -> raise e)
96113
, u )
97114
in
98115
let stream =
@@ -109,17 +126,16 @@ let create service channel waiter =
109126
; max_size = 20
110127
; write
111128
; waiter
112-
; last_wait = Lwt.return_unit
129+
; last_wait = ()
113130
; original_stream_available = true
114131
; error_h }
115132
in
116133
(* the comet channel start receiving after the load phase, so the
117134
original channel (i.e. without message lost) is only available in
118135
the first loading phase. *)
119136
let _ =
120-
let* () = Eliom_client.wait_load_end () in
121-
t.original_stream_available <- false;
122-
Lwt.return_unit
137+
let () = Eliom_client.wait_load_end () in
138+
t.original_stream_available <- false
123139
in
124140
t
125141

@@ -145,21 +161,31 @@ let flush t =
145161
Queue.clear t.queue; t.write l
146162

147163
let try_flush t =
148-
Lwt.cancel t.last_wait;
164+
Lwt.cancel
165+
(* TODO: lwt-to-direct-style: Use [Switch] or [Cancel] for defining a cancellable context. *)
166+
(* TODO: lwt-to-direct-style: Use [Switch] or [Cancel] for defining a cancellable context. *)
167+
t.last_wait;
149168
if Queue.length t.queue >= t.max_size
150169
then flush t
151170
else
152-
let th = Lwt.protected (t.waiter ()) in
171+
let th =
172+
Lwt.protected
173+
(* TODO: lwt-to-direct-style: Use [Switch] or [Cancel] for defining a cancellable context. *)
174+
(* TODO: lwt-to-direct-style: Use [Switch] or [Cancel] for defining a cancellable context. *)
175+
(t.waiter ())
176+
in
153177
t.last_wait <- th;
154-
let _ = th >>= fun () -> flush t in
155-
Lwt.return_unit
178+
let _ = th; flush t in
179+
()
156180

157181
let write t v = Queue.add v t.queue; try_flush t
158182
let close {channel; _} = Eliom_comet.close channel
159183
let set_queue_size b s = b.max_size <- s
160184

161185
let set_time_before_flush b t =
162186
b.waiter <-
163-
(if t <= 0. then Lwt.pause else fun () -> Js_of_ocaml_lwt.Lwt_js.sleep t)
187+
(if t <= 0.
188+
then fun x1 -> Fiber.yield x1
189+
else fun () -> Js_of_ocaml_lwt.Lwt_js.sleep t)
164190

165191
let force_link = ()

src/lib/eliom_bus.client.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ val original_stream : ('a, 'b) t -> 'b Lwt_stream.t
3939
received. This function can be called only in the onload event
4040
handler, if called outside, it will raise a Failure. *)
4141

42-
val write : ('a, 'b) t -> 'a -> unit Lwt.t
42+
val write : ('a, 'b) t -> 'a -> unit
4343
(** [write b v] send [v] to the bus [b]. Every participant of the bus
4444
will receive [v], including the sender. *)
4545

src/lib/eliom_bus.server.ml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
open Lwt.Syntax
2-
31
(* Ocsigen
42
* http://www.ocsigen.org
53
* Copyright (C) 2010
@@ -27,7 +25,7 @@ type ('a, 'b) t =
2725
; scope : Eliom_comet.Channel.comet_scope
2826
; name : string option
2927
; channel : 'b Eliom_comet.Channel.t option
30-
; write : 'a -> unit Lwt.t
28+
; write : 'a -> unit
3129
; service : 'a Ecb.bus_send_service
3230
; service_registered : bool Eliom_state.volatile_table option
3331
; size : int option
@@ -36,7 +34,7 @@ type ('a, 'b) t =
3634

3735
let register_sender scope service write =
3836
Eliom_registration.Action.register ~scope ~options:`NoReload ~service
39-
(fun () x -> Lwt_list.iter_s write x)
37+
(fun () x -> List.iter write x)
4038

4139
let internal_wrap (bus : ('a, 'b) t) :
4240
('a, 'b) Ecb.wrapped_bus * Eliom_common.unwrapper
@@ -94,8 +92,8 @@ let create_filtered ?scope ?name ?size ~filter typ =
9492
(*The stream*)
9593
let stream, push = Lwt_stream.create () in
9694
let push x =
97-
let* y = filter x in
98-
push (Some y); Lwt.return_unit
95+
let y = filter x in
96+
push (Some y)
9997
in
10098
let scope =
10199
match scope with
@@ -144,7 +142,7 @@ let create_filtered ?scope ?name ?size ~filter typ =
144142
bus
145143

146144
let create ?scope ?name ?size typ =
147-
create_filtered ~filter:Lwt.return ?scope ?name ?size typ
145+
create_filtered ~filter:(fun x1 -> x1) ?scope ?name ?size typ
148146

149147
let stream bus =
150148
match bus.scope with `Site -> bus.stream | `Client_process _ -> bus.stream

0 commit comments

Comments
 (0)