[m-dev.] Tabling final DIFF
Fergus Henderson
fjh at cs.mu.OZ.AU
Tue May 5 22:58:12 AEST 1998
On 05-May-1998, Oliver Hutchison <ohutch at students.cs.mu.oz.au> wrote:
>
> Here are to three files you wanted to have a look at. I hope you
> better understand what is going on with table_suspend/resume given the new
> comments. I am sorry about the delay with my response but I have been very
> busy over the last month.
That's OK, thanks for your work. The documentation for suspend &
resume is a lot better, although still short of ideal.
mercury_builtin.m:
> +/*
> +** The following procedure saves the state of the mercury runtime
> +** so that it may be used in the table_resume procedure bellow to return
> +** answers through this saved state. The procedure table_suspend is
> +** declared as nondet but the code bellow is obviously of detism failure,
> +** the reason for this is quite simple. Normally when a nondet proc
> +** is called it will first return all of its answers and then fail. In the
> +** case of calls to this procedure this is reversed first the call will fail
> +** then later on, when the answers are found, answers will be returned.
> +** It is also important to note that the answers are returned not from the
> +** procedure that was originally called (table_suspend) but from the procedure
> +** table_resume. So essentially what is bellow is the code to do the initial
> +** fail the code to return the answers is in table_resume.
> +*/
s/bellow/below/g
s/fail the code/fail; the code/
> +Define_entry(mercury__table_suspend_2_0);
...
> + ListNode = list_cons(Node, *NON_TABLE(r1)->suspend_list_tail);
> + *NON_TABLE(r1)->suspend_list_tail = ListNode;
> + NON_TABLE(r1)->suspend_list_tail = &list_tail(ListNode);
> +}
> + fail();
Here you're calling list_cons(), which will allocate memory
on the Mercury heap, rather than via table_allocate().
In non-conservative-gc grades, this memory will go away
on backtracking, i.e. at the call to fail().
One possible solution would be to define a macro MR_table_list_cons()
which was like list_cons() except that it allocates memory using
table_allocate() rather than incr_hp().
If you're really pressed for time I suppose that you could just do
#ifdef CONSERVATIVE_GC
#define MR_table_list_cons(h,t) list_cons((h),(t))
#else
#define MR_table_list_cons(h,t) list_cons((h),(t)) \
fatal_error("Sorry, not implemented: tabling in non-GC grades")
#endif
but that would be a pity.
> +:- pragma c_code(table_new_ans_slot(T::in, Slot::out),
> + will_not_call_mercury, "
> + Word ListNode;
> + Word ans_num;
> + AnswerListNode *n = table_allocate(sizeof(AnswerListNode));
> +
> + ++(NON_TABLE(T)->num_ans);
> + ans_num = NON_TABLE(T)->num_ans;
> + n->ans_num = ans_num;
> + n->ans = 0;
> + ListNode = list_cons(n, *NON_TABLE(T)->answer_list_tail);
> + *NON_TABLE(T)->answer_list_tail = ListNode;
> + NON_TABLE(T)->answer_list_tail = &list_tail(ListNode);
> +
> + Slot = (Word) &n->ans;
> +").
I think the same consideration about the use of list_cons()
applies here too. Possibly elsewhere, too.
If I were you I'd do a grep for list_cons on your diff.
runtime/mercury_type_info.c:
> + ** NOTE: If you are changing this code, you might also need
> + ** to change the code in create_type_info in library/std_util.m,
> + ** which does much the same thing, only allocating on the
> + ** heap instead of using malloc.
s/create_type_info/MR_create_type_info/
s^in library/std_util.m^(defined above)6
Apart from that, those three files look OK.
So you can go ahead and commit it all.
It may be easiest if you commit what you have
now plus the above-mentioned fixes to comments,
and then commit the list_cons() fix as
a seperate change.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list