Version française
Home     About     Download     Resources     Contact us    
Browse thread
A Question About Types and Inlining
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Philippe Wang <lists@p...>
Subject: Re: [Caml-list] A Question About Types and Inlining
Hi.

Ok I misread a line...

I saw once that there were a lot of optimizations based on types 
informations, especially on basic types... So hidding some type 
information would lead to prevent the compiler from some optimization...

Well, I wonder about how to hide the information from the users without 
hiding it to the type checker...

Typically the function compare (or other comparison operators) have to 
check the kinds of their arguments, except when the compiler knows that 
their types are basic types...

Well, I guess you use a lot the function compare ?

Have you tried to force the polymorphic functions' types that are only 
used with integers with the type int ?
(to take back the performance, you will have to tell explicitely the 
compiler to optimise them... or change the compiler code... I guess.)

Cheers,

   Philippe Wang.

Jim Grundy a écrit :
> Hi Philippe
> 
> Thanks for the mail.  That's not quite what I'm looking for:
> 
> I have some module Foo, that implements a type, lets call it abs, that I 
> would like to keep abstract as far as the other modules are concerned.
> 
> In foo.mli I have
> 
>   type abs
> 
> and in foo.ml I have
> 
>   type abs = int
> 
> (which is the set up you were recommending, right)
> 
> But... if I change foo.mli to reveal the type to other modules, that is 
> if foo.mli also says
> 
>   type abs = int
> 
> then the program runs 36% faster.
> 
> I suspect that hiding the type is either preventing inlining of calls 
> from other modules to functions in the foo module, or that hiding the 
> type is forcing the other modules to use a boxed representation rather 
> than an unboxed representation.
> 
> All the best
> 
> Jim
> 
> Philippe Wang wrote:
>> Hi.
>>
>> If I have understood what you meant :
>>
>> Create a .mli file where you put
>> type variable
>>
>> and in the .ml file, put
>> type variable = int
>>
>>
>> It should do what you want (i.e. tell the compiler that the actual 
>> type is int and not allow unifying int type with variable type elsewhere)
>>
>> Note : ocamlopt -i yourmlfile.ml prints the default .mli
>> So you can generate the default .mli easily (at least on unix or cygwin)
>>
>> Cheers,
>> Philippe Wang
>>   mail@philippewang.info
>>
>>
>>
>> Jim Grundy a écrit :
>>> Apologies in advance for a naive question...
>>>
>>> I'm working on a SAT solver in OCaml.  The solver has various types, 
>>> like three-valued bools, variables, literals.  I have modules that 
>>> encapsulate these types and the operations on them.
>>>
>>> Now, as it turns out, all these types are represented as ints, but 
>>> the other modules that use those types don't need to know that - and 
>>> as a matter of taste I'd rather not expose this.
>>>
>>> The signatures of these modules currently contain lines like this:
>>>
>>> type variable (* = int *)
>>>
>>> If I uncomment all instances of (* = int *) and reveal the 
>>> representation to the compiler then I get a ... 36% performance 
>>> improvement in the SAT solver.
>>>
>>> I have two questions:
>>>
>>> 1/ Is there some way I can reveal this representation to the parts of 
>>> the system that clearly need it for effective optimization, without 
>>> opening this up for general use.
>>>
>>> 2/ Failing that, has someone got a pleasant method of doing 
>>> conditional compilation so that I can switch these comments on and 
>>> off with ease?
>>>
>>> I'm using version 3.09.2 of ocamlopt.
>>>
>>> Thanks in advance
>>>
>>> Jim
>>>
>>>
>