Specify output streams in some places.

Besides this main purpose, this diff also replaces code that calls
io.write_string several times in a row with code that prints the
thing to be printed in one go with io.format.

compiler/accumulator.m:
compiler/code_gen.m:
compiler/dead_proc_elim.m:
compiler/interval.m:
compiler/ite_gen.m:
compiler/lco.m:
compiler/mode_debug.m:
compiler/mode_info.m:
compiler/modes.m:
compiler/stack_opt.m:
    As above.

compiler/Mercury.options:
    Specify --warn-implicit-stream-calls for the modules above,
    and for some other modules that are already free of such warnings.
This commit is contained in:
Zoltan Somogyi
2021-03-24 22:02:18 +11:00
parent a30b60e6bf
commit 85eb971b8d
11 changed files with 327 additions and 285 deletions

View File

@@ -101,12 +101,23 @@ MCFLAGS-parse_tree.parse_tree_out_info = --no-warn-unknown-format-calls
MCFLAGS-backend_libs.c_util += --warn-implicit-stream-calls
MCFLAGS-backend_libs.export += --warn-implicit-stream-calls
MCFLAGS-backend_libs.interval += --warn-implicit-stream-calls
MCFLAGS-check_hlds.cse_detection += --warn-implicit-stream-calls
MCFLAGS-check_hlds.delay_partial_inst += --warn-implicit-stream-calls
MCFLAGS-check_hlds.det_analysis += --warn-implicit-stream-calls
MCFLAGS-check_hlds.inst_test += --warn-implicit-stream-calls
MCFLAGS-check_hlds.mode_debug += --warn-implicit-stream-calls
MCFLAGS-check_hlds.mode_info += --warn-implicit-stream-calls
MCFLAGS-check_hlds.modes += --warn-implicit-stream-calls
MCFLAGS-check_hlds.simplify.format_call += --warn-implicit-stream-calls
MCFLAGS-check_hlds.simplify.simplify_goal += --warn-implicit-stream-calls
MCFLAGS-check_hlds.simplify.simplify_goal_call += --warn-implicit-stream-calls
MCFLAGS-check_hlds.simplify.simplify_goal_conj += --warn-implicit-stream-calls
MCFLAGS-check_hlds.simplify.simplify_goal_disj += --warn-implicit-stream-calls
MCFLAGS-check_hlds.simplify.simplify_goal_ite += --warn-implicit-stream-calls
MCFLAGS-check_hlds.simplify.simplify_goal_scope += --warn-implicit-stream-calls
MCFLAGS-check_hlds.simplify.simplify_goal_switch += --warn-implicit-stream-calls
MCFLAGS-check_hlds.simplify.simplify_goal_unify += --warn-implicit-stream-calls
MCFLAGS-check_hlds.type_assign += --warn-implicit-stream-calls
MCFLAGS-check_hlds.typecheck += --warn-implicit-stream-calls
MCFLAGS-hlds.du_type_layout += --warn-implicit-stream-calls
@@ -119,7 +130,9 @@ MCFLAGS-hlds.hlds_out_util += --warn-implicit-stream-calls
MCFLAGS-hlds.passes_aux += --warn-implicit-stream-calls
MCFLAGS-libs.file_util += --warn-implicit-stream-calls
MCFLAGS-libs.mmakefiles += --warn-implicit-stream-calls
MCFLAGS-ll_backend.code_gen += --warn-implicit-stream-calls
MCFLAGS-ll_backend.code_loc_dep += --warn-implicit-stream-calls
MCFLAGS-ll_backend.ite_gen += --warn-implicit-stream-calls
MCFLAGS-ll_backend.layout_out += --warn-implicit-stream-calls
MCFLAGS-ll_backend.llds_out_code_addr += --warn-implicit-stream-calls
MCFLAGS-ll_backend.llds_out_data += --warn-implicit-stream-calls
@@ -130,6 +143,7 @@ MCFLAGS-ll_backend.llds_out_util += --warn-implicit-stream-calls
MCFLAGS-ll_backend.opt_debug += --warn-implicit-stream-calls
MCFLAGS-ll_backend.optimize += --warn-implicit-stream-calls
MCFLAGS-ll_backend.rtti_out += --warn-implicit-stream-calls
MCFLAGS-ll_backend.stack_opt += --warn-implicit-stream-calls
MCFLAGS-ml_backend.ml_optimize += --warn-implicit-stream-calls
MCFLAGS-ml_backend.mlds_dump += --warn-implicit-stream-calls
MCFLAGS-ml_backend.mlds_to_c_class += --warn-implicit-stream-calls
@@ -176,8 +190,11 @@ MCFLAGS-parse_tree.write_module_interface_files += --warn-implicit-stream-calls
MCFLAGS-recompilation += --warn-implicit-stream-calls
MCFLAGS-recompilation.usage += --warn-implicit-stream-calls
MCFLAGS-recompilation.version += --warn-implicit-stream-calls
MCFLAGS-transform_hlds.accumulator += --warn-implicit-stream-calls
MCFLAGS-transform_hlds.dead_proc_elim += --warn-implicit-stream-calls
MCFLAGS-transform_hlds.deforest += --warn-implicit-stream-calls
MCFLAGS-transform_hlds.intermod += --warn-implicit-stream-calls
MCFLAGS-transform_hlds.lco += --warn-implicit-stream-calls
MCFLAGS-transform_hlds.unneeded_code += --warn-implicit-stream-calls
# Keep all modules' contents in a consistent order, except these (for now).

View File

@@ -258,9 +258,12 @@ accu_transform_proc(proc(PredId, ProcId), PredInfo, !ProcInfo, !ModuleInfo,
(
VeryVerbose = yes,
trace [io(!IO)] (
module_info_get_name(!.ModuleInfo, ModuleName),
get_progress_output_stream(Globals, ModuleName,
ProgressStream, !IO),
PredStr = pred_id_to_string(!.ModuleInfo, PredId),
io.format("%% Accumulators introduced into %s\n",
[s(PredStr)], !IO)
io.format(ProgressStream,
"%% Accumulators introduced into %s\n", [s(PredStr)], !IO)
)
;
VeryVerbose = no

View File

@@ -48,6 +48,7 @@
:- import_module hlds.hlds_desc.
:- import_module hlds.hlds_pred.
:- import_module hlds.instmap.
:- import_module hlds.passes_aux.
:- import_module libs.
:- import_module libs.globals.
:- import_module ll_backend.call_gen.
@@ -89,8 +90,10 @@ generate_goal(ContextModel, Goal, Code, !CI, !CLD) :-
GoalDesc = describe_goal(ModuleInfo, VarSet, Goal),
( if should_trace_code_gen(!.CI) then
io.format("\nGOAL START: %s\n", [s(GoalDesc)], !IO),
io.flush_output(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.format(DebugStream, "\nGOAL START: %s\n",
[s(GoalDesc)], !IO),
io.flush_output(DebugStream, !IO)
else
true
)
@@ -194,11 +197,12 @@ generate_goal(ContextModel, Goal, Code, !CI, !CLD) :-
GoalDesc = describe_goal(ModuleInfo, VarSet, Goal),
( if should_trace_code_gen(!.CI) then
io.format("\nGOAL FINISH: %s\n", [s(GoalDesc)], !IO),
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
Instrs = cord.list(Code),
io.output_stream(Stream, !IO),
write_instrs(Stream, Instrs, no, auto_comments, !IO),
io.flush_output(Stream, !IO)
io.format(DebugStream, "\nGOAL FINISH: %s\n",
[s(GoalDesc)], !IO),
write_instrs(DebugStream, Instrs, no, auto_comments, !IO),
io.flush_output(DebugStream, !IO)
else
true
)

View File

@@ -590,14 +590,13 @@ dead_proc_examine_proc(proc(PredId, ProcId), AnalyzeTraceGoalProcs,
map.lookup(ProcTable, ProcId, ProcInfo)
then
trace [io(!IO), compile_time(flag("dead_proc_elim"))] (
io.write_string("examining proc ", !IO),
io.write_int(pred_id_to_int(PredId), !IO),
io.write_string(" ", !IO),
io.write_int(proc_id_to_int(ProcId), !IO),
io.nl(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.format(DebugStream, "examining proc %d %d\n",
[i(pred_id_to_int(PredId)), i(proc_id_to_int(ProcId))], !IO)
),
proc_info_get_goal(ProcInfo, Goal),
dead_proc_examine_goal(Goal, proc(PredId, ProcId), !Queue, !Needed),
dead_proc_examine_goal(Goal, proc(PredId, ProcId),
ModuleInfo, !Queue, !Needed),
(
AnalyzeTraceGoalProcs = do_not_analyze_link_deleted_calls
;
@@ -615,11 +614,10 @@ dead_proc_examine_proc(proc(PredId, ProcId), AnalyzeTraceGoalProcs,
;
HasPerProcTablingPtr = yes,
trace [io(!IO), compile_time(flag("dead_proc_elim"))] (
io.write_string("need table struct for proc ", !IO),
io.write_int(pred_id_to_int(PredId), !IO),
io.write_string(" ", !IO),
io.write_int(proc_id_to_int(ProcId), !IO),
io.nl(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.format(DebugStream, "need table struct for proc %d %d\n",
[i(pred_id_to_int(PredId)), i(proc_id_to_int(ProcId))],
!IO)
),
TableStructEntity = entity_table_struct(PredId, ProcId),
map.set(TableStructEntity, not_eliminable, !Needed)
@@ -633,11 +631,9 @@ dead_proc_examine_proc(proc(PredId, ProcId), AnalyzeTraceGoalProcs,
)
else
trace [io(!IO), compile_time(flag("dead_proc_elim"))] (
io.write_string("not examining proc ", !IO),
io.write_int(pred_id_to_int(PredId), !IO),
io.write_string(" ", !IO),
io.write_int(proc_id_to_int(ProcId), !IO),
io.nl(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.format(DebugStream, "not examining proc %d %d\n",
[i(pred_id_to_int(PredId)), i(proc_id_to_int(ProcId))], !IO)
)
).
@@ -658,41 +654,42 @@ need_trace_goal_proc(TraceGoalProc, !Queue, !Needed) :-
%-----------------------------------------------------------------------------%
:- pred dead_proc_examine_goals(list(hlds_goal)::in, pred_proc_id::in,
entity_queue::in, entity_queue::out, needed_map::in, needed_map::out)
is det.
module_info::in, entity_queue::in, entity_queue::out,
needed_map::in, needed_map::out) is det.
dead_proc_examine_goals([], _, !Queue, !Needed).
dead_proc_examine_goals([Goal | Goals], CurrProc, !Queue, !Needed) :-
dead_proc_examine_goal(Goal, CurrProc, !Queue, !Needed),
dead_proc_examine_goals(Goals, CurrProc, !Queue, !Needed).
dead_proc_examine_goals([], _, _, !Queue, !Needed).
dead_proc_examine_goals([Goal | Goals], CurrProc, ModuleInfo,
!Queue, !Needed) :-
dead_proc_examine_goal(Goal, CurrProc, ModuleInfo, !Queue, !Needed),
dead_proc_examine_goals(Goals, CurrProc, ModuleInfo, !Queue, !Needed).
:- pred dead_proc_examine_cases(list(case)::in, pred_proc_id::in,
entity_queue::in, entity_queue::out, needed_map::in, needed_map::out)
is det.
module_info::in, entity_queue::in, entity_queue::out,
needed_map::in, needed_map::out) is det.
dead_proc_examine_cases([], _CurrProc, !Queue, !Needed).
dead_proc_examine_cases([], _, _, !Queue, !Needed).
dead_proc_examine_cases([case(_, _, Goal) | Cases], CurrProc,
!Queue, !Needed) :-
dead_proc_examine_goal(Goal, CurrProc, !Queue, !Needed),
dead_proc_examine_cases(Cases, CurrProc, !Queue, !Needed).
ModuleInfo, !Queue, !Needed) :-
dead_proc_examine_goal(Goal, CurrProc, ModuleInfo, !Queue, !Needed),
dead_proc_examine_cases(Cases, CurrProc, ModuleInfo, !Queue, !Needed).
:- pred dead_proc_examine_goal(hlds_goal::in, pred_proc_id::in,
entity_queue::in, entity_queue::out, needed_map::in, needed_map::out)
is det.
module_info::in, entity_queue::in, entity_queue::out,
needed_map::in, needed_map::out) is det.
dead_proc_examine_goal(Goal, CurrProc, !Queue, !Needed) :-
dead_proc_examine_goal(Goal, CurrProc, ModuleInfo, !Queue, !Needed) :-
Goal = hlds_goal(GoalExpr, _),
(
( GoalExpr = conj(_ConjType, Goals)
; GoalExpr = disj(Goals)
),
dead_proc_examine_goals(Goals, CurrProc, !Queue, !Needed)
dead_proc_examine_goals(Goals, CurrProc, ModuleInfo, !Queue, !Needed)
;
GoalExpr = switch(_Var, _CanFail, Cases),
dead_proc_examine_cases(Cases, CurrProc, !Queue, !Needed)
dead_proc_examine_cases(Cases, CurrProc, ModuleInfo, !Queue, !Needed)
;
GoalExpr = negation(SubGoal),
dead_proc_examine_goal(SubGoal, CurrProc, !Queue, !Needed)
dead_proc_examine_goal(SubGoal, CurrProc, ModuleInfo, !Queue, !Needed)
;
GoalExpr = scope(Reason, SubGoal),
( if
@@ -704,13 +701,14 @@ dead_proc_examine_goal(Goal, CurrProc, !Queue, !Needed) :-
% The scope has no references to procedures at all.
true
else
dead_proc_examine_goal(SubGoal, CurrProc, !Queue, !Needed)
dead_proc_examine_goal(SubGoal, CurrProc, ModuleInfo,
!Queue, !Needed)
)
;
GoalExpr = if_then_else(_, Cond, Then, Else),
dead_proc_examine_goal(Cond, CurrProc, !Queue, !Needed),
dead_proc_examine_goal(Then, CurrProc, !Queue, !Needed),
dead_proc_examine_goal(Else, CurrProc, !Queue, !Needed)
dead_proc_examine_goal(Cond, CurrProc, ModuleInfo, !Queue, !Needed),
dead_proc_examine_goal(Then, CurrProc, ModuleInfo, !Queue, !Needed),
dead_proc_examine_goal(Else, CurrProc, ModuleInfo, !Queue, !Needed)
;
GoalExpr = generic_call(_, _, _, _, _)
;
@@ -719,11 +717,10 @@ dead_proc_examine_goal(Goal, CurrProc, !Queue, !Needed) :-
queue.put(Entity, !Queue),
( if proc(PredId, ProcId) = CurrProc then
trace [io(!IO), compile_time(flag("dead_proc_elim"))] (
io.write_string("plain_call recursive ", !IO),
io.write_int(pred_id_to_int(PredId), !IO),
io.write_string(" ", !IO),
io.write_int(proc_id_to_int(ProcId), !IO),
io.nl(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.format(DebugStream, "plain_call recursive %d %d\n",
[i(pred_id_to_int(PredId)), i(proc_id_to_int(ProcId))],
!IO)
),
% If it is reachable and recursive, then we cannot eliminate it
% or inline it.
@@ -734,31 +731,31 @@ dead_proc_examine_goal(Goal, CurrProc, !Queue, !Needed) :-
OldNotation = not_eliminable,
NewNotation = not_eliminable,
trace [io(!IO), compile_time(flag("dead_proc_elim"))] (
io.write_string("plain_call old not_eliminable ", !IO),
io.write_int(pred_id_to_int(PredId), !IO),
io.write_string(" ", !IO),
io.write_int(proc_id_to_int(ProcId), !IO),
io.nl(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.format(DebugStream,
"plain_call old not_eliminable %d %d\n",
[i(pred_id_to_int(PredId)), i(proc_id_to_int(ProcId))],
!IO)
)
;
OldNotation = maybe_eliminable(Count),
NewNotation = maybe_eliminable(Count + 1),
trace [io(!IO), compile_time(flag("dead_proc_elim"))] (
io.write_string("plain_call incr maybe_eliminable ", !IO),
io.write_int(pred_id_to_int(PredId), !IO),
io.write_string(" ", !IO),
io.write_int(proc_id_to_int(ProcId), !IO),
io.nl(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.format(DebugStream,
"plain_call incr maybe_eliminable %d %d\n",
[i(pred_id_to_int(PredId)), i(proc_id_to_int(ProcId))],
!IO)
)
),
map.det_update(Entity, NewNotation, !Needed)
else
trace [io(!IO), compile_time(flag("dead_proc_elim"))] (
io.write_string("plain_call init maybe_eliminable ", !IO),
io.write_int(pred_id_to_int(PredId), !IO),
io.write_string(" ", !IO),
io.write_int(proc_id_to_int(ProcId), !IO),
io.nl(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.format(DebugStream,
"plain_call init maybe_eliminable %d %d\n",
[i(pred_id_to_int(PredId)), i(proc_id_to_int(ProcId))],
!IO)
),
NewNotation = maybe_eliminable(1),
map.det_insert(Entity, NewNotation, !Needed)
@@ -767,11 +764,9 @@ dead_proc_examine_goal(Goal, CurrProc, !Queue, !Needed) :-
GoalExpr = call_foreign_proc(_, PredId, ProcId, _, _, _, _),
Entity = entity_proc(PredId, ProcId),
trace [io(!IO), compile_time(flag("dead_proc_elim"))] (
io.write_string("foreign_proc ", !IO),
io.write_int(pred_id_to_int(PredId), !IO),
io.write_string(" ", !IO),
io.write_int(proc_id_to_int(ProcId), !IO),
io.nl(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.format(DebugStream, "foreign_proc %d %d\n",
[i(pred_id_to_int(PredId)), i(proc_id_to_int(ProcId))], !IO)
),
queue.put(Entity, !Queue),
map.set(Entity, not_eliminable, !Needed)
@@ -786,11 +781,10 @@ dead_proc_examine_goal(Goal, CurrProc, !Queue, !Needed) :-
unshroud_pred_proc_id(ShroudedPredProcId),
Entity = entity_proc(PredId, ProcId),
trace [io(!IO), compile_time(flag("dead_proc_elim"))] (
io.write_string("pred_const ", !IO),
io.write_int(pred_id_to_int(PredId), !IO),
io.write_string(" ", !IO),
io.write_int(proc_id_to_int(ProcId), !IO),
io.nl(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.format(DebugStream, "pred_const %d %d\n",
[i(pred_id_to_int(PredId)),
i(proc_id_to_int(ProcId))], !IO)
)
;
ConsId = type_ctor_info_const(Module, TypeName, Arity),
@@ -801,11 +795,10 @@ dead_proc_examine_goal(Goal, CurrProc, !Queue, !Needed) :-
unshroud_pred_proc_id(ShroudedPredProcId),
Entity = entity_table_struct(PredId, ProcId),
trace [io(!IO), compile_time(flag("dead_proc_elim"))] (
io.write_string("table struct const ", !IO),
io.write_int(pred_id_to_int(PredId), !IO),
io.write_string(" ", !IO),
io.write_int(proc_id_to_int(ProcId), !IO),
io.nl(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.format(DebugStream, "table struct const %d %d\n",
[i(pred_id_to_int(PredId)),
i(proc_id_to_int(ProcId))], !IO)
)
),
queue.put(Entity, !Queue),

View File

@@ -177,9 +177,10 @@
:- pred apply_headvar_correction(set_of_progvar::in, rename_map::in,
hlds_goal::in, hlds_goal::out) is det.
:- pred dump_interval_info(interval_info::in, io::di, io::uo) is det.
:- pred dump_interval_info(io.text_output_stream::in, interval_info::in,
io::di, io::uo) is det.
:- pred write_int_list(list(int)::in, io::di, io::uo) is det.
:- func int_list_to_string(list(int)) = string.
:- func interval_id_to_int(interval_id) = int.
@@ -202,6 +203,7 @@
:- import_module assoc_list.
:- import_module pair.
:- import_module require.
:- import_module string.
:- import_module term.
:- import_module varset.
@@ -1259,93 +1261,88 @@ construct_anchors(Construct, Goal, StartAnchor, EndAnchor) :-
% For debugging purposes.
dump_interval_info(IntervalInfo, !IO) :-
dump_interval_info(Stream, IntervalInfo, !IO) :-
map.keys(IntervalInfo ^ ii_interval_start, StartIds),
map.keys(IntervalInfo ^ ii_interval_end, EndIds),
map.keys(IntervalInfo ^ ii_interval_vars, VarsIds),
map.keys(IntervalInfo ^ ii_interval_succ, SuccIds),
list.condense([StartIds, EndIds, VarsIds, SuccIds], IntervalIds0),
list.sort_and_remove_dups(IntervalIds0, IntervalIds),
io.write_string("INTERVALS:\n", !IO),
list.foldl(dump_interval_info_id(IntervalInfo), IntervalIds, !IO),
io.write_string(Stream, "INTERVALS:\n", !IO),
list.foldl(dump_interval_info_id(Stream, IntervalInfo), IntervalIds, !IO),
map.to_assoc_list(IntervalInfo ^ ii_anchor_follow_map, AnchorFollows),
io.write_string("\nANCHOR FOLLOW:\n", !IO),
list.foldl(dump_anchor_follow, AnchorFollows, !IO).
io.write_string(Stream, "\nANCHOR FOLLOW:\n", !IO),
list.foldl(dump_anchor_follow(Stream), AnchorFollows, !IO).
:- pred dump_interval_info_id(interval_info::in, interval_id::in,
io::di, io::uo) is det.
:- pred dump_interval_info_id(io.text_output_stream::in, interval_info::in,
interval_id::in, io::di, io::uo) is det.
dump_interval_info_id(IntervalInfo, IntervalId, !IO) :-
io.write_string("\ninterval ", !IO),
io.write_int(interval_id_to_int(IntervalId), !IO),
io.write_string(": ", !IO),
dump_interval_info_id(Stream, IntervalInfo, IntervalId, !IO) :-
io.format(Stream, "\ninterval %d:",
[i(interval_id_to_int(IntervalId))], !IO),
( if map.search(IntervalInfo ^ ii_interval_succ, IntervalId, SuccIds) then
SuccNums = list.map(interval_id_to_int, SuccIds),
io.write_string("succ [", !IO),
write_int_list(SuccNums, !IO),
io.write_string("]\n", !IO)
io.format(Stream, "succ [%s]\n",
[s(int_list_to_string(SuccNums))], !IO)
else
io.write_string("no succ\n", !IO)
io.write_string(Stream, "no succ\n", !IO)
),
( if map.search(IntervalInfo ^ ii_interval_start, IntervalId, Start) then
io.write_string("start ", !IO),
io.write(Start, !IO),
io.write_string("\n", !IO)
io.write_string(Stream, "start ", !IO),
io.write_line(Stream, Start, !IO)
else
io.write_string("no start\n", !IO)
io.write_string(Stream, "no start\n", !IO)
),
( if map.search(IntervalInfo ^ ii_interval_end, IntervalId, End) then
io.write_string("end ", !IO),
io.write(End, !IO),
io.write_string("\n", !IO)
io.write_string(Stream, "end ", !IO),
io.write_line(Stream, End, !IO)
else
io.write_string("no end\n", !IO)
io.write_string(Stream, "no end\n", !IO)
),
( if map.search(IntervalInfo ^ ii_interval_vars, IntervalId, Vars) then
list.map(term.var_to_int, set_of_var.to_sorted_list(Vars), VarNums),
io.write_string("vars [", !IO),
write_int_list(VarNums, !IO),
io.write_string("]\n", !IO)
io.format(Stream, "vars [%s]\n",
[s(int_list_to_string(VarNums))], !IO)
else
io.write_string("no vars\n", !IO)
io.write_string(Stream, "no vars\n", !IO)
),
( if
map.search(IntervalInfo ^ ii_interval_delvars, IntervalId, Deletions)
then
io.write_string("deletions", !IO),
list.foldl(dump_deletion, Deletions, !IO),
io.write_string("\n", !IO)
io.write_string(Stream, "deletions", !IO),
list.foldl(dump_deletion(Stream), Deletions, !IO),
io.write_string(Stream, "\n", !IO)
else
true
).
:- pred dump_deletion(set_of_progvar::in, io::di, io::uo) is det.
dump_deletion(Vars, !IO) :-
list.map(term.var_to_int, set_of_var.to_sorted_list(Vars), VarNums),
io.write_string(" [", !IO),
write_int_list(VarNums, !IO),
io.write_string("]", !IO).
:- pred dump_anchor_follow(pair(anchor, anchor_follow_info)::in,
:- pred dump_deletion(io.text_output_stream::in, set_of_progvar::in,
io::di, io::uo) is det.
dump_anchor_follow(Anchor - AnchorFollowInfo, !IO) :-
AnchorFollowInfo = anchor_follow_info(Vars, Intervals),
io.write_string("\n", !IO),
io.write(Anchor, !IO),
io.write_string(" =>\n", !IO),
dump_deletion(Stream, Vars, !IO) :-
list.map(term.var_to_int, set_of_var.to_sorted_list(Vars), VarNums),
io.write_string("vars [", !IO),
write_int_list(VarNums, !IO),
io.write_string("]\nintervals: ", !IO),
set.to_sorted_list(Intervals, IntervalList),
write_int_list(list.map(interval_id_to_int, IntervalList), !IO),
io.write_string("\n", !IO).
io.format(Stream, " [%s]", [s(int_list_to_string(VarNums))], !IO).
write_int_list(List, !IO) :-
io.write_list(List, ", ", io.write_int, !IO).
:- pred dump_anchor_follow(io.text_output_stream::in,
pair(anchor, anchor_follow_info)::in, io::di, io::uo) is det.
dump_anchor_follow(Stream, Anchor - AnchorFollowInfo, !IO) :-
AnchorFollowInfo = anchor_follow_info(Vars, Intervals),
list.map(term.var_to_int, set_of_var.to_sorted_list(Vars), VarNums),
set.to_sorted_list(Intervals, IntervalList),
IntervalIntList = list.map(interval_id_to_int, IntervalList),
io.write_string(Stream, "\n", !IO),
io.write(Stream, Anchor, !IO),
io.write_string(Stream, " =>\n", !IO),
io.format(Stream, "vars [%s]\n",
[s(int_list_to_string(VarNums))], !IO),
io.format(Stream, "intervals: %s\n",
[s(int_list_to_string(IntervalIntList))], !IO).
int_list_to_string(Ints) = IntsStr :-
IntStrs = list.map(string.int_to_string, Ints),
IntsStr = string.join_list(", ", IntStrs).
interval_id_to_int(interval_id(Num)) = Num.

View File

@@ -48,6 +48,7 @@
:- import_module hlds.hlds_module.
:- import_module hlds.hlds_pred.
:- import_module hlds.instmap.
:- import_module hlds.passes_aux.
:- import_module libs.
:- import_module libs.globals.
:- import_module libs.optimization_options.
@@ -152,11 +153,14 @@ generate_ite(CodeModel, CondGoal0, ThenGoal, ElseGoal, IteGoalInfo, Code,
trace [compiletime(flag("codegen_goal")), io(!IO)] (
( if should_trace_code_gen(!.CI) then
get_module_info(!.CI, ModuleInfo),
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
EffectResumeInstrs = cord.list(EffectResumeCode),
io.output_stream(Stream, !IO),
io.write_string(Stream, "\nEFFECT RESUME INSTRS:\n", !IO),
write_instrs(Stream, EffectResumeInstrs, no, auto_comments, !IO),
io.flush_output(!IO)
io.write_string(DebugStream, "\nEFFECT RESUME INSTRS:\n", !IO),
MaybeProcLabel = no,
write_instrs(DebugStream, EffectResumeInstrs, MaybeProcLabel,
auto_comments, !IO),
io.flush_output(DebugStream, !IO)
else
true
)
@@ -221,11 +225,12 @@ generate_ite(CodeModel, CondGoal0, ThenGoal, ElseGoal, IteGoalInfo, Code,
trace [compiletime(flag("codegen_goal")), io(!IO)] (
( if should_trace_code_gen(!.CI) then
get_module_info(!.CI, ModuleInfo),
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
ResumeInstrs = cord.list(ResumeCode),
io.output_stream(Stream, !IO),
io.write_string(Stream, "\nRESUME INSTRS:\n", !IO),
write_instrs(Stream, ResumeInstrs, no, auto_comments, !IO),
io.flush_output(!IO)
io.write_string(DebugStream, "\nRESUME INSTRS:\n", !IO),
write_instrs(DebugStream, ResumeInstrs, no, auto_comments, !IO),
io.flush_output(DebugStream, !IO)
else
true
)
@@ -244,11 +249,12 @@ generate_ite(CodeModel, CondGoal0, ThenGoal, ElseGoal, IteGoalInfo, Code,
trace [compiletime(flag("codegen_goal")), io(!IO)] (
( if should_trace_code_gen(!.CI) then
get_module_info(!.CI, ModuleInfo),
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
ElseSaveInstrs = cord.list(ElseSaveCode),
io.output_stream(Stream, !IO),
io.write_string(Stream, "\nBRANCH END INSTRS:\n", !IO),
write_instrs(Stream, ElseSaveInstrs, no, auto_comments, !IO),
io.flush_output(!IO)
io.write_string(DebugStream, "\nBRANCH END INSTRS:\n", !IO),
write_instrs(DebugStream, ElseSaveInstrs, no, auto_comments, !IO),
io.flush_output(DebugStream, !IO)
else
true
)

View File

@@ -182,6 +182,7 @@
:- import_module hlds.hlds_out.hlds_out_goal.
:- import_module hlds.hlds_pred.
:- import_module hlds.instmap.
:- import_module hlds.passes_aux.
:- import_module hlds.pred_table.
:- import_module hlds.quantification.
:- import_module hlds.status.
@@ -490,13 +491,11 @@ lco_proc(LowerSCCVariants, SCC, CurProc, PredInfo, ProcInfo0,
Changed = proc_changed
then
trace [compiletime(flag("lco")), io(!IO)] (
io.output_stream(Stream, !IO),
io.write_string(Stream, "\ngoal before lco:\n", !IO),
dump_goal(Stream, !.ModuleInfo, VarSet, Goal0, !IO),
io.nl(Stream, !IO),
io.write_string(Stream, "\ngoal after lco:\n", !IO),
dump_goal(Stream, !.ModuleInfo, VarSet, Goal, !IO),
io.nl(Stream, !IO)
get_lco_debug_output_stream(Info, DebugStream, !IO),
io.write_string(DebugStream, "\ngoal before lco:\n", !IO),
dump_goal_nl(DebugStream, !.ModuleInfo, VarSet, Goal0, !IO),
io.write_string(DebugStream, "\ngoal after lco:\n", !IO),
dump_goal_nl(DebugStream, !.ModuleInfo, VarSet, Goal, !IO)
),
some [!ProcInfo] (
!:ProcInfo = ProcInfo0,
@@ -732,9 +731,9 @@ potentially_transformable_recursive_call(Info, ConstInfo, Goal, OutArgs) :-
UnusedArgs = [],
trace [compiletime(flag("lco")), io(!IO)] (
io.write_string("call output args: ", !IO),
io.write(OutArgs, !IO),
io.nl(!IO)
get_lco_debug_output_stream(Info, DebugStream, !IO),
io.write_string(DebugStream, "call output args: ", !IO),
io.write_line(DebugStream, OutArgs, !IO)
),
list.length(OutArgs, NumOutArgs),
CurrProcOutArgs = ConstInfo ^ lci_cur_proc_outputs,
@@ -843,26 +842,23 @@ acceptable_construct_unification(DelayForVars, Goal, !UnifyInputVars, !Info) :-
all_delayed_arg_vars_are_full_words(ConstructArgVars, CtorRepn ^ cr_args,
DelayForVars),
require_det (
trace [compiletime(flag("lco")), io(!IO)] (
io.write_string("processing unification ", !IO),
io.write(ConstructedVar, !IO),
io.write_string(" <= ", !IO),
io.write(ConsId, !IO),
io.write_string("(", !IO),
io.write(ConstructArgVars, !IO),
io.write_string(")\n", !IO)
),
trace [compiletime(flag("lco")), io(!IO)] (
io.write_string("initial UnifyInputVars: ", !IO),
io.write(!.UnifyInputVars, !IO),
io.nl(!IO)
),
bag.delete(ConstructedVar, !UnifyInputVars),
bag.insert_list(ConstructArgVars, !UnifyInputVars),
trace [compiletime(flag("lco")), io(!IO)] (
io.write_string("updated UnifyInputVars: ", !IO),
io.write(!.UnifyInputVars, !IO),
io.nl(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.write_string(DebugStream, "processing unification ", !IO),
io.write(DebugStream, ConstructedVar, !IO),
io.write_string(DebugStream, " <= ", !IO),
io.write(DebugStream, ConsId, !IO),
io.write_string(DebugStream, "(", !IO),
io.write(DebugStream, ConstructArgVars, !IO),
io.write_string(DebugStream, ")\n", !IO),
io.write_string(DebugStream, "initial UnifyInputVars: ", !IO),
io.write_line(DebugStream, !.UnifyInputVars, !IO),
io.write_string(DebugStream, "updated UnifyInputVars: ", !IO),
io.write_line(DebugStream, !.UnifyInputVars, !IO)
)
).
@@ -922,20 +918,17 @@ transform_call_and_unifies(CallGoal, CallOutArgVars, UnifyGoals,
find_args_to_pass_by_addr(ConstInfo, UnifyInputVars, CallHeadPairs,
1, Mismatches, UpdatedCallOutArgs, map.init, Subst, !Info),
trace [compiletime(flag("lco")), io(!IO)] (
io.write_string("find_args_to_pass_by_addr:\n", !IO),
io.write_string("call head pairs: ", !IO),
io.write(CallHeadPairs, !IO),
io.nl(!IO),
io.write_string("mismatches: ", !IO),
io.write(Mismatches, !IO),
io.nl(!IO),
io.write_string("updated call out args: ", !IO),
io.write(UpdatedCallOutArgs, !IO),
io.nl(!IO),
io.write_string("substitution: ", !IO),
io.write(Subst, !IO),
io.nl(!IO),
io.nl(!IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
io.write_string(DebugStream, "find_args_to_pass_by_addr:\n", !IO),
io.write_string(DebugStream, "call head pairs: ", !IO),
io.write_line(DebugStream, CallHeadPairs, !IO),
io.write_string(DebugStream, "mismatches: ", !IO),
io.write_line(DebugStream, Mismatches, !IO),
io.write_string(DebugStream, "updated call out args: ", !IO),
io.write_line(DebugStream, UpdatedCallOutArgs, !IO),
io.write_string(DebugStream, "substitution: ", !IO),
io.write_line(DebugStream, Subst, !IO),
io.nl(DebugStream, !IO)
),
% If there are no mismatches, we would create an identical "variant".
% Such cases should be optimized using other means.
@@ -948,17 +941,16 @@ transform_call_and_unifies(CallGoal, CallOutArgVars, UnifyGoals,
list.map_foldl2(update_construct(ConstInfo, Subst),
UnifyGoals, UpdatedUnifyGoals, map.init, AddrFieldIds, !Info),
trace [compiletime(flag("lco")), io(!IO)] (
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
VarSet = !.Info ^ lco_var_set,
io.output_stream(Stream, !IO),
io.write_string(Stream, "original unifies:\n", !IO),
list.foldl(dump_goal_nl(Stream, ModuleInfo, VarSet),
io.write_string(DebugStream, "original unifies:\n", !IO),
list.foldl(dump_goal_nl(DebugStream, ModuleInfo, VarSet),
UnifyGoals, !IO),
io.write_string("updated unifies:\n", !IO),
list.foldl(dump_goal_nl(Stream, ModuleInfo, VarSet),
io.write_string(DebugStream, "updated unifies:\n", !IO),
list.foldl(dump_goal_nl(DebugStream, ModuleInfo, VarSet),
UpdatedUnifyGoals, !IO),
io.write_string(Stream, "addr field ids:\n", !IO),
io.write(Stream, AddrFieldIds, !IO),
io.nl(Stream, !IO)
io.write_string(DebugStream, "addr field ids:\n", !IO),
io.write_line(DebugStream, AddrFieldIds, !IO)
),
HighLevelData = ConstInfo ^ lci_highlevel_data,
make_variant_args(HighLevelData, AddrFieldIds, Mismatches,
@@ -1875,6 +1867,15 @@ make_unification_arg(GroundVar, TargetArgNum, CurArgNum, ArgType,
free_inst, ground_inst)
).
%-----------------------------------------------------------------------------%
:- pred get_lco_debug_output_stream(lco_info::in, io.text_output_stream::out,
io::di, io::uo) is det.
get_lco_debug_output_stream(Info, DebugStream, !IO) :-
ModuleInfo = Info ^ lco_module_info,
get_debug_output_stream(ModuleInfo, DebugStream, !IO).
%-----------------------------------------------------------------------------%
:- end_module transform_hlds.lco.
%-----------------------------------------------------------------------------%

View File

@@ -36,7 +36,9 @@
:- import_module libs.
:- import_module libs.file_util.
:- import_module libs.globals.
:- import_module hlds.
:- import_module hlds.hlds_module.
:- import_module hlds.hlds_out.
:- import_module hlds.hlds_out.hlds_out_mode.
:- import_module hlds.instmap.
@@ -89,44 +91,52 @@ mode_checkpoint(Port, Msg, !ModeInfo) :-
Detail = yes,
mode_info_get_instmap(!.ModeInfo, InstMap),
trace [io(!IO)] (
io.format("%s%s%s:\n",
mode_info_get_module_info(!.ModeInfo, ModuleInfo),
module_info_get_globals(ModuleInfo, Globals),
module_info_get_name(ModuleInfo, ModuleName),
get_debug_output_stream(Globals, ModuleName, DebugStream, !IO),
io.format(DebugStream, "%s%s%s:\n",
[s(PortStr), s(UniquePrefix), s(Msg)], !IO),
maybe_report_stats(Statistics, !IO),
maybe_flush_output(Statistics, !IO),
maybe_report_stats(DebugStream, Statistics, !IO),
maybe_flush_output(DebugStream, Statistics, !IO),
( if instmap_is_reachable(InstMap) then
instmap_to_assoc_list(InstMap, NewInsts),
mode_info_get_last_checkpoint_insts(!.ModeInfo,
OldInstMap),
mode_info_get_varset(!.ModeInfo, VarSet),
mode_info_get_instvarset(!.ModeInfo, InstVarSet),
write_var_insts(NewInsts, OldInstMap, VarSet, InstVarSet,
Verbose, Minimal, !IO)
write_var_insts(DebugStream, NewInsts, OldInstMap,
VarSet, InstVarSet, Verbose, Minimal, !IO)
else
io.write_string("\tUnreachable\n", !IO)
io.write_string(DebugStream, "\tUnreachable\n", !IO)
),
io.write_string("\n", !IO),
io.flush_output(!IO)
io.write_string(DebugStream, "\n", !IO),
io.flush_output(DebugStream, !IO)
),
mode_info_set_last_checkpoint_insts(InstMap, !ModeInfo)
;
Detail = no,
trace [io(!IO)] (
io.format("%s%s%s:\n",
mode_info_get_module_info(!.ModeInfo, ModuleInfo),
module_info_get_globals(ModuleInfo, Globals),
module_info_get_name(ModuleInfo, ModuleName),
get_debug_output_stream(Globals, ModuleName, DebugStream, !IO),
io.format(DebugStream, "%s%s%s:\n",
[s(PortStr), s(UniquePrefix), s(Msg)], !IO),
io.flush_output(!IO)
io.flush_output(DebugStream, !IO)
)
)
).
:- pred write_var_insts(assoc_list(prog_var, mer_inst)::in, instmap::in,
:- pred write_var_insts(io.text_output_stream::in,
assoc_list(prog_var, mer_inst)::in, instmap::in,
prog_varset::in, inst_varset::in, bool::in, bool::in,
io::di, io::uo) is det.
write_var_insts([], _, _, _, _, _, !IO).
write_var_insts([Var - Inst | VarInsts], OldInstMap, VarSet, InstVarSet,
Verbose, Minimal, !IO) :-
write_var_insts(_, [], _, _, _, _, _, !IO).
write_var_insts(Stream, [Var - Inst | VarInsts], OldInstMap,
VarSet, InstVarSet, Verbose, Minimal, !IO) :-
instmap_lookup_var(OldInstMap, Var, OldInst),
io.output_stream(Stream, !IO),
( if
(
identical_insts(Inst, OldInst)
@@ -138,26 +148,24 @@ write_var_insts([Var - Inst | VarInsts], OldInstMap, VarSet, InstVarSet,
Verbose = yes,
io.write_string(Stream, "\t", !IO),
mercury_output_var(VarSet, print_name_only, Var, Stream, !IO),
io.write_string(Stream, " ::", !IO),
io.write_string(Stream, " unchanged\n", !IO)
io.write_string(Stream, " :: unchanged", !IO)
;
Verbose = no
)
else
io.write_string(Stream, "\t", !IO),
mercury_output_var(VarSet, print_name_only, Var, Stream, !IO),
io.write_string(Stream, " ::", !IO),
(
Minimal = yes,
io.write_string(Stream, " changed\n", !IO)
io.write_string(Stream, " :: changed\n", !IO)
;
Minimal = no,
io.write_string(Stream, "\n", !IO),
io.write_string(Stream, " ::\n", !IO),
mercury_output_structured_inst(Stream, Inst, 2,
output_debug, do_not_incl_addr, InstVarSet, !IO)
)
),
write_var_insts(VarInsts, OldInstMap, VarSet, InstVarSet,
write_var_insts(Stream, VarInsts, OldInstMap, VarSet, InstVarSet,
Verbose, Minimal, !IO).
% In the usual case of a C backend, this predicate allows us to conclude

View File

@@ -1102,15 +1102,18 @@ mode_info_add_error(ModeErrorInfo, !ModeInfo) :-
;
DebugModes = yes(_DebugFlags),
trace [io(!IO)] (
list.length(Errors, ErrorNum),
io.format("Adding error_spec %d\n", [i(ErrorNum)], !IO),
Spec = mode_error_info_to_spec(!.ModeInfo, ModeErrorInfo),
mode_info_get_module_info(!.ModeInfo, ModuleInfo),
module_info_get_globals(ModuleInfo, Globals0),
module_info_get_name(ModuleInfo, ModuleName),
get_debug_output_stream(Globals0, ModuleName, DebugStream, !IO),
list.length(Errors, ErrorNum),
io.format(DebugStream, "Adding error_spec %d\n",
[i(ErrorNum)], !IO),
Spec = mode_error_info_to_spec(!.ModeInfo, ModeErrorInfo),
globals.set_option(print_error_spec_id, bool(yes),
Globals0, Globals),
write_error_spec(Globals, Spec, 0, _, 0, _, !IO),
io.flush_output(!IO)
write_error_spec(DebugStream, Globals, Spec, 0, _, 0, _, !IO),
io.flush_output(DebugStream, !IO)
)
).

View File

@@ -435,10 +435,15 @@ modecheck_to_fixpoint(PredIds, NumIterationsLeft, WhatToCheck,
do_not_include_detism_on_modes, PredIds,
[], InferenceSpecs),
trace [io(!IO)] (
io.write_string("Inferences by current iteration:\n",
!IO),
write_error_specs_ignore(Globals, InferenceSpecs, !IO),
io.write_string("End of inferences.\n", !IO)
module_info_get_name(!.ModuleInfo, ModuleName),
get_debug_output_stream(Globals, ModuleName,
DebugStream, !IO),
io.write_string(DebugStream,
"Inferences by current iteration:\n", !IO),
write_error_specs_ignore(DebugStream, Globals,
InferenceSpecs, !IO),
io.write_string(DebugStream,
"End of inferences.\n", !IO)
)
;
DebugModes = no
@@ -603,7 +608,10 @@ maybe_modecheck_pred(WhatToCheck, MayChangeCalledProc, PredId,
globals.lookup_bool_option(Globals, detailed_statistics, Statistics),
trace [io(!IO)] (
maybe_report_stats(Statistics, !IO)
module_info_get_name(!.ModuleInfo, ModuleName),
get_progress_output_stream(Globals, ModuleName,
ProgressStream, !IO),
maybe_report_stats(ProgressStream, Statistics, !IO)
)
).
@@ -1191,13 +1199,17 @@ queued_proc_progress_message(ModuleInfo, PredProcId, HowToCheckGoal, !IO) :-
globals.lookup_bool_option(Globals, very_verbose, VeryVerbose),
(
VeryVerbose = yes,
module_info_get_name(ModuleInfo, ModuleName),
get_progress_output_stream(Globals, ModuleName, ProgressStream, !IO),
ProcStr = pred_proc_id_to_string(ModuleInfo, PredProcId),
(
HowToCheckGoal = check_modes,
io.format("%% Mode-analysing %s\n", [s(ProcStr)], !IO)
io.format(ProgressStream, "%% Mode-analysing %s\n",
[s(ProcStr)], !IO)
;
HowToCheckGoal = check_unique_modes,
io.format("%% Analysing unique modes for\n%% %s", [s(ProcStr)], !IO)
io.format(ProgressStream, "%% Analysing unique modes for\n%% %s",
[s(ProcStr)], !IO)
)
;
VeryVerbose = no

View File

@@ -102,6 +102,7 @@
:- import_module hlds.hlds_out.
:- import_module hlds.hlds_out.hlds_out_goal.
:- import_module hlds.hlds_out.hlds_out_util.
:- import_module hlds.passes_aux.
:- import_module hlds.quantification.
:- import_module hlds.vartypes.
:- import_module libs.
@@ -131,6 +132,7 @@
:- import_module pair.
:- import_module require.
:- import_module set.
:- import_module string.
:- import_module term.
%-----------------------------------------------------------------------------%
@@ -304,8 +306,9 @@ optimize_live_sets(ModuleInfo, OptAlloc, !ProcInfo, Changed, DebugStackOpt,
StackOptInfo0, StackOptInfo),
( if DebugStackOpt = PredIdInt then
trace [io(!IO)] (
dump_interval_info(IntervalInfo, !IO),
dump_stack_opt_info(StackOptInfo, !IO)
get_debug_output_stream(ModuleInfo, DebugStream, !IO),
dump_interval_info(DebugStream, IntervalInfo, !IO),
dump_stack_opt_info(DebugStream, StackOptInfo, !IO)
)
else
true
@@ -1058,89 +1061,84 @@ maybe_write_progress_message(Message, DebugStackOpt, PredIdInt, ProcInfo,
% This predicate (along with dump_interval_info) can help debug the
% performance of the transformation.
%
:- pred dump_stack_opt_info(stack_opt_info::in, io::di, io::uo) is det.
dump_stack_opt_info(StackOptInfo, !IO) :-
map.to_assoc_list(StackOptInfo ^ soi_left_anchor_inserts, Inserts),
io.write_string("\nANCHOR INSERT:\n", !IO),
list.foldl(dump_anchor_inserts, Inserts, !IO),
io.write_string("\nMATCHING RESULTS:\n", !IO),
list.foldl(dump_matching_result, StackOptInfo ^ soi_matching_results, !IO),
io.write_string("\n", !IO).
:- pred dump_anchor_inserts(pair(anchor, list(insert_spec))::in,
:- pred dump_stack_opt_info(io.text_output_stream::in, stack_opt_info::in,
io::di, io::uo) is det.
dump_anchor_inserts(Anchor - InsertSpecs, !IO) :-
io.write_string("\ninsertions after ", !IO),
io.write(Anchor, !IO),
io.write_string(":\n", !IO),
list.foldl(dump_insert, InsertSpecs, !IO).
dump_stack_opt_info(Stream, StackOptInfo, !IO) :-
map.to_assoc_list(StackOptInfo ^ soi_left_anchor_inserts, Inserts),
io.write_string(Stream, "\nANCHOR INSERT:\n", !IO),
list.foldl(dump_anchor_inserts(Stream), Inserts, !IO),
:- pred dump_insert(insert_spec::in, io::di, io::uo) is det.
io.write_string(Stream, "\nMATCHING RESULTS:\n", !IO),
list.foldl(dump_matching_result(Stream),
StackOptInfo ^ soi_matching_results, !IO),
io.write_string(Stream, "\n", !IO).
dump_insert(insert_spec(Goal, Vars), !IO) :-
:- pred dump_anchor_inserts(io.text_output_stream::in,
pair(anchor, list(insert_spec))::in, io::di, io::uo) is det.
dump_anchor_inserts(Stream, Anchor - InsertSpecs, !IO) :-
io.write_string(Stream, "\ninsertions after ", !IO),
io.write(Stream, Anchor, !IO),
io.write_string(Stream, ":\n", !IO),
list.foldl(dump_insert(Stream), InsertSpecs, !IO).
:- pred dump_insert(io.text_output_stream::in, insert_spec::in,
io::di, io::uo) is det.
dump_insert(Stream, insert_spec(Goal, Vars), !IO) :-
list.map(term.var_to_int, set_of_var.to_sorted_list(Vars), VarNums),
io.write_string("vars [", !IO),
write_int_list(VarNums, !IO),
io.write_string("]: ", !IO),
io.format(Stream, "vars [%s]:", [s(int_list_to_string(VarNums))], !IO),
( if
Goal = hlds_goal(unify(_, _, _, Unification, _), _),
Unification = deconstruct(CellVar, ConsId, ArgVars, _,_,_)
then
term.var_to_int(CellVar, CellVarNum),
io.write_int(CellVarNum, !IO),
io.write_string(" => ", !IO),
io.write_string(cons_id_and_arity_to_string(ConsId), !IO),
io.write_string("(", !IO),
list.map(term.var_to_int, ArgVars, ArgVarNums),
write_int_list(ArgVarNums, !IO),
io.write_string(")\n", !IO)
io.format(Stream, "%d => %s(%s)\n",
[i(CellVarNum), s(cons_id_and_arity_to_string(ConsId)),
s(int_list_to_string(ArgVarNums))], !IO)
else
io.write_string("BAD INSERT GOAL\n", !IO)
io.write_string(Stream, "BAD INSERT GOAL\n", !IO)
).
:- pred dump_matching_result(matching_result::in,
:- pred dump_matching_result(io.text_output_stream::in, matching_result::in,
io::di, io::uo) is det.
dump_matching_result(MatchingResult, !IO) :-
dump_matching_result(Stream, MatchingResult, !IO) :-
MatchingResult = matching_result(CellVar, ConsId, ArgVars, ViaCellVars,
GoalId, PotentialIntervals, InsertIntervals,
PotentialAnchors, InsertAnchors),
io.write_string("\nmatching result at ", !IO),
io.write(GoalId, !IO),
io.write_string("\n", !IO),
io.write_string(Stream, "\nmatching result at ", !IO),
io.write_line(Stream, GoalId, !IO),
term.var_to_int(CellVar, CellVarNum),
list.map(term.var_to_int, ArgVars, ArgVarNums),
list.map(term.var_to_int, set_of_var.to_sorted_list(ViaCellVars),
ViaCellVarNums),
io.write_int(CellVarNum, !IO),
io.write_string(" => ", !IO),
io.write_string(cons_id_and_arity_to_string(ConsId), !IO),
io.write_string("(", !IO),
write_int_list(ArgVarNums, !IO),
io.write_string("): via cell ", !IO),
write_int_list(ViaCellVarNums, !IO),
io.write_string("\n", !IO),
io.format(Stream, "%d => %s(%s): via cell %s\n",
[i(CellVarNum), s(cons_id_and_arity_to_string(ConsId)),
s(int_list_to_string(ArgVarNums)),
s(int_list_to_string(ViaCellVarNums))], !IO),
io.write_string("potential intervals: ", !IO),
PotentialIntervalNums = list.map(interval_id_to_int,
set.to_sorted_list(PotentialIntervals)),
write_int_list(PotentialIntervalNums, !IO),
io.write_string("\n", !IO),
io.write_string("insert intervals: ", !IO),
InsertIntervalNums = list.map(interval_id_to_int,
set.to_sorted_list(InsertIntervals)),
write_int_list(InsertIntervalNums, !IO),
io.write_string("\n", !IO),
io.format(Stream, "potential intervals: %s\n",
[s(int_list_to_string(PotentialIntervalNums))], !IO),
io.format(Stream, "insert intervals: %s\n",
[s(int_list_to_string(InsertIntervalNums))], !IO),
io.write_string("potential anchors: ", !IO),
io.write_list(set.to_sorted_list(PotentialAnchors), " ", io.write, !IO),
io.write_string("\n", !IO),
io.write_string("insert anchors: ", !IO),
io.write_list(set.to_sorted_list(InsertAnchors), " ", io.write, !IO),
io.write_string("\n", !IO).
PotentialAnchorStrs = list.map(string.string,
set.to_sorted_list(PotentialAnchors)),
InsertAnchorStrs = list.map(string.string,
set.to_sorted_list(InsertAnchors)),
PotentialAnchorsStr = string.join_list(" ", PotentialAnchorStrs),
InsertAnchorsStr = string.join_list(" ", InsertAnchorStrs),
io.format(Stream, "potential anchors: %s\n",
[s(PotentialAnchorsStr)], !IO),
io.format(Stream, "insert anchors: %s\n",
[s(InsertAnchorsStr)], !IO).
%-----------------------------------------------------------------------------%
:- end_module ll_backend.stack_opt.