Capnproto functor inlining

I am trying to build a library that generates a capnproto schema from a file called hs_api.capnp

I get an error from the generated file:

File "lib/hs_api.ml", lines 444-1243, characters 0-14:
 444 | module MakeRPC(MessageWrapper : Capnp.RPC.S) = struct
 445 |   type 'a reader_t = 'a MessageWrapper.StructStorage.reader_t
 446 |   type 'a builder_t = 'a MessageWrapper.StructStorage.builder_t
 447 |   module CamlBytes = Bytes
 448 |   module DefaultsMessage_ = Capnp.BytesMessage
...
1240 |     end
1241 |   end
1242 |   module MessageWrapper = MessageWrapper
1243 | end [@@inline]
Error (warning 53 [misplaced-attribute]): the "inline" attribute cannot appear in this context

The dune file for the library looks like this:

(rule
 (targets hs_api.ml hs_api.mli)
 (deps    hs_api.capnp)
 (action (run capnp compile -o %{bin:capnpc-ocaml} %{deps})))

(library
 (name lib)
 (libraries consensus lwt.unix capnp-rpc-lwt capnp-rpc-unix tezos-crypto logs.fmt fmt.tty)
 (flags :standard -w -55)
 )

I included the ‘flags’ bit because of this post: Functor inlining in public library
But it hasn’t fixed my error

Never used Capnproto, but you can disable the warning by passing -w -53 in theflags field.

Cheers,
Nicolas

Ah thank you! It turns out I had to suppress both warnings like this:

(flags :standard -w -53-55)

That is what we have in ocaml-ci for our Capnproto dune file.

Do you have instructions that we could use to reproduce your issue ? The warning 55 is expected, but not warning 53 (this is supposed to be the correct place to put an inlining annotation). I’m particularly interested to know if this issue occurs with recent versions of the compiler (4.14 or 5.0).

I made a PR to remove all the annotations that OCaml 5 + flambda says are invalid now: Fix invalid doc-comments and inline attributes by talex5 · Pull Request #87 · capnproto/capnp-ocaml · GitHub

You still need to disable warning 55 though, and it seems it can’t be disabled from within the generated file. I might remove the remaining annotations too to get rid of these warnings; I don’t think anyone is actually using capnproto with flambda or cares about the minor speed boost anyway.

Can you make an issue on the compiler for the misplaced attribute warnings ? The ones that you removed in your PR are definitely not misplaced, so it’s likely a bug somewhere in the compiler if a warning is emitted.

Normally you should be able to disable it by adding [@@@ocaml.warning "-55"] at the top of the file. I assume you tried this and it didn’t work?

Cheers,
Nicolas

Yes, that doesn’t work. I simplified it to this:

$ cat test.ml
[@@@ocaml.warning "-53-55"]
module M = struct let t = object end end [@@inline]

$ ocamlopt ./test.ml
File "./test.ml", line 2, characters 44-50:
2 | module M = struct let t = object end end [@@inline]
                                                ^^^^^^
Warning 53 [misplaced-attribute]: the "inline" attribute cannot appear in this context

Ok, so there are two different bugs.
The first one is that [@@@ocaml.warning "-53"] doesn’t work. This is not completely surprising, but it might not be that hard to fix.
The second one is that for functors containing classes or objects, the [@@inline] attribute doesn’t get attached to the functor correctly. I have an idea of why, but I’ll need some time to make a proper fix.
I’ll submit bug reports for those issues so that we can track them properly. Thanks for providing the example.

1 Like