Skip to content

Commit

Permalink
Merge pull request #239 from tmcgilchrist/fmt_deprecation
Browse files Browse the repository at this point in the history
Fix deprecations in Fmt 0.8.10
  • Loading branch information
samoht authored Oct 22, 2021
2 parents 5dcc307 + 7f88881 commit 097fd38
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 51 deletions.
25 changes: 15 additions & 10 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### current

- Fix Fmt deprecation warnings (@tmcgilchrist #239)


### v1.2

- Don't crash if the peer disconnects before the bootstrap reply is ready (@talex5 #234).
Expand Down Expand Up @@ -32,41 +37,41 @@

### v0.9.0

- Add connection progress indicator (@talex5 #220).
- Add connection progress indicator (@talex5 #220).
Clients can now use `Capnp_rpc_unix.with_cap_exn` to show a progress indicator while waiting to connect.
It will use the log if enabled.
If not, but stderr is a tty, it shows a message while connecting and then erases it (if connecting takes longer than 0.5s).
If stderr is not a tty, it just prints a message there.

- Use `Mirage_crypto_rng_lwt.initialize` instead of `Mirage_crypto_rng_unix.initialize` (@hannesm #217).
- Use `Mirage_crypto_rng_lwt.initialize` instead of `Mirage_crypto_rng_unix.initialize` (@hannesm #217).
The former periodically feeds entropy to the RNG, while the latter seeds the RNG only once.

- Set TCP_KEEPIDLE=60 if possible (@talex5 #214).
- Set TCP_KEEPIDLE=60 if possible (@talex5 #214).
Cap'n Proto connections tend to be long lived and we therefore turn on the `SO_KEEPALIVE` option.
However, the default keepalive timeout of 2 hours is much too long for some networks.
In particular, Docker's libnetwork silently drops idle connections after about 10 minutes.

Windows support:

- Prevent crash if ExtUnix wasn't built with sockopt (@MisterDA #218).
If ExtUnix isn't built with sockopt then the symbol `have_sockopt_int` isn't available and an exception is raised.
- Prevent crash if ExtUnix wasn't built with sockopt (@MisterDA #218).
If ExtUnix isn't built with sockopt then the symbol `have_sockopt_int` isn't available and an exception is raised.
This may be the case on some environments (e.g., ExtUnix built with mingw-w64).
It is a workaround until support for `TCP_KEEPIDLE` is added for these environments (e.g., using Winsock instead).

- There is no SIGPIPE on Windows (@dra27 #212).

- Switch from "capnpc" to "capnp compile" (@talex5 #213).
- Switch from "capnpc" to "capnp compile" (@talex5 #213).
`capnpc` seems to be the old name, and isn't present on Windows.

Build changes:

- Remove Travis and Dockerfile (@talex5 #220).
- Remove Travis and Dockerfile (@talex5 #220).
Travis is very slow and error-prone now, and ocaml-ci generates a working Dockerfile automatically for people who want it.

- Include transitive dependencies in opam files (@talex5 #219).
- Include transitive dependencies in opam files (@talex5 #219).
Patch generated by https://github.com/ocurrent/opam-dune-lint/

- Require `tcpip.unix` specifically to get the checksum stubs linked (@hannesm #216).
- Require `tcpip.unix` specifically to get the checksum stubs linked (@hannesm #216).

### v0.8.0

Expand Down Expand Up @@ -145,7 +150,7 @@ Breaking changes:

Other changes:

- Add Prometheus metrics for connections (@talex5, #183).
- Add Prometheus metrics for connections (@talex5, #183).
`capnp-rpc-net` now reports the current number of active connections,
the total number of messages received, and
the total number of messages enqueued, sent and dropped
Expand Down
6 changes: 3 additions & 3 deletions capnp-rpc-mirage.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ depends: [
"capnp" {>= "3.1.0"}
"capnp-rpc-net" {= version}
"astring" {with-test}
"fmt"
"fmt" {>= "0.8.7"}
"logs"
"dns-client" {>= "5.0.0"}
"dns-client" {>= "5.0.0" & < "6.0.0"}
"tls-mirage"
"mirage-stack" {>= "2.0.0"}
"mirage-stack" {>= "2.2.0"}
"arp" {>= "2.3.0" & with-test}
"alcotest" {>= "1.0.1" & with-test}
"alcotest-lwt" {>= "1.0.1" & with-test}
Expand Down
4 changes: 2 additions & 2 deletions capnp-rpc-net.opam
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ depends: [
"capnp-rpc" {= version}
"capnp-rpc-lwt" {= version}
"astring"
"fmt"
"fmt" {>= "0.8.7"}
"logs"
"asetmap"
"cstruct" {>= "6.0.0"}
Expand All @@ -28,7 +28,7 @@ depends: [
"ptime"
"prometheus" {>= "0.5"}
"asn1-combinators" {>= "0.2.0"}
"x509" {>= "0.13.0"}
"x509" {>= "0.13.0" & < "0.15.0"}
"tls-mirage"
"dune" {>= "2.0"}
"mirage-crypto"
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc-net/auth.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type hash = [`SHA256]
"sha-512:def". We need to detect it's the same peer. *)

let error fmt =
fmt |> Fmt.kstrf @@ fun msg ->
fmt |> Fmt.kstr @@ fun msg ->
Error (`Msg msg)

let ( >>= ) x f =
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc-net/b64.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let error fmt =
fmt |> Fmt.kstrf @@ fun msg ->
fmt |> Fmt.kstr @@ fun msg ->
Error (`Msg msg)

let encode ~alphabet ~pad s =
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc-net/capnp_address.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Astring

let error fmt =
fmt |> Fmt.kstrf @@ fun msg ->
fmt |> Fmt.kstr @@ fun msg ->
Error (`Msg msg)

let none_if_empty = function
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc-net/endpoint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let of_flow (type flow) ~switch ~peer_id (module F : Mirage_flow.S with type flo
let dump_msg =
let next = ref 0 in
fun data ->
let name = Fmt.strf "/tmp/msg-%d.capnp" !next in
let name = Fmt.str "/tmp/msg-%d.capnp" !next in
Log.info (fun f -> f "Saved message as %S" name);
incr next;
let ch = open_out_bin name in
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc-net/parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module Make_basic
| Return.ResultsSentElsewhere -> `ResultsSentElsewhere
| Return.TakeFromOtherQuestion other -> `TakeFromOtherQuestion (AnswerId.of_uint32 other)
| Return.AcceptFromThirdParty _ -> failwith "TODO: AcceptFromThirdParty"
| Return.Undefined x -> failwith (Fmt.strf "Unexpected return type received: %d" x)
| Return.Undefined x -> failwith (Fmt.str "Unexpected return type received: %d" x)
in
`Return (qid, ret, release_param_caps)

Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc-net/tls_wrapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open Lwt.Infix
open Auth

let error fmt =
fmt |> Fmt.kstrf @@ fun msg ->
fmt |> Fmt.kstr @@ fun msg ->
Error (`Msg msg)

module Make (Underlying : Mirage_flow.S) = struct
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc-unix.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ depends: [
"cmdliner"
"cstruct-lwt"
"astring"
"fmt" {>= "0.8.4"}
"fmt" {>= "0.8.7"}
"logs"
"extunix"
"base64" {>= "3.0.0"}
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc/capTP.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,7 @@ module Make (EP : Message_types.ENDPOINT) = struct
(* Check we're not resolving a settled import. *)
if im.Import.settled then (
let new_target = import_new_target ~embargo_path:None in
let msg = Fmt.strf "Got a Resolve (to %t) for settled import %a!" new_target#pp Import.dump im in
let msg = Fmt.str "Got a Resolve (to %t) for settled import %a!" new_target#pp Import.dump im in
dec_ref new_target;
failwith msg
);
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc/cap_proxy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module Make(C : S.CORE_TYPES) = struct
let cap =
match cap#blocker with
| Some blocker when blocker = (self :> base_ref) ->
let msg = Fmt.strf "@[<v>Attempt to create a cycle detected:@,\
let msg = Fmt.str "@[<v>Attempt to create a cycle detected:@,\
Resolving %t with %t would create a cycle@]" self#pp cap#pp in
Log.info (fun f -> f "%s" msg);
C.dec_ref cap;
Expand Down
4 changes: 2 additions & 2 deletions capnp-rpc/core_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ module Make(Wire : S.WIRE) = struct
let null = broken_cap {Exception.ty = `Failed; reason = "null"}
let cancelled = broken_cap Exception.cancelled

let cap_failf ?(ty=`Failed) msg = msg |> Fmt.kstrf (fun reason -> broken_cap {Exception.ty; reason})
let cap_failf ?(ty=`Failed) msg = msg |> Fmt.kstr (fun reason -> broken_cap {Exception.ty; reason})

let cap_in_cap_list i caps =
match i with
Expand Down Expand Up @@ -291,7 +291,7 @@ module Make(Wire : S.WIRE) = struct
end

let fail ?(ty=`Failed) msg =
msg |> Fmt.kstrf @@ fun reason ->
msg |> Fmt.kstr @@ fun reason ->
broken_struct (`Exception {Exception.ty; reason})

let resolved = function
Expand Down
4 changes: 2 additions & 2 deletions capnp-rpc/debug.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ let pp_exn f = function
| Failure msg -> Fmt.string f msg
| ex -> Fmt.exn f ex

let failf msg = Fmt.kstrf failwith msg
let failf msg = Fmt.kstr failwith msg

let invariant_broken f = raise (Invariant_broken f)

let () =
Printexc.register_printer @@ function
| Invariant_broken pp -> Some (Fmt.strf "%t" pp)
| Invariant_broken pp -> Some (Fmt.str "%t" pp)
| _ -> None

module OID = struct
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc/error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ let pp f = function
| `Cancelled -> Fmt.pf f "cancelled"

let exn ?ty msg =
msg |> Fmt.kstrf @@ fun reason ->
msg |> Fmt.kstr @@ fun reason ->
`Exception (Exception.v ?ty reason)
6 changes: 3 additions & 3 deletions capnp-rpc/struct_proxy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Make (C : S.CORE_TYPES) = struct
let cycle_marker = C.broken_cap (Exception.v "<cycle marker>")

let cycle_err fmt =
"@[<v>Attempt to create a cycle detected:@," ^^ fmt ^^ "@]" |> Fmt.kstrf @@ fun msg ->
"@[<v>Attempt to create a cycle detected:@," ^^ fmt ^^ "@]" |> Fmt.kstr @@ fun msg ->
Log.info (fun f -> f "%s" msg);
C.broken_struct (`Exception (Exception.v msg))

Expand Down Expand Up @@ -273,7 +273,7 @@ module Make (C : S.CORE_TYPES) = struct
@ to: -> %t" self#pp x#pp);
match state with
| Finished -> dec_ref x (* Cancelled *)
| Forwarding x -> failwith (Fmt.strf "Already forwarding (to %t)!" x#pp)
| Forwarding x -> failwith (Fmt.str "Already forwarding (to %t)!" x#pp)
| Unresolved u ->
(* Check for cycles *)
let x =
Expand All @@ -295,7 +295,7 @@ module Make (C : S.CORE_TYPES) = struct
detector_caps.(i) <- RO_array.get_exn caps i
done;
if c#blocker = Some (self :> C.base_ref) then
C.broken_cap (Exception.v (Fmt.strf "<cycle: %t>" c#pp))
C.broken_cap (Exception.v (Fmt.str "<cycle: %t>" c#pp))
else c
in
let fixed_caps = RO_array.map break_cycles caps in
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc/table.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let failf fmt = Fmt.kstrf failwith fmt
let failf fmt = Fmt.kstr failwith fmt

let pp_item ~check pp f (k, v) =
match check v with
Expand Down
2 changes: 1 addition & 1 deletion examples/echo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let local () =
let msg = Params.msg_get params in
release_params ();
let resp, results = Service.Response.create Results.init_pointer in
Results.reply_set results (Fmt.strf "got:%d:%s" count msg);
Results.reply_set results (Fmt.str "got:%d:%s" count msg);
count <- count + 1;
if Params.slow_get params then (
Service.return_lwt (fun () ->
Expand Down
10 changes: 5 additions & 5 deletions fuzz/fuzz.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ let code =

let step = ref 0

let failf msg = Fmt.kstrf failwith msg
let failf msg = Fmt.kstr failwith msg

let styles = [| `Red; `Green; `Blue |]

let actor_for_id id =
let style = styles.(id mod Array.length styles) in
(style, Fmt.strf "vat-%d" id)
(style, Fmt.str "vat-%d" id)

let tags_for_id id =
Logs.Tag.empty |> Logs.Tag.add Test_utils.actor_tag (actor_for_id id)
Expand Down Expand Up @@ -150,7 +150,7 @@ module Msg = struct
let summary = function
| `Abort _ -> "abort"
| `Bootstrap _ -> "bootstrap"
| `Call (_, _, msg, _, _) -> Fmt.strf "call:%a:%d" OID.pp msg.contents.Request.sender msg.contents.Request.seq
| `Call (_, _, msg, _, _) -> Fmt.str "call:%a:%d" OID.pp msg.contents.Request.sender msg.contents.Request.seq
| `Return (_, `Results (msg, _), _) -> "return:" ^ msg.contents
| `Return (_, `Exception ex, _) -> "return:" ^ ex.Capnp_rpc.Exception.reason
| `Return (_, `Cancelled, _) -> "return:(cancelled)"
Expand Down Expand Up @@ -519,13 +519,13 @@ module Vat = struct
counters.next_expected <- counters.next_expected + 1
done;
let expected_seq = counters.next_expected in
let expected_msg = Fmt.strf "%a:%d" OID.pp sender counters.next_expected in
let expected_msg = Fmt.str "%a:%d" OID.pp sender counters.next_expected in
counters.next_expected <- succ counters.next_expected;
let answer_var = OID.next () in
begin
let caps = Core_types.Request_payload.snapshot_caps msg in
match RO_array.length caps with
| 0 ->
| 0 ->
code (fun f -> Fmt.pf f "let %a = %t#pop0 %S in"
pp_resolver
answer_var self#pp_var
Expand Down
2 changes: 1 addition & 1 deletion mirage/network.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ open Lwt.Infix
module Log = Capnp_rpc.Debug.Log

let error fmt =
fmt |> Fmt.kstrf @@ fun msg ->
fmt |> Fmt.kstr @@ fun msg ->
Error (`Msg msg)

module Location = struct
Expand Down
2 changes: 1 addition & 1 deletion mirage/network.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ end

module Make (R : Mirage_random.S) (T : Mirage_time.S) (C : Mirage_clock.MCLOCK) (Stack : Mirage_stack.V4V6) : sig

module Dns : module type of Dns_client_mirage.Make(R)(T)(C)(Stack)
module Dns : module type of Dns_client_mirage.Make(R)(T)(C)(Stack)

type t = {
stack : Stack.t;
Expand Down
2 changes: 1 addition & 1 deletion test-lwt/test_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ let test_crossed_calls switch =
let restore = Restorer.(single id) service in
let config =
let secret_key = `PEM (Auth.Secret_key.to_pem_data secret_key) in
let name = Fmt.strf "capnp-rpc-test-%s" addr in
let name = Fmt.str "capnp-rpc-test-%s" addr in
let socket_path = Filename.(concat (Filename.get_temp_dir_name ())) name in
Lwt_switch.add_hook (Some switch) (fun () -> Lwt.return @@ ensure_removed socket_path);
Capnp_rpc_unix.Vat_config.create ~secret_key (`Unix socket_path)
Expand Down
10 changes: 5 additions & 5 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ let test_local_embargo_4 () =
It therefore does not try to disembargo it. *)
Alcotest.(check string) "Error not embargoed"
"Failed: Invalid capability index!"
(Fmt.strf "%t" broken#shortest#pp);
(Fmt.str "%t" broken#shortest#pp);
(* Clean up *)
dec_ref qp;
dec_ref local;
Expand Down Expand Up @@ -955,12 +955,12 @@ let ensure_is_cycle_error (x:#Core_types.struct_ref) : unit =
match x#response with
| Some (Error (`Exception ex))
when (String.is_prefix ~affix:"Attempt to create a cycle detected:" ex.Exception.reason) -> ()
| _ -> Alcotest.fail (Fmt.strf "Not a cycle error: %t" x#pp)
| _ -> Alcotest.fail (Fmt.str "Not a cycle error: %t" x#pp)

let ensure_is_cycle_error_cap cap =
match cap#problem with
| Some ex when (String.is_prefix ~affix:"<cycle: " ex.Exception.reason) -> ()
| _ -> Alcotest.fail (Fmt.strf "Not a cycle error: %t" cap#pp)
| _ -> Alcotest.fail (Fmt.str "Not a cycle error: %t" cap#pp)

let test_cycle () =
(* Cap cycles *)
Expand Down Expand Up @@ -1396,14 +1396,14 @@ module Level0 = struct
let bs_request = Queue.pop t.from_server in
match bs_request with
| `Bootstrap (qid, "") -> qid
| _ -> Alcotest.fail (Fmt.strf "Expecting bootstrap, got %s" (Testbed.Connection.summary_of_msg bs_request))
| _ -> Alcotest.fail (Fmt.str "Expecting bootstrap, got %s" (Testbed.Connection.summary_of_msg bs_request))

let expect_call t expected =
match Queue.pop t.from_server with
| `Call (qid, _, msg, _, _) ->
Alcotest.(check string) "Get call" expected @@ Request.data msg;
qid
| request -> Alcotest.fail (Fmt.strf "Expecting call, got %s" (Testbed.Connection.summary_of_msg request))
| request -> Alcotest.fail (Fmt.str "Expecting call, got %s" (Testbed.Connection.summary_of_msg request))

let call t target ~qid msg =
send t @@ `Call (qid_of_int qid, `ReceiverHosted target, Request.v msg, RO_array.empty, `Caller)
Expand Down
2 changes: 1 addition & 1 deletion test/testbed/connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ module Endpoint (EP : Capnp_direct.ENDPOINT) = struct
let pop_msg ?expect t =
match Queue.pop t.recv_queue with
| exception Queue.Empty ->
Alcotest.fail (Fmt.strf "No messages found! (expecting %a)" Fmt.(option string) expect)
Alcotest.fail (Fmt.str "No messages found! (expecting %a)" Fmt.(option string) expect)
| msg ->
begin match msg with
| #EP.In.t as msg ->
Expand Down
4 changes: 2 additions & 2 deletions unix/capnp_rpc_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module File_store = File_store
module Sturdy_ref = Capnp_rpc_lwt.Sturdy_ref

let error fmt =
fmt |> Fmt.kstrf @@ fun msg ->
fmt |> Fmt.kstr @@ fun msg ->
Error (`Msg msg)

let parse_uri s =
Expand Down Expand Up @@ -141,7 +141,7 @@ let rec connect_with_progress ?(mode=`Auto) sr =
let x = Sturdy_ref.connect sr in
Lwt.choose [Lwt_unix.sleep 0.5; Lwt.map ignore x] >>= fun () ->
if Lwt.is_sleeping x then (
Console.with_msg (Fmt.strf "[ connecting to %a ]" pp sr)
Console.with_msg (Fmt.str "[ connecting to %a ]" pp sr)
(fun () -> x)
) else x
| `Silent -> Sturdy_ref.connect sr
Expand Down
Loading

0 comments on commit 097fd38

Please sign in to comment.