Commit Graph

9963 Commits

Author SHA1 Message Date
Zoltan Somogyi
bdabaf5dc9 Make an error message more inclusive.
compiler/comp_unit_interface.m:
    When we cannot generate a .int0/.int/.int2 file because of file access
    issues, the reason is *usually* that we can't read a .int3 file.
    However, it is also possible that the reason is that we can't read
    a .int0 file, so include that possibility in the overall error message.
    (The "can't read this file" message, with the specifics of the file
    that couldn't be read, would have been printed earlier.)

tests/invalid_make_int/missing_parent_import.int_err_exp:
tests/invalid_make_int/sub_c.int_err_exp:
tests/invalid_make_int/test_nested.int_err_exp:
    Expect the updated error message.
2023-10-30 18:05:46 +11:00
Zoltan Somogyi
d352b33831 Fix a sixth batch of C# invalid test failures.
compiler/check_typeclass.m:
     Don't module qualify the names of type constructors in which are
     reporting a problem regarding typeclass constraints.

tests/invalid_make_int/bad_detism_category.{m,int_err_exp}:
tests/invalid_make_int/bad_end_module.{m,int_err_exp}:
tests/invalid_make_int/bad_existential_data_type.{m,int_err_exp}:
    Move these test cases here from tests/invalid_nodepend, since
    most of the errors they report are now diagnosed when making .int files.
    Delete the code leading to the two errors that do not fall into this
    category. One of those errors is still exercised by a remnant of the
    old moved test case, which is now undetermined_existential_data_type.m
    in tests/invalid_make_int; the other is exercised by other test cases
    that this diff does not touch.

tests/invalid_make_int/Mercury.options:
tests/invalid_make_int/Mmakefile:
    Add the moved test cases to the list of test case in this directory.

tests/invalid_nodepend/fundeps_unbound_in_ctor.err_exp:
tests/invalid_nodepend/type_vars.err_exp:
    Update these files to expect an unqualified type constructor name.

tests/invalid_nodepend/undetermined_existential_data_type.{m,err_exp}:
    Construct this copy by deleting from the old bad_existential_data_type.m
    all the code moved to tests/invalid_make_int.

tests/invalid_nodepend/Mmakefile:
    Delete the moved test case, and update the name of the remaining test case.
2023-10-28 01:34:33 +11:00
Zoltan Somogyi
68cf30cb37 Fix a fifth batch of C# invalid test failures.
compiler/det_analysis.m:
    Improve an error message about foreign_procs by printing it with
    the context of the foreign_proc itself, not the context of the
    procedure it is for. Also, make the wording more specific.

compiler/prog_event.m:
    Reading event sets is currently implemented when the compiler
    is compiled for the C backend (because its parser uses lex/flex
    and yacc/bison). However, that is no reason for crashing the compiler if
    - someone asks it to read an event set
    - while the compiler is compiled to a target language other than C.
    Fix this by returning an apology message instead of crashing.

tests/invalid/pragma_c_code_no_det.m:
tests/invalid/test_may_duplicate.m:
tests/invalid/test_may_export_body.m:
    Add foreign procs for Java and C# as well as for C.

tests/invalid/pragma_c_code_no_det.err_exp{,2,3}:
tests/invalid/test_may_duplicate.err_exp{,2,3}:
tests/invalid/test_may_export_body.err_exp{,2,3}:
    Add expected output files for Java and C#. Update the line numbers
    in the expected file for C.

tests/invalid/test_type_spec.m:
    Delete the parts of this test case that contain errors that we now report
    when creating .int files. We now test for those errors using the new test
    case tests/invalid_make_int/test_type_spec_int.
tests/invalid/test_type_spec.err_exp:
    Delete the messages for the deleted errors, expect verbose errors
    (see the update of Mercury.options below), and update the line numbers.

tests/invalid/try_detism.m:
    Explain the reason for the need for the new .err_exp2 file.
tests/invalid/try_detism.err_exp{,2}:
    Add the new .err_exp2 file for C#, which differs from the .err_exp file
    only in the variable number of a compiler-generated variable.
    Update the line numbers in the .err_exp file.

tests/invalid/undef_type.m:
    Fix the one problem in this test case that we now report when we create
    .int files. The handling of that problem is now tested in the new
    tests/invalid_make_int/undef_type_int test case.

tests/invalid/undef_type.err_exp:
    Don't expect a report for the fixed error.

tests/invalid/Mercury.options:
    Run the test_type_spec test case with verbose errors.

tests/invalid/Mmakefile:
    Don't try to execute the test cases that this diff moves to
    tests/invalid_make_int.

    Execute the test cases that try to read event set specifications
    only when targeting C. This is not the exact condition we want,
    but it is the closest to that condition that we can actually get.

tests/invalid_make_int/bad_instance.{m,int_err_exp}:
tests/invalid_make_int/type_arity.{m,int_err_exp}:
tests/invalid_make_int/undef_inst.{m,int_err_exp}:
tests/invalid_make_int/undef_mode.{m,int_err_exp}:
tests/invalid_make_int/undef_type_mod_qual.{m,int_err_exp}:
    Move these tests here from tests/invalid.

tests/invalid_make_int/test_type_spec_int.{m,int_err_exp}:
tests/invalid_make_int/undef_type_int.{m,int_err_exp}:
    The parts of the test_type_spec and undef_type test cases in tests/invalid
    that get error messages generarated for them while making .int files.

tests/invalid_make_int/Mercury.options:
tests/invalid_make_int/Mmakefile:
    Add the tests moved here, in whole or in part, from tests/invalid.
2023-10-27 15:52:11 +11:00
Zoltan Somogyi
829f3f146b Delete now-obsolete comment. 2023-10-26 16:27:48 +11:00
Zoltan Somogyi
eaa7b07e12 Line up some comments. 2023-10-26 16:27:05 +11:00
Zoltan Somogyi
5193012242 Fix a fourth batch of C# invalid test fails.
compiler/add_foreign_proc.m:
    Don't module qualify the named of predicates/functions
    defined by foreign_procs when generating an error message
    about that foreign_proc, since

    - you can add foreign_procs only for local predicates/functions, and
    - even if you one for a NON-local predicate/function, the context will
      tell you exactly which foreign_proc is being complained about.

    Also, improve the wording of the error message.

tests/invalid/instances_pc.instances_pc_helper_1.err_exp2:
tests/invalid/instances_pc.m:
    Add a new expected output file for bootchecks in C# and Java grades,
    and document the new expected output file.

tests/invalid/pragma_c_code_dup_var.{err_exp2,err_exp3}:
tests/invalid/pragma_c_code_dup_var.{m,err_exp}:
    Add two new expected output files for bootchecks in C# and Java grades.
    Note the role of each expected output file, and apply the resulting
    line number changes to the expected output file for C.

tests/invalid_make_int/instance_no_type.{m,int_err_exp}:
    Move this test case from tests/invalid to tests/invalid_make_int,
    since the compiler now diagnoses the bug it tests for
    during the creation of the .int file.

tests/invalid_make_int/pragma_export_int.{m,err_exp}:
    Move half of the pragma_export test case here from tests/invalid,
    since the compiler now diagnoses the bug it tests for
    during the creation of the .int file.

tests/invalid_nodepend/pragma_export.{m,err_exp}:
    Move the other half of the pragma_export test case here from tests/invalid.
    With mmc --make, the diagnosable-at-.int-file-creation-time errors
    prevent the compiler from ever getting to the errors that are not
    diagnosable at that time, so delete the code that gives rise to those
    diagnosable-at-that-time errors from this version of the test case..

tests/invalid/Mmakefile:
    Delete the tests moved to other test directories.

tests/invalid_make_int/Mercury.options:
tests/invalid_make_int/Mmakefile:
tests/invalid_nodepend/Mmakefile:
    Add the tests moved to these directories from tests/invalid.
2023-10-26 15:18:41 +11:00
Zoltan Somogyi
f7a06c1f24 Fix a third batch of C# invalid test fails.
compiler/make.program_target.m:
    All the multimodule tests in tests/invalid_make_int have been failing
    in C# grades. The script for these tests has two main steps:

    - build all the .int3 files involved, and then
    - build the .int file.

    The second step is expected to fail, with its error messages being tested,
    but the first step is expected to succeed. The test cases were failing
    because mmc --make built the .int files as part of the FIRST stage.

    The cause was code that built all interface files (.int3, .int0,
    .int/.int2 and even .opt) as a preliminary first step before actually
    trying to act on *any* build-all target. The fix is to make this
    preliminary step build only the interface files that come before
    the build-all target's file kind in the build order. In this case,
    that means not building anything in the preliminatu step of the
    build-all-int3s target before building all the .int3s, thus leaving
    the construction of the .int file for the second step, which is
    *expected* to fail.

tests/invalid/exported_unify_helper_1.m:
    Rename exported_unify2.m to exported_unify_helper_1.m in accordance
    with our usual scheme.

tests/invalid/exported_unify.{m.err_exp,err_exp2}:
    Update both expected error files for the rename. Since the .err_exp2 file
    was ancient, this update fixed the test case failure for C# (and almost
    certainly for Java) bootchecks. Note the role of each expected output
    file in the source code.

tests/invalid/foreign_procs_exist_type.err_exp2:
tests/invalid/foreign_procs_exist_type.err_exp3:
    Add these files containing the expected outputs for Java and C#.

tests/invalid/foreign_procs_exist_type.m:
    Add a note about the role of each expected output file.

tests/invalid/foreign_procs_exist_type.err_exp:
    Update the line numbers for this file containing the C expected output.

tests/invalid/foreign_purity_mismatch.m:
tests/invalid/fp_dup_bug.m:
    For each C foreign proc being tested, add C# and Java foreign_procs
    as well.

    Add a note about the role of each expected output file.

tests/invalid/foreign_purity_mismatch.err_exp2:
tests/invalid/foreign_purity_mismatch.err_exp3:
tests/invalid/fp_dup_bug.err_exp2:
tests/invalid/fp_dup_bug.err_exp3:
    Add these files containing the expected outputs for Java and C#.

tests/invalid/foreign_purity_mismatch.err_exp:
tests/invalid/fp_dup_bug.err_exp:
    Update the line numbers for this file containing the C expected output.

tests/invalid/gh72_errors.m:
    This test case tests an error message from the direct arg transformation.
    This transform does not apply to C# and Java grades, so in those grades,
    the compiler does not generate those messages. In those grades, this
    test case failed because the compilation succeeds, instead of failing
    (with the expected message, or not).

    Fix this failure by adding to gh72_errors.m C# and Java foreign_procs
    that do get error messages.

tests/invalid/gh72_errors.err_exp2:
tests/invalid/gh72_errors.err_exp3:
    Expect these error messages in C# and Java grades respectively.

tests/invalid/gh72_errors.err_exp:
    Update the line numbers in the error messages during C compilations.
2023-10-26 08:47:39 +11:00
Zoltan Somogyi
a3ea222883 Fix more C# test case failures in tests/invalid*.
compiler/options.m:
doc/user_guide.texi:
    Add a new developer-only option, --std-int-file-not-written-msgs,
    which, if specified, calls for the "file not written" messages
    we generate when we want to write interface files but can't
    to be written out in a standard form that deletes the directory
    path component from the names of the files not written out.
    In the long term, it is less work to add this option once
    than to add a separate .err_exp file for each affected test case.

compiler/write_module_interface_files.m:
    Obey the new option.

tests/invalid/ee_invalid.m:
    Add C# and Java foreign_types next to the C foreign_type.

tests/invalid/erroneous_throw_promise.m:
    Add C# foreign_procs next to the C and Java foreign_procs.

tests/invalid/exist_foreign_error.m:
    Add C# and Java foreign_procs next to a C foreign_proc.
tests/invalid/exist_foreign_error.err_exp:
tests/invalid/exist_foreign_error.err_exp2:
tests/invalid/exist_foreign_error.err_exp3:
    Update the line number in the expected error output file for C,
    and add expected error output files for Java and C#.

tests/invalid_make_int/bug17.{m,int_err_exp}:
tests/invalid_make_int/builtin_int.{m,int_err_exp}:
    Move these test cases here from tests/invalid, since all the errors
    we test for are reported when making the .int file.

tests/invalid/Mmakefile:
    Delete the tests moved to tests/invalid_make_int.

tests/invalid_make_int/Mercury.options:
tests/invalid_make_int/Mmakefile:
    Add the tests moved from tests/invalid. Specify the new option
    for all the test cases.
2023-10-25 19:21:06 +11:00
Zoltan Somogyi
a3546b16c3 Move code to generate interface to comp_unit_interface.m.
compiler/write_module_interface_files.m:
compiler/comp_unit_interface.m:
    Move the predicates that generate the parse trees of interface files
    from write_module_interface_files.m to comp_unit_interface.m.
    Move the types they need with them, and document them.

    Rename the predicates involved to make clear whether they generate
    parse trees, write them out, or both.

    In comp_unit_interface.m keep private the previously exported predicates,
    because their only callers are the moved predicates, so all calls them
    are now local to the module.

compiler/make.get_module_dep_info.m:
compiler/mercury_compile_main.m:
    Conform to the changes above.
2023-10-25 12:35:57 +11:00
Zoltan Somogyi
3dabbd4edf Generate and write parse_tree_intNs in separate preds.
compiler/write_module_interface_files.m:
    Put the code that writes out parse_tree_intNs in separate predicates
    from the code that generates them.

    This separation is useful in situations in which

    - we need to generate several .intN files as fast as possible, and
    - later operations will need access to the contents of those files.

    With the current setup, we can call e.g. write_short_interface_file_int3
    on several parse_tree_module_srcs in parallel, but this comes at the cost
    of each worker process building up only its own have_parse_tree_maps
    "database" of parse trees. This means if worker process A generates
    an interface file, another worker process B will need to read that
    interface file to get access to its contents.

    With the setup created by this diff, we can generate all the parse trees
    for the interface files in the main process, keeping *all* their parse
    trees in its have_parse_tree_maps structure, and hand off each parse tree
    as it is constructed to a worker process for writing out.
2023-10-25 10:05:46 +11:00
Julien Fischer
5c7d57807a Temporarily disable the use of depend_ints on MinGW64.
library/MmakeFile:
compiler/Mmakefile:
   As above.
2023-10-24 21:11:53 +11:00
Zoltan Somogyi
343ce49122 Check the extensions for linked target extensions.
compiler/globals.m:
    Add to the globals a new structure that maps extension strings
    (such as ".o", ".a" or ".all_picos) to a representation of what
    mmc --make target they represent.

compiler/handle_options.m:
    Build up this map by processing the values of the options

        object_file_extension
        pic_object_file_extension
        executable_extension
        library_extension
        shared_library_extension

    checking them for collisions both with each other's values,
    and with the fixed ".install" extension.

compiler/make.top_level.m:
    Use the new map to simplify the code that converts extensions
    to mmc --make targets.
2023-10-24 12:57:47 +11:00
Zoltan Somogyi
80238250d7 Minor improvements in mmc --make infrastructure.
These are issues I encountered while working on my previous commit
involving grab_modules.m.

compiler/make.make_info.m:
    Give a name to the type that implements the data structure
    that we usually use variables named DepStatusMap to refer to.

    Rename the make_info field holding this data structure
    from mki_dependency_status, which could mean any of several things,
    to mki_dep_file_status_map, which pretty clearly says it maps
    dependency_files to status information. (mki_dependency__file_status_map
    would have been too long.) Rename the getter/setter predicates
    accordingly.

compiler/make.check_up_to_date.m:
    Do a similar clarifying rename on a predicate.

    Convert an if-then-else to a switch.

    Add a long XXX describing a problem I found while investigating
    with some temporarily-failing test cases. Those test cases now succeed
    despite the presence of this bug.

compiler/make.get_module_dep_info.m:
    Delete code to write out error_specs that later code is guaranteed
    to also write out on all possible execution paths. This resulted
    in double-printed error messages in some test cases, which succeeded
    despite this, because this problem occurred during compilation tasks
    (such as the creation of .int3 files) that the test cases do NOT involve.

    Speed up a search/insert operation pair.

compiler/mercury_compile_main.m:
    Fix a sort-of bug that that included some error_specs in a list of
    error_specs twice. The code writing out the error_specs would have
    deleted the duplicates, but still, it is better to avoid adding
    the duplicates in the first place.

compiler/make.program_target.m:
    Merge two pairs of adjacent switches.

compiler/make.module_target.m:
    Conform to the changes above.
2023-10-23 16:10:23 +11:00
Zoltan Somogyi
26f1e5bb53 Give an initial module_baggage to grab_modules.m.
compiler/grab_modules.m:
    grab_{qual,unqual}_imported_modules_*, the two main predicates
    of this module, have for a while now taken as input both a
    parse_tree_module_src, and several separate arguments each describing
    part of the origin of that parse_tree_module_src. They then created
    a new module_baggage structure, filling some of its fields using
    those arguments, but filling other fields with default values,
    which were no more than guesses at what the right value might be.

    This has obviously worked, but it could work only because
    the guessed-at fields are either not used or were guessed well.
    However, this may change in the future. After this diff, we now require
    the caller to pass to these predicates a fully-and-correctly-filled-in
    module_baggage structure instead, which guards against that
    possibility, and leads to cleaner and more understandable code
    to boot.

    We do throw away any errors in the initial module_baggage
    in order to prevent parts of the compiler that aren't set up
    to handle any errors there from causing additional test failures
    in C# (and probably Java) grades. This preserves old behavior,
    at least for now.

compiler/write_module_interface_files.m:
    Make the versions of write_private_interface_file_int0 and
    write_interface_file_int1_int2 that took a burdened_module
    as an argument the *only* versions of those operations,
    since the burdened_module contains the module_baggage structure
    we now want to pass to grab_modules.m.

    Replace the parse_tree_module_src argument of
    write_short_interface_file_int3 with a burdened_module.
    This is only for "cultural compatibility" with the neighboring
    predicates; unlike those two, this predicate does not need access
    to the module_baggage.

compiler/make.get_module_dep_info.m:
compiler/mercury_compile_main.m:
    Conform to the changes above.

compiler/module_baggage.m:
    Fix a misleading variable name.
2023-10-23 11:39:58 +11:00
Zoltan Somogyi
f27cc609bd Update variable names. 2023-10-22 14:44:43 +11:00
Zoltan Somogyi
0d5a4538ec Update the names of some predicates.
compiler/split_parse_tree_src.m:
    Rename split_into_compilation_units_perform_checks to
    split_into_component_modules_perform_checks. The type of the returned
    data structures was changed from raw_compilation_units to
    parse_tree_module_srcs a while ago.

    Perform the same rename for some internal predicates as well.

    Factor out some common code.

compiler/mercury_compile_main.m:
compiler/module_baggage.m:
    Conform to the changes above.
2023-10-22 14:37:49 +11:00
Zoltan Somogyi
911954dd32 Put the main preds in chrono order. 2023-10-22 14:33:01 +11:00
Zoltan Somogyi
c0cfae0061 Update some variable names. 2023-10-22 11:29:59 +11:00
Zoltan Somogyi
bafd0deb97 Give a field a more descriptive name. 2023-10-22 10:10:21 +11:00
Zoltan Somogyi
b8641b4306 Write "can't open file" messages to ProgressStream ...
... instead of ErrorStream, in more places.

compiler/compile_target_code.m:
compiler/file_util.m:
compiler/handle_options.m:
compiler/mercury_compile_front_end.m:
    As above.

compiler/make.program_target.m:
compiler/mercury_compile_main.m:
compiler/xml_documentation.m:
    Don't pass ErrorStream to predicates that don't need it anymore.
2023-10-22 09:47:52 +11:00
Zoltan Somogyi
d394cfc7a5 Rename have_read_module_maps to have_parse_tree_maps ...
... to account for the fact that they now contain constructed parse trees,
as well as read-in parse trees.

compiler/read_modules.m:
    Make the rename described above.

    Make it possible to differentiate between constructed and read-in
    parse trees, in case this becomes necessary in the future.

compiler/deps_map.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/make.get_module_dep_info.m:
compiler/make.make_info.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/recompilation.check.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.

    In make.get_module_dep_info.m, add an XXX.
2023-10-22 08:39:27 +11:00
Julien Fischer
5c8cb1c4fe Add a no-op .depend_ints target for mmc --make.
compiler/make.top_level.m:
    As above.
2023-10-20 23:42:39 +11:00
Zoltan Somogyi
f9c185e5e8 Start actively using --generate-dependencies-ints.
configure.ac:
    Require the installed compiler to support both the option,
    and the Mmake rules that invoke it.

compiler/Mmakefile:
library/Mmakefile:
mdbcomp/Mmakefile:
mfilterjavac/Mmakefile:
ssdb/Mmakefile:
    Get the mmake depend to depend on prog.depend_ints, not prog.depend,

    Give the prog.depend_ints targets themselves the same prerequisites
    as the existing prog.depend targets.

    In mfilterjavac/Mmakefile, fix what looks like an old problem
    by making the depend target a prerequisite of the check and ints targets.
2023-10-20 20:11:45 +11:00
Zoltan Somogyi
77752419c4 Fix many test cases in C# and Java grades ...
.. that failed because the "For more information, recompile with `-E'
message was missing.

This diff takes the number of failed test cases in these grades
from 228-ish to 171.

compiler/make.module_target.m:
    Stop calling the predicate that outputs that message outside
    of the part of mmc --make's machinery that can fork the compiler process,
    and ...

compiler/mercury_compile_main.m:
    ... ensure that it is called *inside* the forked process, in such cases.

    Do this by ensuring that

    - each switch arm in do_process_compiler_arg gathers up the error_specs
      generated by code executed along that switch arm, and

    - after the switch, do_process_compiler_arg prints both these
      error_specs, *and* the "For more information, recompile with `-E'
      message if warranted.

    Previously, the last of those points happened on some execution paths,
    but not all.
2023-10-20 14:16:07 +11:00
Zoltan Somogyi
4f3bb3394e Write "can't open file" messages to ProgressStream ...
... instead of ErrorStream.

compiler/parse_tree_out.m:
    As above.

compiler/make.get_module_dep_info.m:
compiler/mercury_compile_main.m:
compiler/write_module_interface_files.m:
    Don't pass ErrorStream to predicates that don't need it anymore.
2023-10-19 19:59:40 +11:00
Zoltan Somogyi
5a57f28d03 Don't repeat an error explanation.
compiler/check_typeclass.m:
    Delete the verbose_only part of an error message, because it duplicated
    almost exactly the always-printed part of the same error message.

tests/invalid/instance_var_bug.err_exp:
    Don't expect the verbose part.

tests/invalid/bad_instance2.err_exp:
tests/invalid/invalid_instance_declarations.err_exp:
    Don't expect a reminder about the existence of the verbose part.
2023-10-19 16:09:36 +11:00
Zoltan Somogyi
1319819ec2 Use only explicit streams in make.module_target.m.
compiler/Mercury.options:
    Stop specifying --no-warn-implicit-stream-calls for make.module_target.m.

compiler/make.module_target.m:
    Use explicit streams when invoking mmc recursively for a target.

    Add a call to maybe_print_delayed_error_messages. It does not fix
    the problem it looks like it *should* fix, but it is almost certainly
    a required step for that fix.

compiler/mercury_compile_main.m:
    Take the explicit streams that make.module_target.m now passes.

compiler/write_error_spec.m:
    Make the mutables consulted by maybe_print_delayed_error_messages
    thread local. This should help, but it does not solve the problem.
2023-10-19 11:32:10 +11:00
Zoltan Somogyi
0369f88379 Write truncated .err file to ProgressStream ...
compiler/make.build.m:
    ... as opposed to what you get from io.output_stream.

    Change argument order to reflect our usual style.

compiler/make.get_module_dep_info.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Conform to the changes above.
2023-10-18 11:48:27 +11:00
Zoltan Somogyi
66d07e92fc Replace many calls to io.output_stream ...
... so that the following code can write to an *explicitly*, as opposed
to *implicitly*, specified stream.

compiler/code_gen.m:
compiler/code_info.m:
    Include the stream to which debug output should be written in the
    code_info structure. Move the predicate that tests whether we should
    generate debug output from code_loc_dep.m to code_info.m, since it
    belongs there.

compiler/code_loc_dep.m:
compiler/ite_gen.m:
compiler/proc_gen.m:
    Conform to the changes above.

compiler/typecheck_info.m:
    Include the stream to which debug output should be written in the
    relevant field of the typecheck_info structure.

compiler/unneeded_code.m:
    Include the stream to which debug output should be written in the
    uc_option_values structure.

compiler/dep_par_conj.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_middle_passes.m:
compiler/stack_opt.m:
compiler/typecheck.m:
compiler/typecheck_debug.m:
    Replace calls to io.output_stream with explicitly passed streams.
2023-10-18 08:47:35 +11:00
Zoltan Somogyi
b21e9e459a Delete all calls to get_progress_output_stream ...
... and almost all calls to get_error_output_stream. Replace them
with ProgressStreams and ErrorStreams passed down from higher in the
call tree.

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

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

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

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

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

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

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

    Fix too-long lines.
2023-10-17 20:41:33 +11:00
Zoltan Somogyi
8a06c176b4 Make a predicate name more descriptive. 2023-10-17 05:27:37 +11:00
Zoltan Somogyi
7e143f631d The last step in switch-ifying classify_target_2.
compiler/make.top_level.m:
    Put the code for recognizing the single module targets, the build-all
    module targets, and the misc targets into a single giant switch.

    That leaves the if-then-else chain handling only the dynamic extensions,
    i.e. those whose values are specified by option values. Put the ones
    dealing with executables before the ones dealing with libraries.
2023-10-17 05:23:57 +11:00
Zoltan Somogyi
1dbbf754b5 The second step in switch-ifying classify_target_2.
compiler/make.top_level.m:
    Add a new way to test whether an extension string specifies
    a build-all target type. The new code is a single switch,
    while the old code is an if-then-else chain on top of other code.

    Don't make the new code live yet. Instead, add a predicate to compare
    the outputs of the old and new algorithms both for the extensions
    that are intended to recognize, and some extensions that they shouldn't
    recognize. This predicate reports that the new algorithm agrees with
    the old for all the tested extension strings.
2023-10-16 16:11:59 +11:00
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
2ae0fba6bf The first steps in switch-ifying classify_target_2.
compiler/make.top_level.m:
    Move the predicates extension_to_target_type and target_extension_synonym
    here from make.file_names.m, since they were used only in this module.

    Separate the extension_to_target_type into its two parts, the switch,
    and the test, at both its call sites. Merge the code of
    target_extension_synonym into the switch part, which is now called
    just_ext_to_module_target_type.

    Convert a series of if-then-elses in the middle of an if-then-else chain
    into a switch.

compiler/make.file_names.m:
    Delete the code moved to make.top_level.m.
2023-10-16 10:57:11 +11:00
Zoltan Somogyi
191eb9eb64 Make --generate-dependencies-ints more practical.
scripts/Mmake.rules:
    Add a rule for the pattern target %.depend_ints which invokes mmc
    with --generate-dependencies-ints, just as %.depend invokes mmc
    with --generate-dependencies.

    Document the reason why this addition requires yet more code duplication.

scripts/Mmake.vars.in:
    Add the make variable definitions needed by the new code in Mmake.rules.

compiler/mercury_compile_main.m:
    Make it practical to use --generate-dependencies-ints in a multi-directory
    project like the Mercury implementation, in which some directories
    may use --generate-dependencies-ints as the target of "mmake depend",
    while other directories, which come earlier in the build process,
    still do "mmake depend" using just --generate-dependencies.
    In such cases, mmc --generate-dependencies-ints in the later directory
    may fail to generate .int0, .int or .int2 files simply because
    the .int3 file of a module they import (from an earlier directory
    in which "mmake depend" uses just --generate-dependencies) hasn't been
    made yet. (This is what would happen if someone executed "mmake depend"
    at the top level in a freshly checked out workspace.)

    The practical fix is to simply report this fix using an error message
    that still allows the compiler to exit with an exit status that
    indicates success.

    Most of the rest of this diff is there to make this possible.

compiler/error_spec.m:
    Add a new phase, phase_find_files, that specifically indicates
    that we couldn't read a file because we couldn't find it.
    Give it a string argument naming the file, to allow mercury_compile_main.m
    to replace several error_specs that each report not being able to find
    one file with a single error_spec that reports not being able to find
    many files.

    Add a utility function for use by mercury_compile_main.m to construct
    that error message.

    Add another new phase, phase_make_int, that indicates a problem
    we discovered in the code of a Mercury source file while trying
    to decide what should got into one of the that module's interface files.

compiler/parse_error.m:
    Here also use separate function symbols in the fatal_module_read_error
    type for the situations "couldn't find a file" and "couldn't read a file".

    Update the predicates constructing error_specs to handle this distinction
    (which the callers make using the new function symbol in the above type).

compiler/compile_target_code.m:
compiler/error_util.m:
compiler/grab_modules.m:
compiler/options_file.m:
compiler/parse_module.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.

compiler/options.m:
    Add a way to detect the presence of this diff in an installed compiler.
2023-10-15 13:10:40 +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
af07091940 Consistently pass ProgressStream and KeepGoing ...
compiler/make.dependencies.m:
    ... through all the relevant predicates in this module. This fixes
    all the "XXX MAKE_STREAM"s in the module.

compiler/make.module_target.m:
    Pass ProgressStream to make.dependencies.m.
2023-10-15 07:14:58 +11:00
Zoltan Somogyi
45c5678faf Pass the results from a closure, not the closure. 2023-10-15 04:27:55 +11:00
Zoltan Somogyi
fbb227e943 Call intermod direct/indirect imports as such.
compiler/make.dependencies.m:
compiler/make.deps_cache.m:
compiler/make.make_info.m:
    Rename predicates, fields and function symbols using the scheme

        direct_imports                  -> direct_imports_intermod
        non_intermod_direct_imports     -> direct_imports_non_intermod

    This reflects the fact that the direct_imports dep_spec returns a
    set of modules (in the form of module indexes) that includes
    the sets of modules returned by the non_intermod_direct_imports dep_spec
    as a subset, and adds to it the direct imports of the modules
    returned by get_intermod_imports, whose comment says it returns
    "the set of modules whose .opt files we should read"

    Do similar renames for indirect imports and for foreign language imports
    as well, for the same reason.

    The new names convey the semantic differences between the affected
    dep_specs, and the predicates that implement them, much more clearly
    than the old names.
2023-10-15 02:22:18 +11:00
Zoltan Somogyi
3ba415911f Put the code into a consistent top-down order. 2023-10-14 15:16:14 +11:00
Zoltan Somogyi
be1146c491 Move all the type definitions to the top. 2023-10-14 15:16:01 +11:00
Zoltan Somogyi
3c7f86e44a Simplify some aspects of make's caches.
compiler/make.deps_cache.m:
    Delete a field containing no information from the key of one of the
    caches. Its future role of identifying the info associated with
    the rest of the key can be handled more simply by using separate fields
    in make_infos.

    Several of the caches that this module looks after map the same type
    of keys to the same type of values. Use a single type to describe
    the type of all these caches, replacing several identical earlier types.
    Name these types after their structure, not their purpuse.

compiler/make.make_info.m:
    Put the caches with identical types next to each other.

    Improve the names of the caches' getter and setter predicates,
    making some shorter, and others more meaningful. (The diff makes
    the same changes to the names of the search and update predicates
    in make.deps_cache.m.)

compiler/make.dependencies.m:
compiler/make.find_local_modules.m:
    Conform to the changes above.
2023-10-14 12:32:11 +11:00
Zoltan Somogyi
76212699f9 Rename preds to avoid ambiguities. 2023-10-14 10:23:27 +11:00
Zoltan Somogyi
e9c89c6b8a Delete the old machinery from make.dependencies.m. 2023-10-14 09:34:32 +11:00
Zoltan Somogyi
fffa54b8ea Move search and update cache ops to make.deps_cache.m.
compiler/make.deps_cache.m:
    For each cache that this module looks after, add a predicate
    to search the cache and another to add a new entry to the cache.
    This centralization should make it easier to gather stats about
    the caches.

    Shorten some unnecessarily-long names.

compiler/make.dependencies.m:
compiler/make.find_local_modules.m:
    Replace the inline code for searching and update caches
    with calls to the new predicates in make.deps_cache.m.
    This makes the code easier to read.

    Add to the new machinery in make.dependencies.m the one cache
    that it lacked that the old machinery had. All the other caches
    are used by code in the infrastructure used by both the old and the new
    machineries.
2023-10-13 16:49:12 +11:00
Zoltan Somogyi
e921265eb6 Move a cache definition to make.deps_cache.m.
compiler/make.deps_cache.m:
compiler/make.find_local_modules.m:
    Move the definition of the cache of transitive dependencies
    from make.find_local_modules.m to make.deps_cache.m.

    Rename some types for consistency.

compiler/make.make_info.m:
    Conform to the change above.
2023-10-13 14:55:15 +11:00
Zoltan Somogyi
b92c11973c Document mmakefile fragment files better.
compiler/generate_dep_d_files.m:
    Document the reason for the split between .dep and .dv files.

    Fix typo.

scripts/mmake.in:
    Delete code that was only needed for bootstrapping that split
    (in 1999!).

    Document an incorrect comment.
2023-10-12 15:18:59 +11:00
Zoltan Somogyi
cabf79bb03 Don't pass to write_deps_file.m info it doesn't need.
compiler/write_deps_file.m:
    Don't pass the deps_map argument to generate_dependencies_write_d_files,
    since that argument has been ignored for a long time now (at least
    five years).

    Make that same predicate take a list of burdened modules instead of
    a list of deps, since it uses only the burdened module field
    of the deps structure.

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

    Move a piece of code to where it conceptually belongs.
2023-10-12 09:31:21 +11:00
Zoltan Somogyi
25f8a6cc99 Add new option --generate-dependencies-ints.
This new option extends --generate-dependencies to take advantage of the
opportunity afforded by the fact that "mmc --generate-dependencies prog.m"
reads in every Mercury source file in the current directory that is
part of "prog". It does this by

- generating the .int3 file of all local-directory modules of the program;
- generating the .int0 file for each these modules that has submodules;
- generating the .int and .int2 files of all local-directory modules
  of the program.

Normally, the process of creating .int0, .int and .int3 files would
need to read in .int0 and .int3 files, but in every one of these cases,
we have just written out those files, so simply holding onto their
parse trees, we can skip this step. On my laptop, on a directory
containing library/*.m, mdbcomp/*.m and compiler/*.m, generating
the dependencies and generating all the .int3/.int0/.int/.int2 files
takes just over 25 seconds. Using the new option, the same process
takes less than 10 seconds.

compiler/options.m:
    Add the new option.

compiler/op_mode.m:
    Add a new variant of the existing op_mode for --generate-dependencies,
    which we select in the presence of the new option.

compiler/mercury_compile_main.m:
    Implement the new op_mode.

    Fix an old issue, which is that "mmc --make-private-interface x.m"
    generated a .int0 file for *every* module in x.m, even the modules
    that don't have any submodules.

compiler/deps_map.m:
    The code implementing the new option needs to know which modules
    of the program are in the current directory. The deps_map structure
    built by the code shared with the implementation of --generate-dependencies
    has not needed that info until now, so add a new field to the deps
    structure of each module to provide this info.

compiler/generate_dep_d_files.m:
    Return the deps_map created by the code that implements both
    --generate-dependencies and the new option to mercury_compile_main.m.

compiler/write_module_interface_files.m:
    Add a flag to the predicates that first construct the parse trees of,
    and then write out, .int3/.int0/.int/.int2 files, that
    mercury_compile_main.m can use to tell them to record the parse trees
    in the have read module maps.

    Add new variants of two of those predicates that take some of their
    arguments from burdened_module structures, since that is the form
    in which mercury_compile_main.m has that info.

compiler/module_baggage.m:
    The predicates in write_module_interface_files.m that generate
    .int0/.int/.int2 files take an argument that should be the timestamp
    of the source file they are being derived from, if that timestamp
    is needed for smart recompilation. Until now, we only ever invoked
    those predicates when we have just read in the source file,
    and this timestamp was readily available. The code implementing
    the new option needs to store this info for a short time, and
    the module baggage is the obvious place to store it, so add this field
    to the baggage.

compiler/error_spec.m:
    An invocation of the compiler with new option may report errors that
    prevent the construction of interface files for several modules.
    The new code in mercury_compile.m prints the error_specs that have
    contexts in the order of those contexts, but we want to print
    the messages without contexts (which in this case report that
    certain files could not be written or copied) to have a useful
    order too. Make this possible by allowing the invisible pieces
    we use for ordering to specify that order via a string (in this case,
    the name of the file that e.g. could not be written), rather than
    the only previous option, an integer.

compiler/grab_modules.m:
compiler/make.get_module_dep_info.m:
compiler/make.module_dep_file.m:
    Fill in the new field in the module baggage.

compiler/check_module_interface.m:
compiler/handle_options.m:
compiler/make_hlds_error.m:
compiler/parse_module.m:
compiler/prog_foreign_enum.m:
compiler/typecheck_error_util.m:
compiler/typecheck_msgs.m:
compiler/write_deps_file.m:
compiler/write_error_spec.m:
    Conform to the changes above.
2023-10-12 06:50:07 +11:00