Commit Graph

5 Commits

Author SHA1 Message Date
Zoltan Somogyi
d29183e5fb Improve error messages about unexpected module names.
When you get this message, the error may be in the module name that it
reports to be wrong, but it may be in the places that set the compiler's
expectations of what the name of the module should be. This latter is
very likely the case when one moves a module of the Mercury compiler
from one package to another. In such cases, the problems are the old modules
that continue to refer to the renamed module by its old name.

This diff includes in the error message the identities of the modules
that refer to the old name; these are the modules that establish the
expectation that is not met.

compiler/deps_map.m:
    When tracing references from module A to module B.C (either because
    A imports B.C, or because A = B and A includes C), record A as a source
    of the expectation that any file that contains module C will have
    B.C as module C's fully qualified name. Since a module is usually imported
    by more than one other module, there may be several sources of such
    expectations.

compiler/parse_module.m:
    Require callers of the functions that read in modules from files
    to specify the contexts of the places that establish the expectation
    of the module's fully qualified name.

    When the expectation is not met, include the contexts in the error message.

compiler/read_modules.m:
    Pass those contexts through to parse_module.m.

compiler/find_module.m:
compiler/make.module_dep_file.m:
compiler/mercury_compile_main.m:
compiler/modules.m:
compiler/recompilation.check.m:
    Conform to the changes above.

tests/invalid/bad_module_name.err_exp:
    Expect the updated error message.
2017-12-05 10:51:26 +11:00
Zoltan Somogyi
1af5bcf2f1 Make module_name_to_file_name currying-friendly.
compiler/file_names.m:
    Change the order of arguments of module_name_to_file_name and related
    predicates to make it easier to construct closures from them. Delete
    the previous higher-order-friendly versions, which the previous step
    has made unnecessary.

compiler/compile_target_code.m:
compiler/elds_to_erlang.m:
compiler/export.m:
compiler/find_module.m:
compiler/generate_dep_d_files.m:
compiler/intermod.m:
compiler/llds_out_file.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/modules.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the change above. In several places, this means replacing
    explicit lambda expressions with simple partial application of the
    relevant predicates.
2017-06-12 19:38:20 +02:00
Zoltan Somogyi
d7022606d4 Call the parser with explicit streams.
compiler/analysis.file.m:
compiler/make.module_dep_file.m:
compiler/parse_module.m:
compiler/recompilation.check.m:
    When calling the parser, explicitly specify the stream to read
    the term from; don't touch the current input stream.

compiler/find_module.m:
    Pass the stream to read from explicitly to parse_module.m.
2016-10-07 12:50:17 +11:00
Zoltan Somogyi
66356bae7b Make the predicates that find files handle streams explicitly.
compiler/file_util.m:
    The predicates in this module that find the file containing a Mercury
    module used to allow the caller to specify that if the file can be
    successfully opened, then the current input stream should be set to
    the resulting stream. This meant that callers had to save the original
    current input stream *before* calling this predicate, and later restore it,
    *without* anything in between that would signal to readers of the code
    that the current input stream had ever been changed.

    Replace each of these predicates with two predicates. One returns
    the stream as an explicit part of an output argument, letting the caller
    do with the stream what it wished (in some cases, that would mean
    using it in I/O operations as *explicitly* passed parameters, which
    would not require touching the identity of the current input stream),
    giving it the responsibility to close the stream when it is done using it.
    The other would close the stream immediately, not letting the caller know
    that the file was ever opened. The two versions are distinguised both
    by name and by return type.

compiler/find_module.m:
    Make the same change to search_for_module_source. (This predicate was
    the motivation for this change, because unlike the predicates in
    file_util.m, its signature did NOT provide readers with any sort of clue
    that the searched-for file would actually be opened, and that the
    resulting stream would become the new current input stream.)

    Clarify the code that tries to find the source file for a module
    by dropping qualifiers from the module name by (a) giving the predicate
    a more explicit name, and (b) separating the search from the code
    that handles the failure of the search.

compiler/parse_module.m:
compiler/read_modules.m:
    Change part of the interface between these two modules. This used to be
    that code in read_modules.m passed closures to parse_module.m for it
    to invoke, closures whose predicates were always one of the predicates
    affected by the changes above. Simplify the interface by making
    read_modules.m invoke those predicates directly, and simply pass
    the results.

compiler/compile_target_code.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/mercury_compile_front_end.m:
compiler/mmc_analysis.m:
compiler/module_cmds.m:
compiler/options_file.m:
compiler/write_deps_file.m:
    Conform to the changes above.
2016-09-06 17:10:14 +10:00
Zoltan Somogyi
f1df5d2dd1 Give parsing-related modules more meaningful names.
The mapping from the old to the new module names is:

    prog_io ->                  parse_module
    prog_io_dcg ->              parse_dcg_goal
    prog_io_error ->            parse_error
    prog_io_find ->             find_module
    prog_io_goal ->             parse_goal
    prog_io_inst_mode_defn ->   parse_inst_mode_defn
    prog_io_inst_mode_name ->   parse_inst_mode_name
    prog_io_iom ->              parse_types
    prog_io_item ->             parse_item
    prog_io_mutable ->          parse_mutable
    prog_io_pragma ->           parse_pragma
    prog_io_sym_name ->         parse_sym_name
    prog_io_type_defn ->        parse_type_defn
    prog_io_type_name ->        parse_type_name
    prog_io_typeclass ->        parse_class
    prog_io_util ->             parse_util
    prog_io_vars ->             parse_vars
    unparse ->                  parse_tree_to_term
2016-02-09 13:50:37 +11:00