From: Peter Zotov <whitequark@whitequark.org>
To: <caml-list@inria.fr>
Subject: Re: [Caml-list] LLVM OCaml bindings
Date: Wed, 06 Nov 2013 11:19:09 +0400 [thread overview]
Message-ID: <a25ea39845a65ea0dae832c692cc0e2a@whitequark.org> (raw)
In-Reply-To: <CAHaHOqR6bwy0fnMAFm9KDQGwAH2FSi89p2J4HG9d_SkK6dyNpQ@mail.gmail.com>
Jeff Meister писал 06.11.2013 01:00:
> I can call const_int to get an llvalue representing an integer, then
> pass this llvalue as the first argument to build_call, which expects a
> function. Since both have type llvalue, the OCaml type checker will
> not complain, but a segfault or other undefined behavior will likely
> result at runtime.
As mentioned elsewhere, it's defined in Asserts build. Personally,
I'm going to ship my compiler with LLVM built in Release+Asserts mode.
> What I did to fix this was reintroduce the inheritance hierarchy
> present in the C++ code. Using some module system tricks to make
> OCaml's structural subtyping act like nominal subtyping, I refactored
> everything into classes. In my version, const_int would return a
> ConstInt.t, which is a subtype of Value.t, but not compatible with the
> Function.t required by build_call.
One thing to consider is that the C++ API does not use subtyping for
this kind of safety, either. Consider the prototype of
IRBuilder::CreateCall:
CallInst *CreateCall (Value *Callee, ArrayRef< Value * > Args, const
Twine &Name="")
This means that there is no guarantee you can convert the API to use
the subtyping safety measure you devised. Indeed, there are several
functions which do not have an equivalent type in hierarchy.
Llvm.set_volatile expects a [load] or [store], where Llvm.set_alignment
expects a [load], [store] or a global value, and
Llvm.set_atomic_ordering
expects a [load], [store], [atomicrmw], [fence], or [cmpxchg].
LLVM itself represents this by trying to explicitly cast the
instruction
to each supported one, and then calling the corresponding method.
Interestingly, this kind of relationship can be expressed better by
OCaml's
structural OO system than C++'s nominative one. I think that a project
to wrap either LLVM's C or C++ API into OCaml's classes and objects may
be a good solution to at least part of the problem. I don't have time
to develop this myself, though.
> I will try to find my code and put it up on GitHub if it would be
> useful to you.
I would be interested to look into it, but I probably will not
integrate
it into the bindings.
--
WBR, Peter Zotov.
next prev parent reply other threads:[~2013-11-06 7:19 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-05 4:23 Peter Zotov
2013-11-05 8:12 ` Gabriel Kerneis
2013-11-05 8:18 ` Peter Zotov
2013-11-05 11:09 ` Jacques-Pascal Deplaix
2013-11-05 11:32 ` Peter Zotov
2013-11-05 21:00 ` Jeff Meister
2013-11-06 7:19 ` Peter Zotov [this message]
2013-11-06 7:54 ` Jeff Meister
2013-11-05 21:30 ` Jacques-Pascal Deplaix
2013-11-06 7:06 ` Peter Zotov
2013-11-08 9:36 ` Jon Harrop
2013-11-08 10:18 ` Peter Zotov
2013-11-08 11:31 ` Jon Harrop
2013-11-08 11:44 ` Peter Zotov
2013-11-12 3:44 ` Jeff Meister
2013-11-12 14:13 ` Peter Zotov
2013-11-13 19:00 ` Jon Harrop
2013-11-14 16:06 ` Hongbo Zhang
2013-11-14 19:29 ` Jeff Meister
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=a25ea39845a65ea0dae832c692cc0e2a@whitequark.org \
--to=whitequark@whitequark.org \
--cc=caml-list@inria.fr \
/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