mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-16 01:43:35 +00:00
compiler/module_qual.m:
Delete from this module everything except include_module declarations,
making it a proper package, after moving (most of) the deleted things
to other modules. The rest were already unused.
compiler/module_qual.mq_info.m:
This new submodule of module_qual.m contains the definition of the
mq_info type, its getter/setter predicates, and some utility operations.
This is the bulk of the old module_qual.m.
Delete two fields of the old mq_info/mq_sub_info structure, because
they were never used.
compiler/module_qual.qualify_items.m:
Move the predicates that module qualify entire aug_comp_units,
aug_make_int_units and parse_tree_int3s here from module_qual.m.
Rename some already-here predicates to avoid name clashes with
the newly moved predicates.
Export only the predicates that are used outside the module *now*.
Update some comments.
compiler/module_qual.id_set.m:
Move a type and a predicate here from module_qual.m.
Make a comment more detailed.
Reorder the args of a predicate.
compiler/module_qual.collect_mq_info.m:
Delete some trace goals that lost their usefulness a long time ago.
compiler/notes/compiler_design.html:
Update the documentation of the module_qual package.
Conform to the changes above.
compiler/add_clause.m:
compiler/add_type.m:
compiler/comp_unit_interface.m:
compiler/hlds_module.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile_make_hlds.m:
compiler/module_qual.qual_errors.m:
compiler/pred_table.m:
compiler/qual_info.m:
compiler/superhomogeneous.m:
Conform to the changes above.
compiler/add_class.m:
compiler/add_foreign_proc.m:
compiler/higher_order.make_specialized_preds.m:
compiler/ml_lookup_switch.m:
compiler/mode_errors.m:
compiler/tag_switch_util.m:
Sort import_module declarations.
86 lines
4.3 KiB
Mathematica
86 lines
4.3 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 1996-2012 The University of Melbourne.
|
|
% Copyright (C) 2014-2024 The Mercury team.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% File: module_qual.m.
|
|
% Main authors: stayl, fjh.
|
|
%
|
|
% The code in this package performs two tasks.
|
|
%
|
|
% - It checks for undefined types, typeclasses, insts and modes.
|
|
%
|
|
% - It module qualifies types, typeclasses, insts and modes within declaration
|
|
% items in the source code of the compilation unit. The heads of all
|
|
% declarations should be module qualified as they are read in by the parser;
|
|
% this module qualifies the bodies of those declarations.
|
|
%
|
|
% Note that we don't qualify the parts of the augmented compilation unit
|
|
% that derive from other modules' interface or optimization files, since
|
|
% those parts should be read in fully module qualified already.
|
|
%
|
|
% The algorithm we use does two passes over all the items in the compilation
|
|
% unit. The first pass records the set of modules, types, typeclasses, insts
|
|
% and modes that are visible in the compilation unit. The second uses this
|
|
% information to actually do this package's job.
|
|
%
|
|
% If any type, typeclass, inst or mode used in the module is not uniquely
|
|
% module qualifiable, i.e. if we either find zero matches for it, or we find
|
|
% two or more matches for it, we can generate an error message for it.
|
|
% We do so when we are module qualifying a compilation unit; we don't when
|
|
% we are qualifying the contents of an interface file.
|
|
%
|
|
% Note that this package is NOT the only place in the compiler that does module
|
|
% qualification. The modes of lambda expressions are qualified in modes.m,
|
|
% and predicate and function names are qualified during typecheck, with
|
|
% the results recorded during the post_typecheck phase of the purity pass.
|
|
% This is because figuring out whether e.g. a call to predicate `p' calls
|
|
% module m1's predicate p or module m2's predicate p may require knowing
|
|
% the types of the arguments in the call.
|
|
%
|
|
% Since this package does not and cannot know about the module qualification
|
|
% of predicate names, function names and function symbols, it cannot figure out
|
|
% which modules are referred to in goals. The only goals that may appear
|
|
% in the interface section of a module are in promise declarations.
|
|
% If a promise goal contains any unqualified symbols, the second pass
|
|
% leaves the symbol unchanged, but since the eventual actual qualification
|
|
% of the symbol could refer to any of the modules imported in the interface,
|
|
% we consider them *all* of them to be "used".
|
|
%
|
|
% For the same reason (we don't know what modules predicate names,
|
|
% function names and function symbols in goals may refer to), this package
|
|
% cannot implement any equivalent of --warn-interface-imports that would
|
|
% report unnecessary imports in the *implementation* section of a module.
|
|
%
|
|
% If the --warn-unused-imports option is set, then unused_imports.m
|
|
% can generate all the warnings we would, but it can generate *better*
|
|
% messages, since unlike the code here, it can report that an imported module
|
|
% is unused *anywhere* in the module. However, even if --warn-unused-imports
|
|
% *is* set, the code in unused_imports.m won't be invoked if we stop
|
|
% compilation before its normal invocation time, due to e.g. type or more
|
|
% errors. What we should do is generate warnings here; print them if we
|
|
% stop before the unused_imports pass; throw them away if we *do* get to
|
|
% that pass. We don't (yet) do this.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module parse_tree.module_qual.
|
|
:- interface.
|
|
|
|
:- include_module parse_tree.module_qual.id_set.
|
|
:- include_module parse_tree.module_qual.mq_info.
|
|
:- include_module parse_tree.module_qual.qualify_items.
|
|
|
|
:- implementation.
|
|
|
|
:- include_module parse_tree.module_qual.collect_mq_info.
|
|
:- include_module parse_tree.module_qual.qual_errors.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
:- end_module parse_tree.module_qual.
|
|
%---------------------------------------------------------------------------%
|