Commit Graph

1067 Commits

Author SHA1 Message Date
Zoltan Somogyi
baf1395d7d Disable the two new caches in make.deps_cache.m.
They turned out to have a zero hit rate, making them useless.

compiler/make.dependencies.m:
    Add code to use the two new caches, indirect_imports_non_intermod
    and anc0_dir1_indir2_non_intermod. I got statistics on their
    performance while they were enabled, but since their hit rate was zero,
    this diff includes them only in a commented-out form.

    Note that adding the second cache required adding a new dep_spec,
    which remains, since it shouldn't affect performance at all.

compiler/make.deps_cache.m:
    Disable the those two caches.

    Fix an issue where the original statistics-gathering code
    mixed up hits and misses.

    Include the statistics gathered in course of implementing this diff.

tools/make_deps_cache_stats:
    Update this script to fix the hit/miss issue, and to print more info.
2023-10-16 16:03:06 +11:00
Zoltan Somogyi
0c59ce923c Gather statistics about make.deps_cache.m.
compiler/make.deps_cache.m:
    Add conditionally-compiled code to count the search and addition
    operations on each cache, as well as code to write out these counts.

    Where a cache has two versions, one for intermod and non-intermod
    operations, put the non-intermod version first, since it is more basic.

    Add two new non-intermod cache versions that are not used yet,
    but whose intermod versions are used: one for non-intermod
    indirect imports, and one for non-intermod anc0_dir1_indir2.
    For the latter, include "intermod" in the name of the old cache,
    which uses intermodule information.

compiler/make.make_info.m:
    Add those two caches, and follow the updated order and names of the caches.

compiler/mercury_compile_main.m:
    Call make.deps_cache.m to dump out its cache, it it was enabled
    and gathered any info.

compiler/make.m:
    Make make.deps_cache.m visible from outside the make package,
    in order to make possible the change top mercury_compile_main.m above.

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

tools/make_deps_cache_stats:
    A new script to summarize the information recorded by the new code.
2023-10-15 12:36:47 +11:00
Zoltan Somogyi
104a8ebd9e Get "make cs"/"mmc --make x.cs" to build a C# file ...
... instead of building a bunch of .c files.

Our tradition of adding an "s" at the end of a suffix to mean "all of the
files with the original suffix" had a problem when we added C# as a target
language. Until then, just as "os" stood for ".o files" when it occurred
as either a mmake target, mmc --make target, or mmake variable name component.
"cs" likewise stood for ".c files", but was now also needed to mean ".cs file".
We coped by keeping "cs" meaning ".c files", and adding "csharp" as a target
name synonym to mean ".cs file".

This diff keeps that synonym, but it changes

- the name needed to refer to ".c files" from "cs" to "all_cs"
- the name needed to refer to ".o files" from "os" to "all_os"
- the name needed to refer to ".pic_o files" from "pic_os" to "all_pic_os"
- the name needed to refer to ".cs files" from "css" to "all_css"
- the name needed to refer to ".java files" from "javas" to "all_javas"
- the name needed to refer to ".opt files" from "opts" to "all_opts"
- the name needed to refer to ".trans_opt files"
        from "trans_opts" to "all_trans_opts"

It would be nice if we could apply this same change to all other similar
target names and mmake variable name suffixes, such as "ints" and "int3s",
but some of those names are already in use to mean semantically different
things. All of the names above that used to have the form "<ext>s" and
now have the form "all_<ext>s" stood for all the files with extension
".<ext>" that are prerequisites for building a linked target, i.e.
an executable or a library. But the mmake variable name suffixes
".all_mihs", ".all_mhs" and ".all_int0s" each stand for something subtly
different: the names of files that *may or may not exist", but which,
if they do exist, should be deleted by a clean or realclean target.

To make this breaking change easier to handle by users, this diff does
not simply redefine the meaning of ".all_int0s". (It does change the meaning
of the "cs" target, but the fact this will happen at some time has been
announced ages ago.) Instead, it defines three new mmake var suffixes,
".mihs_to_clean", ".mhs_to_clean" and ".int0s_to_clean", which are
synonyms for ".all_mihs", ".all_mhs" and ".all_int0s" respectively,
and announces that ".all_mihs", ".all_mhs" and ".all_int0s" are being
deprecated, and will have the above change of semantics applied to them
in the future.

NEWS.md:
    Announce the breaking change.

compiler/make.top_level.m:
    Stop treating the target "cs" as meaning "build all the .c files
    for this program".

    The code of classify_target_2 has long been semidet, but only in a way
    that was not apparent to the compiler. Change the code to allow the
    compiler to see its semidet nature while keeping the algorithm the same,
    except for the change in the paragraph above.

    This includes keeping e.g. "ints" as meaning "build all the .int/.int2
    files needed by this program".

compiler/write_deps_file.m:
    Stop generating mmake variables with suffixes ".cs", ".os", ".pic_os",
    ".javas" and ".css". The mmake variables with suffixes ".all_cs",
    ".all_os", ".all_pic_os", ".all_javas" and ".all_css" already existed.
    All had the same value as the mmake variable without the "all",
    with one exception: ".cs". However, in this case, the old (and still
    current) value of ".all_cs" is what the value of ".cs" *should* have been.

    Simplify some code.

The following changes in compiler/*.m are only cosmetic, but they helped me
rule out possible sources of problems with incomplete versions of this diff.

compiler/file_names.m:
    Add a version of a fact_table_file_name_return_dirs which does not
    return directories, since most of its callers don't need that info.

compiler/make.program_target.m:
    Clarify code by making variable names more descriptive,

compiler/make.file_names.m:
compiler/make.module_target.m:
    Conform to the changes above,

browser/Mmakefile:
compiler/Mmakefile:
deep_profiler/Mmakefile:
grade_lib/Mmakefile:
library/Mmakefile:
mdbcomp/Mmakefile:
mfilterjavac/Mmakefile:
profiler/Mmakefile:
slice/Mmakefile:
ssdb/Mmakefile:
    Rename os to all_os, cs to all_cs, css to all_css, javas to all_javas,
    and opts to all_opts. (There were no occurrences of trans_opts to rename.)

    Replace [s as sh command names in actions.

scripts/Mmake.vars.in:
    Specify the names of mmake variables holding the names of sets of files
    with a given extension directly, since for some of them, adding an "s"
    at the end of the name of the extension does not generate the name
    of the corresponding mmake variable anymore.

scripts/Mmake.rules:
    Use the directly specified mmake variable names from Mmake.vars.in
    in the rule for installing lbraries. Temporarily add some debugging
    output to make suree that the updated nested mmake variable references
    work as intended.

tools/bootcheck:
    Specify the names of mmake targets for making all the files in a program
    with a given extension directly, since adding an "s" at the end of the
    name of the extension does not generate the name of the corresponding
    mmake target anymore.

    Print timestamps around the action of checking namespace cleanliness,
    to allow the time taken by that action to be measured. (I kept track
    of bootchecks as they happened while working on this diff, and found
    this time to be nontrivial.)
2023-10-05 02:03:47 +11:00
Zoltan Somogyi
7d2a649b66 Implement new machinery in make.dependencies.m.
compiler/make.dependencies.m:
    The task of this module is to find which source files are needed
    to build each target file of an "mmc --make" invocation.
    (In this case, "source" and "target" files mean the files
    on the right and left hand sides of a make rule respectively.)

    The original machinery used for this purpose used three-level towers
    of closures, which made the code hard to read and to understand, and
    also made it effectively impossible to change the argument list
    of any of the predicates involved without also making the same change
    to all the other predicates used at the same tower level.

    This diff implements new machinery that replaces the towers of closures
    with

    - explicit data structures, to take over for the data in the closures, and
    - simple code walking over those data structures, to take over for
      the code in the closures.

    The new machinery is intended to replace the old machinery after
    a trial period of a week or two. Until then, we execute all operations
    using both the old and the new machinery, and compare their outputs.
    During a bootcheck in csharp grade, the comparisons detect differences
    only in about half a dozen test cases, and it is not clear whether
    they are actually due to the new machinery doing different things
    than the old machinery, or due to the same actions being repeated.

    Note that some of the infrastructure used by both sets of machinery
    still uses the old approach; switching it over to the new approach
    is future work.

    The new machinery also lacks (most of) the caches used by
    the old machinery. Adding caches to the new machinery is also future work,
    because the new machinery is more flexible in *what* can be cached
    reasonably conveniently, and therefore it is not clear whether the
    set of things cached by the old machinery is also the best set of
    things for the new machinery to cache.

    The execution of both machineries and this lack of caching by
    the new machinery will affect performance for probably a couple of weeks.

    Add comments marked with "XXX MDNEW" about ideas for future improvements.

    Add infrastructure to debug both this diff, and some other issues.

compiler/make.find_local_modules.m:
    Add infrastructure to debug some other issues.

tools/bootcheck:
    Delete the tests/*/Mercury directories before starting the execution
    of the test suite. Without this, the files left in there by one bootcheck
    can influence the outcome of the next bootcheck.

    Change the naming scheme we use to record the timestamp of files
    in the TEST_FAILS directory. The old scheme included colon characters,
    which don't play nice with some of my personal scripts :-(
2023-10-02 18:14:41 +11:00
Zoltan Somogyi
e03c2faf63 Gather stats on write_deps_file's file name creation.
compiler/write_deps_file.m:
    Move the filename creation code to the end of the file. Expand it
    with conditionally-enabled code that gathers statistics about the
    hit rate of the file name cache for each extension, and document
    its result, which validates the existing approach.

    Document an approach that looks like would speed up the file name
    creation process, but does not.

compiler/mercury_compile_main.m:
    Call a new predicate in write_deps_file.m to dump out the statistics
    it gathered, if there are any.

tools/write_deps_file_stats:
    A new script to summarize the raw data dumped out by write_deps_file.m.

library/dir.m:
    Improve indentation.
2023-09-08 12:12:31 +10:00
Zoltan Somogyi
ad34bf8d84 Ignore expected stage 2/3 differences for java.
tools/bootcheck:
    Ignore differences between the stage 2 and stage 3 .java files
    where those differences are caused by the fact that the stage 1
    compiler, when generating the stage 2 .java files, is not allowed
    to evaluate calls to int.\ (the one's complement operator)
    at compile time, due to the host machine having 64 bit ints
    and the java target having 32 bit ints.
2023-09-07 08:54:27 +10:00
Zoltan Somogyi
e361ab8fe4 Ignore expected stage 2/3 differences for csharp.
tools/bootcheck:
    Ignore differences between the stage 2 and stage 3 .cs files
    where those differences are caused by the fact that the stage 1
    compiler, when generating the stage 2 .cs files, is not allowed
    to evaluate calls to int.\ (the one's complement operator)
    at compile time, due to the host machine having 64 bit ints
    and the csharp target having 32 bit ints.
2023-09-06 16:22:34 +10:00
Zoltan Somogyi
1694639312 Enable constant propagation at -O2. 2023-08-18 13:14:40 +02:00
Zoltan Somogyi
30f302f348 Make tools/make_optimization_options update options.m.
tools/make_optimization_options:
    Instead of generating a file to be manually copied into the middle
    of compiler/options.m, do that update automatically.

compiler/options.m:
    Mark both ends of the region whose contents are controlled by
    tools/make_optimization_options.
2023-08-18 13:09:48 +02:00
Zoltan Somogyi
a7e6f06262 Enable constant propagation at -O3. 2023-08-18 11:56:39 +02:00
Zoltan Somogyi
43dd12bd5b Merge consecutive switches on the same variable.
compiler/simplify_goal_conj.m:
    When a switch on a variable is followed by a switch on the *same* variable,
    merge the two switches together, if doing so looks like it can save
    the execution of some branches for at least some input values.

    This transform is the second one to merge the goal following a switch
    into the switch itself. Move the parts of the code involved that are
    common between the two transformation to its caller, to reduce runtime
    overhead.

compiler/simplify_goal.m:
    Add infrastructure for printing the pre- and post-simplification versions
    of specific goals. This helped debug the new code in simplify_goal_conj.m.

    Fix an inadvertent unification between two module_infos.
    This was caused by code that

    - defined the variable ModuleInfo, and then
    - reuses the "ModuleInfo" variable name for a slightly different purpose,
      but did so in the condition of an if-then-else, where the semidet nature
      of the implicit unification between the new value intended to be assigned
      to ModuleInfo, and its old value, was expected.

compiler/simplify_proc.m:
    Add infrastructure for printing versions of the procedure body
    before and after quantification, instmap delta recomputation, and
    determinism analysis have been rerun. This helped debug the new code
    in simplify_goal_conj.m.

The rest of the changes concern the option that

- previously called only for the existing transformation to merge a test
  unification following a switch into a switch

- and which now also calls for the merging of two succesive switches
  on the same variable.

compiler/options.m:
    The option was named test_after_switch; this diff updates its name to
    merge_code_after_switch.

compiler/handle_options.m:
compiler/simplify_info.m:
compiler/simplify_tasks.m:
compiler/optimization_options.m:
tools/make_optimization_options_db:
tools/make_optimization_options_end:
    Conform to this name change.
2023-08-17 12:10:13 +02:00
Zoltan Somogyi
88d4bccdba Add new optimization option --split-switch-arms.
Given a switch arm that matches several cons_ids, and which contains
one or more switches on the *same* variable, such as the arm for
f1/f2/f3/f4 below,

    (
        (X = f1 ; X = f2 ; X = f3 ; X = f4),
        ...
        (
            X = f1,
            ...
        ;
            (X = f2 ; X = f3),
            ...
        ;
            X = f4,
            ...
        ),
        ...
    ;
        ...
    )

this new optimization

- partitions the set of cons_id in that arm (in this case, {f1,f2,f3,f4})
  as finely as needed by any other the switches on X in that arm
  (in this case, that is three partitions containing {f1}, {f2,f3} and {f4}),

- splits that original switch arm into N arms, one arm for each partition,
  making a copy of the switch arm's goal for each partition,

- restricts any switches on the original switch variable (in this case, X)
  inside the copy of the arm goal inside each new case to only the cons_ids
  in that case's partition, and then replacing any resulting one-arm switches
  with the just goal inside that one arm.

The code resulting from these three steps will include some code duplication
(some of the pieces of code denoted by ... in the example above would be
duplicated), but it will need to execute fewer transfers of control.
This is worthwhile because (a) the branch instructions used to implement
switches are hard to predict unless most paths through the nested switches
are rarely if ever taken, and (b) the pipeline breaks caused by branches
that are not correctly predicted are one of the two major contributors
to the runtime of Mercury programs. (The other major contributors are
data cache misses.)

The implementation of this option has two major parts.

- Part 1 consists of discovering whether a procedure body contains
  any code in which a switch on a variable is nested inside an arm
  of another switch on that same variable. For any instance of such
  a pair of switches, it records the identity of the variable and
  the set of cons_ids of the outermost arm.

- Part 2 consists of actually transforming the procedure body
  by splitting each outermost switch arm thus recorded. (This part
  contains all three of the steps above.)

We integrate part 1 with the usual procedure body traversal of the
simplification pass, which makes it quite cheap. In most procedure bodies,
it won't find any nested switches meeting its criteria. We execute part 2,
which is relatively expensive, only if it does.

compiler/simplify_info.m:
    Add a new type, switch_arm, which represents one arm of a switch.

    Add a new field to the simplify_nested_context type. Its type
    is list(switch_arm), and it represents the stack of switch arms (if any)
    that the goal currently being simplified is inside. simplify_goal_switch.m
    uses this field to detect switches that occur inside an arm of an
    ancestor goal that is also a switch on the same variable.

    Add a new field to the simplify_info, a set of switch_arms,
    that denotes the set of switch arms from which that detection
    has actually happened, and which should therefore be
    partitioned and split.

compiler/simplify_goal_switch.m:
    Add the code for doing the detection and recording mentioned just above.
    This is the Part 1 mentioned above.

compiler/split_switch_arms.m:
    This new module implements the splitting up process.
    This is the Part 2 mentioned above.

compiler/simplify.m:
    Include the new module in the simplify subpackage of the check_hlds
    package.

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

compiler/simplify_proc.m:
    Invoke split_switch_arms.m (part 2) if the part of simplify_goal_switch.m
    implementing part 1 has found any work for it to do.

compiler/simplify_tasks.m:
    Add split_switch_arms as one of the tasks that simplification
    may be asked to do. Set its default value from the value of
    a new optimization option that, when specified, calls for it to be done.

compiler/options.m:
    Add this option, --split-switch-arms.

    Change the internal name of an existing option,
    everything_in_one_c_function, to the one expected by
    tools/make_optimization_options_middle.

    Replace the part of this file that is constructed by
    tools/make_optimization_options_middle.

doc/user_guide.texi:
    Document the new option.

tools/make_optimization_options_db:
    Add --split-switch-arms to the optimization tuple.

    Fix software rot by

    - renaming optimize_tailcalls to optimize_mlds_tailcalls inside the
      optimization tuple, as it has been in options.m, and

    - deleting erlang_switch_on_strings_as_atoms from the opt_tuple,
      as it has been from options.m.

tools/make_optimization_options_end:
    Enable the new option by default at optimization level 2.

tools/make_optimization_options_middle:
    Fix bugs in this script, which generates compiler/optimization_options.m.

    One bug was that it referred to the opt_level and opt_space options
    by the wrong name (optopt_level and optopt_space respectively).
    The other bug was that it expected opt_level to be a string_special option,
    when it is an int_special option.

    Make the handler_file this script generates easier to put into options.m
    by not generating a line that (a) already exists in options.m, and
    (b) would need to have a comma put after it, if one wanted this line
    to replace the copy already in options.m.

compiler/optimization_options.m:
    Rebuild this file after the changes above.

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

compiler/inst_merge.m:
    Mark two predicates, inst_merge_[34], to be inlined. The intention
    is that inst_merge_4 should be inlined into inst_merge_3, and then
    inst_merge_3 should be inlined inside inst_merge_2; that would then
    generate six levels of switches, three on one of the insts to be
    merged and three on the other, which the new optimization could
    then flatten. Unfortunately, inlining does not do this yet.

tests/hard_coded/test_split_switch_arms.{m,exp}:
    A new test case for the the new transformation.

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
    Enable the new test case, and specify the new option for it.
2023-07-24 19:14:17 +02:00
Zoltan Somogyi
b75dab7fdf Add the option --inst-statistics.
compiler/options.m:
    Add --inst-statistics as a developer-only option.

compiler/hlds_statistics.m:
    Add code to gather and write out statistics about how frequently
    each function symbol of the mer_inst type occurs in (a) the instmaps
    of procedures' goals, and (b) in the automatically generated inst
    tables.

compiler/mercury_compile_front_end.m:
    Invoke the new code if the new option is specified.
    (The code to do so is a near-copy of the nearby code for invoking
    the other functionality in hlds_statistics.m.)

tools/inst_stats:
    Add this tool for summarizing the statistics generated by the new option.
2023-07-18 12:11:33 +02:00
Zoltan Somogyi
6d00821f0d Represent environments using a bespoke type.
compiler/mlds.m:
    Add the type mlds_env_defn, which is a version of mlds_class_defn
    that is specialized to represent the environment structures we use
    in the MLDS backend to implement model_non continuations. The original
    mlds_class_defn has 13 fields; mlds_env_defn has only three. This
    difference effectively encodes a whole lot of invariants about
    environments. Not only does it omit fields of mlds_class_defns
    that are always the same for all environments, it also omits
    fields of mlds_class_defns that can differ between target languages
    but which are always the same for any given target language.
    These differences are implemented by mlds_to_*_class.m.

    Add mlds_env_id as a new type to represent the ids of environment
    structures.

    Add mlds_env_type as a new function symbol in the mlds_type type
    to represent the type of environment structures.

    Include a list of mlds_env_defns in the MLDS representation of the
    translated module.

compiler/ml_elim_nested.m:
    Generate mlds_env_defns instead of mlds_class_defns to represent
    environment structures.

compiler/mlds_to_c_class.m:
compiler/mlds_to_cs_class.m:
compiler/mlds_to_java_class.m:
    Add code to write out mlds_env_defns. In each case, this code is
    a version of the code to write out mlds_class_defns, specialized
    to the invariants of environment structures.

compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
    Call the new code in mlds_to_X_class.m.

compiler/ml_rename_classes.m:
    Add utility predicates for operating on environment structures.

compiler/mercury_compile_mlds_back_end.m:
compiler/ml_accurate_gc.m:
compiler/ml_lookup_switch.m:
compiler/ml_simplify_switch.m:
compiler/ml_top_gen.m:
compiler/mlds_dump.m:
compiler/mlds_to_c_data.m:
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_stmt.m:
compiler/mlds_to_c_type.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_type.m:
compiler/mlds_to_java_data.m:
compiler/mlds_to_java_type.m:
    Conform to the changes above.

tools/bootcheck:
    Redirect the input of mmake in each test directory to come from
    /dev/null, to avoid bootchecks in the Java grade being temporarily
    suspended for input from the terminal.
2023-07-14 03:48:22 +02:00
Julien Fischer
d250940f94 Update bootcheck script.
tools/bootcheck:
    The gc.mak file in the boehm_gc directory no longer
     exists.
2023-07-12 21:23:17 +10:00
Peter Wang
4097f96077 Don't expect .git to be a directory.
tools/build_srcdist:
    Proceed if .git exists but is not a directory - it may be a file.
2023-07-12 13:44:26 +10:00
Julien Fischer
0e8ad1ea39 Fixes for the bootcheck script on Windows.
tools/bootcheck:
    Fix the setting of the WORKSPACE variable when running the tests.
    Due to incorrect use of pwd it was actually pointing back at stage 1.

    If we are running under MSYS2, then set --windows automatically.
    (It's too easy to forget to do this otherwise.)

    Mention this in the documentation for the --windows option. Also,
    the --windows option does not imply anything about the library
    extension -- despite what the usage message has claimed for many
    years.
2023-07-09 20:27:20 +10:00
Julien Fischer
89e7b02836 Handle .lib suffix in lmc script.
tools/lmc.in:
    As above.
2023-07-01 02:01:20 +10:00
Julien Fischer
cabc3d016b Delete stage 2 .obj files.
tools/boocheck:
    As above.
2023-06-29 13:54:59 +10:00
Julien Fischer
adda9be7ea Fix misformed option name.
tools/bootcheck:
    As above.
2023-06-17 20:56:09 +10:00
Julien Fischer
78a61dfa23 Make the test suite work with MSYS2.
tools/bootcheck:
    On MSYS2, translate paths written to .options and _FLAGS files into
    Windows-style paths.

    On MYS2, pass -u and --strip-trailing-cr to diff.
2023-06-13 21:19:41 +10: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
32efc77039 Add tools to find too-long lines.
tools/line_len_stats:
    A new script that computes and prints a histogram of the line lengths
    in the input given to it.

tools/find_long_lines:
    A new script that, when given a line length and a list of filenames,
    prints out the location of the lines in those files that are longer
    than the given line length.
2023-05-15 11:37:13 +10:00
Zoltan Somogyi
8df602b2da Simplify keeping track of test failures.
tools/bootcheck:
    If a directory named TEST_FAILS exists in the top level directory.
    copy tests/UNEXPECTED_FAILED_TESTS to that directory, with a name
    that contains (a) the grade, and (b) the date and time. A diff between
    two of these files with the same grade but different times will make
    it easy to see which test failures are *new*.
2023-05-08 22:09:24 +10:00
Zoltan Somogyi
b6178ef723 Delete prog_out.m, moving its code to other modules.
compiler/parse_tree_out_cons_id.m:
    Move the predicates and functions in prog_out.m that deal with cons_ids
    to this module.

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

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

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

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

compiler/prog_out.m:
    Delete this module.

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

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

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

tools/filter_sort_imports:
    Automatically filter out any repeated imports. This can help with
    changes like this that redistribute the contents of one module to other
    modules. In this case, after a global replacement of prog_out's import
    with the import of parse_tree_out_misc, this updated script could
    remove this changed import from modules that already imported
    parse_tree_out_misc.
2023-04-09 16:23:13 +10:00
Peter Wang
b0ae10248b Use --trans-opt-deps-spec option.
Use the recently added --trans-opt-deps-spec option to break cycles in
the trans-opt dependency graph for the standard library. This enables
more parallelism when making the .trans_opt files; it now takes about
half as long as before.

Ordering modules sensibly, so that .trans_opt files are created in a
logical order, also improves analysis results for many predicates and
functions. The only results which show a regression with this change are
for deprecated forwarding predicates/functions.

In future, we will probably be able to trim more dependencies to further
improve parallelism, without impacting analysis results.

configure.ac:
    Check that the bootstrap compiler supports --trans-opt-deps-spec.

library/mer_std.trans_opt_deps_spec:
    Add the spec file that adjusts dependencies in the trans-opt
    dependency graph.

library/INTER_FLAGS:
    Use the --trans-opt-deps-spec option when building with mmake.

scripts/prepare_install_dir.in:
tools/binary:
tools/bootcheck:
tools/unary:
    Copy mer_std.trans_opt_deps_spec when preparing a copy of the
    library directory.
2023-01-25 16:48:45 +11:00
Julien Fischer
feb8b49b54 Avoid a warning from shellcheck.
tools/bootcheck:
    As above.
2022-12-31 13:37:59 +11:00
Zoltan Somogyi
86657c4b01 Minor style fixes. 2022-12-31 06:48:25 +11:00
Julien Fischer
0153d38646 Do not hardcode sed in the bootcheck script.
tools/bootcheck:
    Allow the executable name used for sed to be overridden
    in the environment. (This is useful for using the GNU
    version of sed on macOS instead of the one it ships with.)
2022-12-30 18:23:31 +11:00
Julien Fischer
d6355e85ee Reduce warnings from shellcheck in the bootcheck script.
tools/bootcheck.java:
    Use $(...) in preference to `...` for command substitutions.

    Quote variables.

    Abort if we attempt to rm / due to a variable not being set.
2022-12-30 16:17:01 +11:00
Zoltan Somogyi
05ef8e01fb Rename the .ll_debug grade component to .c_debug.
Rename mmc and mgnuc options that set this grade component to --c-debug-grade.
Let the options named --c-debug of both mmc and mgnuc enable C level debugging
of only the module being compiled.

runtime/mercury_grade.h:
    Rename the .ll_debug grade component to .c_debug. Also rename the C macro
    that controls the presence or absence of this grade component
    from MR_LL_DEBUG to MR_C_DEBUG_GRADE.

runtime/mercury_conf_param.h:
runtime/mercury_debug.c:
runtime/mercury_debug.h:
runtime/mercury_engine.c:
runtime/mercury_label.c:
runtime/mercury_memory_zones.c:
runtime/mercury_memory_zones.h:
runtime/mercury_overflow.c:
runtime/mercury_std.h:
runtime/mercury_wrapper.c:
    Rename the MR_LOWLEVEL_DEBUG macro to MR_DEBUG_THE_RUNTIME.
    Previously, the name of this macro wrongly implied that it had
    something to do with the old .ll_debug grade component, even though

    - the MR_LOWLEVEL_DEBUG macro was designed to debug LLDS grades,
      since only these existed when it was created, while

    - the .ll_debug grade component (now .c_debug) is useful only for
      MLDS grades targeting C.

compiler/options.m:
    Rename the old confusingly named low_level_debug option to c_debug_grade.
    Move it to the list of grade options, and fix its documentation, which
    was completely wrong:

    - code in compile_target_code.m treated it as being a synonym of
      the .ll_debug (now .c_debug) grade component, while
    - its (commented out) documentation here in options.m said it called for
      the enabling of what is now MR_DEBUG_THE_RUNTIME.

compiler/compile_target_code.m:
    Conform to the rename just above.

    Define MR_C_DEBUG_GRADE instead of MR_LL_DEBUG if c_debug_grade is enabled.

    Pass -g to the C compiler if either c_debug_grade or target_debug
    is enabled.

    Add an XXX about a missing safety check for an obsolete experimental
    feature.

compiler/compute_grade.m:
    When given a grade with a .c_debug grade component, set only the
    c_debug_grade option; don't set the target_debug option, which is NOT
    a grade option. The change to compile_target_code.m above handles the
    only situation in which this implication was formerly required.

scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
    Look for and process the .c_debug grade component instead of .ll_debug.
    Use a sh variable named c_debug_grade to record its absence/presence.

    Look for and process the --c-debug-grade grade-component option,
    setting the same sh variable, c_debug_grade. (All grade components
    can be set piecemeal using sh options to the scripts using these
    subroutines.) This replaces the old, confusingly named option
    --low-level-debug.

scripts/mgnuc.in:
scripts/mgnuc_file_opts.sh-subr:
    Consistently use the sh variable c_debug to record the presence of
    the (non-grade) --c-debug option to mgnuc, and the sh variable
    c_debug_grade to record the presence of the .c_debug grade component.

    Stop looking for and handling the --low-level-debug option, which
    mgnuc used to document, even though this duplicated the same documentation
    in init_grade_options.sh-subr, which mgnuc includes. The difference was
    that init_grade_options.sh-subr meant it to represent the old .ll_debug
    MLDS grade component, while mgnuc treated it as specifying what is now
    MR_DEBUG_THE_RUNTIME for LLDS grades. It didn't help that two sh variables
    with quite different semantics had names that differed only in an
    underscore: LLDEBUG_OPTS vs LL_DEBUG_OPTS.

scripts/Mmakefile:
    Add a missing dependency to force the rebuild of mgnuc after each update
    of its sh subroutine mgnuc_file_ops.sh-subr.

doc/user_guide.texi:
    Document the --c-debug-grade option of mmc. This option was not publicly
    documented under its original misleading name (--low-level-debug), but
    its documentation is now possible without contorted dancing around the
    name.

    Clarify the documentation of mgnuc's --c-debug option.

README.sanitizers:
configure.ac:
    Conform to the rename of the grade component.

grade_lib/grade_spec.m:
grade_lib/grade_string.m:
grade_lib/grade_structure.m:
grade_lib/try_all_grade_structs.m:
    Conform to the rename of the grade component .ll_debug to .c_debug.

    Don't allow the .c_debug grade component in LLDS grades.

    In grade_string.m, add some obvious implications of some grade components.

grade_lib/choose_grade.m:
grade_lib/grade_lib.m:
grade_lib/test_grades.m:
grade_lib/var_value_names.m:
    Fix white space.

scripts/ml.in:
tools/lmc.in:
tools/test_mercury:
    Conform to the change in compile_target_code.m to the naming of
    Boehm gc library variants.
2022-12-29 20:33:08 +11:00
Peter Wang
fc1cd53f83 Reduce size of MR_win32_error_name.
All the strings returned by MR_win32_error_name include a common prefix
"ERROR_". Since there are many (1749) such strings, we can reduce the
size of the data by about 10 KB by returning only the part following the
prefix.

tools/generate_windows_error_name:
runtime/mercury_windows_error_name.c:
    Make MR_win32_error_name return strings without the "ERROR_" prefix.

library/io.m:
    Update caller system_error_win32_error_name to add the "ERROR_"
    prefix.
2022-08-29 10:57:39 +10:00
Peter Wang
fbcaaf805a Reduce list of Windows ERROR_ constants.
Fix compilation with older versions of MinGW(-w64) and any other
compilers which don't have as many ERROR_ constants defined.

tools/generate_windows_error_name:
    Reduce the list of ERROR_ constants.

runtime/mercury_windows_error_name.c:
    Regenerate.
2022-08-26 11:12:25 +10:00
Peter Wang
aaa6ac5fe1 Introduce io.system_error to io.m public interface.
Implement the error handling proposals from February 2022 on the
mercury-users list, and August 2022 on the mercury-reviews list.

We add io.system_error to the public interface of io.m
and document what its foreign representation is for each backend.

We allow io.error to optionally contain an io.system_error value,
and provide predicates to retrieve the io.system_error from an io.error.
The user may then inspect the system error via foreign code.

We also provide a predicate that takes an io.error and returns a name
for the system error it contains (if any). This makes it relatively easy
for Mercury programs to check for specific error conditions.

By returning platform-specific (actually, implementation-dependent)
error names, we are pushing the responsibility of mapping strings to
error conditions onto the application programmer. On the other hand, it
is not practical for us to map all possible system-specific error codes
to some common set of values. We could do it for a small set of common
error codes/exceptions, perhaps.

The standard library will construct io.error values containing
io.system_errors. However, we do not yet provide a facility for user
code to do the same.

library/io.m:
    Move io.system_error to the public interface.

    Change the internal representation of io.error to support containing
    a io.system_error. An io.system_error may originate from an errno
    value or a Windows system error code; the constructor distinguishes
    those cases.

    Add predicates to retrieve a system_error from io.error.

    Add predicate to return the name of the system error in an io.error.

    Replace make_err_msg with make_io_error_from_system_error.

    Replace make_maybe_win32_err_msg with
    make_io_error_from_maybe_win32_error.

    Delete ML_make_err_msg and ML_make_win32_err_msg macros.

browser/listing.m:
library/bitmap.m:
library/dir.m:
library/io.call_system.m:
library/io.environment.m:
library/io.file.m:
library/io.text_read.m:
mdbcomp/program_representation.m:
    Conform to changes.

    Leave comments for followup work.

tools/generate_errno_name:
tools/generate_windows_error_name:
    Add scripts to generate mercury_errno_name.c and
    mercury_windows_error_name.c.

runtime/Mmakefile:
runtime/mercury_errno_name.c:
runtime/mercury_errno_name.h:
runtime/mercury_windows_error_name.c:
runtime/mercury_windows_error_name.h:
    Add MR_errno_name() and MR_win32_error_name() functions,
    used by io.m to convert error codes to string names.

tests/hard_coded/null_char.exp:
    Update expected output.
2022-08-23 16:39:48 +10:00
brendanzab
5f1dfc806f Set config vars for darwin in configure_cross
README.cross.md:
    Add darwin targets

tools/configure_cross:
    Add darwin platforms to case switch
2022-08-16 15:57:27 +10:00
Peter Wang
fbf862bf65 Relax regex to detect clang compiler.
tools/configure_cross:
    Relax regex to detect clang compiler on Debian.
2022-07-20 17:18:44 +10:00
Peter Wang
e6cd115484 Initial support for cross-compiling using clang.
README.cross.md:
    Add instructions for cross-compiling using clang.

tools/configure_cross:
    Adapt script to support a FreeBSD x86-64 target using clang.

NEWS:
    Announce change to script.
2022-07-18 17:50:47 +10:00
Peter Wang
5e3516ca5a Convert README.cross to markdown.
README.cross:
    Convert README.cross to markdown.

    Rename to README.cross.md.

.nocopyright:
README.MS-Windows:
README.md:
tools/configure_cross:
tools/copy_mercury_binaries:
    Update references to README.cross.
2022-07-18 17:41:46 +10:00
Julien Fischer
8a61889a6f Fix typo.
tools/bootcheck:
    As above.
2022-06-08 00:09:05 +10:00
Dirk Ziegemeyer
c5ebef1698 Fix cross compiler config: static MXE target
The configure script for the cross compiler did not recognise MXE
targets with a '.static' suffix, e.g. --host=x86_64-w64-mingw32.static
Running the configure script with such a target resulted in an error
message, e.g. 'unknown host: x86_64-w64-mingw32.static'
See https://mxe.cc/ to find examples of valid MXE targets.

tools/configure_cross:
  As above.
2022-04-26 10:46:05 +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
8055577a7f Optimize the common case in instmap_delta_restrict.
compiler/instmap.m:
    Before code generation, the MLDS backend recomputes all nonlocal sets,
    because the MLDS code generator needs them to contain exact information,
    but the compiler's rules allow the nonlocal sets in goal_infos
    to overapproximate the true nonlocals set. Since instmap_deltas can
    contain a variable as a key only if that variable is in the nonlocals set,
    this also involved calling instmap_delta_restrict to ensure this.

    However, while the nonlocals sets of goal_infos *may* include variables
    that are not true nonlocals, they typically do not do so. This diff
    adds conditionally-enabled code to record information about this,
    and the results show that 90+% of calls to instmap_delta_restrict
    make no changes to the instmap_delta. This diff therefore also
    special-cases the handling of such calls. The reason why I believe
    this to be worthwhile is that in a deep profiled compiler run,
    I observed that the instmap_delta_restrict predicate accounted for
    about 1.4% of the call counts, and about 1.3% of the memory allocated.

library/map.m:
library/tree234.m:
    Add the library predicates needed by the special case code.

    Use predmode declarations in some other places.

NEWS:
    Mention the new library predicates.

compiler/mercury_compile_main.m:
    Invoke the predicate in instmap.m that, if statistics collection
    was enabled, appends its results to a file.

tools/restrict_stats:
    A script to summarize the contents of that file.
2022-04-02 16:35:18 +11:00
Julien Fischer
ec24cfaa22 Simplify bootcheck script.
tools/bootcheck:
     Delete support for checking out the tests directory alongside
     the Mercury source tree. This was useful back when we used
     CVS, but has not been relevant since the switch to git.
2022-03-15 14:41:39 +11:00
Zoltan Somogyi
115b2f20f0 Avoid "stage 2 and stage 3 differ" messages ...
... during bootchecks in C# and Java grades by not comparing the generated
.cs and .java files of the few modules that are known to differ between
the two stages for understood reasons.
2022-03-12 21:42:44 +11:00
Julien Fischer
3040c40c47 Another fix for non-C bootchecks.
tools/bootcheck:
    Build stage 3 flags files with --use-mmc-make.
2022-02-05 00:47:38 +11:00
Julien Fischer
fc347cf998 Fix bootchecks in non-C grades.
tools/bootcheck:
    Add a missing line continuation.
2022-02-04 23:34:10 +11:00
Peter Wang
4834b56dcd Add sanity check to tools/import_srcdist.
tools/import_srcdist:
    Check with "git status" that all files in the workspace have been
    added, not ignored.
2022-01-28 10:43:05 +11:00
Julien Fischer
c6ff123a6a Fix a bug in tools/import_srcdist.
tools/import_srcdist:
    Add files with the -f (--force) option; otherwise files that
    match patterns in .gitignore will be ignored.
2022-01-26 23:53:22 +11:00
Zoltan Somogyi
adf6c55847 Shut up mmake actions for check_namespace.
This reduces the size of the output of tools/bootcheck by 3700+ lines,
or about 25%.

Mmake.common.in:
    Don't print the actions implementing namespace cleanliness checks.
    To allow the attribution of any violations of the namespace rules,
    print the name of the C module before any list of detected
    nonallowed symbols.

    To avoid mmake printing the actions for creating the .o files
    that some of the check_namespace actions later check, rename
    the affected object files .pseudo_o files, so that we can specify
    a rule for them that is a copy of the rule for .o files, differing
    only in not printing the compilation command.

    Mark the files involved in check_namespace actions as dependencies
    of .SECONDARY, which means that mmake does not automatically delete them
    after building them as intermediate files. The reason for this is that
    there is no way to tell make to delete intermediate files *silently*,
    i.e. without writing out the rm command that deletes them.
    To make up for this, tools/bootcheck now cleans up each directory
    immediately after "mmake check_namespace" with "mmake clean_check",
    which invokes mmake rules that do not print the rm commands.

    This change does have the effect that these intermediate files *will*
    hang around if the check_namespace target is every invoked manually.
    However,

    - we just about never run check_namespace in a directory manually, and
    - when we do, a simple "mmake clean_check" will do the required cleanup.

scripts/Mmake.rules:
    Move the vim tag line to its usual place at the top.

    Replace old-school rules such as .m.err with their modern equivalents
    (such as %.err: %.m).

scripts/Mmakefile:
    Instead of printing the rules that make test_mdbrc, print only a
    "making test_mdbrc" message.

runtime/Mmakefile:
    Conform to the change of the name of a make variable in Mmake.common.in.

ssdb/Mmakefile:
    Fix an old bug that something else in this diff tickled: make the
    .depend target of each main module depend on SSDB_FLAGS, *not* just
    the phony general "depend" target. This was a bug because tools/bootcheck

    - copied across to stage 2 ONLY SSDB_FLAGS.in, and NOT SSDB_FLAGS,

    - did NOT explicitly make SSDB_FLAGS from SSDB_FLAGS.in, even though
      pretty much invocations of the Mercury compiler in this directory
      have "--flags SSDB_FLAGS" as an implicit argument, and then

    - built dependencies in the ssdb directory by invoking the top
      Mmakefile's dep_ssdb target, which (indirectly) invokes
      $(SSDB_LIB_NAME).depend.

    Due to all the above, I don't actually know how tools/bootcheck
    could ever build stage2/ssdb until now :-(

tools/bootcheck:
    Invoke "mmake clean_check" after each "mmake check_namespace".

    Change the code that explicitly builds the directory-specific
    X_FLAGS file in each directory (which is invoked only when using
    mmc --make) to actually build all such files, when previously
    it built only a subset.

tests/invalid/Mmakefile:
tests/invalid_nodepend/Mmakefile:
tests/invalid_onlydepend/Mmakefile:
tests/invalid_options_file/Mmakefile:
tests/invalid_purity/Mmakefile:
tests/invalid_submodules/Mmakefile:
tests/stm/Mmakefile:
    Fix an unintended consequence of replacing the .m.err rule in
    scripts/Mmake.rules with %.err: %.m, which is that the %.err: %.m
    rules in these mmakefiles became ineffective, because they appear
    in the makefile we construct *after* the rule in scripts/Mmake.rules,
    which specify a different action (the rules here return a nonzero
    status in the *absence* of failure, which would be ridiculous
    for the rule in scripts/Mmake.rules). Apparently, the %.err: %.m rules
    overrode the rule in scripts/Mmake.rules while it had the old form,
    but do not do so now it has the new form.

    The fix is to make replace all the "%.err: %.m" rules in these Mmakefiles
    with "$(PROGS:%=%.err): %.err: %.m" rules, which specify that they
    override the generic rule for the .err files of the test cases
    in each directory.

    In invalid_purity/Mmakefile, fix a bug: -nodepend suffixes make sense
    in only in the name of a *test*, not the name of a *program*, so
    move such a suffix from a program name to a test name. Without this,
    the program's .err file would be included in the list of .err files
    to which the ".err: .m" rule applies under the wrong name.

    In invalid_submodules/Mmakefile, fix the misleading names of some
    make variables, and fix a misspelt directory name.

    Standardize on "$(PROGS:%=%.err)" notation, replacing earlier instances
    of "$(addsuffix .err,$(PROGS))". The reason for this is that when I tried
    using "$addsuffix .int_err,$(PROGS))" in tests/invalid/invalid_make_int,
    it did not work. (A google search on "gnu make addsuffix" did not yield
    any clues as to why. Maybe you can only add suffixes that do not contain
    underscores?)
2022-01-24 17:38:35 +11:00
Zoltan Somogyi
be03537f10 Set up for --warn-stdlib-shadowing.
This diff does not implement the option itself. The reason is that we want
to turn it off in library/LIB_FLAGS.in, and we can do that only when the
installed compiler knows about the option. This diff is therefore the first
step in the two-step bootstrapping process.

compiler/options.m:
    Add a new option --warn-stdlib-shadowing, which, after the bootstrapping
    step, will cause the compiler to warn about module names that could be
    confused with the name of a module in the Mercury standard library.

    Add a new option, --output-stdlib-modules, that tools/bootcheck can use
    to test whether the compiler's list of Mercury standard library modules
    is complete.

    Rename the option name output_class_dir to output_java_class_dir
    (internally only, leaving the user-visible name unchanged), to fit in
    with the names of options related to C#, which have csharp in the name.

compiler/op_mode.m:
    Add a new op_mode for --output-stdlib-modules.

compiler/mercury_compile_main.m:
    Implement the new op_mode, using new code in library/library.m.

    Simplify some existing code.

library/library.m:
    Add an exported but undocumented predicate that mercury_compile_main.m
    can use to

    - find a list of all the Mercury standard library modules, and
    - find out for each whether it is documented or not.

    Reimplement the existing exported-but-undocumented predicate
    in terms of the new one.

library/Mmakefile:
    Add mmake targets that check whether the contents of MODULES_DOC and
    MODULES_UNDOC match the output of mmc --output-stdlib-modules.

tools/bootcheck:
    Use the new mmake targets to do that check.
2021-12-31 00:57:18 +11:00