Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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:  FAQ:
To unsubscribe, mail  Archives: