Commit Graph

145 Commits

Author SHA1 Message Date
Zoltan Somogyi
083d376e65 Eliminate some redundant target->filename conversions.
compiler/make.util.m:
    Many operations in this module that operate on filenames did not take
    those filenames as arguments; instead, they took an argument such as
    a target_file from which they *computed* the filename. This meant that
    any predicate that called more than one of these operations implicitly
    computed the filename more than once. This could be a problem, because

    - there are several predicates one can use to compute the filename, but
    - there is no guarantee that different operations use the same predicate.

    As a first step in fixing this, change the predicates that print
    filenames in progress or error messages to take those filenames
    as parameters. Delete one of them, target_file_error, because
    after this change, it would have become identical to the existing
    file_error predicate.

compiler/make.module_target.m:
    Require the callers of record_made_target to supply the filename
    as well as the target_file from which it is derived.

compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
    Compute the filename before calling the updated operations in make.util.m
    and/or make.module_target.m.

    Add "XXX MAKE_STREAM" to places in the code that operate on either
    implicit or badly-chosed explicit streams.
2023-06-01 18:17:40 +02:00
Zoltan Somogyi
96702be577 Make make_module_target_main_path truly the main path.
compiler/make.module_target.m:
    Inline the (badly named) make_module_target_file_extra_options predicate
    at its only call site in make_module_target. Factor out the commonalities
    between the dep_file and dep_target parts of make_module_target, which
    (after the above inlining) jump out at you.

    make_module_target_main_path used to handle the main path *and* one
    special case. Move the code to test for, and handle, that special case
    to make_module_target. Since the code handling the special case
    involves calling make_module_target with modified arguments, this move
    also replaces mutual recursion (which originally involved three predicates)
    with self-recursion.
2023-05-31 13:22:33 +02:00
Zoltan Somogyi
9adcbd9840 Improve infrastructure for file name translations.
compiler/file_names.m:
    Document the meaning of the maybe_create_dirs and maybe_search types.

    Delete long-obsolete references to .il files.

compiler/make.util.m:
    Rename make_remove_target_file to remove_make_target_file, since this
    predicate removes target files in Makefiles, and does not "make" anything.
    Rename several other predicates in a similar manner, for the same reason.

    Add an extra argument to get_file_name and some related predicates
    that will allow future conditionally-enabled trace goals in the compiler
    to track where the requests for file name translations come from.

compiler/write_deps_file.m:
    Factor out some code.

compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Conform to the changes above.

tools/file_name_translation_stats:
    Allow for large numbers of file name translations.
2023-05-31 10:14:31 +02:00
Zoltan Somogyi
726db67aa6 Turn semidet functions into predicates.
compiler/prog_foreign.m:
    foreign_language_module_name and foreign_language_file_extension
    were both functions with two modes, one of which was semidet.
    Since semidet functions violate the law of least astonishment,
    turn both into predicates.

    Change the semidet mode into det (this has been possible ever since
    we deleted the Erlang backend). Then comment out the other mode,
    since it has no use left.

compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
    Update the calls to the affected functions (now predicates).
2023-05-23 06:42:47 +10:00
Zoltan Somogyi
12b49bacae Delete several make_write_X predicates ...
compiler/make.util.m:
    ... after inlining some of their at their only call sites.
    The rest were unused.

    The inlining should (eventually) help the call sites to avoid
    redundant conversions from make's representation of target files
    to their actual filesystem names. Eventually, because at the moment,
    the other conversions are hidden somewhere in their call trees.

    Keep one make_write_X predicate after renaming it to write_make_X.

    Add XXXs about possible bugs.

compiler/make.dependencies.m:
    Replace a higher order arg that wrote out a filename with one
    that just returns that filename.

    Improve some debugging output slightly.

compiler/make.module_target.m:
    Inline the former make_write_X predicates.

    Add XXXs about possible bugs.

compiler/make.program_target.m:
    Conform to the change in make.dependencies.m.
2023-05-23 06:10:01 +10:00
Zoltan Somogyi
6bdd8b84ee Move maybe_changed to maybe_succeeded.m and rename it.
compiler/maybe_util.m:
    Move the maybe_changed type from several modules of the compiler
    to maybe_succeeded.m, and rename it to maybe_util.m.

compiler/libs.m:
compiler/notes/compiler_design.html:
    Implement and document the rename.

compiler/common.m:
compiler/compile_target_code.m:
compiler/decide_type_repn.m:
compiler/det_analysis.m:
compiler/det_util.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/file_util.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.top_level.m:
compiler/make.track_flags.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_c_type.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/module_cmds.m:
compiler/parse_tree_out.m:
compiler/process_util.m:
compiler/recompilation.version.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.
2023-04-21 17:24:30 +10:00
Zoltan Somogyi
8c98840193 Define a predicate to compute modules' dependencies.
compiler/make.dependencies.m:
    Create find_target_dependencies_of_modules, a version of the
    deps_set_foldl3_maybe_stop_at_error_find_union_fi predicate
    that is specialized to the call site make.module_target.m
    that passes make.dependencies.m's target_depencies function
    as its FindDeps argument.

    Make some exported types/insts private, now that this is possible.

    Eliminate an unnecessary recursive call. Put the different target types
    into an approximately ascending order of complexity.

compiler/make.module_target.m:
    Call the new specialized predicate.

    Make some code more readable.
2022-12-09 19:19:37 +11:00
Peter Wang
c5a776ab83 Use version_hash_table for target_file timestamps cache.
This change improves the run time of a do-nothing build of Prince using
mmc --make on my machine from 1.46 s to 1.19 s.

compiler/make.make_info.m:
    Use version_hash_table for the target_file timestamps cache
    instead of a tree234 map.

compiler/make.util.m:
    Add function to initialised a target_file_timestamps.

    Conform to change in type.

compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.top_level.m:
    Conform to change in type.

    Add a comment about a possible change.
2022-12-05 17:26:51 +11:00
Peter Wang
ef009a96de Clarify what forkable_module_compilation_task_type means.
library/make.module_target.m:
    Rename forkable_module_compilation_task_type to
    do_task_in_separate_process.

    Add some comments.
2022-12-05 11:50:41 +11:00
Zoltan Somogyi
59681717c2 Specialize more fold predicates.
compiler/make.dependencies.m:
    Specialize the remaining uses of deps_set_foldl3_maybe_stop_at_error_mi,
    and then delete it. Also delete the type and inst that also it used.

    Delete all the *foldl3* predicates whose only task was to call the
    corresponding loop predicate, after inlining them at all their call sites.
    Then transfer their names to their loop predicates.

    Stop exporting the *foldl* predicates that are not used outside this
    module.

    Give a predicate a more expressive name.

compiler/make.module_target.m:
    Conform to the changes above.
2022-12-01 22:03:16 +11:00
Zoltan Somogyi
789bbf0612 Inline all (higher-order) calls to union_deps.
compiler/make.dependencies.m:
    Most calls to deps_set_foldl3_maybe_stop_at_error_{mi,fi} call them
    with closures that package up the union_deps predicate or its
    union_deps_plain_set. Create new versions of these predicates that
    in effect

    - replace the higher order call to the closure argument with a first order
      call to union_deps or union_deps_plain_set, and then
    - inline the call.

    This reduces the height of the higher-order upon higher-order stack by one.

    It also deletes the last remaining calls to union_deps and to
    union_deps_plain_set, so this diff deletes them.

    The new versions completely replace all uses of
    deps_set_foldl3_maybe_stop_at_error_mi, so delete that predicate.

    Move two local types to the top of the implementation section.
    Before this diff, they were defined *after* their first use.

    Note the need for documentation.

compiler/make.module_target.m:
    Eliminate a reference to union_deps here as well.
2022-12-01 20:52:55 +11:00
Zoltan Somogyi
4a8058059e Specialize some folds for their operations.
compiler/make.build.m:
    Replace foldl2_maybe_stop_at_error_{df,str,tt} with
    foldl2_make_module_targets, foldl2_install_library_grades and
    foldl2_make_top_targets respectively. Each of the new predicates
    now knows

    - the operation being folded over the given list,
    - the type of the elements in the list it folds over,
    - the types of the two accumulators,

    The first is also expressed in the new predicate name, while the
    second and third of these are expressed in its type signature.

    Another change in each signature is the replacement of the higher order
    argument specifying the operation with the its optional arguments, if any.

    The loop predicates that do the work in each case are unchanged,
    at least for now.

    Replace foldl2_maybe_stop_at_error_maybe_parallel_df with
    foldl_make_module_targets_maybe_parallel, making the same changes as above.

    Delete foldl2_maybe_stop_at_error_{mi,fi} and
    foldl2_maybe_stop_at_error_maybe_parallel_mi, since they turned out
    to be unused. (Their foldl3 versions do look to be needed.)

compiler/make.dependencies.m:
    Conform to the changes above.

    Give some predicates more expressive names.

compiler/make.module_target.m:
    Replace two predicates make_module_target and
    make_module_target_extra_options, with only the latter taking
    a list of extra options, with just one predicate,
    named make_module_target but taking a list of extra options.
    This allows foldl2_make_module_targets to work the same whether or not
    the list of extra options is empty.

    Conform to the changes above.

compiler/make.program_target.m:
    Conform to the changes above, including by exporting the predicate
    install_library_grade predicate for foldl2_install_library_grades.

compiler/make.top_level.m:
    Conform to the changes above, including by exporting the predicate
    make_target predicate for foldl2_make_top_targets. Rename this
    predicate to make_top_target to help differentiate it from
    make_module_target.
2022-12-01 14:06:24 +11:00
Zoltan Somogyi
e46a560c91 Monomorphize some polymorphic predicates.
compiler/make.build.m:
    Replace three polymorphic predicates that fold over lists of values
    of type T with two, three and five monomorphic predicates respectively.
    The monomorphic versions fold over lists of elements of specified types.
    The list of monomorphic versions needed should be useful information for
    simplifying the make package's overuse of higher order constructs.

    The replaced predicates were mostly just interfaces to the predicates
    that looped over the lists. This diff leaves those predicates alone.

compiler/make.dependencies.m:
    Make the same change to deps_set_foldl3_maybe_stop_at_error and to
    map_find_module_deps (only the first of which does a fold).
    For map_find_module_deps, also change the argument order, because
    operating on the second argument first, and on the first argument second,
    is confusing.

compiler/make.make_info.m:
    Replace a pair type, which some of the above fold operated over,
    with a bespoke type, because its structure and semantics was related
    to existing bespoke types.

compiler/make.program_target.m:
    Conform to the changes above. In two cases, replaces nested folds
    with sequences of folds, both because this is simpler, and because
    it avoids the need for an extra variant of the fold.

compiler/make.module_target.m:
compiler/make.top_level.m:
compiler/make.track_flags.m:
compiler/make.util.m:
    Conform to the changes above.
2022-12-01 07:08:38 +11:00
Peter Wang
4d4ef3e3ab Cache timestamps by target file.
Previously, to look up the timestamp for a target_file we would first
compute a file name for that target_file, then look up the timestamp by
file name. This occurs frequently, so even though the computed file name
was cached, eliminating one of the two steps can be worthwhile.

This change therefore introduces a cache of timestamps indexed by
target_file, in addition to the existing cache of timestamps indexed
by file name.

Cache invalidation can be complicated because when a file is updated,
it is not straightforward to which target_file(s) may be affected.
Invalidating the entire cache is viable as it happens relatively
infrequently, and the cache will be quickly repopulated anyway.

This change improves the run time of a do-nothing build of Prince
on my machine from 1.7 s to 1.6 s.

compiler/make.make_info.m:
compiler/make.top_level.m:
    Add a field to make_info to hold a cache of timestamps indexed by
    target_file.

    Delete the mki_search_file_name_cache field.

compiler/make.util.m:
    Cache timestamps by target_file in get_target_timestamp.

    Avoid computing file names until required.

    Don't cache computed file names in get_file_name.
    get_file_name is now called much less frequently, so caching the
    result should not be necessary (but can be reintroduced if some
    other code path requires it).

    Clear out timestamps for target_files when a file is deleted.

compiler/make.module_target.m:
    Delete old timestamp for a target_file when the target is made.

compiler/make.program_target.m:
    Clear out timestamps for target_files when Java class files are
    made.
2022-11-30 14:45:43 +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
Julien Fischer
cedbee7190 Move quote_arg/1 out of options.m.
Move the function quote_arg/1, which is used to quote arguments to shell
commands, out of options.m and into its own module. It is called from
several other places other than options.m and its implementation details
have nothing to do with the other contents of options.m.

Rename the function to quote_shell_cmd_arg/1.

compiler/shell_util.m:
    New module for quote_arg/1 and its supporting predicates.

compiler/libs.m:
    Include the new module.

compiler/options.m:
compiler/compile_target_code.m:
compiler/file_util.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Import the new module where necessary.

compiler/notes/compiler_design.m:
    Update this document.
2022-07-25 23:43:25 +10:00
Zoltan Somogyi
ea4f95a7ed Use var_tables in lco.m, and when dumping goals.
Since this is the first converted module that dumps out goals when
debugging trace flags are enabled, this required generalizing the code
that does that, to take either varsets or var_tables as a means of
specifying the names of variables. We do this via a new type,
var_name_source, which contains either a varset or a var_table.

Almost all of this diff is there to implement this generalization.
A large part of it affects code in the parse_tree package that we use
to write out the parts of HLDS goals that are defined by types defined
in that package. Since we want to avoid making any part of the parse_tree
package dependent on the hlds package, this required defining the
var_name_source type in the parse_tree package, which in turn requires
var_table.m to be in that same package.

compiler/lco.m:
    Convert this module to use var_tables instead of varsets and vartypes.

compiler/var_table.m:
    Move this module from the hlds package to the parse_tree package.

    To make this, possible, move the parts that required access to the HLDS
    to hlds_pred.m, from where it was usually invoked.

    Export some utility predicates to allow the moved code to work
    in hlds_pred.m without access to the actual definition of the
    var_table type.

    Define the var_name_source type.

    Add some utility functions for use by code writing out variable names.

compiler/hlds_pred.m:
    Add the code moved from var_table.m.

compiler/vartypes.m:
    Move this module from the hlds package to the parse_tree package,
    for symmetry with var_table.m. It did not depend on being in hlds
    in any way.

compiler/hlds.m:
compiler/parse_tree.m:
    Move vartypes.m and var_table.m from the hlds package
    to the parse_tree package.

compiler/hlds_out_goal.m:
    Change all the predicates in this module to take a var_name_source
    instead of a prog_varset.

    Fix some comments.

compiler/hlds_out_util.m:
    Change some of the predicates in this module (those called from
    hlds_out_goal.m) to take a var_name_source instead of a prog_varset.

compiler/parse_tree_out_term.m:
    Provide variants of some existing predicates and functions that take
    var_name_sources instead of varsets. The code of the copies
    duplicates the logic of the originals, though I hope that this
    duplication can be done away with at the end of the transition.
    (The best solution would be to use a typeclass with methods
    that convert vars to their names, but we would want to ensure
    that the compiler can specialize all the affected predicates
    and functions to the two instances of this typeclass, which is
    something that we cannot do yet. In the meantime, the lack of
    any generalization in the old versions preserves their performance.)

tools/sort_imports:
tools/filter_sort_imports:
    A new tool that automatically sorts any occurrences of consecutive
    ":- import_module" declarations in the named files. The sorting is done
    in filter_sort_imports; sort_imports loops over the named files.

    After automatically replacing all occurrences of hlds.{vartypes,var_table}
    in import_module declarations with their parse_tree versions, the updated
    import_module declarations were usually out of order with respect to
    their neighbours. I used this script to fix that, and some earlier
    out-of-order imports.

compiler/accumulator.m:
compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_heap_ops.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_trail_ops.m:
compiler/analysis.m:
compiler/arg_info.m:
compiler/build_mode_constraints.m:
compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/check_promise.m:
compiler/closure_analysis.m:
compiler/closure_gen.m:
compiler/code_info.m:
compiler/code_loc_dep.m:
compiler/common.m:
compiler/compile_target_code.m:
compiler/complexity.m:
compiler/const_prop.m:
compiler/constraint.m:
compiler/continuation_info.m:
compiler/convert_parse_tree.m:
compiler/coverage_profiling.m:
compiler/cse_detection.m:
compiler/ctgc.datastruct.m:
compiler/ctgc.util.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/direct_arg_in_out.m:
compiler/disj_gen.m:
compiler/distance_granularity.m:
compiler/equiv_type_hlds.m:
compiler/exception_analysis.m:
compiler/file_names.m:
compiler/float_regs.m:
compiler/follow_vars.m:
compiler/format_call.m:
compiler/generate_dep_d_files.m:
compiler/get_dependencies.m:
compiler/goal_expr_to_goal.m:
compiler/goal_mode.m:
compiler/goal_path.m:
compiler/goal_store.m:
compiler/goal_util.m:
compiler/granularity.m:
compiler/hhf.m:
compiler/higher_order.m:
compiler/hlds_clauses.m:
compiler/hlds_code_util.m:
compiler/hlds_error_util.m:
compiler/hlds_goal.m:
compiler/hlds_llds.m:
compiler/hlds_out_pred.m:
compiler/hlds_rtti.m:
compiler/hlds_statistics.m:
compiler/inlining.m:
compiler/inst_check.m:
compiler/inst_test.m:
compiler/inst_user.m:
compiler/instance_method_clauses.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/intermod_analysis.m:
compiler/interval.m:
compiler/introduce_exists_casts.m:
compiler/introduce_parallelism.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/llds.m:
compiler/llds_out_data.m:
compiler/llds_out_file.m:
compiler/llds_out_util.m:
compiler/lookup_switch.m:
compiler/loop_inv.m:
compiler/make.module_target.m:
compiler/make.util.m:
compiler/make_goal.m:
compiler/make_hlds_separate_items.m:
compiler/make_hlds_types.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/middle_rec.m:
compiler/ml_accurate_gc.m:
compiler/ml_args_util.m:
compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_commit_gen.m:
compiler/ml_disj_gen.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_gen_info.m:
compiler/ml_lookup_switch.m:
compiler/ml_proc_gen.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/ml_unify_gen.m:
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_test.m:
compiler/ml_unify_gen_util.m:
compiler/mlds_to_c_data.m:
compiler/mlds_to_c_func.m:
compiler/mlds_to_c_global.m:
compiler/mlds_to_cs_class.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_data.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_stmt.m:
compiler/mlds_to_java_type.m:
compiler/mmc_analysis.m:
compiler/mode_comparison.m:
compiler/mode_constraints.m:
compiler/mode_debug.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/mode_ordering.m:
compiler/modecheck_call.m:
compiler/modecheck_coerce.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/module_cmds.m:
compiler/old_type_constraints.m:
compiler/opt_debug.m:
compiler/optimize.m:
compiler/options_file.m:
compiler/ordering_mode_constraints.m:
compiler/par_loop_control.m:
compiler/parse_item.m:
compiler/parse_string_format.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_to_term.m:
compiler/parse_util.m:
compiler/pd_debug.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/peephole.m:
compiler/polymorphism.m:
compiler/polymorphism_info.m:
compiler/polymorphism_lambda.m:
compiler/polymorphism_type_class_info.m:
compiler/polymorphism_type_info.m:
compiler/post_typecheck.m:
compiler/pragma_c_gen.m:
compiler/pred_name.m:
compiler/pred_table.m:
compiler/prog_item.m:
compiler/prog_rep.m:
compiler/prop_mode_constraints.m:
compiler/purity.m:
compiler/push_goals_together.m:
compiler/qual_info.m:
compiler/quantification.m:
compiler/rbmm.execution_path.m:
compiler/rbmm.m:
compiler/rbmm.points_to_analysis.m:
compiler/rbmm.points_to_graph.m:
compiler/rbmm.points_to_info.m:
compiler/rbmm.region_resurrection_renaming.m:
compiler/rbmm.region_transformation.m:
compiler/recompilation.used_file.m:
compiler/recompilation.version.m:
compiler/recompute_instmap_deltas.m:
compiler/resolve_unify_functor.m:
compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/saved_vars.m:
compiler/set_of_var.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_conj.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_ite.m:
compiler/simplify_goal_scope.m:
compiler/simplify_goal_switch.m:
compiler/simplify_goal_unify.m:
compiler/simplify_info.m:
compiler/simplify_proc.m:
compiler/size_prof.m:
compiler/smm_common.m:
compiler/ssdebug.m:
compiler/stack_alloc.m:
compiler/stack_layout.m:
compiler/stack_opt.m:
compiler/stm_expand.m:
compiler/store_alloc.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.domain.m:
compiler/structure_reuse.indirect.m:
compiler/structure_reuse.lbu.m:
compiler/structure_reuse.lfu.m:
compiler/structure_sharing.analysis.m:
compiler/structure_sharing.domain.m:
compiler/superhomogeneous.m:
compiler/switch_detection.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/tabling_analysis.m:
compiler/term_constr_build.m:
compiler/term_constr_data.m:
compiler/term_constr_initial.m:
compiler/term_constr_main.m:
compiler/term_constr_main_types.m:
compiler/term_constr_util.m:
compiler/term_pass1.m:
compiler/term_traversal.m:
compiler/term_util.m:
compiler/trace_gen.m:
compiler/trailing_analysis.m:
compiler/transform_llds.m:
compiler/try_expand.m:
compiler/tupling.m:
compiler/type_assign.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/typecheck_debug.m:
compiler/typecheck_errors.m:
compiler/typecheck_info.m:
compiler/unify_gen_construct.m:
compiler/unify_gen_deconstruct.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unneeded_code.m:
compiler/untupling.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/var_locn.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.
2022-04-18 02:00:38 +10:00
Zoltan Somogyi
3503128d9b Rename module_imports.m to module_baggage.m.
compiler/module_baggage.m:
    This reflects the changes to this module over the last year.

compiler/parse_tree.m:
    Change the module name in the include_module declaration.

compiler/deps_map.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/mercury_compile_main.m:
compiler/module_dep_info.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
    Change the module name in import_module declarations.

compiler/notes/compiler_design.html:
    Change the module name in the module description.
2022-04-15 12:41:32 +10:00
Zoltan Somogyi
c02eb5163e Carve io.{call_system,environment}.m out of io.m.
library/io.call_system.m:
    Move the code in the "system access predicates" section of io.m
    to this new module.

library/io.environment.m:
    Move the predicates dealing with environment variables in io.m
    to this new module.

library/io.m:
    Delete the code moved to the new modules.

    Leave behind in io.m "forwarding predicates", predicates that do nothing
    except call the moved predicates in the new modules, to provide backward
    compatibility. But do mark the forwarding predicates as obsolete,
    to tell people to update their (at their leisure, since the obsoleteness
    warning can be turned off).

    Also leave behind in io.m the definitions of the types used
    by some parameters of some of the moved predicates.

library/MODULES_DOC:
    List the new modules among the documented modules.

library/library.m:
    List the new modules, including io.file.m (added in a previous change)
    among the documented standard library modules.

NEWS:
    Announce the changes.

browser/browse.m:
browser/interactive_query.m:
compiler/fact_table.m:
compiler/handle_options.m:
compiler/make.module_target.m:
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
compiler/optimize.m:
compiler/options_file.m:
deep_profiler/conf.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_test.m:
library/io.file.m:
mdbcomp/trace_counts.m:
ssdb/ssdb.m:
tests/general/environment.m:
tests/hard_coded/closeable_channel_test.m:
tests/hard_coded/setenv.m:
tests/hard_coded/system_sort.m:
    Call the moved predicates directly in their new modules,
    not indirectly through io.m.
2022-03-08 09:38:27 +11:00
Zoltan Somogyi
25b4b67403 Carve io.file.m out of io.m.
library/io.file.m:
library/io.m:
    Move two sections of io.m, the "file handling predicates" section
    and the "handling temporary files" section to the new submodule io.file.m.

    Leave behind in io.m "forwarding predicates", predicates that do nothing
    except call the moved predicates in io.file.m, to provide backward
    compatibility. But do mark the forwarding predicates as obsolete,
    to tell people to update their (at their leisure, since the obsoleteness
    warning can be turned off).

    Also leave behind in io.m the definitions of the two types used
    by some parameters of some of the moved predicates. Document the reason
    why this is done.

library/MODULES_DOC:
    List the new module among the documented modules.

NEWS:
    Announce the changes.

browser/browse.m:
browser/interactive_query.m:
browser/listing.m:
compiler/analysis.file.m:
compiler/compile_target_code.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_util.m:
compiler/handle_options.m:
compiler/make.build.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/module_cmds.m:
compiler/parse_module.m:
compiler/passes_aux.m:
compiler/prog_event.m:
compiler/recompilation.check.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
deep_profiler/conf.m:
deep_profiler/mdprof_cgi.m:
library/dir.m:
mdbcomp/program_representation.m:
ssdb/ssdb.m:
    Call the file operation predicates directly in io.file.m, not indirectly
    through io.m.

    In two modules, add a #include of fcntl.h in C code. These modules contain
    C code that needs this #include, but until now, they got it via a copy
    in an automatically generated C header file of a foreign_decl pragma
    in io.m that contained that #include. This diff moves that foreign_decl
    to io.file.m, removing that crutch.

tests/debugger/browser_test.m:
tests/hard_coded/bit_buffer_test.m:
tests/hard_coded/bitmap_test.m:
tests/hard_coded/construct_bug.m:
tests/hard_coded/dir_fold.m:
tests/hard_coded/dir_test.m:
tests/hard_coded/read_binary_int16.m:
tests/hard_coded/read_binary_int32.m:
tests/hard_coded/read_binary_int64.m:
tests/hard_coded/read_binary_uint16.m:
tests/hard_coded/read_binary_uint32.m:
tests/hard_coded/read_binary_uint64.m:
tests/hard_coded/read_bitmap_size.m:
tests/hard_coded/remove_file.m:
tests/hard_coded/write_binary.m:
tests/hard_coded/write_binary_int8.m:
tests/hard_coded/write_binary_multibyte_int.m:
tests/hard_coded/write_binary_uint8.m:
    Call the file operation predicates directly in io.file.m, not indirectly
    through io.m.
2022-03-08 06:01:21 +11:00
Zoltan Somogyi
c8725fb4bc Carve module_dep_info.m out of module_imports.m.
compiler/module_dep_info.m:
    As above. The only change is added documentation.

compiler/parse_tree.m:
    Include the new module in the parse_tree package.

compiler/notes/compiler_design.html:
    Document the new module, and update the documentation of module_imports.m.

compiler/module_imports.m:
    Delete the moved code, put the main data structure at the top,
    and add some documentation for it.

compiler/compile_target_code.m:
compiler/generate_dep_d_files.m:
compiler/make.dependencies.m:
compiler/make.make_info.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/module_deps_graph.m:
    Import module_dep_info.m, usually instead of module_imports.m,
    sometimes beside module_imports.m.
2022-01-25 08:48:40 +11:00
Zoltan Somogyi
7cba325c94 Make options_file.m return either info or error.
compiler/options_file.m:
    Change the interface of three lookup predicates to return
    either the information they are intended to look up, or a list of
    error_specs, but not both. The old code would have made sense
    if some error_specs generated during the lookup could be warnings,
    but they are always errors.

compiler/make.build.m:
    Do not make room for warnings in make build's setup, because
    (a) the code that filled in that slot with info from options_file.m
    could never put any warnings in there, and (b) most users of that
    data structure ignored that slot anyway.

    Don't take parameters that are unneeded after this change.

compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/mercury_compile_main.m:
    Conform to the changes above.

compiler/maybe_error.m:
    Add a utility predicate.
2022-01-23 02:05:23 +11:00
Zoltan Somogyi
243491523d Stop counting errors in module_infos.
Over time, we have almost completely switched over to using error_specs,
using their severity (if not yet printed out) and their effect on the
exit status (if already printed out) to represent the presence of errors,
leaving only a few places that either updated or paid attention to the
num_error field in the module_info. This diff completes that process.

compiler/hlds_module.m:
    Delete the num_errors field in the module_info, and the predicates
    that operate on it.

compiler/hlds_error_util.m:
    Delete module_info arguments whose only purpose was to update the
    now-delete field.

compiler/error_util.m:
    Delete the old write_error_spec predicates that updated a count of warnings
    and a count of errors.

    Rename the write_error_spec_ignore predicates, which ignored those counts,
    by deleting the "_ignore" from their names. This makes them take the
    place of the deleted predicates.

compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/compile_target_code.m:
compiler/cse_detection.m:
compiler/find_module.m:
compiler/generate_dep_d_files.m:
compiler/handle_options.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.top_level.m:
compiler/make.track_flags.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/mode_info.m:
compiler/modes.m:
compiler/pd_util.m:
compiler/pred_table.m:
compiler/recompilation.check.m:
compiler/typecheck.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.
2022-01-15 16:33:38 +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
346172849c Use standard length comment lines. 2022-01-10 08:59:08 +11:00
Zoltan Somogyi
6f7c176056 Move unneeded-there imports out of the interface. 2021-11-19 11:06:19 +11:00
Zoltan Somogyi
703f52fd7a Stop using exit status to report success/failure.
compiler/make.module_dep_file.m:
    Judge whether calls to write_short_interface_file_int3 succeeded
    by an explicit maybe_succeeded value they now return, instead of
    checking the exit status in the I/O state.

compiler/module_cmds.m:
compiler/parse_tree_out.m:
compiler/write_module_interface_files.m:
    Make operations on files return a maybe_succeeded argument to indicate
    success vs failure.

compiler/make.module_target.m:
compiler/mlds_to_c_file.m:
    Take the new maybe_succeeded arguments in calls into account
    when computing whether an action succeeded.

compiler/analysis.m:
compiler/export.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/recompilation.check.m:
    Ignore the maybe_succeeded results returned by calls, for now.

    In export.m, switch from /* */ to // syntax for the C comments we write.
2021-08-23 22:07:14 +10:00
Zoltan Somogyi
eaab6be179 Inline build_module_with_options_and_output_redirect.
compiler/make.build.m:

compiler/make.build.m:
    Delete build_module_with_options_and_output_redirect after inlining it
    at its only call site. It added nothing but complexity and opacity.

    Similarly inline and then delete the auxiliary predicates it used.

    Delete the types that are not needed after the above.

compiler/make.module_target.m:
    Inline build_module_with_options_and_output_redirect at its call site.
2021-08-19 16:38:03 +10:00
Zoltan Somogyi
d35abe848e Split build_with_check_for_interrupt into two.
compiler/process_util.m:
    Replace build_with_check_for_interrupt with setup_checking_for_interrupt
    and teardown_checking_for_interrupt, two new predicates whose code is
    respectively the part of build_with_check_for_interrupt before and after
    the main higher order call. This makes the code at the former call sites
    significantly easier to read, especially the ones which had higher order
    calls inside higher order calls inside higher order calls.

    Move a type that process_util.m does not need anymore to
    make.program_target.m.

compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Conform to the changes above.
2021-08-18 21:27:16 +10:00
Zoltan Somogyi
0b38bc6e4e Raise the level of a utility predicate. 2021-08-13 04:13:49 +10:00
Zoltan Somogyi
4639ea4e88 Give some predicates better names. 2021-08-13 04:13:49 +10:00
Zoltan Somogyi
775dad0599 Move the maybe_succeeded type to maybe_succeeded.m.
compiler/maybe_succeeded.m:
    The new module.

compiler/libs.m:
    Include the new module in the libs package.

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

compiler/check_libgrades.m:
compiler/compile_target_code.m:
compiler/file_util.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/module_cmds.m:
compiler/process_util.m:
    Conform to the move.
2021-08-13 03:08:19 +10:00
Zoltan Somogyi
1a29beae9e Add a mki_ prefix to make_info's fields. 2021-08-12 07:00:31 +10:00
Zoltan Somogyi
cb340cf714 Replace bools with maybe_succeeded ...
... and other bespoke types.

compiler/process_util.m:
    Define the maybe_succeeded type, and two operations on it.

compiler/make.m:
    Define the maybe_keep_going and maybe_invoked_by_mmc_make types.

    Use the new types instead of bools where applicable.

compiler/check_libgrades.m:
compiler/compile_target_code.m:
compiler/file_util.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/module_cmds.m:
    Use the new types instead of bools where applicable.

    Do not look up the value of the keep_going option in the globals
    when its value (converted to the maybe_keep_going type) is available
    in the make_info.

    Use standard terminology in variable names.
2021-08-12 06:06:39 +10:00
Zoltan Somogyi
114cfb482e Create and use module_dep_summary.
compiler/module_imports.m:
    Until now, we stored the information we read in from .dep files
    in module_and_imports structures in which most of the fields
    were left filled-in with default values, which could be correct
    only by accident.

    This diff switches to storing information from .dep files in
    a values of a type, module_dep_summary, that is made for this purpose.
    With this type, it is obvious that the only fields that are ever
    accessed are fields that have been properly filled in.

    Delete the old predicate that constructed the half-filled-in
    module_and_imports structure, since it is not needed anymore.
    Also, delete the mcm_read construction method, since the deleted
    predicate was its only user.

    Since mmc --make operates both on values of this type *and* on
    values of the old module_and_imports type, introduce a new type,
    module_dep_info, which stores either one or the other,
    and add the needed access predicates on this type.

    Give a field of module_and_imports a more descriptive name.

compiler/make.m:
    Switch to recording module_dep_infos for modules, instead of
    just module_and_imports.

    Replace some uses of maybes and pairs with bespoke types.

compiler/make.module_dep_file.m:
    Store the result of reading a .dep file in a module_dep_summary,
    not in a partially-filled-in module_and_imports.

compiler/module_deps_graph.m:
    Store module_dep_infos in the deps_graph instead of module_and_imports
    structures.

    Delete a named mode, since mode "in" now works for functions
    with the default mode.

compiler/make.dependencies.m:
    Delete the maybe(option) field from dep_file, since it was *always*
    set to "no".

    Conform to the changes above.

compiler/make.util.m:
    Add a new utility predicate, for use in make.dependencies.m.

    Conform to the changes above.

compiler/generate_dep_d_files.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Conform to the changes above.

compiler/compile_target_code.m:
    Expect a module_dep_info instead of a module_and_imports,
    since that is what our callers have.

    Add an XXX for a surprising piece of code.
2021-07-29 17:39:04 +10:00
Zoltan Somogyi
52208fc8bf Use the new type maybe_top_module.
compiler/module_imports.m:
    The module_and_imports structure used to have a field, mf_nested_children,
    which stored a set of module names, but which had confusing semantics:
    it had two different meanings in two different circumstances.
    Replace that field with a value of a new type, maybe_top_module, which
    has two separate function symbols for those two circumstances:
    when a module is the top module in its source file, and when it is not.

compiler/mercury_compile_main.m:
    Conform to the change above.

    Put related arguments next to each other.

compiler/grab_modules.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/recompilation.check.m:
compiler/write_deps_file.m:
    Conform to the change above.

tests/recompilation/test_functions:
    Impose a limit of 10 minutes of CPU time on each process. This should
    help catch infinite loops, such as happened during the development
    of this diff.

    Fix indentation, and clarify some comments.

tests/recompilation/README:
    Fix stray blank line.
2021-07-19 20:48:12 +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
a19a5f0267 Delete the Erlang backend from the compiler.
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_backend.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
compiler/erlang_rtti.m:
compiler/mercury_compile_erl_back_end.m:
    Delete these modules, which together constitute the Erlang backend.

compiler/notes/compiler_design.html:
    Delete references to the deleted modules.

compiler/parse_tree_out_type_repn.m:
    Update the format we use to represent the sets of foreign_type and
    foreign_enum declarations for a type as part of its item_type_repn_info,
    now that Erlang is no longer a target language.

compiler/parse_type_repn.m:
    Accept both the updated version of the item_type_repn_info and the
    immediately previous version, since the installed compiler will
    initially generate that previous version. However, stop accepting
    an even older version that we stopped generating several months ago.

compiler/parse_pragma_foreign.m:
    When the compiler finds a reference to Erlang as a foreign language,
    add a message about support for Erlang being discontinued to the error
    message.

    Make the code parsing foreign_decls handle the term containing
    the foreign language the same way as the codes parsing foreign
    codes, procs, types and enums.

    Add a mechanism to help parse_mutable.m to do the same.

compiler/parse_mutable.m:
    When the compiler finds a reference to Erlang as a foreign language,
    print an error message about support for Erlang being discontinued.

compiler/compute_grade.m:
    When the compiler finds a reference to Erlang as a grade component,
    print an informational message about support for Erlang being discontinued.

compiler/pickle.m:
compiler/make.build.m:
    Delete Erlang foreign procs and types.

compiler/add_foreign_enum.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_type.m:
compiler/check_libgrades.m:
compiler/check_parse_tree_type_defns.m:
compiler/code_gen.m:
compiler/compile_target_code.m:
compiler/compute_grade.m:
compiler/const_struct.m:
compiler/convert_parse_tree.m:
compiler/dead_proc_elim.m:
compiler/decide_type_repn.m:
compiler/deps_map.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/foreign.m:
compiler/globals.m:
compiler/granularity.m:
compiler/handle_options.m:
compiler/hlds_code_util.m:
compiler/hlds_data.m:
compiler/hlds_module.m:
compiler/inlining.m:
compiler/int_emu.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/lco.m:
compiler/llds_out_file.m:
compiler/make.dependencies.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/make_hlds_separate_items.m:
compiler/make_hlds_warn.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/ml_code_util.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_target_util.m:
compiler/ml_top_gen.m:
compiler/mlds.m:
compiler/mlds_dump.m:
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_cs_type.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_type.m:
compiler/module_imports.m:
compiler/parse_pragma_foreign.m:
compiler/parse_tree_out.m:
compiler/polymorphism.m:
compiler/pragma_c_gen.m:
compiler/prog_data.m:
compiler/prog_data_foreign.m:
compiler/prog_foreign.m:
compiler/prog_item.m:
compiler/simplify_goal_scope.m:
compiler/special_pred.m:
compiler/string_encoding.m:
compiler/top_level.m:
compiler/uint_emu.m:
compiler/write_deps_file.m:
    Remove references to Erlang as a backend or as a target language.

tests/invalid/bad_foreign_code.{m,err_exp}:
tests/invalid/bad_foreign_decl.{m,err_exp}:
tests/invalid/bad_foreign_enum.{m,err_exp}:
tests/invalid/bad_foreign_export.{m,err_exp}:
tests/invalid/bad_foreign_export_enum.{m,err_exp}:
tests/invalid/bad_foreign_import_module.{m,err_exp}:
tests/invalid/bad_foreign_proc.{m,err_exp}:
tests/invalid/bad_foreign_type.{m,err_exp}:
    Add a test for Erlang as an invalid foreign language. Expect both the
    new error message for this new error, and the updated list of now-valid
    foreign languages on all errors.
2020-10-29 13:24:49 +11:00
Zoltan Somogyi
c2f92d5454 Partition extensions into ".m" and "all others".
This is a first step towards a much finer grained partition.

compiler/file_names.m:
    Split the ext type into ext_src and ext_other, as mentioned above.

    Add the first predicate for checking whether a string falls into
    a given category of extensions.

    Add an XXX proposing a better solution for an old problem that does not
    actually arise in practice.

compiler/compile_target_code.m:
    Split the two-moded predicate maybe_pic_object_file_extension into
    two separate one-mode predicates, one for each old mode. The
    implementations of the two modes were already separate, because
    the two modes already did different jobs: while one went from PIC
    to an "extension", the other went from an "extension string" to PIC.
    Until now, "extension" and "extension string" were equivalent;
    after this diff, they aren't anymore.

    Delete an unused argument.

compiler/make.util.m:
    Split the two-moded predicate target_extension into
    two separate one-mode predicates, one for each old mode,
    for the same reason as maybe_pic_object_file_extension above:
    the fact that "extension" and "extension string" are now distinct.

compiler/options_file.m:
    Move debug infrastructure here from mercury_compile_main.m, to help
    debug possible problems with options files. (I had such a problem
    while writing this diff.)

    Improve how progress messages are printed.

compiler/options.m:
    Make an error message more useful.

compiler/mercury_compile_main.m:
    Add infrastructure for debugging possible problems with command lines.
    (I had such a problem while writing this diff.)

compiler/analysis.m:
    Conform to the changes above. Put the arguments of some methods
    into the same order as similar predicates in file_names.m.

compiler/find_module.m:
    Conform to the changes above. Delete an unused argument,

compiler/analysis.file.m:
compiler/du_type_layout.m:
compiler/elds_to_erlang.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.deps_set.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/prog_foreign.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/source_file_map.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
2020-08-17 23:43:15 +10:00
Zoltan Somogyi
52c0919975 Make filename extensions a separate type, ...
... to allow later changes to its definition.

compiler/file_names.m:
    We used to represent filename extensions simply as strings. This meant
    all calls to the predicates in file_names.m that convert module names
    to file names with various suffixes had to go through a complicated
    sequence of tests that effectively partition the extensions into
    several classes, with all extensions in a class being treated the same
    but different classes being treated differently. And since this general
    translation process is quite convoluted (which is not helped by it
    being spread across several predicates), it is very hard to construct
    a correctness argument for it.

    It would be better to represent the different classes of extensions
    explicitly, in a du type, with each function symbol of that type
    representing all the extensions in the corresponding class (in the sense
    of the paragraph above). However, getting there in one diff would make
    that diff far too hard to test and to review. So this first diff
    starts by simply making extension a notag type.

    The above is the first step in implementing one old XXX. This diff
    fully implements another old XXX, which is to make the argument order
    of several predicates friendly to higher order code.

    Add infrastructure for profiling how often this code makes directories.

    Delete an unused type.

    Add comments outlining proposed future improvements.

compiler/analysis.file.m:
compiler/analysis.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/elds_to_erlang.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/find_module.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/llds_out_file.m:
compiler/make.build.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_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/module_imports.m:
compiler/parse_tree_out.m:
compiler/prog_foreign.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 to file_names.m.

    Consistently use "Ext" for the abstract representation of extensions
    and "ExtStr" for their string representation.

    In a few places, add "XXX EXT" where the code manipulates extensions
    as strings in a way that potentially inferferes with the partition
    of extensions into classes.

    In a few places, rename predicates to avoid ambiguities. factor out
    common code, delete unneeded arguments, replace bools with bespoke types,
    and make similar minor improvements.

    In a few places, remove rafe-isms, such as the use ^elem.
2020-08-14 20:30:36 +10:00
Zoltan Somogyi
f87c5efcac Avoid floats that are not exact binary fractions.
Such floats are one reason why the generated .cs and .java files
for stages 2 and 3 differ. After this diff, differences such as

-      double Var_12 = 0.90000000000000002;
+      double Var_12 = 0.90000000000000000;

should go away.

compiler/make.module_target.m:
library/hash_table.m:
library/version_hash_table.m:
mdbcomp/slice_and_dice.m:
    Replace float fractions that are not exact binary fractions with
    close by fractions that are exact binary fractions. In none of these cases
    was there a strong reason for the actual value originally picked.
2020-04-09 20:35:24 +10:00
Zoltan Somogyi
3a1ed2efcb Replace simple_call_id with pf_sym_name_arity.
compiler/prog_data.m:
    Delete the simple_call_id data type, since it is isomorphic
    to the pf_sym_name_arity type, which more clearly specifies
    what is stored inside it.

compiler/prog_out.m:
    Rename (all three versions of) simple_call_id_to_string to
    pf_sym_name_orig_arity_to_string, both to conform to the change
    in the input data type, and to emphasize that the resulting string
    will contain the *original* arity of functions (which does not include
    the return value), which is one less than the arity in the
    pf_sym_name_arity structure (which, in accordance with the
    convention inside the compiler that the arity is the length
    of the argument list, *does* include the return value).

    Delete the provision inside simple_call_id_to_string, now
    pf_sym_name_orig_arity_to_string, for special handling of the names
    of the predicates we use to implement promises, because it seems that
    *none* of the call sites to any of the three versions of this function
    can actually pass to it the identity of such a predicate. These calls
    refer to a predicate or mode declaration item (which promise predicates
    do not have), to clause or foreign_proc items (which again, promise
    predicates cannot have) or calls to the predicate (promise predicates
    cannot be called).

    Delete the exported predicate simple_call_id_to_sym_name_arity.
    It was called from exactly one place, inside prog_out.m itself,
    and this diff inlines that call.

    Avoid unnecessary forwarding of work from prog_out.m to error_util.m.

    Delete (all three versions of) write_simple_call_id. The changes
    below replace all their (few) uses with calls to
    pf_sym_name_orig_arity_to_string.

compiler/error_util.m:
    Replace the simple_call() error piece with qual_pf_sym_name_orig_arity,
    and add a new version unqual_pf_sym_name_orig_arity. Their names
    explicitly say that they print the original arities of functions,
    also say whether they strip away any module qualification on the
    sym_name inside the pf_sym_name_arity. We prefer the unqual version
    in situations where the module qualifier is implicit, which usually means
    that it must be the same as the name of the module being compiled, because
    it reduces visual clutter for readers of error messages.

    Put {qual,unqual}_pf_sym_name_orig_arity next to their most closely
    related function symbols, {qual,unqual}_sym_name_arity, in the
    format_component type. (This yields a few inconsequential changes
    in the order of error_specs when sorted.)

compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/check_libgrades.m:
compiler/check_parse_tree_type_defns.m:
compiler/check_promise.m:
compiler/check_typeclass.m:
compiler/convert_parse_tree.m:
compiler/equiv_type.m:
compiler/goal_expr_to_goal.m:
compiler/hlds_data.m:
compiler/hlds_desc.m:
compiler/hlds_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/hlds_pred.m:
compiler/inst_util.m:
compiler/llds_out_instr.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make_hlds_error.m:
compiler/make_hlds_warn.m:
compiler/mark_tail_calls.m:
compiler/ml_unify_gen_construct.m:
compiler/mlds_to_c_stmt.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/modecheck_util.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/parse_item.m:
compiler/parse_module.m:
compiler/parse_type_repn.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/pre_quantification.m:
compiler/pred_table.m:
compiler/prog_item.m:
compiler/recompilation.version.m:
compiler/term_constr_build.m:
compiler/termination.m:
compiler/type_ctor_info.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
compiler/typecheck_info.m:
compiler/unify_gen_construct.m:
compiler/unused_imports.m:
    Conform to the changes above. Where I am pretty sure that in an error
    message, the module qualifier of a name must be the current module,
    use unqual_pf_sym_name_orig_arity instead of qual_pf_sym_name_orig_arity.

    Add some sanity checks where they seem appropriate.

    Replace sequences of io.write_strings with uses of io.format where this
    yields clearer code. (This is why there were no remaining calls to
    write_simple_call_id.)

    Shorten some too-long lines.

    In add_pred.m, make the order of some predicate definitions match
    the order of the calls to them.

tests/invalid/ambiguous_method.err_exp:
tests/invalid/ambiguous_method_2.err_exp:
tests/invalid/bad_pred_arity.err_exp:
tests/invalid/bad_sv_unify_msg.err_exp:
tests/invalid/bigtest.err_exp:
tests/invalid/bug113.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/bug278.err_exp:
tests/invalid/bug410.err_exp:
tests/invalid/bug476.err_exp:
tests/invalid/bug487.err_exp:
tests/invalid/complex_constraint_err.err_exp:
tests/invalid/constrained_poly_insts.err_exp:
tests/invalid/errors.err_exp:
tests/invalid/errors1.err_exp:
tests/invalid/errors2.err_exp:
tests/invalid/exported_mode.err_exp:
tests/invalid/field_syntax_error.err_exp:
tests/invalid/foreign_singleton.err_exp:
tests/invalid/funcs_as_preds.err_exp:
tests/invalid/imported_mode.err_exp:
tests/invalid/invalid_binary_literal.err_exp:
tests/invalid/invalid_float_literal.err_exp:
tests/invalid/invalid_hex_literal.err_exp:
tests/invalid/invalid_octal_literal.err_exp:
tests/invalid/make_opt_error.err_exp:
tests/invalid/missing_det_decls.err_exp:
tests/invalid/multimode_syntax.err_exp:
tests/invalid/null_char.err_exp:
tests/invalid/occurs.err_exp:
tests/invalid/record_syntax_errors.err_exp:
tests/invalid/ref_to_implicit_pred.err_exp:
tests/invalid/require_tailrec_1.err_exp:
tests/invalid/require_tailrec_1.err_exp2:
tests/invalid/require_tailrec_2.err_exp:
tests/invalid/require_tailrec_2.err_exp2:
tests/invalid/require_tailrec_3.err_exp:
tests/invalid/require_tailrec_3.err_exp2:
tests/invalid/state_vars_test2.err_exp:
tests/invalid/state_vars_test3.err_exp:
tests/invalid/state_vars_test5.err_exp:
tests/invalid/type_inf_loop.err_exp:
tests/invalid/typeclass_constraint_extra_var.err_exp:
tests/invalid/typeclass_mode_2.err_exp:
tests/invalid/typeclass_test_12.err_exp:
tests/invalid/typeclass_test_2.err_exp:
tests/invalid/typeclass_test_9.err_exp:
tests/invalid/types.err_exp:
tests/invalid/types2.err_exp:
tests/invalid/unbound_type_vars.err_exp:
tests/invalid/with_type.err_exp:
tests/invalid_purity/purity_nonsense.err_exp:
tests/invalid_purity/purity_nonsense2.err_exp:
tests/warnings/double_underscore.exp:
tests/warnings/pragma_source_file.exp:
tests/warnings/singleton_test.exp:
tests/warnings/singleton_test.exp2:
tests/warnings/singleton_test.exp3:
tests/warnings/singleton_test.exp4:
tests/warnings/singleton_test_state_var.exp:
tests/warnings/warn_return.exp:
tests/warnings/warn_return.exp2:
tests/warnings/warn_return.exp3:
tests/warnings/warn_succ_ind.exp:
tests/warnings/warn_succ_ind.exp2:
tests/warnings/warn_succ_ind.exp3:
tests/warnings/warn_succ_ind.exp4:
    Update all these expected output files. Most changes are due to
    predicate and function names no longer being module qualified when
    the module qualification is obvious. A few changes are due to the
    change in the relative ordering of the function symbols of the
    format_component type.

    For singleton_test, warn_return and warn_succ_ind in warnings,
    the changes to the non-C .exp files were done by hand, so they
    may have the wrong white space.
2020-03-16 12:10:28 +11:00
Zoltan Somogyi
16c7a62f8d Make some code easier to read.
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
    Replace some lambdas with named predicates.

    Make a too-indented piece of code easier to read by putting it into
    its own predicate, thus requiring less indentation.

    Replace a use of pairs with a bespoke type.

    Use one io.format instead of several io.write_strings.

    Improve the wording of some comments, partly by avoiding bad line breaks.
2020-01-05 12:50:36 +11:00
Zoltan Somogyi
9496952b78 Simplify some code. 2019-04-15 06:15:35 +10:00
Zoltan Somogyi
e6870d29f9 Make module_and_imports an abstract type.
compiler/module_imports.m:
    Make the definition of module_and_imports private, to make future changes
    to its structure easier.

    Add the construction, deconstruction, getter and setter predicates
    on the type that are now needed by the other compiler modules.

    Put the related fields of module_and_imports next to each other.
    Give some of the fields more descriptive names.

compiler/compile_target_code.m:
compiler/deps_map.m:
compiler/generate_dep_d_files.m:
compiler/make.dependencies.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/module_deps_graph.m:
compiler/modules.m:
compiler/write_deps_file.m:
    Conform to the changes above.
2019-04-14 23:31:16 +10:00
Zoltan Somogyi
2a74a2b6ed Fix misleading names in two enums.
compiler/make.m:
    Replace references to private, long and short interfaces with references
    to int0, int1, int2 and int3 in two types. These two types, even though
    they were adjacent, used the same word, "short", to refer to two DIFFERENT
    interface file kinds: int2 in one, int3 in the other.

compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
    Conform to the change above.

    Replace the definitions of some predicates, which used to be lists of
    clauses, with a single clause each containing a disjunction, especially
    where the old definitions implemented the DRY principle through recursion
    (because switch arms shared between two or more cons_ids were not yet
    supported when they were written).

    Do some other minor cleanups.
2019-04-10 21:09:40 +10:00
Zoltan Somogyi
77f3b71362 Simplify some code. Note some parallels. 2019-04-10 17:04:55 +10:00
Zoltan Somogyi
e08b8505e9 Import the parents of *all* imported modules. 2019-03-29 12:56:35 +11:00
Zoltan Somogyi
f1906ece65 Fix some too-long lines. 2017-12-14 14:12:30 +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