Commit Graph

22765 Commits

Author SHA1 Message Date
Zoltan Somogyi
3c5075aced Add the init_posn function.
library/io.m:
    As above.

NEWS:
    Announce the addition.

compiler/generate_dep_d_files.m:
library/mercury_term_parser.m:
    Use the new function.
2023-01-14 00:09:48 +11:00
Julien Fischer
ff216d635a Fix compilation in non-C grades.
library/io.error_util.m:
   Update some class names.
2023-01-13 22:12:03 +11:00
Peter Wang
bda87983d4 Move some code to new io.error_util module.
This reduces the size of io.m a bit. The other reason for moving the
code is to allow modules that occur in a dependency cycle with io.m
to read results from io.error_util.trans_opt, whereas they may have
been prevented from reading io.trans_opt.

library/io.m:
library/io.error_util.m:
    Move is_error, throw_on_error and other similar predicates to a
    new undocumented submodule of io.m.

    Also move the support functions/predicates used by those predicates.

    Make io.make_io_error_from_system_error and
    io.make_io_error_from_windows_error call the implementations in
    io.error_util.m.

library/MODULES_UNDOC:
library/library.m:
    List the new submodule as undocumented.

library/benchmarking.m:
library/bitmap.m:
library/dir.m:
library/io.call_system.m:
library/io.file.m:
     Import the new submodule.
2023-01-13 18:54:04 +11:00
Peter Wang
c68795ade9 Fix parsing of module lists in trans-opt-deps-spec files.
compiler/generate_dep_d_files.m:
    Delete duplicated recursive call in
    parse_trans_opt_deps_spec_module_names predicate.
2023-01-13 11:37:47 +11:00
Zoltan Somogyi
a4b04b62e1 Use error_specs when checking trans_opt_deps_specs.
compiler/generate_dep_d_files.m:
    When the new code to handle the new --trans-opt-deps-spec option
    found an error, it printed out an error message and then stopped.
    Replace this with code that

    - continues processing after each error, to allow more than one error
      to be reported by a single compiler invocation, and
    - does not any print error messages, but instead returns
      an error_spec for each error.

    In addition, add code to look for and report

    - any references in the trans_opt_deps_spec to module names
      that do not occur in the deps graph that the trans_opt_deps_spec
      is intended to apply to; and
    - any duplicate entries in module name lists.

    To make the above possible, modify the representation of
    trans_opt_deps_specs to include information that is needed
    only for the generation of meaningful error messages.

    Note some potential problems with the code that outputs the deps graph
    as a .dot file.

compiler/error_spec.m:
    Add a mechanism to gather all the contexts in error_specs, for use
    by new code in generate_dep_d_files.

compiler/mercury_compile_main.m:
    Write out the error_specs (if any) returned by generate_dep_d_files.m.
2023-01-13 02:10:43 +11:00
Peter Wang
c9a6ba783d Add --trans-opt-deps-spec option.
This option lets the user provide a file containing information to
remove some edges from the trans-opt dependency graph, i.e. the graph
used to determine which .trans_opt files to read when making a module's
own .trans_opt file.

The reason to remove edges from the graph is to break dependency cycles.
.trans_opt files for modules within an SCC have to be made one after
another, instead of in parallel. For example, the standard library
contains one large SCC due to circular imports, so making .trans_opt
files turns out to be a bottleneck when building the standard library
(on a machine with sufficient parallelism available).

Furthermore, the user had no control over which modules in an SCC
could read the .trans_opt files of other modules in the same SCC.
If a and b happened to import each other, the compiler would always
break the cycle by allowing a to read b.trans_opt, but not allow b to
read a.trans_opt, simply based on module names. The new option lets the
user break the cycle in a way that may improve analysis results.

compiler/options.m:
    Add the --trans-opt-deps-spec option.

compiler/generate_dep_d_files.m:
    If the option --trans-opt-deps-spec FILE is used, use the
    information given in the file to remove some edges from the
    trans-opt dependency graph.

    If --generate-module-order is passed, also output the module order
    computed from the trans-opt dependency graph to a file.
    Users may find this a useful starting point when writing their own
    spec file.

compiler/write_deps_file.m:
    Add a field to intermod_deps to hold the (user-adjusted)
    trans-opt dependencies.

    Add a type, maybe_include_trans_opt_rule, to indicate whether or not
    to include a trans_opt_deps rule in a mmake dependency file.

    Separate the case when a trans_opt_deps rule is to be written,
    indicating where the dependencies come from.

    When automatically rewriting a .d file after producing target code,
    etc., write the trans_opt_deps rule with the same list of dependencies
    as the old .d file.

compiler/mercury_compile_make_hlds.m:
    Conform to maybe_include_trans_opt_rule change.

    Rename some variables for clarity.
2023-01-12 16:53:42 +11:00
Peter Wang
d32865f00d Fix option name in documentation.
doc/user_guide.texi:
    As above.
2023-01-12 11:00:09 +11:00
Julien Fischer
1137ce97cb Minor fix to Java README.
README.Java.md:
    Delete a stray period.
2023-01-11 17:13:18 +11:00
Julien Fischer
97735d9630 Do not allow std_util.pow/3 with negative values.
library/std_util.m:
    Make std_util.pow/3 throw an exception if it is called with a negative
    integer as its second argument.

tests/hard_coded/Mmakefile:
tests/hard_coded/func_exp.{m,exp}:
    Add a test of pow/3.

NEWS:
    Announce the above change.
2023-01-11 17:10:00 +11:00
Julien Fischer
36268bbbb2 Update and rewrite README.Java.
Convert it to Markdown.

README.Java:
    Add a .md extension.

    Update many of the details in this file.

    Add a table-of-contents.

    Break up the FAQ into separate named sections.

README.md:
    Conform to the above change of name.
2023-01-11 11:58:44 +11:00
Peter Wang
a130458ea2 Fix ambiguous comment. 2023-01-11 11:21:05 +11:00
Peter Wang
fba3fda155 Fix digraph.tc and digraph.rtc.
The implementation of digraph.rtc was incorrect (as demonstrated in the
new test case), which meant that digraph.tc was also incorrect.

library/digraph.m:
    Fix the implementation of rtc (reflexive transitive closure):

    - Following the algorithm used in digraph.cliques, it needs to
      traverse the graph G in *reverse* depth-first order.

    - To find the clique containing a vertex X, it needs to do a DFS on
      the *reversed* graph to find the vertices with a path to X.
      The vertices that were previously unvisited will be members of
      the same clique as X.

    - Previously it found the "followers" of the elements of the clique,
      and the followers of those followers, then added edges from the
      members of the current clique to those followers. However, that
      only includes vertices two steps removed from the clique.
      I have fixed it to add edges to *all* vertices reachable from
      members of the clique.

    Add straightforward implementations of tc and rtc for comparison.

    Add some comments.

tests/hard_coded/Mmakefile:
tests/hard_coded/digraph_tc.exp:
tests/hard_coded/digraph_tc.inp:
tests/hard_coded/digraph_tc.m:
    Add test case.

NEWS:
    Announce the fixes.
2023-01-11 11:04:26 +11:00
Peter Wang
057d2f73b6 Improve digraph.traverse.
library/digraph.m:
    Avoid expanding sparse_bitset to lists in digraph.traverse.
2023-01-09 16:25:20 +11:00
Julien Fischer
d04742542c Test format_call pragmas with multi-moded predicates.
tests/warnings/Mmakefile:
tests/warnings/format_call_multi.{m,exp}:
tests/warnings/m12.m:
     As above.
2023-01-08 16:09:28 +11:00
Julien Fischer
26ef7cdf15 Fix typo.
tests/valid_seq/xml_event_read.m:
    As above.
2023-01-07 16:48:40 +11:00
Julien Fischer
8a3e91c0fa Minor grammar fix.
library/pretty_printer.m:
    As above.
2023-01-05 20:28:06 +11:00
Julien Fischer
5d9e3fe00a Minor grammar fixes.
library/dir.m:
library/exception.m:
library/int32.m:
library/string.format.m:
    As above.
2023-01-05 20:15:05 +11:00
Julien Fischer
79fd8539cb Update copyright notices for 2023.
LICENSE:
compiler/handle_options.m:
doc/*.texi:
profiler/mercury_profile.m:
trace/mercury_trace_internal.c:
    As above.
2023-01-02 15:54:22 +11:00
Julien Fischer
ad7a8a4071 Fix a typo.
NEWS:
    As above.
2022-12-31 17:16:03 +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
Zoltan Somogyi
d4220530c9 Act on a review comment. 2022-12-30 20:01:54 +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
90753b830a Minor documentation fix.
doc/reference_manual.texi:
    s/a/an/ in a couple of spots.
2022-12-29 23:56:25 +11:00
Zoltan Somogyi
05ef8e01fb Rename the .ll_debug grade component to .c_debug.
Rename mmc and mgnuc options that set this grade component to --c-debug-grade.
Let the options named --c-debug of both mmc and mgnuc enable C level debugging
of only the module being compiled.

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

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

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

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

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

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

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

    Define MR_C_DEBUG_GRADE instead of MR_LL_DEBUG if c_debug_grade is enabled.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

scripts/ml.in:
tools/lmc.in:
tools/test_mercury:
    Conform to the change in compile_target_code.m to the naming of
    Boehm gc library variants.
2022-12-29 20:33:08 +11:00
Julien Fischer
01434de794 Shift a NEWS entry.
NEWS:
    As above.
2022-12-28 14:36:24 +11:00
Zoltan Somogyi
3dfa25d641 Fix a compiler abort in term_pass2.m.
compiler/term_pass2.m:
    Fix a compiler abort that would occur if we replaced a call
    to array.lookup with a call to array.unsafe_lookup in array_to_doc_loop
    in pretty_printer.m.

compiler/options.m:
    Provide a way to check for the presence of the fix.

NEWS:
    Mention the fix.
2022-12-28 05:42:08 +11:00
Zoltan Somogyi
b2c607f345 Improve the programming style of term_pass2.m.
compiler/term_pass2.m:
    Replace some uses of pairs with bespoke types.

    Put type definitions into a top-down order.

    Eliminate some redundant map lookups.

    Give some predicates more meaningful names.

    Put loop-invariant input arguments before loop-varying input arguments.

    Move an initial det computation out of an if-then-else's condition.
2022-12-28 03:57:10 +11:00
Zoltan Somogyi
e167c8ffc3 Delete redundant module qualifications. 2022-12-28 03:52:42 +11:00
Zoltan Somogyi
5cbcfaa0ed Move X_to_doc functions to pretty_printer.m.
library/array.m:
library/char.m:
library/float.m:
library/int.m:
library/int16.m:
library/int32.m:
library/int64.m:
library/int8.m:
library/list.m:
library/one_or_more.m:
library/string.m:
library/tree234.m:
library/uint.m:
library/uint16.m:
library/uint32.m:
library/uint64.m:
library/uint8.m:
library/version_array.m:
    Mark the X_to_doc function in each of these modules as obsolete,
    and make it a forwarding function to the actual implementation
    in pretty_printer.m. The intention is that when these forwarding
    functions are eventually removed, this will also remove the dependency
    of these modules on pretty_printer.m. This should help at least some
    of these modules escape the giant SCC in the library's dependency graph.
    (It does not make sense that a library module that adds code to increment
    an int thereby becomes dependent on pretty_printer.m through int.m.)

library/pretty_printer.m:
    Move all the X_to_doc functions from the above modules here.

    Fix the one_or_more_to_doc function, which was

    - missing the comma between the two arguments of the one_or_more
      function symbol, and

    - would print "..., ...]" instead of just "...]" at the end of the
      tail list when that list exceeded the limits of the specified pp_params.

    Rename one of the moved types along with its function symbols,
    to reduce ambiguity.

    Put arrays before their indexes in the argument lists of some of
    the moved functions.

    Some of the moved X_to_doc functions for compound types returned
    a doc that had an indent wrapper. These indents differed between the
    various X_to_doc functions without any visible reason, but they are
    also redundant. The callers can trivially add such wrappers if they
    want to, but taking them off, if they want them off, is harder.
    Eliminate the problem by deleting all such indent wrappers.

    Add formatters for the intN, uintN and one_or_more types to the
    default formatter map. Their previous absence was an oversight.

    Add a function, get_formatter_map_entry_types, that returns the ids
    of the types in the formatter_map given to the function. It is intended
    for tests/hard_coded/test_pretty_printer_defaults.m, but is exported
    for anyone to use.

tests/hard_coded/test_pretty_printer_defaults.{m,exp}:
    Use get_formatter_map_entry_types to print the default formatter map
    in a format that is much more easily readable.

NEWS:
    Announce all the user-visible changes above.
2022-12-27 18:27:52 +11:00
Julien Fischer
870c831a79 Update 22.01.5 NEWS file.
NEWS:
    Mention the recent fix for transitive intermodule optimization
    dependencies.
2022-12-27 15:37:33 +11:00
Julien Fischer
5274170784 Make characters an instance of the uenum typeclass
The recent change to sparse_bitsets broke the lex library in extras.
Specifically, we now now need to make characters an instance of the
uenum typeclass. This diff does so.

library/char.m:
     Add predicates and functions for converting between unsigned integers
     and characters.

     Make characters an instance of the uenum typeclass.

tests/hard_coded/Mmakefile:
tests/hard_coded/char_uint_conv.{m,exp,exp2}:
     Add a test of the above conversions.

NEWS:
     Announce the additions.

extras/lex/lex.m:
     Conform to recent changes.
2022-12-20 20:18:54 +11:00
Peter Wang
4a7cb098bf Prefer predicate over field update notation.
library/bitmap.m:
    Prefer predicate over field update notation.
2022-12-20 11:07:14 +11:00
Zoltan Somogyi
5206fc5bbc Rename hlc-low-level-debug-grades to hlc-gdb-grades.
This should help reduce confusion.
2022-12-20 00:56:13 +11:00
Zoltan Somogyi
4b6219ad45 Update bitmap.m's programming style.
library/bitmap.m:
    Factor out repeated code.

    Use predicate versions of operations over function versions.

    Avoid advertising field access notation.

    Fix module name in exception messages.
2022-12-19 23:31:12 +11:00
Peter Wang
c7b9bb5186 Ensure trans_opt_deps rules can be read back.
When writing out a trans_opt_deps rule in a .d file,
always write each dependency on a separate line. If the rule is
written "horizontally" because there is only one dependency, e.g.

    foo.trans_opt_date : bar.trans_opt

then maybe_read_d_file_for_trans_opt_deps will not be able to parse the
list, and the .trans_opt file will not be used.

compiler/mmakefiles.m:
    As above.
2022-12-15 15:49:39 +11:00
Julien Fischer
98a7f0089a Announce the recent fix for string switches.
NEWS:
    As above.
2022-12-14 20:26:45 +11:00
Julien Fischer
43c7113262 Add a NEWS section for 22.01.5.
NEWS:
    As above.
2022-12-14 01:45:19 +11:00
Julien Fischer
51745bee09 Remove execute bit from a Makefile.
samples/c_interface/standalone_c/Makefile:
     As above.
2022-12-14 01:36:29 +11:00
Julien Fischer
d7a606af4c Update moose to conform to stdlib changes.
extras/moose/check.m:
extras/moose/grammar.m:
extras/moose/mercury_syntax.m:
     As above.
2022-12-14 01:28:34 +11:00
Julien Fischer
ca9fb057a1 Simplify some code.
compiler/handle_options.m:
compiler/intermod_analysis.m:
compiler/lookup_switch.m:
compiler/ml_top_gen.m:
compiler/modecheck_goal.m:
compiler/options_file.m:
compiler/string_switch.m:
compiler/term_constr_build.m:
compiler/term_constr_data.m:
compiler/term_constr_initial.m:
compiler/term_constr_util.m:
grade_lib/grade_setup.m:
     Replace the use of some predicates from the std_util module where more
     direct alternatives now exist.

     Update copyright notices.
2022-12-14 01:13:58 +11:00
Julien Fischer
4baf3b9f20 Delete trailing whitespace.
library/pretty_printer.m:
     As above.
2022-12-13 22:12:14 +11:00
Julien Fischer
ee8029bc9a Use list.take_while_not/4 in a few spots.
library/dir.m:
     As above.
2022-12-13 22:06:25 +11:00
Zoltan Somogyi
12c6926a7b Delete misleading comment. 2022-12-11 00:55:47 +11:00
Zoltan Somogyi
94fb9120c2 Build compiled_code_dependencies in natural order. 2022-12-10 11:21:08 +11:00
Zoltan Somogyi
e9e5f5f799 Add inst_preserving_condense to list.m.
library/list.m:
    As above,

NEWS:
    Announce the addition.

    Fix some typos.
2022-12-10 11:20:53 +11:00
Zoltan Somogyi
3831fc05af Stop using FindDeps for several target types.
compiler/make.dependencies.m:
    Inline target_dependencies into find_target_dependencies_of_modules.

    For several arms of the inlined switch (i.e. for several target types),
    replace the use of FindDeps with direct, first-order code.
    In some of these arms, the replacement is partial: it is done for some
    dependencies, but not all (yet).

    Give a type and its function symbols more meaningfule names.
2022-12-10 00:33:03 +11:00
Zoltan Somogyi
fc3c6b462c Update an expected output file for Java ...
... for a change to io.file.m on 2022 aug 24.
2022-12-09 23:56:59 +11:00
Zoltan Somogyi
8c98840193 Define a predicate to compute modules' dependencies.
compiler/make.dependencies.m:
    Create find_target_dependencies_of_modules, a version of the
    deps_set_foldl3_maybe_stop_at_error_find_union_fi predicate
    that is specialized to the call site make.module_target.m
    that passes make.dependencies.m's target_depencies function
    as its FindDeps argument.

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

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

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

    Make some code more readable.
2022-12-09 19:19:37 +11:00