[m-dev.] Re: About to abandon .par grades... (fwd)

Julien Fischer juliensf at cs.mu.OZ.AU
Wed Oct 20 02:27:09 AEST 2004




---------- Forwarded message ----------
Date: Mon, 18 Oct 2004 19:46:49 -0700
From: Fergus Henderson <fjh007 at galois.com>
To: Ralph Becket <rafe at cs.mu.OZ.AU>
Cc: Fergus Henderson <fjh007 at galois.com>, Julien Fischer <juliensf at cs.mu.OZ.AU>,
     Zoltan Somogyi <zs at cs.mu.OZ.AU>
Subject: Re: About to abandon .par grades...

On 19-Oct-2004, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> Fergus Henderson, Monday, 18 October 2004:
> >
> > Well, I don't understand the fix either.
> > Your diagnosis that without it "the Mercury engine is not initialized"
> > doesn't make much sense to me, since there are calls to
> > "MR_init_thread(MR_use_now)" immediately after the call to
> > MR_init_memory() and the code to initialize the trail.

Ignore that, I misread the #ifdefs.

> > Where does it actually crash?
>
> The code crashes in mercury_wrapper.c:mercury_runtime_init() when it
> executes the macro MR_save_registers().

Ah, I see now.

The code that is causing trouble is in mercury_wrapper.c from line 508

	#if defined(MR_HIGHLEVEL_CODE) && defined(MR_CONSERVATIVE_GC)
		MR_init_memory();
	  #ifdef MR_USE_TRAIL
		/* initialize the trail */
		MR_trail_zone = MR_create_zone("trail", 0,
			MR_trail_size, MR_next_offset(),
			MR_trail_zone_size, MR_default_handler);
		MR_trail_ptr = (MR_TrailEntry *) MR_trail_zone->min;
		MR_ticket_counter = 1;
		MR_ticket_high_water = 1;
	  #endif
	#else
		/* start up the Mercury engine */
		...
	#endif

This code was part of my long-term goal of eventually eliminating the need
for the low-level back-end.  This code is deliberately trying to avoid
starting up the Mercury engine in the case when both MR_HIGHLEVEL_CODE
and MR_CONSERVATIVE are defined.  The idea is that if we're using the
conservative collector and we're generating ANSI C, then there's no need
for the code to have any dependencies on all of that complicated code
which manages the Mercury engine.

Unfortunately this appears to not be the case any more, because
various bits and pieces of code have crept in that depend on the
Mercury engine stuff and are which are not inside appropriate #ifdefs.

> In order to see what's going on
> there we've tried replacing the contents of mercury_wrapper.c with
> mercury_wrapper.i, but that seems to make every version of gcc we have
> either crash or generate code that doesn't work!
>
> The part of the .i file showing the expansion of MR_save_registers is
>
> do {
> 	((void) 0);
> 	(((((MercuryEngine *) ((MercuryEngine *)
> 	pthread_getspecific((MR_engine_base_key))))->
> 		MR_eng_fake_reg))[((32 + 6) + 3) ]) = (MR_Word) (MR_sol_hp_var);
> 	(((((MercuryEngine *) ((MercuryEngine *)
> 	pthread_getspecific((MR_engine_base_key))))->
> 		MR_eng_fake_reg))[((32 + 6) + 4) ]) = (MR_Word) (MR_min_hp_rec_var);
> 	(((((MercuryEngine *) ((MercuryEngine *)
> 	pthread_getspecific((MR_engine_base_key))))->
> 		MR_eng_fake_reg))[((32 + 6) + 5) ]) = (MR_Word) (MR_min_sol_hp_rec_var);
> 	(((((MercuryEngine *) ((MercuryEngine *)
> 	pthread_getspecific((MR_engine_base_key))))->
> 		MR_eng_fake_reg))[((32 + 6) + 6) ]) = (MR_Word) (MR_global_hp_var);
>
> 	((void) 0);
> 	((void) 0);
> } while (0);

Hmm, perhaps all of the stuff which accesses MR_*hp* should be
made conditional on #ifndef MR_CONSERVATIVE_GC.  Also the call to
MR_save_registers() in mercury_init() should be conditional on whether
we're using a Mercury engine.

So, to summarize: instead of the "voodoo" fix, I suggest either
	- change the "#if defined(MR_HIGHLEVEL_CODE) && defined(MR_CONSERVATIVE_GC)"
	  at line to "#if 0" and add a comment explaining the intent of
	  this code and why it doesn't work anymore
or
	- ensure that any uses of the Mercury engine's virtual machine registers
	  are conditionalized with #ifdefs so that they do not happen
	  in the case when there is no Mercury engine.

-- 
Fergus J. Henderson                 |  "I have always known that the pursuit
Galois Connections, Inc.            |  of excellence is a lethal habit"
Phone: +1 503 626 6616              |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list