[m-rev.] for review: make I/O tabling respect pragma no_inline

Ian MacLarty maclarty at cs.mu.OZ.AU
Wed Sep 14 18:19:56 AEST 2005


On Wed, 14 Sep 2005, Julien Fischer wrote:

>
> On Wed, 14 Sep 2005, Ian MacLarty wrote:
>
> ...
>
> > > > tests/debugger/Mercury.options:
> > > > tests/debugger/Mmakefile:
> > > > tests/debugger/io_tab_goto.data:
> > > > tests/debugger/io_tab_goto.exp:
> > > > tests/debugger/io_tab_goto.inp:
> > > > tests/debugger/io_tab_goto.m:
> > > > 	Test that foreign C code with labels is I/O tabled correctly.
> > > >
> > >
> > > I suggest also updating the user guide extion on I/O tabling to warn about
> > > C code that contains labels.
> > >
> >
> > I don't think that's the right place.  I think it should be documented
> > with the tabled_for_io attribute in the reference manual, however the
> > tabled_for_io attribute isn't documented at all, so I've added the
> > following to the reference manual:
> >
> It strikes me as being a reasonable place to put it, after all
> that's where the debugger documentation is.
>

The reference manual is where all the other foreign_proc attributes are
described.

> > @@ -6004,6 +6004,15 @@
> >
> >  @table @asis
> >
> > + at item @samp{tabled_for_io}
> > +This attribute should be attached to foreign procs which do I/O.  It
> Either foreign_procs or foreign procedures
>
> s/which/that/
>

Fixed.

> > +tells the debugger to make calls to the foreign proc idempotent.
> Likewise, either foreign_proc or foreign procedure
>

Fixed.

> > +This allows the debugger to safely retry accross such calls and also
> s/accross/across/
>

Fixed.

> > +allows safe declarative debugging of code containing such calls.
> > +For more information see the I/O tabling section of the Mercury user guide.
> > +If the foreign proc contains gotos then the @samp{pragma no_inline}
> > +directive should also be given.
> > +
> Section 14.1.2 of the reference manual describes the situations where
> you don't want to inline foreign code - you also don't want to do
> it when you have static local variables.  (It may be worth pointing
> the reader to this discussion, although we should really move into
> the documentation for the new foreign language interface.)
>

I added a reference to this section.

> > I actually missed something:  The introduced predicate must not be traced.
> > If it is traced then the event numbers of events after the I/O action will
> > be different when the I/O action is reexecuted (because the introduced
> > predicate won't be reexecuted).
> >
> > Here's the interdiff that fixes this:
> >
> > only in patch2:
> > --- compiler/trace_params.m	29 Aug 2005 08:44:13 -0000	1.24
> > +++ compiler/trace_params.m	14 Sep 2005 04:59:39 -0000
> > @@ -180,6 +180,14 @@
> >  				SpecialPred = (initialise),
> >  				EffTraceLevel = TraceLevel
> >  			)
> > +		; Origin = created(io_tabling) ->
> > +			% Predicates called by a predicate which is I/O
>
> s/which/that/
>

Fixed.

> > +		{ char__is_digit(Char) },
> > +		{ char__digit_to_int(Char, CharInt) }
> > +	->
> > +		tabled_read_decl_goto__poly_test_2(Stream, Unused,
> > +			SoFar * 10 + CharInt, N)
> > +	;
> > +		{ N = SoFar }
> > +	).
> > +
> > +:- pragma c_header_code("#include <stdio.h>").
> > +
> Is there any reason you are not using
> 	:- pragma foreign_decl("C", "#include <stdio.h>")
>
> here?
>

The reason is because I copied this test case from tabled_read_decl.m.

I've changed it to a foreign_decl.

Here's  the interdiff:

diff -u compiler/table_gen.m compiler/table_gen.m
--- compiler/table_gen.m	13 Sep 2005 09:06:16 -0000
+++ compiler/table_gen.m	14 Sep 2005 07:03:51 -0000
@@ -1182,9 +1182,9 @@
         %
         % If the predicate should not be inlined, then we create a new
         % predicate with the same body as the original predicate, which is
-        % called where-ever the original goal would appear in the transformed
+        % called wherever the original goal would appear in the transformed
         % code.  This is necessary when the original goal is foreign C code
-        % which uses labels.  The original goal would otherwise be duplicated
+        % that uses labels.  The original goal would otherwise be duplicated
         % by the transformation, resulting in duplicate label errors from
         % the C compiler.
         %
@@ -1833,7 +1833,8 @@
         OrigPredName = pred_info_name(PredInfo),
         PredOrFunc = pred_info_is_pred_or_func(PredInfo),
         pred_info_context(PredInfo, PredContext),
-        NewPredName = qualified(ModuleName, "OutlinedFrom_" ++ OrigPredName),
+        NewPredName = qualified(ModuleName, "OutlinedForIOTablingFrom_" ++
+            OrigPredName),
         pred_info_arg_types(PredInfo, PredArgTypes),
         pred_info_typevarset(PredInfo, PredTypeVarSet),
         pred_info_get_exist_quant_tvars(PredInfo, PredExistQVars),
diff -u compiler/trace_params.m compiler/trace_params.m
--- compiler/trace_params.m	14 Sep 2005 04:59:39 -0000
+++ compiler/trace_params.m	14 Sep 2005 08:09:37 -0000
@@ -181,7 +181,7 @@
 				EffTraceLevel = TraceLevel
 			)
 		; Origin = created(io_tabling) ->
-			% Predicates called by a predicate which is I/O
+			% Predicates called by a predicate that is I/O
 			% tabled should not be traced.  If such a predicate
 			% were allowed to generate events then the event
 			% numbers of events after the I/O primitive would be
diff -u doc/reference_manual.texi doc/reference_manual.texi
--- doc/reference_manual.texi	14 Sep 2005 05:45:55 -0000
+++ doc/reference_manual.texi	14 Sep 2005 08:16:29 -0000
@@ -6005,13 +6005,14 @@
 @table @asis

 @item @samp{tabled_for_io}
-This attribute should be attached to foreign procs which do I/O.  It
-tells the debugger to make calls to the foreign proc idempotent.
-This allows the debugger to safely retry accross such calls and also
+This attribute should be attached to foreign procedures that do I/O.  It
+tells the debugger to make calls to the foreign procedure idempotent.
+This allows the debugger to safely retry across such calls and also
 allows safe declarative debugging of code containing such calls.
 For more information see the I/O tabling section of the Mercury user guide.
-If the foreign proc contains gotos then the @samp{pragma no_inline}
-directive should also be given.
+If the foreign procedure contains gotos or static variables then the
+ at samp{pragma no_inline} directive should also be given
+(see @ref{pragma c_code}).

 @item @samp{terminates}/@samp{does_not_terminate}
 This attribute specifies the termination properties of the given predicate
diff -u tests/debugger/declarative/tabled_read_decl_goto.m tests/debugger/declarative/tabled_read_decl_goto.m
--- tests/debugger/declarative/tabled_read_decl_goto.m	14 Sep 2005 05:24:26 -0000
+++ tests/debugger/declarative/tabled_read_decl_goto.m	14 Sep 2005 08:10:28 -0000
@@ -92,7 +92,7 @@
 		{ N = SoFar }
 	).

-:- pragma c_header_code("#include <stdio.h>").
+:- pragma foreign_decl("C", "#include <stdio.h>").

 :- pred tabled_read_decl_goto__open_input(string::in, int::out, c_pointer::out,
 	io__state::di, io__state::uo) is det.

Ian.

--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list