[m-rev.] for test and review by Peter: fix mantis 391

Zoltan Somogyi zoltan.somogyi at runbox.com
Sat Aug 15 18:59:05 AEST 2015



On Sat, 15 Aug 2015 14:15:52 +1000, Peter Wang <novalazy at gmail.com> wrote:
> Thanks for the quick fix.

You are welcome.

> > diff --git a/compiler/mercury_to_mercury.m b/compiler/mercury_to_mercury.m
> > index 732ec2a..de6ab38 100644
> > --- a/compiler/mercury_to_mercury.m
> > +++ b/compiler/mercury_to_mercury.m
> > @@ -3624,9 +3624,9 @@ mercury_output_trace_expr(PrintBase, TraceExpr, !IO) :-
> >      ).
> >  
> >  mercury_output_trace_compiletime(trace_flag(FlagName), !IO) :-
> > -    io.write_string("flag(", !IO),
> > +    io.write_string("flag(\"", !IO),
> >      io.write_string(FlagName, !IO),
> > -    io.write_string(")", !IO).
> > +    io.write_string("\")", !IO).
> >  mercury_output_trace_compiletime(trace_grade(Grade), !IO) :-
> >      parse_trace_grade_name(GradeName, Grade),
> >      io.write_string("grade(", !IO),
> > @@ -3644,9 +3644,9 @@ mercury_output_trace_compiletime(trace_trace_level(Level), !IO) :-
> >      io.write_string(")", !IO).
> >  
> >  mercury_output_trace_runtime(trace_envvar(EnvVarName), !IO) :-
> > -    io.write_string("env(", !IO),
> > +    io.write_string("env(\"", !IO),
> >      io.write_string(EnvVarName, !IO),
> > -    io.write_string(")", !IO).
> > +    io.write_string("\")", !IO).
> 
> FlagName requires escaping (with add_quoted_string?).
> It would be safe to escape EnvVarName as well, but not strictly
> necessary due to the (undocumented) restrictions on its characters.

I will fix that.

> There is a problem when a trace goal with a state parameter is
> opt-exported:
> 
> trace_goal_opt_2.opt:034: In clause for predicate `require_lt'/2:
> trace_goal_opt_2.opt:034:   error: undefined predicate `get_x'/1.
> trace_goal_opt_2.opt:034: In clause for predicate `require_lt'/2:
> trace_goal_opt_2.opt:034:   error: undefined predicate `set_x'/1.
> 
> As the goal in the .opt file has already been transformed perhaps the
> state parameters can just be omitted?

We could omit the state parameters, but that won't solve the problem.
Mutables are local to their defining module, and so are their get and
set predicates, so whether you put those get and set calls directly
into the .opt file, or let the module that reads the .opt file recreate
those calls when it processes the trace goal, the result will be
the same: an attempt to access an inaccessible predicate.
Unless of course we opt-export the mutables' access predicates.
We would need to teach the compiler to either do that, or to
veto the opt-export of the predicate body containing that trace goal.

Since the impure predicates to get and set the I/O state *are*
exported from io.m, we *could* use your solution to handle
io parameters in trace goals, possibly with a purity cast thrown in,
if we modified the code that selects what can be put into .opt files
has been modified not to see the calls to those predicates in the
bodies of trace goals as a reason *not* to export the predicate
body containing the trace goal.

Zoltan.




More information about the reviews mailing list