Oleg,

I am using GHC 6.12.3

Here a reproduction:

in the file Template.hs

proc () = runIO $ do runQ [|1+1|]
proc' () = [|1+1|]


In the file Main.hs


i1 = $(proc ())      -- fails at compile time with "Segmentation fault/access violation in generated code". Maybe is it the expected behavior, I do not know.
i2 = $(proc' ())     -- sucessfull

i3 = proc() -- sucessful but proc is executed at "runtime"

main = ...

Hope it is clear enough otherwise let me know.

Regards

J-C


On Mon, Nov 29, 2010 at 4:45 AM, <oleg@okmij.org> wrote:

Hello!

> But, please, correct me if I am wrong, in your example, the splicer are
> executed at run time and not at compile time.

With TH, it becomes a bit difficult to tell what is exactly `compile
time'. One can say however that when the code is ready to be spliced
in at the top level, the IO actions in its splices must have been
completed.

> I have modified your example to make it run at compile time and I get a
> (compile time) segmentation fault.

As I mentioned, the code was specifically designed to cause something
like segmentation fault. Sneaking out free variables is definitely the
bad thing. The principle of exchanging data between splices (using
runQ/runIO) is valid and could be used for good things, too.

I am wondering though what GHC version and command-line parameters are
you using? On my system. with GHC 6.10.3, I tried running the original
and modified code in GHCi and GHC (with and without -O2) and did not
get segmentation fault. Could you provide more details about your
system so to reproduce the segfault? I think Simon Peyton-Jones would
really like to know all that.

       Cheers,
       Oleg