From: "Nicolas Pouillard" <nicolas.pouillard@inria.fr>
To: "Jim Grundy" <jim_grundy@ichips.intel.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] A Question About Types and Inlining
Date: Sat, 9 Dec 2006 14:12:12 +0100 [thread overview]
Message-ID: <cd67f63a0612090512j13398231i1a598b796b9625e3@mail.gmail.com> (raw)
In-Reply-To: <4579F1A4.6080606@ichips.intel.com>
Hi Jim,
On 12/9/06, Jim Grundy <jim_grundy@ichips.intel.com> wrote:
> 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 take the second part of your question since the obvious answer is camlp4:
There is an extension called pa_macro that provides conditional compilation.
Alas this extension doesn't work with signatures so the following
example is not (yet) supported:
(* foo.mli *)
IFDEF ABSTRACT THEN
type t
ELSE
type t = int
ENDIF
To address that shortcoming you can write an extension syntax dealing
with some semi-opaque types. Such an extension can allow us to write
that:
(* foo.mli *)
type t = semi opaque int
And have compilation option to set:
# For an abstract version
$ ocamlc -c -pp "camlp4o ./pa_opaque.cmo -abstract" foo.mli
# For a concrete version
$ ocamlc -c -pp "camlp4o ./pa_opaque.cmo -concrete" foo.mli
With this extension:
-----------8<-------------------------------------------------------------------------
(* pa_opaque.ml *)
open Pcaml;;
let abstract = ref true;;
EXTEND
ctyp: [[ LIDENT "semi"; LIDENT "opaque"; t = SELF ->
if !abstract then <:ctyp< 'abstract >> else t
]];
END;;
Pcaml.add_option "-abstract" (Arg.Set abstract)
"Use abstract types for semi opaque ones";;
Pcaml.add_option "-concrete" (Arg.Clear abstract)
"Use concrete types for semi opaque ones";;
-----------8<-------------------------------------------------------------------------
Compiled that way:
$ ocamlc -c -I +camlp4 -pp "camlp4o pa_extend.cmo q_MLast.cmo" pa_opaque.ml
Best regards,
>
> I'm using version 3.09.2 of ocamlopt.
>
> Thanks in advance
>
> Jim
>
>
> --
> Jim Grundy, Research Scientist. Intel Corporation, Strategic CAD Labs
> Mail Stop RA2-451, 2501 NW 229th Ave, Hillsboro, OR 97124-5503, USA
> Phone: +1 971 214-1709 Fax: +1 971 214-1771
> http://www.intel.com/technology/techresearch/people/bios/grundy_j.htm
> Key Fingerprint: 5F8B 8EEC 9355 839C D777 4D42 404A 492A AEF6 15E2
>
--
Nicolas Pouillard
next prev parent reply other threads:[~2006-12-09 13:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-08 23:13 Jim Grundy
[not found] ` <4579F655.3030307@philippewang.info>
[not found] ` <4579F8E1.6070604@ichips.intel.com>
2006-12-09 0:07 ` [Caml-list] " Philippe Wang
2006-12-09 0:55 ` Eric Cooper
2006-12-09 1:16 ` Philippe Wang
2006-12-09 1:31 ` Eric Cooper
2006-12-09 9:28 ` Jon Harrop
2006-12-09 11:28 ` Andrej Bauer
2006-12-09 13:12 ` Nicolas Pouillard [this message]
2006-12-10 6:27 ` Christian Stork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cd67f63a0612090512j13398231i1a598b796b9625e3@mail.gmail.com \
--to=nicolas.pouillard@inria.fr \
--cc=caml-list@yquem.inria.fr \
--cc=jim_grundy@ichips.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox