Commit Graph

95 Commits

Author SHA1 Message Date
Zoltan Somogyi
4e6a6357c4 Use standard but controllable "can't open file" messages.
compiler/file_util.m:
    Define standard routines for reporting that we couldn't open a file
    for either input or output. Rename the one other predicate in this file
    that the compiler used for that purpose, so that its call sites
    can be redirected to use one of the routines intended for this purpose.

    Give these routines the ability to standardize path names (by removing
    "./" prefixes from relative path names, and removing all directory names
    from adsolute path names) if a new option is given.

compiler/options.m:
    Add that (developer-only) option.

compiler/compile_target_code.m:
compiler/copy_util.m:
compiler/export.m:
compiler/llds_out_file.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_make_hlds.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/module_cmds.m:
compiler/opt_deps_spec.m:
compiler/output_imports_graph.m:
compiler/passes_aux.m:
compiler/system_cmds.m:
compiler/write_deps_file.m:
compiler/xml_documentation.m:
    Replace all call sites to the file_util.m predicates modified
    by this diff. In many cases, it replaces duplicate copies of the
    same code with a call. In some cases, redirect the error message
    to the progress stream, where it belongs.

tests/invalid/Mercury.options:
tests/invalid/foreign_include_file_missing.err_exp3:
    Compile the foreign_include_file_missing test case with the new option,
    and add the expected output in C# grades, which (thanks to the option)
    no longer includes the pathname of the test directory.

tests/invalid/foreign_include_file_missing.m:
    Record what the new .err_exp3 file is for.

tests/warnings/help_text.err_exp:
    Expect the new option.
2025-10-11 12:10:26 +11:00
Zoltan Somogyi
3dd0f2e03b Act on all remaining warnings about unused state vars.
compiler/add_heap_ops.m:
compiler/check_import_accessibility.m:
compiler/comp_unit_interface.m:
compiler/convert_import_use.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/distance_granularity.m:
compiler/equiv_type.m:
compiler/generate_dep_d_files.m:
compiler/generate_mmakefile_fragments.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/higher_order.specialize_unify_compare.m:
compiler/jumpopt.m:
compiler/layout_out.m:
compiler/lco.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.get_module_dep_info.m:
compiler/make.library_install.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/make_hlds_passes.m:
compiler/make_module_file_names.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/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_disj_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_lookup_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_test.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_target_util.m:
compiler/module_cmds.m:
compiler/opt_deps_spec.m:
compiler/optimize.m:
compiler/parse_dcg_goal.m:
compiler/parse_goal.m:
compiler/parse_item.m:
compiler/parse_module.m:
compiler/parse_string_format.m:
compiler/proc_gen.m:
compiler/prop_mode_constraints.m:
compiler/rbmm.points_to_analysis.m:
compiler/rbmm.region_analysis.m:
compiler/rbmm.region_transformation.m:
compiler/simplify_goal_disj.m:
compiler/ssdebug.m:
compiler/stack_opt.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/term_constr_build.m:
compiler/trace_gen.m:
compiler/tupling.m:
compiler/untupling.m:
compiler/write_deps_file.m:
deep_profiler/autopar_calc_overlap.m:
deep_profiler/autopar_find_best_par.m:
deep_profiler/html_format.m:
deep_profiler/startup.m:
profiler/mercury_profile.m:
profiler/propagate.m:
    Act on the new warnings. In a few cases, conform to the changes
    resulting from acting on the warnings in other modules.

browser/Mercury.options:
compiler/Mercury.options:
library/Mercury.options:
mdbcomp/Mercury.options:
ssdb/Mercury.options:
    Specify options for disabling the new warnings for modules
    where we (probably) won't want them.

configure.ac:
    Require the installed compiler to understand the options that
    we now reference in the Mercury.options files above.

tests/debugger/tailrec1.exp:
    Expect variable names for the middle versions of state vars
    using the new naming scheme.

tests/invalid/Mercury.options:
    Fix references to obsolete test names.

tests/warnings/Mercury.options:
    Avoid a test failure with intermodule optimization.
2025-05-19 00:33:06 +10:00
Zoltan Somogyi
ff0506d6c2 Standardize the capitalization of a word. 2024-12-14 20:05:13 +11:00
Zoltan Somogyi
ec99843269 Create launcher scripts more simply.
compiler/module_cmds.m:
    Change the predicates that write out launcher script files to take
    as input not a higher-order predicate that does the writing, but
    simply the string to be written.

compiler/compile_target_code.m:
    Conform to the change above.
2024-11-17 16:23:52 +11:00
Zoltan Somogyi
f3465e5810 Put the grade dir name in the globals.
compiler/globals.m:
    Add to the globals structure a field that holds the pathname component
    identifying the grade (in the names of grade-specific files).
    We used to compute it every time we needed it, using a relatively slow
    algorithm; we now compute it just once, when the globals structure
    is created by the globals_init predicate.

    Put the main read-only fields of the globals into a substructure,
    to make any updates of the writeable fields faster by reducing the size
    of the globals structure itself,

    Change the order of the arguments of globals_init, and the order of the
    getter and setter predicates of the globals structure, to match the
    new order of the fields in the globals structure.

    Don't mix other predicates in with the getter and setter predicates.

compiler/compute_grade.m:
    Delete the predicate that used to compute this pathname component
    after effectively inlining its one-line definition in the globals_init
    predicate.

compiler/check_libgrades.m:
compiler/compile_target_code.m:
compiler/file_names.m:
compiler/file_util.m:
compiler/handle_options.m:
compiler/implementation_defined_literals.m:
compiler/make.clean.m:
compiler/make.library_install.m:
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
    Conform to the changes above.
2024-10-23 11:58:53 +11:00
Zoltan Somogyi
3b3b543a84 Return both legacy and proposed file names.
compiler/file_names.m:
    Change the predicates that return file names to return as their result
    both the current, legacy filename, and the proposed filename.

    For ext_cur extensions, the legacy and the proposed filenames
    will always be identical. Add a predicate for these that returns
    just this one filename.

compiler/comp_unit_interface.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/fact_table.m:
compiler/generate_dep_d_files.m:
compiler/generate_mmakefile_fragments.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.check_up_to_date.m:
compiler/make.clean.m:
compiler/make.dependencies.m:
compiler/make.file_names.m:
compiler/make.get_module_dep_info.m:
compiler/make.library_install.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.timestamp.m:
compiler/make.track_flags.m:
compiler/make.util.m:
compiler/make_module_file_names.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.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/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the changes above. In most places, this means ignoring
    the proposed filename for now, but marking such places with "XXX LEGACY",
    to make them easier to find when we *do* start to make use of the proposed
    file names (first alongside the legacy names, and then without them).

    In some places, make variable names more descriptive.

library/set.m:
    Add utility predicate for use by a diff to one of the modules above.

NEWS.md:
    Announce the new library predicate.
2024-09-19 12:42:33 +02:00
Zoltan Somogyi
52419cde4d Fix an abuse of the "noext" extension.
compiler/generate_mmakefile_fragments.m:
    Replace an (indirect) call to module_name_to_file_name
    with the extension ext_cur_gas_exec_noext. The call's result
    was used as part of the name of a make variable, which meant
    that the presence of a directory name component in the result
    (which could happen with --use-grade-subdirs, if that were ever
    supported by mmake) would be a bug.

compiler/module_cmds.m:
    Make a variable name descriptive enough to make clear
    that there is no such abuse here.
2024-09-18 14:43:03 +02:00
Zoltan Somogyi
e0aad5ca8e Classify grade-specific files on architecture-specificity.
compiler/file_names.m
    Separate "gs" (grade-specific but not architecture-specific) extensions
    from "gas" (both grade- and architecture-specific) extensions.

    The intent is to eventually install them into different directories,
    but that is for future diffs.

    Change the functions that return directory paths into predicates.
    A future change will update them to return *two* directory paths:
    one for the LEGACY directory structure, and one for the PROPOSED
    structure.

compiler/compile_target_code.m
compiler/generate_mmakefile_fragments.m
compiler/make.clean.m
compiler/make.file_names.m
compiler/make.library_install.m
compiler/make.module_target.m
compiler/make.program_target.m
compiler/mercury_compile_llds_back_end.m
compiler/mercury_compile_main.m
compiler/module_cmds.m
    Conform to the changes above.
2024-09-18 13:46:02 +02:00
Zoltan Somogyi
168a5f179d Fix "analysiss" vs "analyses" inconsistency.
compiler/make.library_install.m:
    Pass the full names of extension-specific directories, instead of
    letting callees construct it by adding a "s" suffix to the
    extension string. This fixes the above inconsistency.

    Test whether use_symlinks is set just once.

compiler/module_cmds.m:
    Provide a version of maybe_make_symlink that assumes that the caller
    has already tested use_symlinks.
2024-08-18 00:31:16 +02:00
Zoltan Somogyi
6e2875842f Stop using .tmp files when generating .intN files.
compiler/write_module_interface_files.m:
    Instead of

        - writing out the new version of a .intN file to module.intN.tmp,
        - comparing that file with module.intN, and
        - renaming module.intN.tmp to module.intN if they differ,

    we now

        - read in the old .intN file to a string
        - convert the new parse tree for .intN to a string
        - write out the string form of the new parse tree to module.intN
          if they differ.

    The logic is bit more complex in the presence of smart recompilation
    (in both the old new algorithms) but not by much.

    The new algorithm requires significantly fewer system calls than the old.

compiler/comp_unit_interface.m:
    Don't create a name for .intN.tmp files, since they are not needed anymore.

compiler/module_cmds.m:
    Reorder the predicates that copy files putting the most basic predicate
    last, so that calls go from earlier predicates to later predicates.

compiler/parse_module.m:
    Delete unneeded IO state args from the parse_intN_file predicates.

compiler/parse_tree_out.m:
    Carve output_parse_tree_string out of the existing
    output_some_parse_tree predicate which also *constructed* that parse tree.
    This capability is needed by new code in write_module_interface_files.m,
    which wants to perform other operations on the string forms of parse trees
    before writing them out.
2024-02-13 10:46:48 +11:00
Zoltan Somogyi
f7f8408664 Fix too-long lines. 2024-02-09 23:22:26 +11:00
Julien Fischer
d2c6df9658 Delete unused support for directory copying.
The compiler has long had code for recursively copying directories (via
"cp -R"), but it does not, in fact, use it anywhere.

compiler/make.program_target.m:
compiler/file_util.m:
compiler/module_cmds.m:
    Delete unused predicates for copying directories.

compiler/globals.m:
compiler/handle_options.m:
    Do not store the flag for copying directories in file_install_cmd
    values.

compiler/options.m:
doc/user_guide.texi:
    Delete the documentation for the --install-command-dir-option.

compiler/copy_util.m:
    Delete the comment about moving directory copying to this module.

    Delete the XXX about the Mercury copying code not preserving
    permissions; it now attempts to do so.

NEWS.md:
    Announce the deprecation of --install-command-dir-option.
2024-01-09 16:37:36 +11:00
Julien Fischer
6528f4ece0 Move all file copying operations to the copy_util module.
Document why the compiler copies files and what mechanisms are available for
doing so.

When copying temporary interface files, do not use the Mercury copy_file
procedure as a fall back when invoking an external file copy command fails.

Use the value of the --install-method option to select whether we use an
external command to copy a file, or instead use a library procedure.

compiler/copy_util.m:
    Document why the compiler (as opposed to mmake) copies files.

    Document the mechanisms available to it for doing so.

    Split copy_file/7 into two predicates: copy_file_to_file_name/7 and
    copy_file_to_directory/7. These two predicate correspond to the
    actual file copy use cases in the rest of the compiler.

    Document some assumptions made by the rest of the compiler about
    how file copying behaves.

    Do not fallback to using the file copy procedure written in Mercury if
    invoking an external command fails when copying a file to a file.
    (When copying a file to a directory, we only ever used an external
    command.)

    Make the choice of file copy mechanism depend on the value of
    the --install-method option.

compiler/make.program_target.m:
    Use copy_file_to_directory/7 rather than invoking an external command
    here directly.

compiler/module_cmds.m:
    Use copy_file_to_file_name/7 here. Conform to changes in the way errors
    are reported during file copying.  There are couple of spots marked
    XXX FILE COPY, where the caller previously assumed an io.error would
    be returned to it -- this probably never happened in practice since
    when using an external command invoke_system_command does the error
    reporting. I'll tidy this up in a later change.
2024-01-06 19:49:16 +11:00
Julien Fischer
0eddf3f6b8 Move file copying to its own module.
compiler/module_cmds.m:
    Move the predicate copy_file/6 from here ...

compiler/copy_util.m:
    ... to here. The code is otherwise unchanged.

compiler/libs.m
    Include the new module.

compiler/notes/compiler_design.html:
    Document the new module.
2024-01-05 20:28:26 +11:00
Julien Fischer
d5835f268b Move code for invoking commands via the shell.
Move the code used for invoking commands via the shell out of the module_cmds
module and into its own module. In doing so, this moves it from the parse_tree
package into the libs package.

compiler/module_cmds.m:
    Shift the code for invoking commands via the shell from here ...

compiler/system_cmds.m:
    ... to here.

compiler/libs.m:
    Include the system_cmds module.

compiler/compile_target_code.m:
compiler/fact_table.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Conform to the above change.

compiler/notes/compiler_design.m:
    Document the new module.
2024-01-05 15:45:33 +11:00
Zoltan Somogyi
b21e9e459a Delete all calls to get_progress_output_stream ...
... and almost all calls to get_error_output_stream. Replace them
with ProgressStreams and ErrorStreams passed down from higher in the
call tree.

Use ProgressStreams, not ErrorStreams, to write out error messages about
any failures of filesystem operations. These are not appropriate to put
into a module's .err file, since they are not about an error in the
Mercury code of the module.

compiler/globals.m:
    Delete the predicates that return progress streams, and the mutable
    behind them.

compiler/passes_aux.m:
    Delete the predicates that return progress streams. Delete the
    versions of the progress-message-writing predicates that didn't get
    the progress stream from their caller.

compiler/*.m:
    Pass around ProgressStreams and/or ErrorStreams explicitly,
    as mentioned at the top of log message.

    In a few places, don't write out error_specs to ErrorStream,
    returning it to be printed by our caller, or its caller etc instead.
    In some of those places, this allowed the deletion an existing
    ErrorStream argument.

    Given that get_{progress,error}_output_stream took a ModuleName input,
    deleting some of the calls to those predicates left ModuleName unused.
    Delete such unused ModuleNames.

    In a few places, change argument orders to conform to our usual
    programming style.

    Fix too-long lines.
2023-10-17 20:41:33 +11:00
Zoltan Somogyi
e1e5480f16 Eliminate calls to io.output_stream in read_modules.m.
compiler/read_modules.m:
    When invoked to read a file specified by file name (as opposed to
    by module name), the code of this module wrote out progress messages
    to the current output stream, as returned by io.output_stream.
    Fix this by consistently requiring the ancestors of the predicates involved
    to pass an explicit stream to write progress messages to.

    The interfaces of some of the exported predicates allowed their callers
    to either pass a progress stream or not; if they didn't, this prevented
    the generation of any progress messages with -v and the generation of
    any statistics with -S. Most callers did specify the progress stream;
    the main parts of the compiler that did not were

    - the code that read the old versions of interface files in order to see
      whether the new version was identical to it, or not, and
    - the intermodule analysis framework.

    This diff requires callers to always pass a progress stream, because
    we *always* want to write out any error messages about nonexistent
    or unreadable files, and we don't want to write these to an implicitly
    specified file. We *could* add a parameter to the affected predicates
    to shut up progress messages and statistics for use at the call sites
    that previously passed us "no" as the maybe progress stream argument,
    but I see no reason why one wouldn't want -v and -S to work as usual
    in these above circumstances. If anyone ever finds such a reason,
    there is a simpler fix anyway: turning off -v and -S in the globals
    passed along next to the progress stream.

compiler/module_cmds.m:
    Stop requiring an error stream and as well as a progress stream
    when touching files. If the two streams were ever different, the
    output would have looked strange, as the error message would NOT follow
    the progress message announcing the operation that failed.

compiler/analysis.m:
compiler/deps_map.m:
compiler/generate_dep_d_files.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/recompilation.check.m:
compiler/write_module_interface_files.m:
    Conform to the changes above, mostly by passing along
    an explicit progress stream.
2023-09-15 17:55:14 +10:00
Zoltan Somogyi
d1402ec7b7 Build filenames from <dirs,basename,extstr> triples.
Previosly, there were three places in the compiler that had code to compute
the name of the directory where .class files are stored. Replace two of
these with calls to the third.

compiler/file_names.m:
    Compute the three components of files, that is

    - the dir names list that together specify a relative path,
    - the file's base name and
    - the file's extension string

    in three separate predicates. Export the new predicate doing just
    the first job; the functions doing the second and third jobs were
    already exported.

    Make the code computing the dir names list for .java and .class files
    call get_java_dir_path. This replacement of the old get_class_dir_name
    predicate is now the place that every part of the compiler calls
    for this info.

    As part of this last change, add the "jmercury" component to the path
    for .java and .class files separately, since we need the path both
    with and without this extension. This change allows a simplification
    of the make_grade_subdir_name function.

compiler/compile_target_code.m:
    Call the new get_java_dir_path predicate in file_names.m instead of
    including a duplicate copy of its logic.

compiler/make.program_target.m:
    Add an XXX on code that *looks like* it should either be in
    file_names.m or use code in file_names.m, but which cannot be easily
    updated using either approach, because its purpose is undocumented.

compiler/mercury_compile_main.m:
compiler/module_cmds.m:
    Conform to the changes in file_names.m.
2023-08-19 00:20:27 +02:00
Zoltan Somogyi
8dbbfeb3ea s/classs/classes/ 2023-08-18 15:34:22 +02:00
Zoltan Somogyi
691e5ca0c5 Group extensions by their translation algorithms.
compiler/file_names.m:
    Replace the current groups of extensions, which are based on the
    shared purpose of the files with those extensions, with a smaller
    number of groups, which are based on the algorithm we use to decide
    in what (sub)directories we want to place files with those extensions.
    The old distinctions based on purpose still remain in the naming
    convention for the enum values within each of the new groups.

compiler/analysis.file.m:
compiler/analysis.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/generate_dep_d_files.m:
compiler/llds_out_file.m:
compiler/make.file_names.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.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_make_hlds.m:
compiler/mercury_compile_middle_passes.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/prog_foreign.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the changes above.
2023-08-10 02:47:01 +02:00
Zoltan Somogyi
315fd9eb03 Add a subdir_setting field to the globals.
compiler/globals.m:
    Define a new enum type with three values, which represents the three
    legal combination of the values of the use_subdir and use_grade_subdir
    options.

    Add a field of this type to the globals.

compiler/handle_options.m:
    Set up the value of this field in the globals. This means initializing
    it to a non-meaningful value when the globals is first created, and
    filling it in with the final meaningful value when we finish the setup
    of the global structure.

compiler/options.m:
    Add a "setting_only_" to the internal names of the use_subdir and
    use_grade_subdir options, to signal that their only valid use
    from now on is in deciding the value of the new globals field.
    (Their user-facing names remain unchanged.)

compiler/compile_target_code.m:
compiler/file_names.m:
compiler/make.program_target.m:
compiler/module_cmds.m:
compiler/write_deps_file.m:
    Rewrite code that used to make decisions based on the values of
    the use_subdir and use_grade_subdir options with code that makes
    decisions based on the value of the new field. A field retrieval
    followed by a three-way switch is simpler (and faster) than
    two option lookups and one two-way switch inside another.

    Consistently reorder the code so that the code of the simpler cases
    come first.

    Note a situation where we should be using an even simpler basis
    for the decision.
2023-08-07 01:12:28 +02:00
Zoltan Somogyi
d302a4e5ca Give some predicates/constructors more meaningful names.
compiler/module_cmds.m:
    Rename the update_interface_X predicates to copy_dot_tmp_to_base_file_X,
    because

    - this better describes what they do, and
    - some of the files they are invoked on are *not* interface files.

    Add an extra parameter to copy_dot_tmp_to_base_file_report_any_error
    that specifies what kind of file is being copied, and print *that*
    as part of any error message.

    Do a similar rename of update_interface_result type, and of its
    function symbols.

    Give more meaningful names to touch_interface_datestamp and
    touch_datestamp as well.

compiler/analysis.file.m:
compiler/analysis.m:
compiler/compile_target_code.m:
compiler/export.m:
compiler/intermod.m:
compiler/make.module_target.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/mlds_to_c_file.m:
compiler/recompilation.check.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.
2023-08-02 04:02:24 +02:00
Zoltan Somogyi
d5c54ce697 Take ext_src out of the ext type.
compiler/file_names.m:
    Take ext_src out of the ext type, because this allows us to delete
    the I/O state pair of arguments out of every file translation predicate
    other than module_name_to_source_file_name and the ones that create
    directories.

compiler/file_kind.m:
    Delete the ext output argument of file_kind_to_extension, because
    we can't return ext_src for fk_src anymore.

compiler/write_deps_file.m:
    Delete a test for ext_src which could never succeed, because the
    predicate in question is never called with ext_src.

    Undo an accidental change from the diff that introduced
    module_name_to_lib_file_name_create_dirs.

    Conform to the changes above.

compiler/compile_target_code.m:
compiler/fact_table.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_make_hlds.m:
compiler/mlds_to_c_file.m:
compiler/mmc_analysis.m:
compiler/module_cmds.m:
compiler/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.
2023-07-06 16:14:35 +02:00
Zoltan Somogyi
89979d681a Replace Mkdir parameters with predicate versions.
compiler/file_names.m:
    Split module_name_to_file_name into three versions.

    - One corresponds to the old predicate's operation with do_not_create_dirs,
    - one corresponds to the old predicate's operation with do_create_dirs, and
    - one just returns the directory path, and lets the caller make those
      directories if it wants to, using procedures that we now export.

    Do the same for module_name_to_lib_file_name.

    Do not do the same for fact_table_file_name, which has too few callers
    to make it worthwhile.

    The point is that the versions that do not create any dirs should NOT
    need to take I/O state pairs as arguments, once we take ext_src
    out of the ext type.

compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/fact_table.m:
compiler/generate_dep_d_files.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.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_make_hlds.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/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Update calls to the affected predicates.

    In some places, add XXXs about seemingly-strange choices about
    what calls create directories and which don't.
2023-07-06 12:36:14 +02:00
Zoltan Somogyi
6517982c87 s/newext/ext/g and s/NewExt/Ext/g. 2023-07-04 22:32:38 +02:00
Zoltan Somogyi
0b60f07c46 Cut over to the new code in file_names.m.
compiler/file_names.m:
    Delete the old code for doing filename translations, and use
    just the new code.

    Delete all the code that was needed only for comparing the old and
    new code.

    Delete the newext_other extension category, since it was also needed
    only for that purpose. Delete all the code that supported it.

    Switch the infrastructure for recording the demand for translations
    to work with the new code.

compiler/analysis.file.m:
    Delete functions that returned old-style extensions, which are
    not useful anymore. The new-style extensions, by identifying
    extensions via enums rather than strings, serve the purpose
    for which these functions were created.

compiler/mercury_compile_main.m:
    Move the code to call to write out the translation record
    from just after a call to real_main_after_expansion to the
    end of real_main_after_expansion. The reason is that the
    predicate being called now needs access to a globals structure,
    real_main_after_expansion has access to a globals structure,
    but its caller does not.

    Don't try to test the equivalence of the old and new algorithms
    for file name translation, since that test code has been deleted.

compiler/analysis.m:
compiler/compile_target_code.m:
compiler/du_type_layout.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.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/make.util.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:
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.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the changes in file_names.m.
2023-07-04 18:22:42 +02:00
Zoltan Somogyi
edeb58bc16 Start using the new code in file_names.m.
compiler/file_names.m:
    Change the argument vectors of the predicates that compute filenames
    by taking *two* arguments to specify the extension: adding an argument
    value of the "newext" type right after the old "ext" type. To make this
    possible, export the newext type.

    By default, use the new argument to do every filename computation twice,
    with the old and new algorithms, throwing an exception if their results
    differ. (There is no easy way to test whether the "make-any-needed-dirs"
    part was done the same way, but this is reasonably easy to check
    visually in the code.)

    In case an exception does get thrown, this can be suppressed (hopefully
    after the exception being reported) by setting the environment variable
    "NO_EXT_CHECKS" to any value.

    Add representations of "get the value of this extension from this option"
    style extensions to the newext type, for each of the options that the
    compiler uses this way. The one exception is java_object_file_extension,
    which was used in this way, but which had no code handling it in
    file_names.m.

    Add a representation of ".$(EXT_FOR_PIC_OBJECTS)" as a value
    to the newext type.

    Shorten some function symbol names in the newext type and its components,
    to make them easier to fit without excessive line lengths in the modules
    listed below.

compiler/analysis.file.m:
compiler/analysis.m:
compiler/compile_target_code.m:
compiler/du_type_layout.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.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.track_flags.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_make_hlds.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.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Pass extensions as ext/newext pairs, not just as exts.

    To make this possible, change functions and predicates that returned
    just old-style extensions to return new-style extensions as well.

compiler/make.program_target.m:
    Pass extensions as ext/newext pairs, not just as exts.

    Add an XXX about java_object_file_extension for Julien, since he added
    this option (in 2001 :-().
2023-06-07 18:46:48 +02:00
Zoltan Somogyi
a47de48c4d s/input_stream/text_input_stream/ ...
... and the same for output streams.
2023-04-24 14:59:20 +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
Julien Fischer
abc65f4d05 Improvements to the Java launcher scripts.
Add new options that allow Java runtime flags to be set in the launcher scripts
we generate for executables in the Java grade.

compiler/options.m:
     Add two new options: --java-runtime-flags and --java-runtime-flag
     that can be used to embed flags for the Java interpreter in the
     launcher scripts we generate for Java grade executables.

     Add --javac-flags and --javac-flag as synonyms for --java-flags
     and --java-flag respectively.

     Rename the corresponding values of the option/0 type to
     java_compiler_flags and quoted_java_compiler_flag respectively.

     Extend the documentation of --java-classpath to say that it also
     affects the Java launcher scripts.

compiler/module_cmds.m:
     Include any user-specified Java runtime flags in the launcher
     scripts.

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

doc/user_guide.texi:
     Document the above option changes and additions.

     Document how the launcher scripts interact with with the new
     options and also with --java-classpath.

NEWS:
    Announce the above changes.
2022-07-23 11:45:03 +10:00
Zoltan Somogyi
158e0cba50 Fix another typo. 2022-05-24 00:33:07 +10:00
Zoltan Somogyi
50a9c18459 Fix typo. 2022-05-24 00:29:22 +10:00
Zoltan Somogyi
4271be1856 With -v, print a command before printing "done". 2022-05-04 08:55:06 +10:00
Julien Fischer
6d0b861913 Specialise file copying in the compiler.
Specialise the Mercury implementation of file copying in the compiler by
avoiding the use of io.binary_input_stream_foldl_io/5. This allows us to avoid
a higher-order call each time a byte is written and it allows us to use the
unboxed version of the predicate that reads bytes. The other reason for this
change is that we are planning to deprecate (and eventually remove)
io.binary_input_stream_foldl_io/5.

compiler/module_cmds.m:
    As above.

    Add a comment about improving the Mercury implementation of file copying.

    Fix spelling in a spot.

library/io.m:
    Refer to the Boolean constant yes/0 and no/0 in C code as MR_YES
    and MR_NO respectively, rather than MR_TRUE and MR_FALSE.
2022-04-24 19:30:14 +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
c30a59a222 Simplify comparisons between x.int and x.int.tmp.
compiler/module_cmds.m:
    Read in both files as a single string each and compare the strings,
    instead of comparing the files' bytes one-by-one using higher order code.
    The new code is much, much simpler. It does always read in all of
    both files while the old code would stop at the first difference, but

    - the usual case is that the interface of a file does not change
      after the source file itself changes, and

    - the new code should have significantly lower constant factors,
      so the speedup on "no difference" cases should balance any slowdown
      on "there is a difference" cases.

    The old code could also handle non-text files, but if the compiler
    ever puts non-text bytes into interface files, we have bigger problems
    than possibly invalid comparison results.
2022-03-15 12:22:23 +11: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
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
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
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
0956814c5f Copy a file in bulk. 2021-07-25 02:32:55 +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
722de9a372 Look for only relevant .class files.
library/dir.m:
    Add a new predicate general_foldl2. Unlike foldl2 and recursive_foldl2,
    this predicate can be asked to keep going after finding errors,
    in which case it will return a structured description of those errors.

    To make this possible, generalize the infrastructure shared by foldl2,
    recursive_foldl2 and now general_foldl2.

NEWS:
    Announce the new predicate.

compiler/module_cmds.m:
    Use the new predicate instead of recursive_foldl2 when looking for
    .class files to build Java archives from. Doing so means that when
    e.g. bootcheck runs several test cases at the same time in the same
    directory, the traversal in one test case will NOT stop when a different
    test case deletes one of its .class files between the time the first test
    case has read a directory, and the time it gets around to processing those
    entries. Instead, general_foldl2 will simply return an error description
    in each such case. If an error description is for a file that is not
    relevant to the current test case, we will now ignore it.

    This should eliminate many spurious test case failures in Java grades
    that were caused by such interference between test cases. Unfortunately,
    spurious test failures still happen for other reasons :-(
2021-05-16 11:07:12 +10: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
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
409cbcb6a3 Unify getopt.m and getopt_io.m ...
... using an approach proposed by Peter, with an extra twist from Julien.

Instead of having two modules, getopt.m and getopt_io.m, with the former
defining predicates that do not take an I/O state pair, and the latter
defining predicates that do take an I/O state pair, put both kinds of
predicates into a single module. The versions with an I/O state pair
have an "_io" suffix added to their names for disambiguation.
Both versions are a veneer on top of a common infrastructure,
which relies on a simple type class to implement the operation
"give the contents of the file with this name". The predicate versions
with I/O state pairs have a normal implementation of this typeclass,
while the predicate versions that do not have I/O state pairs
have an implementation that always returns an error indication.

The above change just about doubles the number of exported predicates.
We already had two versions of most exported predicates that differed
in whether we returned errors in the form of a string, or in the form
of a structured representation, with names of the latter having
an "_se" suffix. Since we agreed that the structured representation
is the form we want to encourage, this diff deletes the string versions,
and deletes the "_se" suffix from the predicate names that used to have them.
(It still remains at the end of the name of a type.) This "undoubling"
should offset the effect of the doubling in the previous paragraph.

Eventually, we want to have just one module, getopt.m, containing
the updated code described above, but for now, we put the same code
into both getopt_io.m and getopt.m to prevent too big a shock to
people with existing code that uses getopt_io.m.

library/getopt.m:
library/getopt_io.m:
    Make the changes described above.

library/Mmakefile:
    Instead of building both getopt_io.m and getopt.m from getopt_template,
    build getopt.m from getopt_io.m.

tools/bootcheck:
    Delete references to getopt_template.

compiler/typecheck_errors.m:
    When a type error involves one of the getopt/getopt_io predicates
    whose interfaces are changed by this diff, tell the user about
    how these changes could have caused the error, and thus what the
    probable fix is.

compiler/handle_options.m:
browser/parse.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_create_feedback.m:
deep_profiler/mdprof_dump.m:
deep_profiler/mdprof_procrep.m:
deep_profiler/mdprof_report_feedback.m:
deep_profiler/mdprof_test.m:
profiler/mercury_profile.m:
slice/mcov.m:
slice/mdice.m:
slice/mslice.m:
slice/mtc_diff.m:
slice/mtc_union.m:
tests/hard_coded/space.m:
    Use the updated getopt interface.

compiler/compile_target_code.m:
compiler/compute_grade.m:
compiler/deforest.m:
compiler/det_report.m:
compiler/format_call.m:
compiler/globals.m:
compiler/goal_expr_to_goal.m:
compiler/make.build.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/ml_top_gen.m:
compiler/module_cmds.m:
compiler/op_mode.m:
compiler/optimization_options.m:
compiler/options.m:
compiler/write_module_interface_files.m:
tools/make_optimization_options_middle:
tools/make_optimization_options_start:
    Replace references to getopt_io.m with references to getopt.m.

tests/invalid/getopt_io_old.{m,err_exp}:
tests/invalid/getopt_old.{m,err_exp}:
tests/invalid/getopt_old_se.{m, err_exp}:
    New test cases for the extra help

tests/invalid/Mmakefile:
    Enable the new test cases.
2020-10-09 19:30:46 +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
dbd19430ef Use full error_specs instead of pieces.
compiler/compile_target_code.m:
compiler/fact_table.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/module_cmds.m:
compiler/pred_table.m:
    Replace calls to write_error_pieces* with code that constructs
    full error_specs and then writes them out.

compiler/error_util.m:
    Add a new phase, phase_fact_table_check, for the new code in fact_table.m.
2020-06-04 13:58:00 +10:00