Commit Graph

116 Commits

Author SHA1 Message Date
Julien Fischer
2a366cf295 Deprecate --no-ansi and --no-ansi-c.
--no-ansi (mgnuc) and --no-ansi-c (mmc) have not actually done anything for
many years now. Deprecate these options and remove their "use" throughout most
of the Mercury system. (The remaining uses are in the Makefiles for the Boehm
GC, which need to be updated separately.)

Also deprecate the internal compiler option --cflags-for-ansi.

compiler/options.m:
    Document that --no-ansi-c is now deprecated.

    Document that the internal option --cflags-for-ansi is now
    deprecated.

compiler/compile_target_code.m:
    Do not pass the ANSI options to the C compiler.

scripts/mgnuc.in:
scripts/mgnuc_file_opts.sh-subr:
    Deprecate the --no-ansi option; delete code that no longer does
    anything useful.

configure.ac:
    Delete the configuration variable CFLAGS_FOR_ANSI; it is only ever
    set to be empty. (The comment talks about --no-ansi doing other things
    in the mgnuc script. It used to also cause some preprocessor macros
    to be defined for compatibility with the system headers on some
    platforms -- that has not been the case since 2013.)

doc/user_guide.texi:
    Document that --no-ansi-c is deprecated.

bytecode/Mmakefile:
compiler/Mercury.options:
library/Mercury.options:
extras/odbc/odbc.m:
runtime/Mmakefile:
scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
tests/hard_coded/Mercury.options:
tests/valid/Mercury.options:
trace/Mmakefile:
util/Mmakefile:
    Conform to the above change.

NEWS.md:
    Announce the above.
2023-05-31 17:44:26 +10:00
Zoltan Somogyi
b6178ef723 Delete prog_out.m, moving its code to other modules.
compiler/parse_tree_out_cons_id.m:
    Move the predicates and functions in prog_out.m that deal with cons_ids
    to this module.

compiler/parse_tree_out_sym_name.m:
    Move the predicates and functions in prog_out.m that deal with sym_names
    and similar entities to this module.

compiler/parse_tree_out_type.m:
    Move the predicates and functions in prog_out.m that deal with types
    to this module.

compiler/parse_tree_out_misc.m:
    Move the predicates and functions in prog_out.m that deal with simple
    types to this module.

    Delete mercury_output_det and mercury_format_det, replacing all their
    uses with calls to mercury_det_to_string.

compiler/prog_out.m:
    Delete this module.

compiler/parse_tree.m:
    Delete prog_out from the parse_tree package.

compiler/Mercury.options:
compiler/notes/compiler_design.html:
    Delete references to prog_out.m.

compiler/*.m:
    Update imports and any explicit module qualifications to account
    for the moved code.

tools/filter_sort_imports:
    Automatically filter out any repeated imports. This can help with
    changes like this that redistribute the contents of one module to other
    modules. In this case, after a global replacement of prog_out's import
    with the import of parse_tree_out_misc, this updated script could
    remove this changed import from modules that already imported
    parse_tree_out_misc.
2023-04-09 16:23:13 +10:00
Zoltan Somogyi
1659e9e2cb Use explicit streams in analysis*.m.
compiler/analysis.m:
compiler/analysis.file.m:
    Switch to using explicit streams.

    Use io.format when relevant.

    Give some fields, predicates and variables more meaningful names.

    Replace some rafe-isms with code in our usual coding style.

    Add XXXs for possible future improvements.

    Replace the flag that says whether debug is enabled with a maybe
    wrapped around the stream where debug output should go.

compiler/handle_options.m:
    Initialize the maybe debug stream.

compiler/Mercury.options:
    Stop disabling the warning for the use of implicit streams
    for analysis.m and analysis.file.m.
2023-04-07 01:08:56 +10:00
Zoltan Somogyi
6f82724091 Pass streams explicitly at the top levels.
compiler/mercury_compile_main.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
    Pass progress and error streams explicitly in these top modules
    of the compiler. Use "XXX STREAM" to mark places where we could switch
    from using stderr for both the progress and error streams to using
    module-specific files as the progress and/or error streams.

compiler/passes_aux.m:
    Add a "maybe_" prefix to the names of the predicates that print progress
    messages at the appropriate verbosity levels, as their printing of those
    messages is conditional.

    Provide versions of those predicates that take explicitly specified
    streams to write to, and mark the versions that write to the current
    output stream as obsolete.

    The predicate that wrote progress messages for procedures
    used to have two versions, one taking a pred_proc_id, and one taking
    a pred_id/proc_id pair. Delete the latter, because the arity difference
    that differentiated the two versions is now needed for the difference
    between supplying and not supplying an explicit stream.

compiler/file_util.m:
compiler/hlds_error_util.m:
compiler/write_error_spec.m:
    Delete several predicates that wrote to the current output stream,
    since all their callers now use the versions that specify an explicit
    output stream.

compiler/check_promise.m:
compiler/check_typeclass.m:
compiler/closure_analysis.m:
compiler/complexity.m:
compiler/cse_detection.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/deps_map.m:
compiler/direct_arg_in_out.m:
compiler/grab_modules.m:
compiler/handle_options.m:
compiler/hhf.m:
compiler/inlining.m:
compiler/make.module_dep_file.m:
compiler/ml_proc_gen.m:
compiler/ml_top_gen.m:
compiler/mode_constraints.m:
compiler/modes.m:
compiler/polymorphism.m:
compiler/purity.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/saved_vars.m:
compiler/simplify_proc.m:
compiler/size_prof.m:
compiler/stack_opt.m:
compiler/switch_detection.m:
compiler/typecheck.m:
compiler/unique_modes.m:
compiler/unneeded_code.m:
compiler/write_module_interface_files.m:
    Get these modules to take an explicitly specified stream to which
    to write progress messages when they are invoked from mercury_compile_*.m.

    For predicates in these modules that can be invoked both directly
    by mercury_compile_*.m *and* by other modules, the latter effectively
    as a subcontractor, make them take a maybe(stream), with the intention
    being that all the other modules that use the predicate as a subcontractor
    would pass a "no". This avoids the need to pass progress streams
    down to the internals of other passes, and also avoids overwhelming
    the user invoking the compiler with unnecessary details.

    As above, and also delete a progress message that shouldn't be needed
    anymore.

    Move a test of option value compatibility from
    mercury_compile_middle_passes.m to handle_options.m, where it belongs.

compiler/float_regs.m:
    Write a debug message to the debug stream.

compiler/pd_info.m:
    Include the progress stream in the pd_info structure, because this is
    the simplest way to ensure that all parts of the partial deduction pass
    have access to it.

compiler/make.build.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
    Make the minimal changes needed to conform to the changes above.
    The rest can be done when the make package is converted to consistently
    use explicit streams.

compiler/bytecode_gen.m:
compiler/structure_reuse.direct.m:
compiler/structure_reuse.versions.m:
compiler/structure_sharing.analysis.m:
    Make the minimal changes needed to conform to the changes above.
    The rest can be done when these modules start being maintained again.

compiler/Mercury.options:
    Stop specifying --no-warn-implicit-stream-calls for mercury_compile_*.m,
    since this diff makes that unnecessary.

    Start specifying --no-warn-implicit-stream-calls for some modules that
    are not currently being actively maintained, because the addition of
    progress-reporting predicates that take explicitly specified streams
    would otherwise cause the generation of such warnings for them.
2022-11-01 11:33:41 +11:00
Zoltan Somogyi
307b1dc148 Split up error_util.m into five modules.
compiler/error_spec.m:
    This new module contains the part of the old error_util.m that defines
    the error_spec type, and some functions that can help construct pieces
    of error_specs. Most modules of the compiler that deal with errors
    will need to import only this part of the old error_util.m.

    This change also renames the format_component type to format_piece,
    which matches our long-standing naming convention for variables containing
    (lists of) values of this type.

compiler/write_error_spec.m:
    This new module contains the part of the old error_util.m that
    writes out error specs, and converts them to strings.

    This diff marks as obsolete the versions of predicates that
    write out error specs to the current output stream, without
    *explicitly* specifying the intended stream.

compiler/error_sort.m:
    This new module contains the part of the old error_util.m that
    sorts lists of error specs and error msgs.

compiler/error_type_util.m:
    This new module contains the part of the old error_util.m that
    convert types to format_pieces that generate readable output.

compiler/parse_tree.m:
compiler/notes/compiler_design.html:
    Include and document the new modules.

compiler/error_util.m:
    The code remaining in the original error_util.m consists of
    general utility predicates and functions that don't fit into
    any of the modules above.

    Delete an unneeded pair of I/O states from the argument list
    of a predicate.

compiler/file_util.m:
    Move the unable_to_open_file predicate here from error_util.m,
    since it belongs here. Mark another predicate that writes
    to the current output stream as obsolete.

compiler/hlds_error_util.m:
    Mark two predicates that wrote out error_spec to the current output
    stream as obsolete, and add versions that take an explicit output stream.

compiler/Mercury.options:
    Compile the modules that call the newly obsoleted predicates
    with --no-warn-obsolete, for the time being.

compiler/*.m:
    Conform to the changes above, mostly by updating import_module
    declarations, and renaming format_component to format_piece.
2022-10-12 20:50:16 +11:00
Zoltan Somogyi
5b2f6e533b Disable unknown_format_call warnings using scopes.
configure.ac:
    Require the installed compiler to support disable_warning scopes
    for unknown_format_calls.

compiler/Mercury.options:
library/Mercury.options:
    Do not disable unknown_format_call warnings in whole files.

compiler/parse_tree_out_info.m:
compiler/pd_debug.m:
library/io.m:
library/stream.string_writer.m:
library/string.m:
    Disable unknown_format_call warnings for just the format calls
    that need it.
2022-09-07 12:18:19 +10:00
Zoltan Somogyi
b4da4bbe58 Use explicit streams and var_tables in pd_*.m.
compiler/pd_debug.m:
compiler/pd_util.m:
    Change the interface of pd_debug_message and pd_debug_message_context
    to look up the pd_debug flag internally, instead of requiring callers
    to do that themselves. Change their operation to always output
    to the module's debug stream.

    Delete pd_debug_write, which was not used.

    Delete pd_debug_do_io after effectively inlining it at all its call sites.

    Use var_tables instead of varsets and/or vartypes where relevant.

compiler/deforest.m:
    Conform to the changes above.

compiler/hlds_out_mode.m:
    For two predicates that output debug information, provide versions
    that return a string instead. Replace a varset argument with a
    var_name_source in both predicates and both functions.

compiler/stm_expand.m:
    Use explicit streams.

compiler/Mercury.options:
    Don't disable warnings about implicit stream calls in the modules above.
2022-05-08 17:21:01 +10:00
Zoltan Somogyi
ef98e382da Carve mercury_compile_make_hlds.m out of mercury_compile_main.m.
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
    As above.

    Note some comment rot.

compiler/top_level.m:
compiler/Mercury.options:
    Add the new module.

compiler/notes/compiler_design.html:
    Document the new module.

library/list.m:
    Add a new variant of an existing utility predicate that can simplify
    some of the moved code, together with some variants (for symmetry
    with the existing code).

NEWS:
    Announce the additions to the library.
2022-04-21 19:28:10 +10:00
Julien Fischer
42148d216e Fix compilation in C# and Java grades.
compiler/make.build.m:
    Add a missing import that is only required the above grades.

compiler/Mercury.options.m:
    Do not warn about unused imports in the above module.
2022-01-13 19:01:44 +11:00
Zoltan Somogyi
fe3994f324 Carve three modules out of make.m.
compiler/make.top_level.m:
compiler/make.track_flags.m:
compiler/make.make_info.m:
    Carve these three modules out of make.m.

    make.top_level.m contains the top level of the mmc --make algorithm.

    make.track_flags.m contains code for keeping track of which options
    were used to compile which modules.

    make.make_info.m defines the make_info structure used by all the
    submodules of make.m, as well as a few other utility types.

compiler/notes/compiler_design.html:
    Document the new modules.

compiler/make.m:
    Delete the code that has been moved to the new modules, leaving
    make.m as purely a package.

    Include make.build.m in the interface, so we can delete the forwarding
    predicate we used to have here for use by mercury_compile_main.m.

compiler/Mercury.options:
    Make make.top_level.m and make.track_flags inherit make.m's old
    -no-warn-implicit-stream-calls option.

compiler/file_names.m:
    Move a utility function about extensions here from make.m.
    This also allows the removal of an undesirable module import of make.m
    in write_deps_file.m.

compiler/make.build.m:
    Move a type here from make.m, since it is needed to allow
    mercury_compile_main.m call this module directly (i.e. not through
    a forwarding predicate in make.m).

compiler/make.dependencies.m:
compiler/make.deps_set.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/options_file.m:
compiler/write_deps_file.m:
    Conform to the changes above. This mostly means having each module make.X
    actually import the modules it uses, instead of relying on make.m
    importing them, and getting those imports via make.int0.

    In a few cases, it means having each module make.X NOT import the modules
    it does NOT use, since after the "package-ification" of make.m,
    we now get warnings about these imports being unused.
2022-01-10 12:22:42 +11:00
Zoltan Somogyi
a9076327c0 Use explicit streams in recompilation.check.m.
compiler/recompilation.check.m:
    As above.

compiler/Mercury.options:
    Don't specify --no-warn-implicit-stream-calls for recompilation.check.m.
2021-12-17 16:01:37 +11:00
Zoltan Somogyi
6310117ca5 Enable and fix a bunch of compiler warnings. 2021-06-11 20:11:13 +10:00
Zoltan Somogyi
1af63acad5 Fix inconsistent pred order. 2021-06-11 18:36:52 +10:00
Zoltan Somogyi
d48cbb5d70 Use explicit streams in some more modules.
compiler/closure_analysis.m:
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/options.m:
    As above.

compiler/compiler_util.m:
    Delete the old report_warning predicate, and replace it with
    a renamed report_warning_to_stream predicate.

compiler/Mercury.options:
    Don't specify --no-warn-implicit-stream-calls for the above modules.

compiler/make.build.m:
compiler/make.program_target.m:
compiler/mercury_compile_main.m:
compiler/tupling.m:
    Conform to the changes above.
2021-06-11 17:17:54 +10:00
Zoltan Somogyi
1557cec62d Use explicit streams in two more modules.
compiler/higher_order.m:
compiler/hlds_goal.m:
    As above.

compiler/Mercury.options:
    Don't specify --no-warn-implicit-stream-calls for the above modules.

compiler/file_util.m:
    Add new forms of some utility predicates to make using explicit streams
    more convenient.
2021-06-11 15:25:27 +10:00
Zoltan Somogyi
bb58290e1c Use explicit streams in several modules.
compiler/deps_map.m:
compiler/generate_dep_d_files.m:
compiler/lp.m:
    As above. In lp.m, fix formatting of lambda expressions.

compiler/Mercury.options:
    Do not pass --no-warn-implicit-stream-calls when compiling these modules.
2021-06-08 20:23:47 +10:00
Zoltan Somogyi
bd0b747f6e Use explicit streams in several modules.
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_pragma_tabling.m:
compiler/check_libgrades.m:
compiler/deep_profiling.m:
compiler/goal_expr_to_goal.m:
compiler/options_file.m:
compiler/pickle.m:
compiler/process_util.m:
compiler/state_var.m:
compiler/superhomogeneous.m:
    Ad above.

compiler/Mercury.options:
    Do not pass --no-warn-implicit-stream-calls when compiling these modules.

compiler/analysis.file.m:
compiler/mercury_compile_main.m:
    Conform to the changes above.
2021-06-08 16:44:06 +10:00
Zoltan Somogyi
b922d9b4d1 Use explicit streams in fact_table.m.
compiler/fact_table.m:
    Use explicit streams.

    Do not require callers to supply redundant information.

    Replace several uses of booleans with values of bespoke types.

    Move loop invariants that are not trivial access predicates out of loops.

    Put constant input args (those passed to recursive calls unchanged)
    before non-constant input args.

    Put related args next to each other.

    Replace uses of string.append and string.append_list with ++ and
    string.format where the result is clearer code.

    Document the reason why we do a task the hard way.

    Update the generation of error messages.

    Stop mixing underscores and CamelCase.

    Improve variable names. In particular, stop the old practice
    of giving variables 0 and 1 suffixes when computed from
    the head and the tail of an input list respectively.

    Replace /* */ comments with // comments in the generated C code
    where possible.

    Simplify some convoluted pieces of code.

    Add XXXs for some potential problems and some potential improvements.

compiler/Mercury.options:
    Do not specify --no-warn-implicit-stream-calls for fact_table.m.

compiler/arg_info.m:
    Put constant input args before non-constant input args.

compiler/add_pragma.m:
compiler/bytecode_gen.m:
compiler/follow_vars.m:
    Conform to the changes above.

compiler/error_util.m:
    Improve indentation.
2021-06-08 07:53:05 +10:00
Peter Wang
bd7e672dec Replace MD4 implementation with MD5.
We used MD4 digests in the implementation of the `--track-flags'
feature. While there is no particular need to change, IIRC the only
reason I didn't use the more common MD5 algorithm is because I did not
know of a small portable implementation at the time.

compiler/md5.m:
compiler/Mercury.options:
    Add implementation of MD5 digest algorithm.
    The C code is public domain code, and apparently widely used.

compiler/md4.m:
    Delete this module.

compiler/libs.m:
    Include new module and delete old module.

compiler/make.m:
    Calculate MD5 digest for `.track_flags' files instead of MD4.
2021-06-05 13:15:19 +10:00
Zoltan Somogyi
365e301863 Add back needed --no-warn-implicit-stream-calls. 2021-05-17 23:09:18 +10:00
Zoltan Somogyi
93c306916a Specify streams explicitly in more modules.
compiler/module_cmds.m:
    Require all callers to specify output streams explicitly.

compiler/compile_target_code.m:
    Require callers to specify output streams explicitly in most cases.

    In the remaining cases, add "XXX STREAM" comments to request that
    the explicit streams be passed later.

    Add XXXs where preserving old behavior results in wrong-looking code.

    Modify the signature of compile_java_files to encode the invariant that
    the list of Java files given to it may not be empty.

compiler/error_util.m:
    Provide a version of an error predicate that takes explicit streams.

compiler/make.build.m:
    Mark predicates that help redirect implicit streams as predicates
    that should not be used.

compiler/make.module_target.m:
compiler/make.program_target.m:
    Add "XXX STREAM" comments to request that the explicit streams
    be passed later.

compiler/module_qual.m:
    Provide a means to construct the debug output stream.

compiler/module_qual.collect_mq_info.m:
    Use the debug output stream where relevant.

compiler/analysis.m:
compiler/export.m:
compiler/recompilation.check.m:
compiler/source_file_map.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the changes above, mostly by passing explicit streams.

compiler/Mercury.options:
    Stop specifying --no-warn-implicit-stream-calls for the above modules
    (those that had it specified in the first place).

    Delete a long-unneeded workaround.

compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
    Specify progress and output streams explicitly when calling the modules
    above (not in other places, just yet).
2021-05-17 22:55:06 +10:00
Zoltan Somogyi
1b65273d2d Specify output streams in some places.
compiler/introduce_parallelism.m:
compiler/parallel_to_plain_conj.m:
compiler/push_goals_together.m:
compiler/tabling_analysis.m:
compiler/trailing_analysis.m:
compiler/tupling.m:
compiler/unused_args.m:
    As above.

compiler/Mercury.options:
    Do not specify --no-warn-implicit-stream-calls for the modules above.

compiler/hlds_out_goal.m:
    Add a utility predicate for push_goals_together.m.

compiler/mercury_compile_middle_passes.m:
    Move the code for looking up the source file map, and the code
    for printing any error messages, here from introduce_parallelism.m.
    This allows introduce_parallelism.m to do no I/O whatsoever.
    It should also allow a future change to print any messages together
    with any messages generated by other passes.
2021-03-25 07:57:24 +11:00
Zoltan Somogyi
c2d5118c32 Make pred declaration and definition order match. 2021-03-25 07:07:12 +11:00
Zoltan Somogyi
1dd10f7170 Make pred declaration and definition order match. 2021-03-25 06:22:03 +11:00
Zoltan Somogyi
5b97566f8c Make pred declaration and definition order match. 2021-03-25 04:27:30 +11:00
Zoltan Somogyi
272e547bec Specify output streams in some places.
compiler/check_typeclass.m:
compiler/lp_rational.m:
compiler/matching.m:
compiler/polyhedron.m:
compiler/pred_table.m:
compiler/proc_gen.m:
compiler/stack_opt.m:
compiler/term_constr_build.m:
compiler/term_constr_data.m:
compiler/term_constr_fixpoint.m:
compiler/term_constr_pass2.m:
compiler/term_constr_util.m:
compiler/unused_imports.m:
    As above.

    Use io.format to replace several calls to io.* where possible.

    Give some predicates more specific names to avoid ambiguity.

    Reorder the arguments of some predicates to allow higher order programming
    in future.

    Delete some functions that duplicate the functionality of predicates.

    Rename VarSet to Varset in several places.

    Put all debug predicates in a single group in each module.

compiler/Mercury.options:
    Do not specify --no-warn-implicit-stream-calls for the modules above.
2021-03-25 03:48:01 +11:00
Zoltan Somogyi
6335d0b292 Default to --warn-implicit-stream-calls in compiler.
compiler/COMP_FLAGS.in:
    As above.

compiler/Mercury.options:
    Specify --no-warn-implicit-stream-calls for the modules that
    currently get warnings about implicit streams.
2021-03-24 22:15:19 +11:00
Zoltan Somogyi
85eb971b8d Specify output streams in some places.
Besides this main purpose, this diff also replaces code that calls
io.write_string several times in a row with code that prints the
thing to be printed in one go with io.format.

compiler/accumulator.m:
compiler/code_gen.m:
compiler/dead_proc_elim.m:
compiler/interval.m:
compiler/ite_gen.m:
compiler/lco.m:
compiler/mode_debug.m:
compiler/mode_info.m:
compiler/modes.m:
compiler/stack_opt.m:
    As above.

compiler/Mercury.options:
    Specify --warn-implicit-stream-calls for the modules above,
    and for some other modules that are already free of such warnings.
2021-03-24 22:02:18 +11:00
Zoltan Somogyi
c31bbf65b8 Use explicit streams in several modules.
compiler/cse_detection.m:
compiler/det_analysis.m:
compiler/inst_test.m:
compiler/ml_optimize.m:
compiler/mlds_dump.m:
compiler/optimize.m:
    Replace all uses of implicit streams with explicit streams.

compiler/Mercury.options:
    Warn about any implicit streams in the above modules.

compiler/llds_out_file.m:
    Fix bug: replace the one remaining use of implicit streams
    with an explicit stream.

compiler/mercury_compile_llds_back_end.m:
    Conform to the changes above.
2021-03-22 23:28:13 +11:00
Zoltan Somogyi
d52f305550 Carve three new modules out of polymorphism.m.
The remaining code of polymorphism.m is still less cohesive than
it ought to be, and could probably benefit from further reorganization
and/or breakup, but this diff is definitely a step in the right direction.

compiler/polymorphism_info.m:
    A new module carved out of polymorphism.m, that defines

    - the poly_info type,
    - the types used in the fields in the poly_info type,
    - the basic operations on the poly_info type and its component types,
    - some very basic utility predicates used by several of polymorphism*.m.

    It also contains the infrastructure needed for debugging the polymorphism
    pass. This consists mainly of the mutables accessed from trace goals
    in that pass.

    Replace the bool type of one of these mutables with a bespoke type.

    Attach the mutables to the I/O state, to avoid the need to make code
    using those mutables semipure or impure.

compiler/polymorphism_type_info.m:
    A new module carved out of polymorphism.m, that defines operations
    that create type_infos, or extract type_infos from other type_infos
    or typeclass_infos.

    Add two new preds, polymorphism_make_type_info_{var,vars}_raw.
    Unlike their old non-raw equivalents, these allow their callers to supply
    module_infos, pred_infos and proc_infos without having to first construct
    a poly_info from them.

compiler/polymorphism_lambda.m:
    A new module carved out of polymorphism.m that manipulates lambda goals.

compiler/polymorphism.m:
    Delete the code moved to the new modules.

    Make the definition order of predicates in match their declaration order.

compiler/check_hlds.m:
    Add the new modules to the check_hlds package.

compiler/notes/compiler_design.html:
    Document the new modules. Fix some out-of-date and/or repetitive
    existing documentation.

compiler/Mercury.options:
    Require polymorphism.m to have matching declaration and definition orders
    for its predicates.

compiler/complexity.m:
compiler/equiv_type_hlds.m:
compiler/higher_order.m:
compiler/ml_accurate_gc.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/simplify_goal_unify.m:
compiler/size_prof.m:
compiler/ssdebug.m:
compiler/stm_expand.m:
compiler/table_gen.m:
compiler/try_expand.m:
    Conform to the changes above.

    Call polymorphism_make_type_info_{var,vars}_raw instead of their
    non-raw equivalents.
2021-03-22 20:21:22 +11:00
Peter Wang
6a59f4d6bf Fix module name in options file. 2021-03-22 10:48:30 +11:00
Zoltan Somogyi
bd594dded2 Impose logical order on mode_info.m and mode_util.m.
compiler/mode_info.m:
compiler/mode_util.m:
    Put the predicates in these modules into logical groups, and ensure
    that the orders of the declarations and definitions match.

    Delete the unused predicate mode_info_set_how_to_check from mode_info.m.

    Delete the unused predicates select_output_vars, select_output_things,
    and partition_args from mode_util.m.

    Rename the unify_modes_to_X predicates to unify_mode_to_X, since each
    of these predicates operates on only *one* unify_mode.

    Move three predicates that are needed only during mode checking,
    and not during later compuiler passes, to modecheck_util.m.

compiler/modecheck_util.m:
    Add the predicates moved from mode_util.m.

compiler/Mercury.options:
    Require the order of predicates' definitions to match the order of
    their declarations in mode_info.m and mode_util.m.

compiler/common.m:
compiler/loop_inv.m:
compiler/modecheck_goal.m:
    Conform to the changes in mode_util.m.
2021-03-22 02:26:58 +11:00
Zoltan Somogyi
4455f0450e Specify output streams in some places.
Besides this main purpose, this diff also replaces code that calls
io.write_string several times in a row with code that prints the
thing to be printed in one go with io.format. In a couple of places,
this has caught (and fixed) bugs where we wanted to put `' quotes
around a filename, but printed only one of the two quotes.

compiler/file_util.m:
    Provide alternatives to the existing maybe_report_stats,
    maybe_write_string and maybe_flush_output predicates that explicitly
    specify the output stream.

    Rename report_error_to_stream as report_error, to allow
    --warn-implicit-stream-calls to report calls to the existing report_error
    predicate, which does not take an explicit output stream.

    Add a module_name argument to the output_to_file_stream predicate,
    to allow its code to figure out where to print both progress and
    error messages.

compiler/module_cmds.m:
    Add a module_name argument to the predicates that update interface,
    to allow their code to figure out where to print both progress and
    error messages.

    For now, leave the predicates that issue commands that are not
    clearly linked to a single module using implicit streams.

compiler/pd_debug.m:
compiler/analysis.file.m:
    Specify output streams in some places.

    In other places, doing so would require redoing the whole debug
    infrastructure, since the current one is based on higher order predicates
    that always write to the non-explicitly-specified *current* output stream.

compiler/passes_aux.m:
    Provide predicates that get progress, debug and error streams
    given a module_info, by extracting the globals and the module name
    from the module_info, and then calling the predicates in globals.m
    to get those streams. Doing this sequence of actions here factors out
    what would otherwise be repeated code in many other parts of the compiler.

    Delete two predicates that were not used anywhere in the compiler.

compiler/deforest.m:
compiler/export.m:
compiler/intermod.m:
compiler/llds_out_file.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/recompilation.usage.m:
compiler/simplify_goal_conj.m:
compiler/type_assign.m:
compiler/typecheck.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
    Use explicit streams everywhere where --warn-implicit-stream-calls
    says this is possible.

compiler/Mercury.options:
    Specify --warn-implicit-stream-calls for the modules above
    with the listed exceptions, and with the exception of the modules
    for which it was already specified.

compiler/compile_target_code.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_middle_passes.m:
    Conform to the changes above.
2021-03-21 23:07:59 +11:00
Zoltan Somogyi
91162b548d Fix #line directives emitted in LLDS grades.
compiler/c_util.m:
    Add missing stream argument.

compiler/Mercury.options:
    Fix misspelt filename that prevented the problem in c_util.m
    from being automatically diagnosed.
2021-01-27 16:53:08 +11:00
Zoltan Somogyi
24078e6e75 Write to explicitly named streams in the MLDS backend.
compiler/mlds_to_c_class.m:
compiler/mlds_to_c_data.m:
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_c_func.m:
compiler/mlds_to_c_global.m:
compiler/mlds_to_c_name.m:
compiler/mlds_to_c_stmt.m:
compiler/mlds_to_c_type.m:
compiler/mlds_to_c_util.m:
compiler/mlds_to_cs_class.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_cs_func.m:
compiler/mlds_to_cs_global.m:
compiler/mlds_to_cs_name.m:
compiler/mlds_to_cs_stmt.m:
compiler/mlds_to_cs_type.m:
compiler/mlds_to_cs_util.m:
compiler/mlds_to_java_class.m:
compiler/mlds_to_java_data.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_func.m:
compiler/mlds_to_java_global.m:
compiler/mlds_to_java_name.m:
compiler/mlds_to_java_stmt.m:
compiler/mlds_to_java_type.m:
compiler/mlds_to_java_util.m:
compiler/mlds_to_target_util.m:
    As above.

compiler/Mercury.options:
    Specify --warn-impliciy-stream-calls for all the modules above.

compiler/file_util.m:
    Delete a utility predicate that expects its clients to operate on
    implicit streams, since the changes above replaced the last calls to it
    with the variant that expects its client to operate on explicit streams.
2020-11-17 11:20:43 +11:00
Zoltan Somogyi
5f50259d16 Write to explicitly named streams in many modules.
Right now, most parts of the compiler write to the "current output stream".
This was a pragmatic choice at the time, but has not aged well. The problem
is that the answer to the question "where is the current output stream going?"
is not obvious in *all* places in the compiler (although it is obvious in
most). When using such implicit streams, finding where the output is going
to in a given predicate requires inspecting not just the ancestors of that
predicate, but also all their older siblings (since any of them could have
changed the current stream), *including* their entire call trees. This is
usually an infeasible task. By constrast, if we explicitly pass streams
to all output operations, we need only follow the places where the variable
representing that stream is bound, which the mode system makes easy.

This diff switches large parts of the compiler over to doing output only
to explicitly passed streams, never to the implicit "current output stream".
The parts it switches over are the parts that rely to a significant degree
on the innermost change, which is to the "output" typeclass in
parse_tree_out_info.m. This is the part that has to be switched over to
explicit streams first, because (a) many modules such as mercury_to_mercury.m
rely on the output typeclass, and (b) most other modules that do output
call predicates in these modules. Starting anywhere else would be like
building a skyscraper starting at the top.

This typeclass, output(U), has two instances: output(io), and output(string),
so you could output either to the current output stream, or to a string.
To allow the specification of the destination stream in the first case,
this diff changes the typeclass to output(S, U) with a functional dependency
from U to S, with the two instances being output(io.text_output_stream, io)
and output(unit, string). (The unit arg is ignored in the second case.)

There is a complication with the output typeclass method, add_list, that
outputs a list of items. The complication is that each item is output
by a predicate supplied by the caller, but the separator between the items
(usually a comma) is output by add_list itself. We don't want to give
callers of this method the opportunity to screw up by specifying (possibly
implicitly) two different output streams for these two purposes, so we want
(a) the caller to tell add_list where to put the separators, and then
(b) for add_list, not its caller, tell the user-supplied predicate what
stream to write to. This works only if the stream argument is just before
the di,uo pair of I/O state arguments, which differs from our usual practice
of passing the stream at or near the left edge of the argument list,
not near the right. The result of this complication is that two categories
of predicates that are and are not used to print items in a list differ
in where they put the stream in their argument lists. This makes it easy
to pass the stream in the wrong argument position if you call a predicate
without looking up its signature, and may require *changing* the argument
order when a predicate is used to print an item in a list for the first time.
A complete switch over to always passing the stream just before !IO
would fix this inconsistency, but is far to big a change to make all at once.

compiler/parse_tree_out_info.m:
    Make the changes described above.

    Add write_out_list, which is a variant of io.write_list specifically
    designed to address the "complication" described above. It also has
    the arguments in an order that is better suited for higher-order use.

    Make the same change to argument order in the class method add_list
    as well.

Almost all of the following changes consist of passing an extra stream
argument to output predicates. In some places, where I thought this would
aid readability, I replaced sequences of calls to output predicates
with a single io.format.

compiler/prog_out.m:
    This module had many predicates that wrote things to the current output
    stream. This diff adds versions of these predicates that take an
    explicit stream argument.

    If the originals are still needed after the changes to the other modules,
    keep them, but add "_to_cur_stream" to the end of their names.
    Otherwise, delete them. (Many of the changes below replace
    write_xyz(..., !IO) with io.write_string(Stream, xyz_to_string(...), !IO),
    especially when write_xyz did nothing except call xyz_to_string
    and wrote out the result.)

compiler/c_util.m:
    Add either an explicit stream argument to the argument list, or a
    "_current_stream" suffix to the name, of every predicate defined
    in this module that does output.

    Add a new predicate to print out the block comment containing
    input for mkinit. This factors out common code in the LLDS and MLDS
    backends.

compiler/name_mangle.m:
    Delete all predicates that used to write to the current output stream,
    after replacing them if necessary with functions that return a string,
    which the caller can print to wherever it wants. (The "if necessary"
    part is there because some of the "replacement" functions already
    existed.)

    When converting a proc_label to a string, *always* require the caller
    to say whether the label prefix should be added to the string,
    instead of silently assuming "yes, add it", as calls to one of the old,
    now deleted predicates had it.

compiler/file_util.m:
    Add output_to_file_stream, a version of output_to_file which
    simply passes the output file stream it opens to the predicate
    that is intended to define the contents of the newly created or
    updated file. The existing output_to_file, which instead sets
    and resets the current output stream around the equivalent
    predicate call, is still needed e.g. by the MLDS backend,
    but hopefully for not too long.

compiler/mercury_to_mercury.m:
compiler/parse_tree_out.m:
compiler/parse_tree_out_clause.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_out_pragma.m:
compiler/parse_tree_out_pred_decl.m:
compiler/parse_tree_out_term.m:
compiler/parse_tree_out_type_repn.m:
    Change the code writing out parse trees to explicitly pass a stream
    to every predicate that does output.

    In some places, this allows us to avoid changing the identity
    of the current output stream.

compiler/hlds_out.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_mode.m:
compiler/hlds_out_module.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/intermod.m:
    Change the code writing out HLDS code to explicitly pass a stream
    to every predicate that does output. (The changes to these modules
    belong in this diff because these modules call many of the output
    predicates in the parse tree package.)

    In hlds_out_util.m, delete some write_to_xyz(...) predicates that wrote
    the result of xyz_to_string(...) to the current output stream.
    Replace calls to the deleted predicates with calls to io.write_string
    with the string being written being computed by xyz_to_string.

    Add a predicate to hlds_out_util.m that outputs a comment containing
    the current context, if it is valid. This factors out code that used
    to be common to several of the other modules.

    In a few places in hlds_out_module.m, the new code generates a
    slighly different set of blank lines, but this should not be a problem.

compiler/layout_out.m:
compiler/llds_out_code_addr.m:
compiler/llds_out_data.m:
compiler/llds_out_file.m:
compiler/llds_out_global.m:
compiler/llds_out_instr.m:
compiler/llds_out_util.m:
compiler/opt_debug.m:
compiler/rtti_out.m:
    Change the code writing out the LLDS to explicitly pass a stream
    to every predicate that does output. (The changes to these modules
    belong in this diff because layout_out.m and rtti_out.m call
    many of the output predicates in the parse tree package,
    and through them, the rest of the LLDS backend is affected as well.)

compiler/make.module_dep_file.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
    Replace code that sets and resets the current output stream
    with code that simply passes an explicit output stream to a
    predicate that now *takes* an explicit stream as an argument.

compiler/accumulator.m:
compiler/add_clause.m:
compiler/code_gen.m:
compiler/code_loc_dep.m:
compiler/cse_detection.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/error_msg_inst.m:
compiler/export.m:
compiler/format_call.m:
compiler/goal_expr_to_goal.m:
compiler/ite_gen.m:
compiler/lco.m:
compiler/liveness.m:
compiler/lp_rational.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_c_global.m:
compiler/mode_debug.m:
compiler/mode_errors.m:
compiler/modes.m:
compiler/optimize.m:
compiler/passes_aux.m:
compiler/pd_debug.m:
compiler/pragma_c_gen.m:
compiler/proc_gen.m:
compiler/prog_ctgc.m:
compiler/push_goals_together.m:
compiler/rat.m:
compiler/recompilation.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/rtti.m:
compiler/saved_vars.m:
compiler/simplify_goal_conj.m:
compiler/stack_opt.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.domain.m:
compiler/structure_reuse.indirect.m:
compiler/structure_sharing.analysis.m:
compiler/superhomogeneous.m:
compiler/term_constr_build.m:
compiler/term_constr_data.m:
compiler/term_constr_fixpoint.m:
compiler/term_constr_pass2.m:
compiler/term_constr_util.m:
compiler/tupling.m:
compiler/type_assign.m:
compiler/unneeded_code.m:
compiler/write_deps_file.m:
    Conform to the changes above, mostly by passing streams explicitly.

compiler/hlds_dependency_graph.m:
    Conform to the changes above, mostly by passing streams explicitly.
    Move a predicate's definition next it only use.

compiler/Mercury.options:
    Specify --warn-implicit-stream-calls for all the modules in which
    this diff has replaced all implicit streams with explicit streams.
    (Unfortunately, debugging this diff has shown that --warn-implicit-
    stream-calls detects only *some*, and not *all*, uses of implicit
    streams.)

library/term_io.m:
    Fix documentation.
2020-11-14 15:07:55 +11:00
Peter Wang
29f8e4f6ff Delete unneeded module import. 2020-10-30 13:20:21 +11:00
Zoltan Somogyi
185e4c4e96 Delete all stale code for Erlang from the compiler.
compiler/Mercury.options:
    Delete a workaround we needed only for Erlang.

compiler/add_mutable_aux_preds.m:
    Delete the implementation of mutables for Erlang.

compiler/builtin_ops.m:
    Document the fact that the Erlang backend was the only user of
    two operations.

compiler/compile_target_code.m:
compiler/module_cmds.m:
    Delete the predicates that handled the compilation of Erlang code.

compiler/file_names.m:
    Delete code dealing with file names used only by the Erlang backend.

compiler/options.m:
    Delete the old internal-only order_constructors_for_erlang option.

    Add an XXX about another option intended for Erlang being unused.

    Leave the other erlang-related options alive for now, to avoid breaking
    Mmakefiles, Mercury.options files etc that may still refer to them.

    Delete references to Erlang in help and/or error messages.

compiler/handle_options.m:
    Don't both updating options that were used only by the Erlang backend,
    and which are now unused.

    Delete references to Erlang in help and/or error messages.

compiler/unify_proc.m:
    Delete the code handling the Erlang-specific option deleted from options.m.

compiler/check_libgrades.m:
compiler/delay_partial_inst.m:
compiler/llds_out_data.m:
compiler/make_hlds_passes.m:
compiler/mlds_to_c_data.m:
compiler/prog_item.m:
compiler/simplify_goal_call.m:
compiler/write_deps_file.m:
    Either delete comments referring to Erlang or the Erlang backend,
    or, where their existence was the motivation for some design decisions,
    shift the comments to the past tense.

tests/mmc_make/Mmakefile:
    Delete a reference to a recently deleted .hrl file.
2020-10-29 23:29:36 +11:00
Zoltan Somogyi
6223e79ee1 Make pred defn order match decl order. 2020-09-26 14:23:13 +10:00
Zoltan Somogyi
204b7ae6dd Compile the compiler with --warn-dead-preds.
compiler/COMP_FLAGS.in:
    Specify --warn-dead-preds for all modules by default.

compiler/Mercury.options:
    Stop specifying --warn-dead-preds for modules individually.

compiler/mlds_to_c_func.m:
compiler/mlds_to_c_type.m:
compiler/parse_tree_out_type_repn.m:
    Delete some unused predicates.

compiler/equiv_type_hlds.m:
    Shut up a warning about an unused predicate that may be needed later.

compiler/det_analysis.m:
    Use a bespoke format component.

compiler/error_util.m:
    Fix some comments.

compiler/process_util.m:
    Don't use mode-specific clauses unnecessarily.

compiler/timestamp.m:
    Give a predicate a more descriptive name.
2020-07-31 23:04:05 +10:00
Zoltan Somogyi
79e8804db9 Fix "this disjunct can't have solutions" warnings in multimode preds.
This fixes github issue #85.

A complication is that the compiler itself has code, in make.util.m,
in which a disjunct has no solutions in only one mode of a two mode
function, but in this case, the code works (though its programming style
is pretty bad), so to get this change to bootstrap, we also need
a way to disable the "this disjunct can't have solutions" warning
in a scope.

compiler/simplify_goal_disj.m:
    When we generate a "this disjunct can't succeed" warning,
    do not insist on all modes generating that warning.
    We used to insist on that because in a multi-mode predicate,
    such warnings can be inappropriate for other modes.
    Instead, achieve the same objective of minimizing programmer
    confusion by adding a codicil explicitly mentioninging
    this possibility.

    Make the generation of this warning conditional on a simplify task
    that can be disabled by "disable_warnings" scope.

compiler/prog_data.m:
    Add "no_solution_disjunct" as a warning kind that may be disabled.

compiler/parse_goal.m:
    Parse the new kind of warning.

compiler/prog_out.m:
    Output the new kind of warning.

    Improve some adjacent though unrelated code.

compiler/make.util.m:
    Add code disable this warning in the affected predicate.
    Comment out this code until installed compilers know how
    to parse it and understand it.

compiler/Mercury.options:
    Don't turn warnings into errors for make.util.m until then.

compiler/simplify_goal_scope.m:
compiler/simplify_info.m:
compiler/simplify_tasks.m:
    Provide the mechanism needed to make it possible to disable
    warnings about no solution disjuncts.

doc/reference_manual.texi:
    Document the new disable-able warning.

NEWS:
    Document both the changed behavior of the old warning
    and the new way to disable it.

tests/warnings/gh85.{m,exp}:
    A regression test for the bug, based on the code in the
    github issue. It also tests the way to disable the warning.

tests/warnings/Mmakefile:
    Enable the new test case.
2020-03-24 15:20:59 +11:00
Zoltan Somogyi
1fe767018b Carve make.build.m out of make.util.m.
compiler/make.build.m:
compiler/make.util.m:
    As above. Make.build.m contains the parts of the old make.util.m
    that deal with executing the actions that bring targets up to date.
    This change improves the cohesion of both modules (though make.util.m's
    still isn't great).

compiler/notes/compiler_design.html:
    Document the new module.

compiler/make.m:
    Include the new submodule.

compiler/Mercury.options:
    Insist that all submodules of make.m have definitions in the same order
    as declarations.

compiler/make.dependencies.m:
compiler/options_file.m:
    Fix the order mismatches that Mercury.options used to cover up.

compiler/mercury_compile_main.m:
    Import make.build instead of make.util.
2020-03-16 21:47:08 +11:00
Zoltan Somogyi
9789375cc5 Make pre-HLDS passes use file-kind-specific parse trees.
Replacing item blocks file-kind-specific kinds of section markers with
file-kind-specific parse trees has several benefits.

- It allows us to encode the structural invariants of each kind of file
  we read in within the type of its representation. This makes the detection
  of any accidental violations of those invariants trivial.

- Since each file-kind-specific parse tree has separate lists for separate
  kinds of items, code that wants to operate on one or a few kinds of items
  can just operate on those kinds of items, without having to traverse
  item blocks containing many other kinds of items as well. The most
  important consequence of this is not the improved efficiency, though
  that is nice, but the increased clarity of the code.

- The new design is much more flexible. For example, it should be possible
  to record that e.g. an interface file we read in as a indirect dependency
  (i.e. a file we read not because its module was imported by the module
  we are compiling, but because its module was imported by *another* imported
  module) should be used *only* for the purpose it was read in for. This should
  avoid situations where deleting an import of A from a module, because it
  is not needed anymore, leads the compiler to generate an error message
  about a missing import of module B. This can happen if (a) module B
  always *should* have been imported, since it is used, but (b) module A's
  import of module B lead to module B's interface being available *without*
  an import of B.

  Specifically, this flexibility should enable us to establish each module's
  .int file as the single source of truth about how values of each type
  defined in that module should be represented. When compiling each source
  file, this approach requires the compiler to read in that module's .int file
  but using only the type_repn items from that .int file, and nothing else.

- By recording a single parse tree for each file we have read, instead of
  a varying number of item blocks, it should be significantly easier to
  derive the contents of .d files directly from the records of those
  parse trees, *without* having to maintain a separate set of fields
  in the module_and_imports structure for that purpose. We could also
  trivially avoid any possibility of inconsistencies between these two
  different sources of truth. (We currently fill in the fields used to
  drive the generation of .d files using two different pieces of code,
  one used for --generate-dependencies and one used for all other invocations,
  and these two *definitely* generate inconsistent results, as the significant
  differences in .d files between (a) just after an invocation of
  --generate-dependencies and (b) just after any other compiler invocation
  can witness.)

This change is big and therefore hard to review. Therefore in many files,
this change adds "XXX CLEANUP" comments to draw attention to places that
have issues that should be fixed, but whose fixes should come later, in
separate diffs.

compiler/module_imports.m:
    The compiler uses the module_and_imports structure defined here
    to go from a raw compilation unit (essentially a module to be compiled)
    to an augmented compilation unit (a raw compilation unit together
    with all the interface and optimization files its compilation needs).
    We used to store the contents of both the source file and of
    the interface and optimization files in the module_and_imports structure
    as item blocks. This diff replaces all those item blocks with
    file-kind-specific parse trees, for the reasons mentioned above.

    Separate out the .int0 files of ancestors modules from the .intN
    files for N>0 of directly imported modules. (Their item blocks
    used to be stored in the same list.)

    Maintain a database of the source, interface and optimization files
    we have read in so far. We use it to avoid reading in interface files
    if we have already read in a file for the same module that contains
    strictly more information (either an interface file with a smaller
    number as a suffix, or the source file itself).

    Shorten some field names.

compiler/prog_item.m:
    Define data structures for storing information about include_module,
    import_module and use_module declarations, both in a form that allows
    the representation of possibly erroneous code in actual source files,
    and in checked-and-cleaned-up form which is guaranteed to be free
    of the relevant kinds of errors. Add a block comment at the start
    of the module about the need for this distinction.

    Define parse_tree_module_src, a data structure for representing
    the source code of a single module. This is different from the existing
    parse_tree_src type, which represents the contents of a single source file
    but which may contain *more* than one module, and also different from
    a raw_compilation_unit, which is based on item blocks and is thus
    unable to express to invariants such as "no clauses in the interface".

    Modify the existing parse_tree_intN types to express the distinction
    mentioned just above, and to unify them "culturally", i.e. if they
    store the same information, make them store it using the same types.

    Fix a mistake by allowing promises to appear in .opt files.
    I originally ruled them out because the code that generates .opt files
    does not have any code to write out promises, but some of the predicates
    whose clauses it writes out have goal_type_promise, which means that
    they originated as promises, and get written out as promises.

    Split the existing pragma item kind into three item kinds, which have
    different invariants applying to them.

    - The decl (short for declarative) pragmas give the compiler some
      information, such as that a predicate is obsolete or that we
      want to type specialize some predicate or function, that is in effect
      part of the module's interface. Decl pragmas may appear in module
      interfaces, and the compiler may put them into interface files;
      neither statement is true of the other two kinds of pragmas.

    - The impl (short for implementation) pragmas are named so
      precisely because they may appear only in implementation sections.
      They give the compiler information that is private to that module.
      Examples include foreign_decls, foreign_codes, foreign_procs,
      and promises of clause equivalence, and requests for inlining,
      tabling etc. These will never be put into interface files,
      though some of them can affect the compilation of other modules
      by being included in .opt files.

    - The gen (short for generated) pragmas can never (legally) appear
      in source files at all. They record the results of compiler
      analyses e.g. about which arguments of a predicate are unused,
      or what exceptions a function can throw, and accordingly they
      should only ever occur in compiler-generated interface files.

    Use the new type differences between the three kinds of pragmas
    to encode the above invariants about which kinds of pragmas can appear
    where into the various kinds of parse trees.

    Make the augmented compilation unit, which is computed from
    the final module_and_imports structure, likewise switch from
    storing item blocks to storing the whole parse trees of the
    files that went into its construction. With each such parse tree,
    record *why* we read it, since this controls what permissions
    the source module being compiled has for access to the entities
    in the parse tree.

    Simplify the contains_foreign_code type, since one of three
    function symbols was equivalent to one possible use of another
    function symbol.

    Provide a way to record which method of which class a compiler-generated
    predicate is for. (See hlds_pred.m below.)

    Move the code of almost all utility operations to item_util.m
    (which is imported by many fewer modules than prog_item.m),
    keeping just the most "popular" ones.

compiler/item_util.m:
    Move most of the previously-existing utility operations here from
    prog_item.m, most in a pretty heavily modified form.

    Add a whole bunch of other utility operations that are needed
    in more than one other module.

compiler/convert_parse_tree.m:
    Provide predicates to convert from raw compilation units to
    parse_tree_module_srcs, and vice versa (though the reverse
    shouldn't be needed much longer).

    Update the conversion operations between the general parse_tree_int
    and the specific parse_tree_intN forms for the changes in prog_item.m
    mentioned above. In doing so, use a consistent approach, based on
    new operations in item_util.m, to detect errors such as duplicate
    include_module and import/use_module declarations in all kinds
    of parse trees.

    Enforce the invariants that the types of parse trees of various kinds
    can now express in types, generating error messages for their violations.

    Delete some utility operations that have been moved to item_util.m
    because now they are also needed by other modules.

compiler/grab_modules.m:
    Delete code that did tests on raw compilation units that are now done
    when that raw compilation unit is converted to a parse_tree_module_src.
    Use the results of the checks done during that conversion to decide
    which modules are imported/used and in which module section.

    Record a single reason for why we reading in each interface and
    optimization file. The code of make_hlds_separate_items.m will use
    this reason to set up the appropriate permissions for each item
    in those files.

    Use separate code for handling different kinds of interface and
    optimization files. Using generic traversal code was acceptable economy
    when we used the same data structure for every kind of interface file,
    but now that we *can* express different invariants for different kinds
    of interface and optimization file, we want to execute not just different
    code for each kind of file, but the data structures we want to work on
    are also of different types. Using file-kind-specific code is a bit
    longer, but it is significantly simpler and more robust, and it is
    *much* easier to read and understand.

    Delete the code that separates the parts of the implementation section
    that are exported to submodules, and the part that isn't, since that task
    is now done in make_hlds_separate_items.m.

    Pass a database of the files we have read through the relevant predicates.

    Give some predicates more meaningful names.

compiler/notes/interface_files.html:
    Note a problem with the current operation of grab_modules.

compiler/get_dependencies.m:
    Add operations to gather implicit references to builtin modules
    (which have to be made available even without an explicit import_module
    or use_module declaration) in all kinds of parse trees. These have
    more code overall, but will be at runtime, since we need only look at
    the item kinds that may *have* such implicit references.

    Add a mechanism to record the result of these gathering operations
    in import_and_or_use_maps.

    Give some types, function symbols, predicates and variables
    more meaningful names.

compiler/make_hlds_separate_items.m:
    When we stored the contents of the source module and the
    interface and optimization files we read in to augment it
    in the module_and_imports structure as a bunch of item blocks,
    the job of this module was to separate out the different kinds of items
    in the item blocks, returning a single list of each kind of item,
    with each such item being packaged up with its status (which encodes
    a set of permissions saying what the source module is allowed
    to do with it).

    Now that the module_and_imports structure stores this info in
    file-kind-specific parse trees, all of which have separate lists
    for each kind of item and none of which contain item blocks,
    the job of this module has changed. Now its job is to convert
    the reason why each file was read in into the (one or more) statuses
    that apply to the different kinds of items stored in it, wrap up
    each item with its status, and return the resulting overall list
    of status/item pairs for each kind of item.

compiler/read_modules.m:
    Add predicates that, when reading an interface file, return its contents
    in the tightest possible file-kind-specific parse tree.

    Refine the database of files we have read to allow us to store
    more file-kind-specific parse trees.

    Don't require that files in the database have associated timestamps,
    since in some cases, we read files we can put into the database
    *without* getting their timestamps.

    Allow the database to record that an attempt to read a file failed.

compiler/split_parse_tree_src.m:
    Rearchitect how this module separates out nested submodules from within
    the main module in a file.

    Another of the jobs of this module is to generate error messages for
    when module A includes module B twice, whether via nesting or via
    include_module declarations, with one special exception for the case
    where A's interface contains nested submodule A.B's interface,
    and A's implementation contains nested submodule A.B's implementation.
    The problem ironically was that while it reported duplicate include_module
    declarations as errors, split_parse_tree_src.m also *generated*
    duplicate include_module declarations. Since it replaced each nested
    submodule occurrence with an include_module declaration, in the scenario
    above, it generated two include_module declarations for A.B. Even worse,
    the interface incarnation of submodule A.B could contain
    (the interface of) its own nested submodule A.B.C, while its
    implementation incarnation could contain (the implementation section of)
    A.B.C. Each occurrence of A.B.C would be its only occurrence in the
    including part of its parent A.B, which means local tests for duplicates
    do not work. (I found this out the hard way.)

    The solution we now adopt adds include_module declarations to the
    parents of any submodule only once the parse tree of the entire
    file has been processed, since only then do we know all the
    includer/included relationships among nested modules. Until then,
    we just record such relationships in a database as we discover them,
    reporting duplicates when needed (e.g. when A includes B twice
    *in the same section*), but not reporting duplicates when not needed
    (e.g. when A.B includes A.B.C in *different* sections).

compiler/prog_data.m:
    Add a new type, pf_sym_name_and_arity, that exactly specifies
    a predicate or function. It is a clone of the existing simple_call_id
    type, but its name does NOT imply that the predicate or function
    is being called.

    Add XXXs that call for some other improvements in type names.

compiler/prog_data_foreign.m:
    Give a type, and the operations on that type, a more specific name.

compiler/error_util.m:
    Add an id field to all error_specs, which by convention should be
    filled in with $pred. Print out the value in this field if the compiler
    is invoked with the developer-only option --print-error-spec-id.
    This allows a person debugging the compiler find out where in the code
    an undesired error message is coming from significantly easier
    than was previously possible.

    Most of the modules that have changes only "to conform to the changes
    above" will be for this change. In many cases, the updated code
    will also simplify the creation of the affected error_specs.

    Fix a bug that looked for a phase in only one kind of error_spec.

    Add some utility operations needed by other parts of this change.

    Delete a previously internal function that has been moved to
    mdbcomp/prim_data.m to make it accessible in other modules as well.

compiler/Mercury.options:
    Ask the compiler to warn about dead predicates in every module
    touched by this change (at least in one its earlier versions).

compiler/add_foreign_enum.m:
    Replace a check for an inappropriately placed foreign_enum declaration
    with a sanity check, since with this diff, the error should be caught
    earlier.

compiler/add_mutable_aux_preds.m:
    Delete a check for an inappropriately placed mutable declaration,
    since with this diff, the error should be caught earlier.

compiler/add_pragma.m:
    Instead of adding pass2 and pass3 pragmas, add decl and impl and
    generated pragmas.

    Delete the tests for generated pragma occurring anywhere except
    .opt files, since those tests are now done earlier.

    Shorten some too-long predicate names.

compiler/comp_unit_interface.m:
    Operate on as specific kinds of parse trees as the interface of this
    module will allow. (We could operate on more specific parse trees
    if we changed the interface, but that is future work).

    Use the same predicates for handling duplicate include_module,
    import_module and use_module declarations as everywhere else.

    Delete the code of an experiment that shouldn't be needed anymore.

compiler/equiv_type.m:
    Replace code that operated on item blocks with code that operates
    on various kinds of parse trees.

    Move a giant block of comments to the front, where it belongs.

compiler/hlds_module.m:
    Add a field to the module_info that lets us avoid generating
    misleading error messages above missing definitions of predicates
    or functions when those definitions were present but were not
    added to the HLDS because they had errors.

    Give a field and its access predicates a more specific name.

    Mark a spot where an existing type cannot express everything
    it is supposed to.

compiler/hlds_pred.m:
    For predicates which the compiler creates to represent a class method
    (the virtual function, in OOP terms), record not just this fact,
    but the id of the class and of the method. Using this extra info
    in progress messages (with mmc -V) prevents the compiler from printing e.g.

        % Checking typeclass constraints on class method
        % Checking typeclass constraints on class method
        % Checking typeclass constraints on class method

    when checking three such predicates.

compiler/make.m:
    Provide a slot in the make_info structure to allow the database
    of the files we have read in to be passed around.

compiler/make_hlds_error.m:
    Delete predicates that are needed in just one other module,
    and have therefore been moved there.

compiler/make_hlds_passes.m:
    Add decl, impl and generated pragma separately, instead of adding
    pass2 and pass3 pragmas separately.

    Do not generate error messages for clauses, initialises or finalises
    in module interfaces, since with this diff, such errors should be
    caught earlier.

compiler/mercury_compile_main.m:
compiler/recompilation.check.m:
    Explicitly pass around the expanded database of parse trees
    of files that have been read in.

compiler/module_qual.collect_mq_info.m:
compiler/module_qual.m:
compiler/module_qual.qualify_items.m:
    Collect module qualification information, and do module qualification
    respectively on parse trees of various kinds, not item blocks.
    Take information about what the module may do with the contents
    of each interface or optimization file from the record of why
    we read that file, not from the section markers in item blocks.

    Break up some too-large predicates by carving smaller ones out of them.

compiler/options.m:
    Add an option to control whether errors and/or warnings detecting
    when deciding what should go into a .intN file be printed,
    thus (potentially) preventing the creation of that file.

    Add commented-out documentation for a previously totally undocumented
    option.

doc/user_guide.texi:
    Document the new option.

NEWS:
    Announce the new option.

    Mention that we now generate warnings for unused import_module and
    use_module declarations in the interface even if the module has
    submodules.

compiler/write_module_interface_files.m:
    Let the new option control whether we filter out any messages generated
    when deciding what should go into a .intN file.

compiler/parse_item.m:
    Delete actually_read_module_opt, since it is no longer needed;
    its callers now call actually_read_module_{plain,trans}_opt instead.

    Delete unneeded arguments from some predicates.

compiler/parse_module.m:
    Delete some long unused predicates.

compiler/parse_pragma.m:
    When parsing pragmas, wrap them up in the new decl, impl or generated
    pragma kinds.

compiler/parse_tree_out.m:
    Add predicates to write out each of the file-kind-specific parse trees.

compiler/parse_tree_out_pragma.m:
    Add predicates to write out decl, impl and generated pragmas.

compiler/polymorphism.m:
    Add a conditionally-enabled progress message, which can be useful
    in tracking down problems.

compiler/prog_item_stats.m:
    Conform NOT to the changes above beyond what is needed to let this module
    compile. Let that work be done the next time the functionality of
    this module is needed, by which time the affected data structures
    maybe have changed further.

compiler/typecheck.m:
    Fix a performance problem. With intermodule optimization, we read in
    .opt files, some of which (e.g. list.opt and int.opt) contain promises.
    These promises are read in as predicates with goal_type_promise,
    but they do not have declarations of the types of their arguments
    (since promises do not have declarations as such). Those argument types
    therefore have to be inferred. That inference replaces the original
    "I don't know" argument types with their actual types.

    The performance problem is that when we change the recorded argument types
    of a predicate, we require another loop over all the predicates in the
    module, so that any calls to this predicate can be checked against
    the updated types. This is as it should be for callable predicates,
    but promises are not callable. So if all the *only* predicates whose
    recorded argument types change during the first iteration to fixpoint
    are promises, then a second iteration is not needed, yet we used to do it.

    The fix is to replace the "Have the recorded types of this predicate
    changed?" boolean flag with a bespoke enum that says "Did the checking
    of this predicate discover a need for another iteration", and not
    setting it when processing predicates whose type is goal_type_promise.

compiler/typecheck_errors.m:
    Do not generate an error message for a predicate missing its clauses
    is the clauses existed but were not added to the HLDS because they were
    in the interface section.

    When reporting on ambiguities (when a call can match more than one
    predicate or function), sort the possible matches before reporting
    them.

compiler/accumulator.m:
compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_mode.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/canonicalize_interface.m:
compiler/check_for_missing_type_defns.m:
compiler/check_parse_tree_type_defns.m:
compiler/check_promise.m:
compiler/check_raw_comp_unit.m:
compiler/check_typeclass.m:
compiler/common.m:
compiler/compile_target_code.m:
compiler/compiler_util.m:
compiler/dead_proc_elim.m:
compiler/deps_map.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/du_type_layout.m:
compiler/field_access.m:
compiler/find_module.m:
compiler/float_regs.m:
compiler/format_call.m:
compiler/goal_expr_to_goal.m:
compiler/handle_options.m:
compiler/hlds_out_module.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/inst_check.m:
compiler/intermod.m:
compiler/introduce_parallelism.m:
compiler/layout_out.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make_hlds_warn.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile_llds_back_end.m:
compiler/ml_top_gen.m:
compiler/mmakefiles.m:
compiler/mode_errors.m:
compiler/mode_robdd.equiv_vars.m:
compiler/modes.m:
compiler/module_qual.qual_errors.m:
compiler/oisu_check.m:
compiler/old_type_constraints.m:
compiler/options_file.m:
compiler/parse_class.m:
compiler/parse_dcg_goal.m:
compiler/parse_goal.m:
compiler/parse_inst_mode_defn.m:
compiler/parse_inst_mode_name.m:
compiler/parse_mutable.m:
compiler/parse_sym_name.m:
compiler/parse_type_defn.m:
compiler/parse_type_name.m:
compiler/parse_type_repn.m:
compiler/parse_types.m:
compiler/parse_util.m:
compiler/parse_vars.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/prog_event.m:
compiler/prog_mode.m:
compiler/purity.m:
compiler/qual_info.m:
compiler/recompilation.version.m:
compiler/resolve_unify_functor.m:
compiler/simplify_goal.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_ite.m:
compiler/simplify_proc.m:
compiler/state_var.m:
compiler/stratify.m:
compiler/style_checks.m:
compiler/superhomogeneous.m:
compiler/table_gen.m:
compiler/term_constr_errors.m:
compiler/term_errors.m:
compiler/termination.m:
compiler/trace_params.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/write_deps_file.m:
compiler/xml_documentation.m:
    Conform to the changes above.

mdbcomp/prim_data.m:
    Move a utility function on pred_or_funcs here from a compiler module,
    to make it available to other compiler modules as well.

scripts/compare_s1s2_lib:
    A new script that helped debug this diff, and may help debug
    similar diffs the future. It can compare (a) .int* files, (b) .*opt
    files, (c) .mh/.mih files or (d) .c files between the stage 1 and
    stage 2 library directories. The reason for the restriction
    to the library directory is that any problems affecting the
    generation of any of these kinds of files are likely to manifest
    themselves in the library directory, and if they do, the bootcheck
    won't go on to compile any of the other stage 2 directories.

tests/debugger/breakpoints.a.m:
tests/debugger/breakpoints.b.m:
    Move import_module declarations to the implementation section
    when they are not used in the interface. Until now, the compiler
    has ignored this, but this diff causes the compiler to generate
    a warning for such misplaced import_module declarations even modules
    that have submodules. The testing of such warnings is not the point
    of the breakpoints test.

tests/invalid/Mercury.options:
    Since the missing_interface_import test case tests error messages
    generated during an invocation of mmc --make-interface, add the
    new option that *allows* that invocation to generate error messages.

tests/invalid/ambiguous_overloading_error.err_exp:
tests/invalid/max_error_line_width.err_exp:
tests/warnings/ambiguous_overloading.exp:
    Expect the updated error messages for ambiguity, in which
    the possible matches are sorted.

tests/invalid/bad_finalise_decl.m:
tests/invalid/bad_initialise_decl.m:
    Fix programming style.

tests/invalid/bad_item_in_interface.err_exp:
    Expect an error message for a foreign_export_enum item in the interface,
    where it should not be.

tests/invalid/errors.err_exp:
    Expect the expanded wording of a warning message.

tests/invalid/foreign_enum_invalid.err_exp:
    Expect a different wording for an error message. It is more "standard"
    but slightly less informative.

tests/invalid_submodules/children2.m:
    Move a badly placed import_module declaration, to avoid having
    the message the compiler now generates for it from affecting the test.

tests/submodules/parent2.m:
    Move a badly placed import_module declaration, to avoid having
    the message the compiler now generates for it from affecting the test.

    Update programming style.
2020-03-13 12:58:33 +11:00
Zoltan Somogyi
fbcd431d36 Decide simple representations using checked type definitions.
compiler/check_parse_tree_type_defns.m:
    Change the definition of a checked type to distinguish direct_dummy
    and enum types on the one hand, which may have foreign enum definitions,
    from other du types, which may not.

    Change the definition of a checked type to record the names of the
    function symbols in direct_dummy and enum types, since type representation
    items need this information, we have it, and requiring decide_type_repn.m
    to compute it again from scratch is wasteful.

    Do not explicitly record the number of function symbols in direct_dummy
    % and enum types, and the number bits needed to represent values of
    such types. We now store the list of function symbols in such types,
    and this information is trivially computable from that.

    Check foreign enum definitions for correctness. At the moment,
    this sort-of duplicates related functionality in add_foreign_enum.m,
    but the intention is that eventually, these checks will be done only here,
    with the sort-of duplicated code in add_foreign_enum.m being deleted there.

compiler/prog_item.m:
    Change the data structures we use to record type representation information
    in items to encode all the invariants that the updated checked type
    definition map encodes. This should allow code that reads such items
    from interface files to avoid having to check for violations of those
    invariants.

    Document the relationship between checked type definitions and
    type representation items, including why neither can subsume the other.

compiler/decide_type_repn.m:
    Rewrite this module almost completely. The old version gathered up
    all the type and enum definitions for each type constructor, and then
    did a limited, purpose-specific job of checking their consistency,
    before using the information in them to decide on the representations
    of simple types. The new version takes a checked type definition map
    as input, and so its task is limited to deciding type representations.

    The switch has two main benefits.

    - The consistency checks we now do in check_parse_tree_type_defns.m
      can replace not just the consistency checks we used to do in
      decide_type_repn.m, but in the future, it can also replace
      the consistency checks we now do in add_type.m and add_foreign_enum.m.
      Having a *consistent* set of consistency checks is a good idea,
      even though it is a bit too meta :-)

    - The consistency checks in check_parse_tree_type_defns.m
      are significantly more thorough than both the ones in the version
      of decide_type_repn.m, and the current version distributed through
      add_type.m and add_foreign_enum.m.

    The changes in check_parse_tree_type_defns.m and prog_item.m to bring
    the two representations as close together as possible should significantly
    simplify the code we will need to add to decide_type_repn.m to decide
    the representations of complex types.

compiler/comp_unit_interface.m:
    Pass the checked type definition map to decide_type_repn.m.

compiler/parse_type_repn.m:
    Parse the updated type representations.

compiler/parse_tree_out.m:
    Output the updated type representations.

compiler/du_type_layout.m:
compiler/prog_data.m:
    Move a predicate from du_type_layout.m to prog_data.m (split into
    two predicates), since decide_type_repn.m now wants access to its
    functionality as well.

compiler/prog_type.m:
    Export a utility predicate.

compiler/add_foreign_enum.m:
    Export some functionality to check_parse_tree_type_defns.m.
    That functionality should in fact be moved to check_parse_tree_type_defns,
    but that would make this diff harder to review, so that will be done later
    in a separate commit.

compiler/equiv_type.m:
compiler/module_qual.qualify_items.m:
    Conform to the changes above.

compiler/Mercury.options:
    Specify --warn-dead-preds for the modules touched by this change.
    Since several of them had large parts replaced by new code, this was
    needed to catch left-over parts of their old and now obsolete contents.
2019-10-26 19:30:07 +11:00
Zoltan Somogyi
19ef98b66f Check the type definitions in a module for consistency ...
... when generating interface files.

compiler/check_parse_tree_type_defns.m:
    A new module for doing the checking.

compiler/parse_tree.m:
    Add the new module.

compiler/comp_unit_interface.m:
    When computing what should go into a .intN file, use the new module
    to check for inconsistencies in the source code of the module.

    Making the above possible requires retaining some information
    (such as contexts in foreign enum definitions, and the presence
    of definitions, as opposed to declarations, for some types)
    for longer than was needed until now.

    Give some predicates more descriptive names.

    Move the record_foreign_enum_spec predicate near where it is used.

compiler/write_module_interface_files.m:
    If comp_unit_interface.m reports any errors when generating the
    would-be contents of an interface file, do NOT create that
    interface file.

    The errors comp_unit_interface.m and check_parse_tree_type_defns.m
    now generate are the kinds of inconsistencies whose resolution requires
    everything depending on this module to be recompiled anyway,
    so stopping the compilation process *without* producing
    the would-be-erroneous interface file should be a net win
    almost all the time.

compiler/prog_item.m:
    Factor out some commonalities in data structures.

    When converting the generic parse_tree_int we get from reading
    in a .intN file to the parse tree type specific to that N,
    check the definitions we read in for consistency.

    As in comp_unit_interface, making the above possible requires
    retaining some information for longer than was needed until now.

    Never output two or more declarations of the same type_ctor
    in the same section of an interface file, since the code
    *reading* interface files now reports such redundancies
    (but see the change to options.m).

compiler/options.m:
    Disable the printing of error messages for problems found in
    interface files, since the new code in check_parse_tree_type_defns.m
    now finds problems in interface files generated by currently
    installed compilers. Specifically, many contain duplicate
    declarations for Mercury types. One declaration is written
    by the programmer, the other is the type's actual definition
    turned into the redundant declaration by the compiler.

compiler/parse_pragma.m:
    When parsing foreign enum pragmas, implicitly qualify the
    name of the type constructor they are for with the current module name.
    This is semantically sound, since foreign_enum pragmas *must* be
    for a type constructor defined in the same module. It is desirable
    because type_ctors in type definitions are module qualified.
    The code of check_parse_tree_type_defns.m needs to process
    the type definitions and foreign enums for a type_ctor at the
    same time, and doing so would be more needlessly complicated
    if the type ctor keys in the "type_ctor to type definitions"
    and "type_ctor to foreign enums" maps were incompatible due to
    the difference in qualification.

    The type_ctor in a foreign enum definition may still be manually
    module qualified by programmers; it just happens that any qualification
    other than the default is a semantic error.

compiler/module_qual.qual_errors.m:
    When printing error messages about undefined type_ctors in
    foreign enum definitions, do not print this implicitly
    added qualification, since it adds only clutter.

compiler/error_util.m:
    Provide a mechanism for printing type_ctors directly,
    i.e. without converting them to a sym_name/arity pair.

    Put a qual_ prefix in front of top_ctor_of_type, since it
    always prints module qualification. (This is to remind people
    who may use this component about that qualification.)

    Factor out some common code.

compiler/det_analysis.m:
    Conform to the change in error_util.m.

compiler/parse_module.m:
    Fix too-long lines.

compiler/Mercury.options:
    Require some of the modules above to have no dead predicates.

library/erlang_rtti_implementation.m:
library/io.m:
    Delete declarations of types that are unneeded because the types
    also have definitions.

tests/typeclasses/unqualified_method2.m:
    Move an import out of the interface, since we now print the warning
    generated for its improper location.
2019-09-28 02:57:00 +10:00
Zoltan Somogyi
d9dbc33243 Put instmap.m's contents into a logical order. 2019-09-02 11:44:06 +10:00
Zoltan Somogyi
b6d4d3f30d Fix more issues reported by --warn-inconsistent-pred-order-clauses. 2019-08-24 07:53:41 +10:00
Zoltan Somogyi
ce65f6b2aa Fix more issues reported by --warn-inconsistent-pred-order-clauses.
compiler/assertion.m:
compiler/clause_to_proc.m:
compiler/compute_grade.m:
compiler/const_struct.m:
compiler/export.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_mode.m:
compiler/hlds_promise.m:
compiler/lambda.m:
compiler/lp_rational.m:
compiler/make_goal.m:
compiler/mercury_compile_llds_back_end.m:
compiler/ml_type_gen.m:
compiler/name_mangle.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_out_pragma.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/passes_aux.m:
compiler/polyhedron.m:
compiler/pred_table.m:
compiler/process_util.m:
compiler/prog_data.m:
compiler/prog_data_foreign.m:
compiler/prog_mutable.m:
compiler/rat.m:
compiler/recompilation.m:
compiler/source_file_map.m:
compiler/timestamp.m:
compiler/trace_params.m:
compiler/write_deps_file.m:
    As above.

compiler/Mercury.options:
    Don't pass --no-warn-inconsistent-pred-order-clauses for the above modules.
2019-08-23 20:54:27 +10:00
Zoltan Somogyi
4ef4402ecf Make --warn-inconsistent-pred-order-clauses default for the compiler.
compiler/COMP_FLAGS.in:
    As above.

compiler/Mercury.options:
    List the modules for we need --no-warn-inconsistent-pred-order-clauses
    for now.

compiler/call_gen.m:
compiler/code_util.m:
compiler/deep_profiling.m:
compiler/equiv_type.m:
compiler/error_util.m:
compiler/exprn_aux.m:
compiler/get_dependencies.m:
compiler/global_data.m:
compiler/layout_out.m:
compiler/liveness.m:
compiler/ll_pseudo_type_info.m:
compiler/llds.m:
compiler/llds_out_code_addr.m:
compiler/llds_out_data.m:
compiler/module_cmds.m:
compiler/module_qual.m:
compiler/module_qual.qualify_items.m:
compiler/opt_debug.m:
compiler/parse_class.m:
compiler/parse_goal.m:
compiler/parse_sym_name.m:
compiler/parse_type_defn.m:
compiler/rtti_out.m:
compiler/stack_layout.m:
compiler/trace_gen.m:
    Fix issues reported by --warn-inconsistent-pred-order-clauses
    for these modules.
2019-08-23 18:36:18 +10:00
Zoltan Somogyi
165f9e363c Improve typecheck_info.m.
compiler/typecheck_info.m:
    Give some predicates more meaningful names.

    Make the orders of predicate definitions and predicate declarations
    match each other.

compiler/typecheck.m:
    Conform to the change in typecheck_info.m.

compiler/Mercury.options:
    Turn on --warn-inconsistent-pred-order-clauses for the typechecking
    modules.
2019-07-07 19:36:58 +02:00