mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 21:35:49 +00:00
Estimated hours taken: 12 Branches: main Fix a bug that caused bootchecks with --optimize-constructor-last-call to fail. The problem was not in lco.m, but in follow_code.m. In some cases, (specifically, the LCMC version of insert_2 in sparse_bitset.m), follow_code.m moved an impure goal (store_at_ref) into the arms of an if-then-else without marking those arms, or the if-then-else, as impure. The next pass, simplify, then deleted the entire if-then-else, since it had no outputs. (The store_at_ref that originally appeared after the if-then-else was the only consumer of its only output.) The fix is to get follow_code.m to make branched control structures such as if-then-elses, as well as their arms, semipure or impure if a goal being moved into them is semipure or impure, or if they came from an semipure or impure conjunction. Improve the optimization of the LCMC version of sparse_bitset.insert_2, which had a foreign_proc invocation of bits_per_int in it: replace such invocations with a unification of the bits_per_int constant if not cross compiling. Add a new option, --optimize-constructor-last-call-null. When set, LCMC will assign NULLs to the fields not yet filled in, to avoid any junk happens to be there from being followed by the garbage collector's mark phase. This diff also makes several other changes that helped me to track down the bug above. compiler/follow_code.m: Make the fix described above. Delete all the provisions for --prev-code; it won't be implemented. Don't export a predicate that is not now used anywhere else. compiler/simplify.m: Make the optimization described above. compiler/lco.m: Make sure that the LCMC specialized procedure is a predicate, not a function: having a function with the mode LCMC_insert_2(in, in) = in looks wrong. To avoid name collisions when a function and a predicate with the same name and arity have LCMC applied to them, include the predicate vs function status of the original procedure included in the name of the new procedure. Update the sym_name of calls to LCMC variants, not just the pred_id, because without that, the HLDS dump looks misleading. compiler/pred_table.m: Don't have optimizations like LCMC insert new predicates at the front of the list of predicates. Maintain the list of predicates in the module as a two part list, to allow efficient addition of new pred_ids at the (logical) end without using O(N^2) algorithms. Having predicates in chronological order makes it easier to look at HLDS dumps and .c files. compiler/hlds_module.m: Make module_info_predids return a module_info that is physically updated though logically unchanged. compiler/options.m: Add --optimize-constructor-last-call-null. Make the options --dump-hlds-pred-id, --debug-opt-pred-id and --debug-opt-pred-name into accumulating options, to allow the user to specify more than one predicate to be dumped (e.g. insert_2 and its LCMC variant). Delete --prev-code. doc/user_guide.texi: Document the changes in options.m. compiler/code_info.m: Record the value of --optimize-constructor-last-call-null in the code_info, to avoid lookup at every cell construction. compiler/unify_gen.m: compiler/var_locn.m: When deciding whether a cell can be static or not, make sure that we never make static a cell that has some fields initialized with dummy zeros, to be filled in for real later. compiler/hlds_out.m: For goals that are semipure or impure, note this fact. This info was lost when I changed the representation of impurity from markers to a field. mdbcomp/prim_data.m: Rename some ambiguous function symbols. compiler/intermod.m: compiler/trans_opt.m: Rename the main predicates (and some function symbols) of these modules to avoid ambiguity and to make them more expressive. compiler/llds.m: Don't print line numbers for foreign_code fragments if the user has specified --no-line-numbers. compiler/make.dependencies.m: compiler/mercury_to_mercury.m: compiler/recompilation.usage.m: Don't use io.write to write out information to files we may need to parse again, because this is vulnerable to changes to the names of function symbols (e.g. the one to mdbcomp/prim_data.m). The compiler still contains some uses of io.write, but they are for debugging. I added an item to the todo list of the one exception, ilasm.m. compiler/recompilation.m: Rename a misleading function symbol name. compiler/parse_tree.m: Don't import recompilation.m here. It is not needed (all the components of parse_tree that need recompilation.m already import it themselves), and deleting the import avoids recompiling almost everything when recompilation.m changes. compiler/*.m: Conform to the changes above. compiler/*.m: browser/*.m: slice/*.m: Conform to the change to mdbcomp. library/sparse_bitset.m: Use some better variable names.
181 lines
5.5 KiB
Mathematica
181 lines
5.5 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1998-2002, 2004-2007 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU Library General
|
|
% Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module mdb.util.
|
|
:- interface.
|
|
|
|
:- import_module mdbcomp.prim_data.
|
|
|
|
:- import_module bool.
|
|
:- import_module io.
|
|
:- import_module list.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- func is_predicate(pred_or_func) = bool.
|
|
:- func is_function(pred_or_func) = bool.
|
|
|
|
:- type line_number == int.
|
|
|
|
% Get user input via the same method used by the internal debugger.
|
|
%
|
|
:- pred trace_getline(string::in, io.result(string)::out,
|
|
io::di, io::uo) is det.
|
|
|
|
:- pred trace_getline(string::in, io.result(string)::out,
|
|
io.input_stream::in, io.output_stream::in, io::di, io::uo) is det.
|
|
|
|
% trace_get_command is similar to trace_getline except that it
|
|
% breaks lines into semicolon separated commands, and replaces
|
|
% EOF with the command 'quit'.
|
|
%
|
|
:- pred trace_get_command(string::in, string::out, io::di, io::uo)
|
|
is det.
|
|
|
|
:- pred trace_get_command(string::in, string::out,
|
|
io.input_stream::in, io.output_stream::in, io::di, io::uo) is det.
|
|
|
|
:- pred zip_with(pred(T1, T2, T3)::in(pred(in, in, out) is det),
|
|
list(T1)::in, list(T2)::in, list(T3)::out) is det.
|
|
|
|
% Apply predicate to argument repeatedly until the result
|
|
% remains the same.
|
|
%
|
|
:- pred limit(pred(list(T), list(T))::in(pred(in, out) is det),
|
|
list(T)::in, list(T)::out) is det.
|
|
|
|
% For use in representing unbound head variables in the "print goal"
|
|
% commands in the debugger.
|
|
:- type unbound ---> '_'.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module require.
|
|
|
|
is_predicate(pf_predicate) = yes.
|
|
is_predicate(pf_function) = no.
|
|
|
|
is_function(pf_predicate) = no.
|
|
is_function(pf_function) = yes.
|
|
|
|
trace_getline(Prompt, Result, !IO) :-
|
|
io.input_stream(MdbIn, !IO),
|
|
io.output_stream(MdbOut, !IO),
|
|
trace_getline(Prompt, Result, MdbIn, MdbOut, !IO).
|
|
|
|
trace_getline(Prompt, Result, MdbIn, MdbOut, !IO) :-
|
|
call_trace_getline(MdbIn, MdbOut, Prompt, Line, Success, !IO),
|
|
( Success \= 0 ->
|
|
Result = ok(Line)
|
|
;
|
|
Result = eof
|
|
).
|
|
|
|
:- pred call_trace_getline(input_stream::in, output_stream::in, string::in,
|
|
string::out, int::out, io.state::di, io.state::uo) is det.
|
|
|
|
:- pragma foreign_decl("C", "
|
|
#include ""mercury_wrapper.h""
|
|
#include ""mercury_string.h""
|
|
#include ""mercury_trace_base.h""
|
|
#include ""mercury_library_types.h""
|
|
").
|
|
|
|
:- pragma foreign_proc("C",
|
|
call_trace_getline(MdbIn::in, MdbOut::in, Prompt::in, Line::out,
|
|
Success::out, IO0::di, IO::uo),
|
|
% We need to use will_not_call_mercury here,
|
|
% because MR_make_aligned_string_copy() references MR_hp,
|
|
% which only works for will_not_call_mercury foreign_procs.
|
|
[will_not_call_mercury, promise_pure, tabled_for_io],
|
|
"
|
|
char *line;
|
|
MercuryFile *mdb_in = (MercuryFile *) MdbIn;
|
|
MercuryFile *mdb_out = (MercuryFile *) MdbOut;
|
|
|
|
if (MR_address_of_trace_getline != NULL) {
|
|
line = (*MR_address_of_trace_getline)((char *) Prompt,
|
|
MR_file(*mdb_in), MR_file(*mdb_out));
|
|
} else {
|
|
MR_tracing_not_enabled();
|
|
/* not reached */
|
|
}
|
|
|
|
if (line == NULL) {
|
|
/* we copy the null string to avoid warnings about const */
|
|
MR_make_aligned_string_copy(Line, """");
|
|
Success = 0;
|
|
} else {
|
|
MR_make_aligned_string_copy(Line, line);
|
|
MR_free(line);
|
|
Success = 1;
|
|
}
|
|
|
|
IO = IO0;
|
|
").
|
|
|
|
call_trace_getline(_, _, _, _, _, !IO) :-
|
|
private_builtin.sorry("mdb.call_trace_getline").
|
|
|
|
trace_get_command(Prompt, Result, !IO) :-
|
|
io.input_stream(MdbIn, !IO),
|
|
io.output_stream(MdbOut, !IO),
|
|
trace_get_command(Prompt, Result, MdbIn, MdbOut, !IO).
|
|
|
|
:- pragma foreign_proc("C",
|
|
trace_get_command(Prompt::in, Line::out, MdbIn::in,
|
|
MdbOut::in, State0::di, State::uo),
|
|
[will_not_call_mercury, promise_pure, tabled_for_io],
|
|
"
|
|
char *line;
|
|
MercuryFile *mdb_in = (MercuryFile *) MdbIn;
|
|
MercuryFile *mdb_out = (MercuryFile *) MdbOut;
|
|
|
|
if (MR_address_of_trace_getline != NULL) {
|
|
line = (*MR_address_of_trace_get_command)(
|
|
(char *) Prompt,
|
|
MR_file(*mdb_in), MR_file(*mdb_out));
|
|
} else {
|
|
MR_tracing_not_enabled();
|
|
/* not reached */
|
|
}
|
|
|
|
MR_make_aligned_string_copy(Line, line);
|
|
MR_free(line);
|
|
|
|
State = State0;
|
|
").
|
|
|
|
trace_get_command(_, _, _, _, !IO) :-
|
|
private_builtin.sorry("mdb.trace_get_command/6").
|
|
|
|
zip_with(Pred, XXs, YYs, Zipped) :-
|
|
( (XXs = [], YYs = []) ->
|
|
Zipped = []
|
|
; (XXs = [X | Xs], YYs = [Y | Ys]) ->
|
|
Pred(X,Y,PXY),
|
|
Zipped = [PXY | Rest],
|
|
zip_with(Pred, Xs, Ys, Rest)
|
|
;
|
|
error("zip_with: list arguments are of unequal length")
|
|
).
|
|
|
|
limit(Pred, Xs, Ys) :-
|
|
Pred(Xs, Zs),
|
|
( Xs = Zs ->
|
|
Ys = Zs
|
|
;
|
|
limit(Pred, Zs, Ys)
|
|
).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|