157 Commits

Author SHA1 Message Date
Zoltan Somogyi
3aca14b385 Compile the Mercury system with --warn-unused-types.
configure.ac:
    Require the installed compiler to support that option.

STANDARD_MCFLAGS:
    Specify that option.

compiler/canonicalize_interface.m:
compiler/comp_unit_interface.m:
compiler/inst_user.m:
compiler/parse_module.m:
compiler/switch_util.m:
compiler/type_ctor_info.m:
deep_profiler/mdprof_dump.m:
library/digraph.m:
slice/mcov.m:
    Delete unused equivalence types that were picked up by the option.
2026-03-09 03:07:51 +11:00
Zoltan Somogyi
d5ed3079de Carve type_inst_mode_map.m out of convert_parse_tree.m.
compiler/convert_parse_tree.m:
compiler/type_inst_mode_map.m:
    As above.

compiler/parse_tree.m:
compiler/notes/compiler_design.html:
    Add the new module to the parse_tree package, and document it.

compiler/comp_unit_interface.m:
compiler/recompilation.version.m:
    Conform to the changes above.
2025-11-18 09:28:14 +11:00
Zoltan Somogyi
44d1f0db9c Give some predicates shorter names.
compiler/prog_type_subst.m:
compiler/type_util.m:
    Apply s/apply_variable_renaming_to_/apply_renaming_to_/ and
    s/_to_x_list/_to_xs/ to the names of predicate.

    Conform to the change in hlds_class.m below.

compiler/hlds_class.m:
    This module used to define types named (a) hlds_constraint, and
    (b) hlds_constraints, and the latter was NOT a list of items
    of type hlds_constraint. Rename the latter to hlds_constraint_db
    to free up the name apply_renaming_to_constraints to apply
    to list(hlds_constraint). However, the rename also makes code
    operating on hlds_constraint_dbs easier to understand. Before
    this diff, several modules used variables named Constraints
    to refer to a list(hlds_constraint) in some places and to
    what is now a hlds_constraint_db in other places, which is confusing;
    the latter are now named ConstraintDb.

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

    Add an XXX about some existing variable names that *look* right
    but turn out to be subtly misleading.

compiler/add_pragma_type_spec.m:
compiler/add_type.m:
compiler/check_typeclass.m:
compiler/comp_unit_interface.m:
compiler/cse_detection.m:
compiler/ctgc.util.m:
compiler/decide_type_repn.m:
compiler/deforest.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/higher_order.higher_order_global_info.m:
compiler/higher_order.make_specialized_preds.m:
compiler/higher_order.specialize_calls.m:
compiler/hlds_rtti.m:
compiler/inlining.m:
compiler/modecheck_coerce.m:
compiler/old_type_constraints.m:
compiler/polymorphism_clause.m:
compiler/polymorphism_goal.m:
compiler/polymorphism_type_class_info.m:
compiler/prog_type_unify.m:
compiler/qual_info.m:
compiler/recompilation.version.m:
compiler/resolve_unify_functor.m:
compiler/typecheck.m:
compiler/typecheck_clauses.m:
compiler/typecheck_cons_infos.m:
compiler/typecheck_debug.m:
compiler/typecheck_error_type_assign.m:
compiler/typecheck_errors.m:
compiler/typecheck_unify_var_functor.m:
compiler/typecheck_util.m:
compiler/typeclasses.m:
compiler/unify_proc.m:
compiler/var_table.m:
compiler/vartypes.m:
    Conform to the changes above.
2025-10-21 18:21:35 +11:00
Zoltan Somogyi
0891ff754f Include modules named in supertypes in .int2 files.
This fixes a bug that prevented the compilation of another change
to the compiler I am working on. The commit of that change will ve
the test case for this fix.

compiler/comp_unit_interface.m:
    When computing which modules need to be imported in .int2 files,
    include modules named by the supertype of an exported subtype.

compiler/notes/interface_files.html:
    Fix some documentation errors I found while researching the bug.

compiler/options.m:
    Make it possible to test for the presence of this fix in the
    installed compiler.

tests/warnings/help_text.err_exp:
    Expect the new synonym for compiler_sufficiently_recent.
2025-07-07 19:29:55 +02:00
Zoltan Somogyi
3dd0f2e03b Act on all remaining warnings about unused state vars.
compiler/add_heap_ops.m:
compiler/check_import_accessibility.m:
compiler/comp_unit_interface.m:
compiler/convert_import_use.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/distance_granularity.m:
compiler/equiv_type.m:
compiler/generate_dep_d_files.m:
compiler/generate_mmakefile_fragments.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/higher_order.specialize_unify_compare.m:
compiler/jumpopt.m:
compiler/layout_out.m:
compiler/lco.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.get_module_dep_info.m:
compiler/make.library_install.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/make_hlds_passes.m:
compiler/make_module_file_names.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_disj_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_lookup_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_test.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_target_util.m:
compiler/module_cmds.m:
compiler/opt_deps_spec.m:
compiler/optimize.m:
compiler/parse_dcg_goal.m:
compiler/parse_goal.m:
compiler/parse_item.m:
compiler/parse_module.m:
compiler/parse_string_format.m:
compiler/proc_gen.m:
compiler/prop_mode_constraints.m:
compiler/rbmm.points_to_analysis.m:
compiler/rbmm.region_analysis.m:
compiler/rbmm.region_transformation.m:
compiler/simplify_goal_disj.m:
compiler/ssdebug.m:
compiler/stack_opt.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/term_constr_build.m:
compiler/trace_gen.m:
compiler/tupling.m:
compiler/untupling.m:
compiler/write_deps_file.m:
deep_profiler/autopar_calc_overlap.m:
deep_profiler/autopar_find_best_par.m:
deep_profiler/html_format.m:
deep_profiler/startup.m:
profiler/mercury_profile.m:
profiler/propagate.m:
    Act on the new warnings. In a few cases, conform to the changes
    resulting from acting on the warnings in other modules.

browser/Mercury.options:
compiler/Mercury.options:
library/Mercury.options:
mdbcomp/Mercury.options:
ssdb/Mercury.options:
    Specify options for disabling the new warnings for modules
    where we (probably) won't want them.

configure.ac:
    Require the installed compiler to understand the options that
    we now reference in the Mercury.options files above.

tests/debugger/tailrec1.exp:
    Expect variable names for the middle versions of state vars
    using the new naming scheme.

tests/invalid/Mercury.options:
    Fix references to obsolete test names.

tests/warnings/Mercury.options:
    Avoid a test failure with intermodule optimization.
2025-05-19 00:33:06 +10:00
Zoltan Somogyi
8e66e5c38b Auto-repair missing parent imports when making .int* files.
If the process of making .int0/.int/.int2 files has no errors other than
missing imports of parent modules (i.e. we import module a.b.c but not a.b),
we have for a while now reported this fact when making those files, which
required programmers to fix the error before they could compile other modules
that need those interface files. However, the fix is obvious: add the missing
imports, either as ":- import_module" or ":- use_module" declarations.

Given this fact, there is no point in interrupting the programmer's workflow:
the compiler can itself add the missing declaration to the interface file
it is generating. Reporting the missing parent imports later, when the module
is compiled to the target language, still guarantees that the programmer will
fix the error, but they can do so at a time of their choosing.

compiler/check_import_accessibility.m:
    Report missing parent imports as DelayedSpecs, separately from the Specs
    for other kinds of module accessibility errors, to make the above possible.

    Report separately the set of parent modules whose imports are missing
    from the interface and implementation sections.

    Delete an unused function symbol.

compiler/grab_modules.m:
    When making the aug_make_int_unit structure from which we generate
    .int0/.int/.int2 files, automatically add the missing parent imports
    returned by check_import_accessibility.m to it. Actually, add them
    as ":- use_module" declarations, since this is the less invasive
    alternative. (In the sense that they make the "missing parent import"
    error go away, but do not interfere with the detection of *other* kinds
    of errors.)

    Also, record DelayedSpecs in a new slot in the aug_make_int_unit.

compiler/prog_parse_tree.m:
    Add this new slot.

compiler/comp_unit_interface.m:
    When making .int0/.int/.int2 files, if there is a reason why
    we cannot make them, get the DelayedSpecs from the aug_make_int_unit
    and report them together with all other error_specs, since this will
    not cause any *added* interruptions to the programmer's workflow.
    But in the *absence* of any such reason, throw the DelayedSpecs away.

compiler/module_qual.qualify_items.m:
    Conform to the change in prog_parse_tree.m.

compiler/convert_import_use.m:
    Improve style.

tests/invalid_submodules/missing_parent_import.err_exp:
tests/invalid_submodules/missing_parent_import.m:
tests/invalid_submodules/missing_parent_import_helper_1.m:
tests/invalid_submodules/missing_parent_import_helper_2.m:
    Move this test case here from tests/invalid_make_int, since
    after this diff, the compiler no longer reports missing parent imports
    when making .int files. Make the test case a bit tougher, since this is
    now possible, and update the expected output file to account for the
    errors that we never look for when making .int files.

tests/invalid_make_int/Mmakefile:
tests/invalid_submodules/Mmakefile:
    Disable the moved test case in its original directory,
2025-05-12 21:26:51 +10:00
Zoltan Somogyi
8aaa0a958f Carve two new modules out of item_util.m.
compiler/convert_import_use.m:
    New module for converting to and from checked representations
    of import_module and use_module declarations.

compiler/convert_include.m:
    New module for converting to and from checked representations
    of include_module declarations.

compiler/item_util.m:
    Delete the moved code.

compiler/parse_tree.m:
compiler/notes/compiler_design.html:
    Include and document the new modules.

compiler/check_import_accessibility.m:
compiler/comp_unit_interface.m:
compiler/convert_parse_tree.m:
compiler/grab_modules.m:
compiler/make_hlds_separate_items.m:
compiler/parse_module.m:
compiler/parse_tree_out.m:
compiler/unused_imports.m:
    Conform to the changes above.
2025-01-25 08:03:57 +11:00
Zoltan Somogyi
79bfb1247f Carve prog_parse_tree.m out of prog_item.m.
compiler/prog_item.m:
compiler/prog_parse_tree.m:
    Split prog_item.m into two modules, with the new module prog_parse_tree.m
    containing the definitions of the file-kind-specific parse trees,
    and prog_item.m continuing to contain the definitions of the items
    that occur in those parse trees. Specialize the top-of-module comment
    to the current contents of each module.

compiler/parse_tree.m:
compiler/notes/compiler_design.html:
    Include and document the new module.

compiler/*.m:
    Conform to the changes above.
2024-12-19 01:27:00 +11:00
Zoltan Somogyi
72771d3da5 Delete an already acted-upon XXX. 2024-12-08 16:42:01 +11:00
Zoltan Somogyi
3b3b543a84 Return both legacy and proposed file names.
compiler/file_names.m:
    Change the predicates that return file names to return as their result
    both the current, legacy filename, and the proposed filename.

    For ext_cur extensions, the legacy and the proposed filenames
    will always be identical. Add a predicate for these that returns
    just this one filename.

compiler/comp_unit_interface.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/fact_table.m:
compiler/generate_dep_d_files.m:
compiler/generate_mmakefile_fragments.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.check_up_to_date.m:
compiler/make.clean.m:
compiler/make.dependencies.m:
compiler/make.file_names.m:
compiler/make.get_module_dep_info.m:
compiler/make.library_install.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.timestamp.m:
compiler/make.track_flags.m:
compiler/make.util.m:
compiler/make_module_file_names.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:
    Conform to the changes above. In most places, this means ignoring
    the proposed filename for now, but marking such places with "XXX LEGACY",
    to make them easier to find when we *do* start to make use of the proposed
    file names (first alongside the legacy names, and then without them).

    In some places, make variable names more descriptive.

library/set.m:
    Add utility predicate for use by a diff to one of the modules above.

NEWS.md:
    Announce the new library predicate.
2024-09-19 12:42:33 +02:00
Zoltan Somogyi
f74e2b70c6 Rename the bound_inst type to bound_functor.
compiler/prog_data.m:
    As above. The main function symbol of the type was already named
    bound_functor, and "bound inst", when spoken/typed in text,
    usually refers to the bound/3 function symbol of the mer_inst type,
    not to new-renamed type.

compiler/add_mutable_aux_preds.m:
compiler/comp_unit_interface.m:
compiler/cse_detection.m:
compiler/det_report.m:
compiler/direct_arg_in_out.m:
compiler/equiv_type_hlds.m:
compiler/error_msg_inst.m:
compiler/float_regs.m:
compiler/hlds_code_util.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_mode.m:
compiler/hlds_statistics.m:
compiler/inst_abstract_unify.m:
compiler/inst_check.m:
compiler/inst_match.m:
compiler/inst_merge.m:
compiler/inst_mode_type_prop.m:
compiler/inst_test.m:
compiler/inst_user.m:
compiler/inst_util.m:
compiler/lco.m:
compiler/mode_constraints.m:
compiler/mode_errors.m:
compiler/mode_top_functor.m:
compiler/mode_util.m:
compiler/modecheck_coerce.m:
compiler/modecheck_util.m:
compiler/module_qual.qualify_items.m:
compiler/parse_inst_mode_name.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_out_item.m:
compiler/parse_tree_to_term.m:
compiler/pd_util.m:
compiler/prog_mode.m:
compiler/recompilation.usage.m:
compiler/simplify_goal_switch.m:
compiler/switch_detection.m:
compiler/types_into_modes.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Perform s/bound_inst/bound_functor/ and s/BoundInst/BoundFunctor/ where
    appropriate, with some instances of s/bound_inst_list/bound_functors/.
2024-07-23 13:33:59 +02:00
Zoltan Somogyi
5a45d1afb8 Replace the cons/3 cons_id ...
... with the du_data_ctor/1 cons_id, which contains a du_ctor/3.
Putting all the info about discriminated union data constructors into a
separate type allows code that works only with the cons_ids of du types
to stop having to worry about all the other kinds of cons_ids.

compiler/prog_data.m:
    As above.

    Delete the cons_ctor type from this module after moving it to
    recompilation.usage.m, which is the only part of the compiler
    that uses it.

compiler/add_foreign_enum.m:
    Replace cons_id_to_tag_map with du_ctor_to_tag_map, since the only
    cons_ids the map handles are du_ctors.

compiler/hlds_cons.m:
    Replace cons_ids with du_ctors in the cons_table and in the
    info we keep about du types' fields.

compiler/hlds_data.m:
    Replace cons_ids with du_ctors in cheaper_tag_tests.

    Provide two forms of a utility function. Both return du_ctors,
    but one wraps them up as cons_ids.

compiler/type_assign.m:
    Replace cons_ids with du_ctors in cons_type_info_sources.

compiler/type_util.m:
    Switch many of the utility predicates and functions in this module
    to operate on du_ctors instead of cons_ids. Split some of the others
    to have both du_ctor and cons_id versions.

    Replace a predicate that returned a set of solutions one at a time
    on backtracking with a predicate that returns all the solutions
    at once in a list.

    Reduce unnecessary variability in variable names.

    Add some XXXs for code with unclear motivations.

compiler/typecheck_error_undef.m:
    Delete a function argument that was used only in a sanity check,
    because the code at its only call site derived that argument using code
    that made it impossible for the sanity check to fail.

    Factor out some common code.

compiler/parse_tree_out_cons_id.m:
    For three functions that operate on cons_ids, add versions
    that do the same job on du_ctors.

compiler/inst_match.m:
    Conform to the changes above. This diff rewrites from scratch
    the algorithm for testing whether a list of bound insts covers
    *all* the du_ctors of a type, because the old code was both inefficient
    and very opaque.

compiler/float_regs.m:
    Conform to the changes above, and delete a conditionally enabled abort
    that shouldn't ever be enabled.

compiler/inst_util.m:
    Conform to the changes above, and rename a predicate to avoid
    an ambiguity.

compiler/mode_errors.m:
    Conform to the changes above, and switch to printing the cons_ids
    in some error messages using the standard mechanisms of
    write_error_spec.m.

compiler/resolve_unify_functor.m:
    Conform to the changes above. Factor out repeated tests against
    du_data_ctor.

compiler/term_norm.m:
    Conform to the changes above. Add XXXs for some bugs.

compiler/add_type.m:
compiler/assertion.m:
compiler/builtin_lib_types.m:
compiler/comp_unit_interface.m:
compiler/complexity.m:
compiler/const_struct.m:
compiler/cse_detection.m:
compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/delay_partial_inst.m:
compiler/direct_arg_in_out.m:
compiler/distance_granularity.m:
compiler/du_type_layout.m:
compiler/error_msg_inst.m:
compiler/field_access.m:
compiler/format_call.m:
compiler/goal_expr_to_goal.m:
compiler/goal_util.m:
compiler/hhf.m:
compiler/higher_order.specialize_calls.m:
compiler/higher_order.specialize_unify_compare.m:
compiler/hlds_code_util.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_type_table.m:
compiler/hlds_out_util.m:
compiler/implementation_defined_literals.m:
compiler/inst_abstract_unify.m:
compiler/inst_check.m:
compiler/inst_merge.m:
compiler/inst_mode_type_prop.m:
compiler/inst_test.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/intermod_decide.m:
compiler/lco.m:
compiler/ml_global_data.m:
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_util.m:
compiler/mode_top_functor.m:
compiler/mode_util.m:
compiler/modecheck_coerce.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/module_qual.qualify_items.m:
compiler/old_type_constraints.m:
compiler/parse_inst_mode_name.m:
compiler/parse_tree_out_item.m:
compiler/parse_tree_to_term.m:
compiler/polymorphism_goal.m:
compiler/polymorphism_lambda.m:
compiler/pre_typecheck.m:
compiler/prog_ctgc.m:
compiler/prog_mode.m:
compiler/prog_rep.m:
compiler/prog_type.m:
compiler/prog_util.m:
compiler/purity.m:
compiler/qual_info.m:
compiler/rbmm.execution_path.m:
compiler/rbmm.region_transformation.m:
compiler/recompilation.usage.m:
compiler/recompilation.used_file.m:
compiler/recompute_instmap_deltas.m:
compiler/simplify_goal.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_switch.m:
compiler/simplify_goal_unify.m:
compiler/size_prof.m:
compiler/ssdebug.m:
compiler/stack_opt.m:
compiler/structure_reuse.direct_choose_reuse.m:
compiler/structure_reuse.direct_detect_garbage.m:
compiler/superhomogeneous.m:
compiler/table_gen.m:
compiler/term_constr_build.m:
compiler/typecheck_clauses.m:
compiler/typecheck_error_util.m:
compiler/typecheck_errors.m:
compiler/unify_gen_test.m:
compiler/unify_gen_util.m:
compiler/unify_proc.m:
compiler/untupling.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the changes above.

tests/invalid/coerce_int.err_exp:
tests/invalid/coerce_mode_error.err_exp:
tests/invalid/coerce_mode_error2.err_exp:
tests/invalid/coerce_recursive_inst.err_exp:
tests/invalid/coerce_recursive_type.err_exp:
    Expect diagnostics generated using the standard error_spec representations
    of cons_ids.
2024-06-30 21:36:03 +10:00
Zoltan Somogyi
8f490f6b69 Make module_qual.m a proper package.
compiler/module_qual.m:
    Delete from this module everything except include_module declarations,
    making it a proper package, after moving (most of) the deleted things
    to other modules. The rest were already unused.

compiler/module_qual.mq_info.m:
    This new submodule of module_qual.m contains the definition of the
    mq_info type, its getter/setter predicates, and some utility operations.
    This is the bulk of the old module_qual.m.

    Delete two fields of the old mq_info/mq_sub_info structure, because
    they were never used.

compiler/module_qual.qualify_items.m:
    Move the predicates that module qualify entire aug_comp_units,
    aug_make_int_units and parse_tree_int3s here from module_qual.m.

    Rename some already-here predicates to avoid name clashes with
    the newly moved predicates.

    Export only the predicates that are used outside the module *now*.

    Update some comments.

compiler/module_qual.id_set.m:
    Move a type and a predicate here from module_qual.m.

    Make a comment more detailed.

    Reorder the args of a predicate.

compiler/module_qual.collect_mq_info.m:
    Delete some trace goals that lost their usefulness a long time ago.

compiler/notes/compiler_design.html:
    Update the documentation of the module_qual package.

    Conform to the changes above.

compiler/add_clause.m:
compiler/add_type.m:
compiler/comp_unit_interface.m:
compiler/hlds_module.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile_make_hlds.m:
compiler/module_qual.qual_errors.m:
compiler/pred_table.m:
compiler/qual_info.m:
compiler/superhomogeneous.m:
    Conform to the changes above.

compiler/add_class.m:
compiler/add_foreign_proc.m:
compiler/higher_order.make_specialized_preds.m:
compiler/ml_lookup_switch.m:
compiler/mode_errors.m:
compiler/tag_switch_util.m:
    Sort import_module declarations.
2024-06-08 02:28:36 +10:00
Zoltan Somogyi
ca932da67e Delete the lambda_eval_method type and its uses.
compiler/prog_data.m:
    The lambda_eval_method type has only ever been used by the Aditi backend,
    and it has been a dummy type since that backend has been deleted.
    Delete this type, and the lambda_eval_method fields from closure_cons
    cons_ids, from the corresponding closure_tag cons_tag, and from
    the representation of higher order types, in order to avoid having to
    maintain code that sets or copies fields that have no purpose.

    The lambda_eval_method type is (now was) separate from the eval method
    stored in proc_infos, which does have alternatives to the normal
    eval method. All of these alternatives are forms of tabling, but
    lambdas cannot be tabled on their own.

compiler/hlds_goal.m:
    Delete the lambda_eval_method field from rhs_lambda_goals.

compiler/*.m:
    Conform to the changes above.
2024-04-23 20:00:06 +10:00
Julien Fischer
4cd5c17f61 Fix more copyright notices ...
... and other minor fixes.

library/*.m:
library/LIB_FLAGS.in:
compiler/*.m:
mdbcomp/*.m:
    Fix and update copyright notices.

    Fix spelling.

    Delete trailing whitespace.
2024-02-20 17:18:52 +11:00
Julien Fischer
f5e71b1e90 Fix copyright notices in recently modified files.
compiler/*.m:
library/*.m:
mdbcomp/*.m:
runtime/*.[ch]:
    As above.

    Fix spelling in some spots.
2024-02-20 15:09:17 +11:00
Zoltan Somogyi
6e2875842f Stop using .tmp files when generating .intN files.
compiler/write_module_interface_files.m:
    Instead of

        - writing out the new version of a .intN file to module.intN.tmp,
        - comparing that file with module.intN, and
        - renaming module.intN.tmp to module.intN if they differ,

    we now

        - read in the old .intN file to a string
        - convert the new parse tree for .intN to a string
        - write out the string form of the new parse tree to module.intN
          if they differ.

    The logic is bit more complex in the presence of smart recompilation
    (in both the old new algorithms) but not by much.

    The new algorithm requires significantly fewer system calls than the old.

compiler/comp_unit_interface.m:
    Don't create a name for .intN.tmp files, since they are not needed anymore.

compiler/module_cmds.m:
    Reorder the predicates that copy files putting the most basic predicate
    last, so that calls go from earlier predicates to later predicates.

compiler/parse_module.m:
    Delete unneeded IO state args from the parse_intN_file predicates.

compiler/parse_tree_out.m:
    Carve output_parse_tree_string out of the existing
    output_some_parse_tree predicate which also *constructed* that parse tree.
    This capability is needed by new code in write_module_interface_files.m,
    which wants to perform other operations on the string forms of parse trees
    before writing them out.
2024-02-13 10:46:48 +11:00
Zoltan Somogyi
4d0ce5c35a Carve parse_tree_out_item.m out of parse_tree_out.m.
compiler/parse_tree_out.m:
compiler/parse_tree_out_item.m:
    Move the parts of the old parse_tree_out.m that deal with the output
    of individual items, or item components, to the new module
    parse_tree_out_item.m.

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

compiler/comp_unit_interface.m:
compiler/hlds_out_type_table.m:
compiler/hlds_out_typeclass_table.m:
compiler/intermod.m:
compiler/intermod_analysis.m:
    Import the new module instead of the old.

compiler/indent.m:
compiler/mlds_to_target_util.m:
compiler/parse_tree_out_misc.m:
    Sort imports.
2024-02-08 16:56:47 +11:00
Zoltan Somogyi
5fb7bcdfcc Optimize the generation of .int0 files.
compiler/comp_unit_interface.m:
    When creating .int0 files from .m files, delete the parts of the .m
    parse tree *before* module qualifying it, instead of after.
    This saves the time that would otherwise be needed to module qualify
    those parts. The biggest saving comes from not module qualifying clauses,
    though we delete some other parts as well.
2023-11-04 04:54:14 +11:00
Zoltan Somogyi
bdabaf5dc9 Make an error message more inclusive.
compiler/comp_unit_interface.m:
    When we cannot generate a .int0/.int/.int2 file because of file access
    issues, the reason is *usually* that we can't read a .int3 file.
    However, it is also possible that the reason is that we can't read
    a .int0 file, so include that possibility in the overall error message.
    (The "can't read this file" message, with the specifics of the file
    that couldn't be read, would have been printed earlier.)

tests/invalid_make_int/missing_parent_import.int_err_exp:
tests/invalid_make_int/sub_c.int_err_exp:
tests/invalid_make_int/test_nested.int_err_exp:
    Expect the updated error message.
2023-10-30 18:05:46 +11:00
Zoltan Somogyi
a3546b16c3 Move code to generate interface to comp_unit_interface.m.
compiler/write_module_interface_files.m:
compiler/comp_unit_interface.m:
    Move the predicates that generate the parse trees of interface files
    from write_module_interface_files.m to comp_unit_interface.m.
    Move the types they need with them, and document them.

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

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

compiler/make.get_module_dep_info.m:
compiler/mercury_compile_main.m:
    Conform to the changes above.
2023-10-25 12:35:57 +11:00
Zoltan Somogyi
625ec287f1 Carve five new modules out of prog_type.m.
compiler/prog_type_construct.m:
    New module for constructing types.

compiler/prog_type_repn.m:
    New module for testing things related to type representation.

compiler/prog_type_scan.m:
    New module for gather type vars in types.

compiler/prog_type_test.m:
    New module containing simple tests on types.

compiler/prog_type_unify.m:
    New module for testing whether two types unify, or whether
    one type subsumes another.

compiler/prog_type.m:
    Delete the code moved to the new modules.

compiler/parse_tree.m:
    Include the new modules.

compiler/notes/compiler_design.html:
    Document the new modules.

compiler/*.m:
    Conform to the changes above, by adjusting imports as needed,
    and by deleting any explicit module qualifications that
    this diff makes obsolete.
2023-10-06 08:42:43 +11:00
Zoltan Somogyi
8e32ce0c7f Allow use_module declarations in .int2 files ...
... for modules referenced in the definitions of equivalence types.

compiler/comp_unit_interface.m:
    Add use_module declarations for modules referenced by the right hand sides
    of equivalence type definitions to the implementation sections of .int2
    files.

    Update the names of some of the predicates involved.

    Make the definitions of the predicates accumulate_modules_in_type and
    accumulate_modules_in_qual_type, which do *almost* the same job,
    as similar to each other as possible.

compiler/make_hlds_separate_items.m:
    Allow use_module declarations in the implementation sections of .int2
    files.

compiler/grab_modules.m:
    Ensure that we grab the .int2 files of any modules that have use_module
    declarations for them in the implementation sections of .int2 files.

tests/valid_seq/bug563.m:
tests/valid_seq/bug563_helper_1.m:
tests/valid_seq/bug563_helper_2.m:
    The test case from the Mantis bug report, renamed.

tests/valid_seq/Mmakefile:
    Enable the new test case.
2023-09-04 15:00:38 +10:00
Zoltan Somogyi
9d38b252bf Separate marker pragmas from other decl/impl pragmas.
compiler/prog_item.m:
    Previously, both decl and impl pragmas contained some pragma kinds
    that contained only the specification of a predicate or function.
    These served only to specify a marker to be applied to the named
    predicate or function.

    This diff separates out those kinds of pragmas from the types of
    both the decl pragmas and the impl pragmas (the difference is that
    decl pragmas may appear in module interfaces, while impl pragmas may not),
    and gives them two new representations: decl markers and impl markers.

    While in the old representation, each kind of marker had its own wrapper
    around the predicate/function specification, in the new representation,
    they are side-by-side, which allows simpler construction techniques
    and smaller code.

    Update the definition of parse_tree_module_src, parse_tree_plain_opt,
    parse_tree_int0 and parse_tree_int1 to include markers alongside
    pragmas of each kind. Use subtypes to restrict the kinds of markers
    that can appear in parse_tree_plain_opts to the set that we actually
    can put into them. (Source files of course can contain any markers,
    and .intN files either get put into them either all of the markers
    that occur in the source file in a given section, or none of them.)

    Delete the item_pragma_info type, which was a wrapper around
    the specific info of each pragma, and stored a context and an item
    sequence number alongside it. Move the context and the item sequence
    number into the representation of each pragma. This should reduce
    visual clutter in the source code at places that construct or deconstruct
    pragmas, and at runtime (with direct args) it should reduce both
    the number of memory cells we need to allocate, and the number
    of pointers we need to follow.

    Include decl vs impl in the names of some function symbols.

    Partly to counteract that, shorten some names to avoid excessive
    line lengths.

compiler/add_pragma.m:
    Add predicates to add decl and impl markers.

    Move the predicates looping over lists of pragma next to the
    predicates handling those pragmas.

compiler/make_hlds_passes.m:
    Add both decl and impl markers before adding foreign_procs.
    The ability to do this was the original motivation for this diff.
    Update the comments both about this issue, and about why we delay
    adding tabling pragmas to the HLDS.

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

    Add an XXX about something fishy.

compiler/item_util.m:
    Delete aux functions that are no longer needed.

compiler/add_mutable_aux_preds.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/comp_unit_interface.m:
compiler/convert_parse_tree.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/hlds_module.m:
compiler/intermod.m:
compiler/intermod_analysis.m:
compiler/make_hlds_separate_items.m:
compiler/mercury_compile_middle_passes.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qual_errors.m:
compiler/module_qual.qualify_items.m:
compiler/parse_pragma.m:
compiler/parse_pragma_analysis.m:
compiler/parse_pragma_foreign.m:
compiler/parse_pragma_tabling.m:
compiler/parse_tree_out.m:
compiler/parse_tree_out_pragma.m:
compiler/prog_item_stats.m:
compiler/prog_mutable.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/unused_args.m:
    Conform to the changes above.
2023-08-06 12:33:55 +02:00
Zoltan Somogyi
155bc71d72 Make foreign_procs their own top-level item kind.
compiler/prog_item.m:
    Change foreign_procs from being one kind of impl_pragma item
    to being their own item kind. Because of this, the changes to
    some of the modules listed below delete "pragma" from the names
    of predicates and types referring to foreign_procs.

    Include foreign_proc items in parse_tree_module_srcs and
    parse_tree_plain_opts, the two kinds of parse trees that may contain
    foreign_procs.

compiler/make_hlds_separate_items.m:
    Gather foreign procs independently of impl pragmas.

compiler/make_hlds_passes.m:
    Add foreign_procs from the parse_tree_module_src and any
    parse_tree_plain_opts to the HLDS at the same time as we add
    foreign_procs generated by the compiler to implement solver types
    and mutables. Document the reason for this.

    Document also the reason why we should add all marker pragmas
    just before we do this. Document the reason why two tests will fail
    until that, or something similar, is done.

compiler/add_foreign_proc.m:
    Delete a test that was required only because we couldn't guarantee
    the relative order of adding foreign_procs and pragmas that mark
    predicates as external on one backend.

compiler/module_qual.qual_errors.m:
    Add foreign_procs as a possible context for errors during qualification.

compiler/status.m:
    Add a comment documented an old issue.

compiler/add_mutable_aux_preds.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_solver.m:
compiler/check_module_interface.m:
compiler/comp_unit_interface.m:
compiler/convert_parse_tree.m:
compiler/coverage_profiling.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/equiv_type.m:
compiler/foreign.m:
compiler/get_dependencies.m:
compiler/goal_util.m:
compiler/grab_modules.m:
compiler/hlds_goal.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/ml_foreign_proc_gen.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/parse_pragma_foreign.m:
compiler/parse_tree_out.m:
compiler/parse_tree_out_pragma.m:
compiler/pragma_c_gen.m:
compiler/prog_item_stats.m:
compiler/prog_mutable.m:
compiler/recompilation.version.m:
compiler/structure_sharing.domain.m:
compiler/table_gen.m:
compiler/tabling_analysis.m:
compiler/term_util.m:
compiler/termination.m:
compiler/trailing_analysis.m:
compiler/prog_data_foreign.m:
compiler/unify_proc.m:
    Conform to the changes above.
2023-08-04 11:42:46 +02:00
Zoltan Somogyi
ecf3902b91 Use abstract typeclasses in parse_tree_int[13].
compiler/prog_data.m:
    Define a subtype of the typeclass interface type for abstract typeclasses.

compiler/prog_item.m:
    Change the types of the fields representing

    - implementation section typeclasses in .int files, and
    - interface section typeclasses in .int3 files

    to a subtype that allows the definition of only abstract typeclasses.

    The interface section typeclasses in .int3 files have more invariants
    than just being abstract, but these cannot currently be expressed
    using subtypes.

library/list.m:
    Add a comment (which is visible only to Mercury developers)
    about why this is so.

compiler/comp_unit_interface.m:
compiler/convert_parse_tree.m:
compiler/equiv_type.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/recompilation.check.m:
compiler/recompilation.version.m:
    Conform to the changes above.
2023-08-02 03:07:11 +02:00
Zoltan Somogyi
dde8c1f396 Delete mer_inst's free/1 functor.
This functor was intended to have the same semantics as free/0, while
containing the type of the value it was applied to. However, commit
87e7e3bafa, the commit in which Fergus
introduced this function symbol, also contained an "XXX temporary hack"
in which the code that was supposed to create a value using this function
symbol when propagating a type into a free/0 inst, just ignored the type,
and left the inst as free/0. THIS TEMPORARY HACK HAS REMAINED IN THE CODE
SINCE 1994.

In a few places, we did hand-create insts using free/1 for code created
by the compiler itself. However, as far as I can tell, no free/1 inst
ever described any code read in from source files. This meant that
any code in switch arms for free/1 in switches on insts was never tested
in any meaningful sense. And predicates such as inst_merge_4, which
processed several kinds of insts without doing a complete switch on insts,
simply lacked code handle free/1 at all.

This diff deletes the free/1 function symbol. It does so NOT because
the type stored as its argument is not useful, but because it is useful
NOT JUST for free insts, but for ALL insts. This means that any mechanism
for providing information about the type of the value that an inst applies to
should work for all insts. This can be done

- either by passing along the type with every inst, and stepping into
  the argument types of each argument of a function symbol as we process
  bound insts, in every operation that operates on insts that needs
  type information.

- or by including a type in ALL the function symbols of the inst type.
  (We could do this either by adding a maybe(mer_type) field to each
  function symbol, which would be "no" before the propagate-types-
  into-modes pass, or by adding just a mer_type field, which would
  be a special dummy value before that pass. I (zs) prefer the latter,
  and so would juliensf.)

The second option would involve reintroducing a free/1 function symbol
into the inst type, but this would replace the existing free/0
function symbol, and it would inherit all the code that currently
handles free/0, NOT the code being deleted by this diff for handling
the *current* free/1.

The first option would be easier to implement if only one or maybe two
operations needed type info, the second would be both easier to implement
and more efficient if more operations needed that info.

compiler/prog_data.m:
    Delete free/1.

compiler/add_mode.m:
compiler/add_mutable_aux_preds.m:
compiler/comp_unit_interface.m:
compiler/dep_par_conj.m:
compiler/direct_arg_in_out.m:
compiler/equiv_type_hlds.m:
compiler/error_msg_inst.m:
compiler/float_regs.m:
compiler/hlds_code_util.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_mode.m:
compiler/hlds_statistics.m:
compiler/inst_abstract_unify.m:
compiler/inst_check.m:
compiler/inst_match.m:
compiler/inst_merge.m:
compiler/inst_mode_type_prop.m:
compiler/inst_test.m:
compiler/inst_user.m:
compiler/inst_util.m:
compiler/mode_constraints.m:
compiler/mode_errors.m:
compiler/mode_top_functor.m:
compiler/modecheck_coerce.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_to_term.m:
compiler/pd_util.m:
compiler/prog_mode.m:
compiler/prog_rep.m:
compiler/recompilation.usage.m:
compiler/types_into_modes.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the change above.
2023-07-22 12:26:55 +02:00
Zoltan Somogyi
92941c4239 Delete mer_inst's abstract_inst functor.
We have never supported abstract insts, and we are not likely to start
using them any time soon, but we have had them in the representation of insts
since the beginning. Since they were never actually generated, the code
that operated on them was never really tested, which is good, because
in many places, that code simply threw an exception. The code that didn't
throw an exception when it found an abstract inst had to work correctly
for the abstract_insts that we actually generated, which were abstract
only in the sense that they were references to a would-be user-defined inst
name that wasn't actually defined.

There were two sources of such "abstract" insts.

- One was failed calls to inst_lookup that specified an user_inst inst_name.

- The other consisted of predicates whose job was to construct error messages
  involving insts. These either converted cons_ids into abstract insts,
  or mangled valid user_inst inst_names into invalid user_inst inst_names,
  because error_msg_inst.m generated good-looking messages when given
  the results of such conversions.

The first is handled by the fact that module qualification detects and
reports references to undefined insts and modes, and does not let the
compiler proceed to the compiler phases that may call inst_lookup.

The second is handled by the changes to error_msg_inst.m below.
These change to handle the use cases of the two error-message-constructing
predicates that used to employ abstract_insts, but now employ user_inst
defined_insts with a two particular kinds of undefined inst ctor,
one for each use case.

compiler/prog_data.m:
    Delete the abstract_int function symbol from the mer_inst type.

compiler/inst_lookup.m:
    When the lookup of an user_inst inst_name inside a defined_inst
    fails, don't convert that defined_inst into abstract inst,
    throw an exception.

compiler/error_msg_inst.m:
    Add code to deal with the insts that add_mutable_aux_preds.m and
    mode_errors.m generate for us to convert to lists of error message pieces.
    The addition is done twice, in an as identical a fashion as possible,
    when generating non-inline pieces and when generating inline pieces.

compiler/add_mutable_aux_preds.m:
compiler/mode_errors.m:
    Document how these modules cooperates with error_msg_inst.m.

compiler/add_mode.m:
compiler/comp_unit_interface.m:
compiler/direct_arg_in_out.m:
compiler/equiv_type_hlds.m:
compiler/float_regs.m:
compiler/hlds_code_util.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_mode.m:
compiler/hlds_statistics.m:
compiler/inst_abstract_unify.m:
compiler/inst_check.m:
compiler/inst_match.m:
compiler/inst_merge.m:
compiler/inst_mode_type_prop.m:
compiler/inst_test.m:
compiler/inst_user.m:
compiler/inst_util.m:
compiler/make_hlds_passes.m:
compiler/mode_top_functor.m:
compiler/modecheck_coerce.m:
compiler/modecheck_util.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_to_term.m:
compiler/pd_util.m:
compiler/prog_mode.m:
compiler/recompilation.usage.m:
compiler/types_into_modes.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the changes above, mostly by deleting code dealing with
    abstract_insts.

tests/invalid/functor_ho_inst_bad.err_exp:
tests/invalid/functor_ho_inst_bad_3.err_exp:
tests/invalid/partial_implied_mode.err_exp:
tests/invalid_nodepend/occurs.err_exp:
    Update these expected outputs, which each involve errors generated
    by the modified code in mode_errors.m or add_mutable_aux_preds.m.
    Some of these referred to some things as "named insts" when they were
    *not* named insts in the program.

tests/invalid_nodepend/kind.{m,err_exp}:
    Add some invalid code to this test, and update the expected output
    accordingly.
2023-07-21 21:03:40 +02: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
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
Zoltan Somogyi
f355497087 Delete include context maps from parse_tree_int[012].
compiler/prog_item.m:
    We used to record information about include declarations
    in parse_tree_int[012] in two forms:

    - as a pair of maps from module names to contexts (one each for
      includes in the interface and implementation sections), and
    - as a single map from module names to an include_module_info, which
      recorded the section of its appearance along with its context.

    The second of these data structures is derived from the first,
    in a process that can result in the generation of diagnostic messages.
    In the absence of any issues reported by these diagnostics, the two forms
    contain the same information.

    Avoid this redundancy by keeping only the second form in the parse trees
    of .int0, .int and .int2 files. (.int3 files cannot contain include_module
    declarations.)

    Since .int2 files may contain include_module declarations only in
    the interface section, change the representation of the second form
    to a type that expresses this invariant: int_include_module_map,
    which is a subtype of the existing type include_module_map.

compiler/comp_unit_interface.m:
compiler/convert_parse_tree.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/parse_tree_out.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
    Conform to the change above.

compiler/item_util.m:
    Add a utility predicate for use by new code above.
2023-01-22 19:01:42 +11:00
Zoltan Somogyi
5ae7d25740 Delete import/use context maps from parse_tree_int[012].
compiler/prog_item.m:
    We used to record information about import and use declarations
    in parse_tree_int[012] in two forms:

    - as a quartet of maps from module names to contexts (one each for
      int imports, int uses, imp imports and imp uses), and
    - as a single map from module names to a section_import_and_or_use,
      which recorded the section and kind (import or use) of its appearance
      along with its one context, except for the case of modules that have
      an use_module declaration in the interface section and an import_module
      declaration in the implementation section.

    The second of these data structures is derived from the first,
    in a process that can result in the generation of diagnostic messages.
    In the absence of any issues reported by these diagnostics, the two forms
    contain the same information.

    Avoid this redundancy by keeping only the second form in the parse trees
    of .int0, .int and .int2 files. (For .int3 files, which can contain
    only import_modules, and only in the interface section, this redundancy
    has not been present even before now.)

    Since .int and .int2 files may contain only use_module declarations
    and not import_module declarations, change the representation of the
    second form to a type that expresses this invariant: the new type
    section_use_map, which is a subtype of the existing type
    section_import_and_or_use_map.

    For .int2 files, we could use an even tighter type right now, but
    a fix for Mantis bug #563 would have to undo such a change, so
    don't bother.

compiler/comp_unit_interface.m:
    Delete the code that used to construct the first form above
    for these interface file kinds. Conform to the changes above.

compiler/convert_parse_tree.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/parse_tree_out.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
    Conform to the changes above.

compiler/item_util.m:
    Add new, specialized versions of existing utility predicates
    to make that conformance possible.
2023-01-21 21:31:00 +11:00
Zoltan Somogyi
faf9ebf5e3 Don't provide for implicit imports in .intN parse trees.
compiler/prog_item.m:
    The ptiN_import_use_map fields in the representations of .int0, .int
    and .int2 files had the same type as the ptms_import_use_map field
    in the parse trees of .m files, which is where they were derived from.
    However, while the ptms_import_use_map field needs to be able to represent
    implicit imports, the parse trees of .int0, .int and .int2 files
    should never include any implicit imports, and in fact any implicit
    imports in these fields were already ignored.

    Encode the invariant that interface files never include implicit imports
    in the types of these fields.

compiler/comp_unit_interface.m:
    Discard the implicit part of the source file's import_and_or_use_map
    when computing the contents of .int0, .int and .int2 files.

compiler/item_util.m:
    Provide the facilities used by the updated code in the modules above.

compiler/convert_parse_tree.m:
compiler/grab_modules.m:
compiler/make_hlds_separate_items.m:
    Conform to the changes above.
2023-01-21 06:38:17 +11:00
Zoltan Somogyi
307b1dc148 Split up error_util.m into five modules.
compiler/error_spec.m:
    This new module contains the part of the old error_util.m that defines
    the error_spec type, and some functions that can help construct pieces
    of error_specs. Most modules of the compiler that deal with errors
    will need to import only this part of the old error_util.m.

    This change also renames the format_component type to format_piece,
    which matches our long-standing naming convention for variables containing
    (lists of) values of this type.

compiler/write_error_spec.m:
    This new module contains the part of the old error_util.m that
    writes out error specs, and converts them to strings.

    This diff marks as obsolete the versions of predicates that
    write out error specs to the current output stream, without
    *explicitly* specifying the intended stream.

compiler/error_sort.m:
    This new module contains the part of the old error_util.m that
    sorts lists of error specs and error msgs.

compiler/error_type_util.m:
    This new module contains the part of the old error_util.m that
    convert types to format_pieces that generate readable output.

compiler/parse_tree.m:
compiler/notes/compiler_design.html:
    Include and document the new modules.

compiler/error_util.m:
    The code remaining in the original error_util.m consists of
    general utility predicates and functions that don't fit into
    any of the modules above.

    Delete an unneeded pair of I/O states from the argument list
    of a predicate.

compiler/file_util.m:
    Move the unable_to_open_file predicate here from error_util.m,
    since it belongs here. Mark another predicate that writes
    to the current output stream as obsolete.

compiler/hlds_error_util.m:
    Mark two predicates that wrote out error_spec to the current output
    stream as obsolete, and add versions that take an explicit output stream.

compiler/Mercury.options:
    Compile the modules that call the newly obsoleted predicates
    with --no-warn-obsolete, for the time being.

compiler/*.m:
    Conform to the changes above, mostly by updating import_module
    declarations, and renaming format_component to format_piece.
2022-10-12 20:50:16 +11:00
Zoltan Somogyi
30cb4f0ba3 Tighten representation of include/import/use decls.
compiler/prog_item.m:
    Change the representation of include, import and use declarations
    in the data structures of .int0 and .int3 files.

    For both .int0 and .int3 files, switch from data structures that can
    associate one or more contexts with each such declaration with
    data structures that can associate just one. Any duplicates would be
    errors, and we don't want to allow the representation of errors in
    compiler-generated interface files. (Similar updates to .int/.int2
    files are coming soon.)

    For .int3 files, delete two fields that hold information about include
    declarations and import/use declarations respectively in a fully checked
    form. They are not needed, because with invariants that .int3 files
    are subject to (no uses, no implementation section, no implicit imports),
    they contain just the same info as the new data structures mentioned
    in the paragraph above.

compiler/comp_unit_interface.m:
    Update the code that computes the contents of .int0/.int3 files.

    Fix some out-of-sequence variable names.

compiler/convert_parse_tree.m:
    Update the code that converts the generic parsed representation of
    interface files to the specific representations of .int0/.int3 files.

compiler/item_util.m:
    Update the utility predicates that comp_unit_interface.m and
    convert_parse_tree.m use to do their jobs. Add new variants
    of some existing predicates.

compiler/grab_modules.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out.m:
compiler/recompilation.check.m:
2022-09-03 11:01:08 +10:00
Zoltan Somogyi
c7171d0acf Simplify parameter passing. 2022-04-04 05:10:28 +10:00
Zoltan Somogyi
924f47b5bd Put all accumulate_modules_* predicates together ...
at the end of the module, in a top-down order, and with a consistent
naming scheme.
2022-01-25 23:01:49 +11:00
Zoltan Somogyi
0fa22b6e5a Update a comment. 2022-01-25 22:15:58 +11:00
Zoltan Somogyi
d64961d79d Use checked types/insts/modes in parse_tree_module_src.
This means that we can do the exact same checks (and, if needed, generate
the exact same error messages) when generating interface files as when
generating target language code.

This should also allow us to simplify the process of adding type, inst
and mode definitions to the HLDS.

compiler/prog_item.m:
    As above.

    Delete unused function.

compiler/error_util.m:
    Add mechanisms that allow us to distinguish (a) error specs that represent
    a type, inst or mode name definition being invalid, from (b) other error
    specs.

compiler/check_type_inst_mode_defns.m:
    Improve the error messages we generate, in several ways.

    First, for each message, specify a real severity. When the messages
    could be seen only when generating interface files, making them all
    warnings was fine and preserved old behavior, but since soon these
    will be the only place for these checks, we need to call errors errors.

    Second, specify, in the phase, which errors represent a invalid type,
    inst or mode definition, and which don't.

    Third, improve the wording of messages. In some places, do this by
    being clearer about the distinction between declarations and definitions.
    In others, do it by including more information in the message. In yet
    others, do it by recovering some kinds of mistakes (mostly items being
    in the wrong section) enough to avoid avalanche errors.

    Fourth, fix a bug. If a type ctor has an exported *declaration*,
    then it is ok for any foreign type definitions for that type_ctor
    being in the implementation section, but if the type_ctor has an
    exported Mercury *definition*, then any foreign_type definitions
    must be in the interface section as well. The code that handled
    both these situations did not enforce that.

    Fifth, fix another bug: do not include foreign type definitions
    in the source definitions of a type_ctor twice, once as a "du" (sic)
    definition, and once as itself.

compiler/convert_parse_tree.m:
    Check type, inst and mode definitions in raw_compilation_units
    when creating parse_tree_module_srcs.

compiler/comp_unit_interface.m:
    Make the code constructing interface files work from the checked maps
    in parse_tree_module_srcs.

compiler/make_hlds_passes.m:
    Set the flags that say we have found invalid type, inst or mode definitions
    from the error specs constructed during the creation of the checked
    type, inst and mode maps.

compiler/add_type.m:
    Comment out an error message for a condition that will be detected and
    reported by check_type_inst_mode_defns.m.

compiler/make_hlds_separate_items.m:
    For now, turn checked maps of type, inst and mode definitions
    back to item lists for addition to the HLDS. Adding whole checked
    definitions to the HLDS will be done by a future change.

compiler/make_hlds_error.m:
    Fix misleading indentation in an error message.

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

    Generate output whose indentation does not depend on tab settings.

compiler/check_raw_comp_unit.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
    Conform to the changes above.

compiler/parse_type_defn.m:
    Fix misleading error message for ":- type <name> = <type>".

tests/debugger/foreign_type.{m,exp}:
    Delete a redundant type declaration to avoid a warning, and update
    the .exp file to expect the new line numbers.

tests/invalid/any_mode.err_exp:
tests/invalid/bug436.err_exp:
tests/invalid/bug476.err_exp:
tests/invalid/exported_foreign_enum.err_exp:
tests/invalid/fe_unmapped_nonverbose.err_exp:
tests/invalid/fe_unmapped_verbose.err_exp:
tests/invalid/foreign_enum_invalid.err_exp:
tests/invalid/foreign_solver_type.err_exp:
tests/invalid/foreign_type_visibility.err_exp:
tests/invalid/pragma_qual_error.err_exp:
tests/invalid/repeated_field_name.err_exp:
tests/invalid/subtype_foreign.err_exp:
tests/invalid/type_with_no_defn.err_exp:
tests/invalid/types2.err_exp:
tests/invalid/user_field_access_decl_conflict.err_exp:
tests/invalid_nodepend/bad_foreign_type.err_exp:
tests/invalid_nodepend/bigtest.err_exp:
tests/invalid_nodepend/invalid_typeclass.err_exp:
tests/invalid_nodepend/types.err_exp:
tests/invalid_nodepend/uu_type.err_exp:
tests/invalid_nodepend/where_abstract_enum.err_exp:
    Expect the new error messages.

tests/invalid/abstract_solver_type.{m,err_exp}:
tests/warnings/abstract_solver_type.{m,exp}:
    Move the abstract_solver_type test case from invalid to warnings, because
    this diff changes its only error to be only a warning.

tests/invalid/Mmakefile
2021-10-16 17:37:36 +11:00
Zoltan Somogyi
4548706b85 Switch to checked type/inst/mode maps for .int0.
compiler/prog_item.m:
    As above.

compiler/comp_unit_interface.m:
compiler/convert_parse_tree.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/parse_tree_out.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
    Conform to the change above.
2021-10-03 06:21:44 +11:00
Zoltan Somogyi
4126519139 Separate subtypes from du types in parse trees.
compiler/prog_data.m:
    Split type_details_sub from type_details_du, and separate
    parse_tree_sub_type from parse_tree_du_type. This gets us two things:

    - It allows us to encode the prohibition on user-specified equality and
      comparison predicates, and "where direct_arg is" clauses,
      on subtype definitions.

    - It gives us data types we can use to represent (a) only subtype
      definitions, and (b) only non-subtype du definitions.

    Note that this diff deliberately leaves the HLDS representation
    of subtypes unchanged. This is because while a subtype *definition*
    may not specify e.g. equality and comparison predicates, a subtype *can*
    have equality and comparison predicates; it just has to get them from
    its base type. And the same applies to direct args.

compiler/parse_type_defn.m:
    Enforce the invariant that subtypes may not have user-specified equality
    and comparison predicates, or "where direct_arg is" clauses.

    If we find a subtype definition that does have one or both of these
    non-allowed and now-nonrepresentable components, we do still want to
    return the rest of the type definition, in order to avoid misleading
    error messages about that type having no definition at all. To make this
    possible, allow the parsing predicate to return error_specs "alongside",
    as well as "instead of", the item or marker being parsed.

compiler/parse_item.m:
compiler/parse_module.m:
compiler/parse_class.m:
    Handle these "alongside" error messages.

compiler/prog_item.m:
    Separate out subtypes from other du types in type definition maps.

compiler/add_type.m:
    Delete a semantic check that is now in parse_type_defn.m.

    Conform to the change to the representations of subtypes/du types
    in the parse tree.

compiler/item_util.m:
    Add a new utility function for subtypes.

compiler/check_type_inst_mode_defns.m:
compiler/comp_unit_interface.m:
compiler/convert_parse_tree.m:
compiler/decide_type_repn.m:
compiler/equiv_type.m:
compiler/get_dependencies.m:
compiler/intermod.m:
compiler/make_hlds_passes.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/prog_type.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
    Conform to the change to the representations of subtypes/du types
    in the parse tree.
2021-10-02 16:45:26 +10:00
Zoltan Somogyi
12605f8c10 Use checked type/inst/modes in parse_tree_int[123]s.
With this change, we guarantee that if any type, inst or mode
has inconsistent definitions in its defining module, those inconsistencies
will not make it into the the module's .int/.int2/.int3 files, where
they would confuse any compiler invocation that reads them in.

compiler/prog_item.m:
    Replace {type,inst,mode}_ctor_defn_maps, which are unchecked,
    with {type,inst,mode}_ctor_checked_maps in parse_tree_int[123]s.

    To make this possible,

    - generalize the items containing inst and mode definitions the way that
      items containing type definitions have been generalized previously,
      to allow them to store particular *kinds* of inst or mode definitions;

    - move the definitions of type_ctor_checked_map and its components
      here from check_type_inst_mode_defns.m; and

    - add similar, but simpler, definitions for {inst,mode}_ctor_checked_map.

compiler/check_type_inst_mode_defns.m:
    Delete the type definitions moved to prog_item.m.

    Modify the checking process slightly to allow it to check properly
    the definitions we now put into .int, .int2 and .int3 files.

    Add code to check inst and mode definitions as well as type definitions.
    Since insts and modes have only one non-abstract kind of definition,
    these codes are much simpler than the code for checking types.

compiler/comp_unit_interface.m:
    Construct checked type, inst and mode definitions to put into
    .int, .int2 and .int3 files. The .int2 and .int3 parts were
    reasonably simple, but the .int part requires some detailed
    case-by-case analysis.

compiler/convert_parse_tree.m:
    Check the type, inst and mode definitions read in from .int/.int2/.int3
    files when creating their parse trees. If those files were generated
    by a compiler that has this diff, then this checking process should
    not find any problems.

compiler/equiv_type.m:
    Operate on checked type, inst and mode definitions instead of their
    unchecked versions.

    Delete an unneeded field from a structure.

compiler/error_util.m:
    Add {qual,unqual}_{inst,mode}_ctor as format components, so that
    any error messages about inst and mode definitions do not have to convert
    inst_ctors and mode_ctors to symname/arity pairs.

compiler/item_util.m:
    Add some utility predicates and functions needed by the changes above.

compiler/module_qual.collect_mq_info.m:
    Since checked type, inst and mode definitions can contain info that is
    derived from both the interface and implementation sections of a module,
    add the capability to get only the *publicly* declared types, insts and
    modes from their respective kinds of checked definitions.

compiler/module_qual.qualify_items.m:
    Module qualify checked type, inst and mode definitions.

compiler/module_qual.qual_errors.m:
    Treat references to inst_ctors and mode_ctors in qualification error
    messages the same way as we treat type_ctors.

    Also replace mq_ids that are intended to represent classes with class_ids,
    to represent the intent better.

compiler/parse_tree_out.m:
    Output the updated parse_trees of .int/.int2/.int3 files.

compiler/prog_data.m:
    Add an XXX about a future change.

compiler/decide_type_repn.m:
compiler/get_dependencies.m:
compiler/grab_modules.m:
compiler/make_hlds_separate_items.m:
compiler/pred_table.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
    Conform to the changes above.

library/maybe.m:
    Add utility predicates needed by the code above.

NEWS:
    Announce the new predicates in maybe.m.

tools/intdiffall:
    A script that shows differences between the automatically generated
    interface files between stage 1 and stage 2, which helped debug this diff.
2021-10-01 17:57:15 +10:00
Zoltan Somogyi
22038a5b28 Rename check_parse_tree_type_defns.m ...
... to check_type_inst_mode_defns.m.

compiler/parse_tree.m:
    Change the name in the include_module declaration.

compiler/comp_unit_interface.m:
compiler/convert_parse_tree.m:
compiler/decide_type_repn.m:
compiler/prog_foreign_enum.m:
compiler/prog_item.m:
    Change the name in import_module declarations.

compiler/notes/compiler_design.html:
    Change the name in the documentation.
2021-09-08 06:59:35 +10:00
Zoltan Somogyi
7194baab3c Rename version_numbers to module_item_version_numbers.
Also, turn some semidet functions into predicates, and given them
more meaningful names.

compiler/recompilation.m:
compiler/timestamp.m:
    As above.

compiler/comp_unit_interface.m:
compiler/grab_modules.m:
compiler/make_hlds_passes.m:
compiler/parse_item.m:
compiler/parse_module.m:
compiler/parse_tree_out.m:
compiler/parse_types.m:
compiler/prog_item.m:
compiler/recompilation.check.m:
compiler/recompilation.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
    Conform to the changes above.
2021-08-28 00:05:34 +10:00
Zoltan Somogyi
163af89c98 Don't put duplicate imports/uses in .int{,0,2}.
The problem addressed by this diff is that copying any duplicate
import_module and/or use_module declarations in .m files to
automatically generated .intN files will cause those errors to be
reported 1+M times, once when compiling the source module, and
once for each of the M modules that import it. Those extra M reports
are not useful; they are only clutter.

compiler/comp_unit_interface.m:
    Do not copy the raw set of import_module and use_module declarations
    from the source file to the .int0 file. Instead, compute them anew
    from the import_and_or_use map, which was built by discarding any
    duplicate declarations, either within a single section, or across
    both sections.

    When deciding which modules to generate a use_module declaration for
    in the implementation section of a .int or .int2 file, do not include
    one for any module which has a use_module declaration in the interface.

compiler/item_util.m:
    Add a predicate that comp_unit_interface.m uses in the first task above.
2021-08-20 20:36:54 +10:00
Zoltan Somogyi
15c6fcabda Fix comment rot. 2021-08-17 23:12:51 +10:00
Zoltan Somogyi
8d513a9954 Delete some use unused types and preds. 2021-08-17 20:22:46 +10:00
Zoltan Somogyi
428aa400eb Introduce aug_make_int_unit.
compiler/prog_item.m:
    Split aug_compilation_unit into two types. One, aug_make_int_unit,
    is a new type, and it is a version of the old aug_compilation_unit
    that contains only what is needed when making .int{,0,2} files.
    The other, the new aug_compilation_unit, contains what is needed
    when generating target language code. Both encode in their argument types
    stronger invariants that the old aug_compilation_unit type did.

compiler/comp_unit_interface.m:
compiler/decide_type_repn.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.m:
compiler/parse_tree_out.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
    Conform to the change above.

    In some cases, this means passing around aug_make_int_units instead of
    aug_compilation_units.

    In a few cases, it means creating two copies of a predicate,
    one for aug_compilation_units and one for aug_make_int_units.
    In such cases, factor out any commonalities between the copies.

    In many cases, it means updates to account for the specialized types
    of the fields of aug_compilation_unit or aug_make_int_unit.

    In some cases, it means deleting code that was always unreachable,
    but the not-tight-enough types did not make this fact visible.
    (Due to this effect, this diff removes more lines than it adds.)
2021-08-17 19:23:55 +10:00
Zoltan Somogyi
80798bff2b Put related code together. 2021-08-17 12:09:43 +10:00
Zoltan Somogyi
b3748a367b Separate self-FIM languages by module section.
compiler/prog_item.m:
    Split the parse_tree_module_src that holds the languages for which
    the module needs a self-foreign-import into two, depending on the
    section (interface or implementation) into which the self-FIM should go.

compiler/convert_parse_tree.m:
    When computing the self-FIM languages, put each one into its section.

compiler/comp_unit_interface.m:
    Don't compute the interface self-FIMs, since they are now available
    in the parse_tree_module_src.

    Document why we *do* compute the implementation self-FIMs
    for the interface file we are constructing.

compiler/check_raw_comp_unit.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:
    Conform to the changes above.
2021-08-17 12:01:52 +10:00