mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-20 08:19:28 +00:00
Estimated hours taken: 14 Implemented a :- use_module directive. This is the same as :- import_module, except all uses of the imported items must be explicitly module qualified. :- use_module is implemented by ensuring that unqualified versions of items only get added to the HLDS symbol tables if they were imported using import_module. Indirectly imported items (from `.int2' files) and items declared in `.opt' files are treated as if they were imported with use_module, since all uses of them should be module qualified. compiler/module_qual.m Keep two sets of type, mode and inst ids, those which can be used without qualifiers and those which can't. Renamed some predicates which no longer have unique names since '__' became a synonym for ':'. Made mq_info_set_module_used check whether the current item is in the interface, rather than relying on its caller to do the check. Removed init_mq_info_module, since make_hlds.m now uses the mq_info built during the module qualification pass. compiler/prog_data.m Added a pseudo-declaration `used', same as `imported' except uses of the following items must be module qualified. Added a type need_qualifier to describe whether uses of an item need to be module qualified. compiler/make_hlds.m Keep with the import_status whether current item was imported using a :- use_module directive. Use the mq_info structure passed in instead of building a new one. Ensure unqualified versions of constructors only get added to the cons_table if they can be used without qualification. compiler/hlds_module.m Added an extra argument to predicate_table_insert of type need_qualifier. Only add predicates to the name and name-arity indices if they can be used without qualifiers. Changed the structure of the module-name-arity index, so that lookups can be made without an arity, such as when type-checking module qualified higher-order predicate constants. This does not change the interface to the module_name_arity index. Factored out some common code in predicate_table_insert which applies to both predicates and functions. compiler/hlds_pred.m Removed the opt_decl import_status. It isn't needed any more since all uses of items declared in .opt files must now be module qualified. Added some documentation about when the clauses_info is valid. compiler/intermod.m Ensure that predicate and function calls in the `.opt' file are module qualified. Use use_module instead of import_module in `.opt' files. compiler/modules.m Handle use_module directives. Report a warning if both use_module and import_module declarations exist for the same module. compiler/mercury_compile.m Collect inter-module optimization information before module qualification, since it can't cause conflicts any more. This means that the mq_info structure built in module_qual.m can be reused in make_hlds.m, instead of building a new one. compiler/prog_out.m Add a predicate prog_out__write_module_list, which was moved here from module_qual.m. compiler/typecheck.m Removed code to check that predicates declared in `.opt' files were being used appropriately, since this is now handled by use_module. compiler/*.m Added missing imports, mostly for prog_data and term. NEWS compiler/notes/todo.html doc/reference_manual.texi Document `:- use_module'. tests/valid/intermod_lambda_test.m tests/valid/intermod_lambda_test2.m tests/invalid/errors.m tests/invalid/errors2.m Test cases.
125 lines
4.0 KiB
Mathematica
125 lines
4.0 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 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, list, assoc_list, io, bool, map.
|
|
:- import_module term, varset.
|
|
:- import_module modes, options, mercury_to_mercury, passes_aux.
|
|
:- import_module hlds_goal, instmap, prog_data.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% 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_info_get_last_checkpoint_insts(ModeInfo0, OldInsts),
|
|
mode_checkpoint_2(Port, Msg, OldInsts, NewInsts, ModeInfo0,
|
|
IOState1, IOState),
|
|
mode_info_set_last_checkpoint_insts(NewInsts, ModeInfo0,
|
|
ModeInfo1)
|
|
;
|
|
ModeInfo1 = ModeInfo0,
|
|
IOState = IOState1
|
|
),
|
|
mode_info_set_io_state(ModeInfo1, IOState, ModeInfo).
|
|
|
|
:- pred mode_checkpoint_2(port, string, assoc_list(var, inst),
|
|
assoc_list(var, inst), mode_info, io__state, io__state).
|
|
:- mode mode_checkpoint_2(in, in, in, out, mode_info_ui, di, uo) is det.
|
|
|
|
mode_checkpoint_2(Port, Msg, OldInstList, NewInstList, 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),
|
|
maybe_flush_output(Statistics),
|
|
{ mode_info_get_instmap(ModeInfo, InstMap) },
|
|
( { instmap__is_reachable(InstMap) } ->
|
|
{ instmap__to_assoc_list(InstMap, NewInstList) },
|
|
{ mode_info_get_varset(ModeInfo, VarSet) },
|
|
{ mode_info_get_instvarset(ModeInfo, InstVarSet) },
|
|
write_var_insts(NewInstList, OldInstList,
|
|
VarSet, InstVarSet)
|
|
;
|
|
{ NewInstList = [] },
|
|
io__write_string("\tUnreachable\n")
|
|
)
|
|
;
|
|
{ NewInstList = OldInstList }
|
|
),
|
|
io__write_string("\n"),
|
|
io__flush_output.
|
|
|
|
:- pred write_var_insts(assoc_list(var, inst), assoc_list(var, inst),
|
|
varset, varset, io__state, io__state).
|
|
:- mode write_var_insts(in, in, in, in, di, uo) is det.
|
|
|
|
write_var_insts([], _, _, _) --> [].
|
|
write_var_insts([Var - Inst | VarInsts], OldInstList, VarSet, InstVarSet) -->
|
|
io__write_string("\t"),
|
|
mercury_output_var(Var, VarSet, no),
|
|
io__write_string(" ::"),
|
|
(
|
|
{ assoc_list__search(OldInstList, Var, OldInst) },
|
|
{ Inst = OldInst }
|
|
->
|
|
io__write_string(" unchanged\n")
|
|
;
|
|
io__write_string("\n"),
|
|
mercury_output_structured_inst(Inst, 2, InstVarSet)
|
|
),
|
|
write_var_insts(VarInsts, OldInstList, VarSet, InstVarSet).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|