caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] functor inlining
@ 2021-01-14 21:31 Christophe Raffalli
  2021-01-14 21:41 ` Christophe Raffalli
  0 siblings, 1 reply; 5+ messages in thread
From: Christophe Raffalli @ 2021-01-14 21:31 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1981 bytes --]


Hello

I try to inline some module application. It works when
I compile with ocamlopt or ocamlc manually:

ocamlopt -w a -warn-error a mat.ml test.ml

But fails using dune:

dune build

gives this error without flambda:

File "test.ml", line 12, characters 18-52:
12 | module FloatMat = Mat.Make [@inlined always] (Float)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error (warning 55): Cannot inline: Unknown function

and this error with flambda:

File "test.ml", line 12, characters 18-52:
12 | module FloatMat = Mat.Make [@inlined always] (Float)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error (warning 55): Cannot inline: [@inlined] attribute was not used on this function application (the optimizer did not know what function was being applied)

Am I missing something ?

Here are the files to reproduce:

------------------------- mat.ml ----------------------
module type Field = sig
  type t

  val zero : t
  val one : t
  val ( + ) : t -> t -> t
  val ( * ) : t -> t -> t
end

module Make (R:Field) = struct
  open R

  type v = t array
  type m = t array array

  let ( *. ) v1 v2 =
    let r = ref zero in
    for i = 0 to Array.length v1 do
      r := !r + v1.(i) * v2.(i)
    done;
    !r

  let ( ** ) m v = Array.map (fun w -> w *. v) m
end
--------------------------------------------------------

------------------------- test.ml ----------------------
module Float = struct
  type t = float

  let zero = 0.0
  let one  = 1.0

  let ( + ) = ( +. )
  let ( * ) = ( *. )
end

module FloatMat = Mat.Make [@inlined always] (Float)
--------------------------------------------------------

------------------------- dune -------------------------
; Add project-wide flags here.
(env
  (dev     (flags :standard -w -9-32)
           (ocamlopt_flags -O3))
  (release (flags :standard -w -9-32)
           (ocamlopt_flags -O3)))

(executable
  (name Test)
  (modules :standard))
---------------------------------------------------------

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] functor inlining
  2021-01-14 21:31 [Caml-list] functor inlining Christophe Raffalli
@ 2021-01-14 21:41 ` Christophe Raffalli
  2021-01-15  3:57   ` Christophe Raffalli
  0 siblings, 1 reply; 5+ messages in thread
From: Christophe Raffalli @ 2021-01-14 21:41 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1012 bytes --]

Le 21-01-14 12:31:46, Christophe Raffalli a écrit :
>
> Hello
>
> I try to inline some module application. It works when
> I compile with ocamlopt or ocamlc manually:
>
> ocamlopt -w a -warn-error a mat.ml test.ml
>
> But fails using dune:
>
> dune build

Found the problem: dune is compiling with -opaque ... but could
not find yet how to remove this option!

> gives this error without flambda:
>
> File "test.ml", line 12, characters 18-52:
> 12 | module FloatMat = Mat.Make [@inlined always] (Float)
>                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Error (warning 55): Cannot inline: Unknown function
>
> and this error with flambda:
>
> File "test.ml", line 12, characters 18-52:
> 12 | module FloatMat = Mat.Make [@inlined always] (Float)
>                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Error (warning 55): Cannot inline: [@inlined] attribute was not used on this function application (the optimizer did not know what function was being applied)
>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] functor inlining
  2021-01-14 21:41 ` Christophe Raffalli
@ 2021-01-15  3:57   ` Christophe Raffalli
  2021-01-15  7:43     ` Nicolás Ojeda Bär
  0 siblings, 1 reply; 5+ messages in thread
From: Christophe Raffalli @ 2021-01-15  3:57 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 896 bytes --]

> >
> > But fails using dune:
> >
> > dune build
>
> Found the problem: dune is compiling with -opaque ... but could
> not find yet how to remove this option!

dune build --release ...

A bit annoying still, I will fill an issue on dune's github.

> > gives this error without flambda:
> >
> > File "test.ml", line 12, characters 18-52:
> > 12 | module FloatMat = Mat.Make [@inlined always] (Float)
> >                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > Error (warning 55): Cannot inline: Unknown function
> >
> > and this error with flambda:
> >
> > File "test.ml", line 12, characters 18-52:
> > 12 | module FloatMat = Mat.Make [@inlined always] (Float)
> >                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > Error (warning 55): Cannot inline: [@inlined] attribute was not used on this function application (the optimizer did not know what function was being applied)
> >

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [Caml-list] functor inlining
  2021-01-15  3:57   ` Christophe Raffalli
@ 2021-01-15  7:43     ` Nicolás Ojeda Bär
  2021-01-15 17:05       ` Christophe Raffalli
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolás Ojeda Bär @ 2021-01-15  7:43 UTC (permalink / raw)
  To: caml-list, Christophe Raffalli

[-- Attachment #1: Type: text/plain, Size: 702 bytes --]

Dear Christophe,

You can disable the use of "-opaque" by always compiling in the release profile, either by passing "--profile release" on the command line or by adding (profile release) to the dune-workspace file.

Hope that helps,
Nicolas
________________________________
De : caml-list-request@inria.fr <caml-list-request@inria.fr> de la part de Christophe Raffalli <christophe@raffalli.eu>
Envoyé : vendredi 15 janvier 2021 04:57
À : caml-list@inria.fr <caml-list@inria.fr>
Objet : Re: [Caml-list] functor inlining

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.


[-- Attachment #2: Type: text/html, Size: 2185 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] functor inlining
  2021-01-15  7:43     ` Nicolás Ojeda Bär
@ 2021-01-15 17:05       ` Christophe Raffalli
  0 siblings, 0 replies; 5+ messages in thread
From: Christophe Raffalli @ 2021-01-15 17:05 UTC (permalink / raw)
  To: Nicolás Ojeda Bär; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 683 bytes --]

Le 21-01-15 07:43:39, Nicolás Ojeda Bär a écrit :
> Dear Christophe,
>
> You can disable the use of "-opaque" by always compiling in the release
> profile, either by passing "--profile release" on the command line or by adding
> (profile release) to the dune-workspace file.

Thanks,

I finally use

(env
  (dev     (flags :standard -warn-error -55)
           (ocamlopt_flags :standard -warn-error -55 -inline 50000 -O3))
  ....)

in my dune file. But I submitted an issue and suggest -warn-error -55
as default for the dev profile. This makes sure compilation works for both
profiles or fails for both.

Cheers,
Christophe

> Hope that helps,
> Nicolas

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-01-15 17:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14 21:31 [Caml-list] functor inlining Christophe Raffalli
2021-01-14 21:41 ` Christophe Raffalli
2021-01-15  3:57   ` Christophe Raffalli
2021-01-15  7:43     ` Nicolás Ojeda Bär
2021-01-15 17:05       ` Christophe Raffalli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).