mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
When I split two files in a recent change, I ran into an annoying problem.
The problem was caused by unneeded imports in the interface of the new modules,
whose initial part I originally simply copied from the source module.
The problem was that when I attempted to compile new module A which imported
new module B, the compilation of module A would fail with a message about
not finding module B's .int file. It couldn't find B.int because the
compiler invocation that was supposed to create it failed, but it did not
print any error message about *why* it failed, and as a consequence,
it also did not set the exit status to nonzero to tell mmake that
the file was not actually built, so later build actions that need that file
should not be executed.
The cause of this problem was the following.
- The default value of the --warn-unused-imports is off, but COMP_FLAGS
turns it on for modules in the compiler directory. This enables warnings
generated by unused_imports.m.
- There is code that does a similar job in module_qual.qual_errors.m, but
that one is limited to imports in interface sections. Due to the overlap
between tasks, when this code finds an unused import_module declaration
in an interface, it generates an error message that was conditional
on --warn-unused-imports being off. When it was on, as it is with
COMP_FLAGS, it generates an error_spec that, when given to write_error_specs,
generates no output.
- Code in write_module_interface_files.m that decided whether the building
of the .int file has failed, tested only whether the process of generating
its contents has returned any error_specs, not whether it returned
any error_specs that would actually be printed, and, by being printed
with a sufficiently high severity, would set the exit status to signal
failure.
compiler/error_util.m:
The two changes to this file together fix the root cause of this problem.
First, a new predicate checks whether an error_spec has any part
whose printing is NOT disabled by being attached to an unmet condition.
Second, the predicate through which we pass all error_specs created
during the generation of the contents of the .int file filters out
any error_specs that yield no output.
The later changes are not strictly part of the bugfix, they are there
simply to make the code simpler to understand, in the hope that this fact
will reduce the probability of similar problems in the future.
compiler/module_qual.qual_errors.m:
Instead of generating error_specs that are conditional on
--warn-unused-imports being OFF, generate them conditional on
the new option --warn-unused-interface-imports being ON.
Using --warn-unused-imports here was strange because that option controls
whether the compiler invokes unused_imports.m. It was NOT specific
to this piece of code, while the new option is.
compiler/options.m:
doc/user_guide.texi:
Add the new option. Comment out its documentation, since I don't think
I can describe the reason for its existence simply enough for users
to understand.
compiler/handle_options.m:
Turn off the new option --warn-unused-interface-imports if
--warn-unused-imports is set. This duplicates the old behavior
of module_qual.qual_errors.m.
Turn off the new option --warn-unused-interface-imports if
we are generating interface files. This is because the presence
of unneeded imports in .m files does not prevent the creation
of valid .int files, so having to fix such warnings at .int file
creation time interferes with the programmer's ability to choose
the order in which he/she works on getting modules to a compilable shape.
compiler/write_module_interface_files.m:
Generate all output on error as part of an error_spec.
compiler/unused_imports.m:
Fix indentation.
tests/valid_make_int/extra_interface_import.m:
A new test case for this bug.
tests/valid_make_int/Mmakefile:
Enable the new test case.