Commit Graph

9709 Commits

Author SHA1 Message Date
Zoltan Somogyi
79d6142bc3 Simplify more code in mercury_compile_main.m.
compiler/mercury_compile_main.m:
    Simplify the code interpreting the result of calls to lookup_mmc_options.

    Eliminate the one remaining redundant computation of the
    default option table.

compiler/options_file.m:
    Expand the documentation of the predicates that read options files.

    Document that the predicates that only look things up in the data
    structures representing already-read-in options files can return
    only errors, not warnings.

    Delete a long-obsolete comment.

compiler/maybe_error.m:
    Add a utility predicate that could be useful later. (I thought it
    would be useful in this diff, but it wasn't.)
2023-07-11 00:56:38 +02:00
Zoltan Somogyi
b1c0b42a34 Generate the default option_table just once.
compiler/handle_options.m:
    The main predicate of this module, handle_given_options, used
    to generate the default option table every time it was called,
    and its callers couldn't prevent this by supplying it with that
    default option table. Fix this by adding an argument for that info.

compiler/mercury_compile_main.m:
    Create the default option table at the start of real_main_after_expansion.
    Pass it to later invocations of handle_given_options.

compiler/globals.m:
    Include the default option table, as well as the processed option table
    (created by handle_given_options from the default table) in the globals
    structure. This is so that the parts of the make package that want to
    build a new globals structure "from scratch" don't have to redo
    the part of the work that is independent of the set of actually specified
    options.

compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
    Conform to the changes above.

    In some cases, fix misleading variable names.

    In make.track_flags.m, add an XXX outlining a possibly better approach
    to hashing options for tracking.

library/Mmakefile:
    Stop copying a part of getopt_io.m to geteopt.m, because it is
    confusing as hell after an automatic edit.

library/getopt.m:
    Expect the effect of the change to library/Mmakefile.
2023-07-10 19:40:56 +02:00
Zoltan Somogyi
786fc9d773 Improve variable names. 2023-07-10 13:46:55 +02:00
Zoltan Somogyi
fe1e78e126 Simplify some code.
compiler/mercury_compile_main.m:
    Simplify the interface of two predicates by moving to their (only) callers
    code that belongs better in those callers.

    Inline the only call to a predicate.

compiler/handle_options.m:
    Delete the predicate inlined in mercury_compile_main.m
2023-07-10 13:43:18 +02:00
Zoltan Somogyi
8b70437f3a Clarify that length means #code points. 2023-07-10 10:19:40 +02:00
Zoltan Somogyi
713f100508 Use string builder in the rest of parse_tree_out*.m.
compiler/parse_tree_out_pragma.m:
compiler/parse_tree_out_pred_decl.m:
    Use the string builder instance of pt_output instead of the plain string
    instance, due to its better worst case behavior.

    Add format_X versions of some operations that did not have them.

    Implement write_X and format_X in terms of X_to_string where X_to_string
    is trivial, and (mostly) returns existing strings.

    Delete the maybe with_type argument from some predicates, because
    they were always set to "no".

compiler/parse_tree_out_info.m:
    Delete the plain string instance of pt_output, since it is no longer
    needed.

compiler/hlds_out_mode.m:
compiler/hlds_out_pred.m:
    Conform to the changes above.
2023-07-09 21:44:44 +02:00
Zoltan Somogyi
c414a99736 Make a test more efficient.
library/string.builder.m:
    Add a predicate that tests whether the total length of the string
    implicit in a string builder is within a limit, or not.

    Add a function that returns that total length.

NEWS.md:
    Announce the new predicate and function.

compiler/parse_tree_out_term.m:
    Use the new predicate to optimize a test.
2023-07-09 17:46:43 +02:00
Zoltan Somogyi
8e7c5dfbd1 Use string builder in more of parse_tree_out*.m.
compiler/parse_tree_out_sym_name.m:
    Use the string builder instance of pt_output instead of the plain string
    instance, due to its better worst case behavior.

    Rename sym_name_arity_to_string to unescaped_sym_name_arity_to_string,
    to make it clear that it does not escape the sym_names it is given.
    Rename write_sym_name_arity in the same way.

    Add format_X versions of some operations that did not have them.

    Delete the write_quoted_sym_name predicate, because it was used only
    once, so it is not worth generalizing.

    Delete the escaped_module_name_to_string function, because it was
    unused.

compiler/parse_tree_out.m:
compiler/parse_tree_out_cons_id.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_out_misc.m:
compiler/parse_tree_out_sym_name.m:
compiler/parse_tree_out_term.m:
compiler/parse_tree_out_type.m:
    Use the string builder instance of pt_output instead of the plain string
    instance, due to its better worst case behavior.

    Add format_X versions of some operations that did not have them.

    Implement write_X and format_X in terms of X_to_string where X_to_string
    is trivial, and (mostly) returns existing strings.

compiler/add_clause.m:
compiler/add_type.m:
compiler/analysis.file.m:
compiler/complexity.m:
    Conform to the changes above.
2023-07-09 16:47:48 +02:00
Zoltan Somogyi
3a928fe1ea Start using the string builder in parse_tree_out*.m
compiler/parse_tree_out_sym_name.m:
    As a test, implement the output of sym_names, one of the smallest
    nonatomic parse tree components, using string builders.

    Change the name of the write_X version of the operation
    from just write_sym_name to write_escaped_sym_name,
    since every component of the sym_name is in fact escaped.

    Change the name of the X_to_string version of the operation
    from sym_name_to_escaped_string to escaped_sym_name_to_string,
    to make the X identical to the write_X version. Change its implementation
    to use string builders.

    Implement both write_escaped_sym_name and escaped_sym_name_to_string
    in terms of the new predicate format_escaped_sym_name.

    Add an XXX about a potential problem.

compiler/parse_tree_out_info.m:
    Since format_escaped_sym_name calls term_io.format_escaped_string,
    it needs to comply with its typeclass constraint. This requires
    making the typeclass in the constraint on format_escaped_sym_name,
    the "output" typeclass in parse_tree_out_info.m, a superclass of
    stream.writer.

    However, giving parse_tree_out_info.m access to the stream.writer class
    also gives it access to the stream.output class, since they are both
    defined in library/stream.m. Avoiding a flood of ambiguity warnings
    about output being either stream.output or parse_tree_out_info.output
    requires either fully module qualifying all occurrences of the output
    typeclass name, or renaming one of the typeclasses. The obvious one
    to rename is parse_tree_out_info.output, so this diff renames it to
    pt_output (pt being short for "parse tree").

compiler/higher_order.m:
compiler/hlds_out_mode.m:
compiler/hlds_out_module.m:
compiler/hlds_out_type_table.m:
compiler/hlds_out_util.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/parse_tree_out.m:
compiler/parse_tree_out_cons_id.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_out_misc.m:
compiler/parse_tree_out_pragma.m:
compiler/parse_tree_out_pred_decl.m:
compiler/parse_tree_out_term.m:
compiler/parse_tree_out_type.m:
compiler/recompilation.check.m:
compiler/source_file_map.m:
compiler/write_deps_file.m:
    Conform to the changes above.
2023-07-08 14:42:26 +02:00
Zoltan Somogyi
8bc9a8310f Put predicates into a standard order. 2023-07-08 11:36:52 +02:00
Zoltan Somogyi
bb695f455c Use term_io.m's stream writer predicates. 2023-07-08 02:38:40 +02:00
Zoltan Somogyi
78258146b2 Put related predicates next to each other. 2023-07-08 01:42:19 +02:00
Zoltan Somogyi
c09df50f64 Allow use of string builders in parse_tree_out_*.m ...
compiler/parse_tree_out_info.m:
    ... by making string builders instances of the "output" typeclass,
    whose operations are the base level of the code of parse_tree_out*.m.

    Strings were already instances of "output", but the use of this instance
    was problematic for large structures such as entire files. This is because
    if the final string was constructed by adding together N atomic strings,
    then the construction of the final string involves copying each of those
    atomic strings about N/2 times on average.

    With the string builder instance, each string is copied just twice:
    when it is added to the string builder state, and when that state is
    converted to the final string.

library/string.builder.m:
    Add three new predicates, append_char, append_string and append_strings.
    The first two are copied from existing instance methods; making them
    separate predicates allows them to be invoked using a first order call,
    instead of a method call. The third is just for convenience. All three
    are used by the new code in parse_tree_out_info.m.

NEWS.md:
    Announce the new predicates in string.builder.m.
2023-07-08 01:05:29 +02:00
Zoltan Somogyi
d944f70d61 Simplify some code. 2023-07-07 23:23:35 +02:00
Zoltan Somogyi
6eed4f7c72 Write out whole lines at a time in a C struct. 2023-07-07 23:23:01 +02:00
Julien Fischer
404c57907f Avoid a clash with a system header.
compiler/md5.m:
    Add a distinguishing prefix to a macro, which otherwise
    clashes with a system header on mingw-w64-ucrt-x86_64.
2023-07-07 23:37:33 +10:00
Zoltan Somogyi
497f8b07ad Fix typos and not-quite-right comments. 2023-07-07 11:19:38 +02:00
Zoltan Somogyi
d5c54ce697 Take ext_src out of the ext type.
compiler/file_names.m:
    Take ext_src out of the ext type, because this allows us to delete
    the I/O state pair of arguments out of every file translation predicate
    other than module_name_to_source_file_name and the ones that create
    directories.

compiler/file_kind.m:
    Delete the ext output argument of file_kind_to_extension, because
    we can't return ext_src for fk_src anymore.

compiler/write_deps_file.m:
    Delete a test for ext_src which could never succeed, because the
    predicate in question is never called with ext_src.

    Undo an accidental change from the diff that introduced
    module_name_to_lib_file_name_create_dirs.

    Conform to the changes above.

compiler/compile_target_code.m:
compiler/fact_table.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mlds_to_c_file.m:
compiler/mmc_analysis.m:
compiler/module_cmds.m:
compiler/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.
2023-07-06 16:14:35 +02:00
Zoltan Somogyi
ef89c81527 Move two predicates. 2023-07-06 12:37:35 +02:00
Zoltan Somogyi
89979d681a Replace Mkdir parameters with predicate versions.
compiler/file_names.m:
    Split module_name_to_file_name into three versions.

    - One corresponds to the old predicate's operation with do_not_create_dirs,
    - one corresponds to the old predicate's operation with do_create_dirs, and
    - one just returns the directory path, and lets the caller make those
      directories if it wants to, using procedures that we now export.

    Do the same for module_name_to_lib_file_name.

    Do not do the same for fact_table_file_name, which has too few callers
    to make it worthwhile.

    The point is that the versions that do not create any dirs should NOT
    need to take I/O state pairs as arguments, once we take ext_src
    out of the ext type.

compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/fact_table.m:
compiler/generate_dep_d_files.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/make.util.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Update calls to the affected predicates.

    In some places, add XXXs about seemingly-strange choices about
    what calls create directories and which don't.
2023-07-06 12:36:14 +02:00
Zoltan Somogyi
c72b3a8f97 Reorder the contents of file_names.m.
now that the new code has replaced the old, move it to the prime position.
2023-07-06 02:36:31 +02:00
Zoltan Somogyi
7f6bb059a0 Update comments in file_names.m.
compiler/file_names.m:
    Delete now-obsolete comments. Move their still-relevant parts
    next to the entity that they apply to.

    List the string form, if any, of each enum representing an extension.

    Explain the meaning of _gs, _ngs and _opt suffixes.

    Delete obsolete commented-out code.

    Delete an obsolete, unused type definition.

compiler/options.m:
doc/user_guide.texi:
    Fix two bugs that a comment that this diff pointed to.

    First, since 2017, the --dump-hlds option has output C code
    only if the target language is C, but the documentation
    of that option did not mention this. Fix this omission.

    Second, ever since we split .mh and .mih files, the header
    part of MLDS dumps in C form were output to .mih_dump file.
    However, the documentation of the --dump-hlds  option said that
    it was output to a .h_dump file. Fix this as well.
2023-07-06 02:29:03 +02:00
Zoltan Somogyi
6e795080ed Delete an unused argument. 2023-07-06 00:44:57 +02:00
Zoltan Somogyi
bd51efccea Address a review comment. 2023-07-05 13:26:20 +02:00
Zoltan Somogyi
6517982c87 s/newext/ext/g and s/NewExt/Ext/g. 2023-07-04 22:32:38 +02:00
Zoltan Somogyi
0b60f07c46 Cut over to the new code in file_names.m.
compiler/file_names.m:
    Delete the old code for doing filename translations, and use
    just the new code.

    Delete all the code that was needed only for comparing the old and
    new code.

    Delete the newext_other extension category, since it was also needed
    only for that purpose. Delete all the code that supported it.

    Switch the infrastructure for recording the demand for translations
    to work with the new code.

compiler/analysis.file.m:
    Delete functions that returned old-style extensions, which are
    not useful anymore. The new-style extensions, by identifying
    extensions via enums rather than strings, serve the purpose
    for which these functions were created.

compiler/mercury_compile_main.m:
    Move the code to call to write out the translation record
    from just after a call to real_main_after_expansion to the
    end of real_main_after_expansion. The reason is that the
    predicate being called now needs access to a globals structure,
    real_main_after_expansion has access to a globals structure,
    but its caller does not.

    Don't try to test the equivalence of the old and new algorithms
    for file name translation, since that test code has been deleted.

compiler/analysis.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/make.util.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/prog_foreign.m:
compiler/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the changes in file_names.m.
2023-07-04 18:22:42 +02:00
Zoltan Somogyi
3d756f61cd Put varsets before vars in write_variable.
library/term_io.m:
    Put the varset before the variable, the item to be written out,
    in the various versions of the write_variable operation.
    The new argument order

    - fits in better with the versions of write_term, which also put
      the varset before the item to be written out, and

    - allows the convenient use of fold operations that write out
      several variables.

NEWS.md:
    Announce the change, though only for the versions that existed
    before yesterday :-)

compiler/inst_graph.m:
extras/moose/mercury_syntax.m:
    Conform to the change.
2023-07-04 16:35:01 +02:00
Zoltan Somogyi
685eefa206 Move base of term_io.m to X_to_string, write_X, format_X.
library/term_io.m:
    Move the base operations of term_io.m to the structure we use
    in parse_tree_out*.m in the compiler, where for every type X,
    there is a function X_to_string, and two predicates write_X and format_X,
    with the former operating on I/O states, and the latter operating on
    arbitrary streams. The idea is to apply the "don't repeat yourself"
    principle by having both X_to_string and write_X just call format_X.

    Apply that principle here as well, with one minor exception,
    which is that for some values of X, both write_X and format_X are
    implemented in terms of X_to_string.

    Impose the X_to_string, write_X, format_X naming scheme. The ancient code
    already in term_io.m had (each for some values of X) had

    - some of these functions/predicates missing
    - inconsistent names, in that write_X/N did I/O while write_X/(N+1)
      wrote to arbitrary streams
    - names that were inconsistent in another way, in that write_X/N did
      I/O of values of type X, but the function to convert X to string
      was NOT named X_to_string.

    Keep some of the misnamed functions around permanently, because
    some of the names for fitting into the new scheme, such as
    "escaped_string_to_string", would be strange.

    Keep the rest of the misnamed functions and all the misnamed predicates
    around temporarily, with commented-out obsolete pragmas. I expect
    to make these pragmas active when the rest of term_io.m is converted
    to this scheme.

    To prepare for that, use string.builder, not string, as the
    stream.writer instance to implement X_to_string, because of its
    better algorithmic complexity, which is needed mainly for terms
    of nontrivial size.

    Consistently put operations on each X in the order X_to_string,
    write_X and format_X.

NEWS.md:
    List all the new predicates and functions.

configure.ac:
    Require the installed compiler to contain the fix which allows
    a typespec pragma for an obsolete predicate or function.

browser/interactive_query.m:
compiler/hlds_out_util.m:
compiler/parse_tree_out_clause.m:
compiler/parse_tree_out_cons_id.m:
compiler/parse_tree_out_info.m:
compiler/parse_tree_out_pragma.m:
compiler/parse_tree_out_sym_name.m:
compiler/parse_tree_out_type_repn.m:
library/pretty_printer.m:
library/stream.string_writer.m:
library/string.builder.m:
mdbcomp/trace_counts.m:
    Update all references to the newly-obsolete predicates and functions.

library/string.to_string.m:
    Improve variable names.
2023-07-04 00:00:09 +02:00
Zoltan Somogyi
cae40f0300 Fix typos. 2023-07-04 00:00:09 +02:00
Zoltan Somogyi
b6ec42a132 Make some arities into pred_form_arities.
compiler/hlds_pred.m:
    Replace the arity field in pred_infos with a pred_form_arity field.

    Move the pred_info's pred_or_func field to its usual position
    in predicate/function descriptions: at the front (pred/func name/arity).

compiler/hlds_pred.m:
    Change two utility operations to return pred_form_arities instead of
    just arities, since they get them from pred_infos.

compiler/inst_mode_type_prop.m:
compiler/llds.m:
compiler/rtti.m:
    Change some fields whose types used to be arity (or int) to be
    pred_form_arity.

    In llds.m, include a pred_or_func field in c_procedures,
    for use in procedure-start comments.

mdbcomp/prim_data.m:
mdbcomp/program_representation.m:
    Add notes about two possible future improvements along similar lines.

compiler/prog_data.m:
    Add a utility function to calculate the number of extra arguments
    added to predicates/functions by compiler passes such as polymorphism.

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

    Fix a bug in an error message about ":- external" pragmas:
    the message used the pred_form arity instead of the user arity.
    (See the diff to external2.err_exp below.)

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

    Include pred/func prefixes before name/arity pairs in the output
    where relavnt. (The user guide does not need to be updated, because
    its wording permits both the old and the new behavior.)

    Fix two separate bugs that referred to functions in user-facing output
    with the predicate form of their arity.

compiler/table_gen.m:
compiler/unused_args.m:
    Conform to the changes above.

    Fix a bug in each module that referred to functions in user-facing output
    with the predicate form of their arity.

compiler/recompilation.usage.m:
compiler/xml_documentation.m:
    Conform to the changes above.

    Mark a probable bug in each module with an XXX.

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

    Improve the wording of an error message a bit.
    (See the diff to gh72_errors.err_exp below.)

compiler/accumulator.m:
compiler/bytecode_gen.m:
compiler/complexity.m:
compiler/default_func_mode.m:
compiler/det_report.m:
compiler/distance_granularity.m:
compiler/equiv_type_hlds.m:
compiler/exception_analysis.m:
compiler/higher_order.m:
compiler/hlds_defns.m:
compiler/hlds_error_util.m:
compiler/hlds_module.m:
compiler/intermod.m:
compiler/intermod_order_pred_info.m:
compiler/introduce_exists_casts.m:
compiler/introduce_parallelism.m:
compiler/llds_out_file.m:
compiler/mercury_compile_llds_back_end.m:
compiler/ml_accurate_gc.m:
compiler/ml_args_util.m:
compiler/mode_errors.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/old_type_constraints.m:
compiler/optimize.m:
compiler/polymorphism.m:
compiler/polymorphism_goal.m:
compiler/post_typecheck.m:
compiler/pre_typecheck.m:
compiler/pred_table.m:
compiler/proc_gen.m:
compiler/rbmm.region_transformation.m:
compiler/recompilation.usage.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/simplify_goal_call.m:
compiler/ssdebug.m:
compiler/table_gen.m:
compiler/tabling_analysis.m:
compiler/term_constr_initial.m:
compiler/termination.m:
compiler/trailing_analysis.m:
compiler/transform_llds.m:
compiler/tupling.m:
compiler/type_class_info.m:
compiler/typecheck.m:
compiler/typecheck_error_undef.m:
compiler/types_into_modes.m:
compiler/xml_documentation.m:
    Conform to the changes above.

compiler/recompilation.m:
    Add a note.

compiler/parse_tree_out_sym_name.m:
    Improve variable names.

tests/invalid/external2.err_exp:
    Expect the fixed arity in an error message.

tests/invalid/gh72_errors.err_exp:
    Expect the expanded text of an error message.
2023-07-03 01:57:10 +02:00
Zoltan Somogyi
29b120dd3d Don't generate warnings for transformed predicates.
compiler/simplify_goal_call.m:
    Don't generate "reference to obsolete predicate" warnings in predicates
    that are created by the compiler, not the user, by transforming another
    predicate. Any such warning should properly be emitted for the *base*
    predicate of the transformation.

    We have traditionally not generated "reference to obsolete predicate"
    warnings in predicates that are themselves marked obsolete. This is
    to allow a cluster of predicates in some members are implemented
    using calls to other members to be obsoleted together.

    Without this diff, a type_spec pragma for a predicate p1 that is
    marked obsolete that calls another obsolete predicate p2 would get
    a warning for the call, because the context of the pragma is used
    as the context of the compiler-generated type-specialized version of p1,
    and this version is NOT itself marked obsolete. (It *cannot* be marked
    obsolete, because even if the programmer knew the eventual
    compiler-generated name of the type specialized predicate and
    added a obsolete pragma for it, that predicate does not yet exist
    when its pragma would be processed.)

    We *could* copy the obsolete marker from base to transformed predicates,
    but the blanked rule given at the top is a more robust solution.

compiler/options.m:
    Add a new name for the compiler_sufficiently_recent option
    that can be used to detect the presence of thid diff in the
    installed compiler.
2023-07-03 01:13:09 +02:00
Julien Fischer
dd85e44fd6 Adjust a comment.
compiler/Mmakefile:
    Document where we currently set the stack size for MSVC.
2023-07-02 15:59:00 +10:00
Zoltan Somogyi
fcad1b21e8 Delete module_names_contexts fields from parse trees.
compiler/prog_item.m:
    We used to include information about include_module, import_module
    and use_module declarations in a module in the parse_tree_module_src
    in two forms: an unchecked form, which had type module_names_contexts,
    and a checked form, which had types include_module_map and
    import_and_or_use_map respectively. We have been gradually switching
    more and more code working on parse trees from taking the unchecked form
    as input to taking the checked form as input.

    This diff completes the process.

    - It deletes the ptms_{int,imp}_includes and ptms_{int,imp}{imports,uses}
      fields from parse_tree_module_src. Their checked versions remain.

    - It changes the parse_tree_int3 type to store include and import
      information using checked rather than unchecked types. The reason
      why this wasn't done before is that the checked data structures
      could not preserve the relevant invariants until subtypes were added
      to the language. This diff thus also defines the needed new subtype.

    Fix a typo (wrong int file number) in a field name.

compiler/item_util.m:
    Add some utility predicates needed by new code in the modules below.

    Change the interface of a utility predicate

    - to stop requiring the caller to supply unchecked data structures,
      constructing them internally as intermediate data structures instead,
      and
    - to stop returning some now-unneeded unchecked data structures.

    Keep some utility predicates private that are no longer needed
    outside this module.

    Delete a whole bunch of utility predicates which are no longer needed
    at all.

compiler/comp_unit_interface.m:
compiler/convert_parse_tree.m:
    Conform to the changes in prog_item.m, by changing code that used
    to construct unchecked to now construct checked data structures.

compiler/check_module_interface.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out.m:
compiler/write_deps_file.m:
    Conform to the changes in prog_item.m, mostly by changing code that
    used to take unchecked data structures as input to now take checked
    data structures as input.

compiler/deps_map.m:
compiler/module_baggage.m:
compiler/module_dep_info.m:
    Delete now-unneeded imports.
2023-07-01 15:03:18 +02:00
Julien Fischer
8f793b5500 Fix some HTML.
compiler/notes/developer_intro.html:
    Replace '>' with the appopriate entity reference.
2023-07-01 03:08:36 +10:00
Julien Fischer
d0b64c87c7 Ignore files generated by MSVC.
*/.gitignore:
   Ignore any increment linker files (.ilk) and program database (.pdb)
   file that MSVC generates.
2023-07-01 02:25:53 +10:00
Zoltan Somogyi
e73358975c Add a reminder about eqv types in instance method clauses. 2023-06-30 13:21:25 +02:00
Zoltan Somogyi
7292ecb571 Don't generate duplicate instance declarations.
We used to include in the .int0 file the abstract form of all the instance
declarations in both the interface and the implementation sections.
When an instance is declared (in an already-abstract form) in the interface
section and defined in the implementation section, this resulted in the
abstract interface declaration being included in the .int0 file twice,
once in the interface section, and once in the implementation section.

compiler/comp_unit_interface.m:
    Fix this by including an abstract instance declaration in the
    implementation section of a .int0 file only if it does not also appear
    in the interface section.

    Conform to the changes in prog_item.m below.

compiler/parse_tree_out.m:
    To help implement the above test, add a function to return the string
    form of an abstract instance declaration.

    It is easy to make this change for *abstract* instance declarations,
    but not *concrete* instance definitions, because (in order to handle
    instances that define methods by clauses, instead of by pred/func names)
    the latter would require generalizing *all* the code for writing out
    clauses, with all the overhead associated with replacing first order calls
    with method calls.

    Another change (unrelated to the problem above) is to write out
    typeclass and instance definitions for typeclasses with no methods
    in a nicer form. Instead of looking like this:

        :- instance classname(argtypes) where [

        ].

    they now look like this:

        :- instance classname(argtypes) where [].

    Another formatting change unrelated to the above: don't put parentheses
    around typeclass names in instance declarations/definitions if the name
    is all alphanumeric and not an operator.

    Conform to the changes in prog_item.m below.

compiler/prog_data.m:
compiler/prog_item.m:
    To be able to use the new code to convert abstract instances to strings
    in comp_unit_interface, and to write out abstract instance declarations
    inside .int0 (and other .intN) files, it helps to know which instance
    items can only be abstract in these files. As it turns out, none can be
    concrete. So define a subtype of item_instance_info that can contain
    only abstract instance declarations, and use it to replace
    item_instance_info in parse_tree_intN for all N.

compiler/parse_tree_out_info.m:
    Add a utility function for new code in comp_unit_interface.m
    invoking new code in parse_tree_out.m.

compiler/convert_parse_tree.m:
    Conform to the changes in prog_item.m by insisting that instances
    read in from .intN files are all abstract.

    Fix some typos in some error messages (which people can see only if
    something has screwed up a .intN file).

compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/recompilation.version.m:
    Conform to the changes above.

compiler/intermod.m:
    Simplify some code.

tests/invalid/Mercury.options:
    Fix the failure of the instances_pc.instances_pc_helper_1 test case
    when intermodule optimization is enabled for a bootcheck by disabling
    intermodule optimization for this test. The old code to do so didn't
    work due to typos.

tests/invalid/instances_pc.instances_pc_helper_1.err_exp:
    Expect a reference to only ONE old instance declaration in
    instances_pc.int0. Expect it at a new line number, due to the first
    formatting change above.

tests/misc_tests/pretty_print_test.exp:
    Expect no unnecessary parentheses around a class name in an
    instance definition, due to the second formatting change.
2023-06-30 09:34:01 +02:00
Peter Wang
2e5c8a4fd7 Advise to create annotated tags.
compiler/notes/upgrade_boehm_gc.html:
    As above.
2023-06-29 11:10:23 +10:00
Zoltan Somogyi
68d47c9e95 Delete an unneeded call, stop reversing a list, ...
... and make a predicate name more descriptive.
2023-06-28 17:03:50 +02:00
Zoltan Somogyi
9eb003458b Add verbose_make_N_part_msg predicates.
compiler/make.util.m:
    Add verbose_make_N_part_msg predicates, and the more general
    option_set_make_N_part_msg predicates, to allow simpler code
    to construct progress and informational messages.

    Pass to debug_make_msg a message *generator*, instead of a predicate
    that *writes out* a message. Make debug_make_msg return the message
    (if debug_make is enabled) to be written out (hopefully) to an explicitly
    specified stream.

compiler/make.dependencies.m:
    Rename the dependency_status predicate to get_dependency_status.
    Make it return the original dependency_file, and the filename it
    corresponds to, alongside the status, because this is the simplest
    way to avoid requiring its callers to reconstruct that information
    after their calls to get_dependency_status.

    Change the signature of check_dependency_timestamps to expect
    the new output of get_dependency_status.

    Replace code to write out debugging messages with code to just return
    them as a string. Move one of these predicates to just after its caller.

    Give some predicates more descriptive names.

compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Conform to the changes above.

    In make.program_target.m, add XXXs about progress messages
    that end with a period, unlike all the other progress messages.
2023-06-28 15:13:43 +02:00
Julien Fischer
ae4d3db0d0 Document how to modify our local Boehm GC customisations.
compiler/notes/upgrade_boehm_gc.html:
    As above.

    Add markup to distinguish file, branch, tag etc. names from
    surrounding text.

    Fix markup so this passes through htmlhint cleanly.
2023-06-28 19:49:30 +10:00
Zoltan Somogyi
dbcb4672d3 Create progress/error msgs separately from writing them.
compiler/make.util.m:
    The predicates that handled progress messages in this module

    - tested whether the progress message was needed, and if yes,
    - first constructed the message,
    - and then printed it.

    The predicates that handled error messages were similar,
    but error messages are always needed.

    In most cases, the printing was done to the current *implicit* output
    stream.

    Code calling these predicates won't get warnings about implicit stream
    calls unless every predicate has both implicit and explicit stream
    variants.

    Make all these predicates do just the first two of the above jobs,
    and return a string that may be empty or not. Then require callers
    to call one of four new predicates to print out the resulting string
    if it is not empty. The four are distinguished along two axes:
    implicit vs explicit stream, and locked/unlocked stdout.

    Add XXXs about the problems of even this updated approach,
    including the one with locking stdout when the output stream,
    whether implicitly or explicitly specified, is *not* stdout.

    Make the names of all the predicates affected by the above change
    end in "_msg". Change some of the names to be more descriptive.
    Delete one predicate whose code was identical to that of another.

compiler/make.build.m:
    Export the lock/unlock stdout predicates for use by the new predicates
    in make.util.m.

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

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

    Give a predicate a less misleading name.

    Add an XXX in a place.
2023-06-28 01:27:27 +02:00
Zoltan Somogyi
5aaa1f68fb Eliminate a redundant target->filename conversion.
The main purpose of this change is not extra efficiency, but uncovering
inconsistencies, and in fact, it found one. A secondary purpose is preparing
for the use of explicit streams in the make package.

compiler/make.util.m:
    Avoid such a conversion in the debug_file_msg predicate by requiring
    the caller to supply not a target file, but the result of the conversion.

    Create separate do_not_search and do_search versions of the
    module_TARGET_to_file_name predicate, to reduce the unnecessary
    differences between this predicate (now these predicates) and the
    corresponding code in file_names.m, i.e. module_NAME_to_file_name/
    module_NAME_to_search_file_name. The point of this is to make it easier
    to compare two predicates that may, or may not, do identical jobs
    using different code, as noted by the new XXX in make.module_target.m.

    Put do_not_search code before do_search alternatives, again following
    the pattern in file_names.m.

compiler/make.module_target.m:
    Update the calls to debug_file_msg.

    In one case, add an XXX for the fact that the filename corresponding
    to a target file is computed twice, in two different predicates, using
    two seemingly different algorithms.
2023-06-27 20:19:48 +02:00
Zoltan Somogyi
54948d0fd7 Make some pred/func names more descriptive.
compiler/make.util.m:
    As above.

compiler/compile_target_code.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
    Conform to the changes in make.util.m.
2023-06-27 17:07:28 +02:00
Julien Fischer
19d818209f Ignore *.obj files.
*/.gitignore:
    As above.

    Fix a few other omissions.
2023-06-26 20:05:24 +10:00
Julien Fischer
4b5c94c050 Work towards supporting 64-bit Windows with MSVC.
compiler/globals.m:
     Extend c_compiler_type to distinguish between versions of MSVC
     that target x86 and those that target x86_64 (x64).

compiler/handle_options.m:
     Update the list of valid C compiler types.

compiler/compile_target_code.m:
     Handle versions of MSVC that generate x86_64 code.

m4/mercury.m4:
    Distinguish between versions of MSVC that target x86 and those
    that target x86_64.

configure.ac:
    Generate the new values of --c-compiler-type for MSVC.

    Determine the CPU type to pass to boehm_gc/NT_MAKEFILE.
    (This will also require an update to boehm_gc/Mmakefile; this change does
    not do that.)

Mmake.common.in:
    Add a new variable for setting the CPU type for boehm_gc/NT_MAKEFILE.
2023-06-25 16:19:01 +10:00
Zoltan Somogyi
057c8e1553 Resolve a ZZZ. 2023-06-24 09:37:05 +02:00
Zoltan Somogyi
056fe37a5b Make make_info an abstract type.
This should allow profiling runs to collect information about the
number of accesses to each field.

compiler/make.make_info.m:
    Move the definition of the make_info type from the interface section
    to the implementation section. Add getter functions for all its fields,
    setter predicates for its writeable fields, and an initialization
    function.

    Move all the readonly fields to the start of the structure.
    Put related fields next to each other.

compiler/make.top_level.m:
    Replace the explicit construction of the initial make_info value
    with a call to its initialization function.

compiler/make.build.m:
compiler/make.dependencies.m:
compiler/make.deps_set.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/make.util.m:
    Replace all accesses to the fields of make_info with calls to the
    getter functions or the setter predicates.
2023-06-24 09:34:15 +02:00
Zoltan Somogyi
4f63a92085 Minor improvements in make.*.m.
compiler/make.dependencies.m:
    Delete a comment about deleting a field from the make_info, and passing
    its info via separate arguments. An experiment showed that it would
    complicate much more code than it would simplify.

compiler/make.make_info.m:
    Document why that field of the make_info should stay there.

    Fix some comment rot.

    Add some XXXs about unclear comments.

    Give a type a more meaningful name.

compiler/make.module_dep_file.m:
    Use that new type name.

compiler/make.deps_set.m:
    Improve a variable name.
2023-06-23 22:08:44 +02:00
Zoltan Somogyi
81b4c3272e Stop using digraph.tsort and digraph.atsort ...
... and start using their more descriptively-named synonyms.

In some cases, instead of getting and then reversing a list of sccs,
ask for the sccs in the needed order in the first place.

compiler/dependency_graph.m:
compiler/generate_dep_d_files.m:
compiler/make.program_target.m:
compiler/mlds_to_java_global.m:
compiler/mode_ordering.m:
compiler/rtti_to_mlds.m:
compiler/stratify.m:
    As above.

compiler/prog_event.m:
    As above.

    Address an old and now-inaccurate XXX. When a synthesized attribute
    depends on its value, either directly or through the values of other
    synthesized attributes, include the names of the attributes involved
    in the error message, instead of just saying that there is circular
    dependency *somewhere* among the attributes.

tests/invalid/synth_attr_error.err_exp:
    Expect the updated, more specific error messages.

tests/invalid/Mmakefile:
    Enable the synth_attr_error test case, which wasn't enabled before
    (though it does have an entry in Mercury.options.)

tests/invalid/invalid_event_spec:
tests/invalid/syntax_error_event_spec:
tests/invalid/synth_attr_error_spec:
    Replace tabs with spaces.
2023-06-22 00:25:26 +02:00