Commit Graph

303 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Julien Fischer
8a61889a6f Fix typo.
tools/bootcheck:
    As above.
2022-06-08 00:09:05 +10: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
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
Zoltan Somogyi
6413b4fb08 Create invalid_nodepend and invalid_onlydepend.
tests/invalid_onlydepend:
    Move the one test case in tests/invalid for which we want to check
    the error messages generated during the generation of dependencies
    to this new test directory.

tests/invalid_nodepend:
    Move all test cases in tests/invalid which get errors during the
    generation of dependencies but for which we want to check the error
    messages generated during normal compilation to this new test directory.

tests/invalid_nodepend/Mmakefile:
tests/invalid_nodepend/Mercury.options:
tests/invalid_onlydepend/Mmakefile:
tests/invalid_onlydepend/Mercury.options:
    Versions of the same files in tests/invalid, but containing only
    the entries relevant to the moved test cases.

tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
    Delete the entries that refer to the moved test cases.

tests/README:
    Document the two new test directories.

tools/bootcheck:
    Add invalid_onlydepend and invalid_nodepend to the list of
    test directories.
2021-07-28 00:59:04 +10:00
Zoltan Somogyi
439eecf23d Make --test-params the default for bootchecks. 2021-07-27 14:41:38 +10:00
Zoltan Somogyi
6b4712a2fa Report error if specified test dir does not exist. 2021-07-25 14:19:18 +10:00
Peter Wang
c4c840cb7e Delete Erlang backend from configure.
configure.ac:
m4/mercury.m4:
    Delete --enable-erlang-grade configure option.

    Don't search for erlang compiler and interpreter.

    Don't substitute @ERLC@ and @ERL@.

    Don't add erlang to libgrades.

    Don't generate erlang_conf.hrl

library/erlang_conf.hrl.in:
    Delete template file.

.dockerignore:
browser/MDB_FLAGS.in:
compiler/COMP_FLAGS.in:
deep_profiler/DEEP_FLAGS.in:
library/.gitignore:
library/Mmakefile:
library/library.m:
mdbcomp/MDBCOMP_FLAGS.in:
mfilterjavac/MFILTERJAVAC_FLAGS.in:
profiler/PROF_FLAGS.in:
scripts/Mercury.config*.in:
scripts/mercury_config.in:
scripts/prepare_install_dir.in:
ssdb/SSDB_FLAGS.in:
tools/bootcheck:
    Delete references to Erlang .hrl files.

    Delete references to @ERLC@ and @ERL@.
2020-10-27 11:10:11 +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
cf22c0af9a Fix typo. 2020-10-06 23:10:09 +11:00
Zoltan Somogyi
be3f9443b1 Simplify the setup of mdbrc for tests.
We used to set up *two* mdbrc files for use by test cases:
scripts/test_mdbrc, and tests/mdbrc. Tools/bootcheck said
the tests should use the former, while tests/Mmake.common
said they should use the latter. This diff deletes the latter,
and uniformly uses the former.

The setup code was also scattered, with parts being done by
the configure script, and part being done by tools/bootcheck.
Move it all to scripts/Mmakefile, since that is the natural
place to put code to build scripts/test_mdbrc.

Mmakefile:
    Fix the action for cleaning up the tests directory.
    This started out as the reason for this whole change.
    As it happens, a *working* action for cleaning up the tests
    broke things, because it deleted an autoconfigured file
    (tests/mdbrc) that there was no rule for rebuilding.
    This issue is what required the rest of this diff.

    When doing "mmake clean/realclean", clean the extras as well.

configure.ac:
    Delete the code creating tests/mdbrc.in.

scripts/Mmakefile:
    Add a rule to build test_mdbrc, as mentioned above.

tests/Mmake.common:
    Switch to using scripts/test_mdbrc in test cases
    run under mdb.

    Mark the rules that clean up mdbrc and mdbrc.in
    as obsolete, since we will now stop creating those files.

tools/bootcheck:
    Delete the code that used to build tests/mdbrc. Instead,
    rebuild scripts/test_mdbrc (in case the workspace was moved),
    and use that.

tests/Mmakefile:
    When cleaning the tests directory, clean its subdirectories
    (since the top level directory does not have much clean).
2020-10-04 23:00:29 +11:00
Julien Fischer
b3d4fad5bb Do not symlink getopt*.m into stage 2.
tools/bootcheck:
    As above.
2020-09-20 21:55:36 +10:00
Zoltan Somogyi
dd8424045f Ensure the building of getopt.m and getopt_io.m.
library/Mmakefile:
    Ensure that getopt.m and getopt_io.m are built in freshly checked out
    workspaces before starting making the dependencies.

    Include getopt_template as a source file when building the tags file.

tools/bootcheck:
    Copy getopt_template to the stage 2 and 3 libraries, to allow
    the rule for ensuring the existence of the tags file to work.
2020-09-19 07:30:08 +10:00
Zoltan Somogyi
155fbdd7fd Make programming style consistent. 2020-08-09 20:31:46 +10:00
Zoltan Somogyi
c644e8d19f Consistently ${var} instead of $var. 2020-06-13 22:17:28 +10:00
Zoltan Somogyi
ac50b3cbd1 Do not use exceptions in options_file.m.
And add tests for how the compiler handles both valid and invalid
options files.

compiler/options_file.m:
    This diff rewrites options_file.m in a straightforward, direct style that
    returns indications of errors as error_specs rather than as exceptions.
    A recent diff started on this task; this diff finishes it.

    The new approach has several advantages.

    - The control flow is much simpler, and therefore more understandable.
      Correctness arguments for propositions such as "this code closes
      all the file streams that it opens" are now much simpler to make.

    - We now report errors using error_specs, which contain context
      information, while previously, each error was described only
      by a string, without context info.

    - Once we detect and report one error, we can continue to read the
      rest of the input. This allows a single compiler invocation to find
      and report several errors, not just the first.

    - Since we now return the gathered set of error_specs instead of printing
      them, the predicates of this file don't have to take globals structures
      as arguments, which allows our callers to avoid constructing those
      structures.

    - Deep profiling, which cannot handle exceptions, now works on
      the code of this module.

    Change over to using trace goals for debugging prints, since continuing
    to use debug_make_msg would require a globals structure.

    Add an XXX on a likely bug.

    Add a mechanism for writing out a database of variable names and values.

compiler/mercury_compile_main.m:
    Conform to the changes in options_file.m. Document where exactly
    we could avoid constructing a globals just for options_file.m.

    If the right option is given, get options_file to write out the database
    of variable names and values it has just read in, to enable the
    functionality of this module to be tested.

compiler/options.m:
doc/user_guide.texi:
    Add a new developer option, --dump-options-file, to control the above.

compiler/make.build.m:
compiler/make.m:
compiler/make.program_target.m:
    Conform to the changes in options_file.m.

compiler/file_util.m:
    Fix an error message.

tests/Mmakefile:
tools/bootcheck:
    List options_file and invalid_options_file as two new test directories.

    Fix a command in bootcheck.

tests/options_file/Mmakefile:
    Add a mechanism for testing whether options_file.m builds mapping
    from make variable names to values that we expect.

tests/Mmake.common:
    Provide a mechanism for comparing dumped options_files against
    their expected contents, for use by tests/invalid_options_file/Mmakefile.

    Fix a comment.

tests/options_file/basic_test.m:
tests/options_file/basic_test.optfile_exp:
tests/options_file/basic_test.options_file:
tests/options_file/basic_test.options_file.sub0:
tests/options_file/basic_test.options_file.sub1:
    A simple test case for exercising all the usual options_file constructs.

tests/invalid_options_file/Mmakefile:
    Add a mechanism for testing whether options_file.m generates
    the error messages we expect for various kinds of errors in options files.

tests/invalid_options_file/no_assign.{m,options_file,err_exp}:
tests/invalid_options_file/no_var.{m,options_file,err_exp}:
tests/invalid_options_file/nonexistent_file.{m,options_file,err_exp}:
tests/invalid_options_file/undefined_var.{m,options_file,err_exp}:
tests/invalid_options_file/unterminated_string.{m,options_file,err_exp}:
tests/invalid_options_file/unterminated_var.{m,options_file,err_exp}:
    Six test cases to test six different kinds of errors that can be
    detected by options_file.m.
2020-06-12 04:14:00 +10:00
Zoltan Somogyi
1f45f91886 Make "mmake runtests" work again.
My commit afe2887882 broke the ability
to run the test suite outside of a bootcheck by executing "mmake runtests"
in the tests directory. This diff fixes that.

tests/Mmake.common:
    Don't define "TESTS_DIR = ..". While every single tests/*/Mmakefile
    defined it as such, I overlooked the fact that tests/Mmakefile itself
    defined it ".", referring to the same directory from a different starting
    point. Document this easily-overlooked fact.

    Rename the old runtests target, which after afe2887 runs the tests
    in a single directory, as runtests_dir, to leave the target name
    "runtests" itself free for tests/Mmakefile to use.

tests/Mmakefile:
    Define "TESTS_DIR = .", and add a target "runtests" which invokes
    "mmake runtests_dir" in each test directory.

tools/bootcheck:
    Invoke "mmake runtests_dir" instead of "mmake runtests" in each
    test directory.

    Initialize a variable just before it is used.

tests/*/Mmakefile:
    Add back the definition "TESTS_DIR = .."
2020-06-10 01:05:15 +10:00
Zoltan Somogyi
fe44a831bd Remove a workaround for NFS. 2020-05-30 23:35:53 +10:00
Zoltan Somogyi
79d81d09d8 Fix bugs and nits pointed out by shellcheck.
scripts/mgnuc.in:
    Delete the unused variables AS, AS_OPTS, HLD_OPTS and ARG_OPTS.
    The first two are hstorical relics, HLD_OPTS lost its raison d'etre
    when we deleted the hl grades; I don't know what we used ARG_OPTS for.

    Make the unused variable CFLAGS_FOR_ANSI used.

    Fix a spelling inconsistency: DEBUG_OPT vs DEBUG_OPTS.

scripts/ml.in:
    Delete the unused variables NONSHARED_LIB_DIR and DL_LIBRARY.

scripts/parse_grade_options.sh-subr:
    Fix typos that prevented an almost-never-used option from working.

scripts/parse_ml_options.sh-subr.in:
    Fix a quoting error.

tools/bootcheck:
    Comment out the definition of an unused variable. (Its parallel
    exists and is used in c2init.in, which is why it is not deleted.)

    Fix typos in spelling SSDB_LIB_NAME.

    Quote a variable value that may contain spaces.

    Replace "cat file | cmd" with "cmd < file".
2020-05-29 21:18:08 +10:00
Zoltan Somogyi
a67a33d639 Specify ft=sh in the vim modeline. 2020-04-28 11:50:33 +10:00
Zoltan Somogyi
58ff05ebaf Allow bootcheck in C# grade after grade_lib changes.
tools/bootcheck:
    Build grade_lib/GRADE_LIB_FLAGS before building stage 2.

    Make dependencies in grade_lib/ before building stage 3.

grade_lib/Mmakefile:
    Get the "make dependencies" step in stage 3 build GRADE_LIB_FLAGS.
2020-04-16 12:01:29 +10:00
Zoltan Somogyi
0c40f3b5f0 Build the grade_lib directory by default.
This should prevent bit rot in its code, such as that caused by the
move of the one_or_more type from list.m to one_or_more.m.

Mmakefile:
    Add grade_lib to the list of directories to build, to the list of
    directories in which dependencies are made, the list of directories
    in which tags files are made, and the list of directories to clean.

    Do not include the grade library in source distributions. In the
    intended use case, the grade library modules that the compiler needs
    will be present in the source distribution in the *compiler* directory.

    Add mfilterjavac to the list of directories for tags files; its former
    absence was an oversight.

    Fix inconsistent indentation.

tools/bootcheck:
    Build the grade library during stages 2 and 3. Compare its stage 2 and 3
    versions as we do for other directories.

    Put the commands that create stages 2 and 3 into recognizable blocks.

grade_lib/Mmakefile:
    Add the targets needed by either by bootcheck or by the top level
    Mmakefile.

    Document the intended usage of the grade library.

grade_lib/.mgnuc_copts:
grade_lib/.mgnuc_opts:
    Use the same .mgnu_*opts files as e.g. the profiler directory.
    The common command sequence used by bootcheck to build the
    stage 2 and 3 directories assumes their presence.

library/Mmakefile:
    Make it clear that some rules previously separated by dividing lines
    are actually related.
2020-04-14 09:35:55 +10:00
Zoltan Somogyi
aea3b98033 Test the process of making .int files.
tests/Mmakefile:
tools/bootcheck:
    Add invalid_make_int and valid_make_int as new test directories.

tests/invalid_make_int/missing_interface_import.m:
tests/invalid_make_int/missing_interface_import.int_err_exp:
tests/invalid_make_int/missing_interface_import.int_err_exp2:
    Move this test case from invalid to invalid_make_int, since it was
    *already* testing the error message we get from "mmc --make-interface".

tests/invalid_make_int/Mercury.options:
tests/invalid_make_int/Mmakefile:
    Set up testing of whether we get the right error messages during
    the process of making .int files.

tests/Mmake.common:
    Provide a way for tests in invalid_make_int to compare a .int_err file
    against several .int_err_exp* files.

tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
    Delete references to the test case moved to invalid_make_int.

tests/valid_make_int/bug499.m:
    Add the test case that motivated this change.

tests/valid_make_int/Mercury.options:
tests/valid_make_int/Mmakefile:
    Set up testing of whether we can generate .int files for modules.
2020-04-13 04:14:51 +10:00
Zoltan Somogyi
66aa649378 Keep the .log files of successful tests if requested.
Sometimes, when a test case fails in a workspace even though it has passed
before, it is not clear whether the cause of the failure is that the
updated code in the workspace is generating a different sequence of
mmc invocations, or whether the same invocations do something different.
The new option allows developers to answer that question by keeping the logs
from a bootcheck in an unchanged workspace, and comparing the logs
between the workspaces.

tools/bootcheck:
    If given the --keep-success-log-files option, set an environment variable
    that records this fact.

tests/run_one_test:
    If this environment variable is set, then rename the .log files of
    successful test cases as .kept_log files instead of deleting them.

    Note that we cannot keep the .log files around under their original name,
    because we currently interpret the presence of *any* .log file
    in a test directory as meaning "some tests failed in this test directory".
2020-03-08 13:41:57 +11:00
Zoltan Somogyi
078e1dbfbc Enable the tests in the feedback directory. 2019-08-15 09:15:37 +10:00
Zoltan Somogyi
bd7d7db57d Move nested-module programs from invalid to invalid_submodules.
This is to compile them with "mmake -j1", and thus avoid the intermittent
failures caused by interface files of nested submodules not being ready
when another job, executed in parallel by mmake, wants to read them.

tests/invalid_submodules/children.m:
tests/invalid_submodules/children2.m:
tests/invalid_submodules/duplicate_module.m:
tests/invalid_submodules/duplicate_module_test.err_exp:
tests/invalid_submodules/duplicate_module_test.m:
tests/invalid_submodules/exported_unify3.err_exp:
tests/invalid_submodules/exported_unify3.err_exp2:
tests/invalid_submodules/exported_unify3.m:
tests/invalid_submodules/func_class.err_exp:
tests/invalid_submodules/func_class.m:
tests/invalid_submodules/import_in_parent.err_exp:
tests/invalid_submodules/import_in_parent.m:
tests/invalid_submodules/missing_parent_import.err_exp:
tests/invalid_submodules/missing_parent_import.m:
tests/invalid_submodules/nested_impl_in_int.err_exp:
tests/invalid_submodules/nested_impl_in_int.m:
tests/invalid_submodules/sub_a.m:
tests/invalid_submodules/sub_c.err_exp:
tests/invalid_submodules/sub_c.m:
tests/invalid_submodules/undef_mod_qual.err_exp:
tests/invalid_submodules/undef_mod_qual.m:
tests/invalid_submodules/unresolved_overloading.err_exp:
tests/invalid_submodules/unresolved_overloading.m:
    Move these files, which contain the source code and expected outputs
    of the affected test cases, from the invalid directory to the new
    invalid_submodules directory.

tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
    Delete any mentions of the moved test cases.

    Improve sh programming style in actions.

tests/invalid_submodules/Mercury.options:
tests/invalid_submodules/Mmakefile:
    List *only* the moved test cases. Specify the -j1 flag for mmake.

tests/Mmakefile:
tools/bootcheck:
    Mention the new test directory.

    Request that the list of test directories in these two places be kept
    in sync.

    Note that the feedback test directory is not yet ready.
2019-08-14 23:28:00 +10:00
Julien Fischer
8e4fc73fc6 Support parallel bootchecks using --use-mmc-make.
Parallel bootchecks using --use-mmc-make do not currently work because mmake
creates multiple instances of mmc --make per directory and these conflict with
each other.  Modify the bootcheck script so that when --use-mmc-make is
enabled, we do not build affected directories with mmake's -j option but
instead pass the -j option directly to Mercury compiler.

tools/bootcheck:
   As above.
2019-07-09 12:25:23 +10:00
Julien Fischer
d79a07f13a Handle macOS shared libraries in a spot.
tools/bootcheck:
    As above.
2019-07-08 20:54:27 +10:00
Zoltan Somogyi
4bf9dd6ca3 Build more directories in stages 2 and 3.
tools/bootcheck:
    Build the deep_profiler and mfilterjavac directories in stage 2.

    Build the slice, profiler, deep_profiler and mfilterjavac directories
    in stage 3. (We already used to build slice and profiler in stage 2.)

    Compare target language files in the stage 2 and stage 3 versions
    of the slice, profiler, deep_profiler and mfilterjavac directories,
    to make bootcheck a tougher test. This requires copying these directories
    to stage 3, instead of just linking them.

    Don't make dependencies in a directory if we had already done them
    earlier.

mfilterjavac/Mmakefile:
    Add targets for building C# and Java files.

slice/Mmakefile:
    Include the modules of the mcov and mtc_diff programs in the
    existing targets for building C, C# and Java files.

deep_profiler/Mmakefile:
profiler/Mmakefile:
    These makefiles already had targets for building C# and Java files.
    Fix grammar and/or indentation.

compiler/Mmakefile:
    Fix grammar and/or indentation.
2019-06-25 14:22:53 +02:00
Zoltan Somogyi
4ffaa6f573 Don't apply stage 2 settings to stage 1.
tools/bootcheck:
    We compute the values of $use_subdirs and $use_mmc_make based on
    the grade specified for the stage 2 compiler. So use them to set
    the values of MMAKE_USE_SUBDIRS and MMAKE_USE_MMC_MAKE respectively
    only *after* we finished the last mmake invocation on stage 1.
    Setting them *before* then could screw up the stage 1 if it was built
    with different settings of those variables.

    This fixes Mantis #459.
2018-05-06 23:04:24 +02:00
Zoltan Somogyi
310048037c Try to guard against future bitrot.
tools/bootcheck:
    Build the dependencies for auxiliary programs, and the programs themselves,
    in the browser and profiler directories.

Mmakefile:
    Provide targets for bootcheck to use to make dependencies for the
    auxiliary programs in the browser and profiler directories.

browser/Mmakefile:
    Take the two aux programs in this directory out of the "all" target.
    Due to past bitrot, one gets errors during compilation, the other
    during linking. (The "all" target is not used by default, which is why
    this has not been a problem.)

    Add depend_aux and aux targets that should build these programs
    if they are ever fixed. The aux target is empty for now; the depend_aux
    target does make dependencies for both aux programs (since that still
    works, and we want to keep it that way).

profiler/Mmakefile:
    Add depend_aux and aux targets that build the one auxiliary program
    in this directory that works now. Add a comment about the other program
    that doesn't.
2018-01-09 01:05:42 +11:00