English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] optimizing functors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-02-02 (17:59)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] optimizing functors
> OCaml does inlining of functions in the same module. Does it also do it
> between different modules?

Yes, but not across functor applications.  More precisely, functions
that are passed through a functor parameter cannot be inlined nor
called with the optimized "direct" application scheme, they always go
through the generic "indirect-through-closure" application scheme.

> Would it optimize the following:
> module M=
> struct
>   let f = function 0 -> true | _ -> false
> end
> module N (D : sig val f: int->bool end) =
> struct
>   let f = D.f
> end
> module P=N(M)
> Does the compiler optimize the call to f in P, resolving it directly to
> M.f, or does it do multiple indirections?

It will do exactly one indirection: fetch a function closure from P.f (which
happens to be the closure of M.f), and call it indirectly (and without

- Xavier Leroy
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr