mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-19 15:54:18 +00:00
Estimated hours taken: 10 This change fixes two bugs, in quantification and liveness. I made the changes to the other files while trying to find them; they ought to be useful in trying to find similar bugs in the future. The compiler now bootstraps with agressive inlining enabled. quantification: Fix a bug that switched two different accumulators of the same type when processing pragma_c_codes. liveness: Fix a bug that could cause a variable to end up in both the post-death and post-birth set of the same goal. options: Reenable inlining. hlds_out, mercury_to_mercury: If -D v is given, include the number of each variable at the end of its name (e.g. Varname_20). The predicates involved (a few from mercury_to_mercury and many from hlds_out) now have an extra argument that says whether this should be done or not. (It is not done when printing clauses e.g. for .opt files.) The bug in quantification was causing the improper substitution of one variable for another, but both had the same name; such bugs would be very difficult to find without this change. constraint, det_report, intermod, make_hlds, mercury_to_c, mode_debug, mode_errors, module_qual, typecheck: Call predicates in hlds_out or mercury_to_mercury with the extra argument. saved_vars: Thread the io__state through this module to allow debugging. mercury_compile: Call saved_vars via its new interface. Fix an inadvertent use of an out-of-date ModuleInfo. goal_util, hlds_goal: Minor formatting cleanup. code_gen: Clean up the import sequence.
111 lines
4.1 KiB
Mathematica
111 lines
4.1 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 1995 University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% File: mode_debug.m.
|
|
% Main author: fjh.
|
|
%
|
|
% This module contains code for tracing the actions of the mode checker.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module mode_debug.
|
|
|
|
:- interface.
|
|
|
|
:- import_module hlds_module, hlds_pred, mode_info.
|
|
|
|
% Print a debugging message which includes the port, message string,
|
|
% and the current instmap (but only if `--debug-modes' was enabled).
|
|
%
|
|
:- pred mode_checkpoint(port, string, mode_info, mode_info).
|
|
:- mode mode_checkpoint(in, in, mode_info_di, mode_info_uo) is det.
|
|
|
|
:- type port
|
|
---> enter
|
|
; exit
|
|
; wakeup.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
:- import_module globals, std_util, assoc_list, io, bool, map.
|
|
:- import_module modes, options, mercury_to_mercury, passes_aux.
|
|
:- import_module hlds_goal, instmap.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% This code is used to trace the actions of the mode checker.
|
|
|
|
mode_checkpoint(Port, Msg, ModeInfo0, ModeInfo) :-
|
|
mode_info_get_io_state(ModeInfo0, IOState0),
|
|
globals__io_lookup_bool_option(debug_modes, DoCheckPoint,
|
|
IOState0, IOState1),
|
|
( DoCheckPoint = yes ->
|
|
mode_checkpoint_2(Port, Msg, ModeInfo0, IOState1, IOState)
|
|
;
|
|
IOState = IOState1
|
|
),
|
|
mode_info_set_io_state(ModeInfo0, IOState, ModeInfo).
|
|
|
|
:- pred mode_checkpoint_2(port, string, mode_info, io__state, io__state).
|
|
:- mode mode_checkpoint_2(in, in, mode_info_ui, di, uo) is det.
|
|
|
|
mode_checkpoint_2(Port, Msg, ModeInfo) -->
|
|
{ mode_info_get_errors(ModeInfo, Errors) },
|
|
( { Port = enter } ->
|
|
io__write_string("Enter "),
|
|
{ Detail = yes }
|
|
; { Port = wakeup } ->
|
|
io__write_string("Wake "),
|
|
{ Detail = no }
|
|
; { Errors = [] } ->
|
|
io__write_string("Exit "),
|
|
{ Detail = yes }
|
|
;
|
|
io__write_string("Delay "),
|
|
{ Detail = no }
|
|
),
|
|
io__write_string(Msg),
|
|
( { Detail = yes } ->
|
|
io__write_string(":\n"),
|
|
globals__io_lookup_bool_option(statistics, Statistics),
|
|
maybe_report_stats(Statistics),
|
|
{ mode_info_get_instmap(ModeInfo, InstMap) },
|
|
( { instmap__is_reachable(InstMap) } ->
|
|
{ instmap__to_assoc_list(InstMap, AssocList) },
|
|
{ mode_info_get_varset(ModeInfo, VarSet) },
|
|
{ mode_info_get_instvarset(ModeInfo, InstVarSet) },
|
|
write_var_insts(AssocList, VarSet, InstVarSet)
|
|
;
|
|
io__write_string("\tUnreachable\n")
|
|
)
|
|
;
|
|
[]
|
|
),
|
|
io__write_string("\n").
|
|
|
|
:- pred write_var_insts(assoc_list(var, inst), varset, varset,
|
|
io__state, io__state).
|
|
:- mode write_var_insts(in, in, in, di, uo) is det.
|
|
|
|
write_var_insts([], _, _) --> [].
|
|
write_var_insts([Var - Inst | VarInsts], VarSet, InstVarSet) -->
|
|
io__write_string("\t"),
|
|
mercury_output_var(Var, VarSet, no),
|
|
io__write_string(" :: "),
|
|
mercury_output_inst(Inst, InstVarSet),
|
|
( { VarInsts = [] } ->
|
|
[]
|
|
;
|
|
io__write_string("\n"),
|
|
write_var_insts(VarInsts, VarSet, InstVarSet)
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|