mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
Specifically, make it warn about interface imports that are not used
in the initial HLDS, even if they *are* used after the expansion of
type-, inst- and mode-equivalences.
compiler/hlds_module.m:
Add a slot to the HLDS to store the set of modules that are
imported in the interface but are unused there when the HLDS
is first constructed.
compiler/module_qual.qualify_items.m:
Compute this set, and return it to mercury_compile_make_hlds.m.
Make the code module qualifying aug_compilation_units warn about
unused interface imports only if unused_imports.m won't do the same later.
compiler/mercury_compile_make_hlds.m:
Pass the set to make_hlds_passes.m.
compiler/make_hlds_passes.m:
Store the set in the initial HLDS.
compiler/prog_data_used_modules.m:
Replace set_ordlists with set_tree234s.
compiler/unused_imports.m:
Consider an interface-imported module unused in the interface
if module_qual.qualify_items.m considered it unused, even if
changes made by equiv_type.m has added uses of it later.
compiler/handle_options.m:
Stop making --warn-unused-imports imply --no-warn-unused-interface-imports,
since new logic in module_qual.qualify_items.m makes this unnecessary.
compiler/make_module_file_names.m:
compiler/type_inst_mode_map.m:
compiler/write_deps_file.m:
Move imports from the interface section to the implementation section,
in response to the new, more thorough warnings.
107 lines
3.8 KiB
Mathematica
107 lines
3.8 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%---------------------------------------------------------------------------%
|
|
% Copyright (C) 2016, 2022, 2025 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.
|
|
%---------------------------------------------------------------------------%
|
|
%
|
|
% This module defines the used_modules type and its operations.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module parse_tree.prog_data_used_modules.
|
|
:- interface.
|
|
|
|
:- import_module mdbcomp.
|
|
:- import_module mdbcomp.sym_name.
|
|
|
|
:- import_module set_tree234.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- type used_modules
|
|
---> used_modules(
|
|
% The modules used in the interface and implementation.
|
|
int_used_modules :: set_tree234(module_name),
|
|
imp_used_modules :: set_tree234(module_name)
|
|
).
|
|
|
|
:- type item_visibility
|
|
---> visibility_public
|
|
; visibility_private.
|
|
|
|
% Initialize the used_modules structure.
|
|
%
|
|
:- func used_modules_init = used_modules.
|
|
|
|
% Given a sym_name, call record_module_and_ancestors_as_used on the module
|
|
% part of the name.
|
|
%
|
|
:- pred record_sym_name_module_as_used(item_visibility::in, sym_name::in,
|
|
used_modules::in, used_modules::out) is det.
|
|
|
|
% Given a module name, add the module and all of its parent modules
|
|
% to the used_modules.
|
|
%
|
|
:- pred record_module_and_ancestors_as_used(item_visibility::in, sym_name::in,
|
|
used_modules::in, used_modules::out) is det.
|
|
|
|
:- pred record_format_modules_as_used(used_modules::in, used_modules::out)
|
|
is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module mdbcomp.builtin_modules.
|
|
|
|
:- import_module list.
|
|
|
|
used_modules_init = used_modules(set_tree234.init, set_tree234.init).
|
|
|
|
record_sym_name_module_as_used(Visibility, SymName, !UsedModules) :-
|
|
(
|
|
SymName = unqualified(_)
|
|
;
|
|
SymName = qualified(ModuleName, _),
|
|
record_module_and_ancestors_as_used(Visibility, ModuleName,
|
|
!UsedModules)
|
|
).
|
|
|
|
record_module_and_ancestors_as_used(Visibility, ModuleName, !UsedModules) :-
|
|
(
|
|
Visibility = visibility_public,
|
|
IntUsedModules0 = !.UsedModules ^ int_used_modules,
|
|
add_module_and_ancestors(ModuleName, IntUsedModules0, IntUsedModules),
|
|
!UsedModules ^ int_used_modules := IntUsedModules
|
|
;
|
|
Visibility = visibility_private,
|
|
ImpUsedModules0 = !.UsedModules ^ imp_used_modules,
|
|
add_module_and_ancestors(ModuleName, ImpUsedModules0, ImpUsedModules),
|
|
!UsedModules ^ imp_used_modules := ImpUsedModules
|
|
).
|
|
|
|
:- pred add_module_and_ancestors(sym_name::in,
|
|
set_tree234(module_name)::in, set_tree234(module_name)::out) is det.
|
|
|
|
add_module_and_ancestors(ModuleName, !UsedModuleNames) :-
|
|
set_tree234.insert(ModuleName, !UsedModuleNames),
|
|
(
|
|
ModuleName = unqualified(_)
|
|
;
|
|
ModuleName = qualified(ParentModuleName, _),
|
|
add_module_and_ancestors(ParentModuleName, !UsedModuleNames)
|
|
).
|
|
|
|
record_format_modules_as_used(!UsedModules) :-
|
|
ImpUsedModules0 = !.UsedModules ^ imp_used_modules,
|
|
FormatModules = [mercury_string_format_module,
|
|
mercury_string_parse_util_module, mercury_stream_module],
|
|
set_tree234.insert_list(FormatModules, ImpUsedModules0, ImpUsedModules),
|
|
!UsedModules ^ imp_used_modules := ImpUsedModules.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
:- end_module parse_tree.prog_data_used_modules.
|
|
%---------------------------------------------------------------------------%
|