Commit Graph

924 Commits

Author SHA1 Message Date
Julien Fischer
2a366cf295 Deprecate --no-ansi and --no-ansi-c.
--no-ansi (mgnuc) and --no-ansi-c (mmc) have not actually done anything for
many years now. Deprecate these options and remove their "use" throughout most
of the Mercury system. (The remaining uses are in the Makefiles for the Boehm
GC, which need to be updated separately.)

Also deprecate the internal compiler option --cflags-for-ansi.

compiler/options.m:
    Document that --no-ansi-c is now deprecated.

    Document that the internal option --cflags-for-ansi is now
    deprecated.

compiler/compile_target_code.m:
    Do not pass the ANSI options to the C compiler.

scripts/mgnuc.in:
scripts/mgnuc_file_opts.sh-subr:
    Deprecate the --no-ansi option; delete code that no longer does
    anything useful.

configure.ac:
    Delete the configuration variable CFLAGS_FOR_ANSI; it is only ever
    set to be empty. (The comment talks about --no-ansi doing other things
    in the mgnuc script. It used to also cause some preprocessor macros
    to be defined for compatibility with the system headers on some
    platforms -- that has not been the case since 2013.)

doc/user_guide.texi:
    Document that --no-ansi-c is deprecated.

bytecode/Mmakefile:
compiler/Mercury.options:
library/Mercury.options:
extras/odbc/odbc.m:
runtime/Mmakefile:
scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
tests/hard_coded/Mercury.options:
tests/valid/Mercury.options:
trace/Mmakefile:
util/Mmakefile:
    Conform to the above change.

NEWS.md:
    Announce the above.
2023-05-31 17:44:26 +10:00
Zoltan Somogyi
585c5f6165 Limit the size of insts we output in HLDS dumps.
The reason for this is that without such limits,

- the generation of a HLDS dump for the valid/inst_perf_bug_2 test case
  takes almost forever, and
- generates a multi-gigabyte HLDS dump, which causes e.g. vim to take
  forever to open.

Making the generation and use of HLDS dumps practical is worth the cost
of losing some information. (Information you can't afford to generate
or to use is lost anyway.)

compiler/options.m:
doc/user_guide.texi.m:
    Add a new option to limit the size of the insts we output
    in the inst tables part of HLDS dumps. This option should allow users
    to select the tradeoff between the amount of information being preserved
    and the cost of generating/using that information.

compiler/hlds_out_module.m:
    Pass the value of the new option to hlds_out_inst_table.m.

compiler/hlds_out_inst_table.m:
    Specify the size limit when writing out insts as either the keys or
    the values in the various kinds of inst tables.

compiler/parse_tree_to_term.m:
    To implement those limits, add inst_to_limited_size_term and
    inst_name_to_limited_size_term, versions of the old inst_to_term
    and inst_name_to_term functions that truncate the given inst or inst name
    at the given "size" if necessary. The measure of "size" is just
    function symbols in the resulting term in most cases, though
    we treat things that in practice never get too big, such as types,
    as "one", regardless of the number of function symbols they contain.

    To make the parallel between the old non-size-limiting and the new
    size-limiting versions of the relevant codes easier to see, transform
    the functions in the old code to predicates. (The new versions have
    to be predicates to allow the size to be passed along in a state var.)

compiler/hlds_out_goal.m:
    When we print out the argument modes of a unification, limit the depth
    to which we write out the various insts to three. This should be
    more than enough, because any inst that we now replace with "..."
    should be available in the mode information of the atomic goal that
    generates it, whether that goal is a unification or a call.
2023-05-29 10:45:53 +02:00
Zoltan Somogyi
da3e2e80d3 Make invoked_by_mmc_make part of the op_mode.
compiler/op_mode.m:
    Add a field that specifies whether the compiler was invoked by
    "mmc --make" to the opm_top_args top-level op_mode. This is the
    class of op_modes for which we need that info.

    Fill in this new field from the value of the --invoked-by-mmc-make
    option.

compiler/options.m:
    Add an "only_opmode_" prefix to the internal name of the
    --invoked-by-mmc-make option. Move this option next to the --make option.

    Improve the wording of some options' usage messages.

doc/user_guide.texi:
    Make the same changes in wording here as well.

compiler/add_pragma.m:
compiler/add_type.m:
compiler/exception_analysis.m:
compiler/handle_options.m:
compiler/headvar_names.m:
compiler/hlds_module.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mode_errors.m:
compiler/op_mode.m:
compiler/options.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.versions.m:
compiler/structure_sharing.analysis.m:
compiler/tabling_analysis.m:
compiler/term_util.m:
compiler/trailing_analysis.m:
compiler/unused_args.m:
    Conform to the changes above, either by finding out whether
    the compiler was invoked by mmc --make using the op_mode instead
    of the option, or by ignoring that info where not needed.
2023-03-11 16:55:06 +08:00
Chloé Kekoa
23cf3b5d38 Fix --no-warn-non-contiguous-decls documentation.
doc/user_guide.texi:
compiler/options.m:
    Name the option correctly in the documentation.
2023-03-03 07:21:16 +11:00
Julien Fischer
bbff6f8609 Fix a bug in string.format.
The current implementation of the unsigned conversion specifiers (i.e. %x, %X,
%o, %u) for fixed-size 8-, 16- and 32-bit signed integers works by casting
theses values into (word-sized) ints and then using the existing code for
formatting ints as unsigned values. This does not work for negative values as
they are being sign extended when converted to ints. For example,

      io.format("%x", [i8(min_int8)], !IO)

prints:

      ffffffffffffff80 (on a 64-bit machine)

rather than just:

      80

Fix the above problem by casting ints, int8s, int16s etc. that are being
formatted as unsigned values to uints and using the uint formatting code.

NOTE: the formatting code for 64-bit integers follows a different code path
and is not affected by any of this.

library/string.format.m:
    Implement unsigned conversion specifiers for non-64-bit signed
    integers by casting to uint and using the uint formatting code.

    Add predicates for converting signed integers into uints.

    The format_unsigned_int_* predicates can be deleted after this change
    is installed.

compiler/format_call.m:
    Implement unsigned conversion specifiers for non-64-bit signed
    integers by casting to uint and using the uint formatting code.

compiler/introduced_call_table.m:
    Update the table of introduced predicates.

compiler/options.m:
    Add an option that can be used to test whether this fix is
    installed.

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
tests/hard_coded/opt_format_sign_extend.{m,exp}:
    Test that formatting code introduced by the compiler does not
    accidentally sign-extend negative values.

tests/string_format/string_format_{o,x,u}.{m,exp,exp2}:
    Make these tests much more comprehensive then they previously
    were.
2023-01-27 17:16:54 +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
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
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
c138bbb632 Fix a bug in string trie jump switches.
compiler/ml_string_switch.m:
    Fix a too-strong sanity check. It insisted on a semidet switch
    containing code to handle the failure of the switch, but a switch
    on strings can be both semidet and cannot_fail if

    - the switched-on variable's inst is known to contain only the strings
      handled by the arms of the switch, and

    - one or more of the switch arms containing semidet code.

    In that case, the switch does not need a default case, since it would be
    unreachable.

compiler/options.m:
    Provide a way to test for the presence of this fix.
2022-12-08 19:15:56 +11:00
Zoltan Somogyi
4c528d429d Add <<u and >>u to library/{int,uint}*.m ...
... along with their unchecked equivalents. These differ from <<, >> and
their unchecked equivalents in that they take the shift amount as a uint,
instead of an int.

library/int.m:
library/int16.m:
library/int32.m:
library/int64.m:
library/int8.m:
library/uint.m:
library/uint16.m:
library/uint32.m:
library/uint64.m:
library/uint8.m:
    As above. The unchecked versions have only declarations, since
    these operations have been recognized as builtins for a while now.

NEWS:
    Document the new operations, and the recent change to recognize
    <<u and >>u as single tokens, and fix a typo in a recent addition.

configure.ac:
    Require the compiler to be sufficiently recent to be able to parse
    <<u and >>u as operators.

compiler/options.m:
    Provide a way for a later change to configure.ac to detect the presence
    of this change.

tests/hard_coded/bitwise_int.exp:
tests/hard_coded/bitwise_int.exp2:
tests/hard_coded/bitwise_int.m:
tests/hard_coded/bitwise_int16.exp:
tests/hard_coded/bitwise_int16.m:
tests/hard_coded/bitwise_int32.exp:
tests/hard_coded/bitwise_int32.m:
tests/hard_coded/bitwise_int64.exp:
tests/hard_coded/bitwise_int64.m:
tests/hard_coded/bitwise_int8.exp:
tests/hard_coded/bitwise_int8.m:
tests/hard_coded/bitwise_uint.exp:
tests/hard_coded/bitwise_uint.exp2:
tests/hard_coded/bitwise_uint.m:
tests/hard_coded/bitwise_uint16.exp:
tests/hard_coded/bitwise_uint16.m:
tests/hard_coded/bitwise_uint32.exp:
tests/hard_coded/bitwise_uint32.m:
tests/hard_coded/bitwise_uint64.exp:
tests/hard_coded/bitwise_uint64.m:
tests/hard_coded/bitwise_uint8.exp:
tests/hard_coded/bitwise_uint8.m:
    Check that <<u and >>u compute the same results as << and >> respectively.
2022-12-07 23:12:33 +11:00
Zoltan Somogyi
73d7d2ef6a Add a new synonym for compiler sufficiently recent. 2022-12-06 00:59:49 +11:00
Zoltan Somogyi
0337cee2df Add the new option --reverse-error-order.
compiler/options.m:
doc/user_guide.texi:
    As above.

NEWS:
    Announce the new option.

compiler/error_sort.m:
    Implement the new option.
2022-11-01 17:41:45 +11:00
Zoltan Somogyi
daa4513894 Add the new compiler option --show-local-call-tree.
When specified, this option causes the compiler to output,
to <module>.local_call_tree, a flattened form of the part of the
module call tree restricted to local predicates and functions, like this:

    pred polymorphism_process_module/5
        pred maybe_polymorphism_process_pred/7
        pred polymorphism_update_arg_types/5

    pred maybe_polymorphism_process_pred/7
        pred polymorphism_process_pred_msg/7

    pred polymorphism_process_pred_msg/7
        pred polymorphism_process_pred/6

    pred polymorphism_process_pred/6
        pred polymorphism_process_clause_info/6
        pred add_extra_arg_modes_to_proc/3

This output consists of a list of entries, with each entry naming
a predicate or function, and listing all the local predicates and functions
it calls. Both the callees in a single entry and the entries themselves
are in the order in which a depth-first left-to-right traversal of the
module, starting at the exported predicates and functions, would encounter
them. That order is also output to <module>.local_call_tree_order.
This information can give useful guidance about how the contents
of a module should be ordered.

doc/user_guide.texi:
compiler/options.m:
    As above.

NEWS:
    Announce the new option.

compiler/hlds_call_tree.m:
    A new module to implement the new option.

compiler/hlds.m:
compiler/notes/compiler_design.html:
    Add and document the new module.

compiler/mercury_compile_front_end.m:
    Invoke the new module if the new option is set.

compiler/hlds_desc.m:
    Add describe_pred and describe_pred_from_id. Reimplement
    describe_proc and describe_proc_from_id in terms of those.
    Allow callers of all four to decide whether we want the descriptions
    to include the names of the defining module.

compiler/dead_proc_elim.m:
compiler/ml_proc_gen.m:
compiler/proc_gen.m:
    Conform to the change to hlds_desc.m.

compiler/hlds_goal.m:
    Document when it is ok for traversals of goals to assume that
    they won't find any rhs_lambda_goals or complicated_unifys
    in unifications.

    Change the documentation of the five classes of unifications
    (construct/deconstruct/assign/simple_test/complicated_unify)
    to refer to the LHS as X and the RHS as Y, since pretty much
    all the modules focusing on unifications (such as superhomoneous.m)
    use that naming convention. Having the opposite convention here
    was not a good idea.

compiler/prog_data.m:
    Fix comment rot.
2022-09-25 18:04:20 +10:00
Zoltan Somogyi
47ca4f9a66 Let disable_warning apply to unknown_format_calls.
doc/reference_manual.texi:
NEWS:
    Allow a disable_warning scope to override the setting of the
    --warn-unknown-format-calls option to "yes" inside its scope.

compiler/prog_data.m:
    Provide a representation for the new kind of disable-able warning.

compiler/parse_goal.m:
    Parse the new kind of disable-able warning.

compiler/prog_out.m:
    Print out the new kind of disable-able warning.

compiler/format_call.m:
    Add a parameter to the format checking code to control whether
    we generate this warning. Using this parameter yields clearer code
    that locally overriding the value of the option.

compiler/simplify_goal_scope.m:
    Ignore the new kind of disable-able warning in code that has nothing
    to do with it.

compiler/options.m:
doc/user_guide.texi:
    Fix an old issue: include stream.string_writer.format in the description
    of --warn-unknown-format-calls.

tests/warnings/disabled_warning.{m,exp}:
    Add a test of the new functionality.

tests/warnings/Mmakefile:
tests/warnings/Mercury.options:
    Enable the new test case.
2022-08-24 16:33:46 +10:00
Zoltan Somogyi
26be4bb8e3 Add --warn-ambiguous-pragmas.
The new option is on by default, and it generates a warning about pragmas
that specify a name/arity pair that matches both a predicate and a function,
but does not say which one it is intended to apply to.

compiler/options.m:
doc/user_guide.texi:
    Add the new option.

NEWS:
    Announce the new option.

compiler/add_pragma.m:
    Implement the new option.

    Move to one predicate, get_matching_pred_ids, the code for dealing with
    both the absence of any matches, and the presence of more than one match,
    when looking up name/arity pairs in the predicate table. This allows us
    to delete the mostly-duplicate code fragments that did the same thing
    in all of get_matching_pred_ids's callers.

    Simplify the handling of conflicts between marker pragmas.

compiler/hlds_pred.m:
    Separate out no_inline decisions made by the compiler itself from
    the similar decisions made by users, in order to allow that simplification.

    Move the two inline markers next to each other.

compiler/make_hlds_error.m:
    Change a predicate called from add_pragma*.m to take user arities
    in their semantic form, not their int form, which raises the level
    of the predicate's interface, and factors out duplicate code in its
    callers.

compiler/add_pragma_type_spec.m:
compiler/intermod.m:
compiler/table_gen.m:
    Conform to the changes above.

doc/reference_manual.texi:
    Document pred(...) and func(...) wrappers around name/arity pairs
    in pragmas.

    Delete the commented out section on reserve_tag pragmas, which were
    deleted a while ago.

tests/invalid/inline_conflict.m:
    Expand this test case to test the *absence* of a warning for an
    ambiguous pragma with --no-warn-ambiguous-pragma.

tests/invalid/inline_conflict_warn.{m,err_exp}:
tests/invalid/Mercury.options:
    Add a copy of the inline_conflict test case to test the presence of
    a warning for an actually ambiguous pragma.

tests/invalid_nodepend/fact_table_in_interface.err_exp:
    Expect the updated wording of a warning.
2022-07-31 18:17:02 +10:00
Julien Fischer
cedbee7190 Move quote_arg/1 out of options.m.
Move the function quote_arg/1, which is used to quote arguments to shell
commands, out of options.m and into its own module. It is called from
several other places other than options.m and its implementation details
have nothing to do with the other contents of options.m.

Rename the function to quote_shell_cmd_arg/1.

compiler/shell_util.m:
    New module for quote_arg/1 and its supporting predicates.

compiler/libs.m:
    Include the new module.

compiler/options.m:
compiler/compile_target_code.m:
compiler/file_util.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Import the new module where necessary.

compiler/notes/compiler_design.m:
    Update this document.
2022-07-25 23:43:25 +10:00
Julien Fischer
ae0525af53 Add string.contains_match/2.
Add a new predicate that tests if string contains any characters that succeed
for a given test predicate.

library/string.m:
    Add the new predicate.

compiler/options.m:
    Replace the predicate string_contains_whitespace/1 defined here
    with a call to the new library predicate.

NEWS:
    Announce the new predicate.

tests/hard_coded/Mmakefile:
tests/hard_coded/string_contains_match.{m,exp}:
    Add a test of the new predicate.
2022-07-25 19:38:01 +10:00
Julien Fischer
abc65f4d05 Improvements to the Java launcher scripts.
Add new options that allow Java runtime flags to be set in the launcher scripts
we generate for executables in the Java grade.

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

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

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

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

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

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

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

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

NEWS:
    Announce the above changes.
2022-07-23 11:45:03 +10:00
Zoltan Somogyi
08365979d0 Move pred_name.m to the HLDS package.
This is so that it can become the home of the type currently named
pred_origin in hlds_pred.m, which (after being given new name) will become
a structured representation of predicate names.

The only thing that kept pred_name.m in the parse_tree package was the fact
that parse_pragma.m, which has no access to the hlds package, called it
to create the name of a type-specialized predicate when parsing
type_spec pragmas. The main part of this diff, apart from the trivial
updates to import hlds.pred_name instead parse_tree.pred_name, deals
with this issue.

The problem is how to ensure that the compiler invocations that create
type-specialized predicates (invocations that compile the module containing
the type_spec pragma that calls for this) and the invocations that create
the calls to those predicates (invocations that mostly compile other modules)
agree on the name of the name of the type-specialized predicate.

The old approach was this.

    When reading in (say) mod1.m which contains a type_spec pragma,
    we construct the name of the type-specialized predicate from

    - the name of the module (mod1),
    - the name of the predicate to be specialized, and
    - the type substitution in the pragma.

    We then record this name in the pragma.

    If the compiler invocation generates code, we use this name in the
    predicate definition. If the compiler invocation creates a .int file,
    we record the name in the third argument of the type_spec pragma.
    This third argument is NOT allowed to exist in .m files.

    Other compiler invocations that read in mod1.int when compiling
    another module, e.g. mod2.m, use the specialized name in the third argument
    of the type_spec pragma as the name to use in calls.

In this approach, the single-source-of-truth about the name of the
type-specialized predicate is the name constructed when parsing mod1.m,
which is conveyed to compiler invocations on other modules through
the third argument of the type_spec pragma.

The new approach is this:

    When reading in (say) mod1.m which contains a type_spec pragma,
    we give guaranteed-to-be-unique names to all the anonymous variables
    in the type_spec pragma. We also record in the type_spec pragma
    the name of the module whose (source or interface) file we read
    the pragma from. The name of the predicate to be specialized
    was of course already in the pragma.

    If the compiler invocation generates code, we construct the name
    of the type-specialized version of the predicate when we add the
    all-tvars-are-named type_spec pragma to the HLDS. If the compiler
    invocation creates a .int file, we write out the all-tvars-are-named
    version of the type_spec pragma. The pragma also contains the predicate
    name to be specialized. It does not contain the name of the module,
    but we will write out type_spec pragmas from module_x.m *only* to
    module_x.int, never to any other .int file, so any readers of
    the type_spec pragma from mod1.int will also know the name of the
    module that the pragma came from.

    Other compiler invocations that read in mod1.int when compiling
    another module, e.g. mod2.m, therefore get exactly the same

    - module name,
    - the name of the predicate to be specialized, and
    - the type substitution in the pragma

    as the compiler invocations on mod1.m. The module name are the
    predicate name are never changed by being written out and then
    read back in, and *due to the explicit names given to any formerly
    anonymous variables*, the type substitution is changed by this either.
    This means that the compiler invocations on mod1.m and mod2.m
    give the same parameters to the same function, and therefore they are
    guaranteed to get the same string as the name of the type-specialized
    version of the predicate.

In this approach, the single-source-of-truth about the name of the
type-specialized predicate is the function constructing that name
and its inputs.

compiler/hlds.m:
compiler/parse_tree.m:
compiler/pred_name.m:
    Move pred_name.m from the parse_tree package to the hlds package.

compiler/prog_item.m:
    Change the representation of type_spec pragmas to

    - delete the name of the specialized predicate, and replace it with
    - the name of the module the pragma was read in from.

compiler/parse_pragma.m:
    Delete the code for parsing the third argument of type_spec pragmas.
    Allow them to exist for a short transition period, but ignore them.
    (If we read in files containing them, the result will be a link error
    if the type substitution contains anonymous variables. In that case,
    a rebuild of the program with all modules compiled using the *same
    compiler version* will work.)

    Give guaranteed-to-be-unique names to all anonymous type variable
    in the type substitution part of the type_spec pragma we construct.

compiler/add_pragma_type_spec.m:
    Construct the name of the type-specialized predicate as the type_spec
    pragma is added to the HLDS.

compiler/parse_tree_out_pragma.m:
    Never write out a type_spec par_loop_control with a third argument.

    Delete the var_name_print argument of the predicate that writes out
    type_spec pragmas. Instead, *always* use print_name_only.

compiler/options.m:
    Add a way of testing whether the installed compiler has this change.

compiler/accumulator.m:
compiler/add_pragma_tabling.m:
compiler/add_special_pred.m:
compiler/base_typeclass_info.m:
compiler/check_typeclass.m:
compiler/dep_par_conj.m:
compiler/distance_granularity.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/layout_out.m:
compiler/lco.m:
compiler/loop_inv.m:
compiler/make_hlds_passes.m:
compiler/name_mangle.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_loop_control.m:
compiler/parse_tree_out.m:
compiler/pd_info.m:
compiler/prog_rep.m:
compiler/ssdebug.m:
compiler/stm_expand.m:
compiler/structure_reuse.versions.m:
compiler/table_gen.m:
compiler/tupling.m:
compiler/untupling.m:
compiler/unused_args.m:
2022-07-20 21:33:09 +10:00
Zoltan Somogyi
ee34187966 Don't print specialization requests with -V.
compiler/options.m:
doc/user_guide.texi:
    Introduce a new option, --debug-higher-order-specialization.

compiler/higher_order.m:
    Print messages about procedures being specialized to a specific
    higher-order value only if this new option is specified, not when
    -V is specified, since these messages are of interest only to people
    who are actively working on higher_order.m.

    Check whether the option is enabled just once, rather than performing
    that test, and possibly the creation of the progress output stream,
    once per specialization.
2022-05-13 19:24:09 +10:00
Zoltan Somogyi
189e426bc6 Extend debug messages from dead_proc_elim.m.
compiler/dead_proc_elim.m:
    If the new option --debug-dead-proc-elim is enabled, print information
    about why each procedure (actually any entity) we cannot delete
    is actually needed. This is the information we need when we want
    to find out why procedures that we think should have been deleted
    haven't been. This requires modifying the needed map to keep track
    of this information.

    Also, use the same option, instead of -V, to control whether we print
    messages about which predicates/procedures have been eliminated,
    since such messages are rarely of interest to anyone who is not actively
    working on dead_proc_elim.m.

    To allow these two sets of diagnostics to come out in the natural order
    (first what we need and why, and then what we could eliminate), don't
    print messages about what we eliminated as we go along. Instead,
    gather up a map of what we eliminated from each affected predicate,
    and print all the messages, in sorted order, at the end. Fix the
    messages themselves by avoiding phrasing such as "Eliminated the dead
    procedure function ...".

    Refer to procedures in entities using a pred_proc_id instead of
    separate pred- and proc_ids, to minimize the conversions required
    to the new data structures.

    Improve documentation.

compiler/options.m:
doc/user_guide.texi:
    Add the new developer-only option --debug-dead-proc-elim.

compiler/mercury_compile_middle_passes.m:
    Print the needed map and list of eliminated procedures only if
    the new option is enabled.

compiler/deep_profiling.m:
compiler/inlining.m:
    Conform to the changes in dead_proc_elim.m.

library/set_ctree234.m:
    Enable a sanity check only with the right trace flag.
2022-05-13 18:50:08 +10:00
Julien Fischer
8731d16c74 Fix spelling.
compiler/options.m:
doc/user_guide.texi:
    As above.
2022-04-18 23:57:12 +10:00
Zoltan Somogyi
0186a64520 Warn for unneeded use of mode-specific clauses.
compiler/add_clause.m:
    Generate a warning for mode-specific clauses when the clause is for
    a predicate that has only one mode, provided that the warning is enabled.

compiler/options.m:
    Add an option to enable this warning.

doc/user_guide.texi:
    Document this option.

library/exception.m:
library/int.m:
library/rtti_implementation.m:
library/string.m:
    Delete modes from clause heads that would get this warning.

tests/valid/spurious_purity_warning.m:
    Delete modes from clause heads that would get this warning.

    Do not interleave predicate definitions.

tests/warnings/unneeded_mode_specific_clause.{m,exp}:
    A test case for this warning.
tests/warnings/Mmakefile:
    Enable the new test case.

tests/invalid/multimode_syntax.err_exp:
    Expect the new warning.
2022-04-13 23:39:23 +10:00
Julien Fischer
105580a765 Delete the trseg component and --trail-segments option.
Trail segments have been the default in trailing grades since Mercury 20.06.
Delete the trseg grade components and --trail-segment option since apart from
acting as synonyms for the tr component and --use-trail option repsectively,
they no longer do anything.

compiler/compute_grade.m:
compiler/handle_options.m:
compiler/options.m:
doc/user_guide.texi:
grade_lib/grade_vars.m:
scripts/parse_grade_option.sh-subr:
grade_lib/grade_string.m:
grade_lib/grade_vars.m:
   Delete the trseg grade component and --trail-segments option.

compiler/add_pragma.m:
   Update the wording of an error message.

NEWS:
   Announce the above.

extras/trail/Mercury.options:
extras/trailed_update/Mmakefile:
extras/references/Mercury.options:
tests/invalid/test_feature_set.err_exp:
    Conform to the above changes
2022-04-05 17:02:40 +10:00
Zoltan Somogyi
b897284fb7 Allow testing for the recent subtype .opt fix. 2022-02-19 17:34:24 +11:00
Zoltan Somogyi
206aad721d Delete almost all remaining references to Erlang.
The only references remaining are for telling users who try to target Erlang
that this is no longer possible.

compiler/options.m:
    Delete all erlang-specific options.

compiler/handle_options.m:
compiler/options_file.m:
    Delete references to erlang-specific options.

compiler/compute_grade.m:
    Fix one of those error messages.

compiler/parse_type_repn.m:
    Delete old backward-compatibility hack, and fix error messages.

compiler/simplify_goal_call.m:
compiler/simplify_goal_unify.m:
    In two places, we used to check whether the can_compare_compound_values
    option is set. This option was only ever set for erlang, so this diff
    has deleted it. Replace those tests with semidet_fail. This makes the
    code guarded by the tests unreachable, but still keeps it around and
    checked by the compiler, in case we need it again later.
2022-01-23 03:34:36 +11:00
Zoltan Somogyi
87a05b7b95 Add the new option --output-stdlib-grades.
compiler/mercury_compile_main.m:
    Implement the new option. Doing so without duplicating the existing
    code tree of detect_libgrades required factoring out its reusable parts.

    Do not pass I/O states to computations that do not need them.

    Add XXXs for some questionable past decisions.

compiler/op_mode.m:
    Define the new op_mode selected by the new option.

compiler/options.m:
doc/user_guide.texi:
    Add and document the new option, and revert my screw-up of the
    documentation of --output-libgrades.

compiler/options_file.m:
    Make the interface of another predicate less error prone.

NEWS:
    Mention the new option.
2022-01-21 20:59:02 +11:00
Zoltan Somogyi
6e11ee923f Improve documention of the query options.
compiler/options.m:
doc/user_guide.texi:
    As above. Also, fix some existing inconsistencies between these two files.
2022-01-14 21:43:03 +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
Julien Fischer
419feb0ba3 Add a missing word.
compiler/options.m:
doc/user_guide.texi:
    As above.
2021-12-21 12:48:08 +11:00
Zoltan Somogyi
da4b368fac Fix compiler abort adding pragmas for unknown procs.
compiler/add_pragma.m:
    The code that added gen_pragmas (pragmas that are generated
    *only* by the compiler, and which hold the analysis results)
    to the HLDS checked whether the *predicate* named by the pragma
    existed, and was prepared for the case where it did not.
    However, it was NOT prepared for the case where the predicate
    did exist, but the *procedure* whose mode number the pragma also named
    did not exist. It called module_info_pred_proc_info, which did a map.lookup
    in the predicate's procedure table, which crashed the compiler
    when the lookup failed.

    The code that puts these pragmas into .opt files does not check
    whether the pragma is for a predicate whose declaration will be visible
    to the readers of the .opt file, either by being contained in the
    module's .int file (for exported predicates) or in the .opt file itself
    (for nonexported predicates). Fixing that will be next.

    To help with that fix, change how we handle pragmas whose target
    predicate/procedure is not uniquely determined, i.e. either unknown
    or ambiguous. Before, we always ignored the error. Now, we still do that
    by default, but a developmer can now specify a new option
    which will cause add_pragma.m to generate an informational message
    for each such pragma.

compiler/options.m:
    Add the new option, --inform-ignored-pragma-errors.

doc/user_guide.texi:
    Document the new option, as well as an old one whose documentation
    was missing.
2021-12-19 18:15:47 +11:00
Zoltan Somogyi
63a17c6346 Add --halt-at-warn-make-{int,opt}.
compiler/options.m:
doc/user_guide.texi:
    Add these two new options, which function as --halt-at-warn when
    generating interface files and optimization files respectively.
    Document them both for users and for developers.

compiler/handle_options.m:
    Set --halt-at-warn from --halt-at-warn-make-int when making interface
    files, and from --halt-at-warn-make-opt when making optimization files,
    allowing the test of the compiler to look at only --halt-at-warn.
2021-12-17 23:57:55 +11:00
Zoltan Somogyi
8f50e16eb2 Fix a possible silent failure when making .int files.
When I split two files in a recent change, I ran into an annoying problem.
The problem was caused by unneeded imports in the interface of the new modules,
whose initial part I originally simply copied from the source module.
The problem was that when I attempted to compile new module A which imported
new module B, the compilation of module A would fail with a message about
not finding module B's .int file. It couldn't find B.int because the
compiler invocation that was supposed to create it failed, but it did not
print any error message about *why* it failed, and as a consequence,
it also did not set the exit status to nonzero to tell mmake that
the file was not actually built, so later build actions that need that file
should not be executed.

The cause of this problem was the following.

- The default value of the --warn-unused-imports is off, but COMP_FLAGS
  turns it on for modules in the compiler directory. This enables warnings
  generated by unused_imports.m.

- There is code that does a similar job in module_qual.qual_errors.m, but
  that one is limited to imports in interface sections. Due to the overlap
  between tasks, when this code finds an unused import_module declaration
  in an interface, it generates an error message that was conditional
  on --warn-unused-imports being off. When it was on, as it is with
  COMP_FLAGS, it generates an error_spec that, when given to write_error_specs,
  generates no output.

- Code in write_module_interface_files.m that decided whether the building
  of the .int file has failed, tested only whether the process of generating
  its contents has returned any error_specs, not whether it returned
  any error_specs that would actually be printed, and, by being printed
  with a sufficiently high severity, would set the exit status to signal
  failure.

compiler/error_util.m:
    The two changes to this file together fix the root cause of this problem.

    First, a new predicate checks whether an error_spec has any part
    whose printing is NOT disabled by being attached to an unmet condition.

    Second, the predicate through which we pass all error_specs created
    during the generation of the contents of the .int file filters out
    any error_specs that yield no output.

The later changes are not strictly part of the bugfix, they are there
simply to make the code simpler to understand, in the hope that this fact
will reduce the probability of similar problems in the future.

compiler/module_qual.qual_errors.m:
    Instead of generating error_specs that are conditional on
    --warn-unused-imports being OFF, generate them conditional on
    the new option --warn-unused-interface-imports being ON.
    Using --warn-unused-imports here was strange because that option controls
    whether the compiler invokes unused_imports.m. It was NOT specific
    to this piece of code, while the new option is.

compiler/options.m:
doc/user_guide.texi:
    Add the new option. Comment out its documentation, since I don't think
    I can describe the reason for its existence simply enough for users
    to understand.

compiler/handle_options.m:
    Turn off the new option --warn-unused-interface-imports if
    --warn-unused-imports is set. This duplicates the old behavior
    of module_qual.qual_errors.m.

    Turn off the new option --warn-unused-interface-imports if
    we are generating interface files. This is because the presence
    of unneeded imports in .m files does not prevent the creation
    of valid .int files, so having to fix such warnings at .int file
    creation time interferes with the programmer's ability to choose
    the order in which he/she works on getting modules to a compilable shape.

compiler/write_module_interface_files.m:
    Generate all output on error as part of an error_spec.

compiler/unused_imports.m:
    Fix indentation.

tests/valid_make_int/extra_interface_import.m:
    A new test case for this bug.

tests/valid_make_int/Mmakefile:
    Enable the new test case.
2021-12-17 12:55:29 +11:00
Zoltan Somogyi
8827b6a466 Make --halt-at-invalid-interface the default.
NEWS:
    Mention this fact.

    Group related changes together.

    Fix some typos.

compiler/error_util.m:
    Let the halt_at_invalid_interface option govern whether we print error
    messages when we generate .int/.int2 files, rather than
    the print_errors_warnings_when_generating_interface option.
    This simplifies the use of that option.

compiler/options.m:
doc/user_guide.texi:
    Document the halt_at_invalid_interface option.

    Delete the print_errors_warnings_when_generating_interface option,
    since its functionality has been subsumed into halt_at_invalid_interface.

compiler/grab_modules.m:
    Check the accessibility of imported modules not just when generating target
    language code, but also when generating .int/.int2 files. Without this,
    the test_nested test case, which this diff moves from invalid to
    invalid_make_int, would miss out on some errors being reported
    in its new home.

    To make the above possible, refactor the code that does the check
    to let it work on aug_make_int_units as well as from aug_compilation_units.
    Make the wording of any error message depend on where the info came from,
    because unlike aug_comp_units, aug_make_int_units work with an
    known-incomplete picture of the relevant info.

    Update some obsolete comments.

compiler/write_module_interface_files.m:
    Add a comment about a design decision that affects this diff.

tests/invalid_make_int/Mercury.options:
tests/invalid_make_int/Mmakefile:
    Add to this directory's list the test cases that this diff moves
    to this directory from other test directories, because the errors
    that they test for are now reported at interface generation time.

    Fix the rule handling multimodule tests, now that we have some :-(

    Specify -j1 for this directory, since the two tests moved here
    from invalid_submodules include nested submodules.

tests/invalid_make_int/bad_type_class_constraint_intermodule.{m,int_err_exp}:
    Move this test case here from invalid, renaming files slightly,
    and update the expected output.

tests/invalid_make_int/bug499.{m,int_err_exp}:
    Move this test case here from invalid, and update the expected output.

tests/invalid_make_int/int_impl_imports.{m,int_err_exp}:
tests/invalid_make_int/int_impl_imports_2.m:
    Move this test case here from invalid, and update the expected output.

tests/invalid_make_int/missing_interface_import2.{m,int_err_exp}:
tests/invalid_make_int/missing_interface_import3.m:
    Move this test case here from invalid, and update the expected output.

tests/invalid_make_int/missing_parent_import.{m,int_err_exp}:
tests/invalid_make_int/children.m:
tests/invalid_make_int/children2.m:
    Move this test case here from invalid_submodules,
    and update the expected output.

tests/invalid_make_int/sub_c.{m,int_err_exp}:
tests/invalid_make_int/sub_a.m:
    Move this test case here from invalid_submodules,
    and update the expected output.

tests/invalid_make_int/test_nested.{m,int_err_exp}:
tests/invalid_make_int/parent.m:
tests/invalid_make_int/parent.private_child.m:
tests/invalid_make_int/parent.public_child.m:
tests/invalid_make_int/parent.undeclared_child.m:
tests/invalid_make_int/parent2.child.m:
tests/invalid_make_int/parent2.m:
    Move this test case here from invalid, and update the expected output.

tests/invalid_make_int/transitive_import.{m,int_err_exp}:
    Move this test case here from invalid, update it,
    and update the expected output.

tests/invalid/Mmakefile:
    Delete from the list of tests in this directory the tests
    moved to invalid_make_int, and test bug521.

tests/invalid/bug521.{m,err_exp}:
tests/invalid/bug521_sub.m:
    Delete this test. invalid_make_int already had a copy of the relevant
    part of this test.

tests/invalid_submodules/Mmakefile:
    Delete from the list of tests in this directory the two tests
    moved to invalid_make_int.

    Delete from the list of tests in this directory two other tests
    for which we now detect some or all of the errors tested for
    at interface generation time, but which are already covered
    by other tests.

tests/valid_make_int/Mmakefile:
    Delete from the list of tests in this directory the test
    moved to invalid_make_int. (We could successfully generate
    a .int file for that test case *only if* we did not check it
    for errors :-)

tests/valid_seq/intermod_nested_module_bug2.m:
tests/valid_seq/intermod_nested_module_bug2.sub.m:
    Move two module imports from the parent to the child module,
    because only the child needs them, and any compiler with this diff
    will now complain about them being unused in the parent
    at interface generation time. Delete a third import, which was
    not used anywhere.
2021-11-20 23:49:19 +11:00
Zoltan Somogyi
903135abad Add the --debug-types-pred-name <Name> option.
The idea is to allow people debugging the typechecker to restrict
checkpoint output to the typechecking of one or more named predicates.

compiler/options.m:
doc/user_guide.texi:
    Add the new accumulating option.

compiler/typecheck_info.m:
    Add a field to the typecheck_info (actually, the typecheck_sub_info)
    that records whether the user wants checkpoint output from the
    typechecking of the current predicate.

compiler/typecheck_debug.m:
    Use this new field to make decisions, instead of looking up options
    in the globals structure at every checkpoint.

compiler/typecheck.m:
compiler/typeclasses.m:
    Conform to the change in typecheck_debug.m.
2021-08-09 09:28:06 +10:00
Zoltan Somogyi
aed31c7eda Fix several test case failures.
tests/debugger/user_event_shallow.{m,exp}:
    Mark a predicate with no_inline to prevent -O5 from optimizing
    away an event that the .inp of this case depends on.

tests/invalid/Mmakefile:
    Make the test cases in this directory work even if code generation
    requires reading in the module's own .int file.

tests/invalid/bad_item_in_interface.err_exp2:
    Add an expected output file for grades that do not support memoisation.

tests/invalid/bad_item_in_interface.m:
    Document the reason for the existence of the .err_exp2 file.

tests/options_file/Mmakefile:
    Make the test cases in this directory work even if code generation
    requires reading in the module's own .int file.

    Conform to the changes below.

compiler/options.m:
doc/user_guide.texi:
    Make the --dump-options-file file take an argument that specifies
    the file to which the contents of the options file should be dumped.

compiler/mercury_compile_main.m:
compiler/options_file.m:
    Dump the options file to the specified file, if the filename is not "".
2021-07-30 01:43:59 +10:00
Zoltan Somogyi
2c89d237c8 Don't set experiment[34], which are unused. 2021-07-24 23:51:38 +10:00
Julien Fischer
0a32475a83 Fix misspelt option name.
compiler/options.m:
    As above.
2021-06-19 20:34:45 +10:00
Zoltan Somogyi
8a4807a0cd Add option --warn-potentially-ambiguous-pragma.
compiler/options.m:
doc/user_guide.texi:
    As above.

compiler/add_pragma.m:
    Provide mechanisms that, if this option is set, generate a warning
    for pragmas that take a symname/arity pair but do not say whether
    they are for a predicate or a function.

    Use these mechanisms for all pragmas added to the HLDS in this module.

compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
    Use these mechanisms for all pragmas added to the HLDS in these modules.
2021-06-16 15:18:45 +10:00
Zoltan Somogyi
d48cbb5d70 Use explicit streams in some more modules.
compiler/closure_analysis.m:
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/options.m:
    As above.

compiler/compiler_util.m:
    Delete the old report_warning predicate, and replace it with
    a renamed report_warning_to_stream predicate.

compiler/Mercury.options:
    Don't specify --no-warn-implicit-stream-calls for the above modules.

compiler/make.build.m:
compiler/make.program_target.m:
compiler/mercury_compile_main.m:
compiler/tupling.m:
    Conform to the changes above.
2021-06-11 17:17:54 +10:00
Peter Wang
1dcebc891b Fix -O<n> options below default optimisation level.
The default optimisation level was implemented by having the
Mercury.config file add a -O<n> option to the DEFAULT_MCFLAGS variable.
This allowed the user to override the default optimisation level
by setting the MERCURY_DEFAULT_OPT_LEVEL environment variable.

Commit 181ada0dbf made it so that -O<n>
options do not reset previously set options. This had the unintended
consequence that any -O<n> options below the default optimisation level
had no effect when passed on the command line or in a Mercury.options
file, because a -O<n> option passed by the user would never undo the
options set by the default optimisation level.

compiler/options.m:
    Add new option `--default-opt-level' for use by Mercury.config.

tools/make_optimization_options_end:
    Add predicate to parse the value of `--default-opt-level' from the
    options table. The option value is a string because the value of the
    MERCURY_DEFAULT_OPT_LEVEL environment variable will be passed as
    the option value. The existence of the environment variable was
    (barely) documented, but the allowable values are not.
    Though the user might conceivably have set any Mercury compiler
    option in that environment variable, the value was probably only
    intended to be a string of the form "-O<int>", and that is all we
    will support.

tools/make_optimization_options_middle:
    Use `get_default_opt_level'.

compiler/optimization_options.m:
    Regenerate this file.

compiler/options_file.m:
    Do not automatically add "-O2" to MCFlags.
    The comment says this was to set a default optimisation level when
    calling the `mercury_compile' binary instead of the `mmc' script,
    but `get_default_opt_level' already defaults to optimisation level 2.

scripts/Mercury.config.in:
    Pass the value of MERCURY_DEFAULT_OPT_LEVEL using the
    `--default-opt-level' option.
2021-06-07 16:49:54 +10:00
Zoltan Somogyi
9c4a8be0f6 Let simplify introduce ground_term_const cons_ids.
This diff gives simplification the ability to look for construction
unifications X = f(...) that construct static terms, and to replace
those unifications with unifications X = ground_term_const(N), where
entry #N in the const_struct_db is f(...).

The idea is to ask simplification to do this when it is invoked
at the end of the front end. Later on, if and when we identify one or more
middle passes that may introduce new code that benefit from this
optimization, we could ask the pre-code-generation invocation
of simplification to repeat this optimization; until then,
such a repeat is not warranted.

In the long term, this diff should enable us to discard mark_static_terms.m,
the construct_statically code path in ml_unify_gen_construct.m, and the
equivalent code in the LLDS code generator.

compiler/common.m:
    This new optimization is done in common.m. The reason for this is that
    when this optimization is applicable, it overrides one part of common.m's
    functionality (replacing X = f(...) with X = Y, if Y already contains
    f(...)), but not another (gathering information about variable
    equivalences for use in optimizing away and/or warning about
    duplicate calls). Such half-override would be effectively impossible
    to arrange from a new module.

    Because of the need for this partial override, have this module,
    rather than simplify_goal_unify.m, make decisions about exactly
    what is to be done for each unification.

    For a similar reason, bring part of the logic controlling the recording
    of stack flushes here from simplify_goal.m.

compiler/simplify_tasks.m:
    Add the new optimization as a new task that simplification may be asked
    to do.

    Rather than add it as yet another bool field in the simplify_tasks
    structure, add it with its own bespoke bool-like type, and replace
    all the other bools with separate bespoke types as well.

    Do the same with the "should we generate warnings" flag for
    find_simplify_tasks. Fix simplify_tasks's arg order.

    Switch from (C->T;E) to (if C then T else E) syntax.

compiler/optimization_options.m:
compiler/options.m:
tools/make_optimization_options_db:
    To let simplify_tasks.m know whether the use of constant structures
    is allowed, either for terms created by the polymorphism pass,
    or for user terms, use two separate optimization options for these two
    separate though related concepts. Keep the one that is relevant only
    for the polymorphism pass invisible to users.

compiler/handle_options.m:
compiler/const_struct.m:
    Move the code that adjusts the values of these two options
    based on the target language and on the values of other options
    from const_struct.m to handle_options.m, so that information
    simplify_tasks.m needs is available in the globals structure
    it is passed (i.e. so that we don't have to pass it a const_struct_db).

    Suppress the use of const structs for user terms when generating
    optimization interface files, because after this change to common.m,
    their use could result in dangling references to the const_struct_db
    in those files.

compiler/mercury_compile_front_end.m:
    Ask for the new optimization to be done during the after-front-end
    invocation of simplification, if the option settings allow it.

compiler/simplify_proc.m:
    Fit the new optimization into the logic that decides whether
    we need two passes through the procedure body, or just one.

    Factor out some common code.

compiler/simplify_goal.m:
compiler/simplify_goal_unify.m:
    Delete code whose job has been moved to common.m.

compiler/simplify_info.m:
    Delete some no-longer-needed test predicates.

    Conform to the changes above.

compiler/simplify_goal_call.m:
    Add an XXX about code that relies on common_info even in situations
    in which it may not have been set up.

compiler/deforest.m:
compiler/mercury_compile_llds_back_end.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/polymorphism_type_info.m:
compiler/simplify_goal_scope.m:
compiler/size_prof.m:
compiler/stack_opt.m:
compiler/structure_sharing.analysis.m:
    Conform to the changes above.
2021-06-01 12:31:28 +10:00
Peter Wang
e2b5ba8884 Make subtypes share high-level data representation with base type.
In the high-level data representation, make a subtype term be
represented using the class corresponding to the base type constructor
instead of its own class. This is necessary to be able to downcast
a term from a type to a subtype in Java and C#.

compiler/du_type_layout.m:
    Move get_base_type_ctor predicate to type_util.m.

    Abort in a couple of places that should not occur.

compiler/type_util.m:
    Add get_base_type_ctor predicate.

compiler/globals.m:
    Add compilation_target_high_level_data predicate.

compiler/lco.m:
    Use compilation_target_high_level_data predicate.

compiler/ml_type_gen.m:
    When using the high-level data representation,
    don't generate a MLDS type definition (class) for a subtype.

compiler/mlds.m:
    When using the high-level data representation,
    replace a Mercury subtype with its base type in an mlds_type.

    Move foreign_type_to_mlds_type.

compiler/ml_unify_gen_util.m:
    To access a field when using the high-level data representation,
    use field names from the base type constructor of a subtype.

compiler/unify_proc.m:
    When using the high-level data representation,
    generate unify/compare procs for subtypes that just call the
    unify/compare proc for the base type constructor.

compiler/options.m:
    Delete references to --high-level and --high-level-data.

---------------

runtime/mercury_type_info.h:
    Document a new field MR_type_ctor_base in MR_TypeCtorInfo_Struct.
    The field is unnecessary and does not exist in the
    MR_TypeCtorInfo_Struct for C.

runtime/mercury_dotnet.cs.in:
    Add type_ctor_base member to MR_TypeCtorInfo_Struct for C#.

java/runtime/TypeCtorInfo_Struct.java
    Add type_ctor_base member to MR_TypeCtorInfo_Struct for Java.

compiler/rtti.m:
compiler/type_ctor_info.m:
    Add field corresponding to MR_type_ctor_base in type_ctor_details
    for enum, notag and general du types.

compiler/rtti_to_mlds.m:
    Initialize the MR_type_ctor_base field in type_ctor_infos
    for high-level data grades.

compiler/rtti_out.m:
    Don't write out the MR_type_ctor_base field when using
    the low-level data representation.

library/rtti_implementation.m:
    In Java and C# grades (high-level data grades), use the
    MR_type_ctor_base field to get the type_ctor_info of the base type
    ctor when constructing or deconstructing terms of a subtype.
    It is necessary to perform reflection using class and field names
    from the base type constructor since there are no classes
    corresponding to subtypes.

    Clean up some code.

---------------

tests/hard_coded/Mmakefile:
tests/hard_coded/subtype_abstract.m:
tests/hard_coded/subtype_abstract_2.m:
tests/hard_coded/subtype_abstract.exp:
    Add a test case.

tests/hard_coded/subtype_rtti.m:
tests/hard_coded/subtype_rtti.exp2:
    Enable a test that was previously skipped in Java and C# grades.
2021-04-09 17:41:23 +10:00
Zoltan Somogyi
1dd10f7170 Make pred declaration and definition order match. 2021-03-25 06:22:03 +11:00
Zoltan Somogyi
cdad329d15 Apply default func mode only to functions.
compiler/modecheck_call.m:
    This fixes a bug in my fix for Mantis bug #529.

compiler/options.m:
    Allow configure to test whether the bug is fixed, so we can delete
    any now-redundant explicit higher order insts in mode declarations.
2021-02-25 03:44:42 +11:00
Zoltan Somogyi
03d6c5f436 Get higher insts from types as well as modes.
compiler/modecheck_call.m:
    As above. This fixes Mantis bug #529.

compiler/options.m:
    Allow configure to test whether the bug is fixed, so we can delete
    any now-redundant explicit higher order insts in mode declarations.

tests/hard_coded/exist_cons_ho_arg.{m,exp}:
    A test case for the bug. This is a strengthened version of the
    Mantis test case.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2021-02-24 19:57:37 +11:00
Zoltan Somogyi
a93fbc92f6 Recognize partial_inst_copy as no_type_info_builtin.
mdbcomp/program_representation.m:
    As above.

compiler/options.m:
    Make it possible to detect whether the installed compiler
    contains the above change.
2021-01-05 01:37:04 +11:00
Zoltan Somogyi
9285072439 Add a way to test for partial_inst_copy. 2020-12-30 23:21:07 +11:00
Zoltan Somogyi
5a71bfb9b8 Set up for five streams for compiler output.
compiler/globals.m:
    Set up a system that should eventually allow us to output most or all
    compiler output to five streams, which can be individually directed
    to module-specific files by users if needed.

compiler/options.m:
    Add the five options that give users this control.

doc/user_guide.text:
    Document the (user-visible) new options.

compiler/mercury_compile_main.m:
    Close any module-specific output streams that we opened.

compiler/polymorphism.m:
    A first use of this system.
2020-11-20 18:53:39 +11:00
Zoltan Somogyi
185e4c4e96 Delete all stale code for Erlang from the compiler.
compiler/Mercury.options:
    Delete a workaround we needed only for Erlang.

compiler/add_mutable_aux_preds.m:
    Delete the implementation of mutables for Erlang.

compiler/builtin_ops.m:
    Document the fact that the Erlang backend was the only user of
    two operations.

compiler/compile_target_code.m:
compiler/module_cmds.m:
    Delete the predicates that handled the compilation of Erlang code.

compiler/file_names.m:
    Delete code dealing with file names used only by the Erlang backend.

compiler/options.m:
    Delete the old internal-only order_constructors_for_erlang option.

    Add an XXX about another option intended for Erlang being unused.

    Leave the other erlang-related options alive for now, to avoid breaking
    Mmakefiles, Mercury.options files etc that may still refer to them.

    Delete references to Erlang in help and/or error messages.

compiler/handle_options.m:
    Don't both updating options that were used only by the Erlang backend,
    and which are now unused.

    Delete references to Erlang in help and/or error messages.

compiler/unify_proc.m:
    Delete the code handling the Erlang-specific option deleted from options.m.

compiler/check_libgrades.m:
compiler/delay_partial_inst.m:
compiler/llds_out_data.m:
compiler/make_hlds_passes.m:
compiler/mlds_to_c_data.m:
compiler/prog_item.m:
compiler/simplify_goal_call.m:
compiler/write_deps_file.m:
    Either delete comments referring to Erlang or the Erlang backend,
    or, where their existence was the motivation for some design decisions,
    shift the comments to the past tense.

tests/mmc_make/Mmakefile:
    Delete a reference to a recently deleted .hrl file.
2020-10-29 23:29:36 +11:00