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

Peter Wang novalazy at gmail.com
Sat Aug 15 14:15:52 AEST 2015


On Fri, 14 Aug 2015 20:28:57 +1000 (AEST), "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> Peter, I think this fixes mantis 391, but I can only look at
> the generated .opt file; in the absence of the rest of the code
> that require_lt.m was derived from, I cannot fully test the fix.
> Can you please try out this diff? You may also want to add
> a test case for the bug to our test suite.
> 

Thanks for the quick fix.

> 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.

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?

I've attached the modules.

Peter
-------------- next part --------------
%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
% Check that trace goal conditions are written to .opt files.

:- module trace_goal_opt.

:- interface.

:- import_module io.

:- pred main(io::di, io::uo) is det.

:- implementation.

:- import_module trace_goal_opt_2.

main(!IO) :-
    require_lt(2, 1),
    io.write_string("done.\n", !IO).
-------------- next part --------------
%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%

:- module trace_goal_opt_2.
:- interface.

:- pred require_lt(int::in, int::in) is det.

:- implementation.

:- import_module exception.
:- import_module int.

:- mutable(x, int, 0, ground, [untrailed]).

:- pragma inline(require_lt/2).

require_lt(A, B):-
    trace [
        compiletime(flag("abc") or flag("\"xyz\"") or grade(debug)),
        runtime(env("TRACE_ABC")),
        state(x, !X)
        % io(!IO) prevents opt-exporting?
    ] (
        require_lt0(A, B)
    ).

:- pred require_lt0(int::in, int::in) is det.

require_lt0(A, B):-
    ( if A < B then
        true
    else
        throw("require_lt0")
    ).


More information about the reviews mailing list