Commit Graph

59 Commits

Author SHA1 Message Date
Zoltan Somogyi
b6178ef723 Delete prog_out.m, moving its code to other modules.
compiler/parse_tree_out_cons_id.m:
    Move the predicates and functions in prog_out.m that deal with cons_ids
    to this module.

compiler/parse_tree_out_sym_name.m:
    Move the predicates and functions in prog_out.m that deal with sym_names
    and similar entities to this module.

compiler/parse_tree_out_type.m:
    Move the predicates and functions in prog_out.m that deal with types
    to this module.

compiler/parse_tree_out_misc.m:
    Move the predicates and functions in prog_out.m that deal with simple
    types to this module.

    Delete mercury_output_det and mercury_format_det, replacing all their
    uses with calls to mercury_det_to_string.

compiler/prog_out.m:
    Delete this module.

compiler/parse_tree.m:
    Delete prog_out from the parse_tree package.

compiler/Mercury.options:
compiler/notes/compiler_design.html:
    Delete references to prog_out.m.

compiler/*.m:
    Update imports and any explicit module qualifications to account
    for the moved code.

tools/filter_sort_imports:
    Automatically filter out any repeated imports. This can help with
    changes like this that redistribute the contents of one module to other
    modules. In this case, after a global replacement of prog_out's import
    with the import of parse_tree_out_misc, this updated script could
    remove this changed import from modules that already imported
    parse_tree_out_misc.
2023-04-09 16:23:13 +10: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
0f75764e41 Pinpoint more actual/expected type differences.
compiler/typecheck_errors.m:
    When there is a difference between actual and expected types
    in predicate calls, do not just print the actual and expected types,
    but if possible, point out the specific part(s) that cause the difference.
    For example, report differences in arities, purity, determinism etc.
    Also point out cases where the code is trying to specify the value
    of an existentially quantified type variable.

    When higher order types are printed as part of an error message,
    strip any builtin qualifiers not just from the names of types,
    but also from the names of the argument modes.

    Start each part of an actual/expected pair at the same level of
    indentation.

compiler/error_util.m:
    Add a way to print out small integers as english names (one, two etc)
    instead as numerals (1, 2 etc).

    Add a way to print out purity descriptions.

    Add a component, treat_next_as_first, that specifies that the next
    format_component should be treated as the first part of a sentence
    with respect to (de)capitalization by lower_next_if_not_first,
    even if it is preceded by other format_components in a message.
    This is useful in cases where the code that generates part of an
    error message does not know whether that part will end up at the start
    of the sentence, as the

        <preceding sentence, ending in a period>
        treat_next_as_first <context> lower_next_if_not_first, Words ...

    sequence will keep Words capitalized if <context> is empty,
    but will decapitalize it if <context> is not empty.

    Rename {qual,unqual}_pf_sym_name_orig_arity as
    {qual,unqual}_pf_sym_name_pred_form_arity, since this is clearer.

compiler/prog_out.m:
    Apply the same s/orig_arity/pred_form_arity/ rename to some functions.

compiler/module_qual.qual_errors.m:
    Fix an unrelated problem I came across while working on the changes above:
    stray spaces at the ends of words(...) format_components, which screwed up
    some error messages.

    Simplify the description of classes and predicates by using facilities
    in error_util.m that did not yet exist when this code was converted
    to use error_util.m.

compiler/prog_type.m:
    When stripping builtin qualifiers from types, strip them from the
    modes stored in the higher_order inst into of higher order types as well,
    for the same reason: to eliminate clutter in error messages.

    Make the strip_kind_annotation function return a value that
    shows in its type that the result will *not* be a kinded_type.
    THIS IS THE FIRST USE OF SUBTYPES IN THE COMPILER.

compiler/type_assign.m:
    Fix a long-standing documentation problem.

    The type_assign type has long had a field named ta_external_type_params,
    whose type was external_type_params, which was defined as equivalent
    to a list of type variables. The name does not say what kinds of type
    variables it contains, but the only two places that add type vars to
    this field add type vars that are existentially quantified, either
    by a predicate, or a cons_id. This diff therefore renames this field
    to ta_existq_tvars, and changes its type to be just plain list(tvar).
    (The external_type_params type has no documentation, so it may be used
    to store different kinds of type variables in different places,
    some of which may *not* be existentially quantified. Using the same name
    for different purposes may be confusing.)

compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/check_promise.m:
compiler/check_typeclass.m:
compiler/convert_parse_tree.m:
compiler/hhf.m:
compiler/hlds_desc.m:
compiler/hlds_out_util.m:
compiler/make_hlds_error.m:
compiler/make_hlds_warn.m:
compiler/mark_tail_calls.m:
compiler/module_qual.qualify_items.m:
compiler/post_typecheck.m:
compiler/pred_table.m:
compiler/typecheck.m:
compiler/typecheck_debug.m:
compiler/typeclasses.m:
    Conform to the changes above.

tests/invalid/fbnf.{m,err_exp}:
    The motivating test case for this diff, slightly modified
    from the code posted to m-users.

tests/invalid/type_diff.{m,err_exp}:
    A test case to test the parts of the new code in typecheck_errors.m
    that are not covered by other tests.

tests/invalid/Mmakefile:
    Enable the new test cases.

tests/invalid/ext_type_bug.{m,err_exp}:
    Extend this test case to test the pinpointing of errors that try to bind
    existentially quantified type variables, at both the top level
    and nested inside other type constructors.

tests/invalid/bug197.err_exp:
tests/invalid/higher_order_mode_mismatch.err_exp:
tests/invalid_purity/impure_pred_t1_fixed.err_exp:
tests/invalid_purity/impure_pred_t2.err_exp:
tests/invalid_purity/purity_nonsense.err_exp:
tests/invalid_purity/purity_nonsense2.err_exp:
    Expect pinpointed type differences in these error messages.

tests/invalid/abstract_eqv.err_exp:
tests/invalid/integral_constant_no_suffix.err_exp:
tests/invalid/method_impl.err_exp:
tests/invalid/mixed_up_streams.err_exp:
tests/invalid/try_bad_params.err_exp:
tests/invalid/type_error_ambiguous.err_exp:
tests/invalid/types2.err_exp:
tests/invalid_nodepend/errors2.err_exp:
    Expected updated formatting in these error messages.
2022-10-11 22:59:03 +11:00
Zoltan Somogyi
3e2cde2c33 Don't abort compilation for unresolved overloading.
compiler/pred_table.m:
    When we find more than one match for a predicate or function signature,
    we used to generate an error message, print it, and then abort
    compilation. Fix this by returning the error message to be handled
    by our callers.

    The compiler now has to pick one of the matches to continue with.
    The compiler's pick (the first match) may not be the match intended
    by the programmer, and it is possible that the compiler will later generate
    some error messages that would not happen if we picked the match
    intended by the programmer. We therefore warn the programmer about
    this possibility.

compiler/purity.m:
compiler/resolve_unify_functor.m:
    Include the error messages now returned by pred_table.m among
    all the other error messages generated by the purity pass,
    which, amongst other things, does the last part of the job
    of the typechecker.

compiler/intermod.m:
    Ignore the errors caused by unresolved overloading when generating
    .opt files. They will be reported when the compiler tries to generate
    target language code.

library/list.m:
    Add three related utility predicates that we discussed earlier,
    each of which was needed by one version or another of the code
    for constructing the error message in pred_table.m.

NEWS:
    Announce the additions to list.m.

tests/invalid_submodules/unresolved_overloading.{m,err_exp}:
    Expect the updated error message, and the *absence* of a compiler abort.
2022-08-21 15:28:55 +10:00
Zoltan Somogyi
ea4f95a7ed Use var_tables in lco.m, and when dumping goals.
Since this is the first converted module that dumps out goals when
debugging trace flags are enabled, this required generalizing the code
that does that, to take either varsets or var_tables as a means of
specifying the names of variables. We do this via a new type,
var_name_source, which contains either a varset or a var_table.

Almost all of this diff is there to implement this generalization.
A large part of it affects code in the parse_tree package that we use
to write out the parts of HLDS goals that are defined by types defined
in that package. Since we want to avoid making any part of the parse_tree
package dependent on the hlds package, this required defining the
var_name_source type in the parse_tree package, which in turn requires
var_table.m to be in that same package.

compiler/lco.m:
    Convert this module to use var_tables instead of varsets and vartypes.

compiler/var_table.m:
    Move this module from the hlds package to the parse_tree package.

    To make this, possible, move the parts that required access to the HLDS
    to hlds_pred.m, from where it was usually invoked.

    Export some utility predicates to allow the moved code to work
    in hlds_pred.m without access to the actual definition of the
    var_table type.

    Define the var_name_source type.

    Add some utility functions for use by code writing out variable names.

compiler/hlds_pred.m:
    Add the code moved from var_table.m.

compiler/vartypes.m:
    Move this module from the hlds package to the parse_tree package,
    for symmetry with var_table.m. It did not depend on being in hlds
    in any way.

compiler/hlds.m:
compiler/parse_tree.m:
    Move vartypes.m and var_table.m from the hlds package
    to the parse_tree package.

compiler/hlds_out_goal.m:
    Change all the predicates in this module to take a var_name_source
    instead of a prog_varset.

    Fix some comments.

compiler/hlds_out_util.m:
    Change some of the predicates in this module (those called from
    hlds_out_goal.m) to take a var_name_source instead of a prog_varset.

compiler/parse_tree_out_term.m:
    Provide variants of some existing predicates and functions that take
    var_name_sources instead of varsets. The code of the copies
    duplicates the logic of the originals, though I hope that this
    duplication can be done away with at the end of the transition.
    (The best solution would be to use a typeclass with methods
    that convert vars to their names, but we would want to ensure
    that the compiler can specialize all the affected predicates
    and functions to the two instances of this typeclass, which is
    something that we cannot do yet. In the meantime, the lack of
    any generalization in the old versions preserves their performance.)

tools/sort_imports:
tools/filter_sort_imports:
    A new tool that automatically sorts any occurrences of consecutive
    ":- import_module" declarations in the named files. The sorting is done
    in filter_sort_imports; sort_imports loops over the named files.

    After automatically replacing all occurrences of hlds.{vartypes,var_table}
    in import_module declarations with their parse_tree versions, the updated
    import_module declarations were usually out of order with respect to
    their neighbours. I used this script to fix that, and some earlier
    out-of-order imports.

compiler/accumulator.m:
compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_heap_ops.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_trail_ops.m:
compiler/analysis.m:
compiler/arg_info.m:
compiler/build_mode_constraints.m:
compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/check_promise.m:
compiler/closure_analysis.m:
compiler/closure_gen.m:
compiler/code_info.m:
compiler/code_loc_dep.m:
compiler/common.m:
compiler/compile_target_code.m:
compiler/complexity.m:
compiler/const_prop.m:
compiler/constraint.m:
compiler/continuation_info.m:
compiler/convert_parse_tree.m:
compiler/coverage_profiling.m:
compiler/cse_detection.m:
compiler/ctgc.datastruct.m:
compiler/ctgc.util.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/direct_arg_in_out.m:
compiler/disj_gen.m:
compiler/distance_granularity.m:
compiler/equiv_type_hlds.m:
compiler/exception_analysis.m:
compiler/file_names.m:
compiler/float_regs.m:
compiler/follow_vars.m:
compiler/format_call.m:
compiler/generate_dep_d_files.m:
compiler/get_dependencies.m:
compiler/goal_expr_to_goal.m:
compiler/goal_mode.m:
compiler/goal_path.m:
compiler/goal_store.m:
compiler/goal_util.m:
compiler/granularity.m:
compiler/hhf.m:
compiler/higher_order.m:
compiler/hlds_clauses.m:
compiler/hlds_code_util.m:
compiler/hlds_error_util.m:
compiler/hlds_goal.m:
compiler/hlds_llds.m:
compiler/hlds_out_pred.m:
compiler/hlds_rtti.m:
compiler/hlds_statistics.m:
compiler/inlining.m:
compiler/inst_check.m:
compiler/inst_test.m:
compiler/inst_user.m:
compiler/instance_method_clauses.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/intermod_analysis.m:
compiler/interval.m:
compiler/introduce_exists_casts.m:
compiler/introduce_parallelism.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/llds.m:
compiler/llds_out_data.m:
compiler/llds_out_file.m:
compiler/llds_out_util.m:
compiler/lookup_switch.m:
compiler/loop_inv.m:
compiler/make.module_target.m:
compiler/make.util.m:
compiler/make_goal.m:
compiler/make_hlds_separate_items.m:
compiler/make_hlds_types.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/middle_rec.m:
compiler/ml_accurate_gc.m:
compiler/ml_args_util.m:
compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_commit_gen.m:
compiler/ml_disj_gen.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_gen_info.m:
compiler/ml_lookup_switch.m:
compiler/ml_proc_gen.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/ml_unify_gen.m:
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_test.m:
compiler/ml_unify_gen_util.m:
compiler/mlds_to_c_data.m:
compiler/mlds_to_c_func.m:
compiler/mlds_to_c_global.m:
compiler/mlds_to_cs_class.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_data.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_stmt.m:
compiler/mlds_to_java_type.m:
compiler/mmc_analysis.m:
compiler/mode_comparison.m:
compiler/mode_constraints.m:
compiler/mode_debug.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/mode_ordering.m:
compiler/modecheck_call.m:
compiler/modecheck_coerce.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/module_cmds.m:
compiler/old_type_constraints.m:
compiler/opt_debug.m:
compiler/optimize.m:
compiler/options_file.m:
compiler/ordering_mode_constraints.m:
compiler/par_loop_control.m:
compiler/parse_item.m:
compiler/parse_string_format.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_to_term.m:
compiler/parse_util.m:
compiler/pd_debug.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/peephole.m:
compiler/polymorphism.m:
compiler/polymorphism_info.m:
compiler/polymorphism_lambda.m:
compiler/polymorphism_type_class_info.m:
compiler/polymorphism_type_info.m:
compiler/post_typecheck.m:
compiler/pragma_c_gen.m:
compiler/pred_name.m:
compiler/pred_table.m:
compiler/prog_item.m:
compiler/prog_rep.m:
compiler/prop_mode_constraints.m:
compiler/purity.m:
compiler/push_goals_together.m:
compiler/qual_info.m:
compiler/quantification.m:
compiler/rbmm.execution_path.m:
compiler/rbmm.m:
compiler/rbmm.points_to_analysis.m:
compiler/rbmm.points_to_graph.m:
compiler/rbmm.points_to_info.m:
compiler/rbmm.region_resurrection_renaming.m:
compiler/rbmm.region_transformation.m:
compiler/recompilation.used_file.m:
compiler/recompilation.version.m:
compiler/recompute_instmap_deltas.m:
compiler/resolve_unify_functor.m:
compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/saved_vars.m:
compiler/set_of_var.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_conj.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_ite.m:
compiler/simplify_goal_scope.m:
compiler/simplify_goal_switch.m:
compiler/simplify_goal_unify.m:
compiler/simplify_info.m:
compiler/simplify_proc.m:
compiler/size_prof.m:
compiler/smm_common.m:
compiler/ssdebug.m:
compiler/stack_alloc.m:
compiler/stack_layout.m:
compiler/stack_opt.m:
compiler/stm_expand.m:
compiler/store_alloc.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.domain.m:
compiler/structure_reuse.indirect.m:
compiler/structure_reuse.lbu.m:
compiler/structure_reuse.lfu.m:
compiler/structure_sharing.analysis.m:
compiler/structure_sharing.domain.m:
compiler/superhomogeneous.m:
compiler/switch_detection.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/tabling_analysis.m:
compiler/term_constr_build.m:
compiler/term_constr_data.m:
compiler/term_constr_initial.m:
compiler/term_constr_main.m:
compiler/term_constr_main_types.m:
compiler/term_constr_util.m:
compiler/term_pass1.m:
compiler/term_traversal.m:
compiler/term_util.m:
compiler/trace_gen.m:
compiler/trailing_analysis.m:
compiler/transform_llds.m:
compiler/try_expand.m:
compiler/tupling.m:
compiler/type_assign.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/typecheck_debug.m:
compiler/typecheck_errors.m:
compiler/typecheck_info.m:
compiler/unify_gen_construct.m:
compiler/unify_gen_deconstruct.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unneeded_code.m:
compiler/untupling.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/var_locn.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.
2022-04-18 02:00:38 +10:00
Zoltan Somogyi
e657a091e4 Encode the arity kind in the type in pred lookups.
compiler/pred_table.m:
    Some predicates in this module have traditionally taken an arity argument
    that *included* function result arguments, while others took an arity
    arguments that *excluded* function result arguments. While the difference
    was documented, it was not enforced in the types. Change this by
    switching the two kinds of arities to pred_form_arities and user_arities
    respectively.

    Change the internal data structures to specify in the types
    that they operate on user_arities.

    Change the operation of lookup_builtin_pred_proc_id as part of the
    change to goal_util.m (described below).

compiler/goal_util.m:
    When looking up the pred_info of a builtin, callers used to pass to the
    predicates that did that (generate_simple_call and generate_foreign_proc)
    a list of the arguments of the call without specifying which arguments
    were type_info/typeclass_info arguments added by polymorphism.
    This meant that the length of the argument list was *not* necessarily
    the called predicate or function's pred form arity, but could exceed it
    by the number of arguments added by polymorphism. The only reason this
    worked was because the lookup_builtin_pred_proc_id procedure they used
    to look up the named predicate in the pred table compensated for it

    - by doing a lookup on the original arity plus one, if the lookup on the
      original arity failed, and

    - in all the calls to generate_simple_call and generate_foreign_proc,
      the number of arguments added by polymorphism was either zero or one.

    Nevertheless, the system was fragile. It could have broken either

    - because when looking up the arity that included a type_info argument,
      (e.g. one typeinfo and two original args) the lookup could have found
      a false match (a predicate with the same name with three original args),

    - or because a new call to a new builtin could need to specify two or more
      arguments added by polymorphism.

    Fix this issue by

    - requiring calls to generate_simple_call and generate_foreign_proc
      to pass the arguments added by polymorphism separately, so the number
      of the original arguments specifies the predicate's pred_form_arity, and

    - deleting the code in lookup_builtin_pred_proc_id that tried to
      compensate for the presence of an "unannounced" typeinfo argument.

compiler/analysis.m:
    Change the type of a slot in a structure from arity to pred_form_arity,
    since that seems to have been how that slot was used.

compiler/recompilation.check.m:
compiler/recompilation.m:
compiler/recompilation.usage.m:
    Conform to the changes above, but only in a minimal fashion,
    because I don't *know* whether the values of type 'arity' passed around
    in the recompilation modules represent user arities or pred form arities.
    Record my guesses, but also record the fact that they are *only* guesses.
    Mark suspect code with "XXX ARITY BUG".

compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/stm_expand.m:
compiler/table_gen.m:
    Conform to the changes above.

    Rationalize the argument order of the internal module-specific predicates
    they use to generate calls to builtins.

compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/analysis.file.m:
compiler/check_typeclass.m:
compiler/complexity.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/dep_par_conj.m:
compiler/direct_arg_in_out.m:
compiler/distance_granularity.m:
compiler/format_call.m:
compiler/goal_util.m:
compiler/granularity.m:
compiler/higher_order.m:
compiler/hlds_module.m:
compiler/intermod.m:
compiler/lco.m:
compiler/make_hlds_passes.m:
compiler/mmc_analysis.m:
compiler/modecheck_goal.m:
compiler/par_loop_control.m:
compiler/polymorphism_type_class_info.m:
compiler/polymorphism_type_info.m:
compiler/pred_table.m:
compiler/purity.m:
compiler/rbmm.region_transformation.m:
compiler/resolve_unify_functor.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_scope.m:
compiler/simplify_goal_unify.m:
compiler/size_prof.m:
compiler/special_pred.m:
compiler/ssdebug.m:
compiler/try_expand.m:
compiler/typecheck.m:
compiler/unify_proc.m:
    Conform to the changes above.
2022-02-22 23:59:20 +11:00
Zoltan Somogyi
0332446462 Introduce introduced_call_table.m.
compiler/introduced_call_table.m:
    Move the tables of predicates that compiler passes may introduce
    calls to here from direct_arg_in_out.m, simplify_proc.m and try_expand.m.

    Start checking some of the arities of introduced predicates
    (those I am sure of).

compiler/hlds.m:
    Add the new module to the hlds package.

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

compiler/dead_proc_elim.m:
    Invoke the one exported predicate of the new module, instead
    of three predicates exported by the three source modules.

    Clarify some related code.

    Delete code that became unneeded when we stopped supporting
    automatic initialization of solver type variables.

compiler/direct_arg_in_out.m:
compiler/simplify_proc.m:
compiler/try_expand.m:
    Delete the code moved to

compiler/pred_table.m:
    Clarify some code used by dead_proc_elim.m.
2022-02-14 11:35:07 +11:00
Zoltan Somogyi
5cada10369 Rename pred_table to pred_id_table.
compiler/pred_table.m:
    As above. This addresses half of an old XXX, which is that the two types
    defined in this module, predicate_table and pred_table (as it was then)
    should have names that (a) say what they do, and (b) are distinct.
    Addressing the other half requires a more descriptive but not-too-long
    name to replace "predicate_table".

    Rename the predicates that operate on the type to follow the name change.

    Add a distinguishing prefix to the names of the fields of the
    predicate_table type.

compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_special_pred.m:
compiler/arg_info.m:
compiler/bytecode_gen.m:
compiler/clause_to_proc.m:
compiler/closure_gen.m:
compiler/cse_detection.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/default_func_mode.m:
compiler/det_analysis.m:
compiler/det_util.m:
compiler/direct_arg_in_out.m:
compiler/distance_granularity.m:
compiler/export.m:
compiler/float_regs.m:
compiler/goal_mode.m:
compiler/granularity.m:
compiler/hlds_defns.m:
compiler/hlds_error_util.m:
compiler/hlds_module.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_module.m:
compiler/hlds_out_util.m:
compiler/hlds_pred.m:
compiler/hlds_statistics.m:
compiler/implementation_defined_literals.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/introduce_exists_casts.m:
compiler/introduce_parallelism.m:
compiler/lambda.m:
compiler/lco.m:
compiler/make_hlds_passes.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile_llds_back_end.m:
compiler/ml_proc_gen.m:
compiler/mode_info.m:
compiler/modecheck_call.m:
compiler/modes.m:
compiler/oisu_check.m:
compiler/old_type_constraints.m:
compiler/passes_aux.m:
compiler/polymorphism.m:
compiler/polymorphism_post_copy.m:
compiler/post_typecheck.m:
compiler/pre_typecheck.m:
compiler/proc_gen.m:
compiler/proc_requests.m:
compiler/simplify_proc.m:
compiler/stm_expand.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.m:
compiler/structure_sharing.analysis.m:
compiler/switch_detection.m:
compiler/table_gen.m:
compiler/term_constr_build.m:
compiler/term_constr_initial.m:
compiler/term_constr_util.m:
compiler/term_util.m:
compiler/termination.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
compiler/typecheck_info.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the change in pred_table.m.

    Refer to values of the renamed type using a consistent naming scheme.

    When the affected code repeats the body of existing helper predicates
    for lookup up a pred_info or proc_info, or updating a proc_info
    inside a pred_info, or updating a pred_info inside a module_info,
    call the helper predicate instead. This makes code shorter and less
    cluttered, and the use of the helper predicates for updates automatically
    ensures that we don't accidentally update a stale version of the relevant
    table. (This has sometimes been a problem in the past.)

    In a few places, carve a new predicate for processing one element
    of a list out of an existing predicate for processing all list elements.
2022-02-03 10:01:21 +11:00
Zoltan Somogyi
243491523d Stop counting errors in module_infos.
Over time, we have almost completely switched over to using error_specs,
using their severity (if not yet printed out) and their effect on the
exit status (if already printed out) to represent the presence of errors,
leaving only a few places that either updated or paid attention to the
num_error field in the module_info. This diff completes that process.

compiler/hlds_module.m:
    Delete the num_errors field in the module_info, and the predicates
    that operate on it.

compiler/hlds_error_util.m:
    Delete module_info arguments whose only purpose was to update the
    now-delete field.

compiler/error_util.m:
    Delete the old write_error_spec predicates that updated a count of warnings
    and a count of errors.

    Rename the write_error_spec_ignore predicates, which ignored those counts,
    by deleting the "_ignore" from their names. This makes them take the
    place of the deleted predicates.

compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/compile_target_code.m:
compiler/cse_detection.m:
compiler/find_module.m:
compiler/generate_dep_d_files.m:
compiler/handle_options.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.top_level.m:
compiler/make.track_flags.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/mercury_compile_mlds_back_end.m:
compiler/mode_info.m:
compiler/modes.m:
compiler/pd_util.m:
compiler/pred_table.m:
compiler/recompilation.check.m:
compiler/typecheck.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.
2022-01-15 16:33:38 +11: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
d02751a38b Add name_arity as a format_component.
compiler/error_util.m:
    As above.

compiler/prog_data.m:
    To make this possible, move the existing definitions of name_arity here.

compiler/hlds_defns.m:
compiler/pred_table.m:
    Delete two the old copies of that definition.
2021-06-27 20:39:50 +10:00
Zoltan Somogyi
bd6e6fca8c Diagnose names with non-full qualifications.
compiler/typecheck_errors.m:
    When the program refers to a predicate, function or data constructor
    from a module with only a use_module declaration, it must do so
    using its fully qualified name. If it refers to it with an unqualified
    or only partially qualified name, the typechecker won't find it,
    because the predicate_table and the cons_table record non-fully-qualified
    names only for the entities imported with import_module declarations.

    When generating error_specs for such errors, look for matches with
    the relevant name among the fully-qualified entries in the predicate
    and cons tables. If we find some, add a sentence to the error message
    about the modules defining such names being imported with use_module,
    not import_module.

compiler/hlds_cons.m:
    Add a way to look up the definitions of all the constructors with
    a given name.

compiler/pred_table.m:
    Add a way to look up the definitions of all the predicates or functions
    with a given name.

mdbcomp/sym_name.m:
    Add some functionality for use by typecheck_errors.m.

tests/invalid/type_error_use_module.m:
tests/invalid/type_error_use_module_2.m:
tests/invalid/type_error_use_module.err_exp:
    A test case for the new functionality.

tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
    Enable the new test case. Sort the list of multimodule tests.

tests/invalid/errors2.err_exp:
    Expect the new addendum to an existing error message.
2021-04-26 23:47:03 +10:00
Zoltan Somogyi
60df32dbc4 Put related predicates next to each other. 2021-04-26 06:31:09 +10:00
Zoltan Somogyi
272e547bec Specify output streams in some places.
compiler/check_typeclass.m:
compiler/lp_rational.m:
compiler/matching.m:
compiler/polyhedron.m:
compiler/pred_table.m:
compiler/proc_gen.m:
compiler/stack_opt.m:
compiler/term_constr_build.m:
compiler/term_constr_data.m:
compiler/term_constr_fixpoint.m:
compiler/term_constr_pass2.m:
compiler/term_constr_util.m:
compiler/unused_imports.m:
    As above.

    Use io.format to replace several calls to io.* where possible.

    Give some predicates more specific names to avoid ambiguity.

    Reorder the arguments of some predicates to allow higher order programming
    in future.

    Delete some functions that duplicate the functionality of predicates.

    Rename VarSet to Varset in several places.

    Put all debug predicates in a single group in each module.

compiler/Mercury.options:
    Do not specify --no-warn-implicit-stream-calls for the modules above.
2021-03-25 03:48:01 +11:00
Zoltan Somogyi
63dabcfcf8 Fix filling in partial terms that use direct_arg tags.
This fix uses the approach discussed on m-dev 2020 nov 16/17 for fixing
github issue #72, whose core problem is a need for information flow
back to a the caller from a callee when the callee fills in the
argument of a function symbol whose representation is a direct_arg tag.
In most cases when the callee fills in the value of an argument,
the caller can see it because the argument is in a word on the heap,
but when the function symbol uses a direct_arg tag, that is not the case.

compiler/direct_arg_in_out.m:
    A new module that implements the transformation proposed on m-dev.
    It creates a fresh clone variable every time an argument of a direct_arg
    tag function symbol is (or may be) updated. This can happen several
    times if a type has more than one function symbol with a direct_arg tag.
    Since the affected variable can be bound to only one function symbol
    at the start, its argument can be filled in only once, but the
    compiler cannot know in advance what function symbol the variable
    contains, and therefore which of the possibly several fill-in sites
    (which fill in the arguments of different function symbols) executed
    in sequence will actually update the variable.

    The transformation ensures that once a variable is cloned, it is
    never referred to again. It also ensures that in a branched control
    structure (if-then-else, disjunction or switch), all branches will use
    the *same* variable to represent the latest version of each cloned
    variable at the end, so that following code has a consistent view
    regardless of through which branch execution has reached it.

    There are three situations that the transformation cannot and does not
    handle.

    1. Situations in which the mode of an argument is either an inst variable,
       or an abstract inst. In either case, the pass cannot know whether
       it should apply its transformation to the argument.

    2. Situations where a procedure that has such an argument is
       exported to C code as a function. In that case, the C signature
       of the function we would generate would be different from what
       the user would normally expect. We could modify the documentation
       of the export pragma, but I don't think there much point due to
       lack of demand. (The problem cannot arise when targeting any language
       other than C, because we use direct_arg tags only with the low level
       data representation, which we only use for C.)

    3. Situations where a procedure that has such an argument is defined
       by foreign_proc. Again, dealing with the problem would require
       nontrivial changes to the documented interface between code in
       foreign_procs and the surrounding Mercury code, and I see no demand
       for code that could benefit from that.

    In these cases, this module generates error messages.

compiler/transform_hlds.m:
    Include the new module in the transform_hlds package.

    Delete unnecessary module qualification on some existing inclusions.
    Put some existing inclusions into a more meaningful order.

compiler/notes/compiler_design.html:
    Document the new pass. Fix some nearby prose.

compiler/lambda.m:
compiler/simplify_proc.m:
    Use a predicate exported by direct_arg_in_out.m to test, for each
    procedure, whether the procedure has any argument positions that are
    subject to the problem that direct_arg_in_out.m addresses.
    simplify_proc.m does this for all procedures it processes;
    lambda.m does this for all the procedures it creates from
    lambda expressions.

    Give a predicate in simplify_proc.m a better name.

    Sort a list of predicate names.

compiler/hlds_module.m:
    Add a field to the module_info that simplify_proc.m and lambda.m
    can use to tell direct_arg_in_out.m what work (if any) it needs to do.

compiler/mercury_compile_middle_passes.m:
    Invoke direct_arg_in_out.m if the new field in the HLDS indicates
    that it has some work to do. (In the vast majority of compiler invocations,
    it won't have any.)

compiler/hlds_pred.m:
    The new code in direct_arg_in_out.m creates a clone of each procedure
    affected by the problem, before deleting the originals (to make sure that
    no references to the unfixed versions of now-fixed procedures remain.)
    Make it possible to create exact clones of both predicates and procedures
    by adding two pairs of predicates, {pred,proc}_prepare_to_clone and
    {pred,proc}_create.

    Add the direct_arg_in_out transformation as a possible source
    of transformed predicates.

library/private_builtin.m:
    Add a new builtin operation, partial_inst_copy, that the new module
    generates calls to.

configure.ac:
    Require the installed compiler to recognize partial_inst_copy
    as a no_type_info builtin.

compiler/builtin_ops.m:
    Recognize the new builtin. (This was committed before the rest; the diff
    to private_builtin.m can be done only once the change to builtin_ops.m
    is part of the installed compiler.)

compiler/options.m:
    Add a way to test whether the builtin_ops.m in the installed compiler
    recognizes the new builtin.

compiler/dead_proc_elim.m:
    Do not delete the new primitive before direct_arg_in_out.m has had
    a chance to generate calls to it.

    Add an XXX.

compiler/error_util.m:
    Recognize the new module as a source of error messages.

compiler/pred_table.m:
    Add a pair of utility predicates to be used when looking up
    builtin predicates, for which the compiler writer knows that
    there should be exactly one match. These are used in direct_arg_in_out.m.

compiler/simplify_goal_call.m:
    Replace some existing code with calls to the new predicates
    in pred_table.m.

compiler/hlds_goal.m:
    Add modes to rename_vars_in_goal_expr that express the fact
    that when an atomic goal_expr has some variables renamed inside it,
    it does not suddenly become some *other* kind of goal_expr.
    New code in direct_arg_in_out.m relies on this.

compiler/hlds_out_goal.m:
    When the HLDS we are dumping out is malformed because it contains
    calls to predicates that have been deleted, the compiler used to abort
    at such calls. (I ran into this while debugging direct_arg_in_out.m.)

    Fix this. When such calls are encountered, we now print out as much
    information we can about the call, and prefix the call with an
    unmistakable prefix to draw attention to the problem.

compiler/inst_util.m:
    Fix a bug that prevented direct_arg_in_out.m from even being invoked
    on some test code for it.

    The bug was in code that we use to unify a headvar's initial inst
    with its final inst. When the initial inst was a non-ground bound_inst
    such as the ones used in tests/hard_coded/gh72.m, and the final inst
    was simply "ground", this code quite properly returned a bound_inst
    (which, unlike ground, can show the exact set of function symbols
    that the headvar could be bound to). The problem was that it
    reused the original bound_inst's test results, including the one
    that said the final inst is NOT ground, which of course is wrong
    for any inst unified with ground. Fix two instances of this bug.

compiler/modes.m:
    Make some of the code I had to traverse to find the bug in inst_util.m
    easier to read and understand.

    Replace some uses of booleans with bespoke enum types.

    Change the argument lists of some predicates to put related arguments
    next to each other.

    Give some variables more descriptive names.

compiler/layout_out.m:
    Conform to the change in hlds_pred.m.

compiler/var_locn.m:
    Fix a code generation bug. When filling-in the value of the argument
    of a function symbol represented by a direct_arg tag, the code we
    generated for it worked only if the direct_arg tag used 0
    as its ptag value. In the test cases we initially used for
    github issue 72, that was the case, but the new tests/hard_coded/gh72.m
    has direct_tag args that use other ptag values as well.

    Document the reason why the updated code works.

compiler/term_constr_initial.m:
    Add the new primitive predicate added to private_builtin.m,
    partial_inst_copy, to a table of builtins that do not take type_infos,
    even though their signatures contain type variables.

    Fix a bunch of old bugs: most other such primitives were not listed
    either.

mdbcomp/program_representation.m:
    Add partial_inst_copy to the master list of builtins that do not take
    type_infos even though their signatures contain type variables. (Done
    by an earlier commit.)

    Document the fact that any updates here require updates to
    term_constr_initial.m.

library/multi_map.m:
    We have long had multi_map.add and multi_map.set as synonyms,
    but we only had multi_map.reverse_set. Add multi_map.reverse_add
    as a synonym for it.

    Define the "set" versions in terms of the "add" versions,
    instead of vice versa.

NEWS:
    Document the new predicates in multi_map.m.

tests/hard_coded/gh72a.m:
    Fix typo.

tests/hard_coded/gh72.{m,exp}:
    A new, much more comprehensive test case than gh72a.m.
    This one tries to tickle github issue 72 in as many forms of code
    as I can think of.

tests/invalid/gh72_errors.{m,err_exp}:
    A test case for testing the generation of error messages for
    two out of the three kinds of situations that direct_arg_in_out.m
    cannot handle. (Proposals for how to test the third category welcome.)

tests/hard_coded/Mmakefile:
tests/invalid/Mmakefile:
    Enable the two new test cases, as well as two old ones, gh72[ab].m,
    that previously we didn't pass.

tests/invalid/Mercury.option:
    Do not compile gh72_error.m with --errorcheck-only, since its errors
    are reported by a pass that --errorcheck-only does not invoke.
2021-01-13 05:35:40 +11:00
Zoltan Somogyi
206cc8503b Revisit valid vs all proc_ids in a pred_info.
compiler/hlds_pred.m:
    We have several predicates that retrieve selected subsets of all
    the proc_ids in a pred_info. For those that retrieve the proc_ids
    of only valid procedures, put "valid" into their names.

    Fix a bug in the implementation of pred_info_all_non_imported_proc_ids,
    which, despite its name, used to return the proc_ids of only the
    *valid* non-imported procedures.

    The distinction between all procedures and only valid procedures
    only really matters between mode analysis and the end of the front end.
    A procedure is valid if it has no mode errors, so before mode analysis,
    all procedures are valid by default, and if any procedure has any
    mode errors, the compiler should terminate after the front end is done.

    However, the distinction matters for readability, so this diff changes
    things so that we get all proc_ids in code executed before mode analysis,
    and valid proc_ids after the front end, with calls handled on a case-by-
    case basis in between.

    The distinction also matters in the presence of errors. For example,
    we shouldn't tell users that a predicate has no modes when it has
    modes that all happen to be invalid, and we should dump procedures
    into .hlds_dump files even if they are invalid, since their invalidity
    may be exactly what the user is trying to debug.

compiler/*.m:
    Make the changes described above.

    In some places, fix bad programming style.
2020-07-30 19:46:14 +10:00
Zoltan Somogyi
dbd19430ef Use full error_specs instead of pieces.
compiler/compile_target_code.m:
compiler/fact_table.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/module_cmds.m:
compiler/pred_table.m:
    Replace calls to write_error_pieces* with code that constructs
    full error_specs and then writes them out.

compiler/error_util.m:
    Add a new phase, phase_fact_table_check, for the new code in fact_table.m.
2020-06-04 13:58:00 +10:00
Zoltan Somogyi
3a1ed2efcb Replace simple_call_id with pf_sym_name_arity.
compiler/prog_data.m:
    Delete the simple_call_id data type, since it is isomorphic
    to the pf_sym_name_arity type, which more clearly specifies
    what is stored inside it.

compiler/prog_out.m:
    Rename (all three versions of) simple_call_id_to_string to
    pf_sym_name_orig_arity_to_string, both to conform to the change
    in the input data type, and to emphasize that the resulting string
    will contain the *original* arity of functions (which does not include
    the return value), which is one less than the arity in the
    pf_sym_name_arity structure (which, in accordance with the
    convention inside the compiler that the arity is the length
    of the argument list, *does* include the return value).

    Delete the provision inside simple_call_id_to_string, now
    pf_sym_name_orig_arity_to_string, for special handling of the names
    of the predicates we use to implement promises, because it seems that
    *none* of the call sites to any of the three versions of this function
    can actually pass to it the identity of such a predicate. These calls
    refer to a predicate or mode declaration item (which promise predicates
    do not have), to clause or foreign_proc items (which again, promise
    predicates cannot have) or calls to the predicate (promise predicates
    cannot be called).

    Delete the exported predicate simple_call_id_to_sym_name_arity.
    It was called from exactly one place, inside prog_out.m itself,
    and this diff inlines that call.

    Avoid unnecessary forwarding of work from prog_out.m to error_util.m.

    Delete (all three versions of) write_simple_call_id. The changes
    below replace all their (few) uses with calls to
    pf_sym_name_orig_arity_to_string.

compiler/error_util.m:
    Replace the simple_call() error piece with qual_pf_sym_name_orig_arity,
    and add a new version unqual_pf_sym_name_orig_arity. Their names
    explicitly say that they print the original arities of functions,
    also say whether they strip away any module qualification on the
    sym_name inside the pf_sym_name_arity. We prefer the unqual version
    in situations where the module qualifier is implicit, which usually means
    that it must be the same as the name of the module being compiled, because
    it reduces visual clutter for readers of error messages.

    Put {qual,unqual}_pf_sym_name_orig_arity next to their most closely
    related function symbols, {qual,unqual}_sym_name_arity, in the
    format_component type. (This yields a few inconsequential changes
    in the order of error_specs when sorted.)

compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/check_libgrades.m:
compiler/check_parse_tree_type_defns.m:
compiler/check_promise.m:
compiler/check_typeclass.m:
compiler/convert_parse_tree.m:
compiler/equiv_type.m:
compiler/goal_expr_to_goal.m:
compiler/hlds_data.m:
compiler/hlds_desc.m:
compiler/hlds_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/hlds_pred.m:
compiler/inst_util.m:
compiler/llds_out_instr.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make_hlds_error.m:
compiler/make_hlds_warn.m:
compiler/mark_tail_calls.m:
compiler/ml_unify_gen_construct.m:
compiler/mlds_to_c_stmt.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/modecheck_util.m:
compiler/module_qual.collect_mq_info.m:
compiler/module_qual.qualify_items.m:
compiler/parse_item.m:
compiler/parse_module.m:
compiler/parse_type_repn.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/pre_quantification.m:
compiler/pred_table.m:
compiler/prog_item.m:
compiler/recompilation.version.m:
compiler/term_constr_build.m:
compiler/termination.m:
compiler/type_ctor_info.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
compiler/typecheck_info.m:
compiler/unify_gen_construct.m:
compiler/unused_imports.m:
    Conform to the changes above. Where I am pretty sure that in an error
    message, the module qualifier of a name must be the current module,
    use unqual_pf_sym_name_orig_arity instead of qual_pf_sym_name_orig_arity.

    Add some sanity checks where they seem appropriate.

    Replace sequences of io.write_strings with uses of io.format where this
    yields clearer code. (This is why there were no remaining calls to
    write_simple_call_id.)

    Shorten some too-long lines.

    In add_pred.m, make the order of some predicate definitions match
    the order of the calls to them.

tests/invalid/ambiguous_method.err_exp:
tests/invalid/ambiguous_method_2.err_exp:
tests/invalid/bad_pred_arity.err_exp:
tests/invalid/bad_sv_unify_msg.err_exp:
tests/invalid/bigtest.err_exp:
tests/invalid/bug113.err_exp:
tests/invalid/bug197.err_exp:
tests/invalid/bug278.err_exp:
tests/invalid/bug410.err_exp:
tests/invalid/bug476.err_exp:
tests/invalid/bug487.err_exp:
tests/invalid/complex_constraint_err.err_exp:
tests/invalid/constrained_poly_insts.err_exp:
tests/invalid/errors.err_exp:
tests/invalid/errors1.err_exp:
tests/invalid/errors2.err_exp:
tests/invalid/exported_mode.err_exp:
tests/invalid/field_syntax_error.err_exp:
tests/invalid/foreign_singleton.err_exp:
tests/invalid/funcs_as_preds.err_exp:
tests/invalid/imported_mode.err_exp:
tests/invalid/invalid_binary_literal.err_exp:
tests/invalid/invalid_float_literal.err_exp:
tests/invalid/invalid_hex_literal.err_exp:
tests/invalid/invalid_octal_literal.err_exp:
tests/invalid/make_opt_error.err_exp:
tests/invalid/missing_det_decls.err_exp:
tests/invalid/multimode_syntax.err_exp:
tests/invalid/null_char.err_exp:
tests/invalid/occurs.err_exp:
tests/invalid/record_syntax_errors.err_exp:
tests/invalid/ref_to_implicit_pred.err_exp:
tests/invalid/require_tailrec_1.err_exp:
tests/invalid/require_tailrec_1.err_exp2:
tests/invalid/require_tailrec_2.err_exp:
tests/invalid/require_tailrec_2.err_exp2:
tests/invalid/require_tailrec_3.err_exp:
tests/invalid/require_tailrec_3.err_exp2:
tests/invalid/state_vars_test2.err_exp:
tests/invalid/state_vars_test3.err_exp:
tests/invalid/state_vars_test5.err_exp:
tests/invalid/type_inf_loop.err_exp:
tests/invalid/typeclass_constraint_extra_var.err_exp:
tests/invalid/typeclass_mode_2.err_exp:
tests/invalid/typeclass_test_12.err_exp:
tests/invalid/typeclass_test_2.err_exp:
tests/invalid/typeclass_test_9.err_exp:
tests/invalid/types.err_exp:
tests/invalid/types2.err_exp:
tests/invalid/unbound_type_vars.err_exp:
tests/invalid/with_type.err_exp:
tests/invalid_purity/purity_nonsense.err_exp:
tests/invalid_purity/purity_nonsense2.err_exp:
tests/warnings/double_underscore.exp:
tests/warnings/pragma_source_file.exp:
tests/warnings/singleton_test.exp:
tests/warnings/singleton_test.exp2:
tests/warnings/singleton_test.exp3:
tests/warnings/singleton_test.exp4:
tests/warnings/singleton_test_state_var.exp:
tests/warnings/warn_return.exp:
tests/warnings/warn_return.exp2:
tests/warnings/warn_return.exp3:
tests/warnings/warn_succ_ind.exp:
tests/warnings/warn_succ_ind.exp2:
tests/warnings/warn_succ_ind.exp3:
tests/warnings/warn_succ_ind.exp4:
    Update all these expected output files. Most changes are due to
    predicate and function names no longer being module qualified when
    the module qualification is obvious. A few changes are due to the
    change in the relative ordering of the function symbols of the
    format_component type.

    For singleton_test, warn_return and warn_succ_ind in warnings,
    the changes to the non-C .exp files were done by hand, so they
    may have the wrong white space.
2020-03-16 12:10:28 +11:00
Julien Fischer
ae4fe0ff86 Improve documentation consistency.
Use the non-hyphenated forms of "submodule" and "fully qualified" throughout.

doc/reference_manual.texi:
doc/user_guide.texi:
compiler/add_type.m:
compiler/deps_map.m:
compiler/module_imports.m:
compiler/pred_table.m:
compiler/process_util.m:
compiler/status.m:
   As above.
2020-01-14 19:10:58 +11:00
Zoltan Somogyi
ce65f6b2aa Fix more issues reported by --warn-inconsistent-pred-order-clauses.
compiler/assertion.m:
compiler/clause_to_proc.m:
compiler/compute_grade.m:
compiler/const_struct.m:
compiler/export.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_mode.m:
compiler/hlds_promise.m:
compiler/lambda.m:
compiler/lp_rational.m:
compiler/make_goal.m:
compiler/mercury_compile_llds_back_end.m:
compiler/ml_type_gen.m:
compiler/name_mangle.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_out_pragma.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/passes_aux.m:
compiler/polyhedron.m:
compiler/pred_table.m:
compiler/process_util.m:
compiler/prog_data.m:
compiler/prog_data_foreign.m:
compiler/prog_mutable.m:
compiler/rat.m:
compiler/recompilation.m:
compiler/source_file_map.m:
compiler/timestamp.m:
compiler/trace_params.m:
compiler/write_deps_file.m:
    As above.

compiler/Mercury.options:
    Don't pass --no-warn-inconsistent-pred-order-clauses for the above modules.
2019-08-23 20:54:27 +10:00
Zoltan Somogyi
5722645ce5 Separate out type_info args and return values in mode error msgs.
compiler/mode_errors.m:
    When printing an error message that says "these args have these modes,
    which do not match any declared mode of the callee", avoid confusing
    users by not mentioning the extra type_info/typeclass_info args added by
    polymorphism, except in the very rare case that they could be the *cause*
    of the mode error.

    When the callee is a function, list its return value separately from
    the other arguments, again in an effort to reduce possible confusion.

compiler/mode_info.m:
    To make the above possible, record the actual pred_id of the callee
    for plain calls. This should actually be faster than the old code
    it replaces, because it avoids the computation of the call_id from
    the pred_id for all calls that do not result in error messages.

    Fix a misleading predicate name.

compiler/modecheck_goal.m:
compiler/modecheck_util.m:
compiler/unique_modes.m:
    Conform to the changes in mode_info.m.

compiler/hlds_pred.m:
    Fix a misleading predicate name.

compiler/polymorphism.m:
compiler/pred_table.m:
    Conform to the changes in hlds_pred.m.

compiler/add_pred.m:
compiler/add_special_pred.m:
compiler/higher_order.m:
    Use variable names that specify which kind of arity they talk about:
    the one that counts functions' return values, or the one that doesn't.

tests/invalid/any_passed_as_ground.err_exp:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_3.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/state_vars_test1.err_exp:
tests/invalid/try_detism.err_exp:
    Update these expected output files to account for the change to
    mode_errors.m above.

tests/invalid/any_passed_as_ground.err_exp2:
    The old any_passed_as_ground.err_exp could not be matched for a long time
    now. The new any_passed_as_ground.err_exp actually updates the old
    any_passed_as_ground.err_exp2, since we can't have a .err_exp2 file
    without a .err_exp file. Since we now need only one expected output file,
    delete the .err_exp2 file.

tests/invalid/ho_default_func_1.err_exp2:
tests/invalid/ho_default_func_3.err_exp2:
    Delete these files, since they could not be matched for a long time now.

tests/invalid/try_detism.err_exp2:
    The same deal as with the any_passed_as_ground test case.
2019-03-13 01:33:02 +11:00
Zoltan Somogyi
15aa457e12 Delete $module arg from calls to unexpected. 2018-04-07 18:25:43 +10:00
Zoltan Somogyi
4d01ddc97d Replace a pair with a bespoke type. 2017-04-04 05:13:16 +10:00
Zoltan Somogyi
9d4f1e6ae5 Avoid using some Mercury keywords.
compiler/pred_table.m:
compiler/prog_data.m:
    Avoid using / as a function symbol.

    Rename some function symbols to avoid ambiguity.

compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_enum.m:
compiler/add_foreign_proc.m:
compiler/add_mode.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/check_for_missing_type_defns.m:
compiler/check_typeclass.m:
compiler/complexity.m:
compiler/det_report.m:
compiler/equiv_type.m:
compiler/error_util.m:
compiler/format_call.m:
compiler/hlds_error_util.m:
compiler/hlds_module.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/inst_check.m:
compiler/introduce_parallelism.m:
compiler/make_hlds_error.m:
compiler/make_hlds_passes.m:
compiler/make_tags.m:
compiler/mercury_to_mercury.m:
compiler/mode_errors.m:
compiler/modes.m:
compiler/module_qual.qual_errors.m:
compiler/oisu_check.m:
compiler/parse_mutable.m:
compiler/parse_sym_name.m:
compiler/parse_type_defn.m:
compiler/post_term_analysis.m:
compiler/prog_out.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/resolve_unify_functor.m:
compiler/type_constraints.m:
compiler/typecheck_errors.m:
compiler/unused_args.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.

    In a few places, improve the format of error messages.

tests/invalid/cyclic_typeclass.err_exp:
tests/invalid/cyclic_typeclass_2.err_exp:
tests/invalid/cyclic_typeclass_3.err_exp:
tests/warnings/inst_with_no_type.exp:
    Expect the updated error messages.
2016-05-13 11:46:37 +10:00
Zoltan Somogyi
5649f36c80 Handle "use_module in interface, import_module in implementation".
If a module m1 imports module m2 using a use_module declaration in its
interface section but also imports it using an import_module declaration
in its implementation section, then references to entities defined in m2
in the interface of m1 must be module qualified, but similar references
in the implementation of m1 need NOT be module qualified.

The Mercury compiler has long had a bug that allowed entities imported
in the implementation of module m1 to be used in the interface of m1,
against the rules of the language. When I fixed that bug on 2015 nov 11,
the compiler became unable to properly process the situation described
in the paragraph above, because it still had another bug, which was that
it had a single setting for module qualification requirements: either it
was required *everywhere* in m1, or it was required *nowhere* in m1.
This diff fixes that bug (mantis bug 401) by allowing different requirements
in this respect in the interface of m1 versus its implementation.

It also changes the de-facto meaning of what exactly a use_module declaration
requires. The reference manual says only:

    Uses of entities imported using @code{use_module} declarations
    @emph{must} be explicitly module qualified.

This WAS unambiguous when it was written in june 1997, a few months before
submodules were added to the language. With a flat module system, there were
no nested module names, so either the module name was present, or it wasn't.
In the presence of nested modules, though, it IS ambiguous: HOW MUCH of
the module name must be present? The reference manual is silent on this.

At the moment, in the presence of a use_module for module ma.mb.mc,
a predicate p1 in ma.mb.mc may of course be referred to as ma.mb.mc.p1,
but may also be referred to as mb.mc.p1, or even just mc.p1. The specification
of mc is always required, but exactly WHICH of the previous module name
components are required depends on whether e.g. ma or ma.mb were themselves
imported via use_module or import_module declarations. The code implementing
the check (find_matches_in_permissions_map in module_qual.id_set.m) is itself
not too clear.

This diff changes the rules so that all references to anything imported
via a use_module declarations have to be fully qualified. This is stricter
than the existing rule, but it is MUCH simpler, and it better matches
the original intent of use_module declarations, which is the avoidance
of ALL POSSIBILITY of ambiguity.

NEWS:
doc/reference_manual.texi:
    Document this change to the language.

compiler/prog_item.m:
    Change the representation of sections in .int* files. Previously,
    we recorded whether the interface file that the section was from
    was read for an `import_module' or a `use_module' declaration.
    We now allow the recording of the fact that it had both declarations,
    a use_module in the interface and an import_module in the implementation.

compiler/modules.m:
    Treat modules that have both a `use_module' declaration in interface
    and an `import_module' declaration in the implementation as being of this
    new internal section kind.

    Add some infrastructure for debugging similar problems in the future.

compiler/module_qual.id_set.m:
    Change the permissions system. Instead of recording *independently*
    whether (a) an entity may be used in the interface and (b) whether
    references to it must be qualified, record *separately* whether
    (a) it may be used in the interface, and if so with what qualification
    requirements, and (b) what its qualification requirements are in the
    implementation. Unlike the old permission setup, the new one allows us
    to express the "use_module in interface, import_module in implementation"
    situation.

    Implement the change to the language, by requiring full module
    qualification of entities imported via use_module declarations.
    This allows us to use a single parameterized piece of code to handle
    both unqualified and qualified references, whereas before we used
    separate pieces of code for them.

    Change the way we handle errors in module qualification. Instead of
    looking only for precise matches only, and looking for the possible causes
    of errors only if we find either no matches or two or more matches, we now
    return the near-miss matches as well, the ones that we need to decide
    on what error message we want to generate. While this is slightly slower,
    it is *much* simpler, since it allows us to avoid duplicating the search
    code: once for precise matches only, once for no-match errors, and once
    for multiple-match errors.

compiler/module_qual.collect_mq_info.m:
    Set permissions for symbol access according to the new permissions system.
    Code that previously triggered the bug will use the new interface file
    section kind, and can now have its permissions record correctly.

compiler/module_qual.qual_errors.m:
    Use a single predicate to generate error messages for all situations
    in which there is not a single precise match for a module qualification.
    This allows us to diagnose multiple potential problems with a single
    lookup.

    Change the wording of an existing error message to avoid a possibly-untrue
    implication.

compiler/hlds_data.m:
    Rename a field of the type_defn type to better document its meaning.

compiler/make_hlds.m:
    Document the meaning of the need_qualifier field in sec_infos.

compiler/add_type.m:
compiler/make_hlds_separate_items.m:
compiler/module_qual.m:
compiler/pred_table.m:
compiler/parse_tree_out.m:
compiler/prog_item_stats.m:
    Conform to the above changes.

mdbcomp/sym_name.m:
    Add a utility predicate for use in looking for near-miss matches
    in module qualification.

    Make the documentation of a related predicate more precise.

tests/invalid/bad_instance.m:
tests/submodules/class.m:
tests/submodules/nested.m:
tests/submodules/nested3.m:
tests/submodules/parent.m:
    Make names fully module qualified where the language rules now require it.

tests/submodules/deeply_nested.m:
    Comment out a part of the test that tested the partially qualified names,
    since these are now not allowed.

tests/invalid/errors.err_exp:
    Expect a now-improved error message.

tests/invalid/test_nested.err_exp:
tests/invalid/transitive_import.err_exp:
tests/invalid/undef_type.err_exp:
    Expect a now less-likely-to-mislead error message.

tests/valid_seq/int_impl_imports.m:
tests/valid_seq/int_impl_imports_2.m:
    The test case for mantis bug 401.

tests/valid_seq/Mmakefile:
    Enable the new test case.
2016-01-11 23:05:39 +11:00
Julien Fischer
3382f49a1c Fix spelling.
compiler/*.m:
    As above.
2015-12-17 09:43:24 +11:00
Zoltan Somogyi
c8c6ea41c1 Rename head_type_params to external_type_params.
Since it includes type parameters not just from the clause head, but also
from existentially type parameters returned by calls in the clause body.
2015-12-06 14:16:41 +11:00
Zoltan Somogyi
cc9912faa8 Don't import anything in packages.
Packages are modules whose only job is to serve as a container for submodules.
Modules like top_level.m, hlds.m, parse_tree.m and ll_backend.m are packages
in this (informal) sense.

Besides the include_module declarations for their submodules, most of the
packages in the compiler used to import some modules, mostly other packages
whose component modules their submodules may need. For example, ll_backend.m
used to import parse_tree.m. This meant that modules in the ll_backend package
did not have to import parse_tree.m before importing modules in the parse_tree
package.

However, this had a price. When we add a new module to the parse_tree package,
parse_tree.int would change, and this would require the recompilation of ALL
the modules in the ll_backend package, even the ones that did NOT import ANY
of the modules in the parse_tree package.

This happened even at one remove. Pretty much all modules in every one
of the backend have to import one or more modules in the hlds package,
and they therefore have import hlds.m. Since hlds.m imported transform_hlds.m,
any addition of a new middle pass to the transform_hlds package required
the recompilation of all backend modules, even in the usual case of the two
having nothing to do with each other.

This diff removes all import_module declarations from the packages,
and replaces them with import_module declarations in the modules that need
them. This includes only a SUBSET of their child modules and of the non-child
modules that import them.
2015-11-13 15:03:20 +11:00
Zoltan Somogyi
41f36f7e07 Convert (C->T;E) to (if C then T else E). 2015-10-09 04:20:21 +11:00
Zoltan Somogyi
ea094b5bb7 Make the import_status type part of the HLDS.
The import_status type was defined in parse_tree.status.m, but it is
not actually used in the parse_tree package. It is used, extensively,
in the hlds package.

compiler/status.m:
compiler/prog_item.m:
compiler/prog_data.m:
    Move the parts of status.m that *are* needed in the parse_tree package
    to modules in that package. The section markers and the import_locn type
    are moved to prog_item.m, while the need_qualifier type is moved to
    prog_data.m.

compiler/parse_tree.m:
compiler/hlds.m:
    Switch the status.m module from being in the parse_tree package
    to being in the hlds package.

compiler/notes/compiler_design.html:
    Document the switch.

compiler/*.m:
    Update import_module declarations as needed after the above change.

    In some places, import parse_tree.prog_item as well as hlds.status,
    even if we are only intested in statuses, because the import_locn type,
    which part of some statuses, *is* used in the parse_tree package,
    and must therefore be defined there. These undesirable dependencies
    will go away when we implement the proposal for purpose-specific status
    types.
2015-09-09 01:47:08 +10:00
Zoltan Somogyi
850d461c40 Make `:- external' a pragma inside the compiler and out.
We used to have only the first of these three forms, we now have all three:

:- external(low_level_backend, a/2).
    % declared pred a/2 and func a/2 to be external on llds
:- pragma external_pred(a/2, [low_level_backend]).
    % declared pred a/2 (and NOT func a/2) to be external on llds
:- pragma external_func(a/2, [low_level_backend]).
    % declared func a/2 (and NOT pred a/2) to be external on llds

The new forms allow for more precise control of what is declared to be
external. The difference in syntax (the options coming after the name,
and the options being in a list, even though this pragma allows only
one option at present) are to fit in with the style of the other pragmas.

Of course, the backend does not have to be specified, so these are
also allowed:

:- pragma external_pred(a/2).
:- pragma external_func(a/2, []).

Using `:- external' declarations is for implementors only, since using it
requires writing target language code by hand in a way that conforms to all
the compiler's conventions for e.g. symbol naming and parameter passing.
It is not a documented part of Mercury. Therefore the new external_{func,pred}
pragmas are not documented either.

compiler/prog_item.m:
    Change the representation of the `:- external' declaration from being
    a module_defn to being a pragma. Generalize it to allow the new pragmas,
    by allowing the recording of an option pred_or_func indication.

    Add a function that returns a description of a pragma for use as a context
    in error messages. We need this to avoid confusing users by having an
    error message refer to a `:- external' declaration when they wrote e.g.
    `:- pragma external_pred', or vice versa.

compiler/add_pragma.m:
    Move the code for handling external declarations from make_hlds_passes
    (which handles module_defns) to this module (which handles pragmas),
    and update it.

    Execute this code in pass 2, not pass 1, since we need to record
    the "external" flag in the pred_info, and that is created in pass 1.
    (I think this worked in the past ONLY if the declaration of the affected
    predicate or function came textually before the `:- external' declaration.)

compiler/make_hlds_passes.m:
    Remove the code that is now in add_pragma.m (in adapted form).

compiler/prog_io_item.m:
    Change the code for parsing old-style `:- external' declarations to
    generate the new pragma internally.

compiler/prog_io_pragma.m:
    Add code for parsing the new pragmas.

compiler/equiv_type.m:
compiler/item_util.m:
compiler/mercury_to_mercury.m:
compiler/module_imports.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.version.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.

compiler/make_hlds_error.m:
    Improve a variable name.

compiler/pred_table.m:
    Improve the documentation of several predicates.

tests/hard_coded/backend_external.m:
    Improve the documetation of this old test case, which tests the
    handling of backend-specific `:- external' declarations.

tests/hard_coded/backend_external_{func,pred}.m:
    Two copies of the old backend_external.m test case, which test the
    handling of backend-specific `:- pragma external_func' and
    `:- pragma external_pred' declarations respectively.

tests/hard_coded/backend_external_func.exp:
tests/hard_coded/backend_external_pred.{exp,exp2}:
    The expected outputs of the new test cases.

tests/hard_coded/Mmakefile:
    Enable the new test cases.

tests/invalid/type_spec.err_exp:
    Expect an error message for a `:- external' declaration in the interface
    of type_spec.m. Since declaring a procedure to be external is in essence
    a representation of the implementation of that procedure, the previous
    absence of an error message for this implementation detail in the interface
    was a bug.

tests/invalid/external.err_exp:
    We always generated an error for a `:- external' declaration that
    did not specify an arity, but the text of the error message used to say
    "warning", not "error" (even though the severity level was "error").
    Expect the corrected error message.

tests/invalid/not_in_interface.err_exp:
    Expect the updated, more precise form of an error message.

vim/syntax/mercury.vim:
    Add the two new keywords.
2015-07-22 14:58:44 +10:00
Zoltan Somogyi
f2043fc9bd Replace the item list with more structured ASTs.
The parts of the compiler that run before the HLDS is constructed used to use
a raw list of items to represent source files (.m), interface files (.int0,
.int3, .int2 and .int) and optimization files (.opt, and .trans_opt).
These lists had structure, but this structure was implicit, not explicit,
and its invariants were never really documented.

This diff changes that. It replaces the item list with FIVE separate types.

Three of these each represent the unprocessed content of one file:

- parse_tree_int represents the contents of one interface file;
- parse_tree_opt represents the contents of one optimization file;
- parse_tree_src represents the contents of one source file.

Two of these each represent the processed contents of one or more files:

- raw_compilation_unit represents the contents of one module in a source file.
  (The source file may contain several nested modules; the compilation unit
  represents just one.)
- aug_compilation_unit represents the contents of one module in a source file,
  just like raw_compilation_unit, but it is augmented with the contents of the
  interface and optimization files of the other modules imported (directly or
  indirectly) by the original module.

These five separate concepts all used to be represented by the same type,
list(item), but different invariants applied to the structure of those lists.
The most important of those invariants at least are now explicit in the types.
I think it is entirely possible that there are other invariants I haven't
discovered and documented (for example, .int3 files must have stricter
invariants on what can appear in them than .int files), but discovering
and documenting these should be MUCH easier after this change.

I have marked many further opportunities for improvements with "XXX ITEM_LIST".
Some of these include moving code between modules, and the creation of new
modules. However, I have left acting on those XXXs until later, in order to
keep the size of this diff down as much as possible, for easier reviewing.

compiler/prog_item.m:
    Define the five new AST types described above, and utility predicates
    that operate on them.

    In the rest of this change, I tried, as much as possible, to change
    predicates that used to take item lists as arguments to make them change
    one of these types instead. In many cases, this required putting
    the argument lists of those predicates into a more consistent order.
    (Often, predicates that operated on the contents of the module
    took the name of the module and the list of items in the module
    not just as separate arguments, but as separate arguments that
    weren't even next to each other.)

    Define types that identify the different kinds of interface and
    optimization files (.int, .int2 etc). These replace the string suffixes
    we used to use to identify file types. Predicates that used to take strings
    representing suffixes as arguments now have to specify whether they can
    handle all these file types (source, interface and optimization),
    or just (e.g.) all interface file types.

    We used to have items corresponding to `:- module' and `:- end_module'.
    Delete these; this information is now implicit in the structure of the
    relevant AST. The parser handles the corresponding terms as markers,
    not items; these markers are live only during parsing.

    We used to have module_defns corresponding to `:- interface' and
    `:- implementation'. Delete these; this information is now also implicit
    in the structure of the relevant AST. Delete also, for the same reason,
    the module_defns used to mark the starts of sublists in the overall lists
    of items whose items came from the interface files or optimization files
    of other modules. The former are now markers during parsing. The latter
    are never parsed, but are created directly, after parsing has been done.

    Delete the pragma type for `:- pragma source_file'. This is never
    needed later; it is now a marker during parsing.

    Change the internal representation of `:- import' and `:- use'.
    It used to store a list of module names, but that list was an actual list
    only during parsing; after that, it always had exactly one element.
    It now stores one module name, and the parser has a mechanism to convert
    one read-in term to more than one item, for use with terms such as
    `:- import_module a, b'.

    Delete the internal representation of `:- export', which was never
    implemented, since if it IS ever implemented, it will almost certainly
    be in a different form, which will need different support.

    Document some further opportunities for simplification, later.
    (This diff is already more than big enough.)

compiler/prog_io_item.m:
    Rewrite the top-level part of this module. Instead of returning an item
    for every parsed term, distinguish between parsing items that end up
    in item lists inside ASTs, and parsing markers that end up creating
    the STRUCTURE of those ASTs.

compiler/prog_io.m:
    Rewrite the meat of this module. Instead of reading in a simple item list,
    we now have to read in three different parse trees with three different
    grammars, each of which is more complex than a simple list.

compiler/read_modules.m:
    We used to have a map that mapped file names to the contents of those
    files. We now need three separate maps, for interface files, optimization
    files and source files, due to their separate types.
    (We don't actually use the map for optimization files, which seems
    to be a potential performance bug. The root cause of that problem
    us that while intermod.m and the grab_*modules part of modules.m do
    similar jobs, they don't use the same mechanisms.)

    Replace the read_module predicate with the predicates read_module_src
    and read_module_int, since these now return different types.

    To avoid having to create AST-type-specialized variants of
    read_module_ignore_errors and read_module_if_changed, give each of
    read_module_{src,int} arguments that optionally tell them to ignore errors
    and/or to read the module only if changed (though the "and" part of
    "and/or" should not be needed.) These options already existed, but
    they weren't exported.

compiler/timestamp.m:
    Define the type we use for this option in read_modules.

compiler/status.m:
    New module, containing mostly

    - stuff carved out of hlds_pred.m, which defines the import_status type,
      and the predicates that operate on it;
    - stuff carved out of make_hlds_passes.m, which defines the item_status
      type and the predicates that operate on that; and
    - stuff carved out prog_data.m, which defines the section (now
      module_section) and import_locn types.

    It also contains the new section kinds we now use to represent item blocks
    that were imported from interface and optimization files.

compiler/parse_tree.m:
compiler/notes/compiler_design.html:
    Add status.m to the parse_tree package.

compiler/hlds_pred.m:
compiler/prog_data.m:
    Remove the stuff now in status.m.

compiler/error_util.m:
    Provide a mechanism to control the order of messages with respect to
    ALL other messages, not just those that also specify ordering.

compiler/mercury_to_mercury.m:
    Provide predicates for printing out parse_tree_* and *_compilation_unit,
    since printing out a simple item list is no longer enough for debugging.

    Pretty-print type definitions nicely.

    Replace a boolean with a purpose-specific enum.

compiler/modules.m:
    Rewrite virtually all this module to make it work on the new AST
    representations. Generate more detailed error messages for duplicate
    module inclusions. Note lots of possibilities for further improvements,
    including in the documentation. Mark places I am still not sure about,
    especially places where I am not sure *why* the code is doing
    what it is doing.

compiler/module_imports.m:
    This module stores the data structure in which we accumulate the stuff
    imported into a compilation unit, i.e. it is in these data structures
    that a raw_compilation_unit becomes an aug_compilation_unit. Modify
    the data structure and the predicates that operate on it to work on the
    new AST representations, not on an (apparently) simple list of items.

    Avoid ambiguities by adding a prefix to field names.

    Add some convenience predicates.

compiler/module_qual.m:
    Perform module qualification on both raw lists of items (for use when
    generating .int3 files) but also on item blocks (for use pretty much
    in every other situation).

    Generate warnings about module imports that are unnecessarily in the
    module interface using the module's context (the context of the `:- module'
    declaration), not line 1 of the relevant file.

compiler/prog_io_error.m:
    Split some error categories more finely, since some error kinds here
    actually used to be reported for more than one distinct situation.

compiler/prog_io_util.m:
    Provide utility predicates that operate on nonempty lists.

compiler/recompilation.version.m:
    Make the comparison of the old and new contents of the interface file
    work on two parse_tree_ints, not on two raw sequences of items.

    Delete a boolean option that was always `yes', never 'no'.

compiler/recompilation.m:
    Turn some functions into predicates to allow the use of state variable
    notation.

    Avoid ambiguities by adding a prefix to field names.

compiler/write_module_interface_files.m:
    Besides updating the code in this module to work on the new parse tree
    representations, also use cords instead of reversed lists in several cases.
    Note many possibilities for further improvements.

library/list.m:
    Move the type one_or_more here from the compiler directory, since
    we now use it in more than one compiler module, and this is its natural
    home.

mdbcomp/sym_name.m:
    Rename "match_sym_name" to "partial_sym_name_matches_full", since this
    better describes its job.

    Add a det version of sym_name_get_module_name.

compiler/equiv_type.m:
    Rename some types to make them more expressive.

compiler/accumulator.m:
compiler/add_class.m:
compiler/add_foreign_enum.m:
compiler/add_foreign_proc.m:
compiler/add_mode.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_special_pred.m:
compiler/add_type.m:
compiler/assertion.m:
compiler/base_typeclass_info.m:
compiler/check_typeclass.m:
compiler/ctgc.util.m:
compiler/dead_proc_elim.m:
compiler/dep_par_conj.m:
compiler/dependency_graph.m:
compiler/deps_map.m:
compiler/det_report.m:
compiler/elds_to_erlang.m:
compiler/equiv_type_hlds.m:
compiler/erl_code_gen.m:
compiler/export.m:
compiler/format_call.m:
compiler/higher_order.m:
compiler/hlds_data.m:
compiler/hlds_module.m:
compiler/hlds_out_pred.m:
compiler/inst_check.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/lco.m:
compiler/make.module_dep_file.m:
compiler/make_hlds.m:
compiler/make_hlds_error.m:
compiler/make_hlds_passes.m:
compiler/make_tags.m:
compiler/mercury_compile.m:
compiler/ml_proc_gen.m:
compiler/ml_type_gen.m:
compiler/mode_errors.m:
compiler/oisu_check.m:
compiler/par_loop_control.m:
compiler/polymorphism.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/pred_table.m:
compiler/prog_io_dcg.m:
compiler/prog_io_find.m:
compiler/prog_io_pragma.m:
compiler/prog_io_sym_name.m:
compiler/prog_io_type_defn.m:
compiler/prog_io_typeclass.m:
compiler/prop_mode_constraints.m:
compiler/push_goals_together.m:
compiler/qual_info.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/simplify_proc.m:
compiler/smm_common.m:
compiler/special_pred.m:
compiler/ssdebug.m:
compiler/stm_expand.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.m:
compiler/structure_reuse.indirect.m:
compiler/structure_reuse.versions.m:
compiler/structure_sharing.analysis.m:
compiler/structure_sharing.domain.m:
compiler/table_gen.m:
compiler/term_constr_initial.m:
compiler/term_constr_main.m:
compiler/termination.m:
compiler/trace_params.m:
compiler/trans_opt.m:
compiler/type_class_info.m:
compiler/type_ctor_info.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
compiler/typecheck_info.m:
compiler/unify_proc.m:
compiler/untupling.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/write_deps_file.m:
compiler/xml_documentation.m:
    Conform to the changes above.

tests/hard_coded/higher_order_func_test.m:
tests/hard_coded/higher_order_syntax.m:
    Avoid a warning about importing a module in the interface, not the
    implementation.

tests/invalid/after_end_module.err_exp:
tests/invalid/any_mode.err_exp:
tests/invalid/bad_end_module.err_exp:
tests/invalid/bigtest.err_exp:
tests/invalid/bug113.err_exp:
tests/invalid/duplicate_modes.err_exp:
tests/invalid/errors.err_exp:
tests/invalid/errors1.err_exp:
tests/invalid/errors2.err_exp:
tests/invalid/funcs_as_preds.err_exp:
tests/invalid/inst_list_dup.err_exp:
tests/invalid/invalid_main.err_exp:
tests/invalid/missing_interface_import2.err_exp:
tests/invalid/no_exports.err_exp:
tests/invalid/occurs.err_exp:
tests/invalid/predmode.err_exp:
tests/invalid/prog_io_erroneous.err_exp:
tests/invalid/type_inf_loop.err_exp:
tests/invalid/typeclass_missing_det_3.err_exp:
tests/invalid/typeclass_test_11.err_exp:
tests/invalid/types.err_exp:
tests/invalid/undef_inst.err_exp:
tests/invalid/undef_mode.err_exp:
tests/invalid/undef_type.err_exp:
tests/invalid/unicode1.err_exp:
tests/invalid/unicode2.err_exp:
tests/invalid/vars_in_wrong_places.err_exp:
tests/warnings/unused_import.exp:
tests/warnings/unused_interface_import.exp:
    Update the expected outputs in the invalid and warnings directories
    to account for one or more of the following five changes.

    Error messages that warn about a module not exporting anything
    used to always refer to line 1 of the module's source file.
    Now expect these messages to refer to the actual context of the module,
    which is the context of its `:- module' declaration.

    Expect a similarly updated context for messages that warn about
    unnecessarily importing modules in the interface, not in the
    implementation.

    Expect a similarly updated context for messages that warn about
    importing a module via both `:- import_module' and `:- use_module'.

    For the modules that follow the `:- module' declaration directly with code,
    also expect an error message about the missing section marker.

    For modules that have terms after the `:- end_module' declaration,
    replace "end_module" with "`:- end_module'" in the error message.

tests/invalid/func_class.{m,err_exp}:
    New test case. It is a copy of the old tests/valid/func_class.m, which
    is missing more than one module marker. The expected output is what I think
    we should generate. The test case currently fails, because we currently
    print only a subset of the expected errors. I am pretty sure the reason
    for that is that old code I have not modified simply throws away the
    missing error messages. Fixing this is work for the near future.

tests/invalid/Mmakefile:
    Enable the new test case.

tests/misc_tests/pretty_print_test.exp:
    Expect the pretty-printed output to use four-space indentation,
    per our current style guide, since the compiler now generates such output.

tests/misc_tests/pretty_print_test.m:
    Clean up the source code of the test as well.

tests/valid/complicated_unify.m:
tests/valid/det_switch.m:
tests/valid/easy_nondet_test.m:
tests/valid/error.m:
tests/valid/func_class.m:
tests/valid/func_int_bug_main.m:
tests/valid/higher_order.m:
tests/valid/higher_order2.m:
tests/valid/implied_mode.m:
tests/valid/indexing.m:
tests/valid/multidet_test.m:
tests/valid/nasty_func_test.m:
tests/valid/semidet_disj.m:
tests/valid/stack_alloc.m:
tests/valid/switches.m:
    Add missing section markers to these modules. They used to follow
    the `:- module' declaration directly with code.
2015-07-21 04:06:52 +10:00
Zoltan Somogyi
ba6f7f75eb Separate type_assign_sets from typecheck_infos.
compiler/typecheck.m:
    Always pass around the current type_assign_set explicitly, and not as part
    of the typecheck_info. The old code did this in some places, but not
    others. In the places where it was passing around a type_assign_set,
    it was not always clear what the relationship between this explicitly
    passed-around type_assign_set and the one in the typecheck_info was.
    This diff eliminates this source of possible confusion.

compiler/type_assign.m:
    New module, carved out of the old typecheck_info.m, to handle type_assigns
    and related types. This code was actually bigger than the rest of
    typecheck_info.

compiler/typecheck_info.m:
    Delete the code that is now in type_assign.m.

    Put the remaining code in a more logical order.

    Since the typecheck_info does not need to store the current
    type_assign_set, move the most frequently used field in the
    typecheck_sub_info up to the typecheck_info. The speedup this yields
    compensates for the cost of always passing around the current
    type_assign_set in typecheck.m. (The overall performance does not change.)

compiler/check_hlds.m:
compiler/notes/compiler_design.html:
    Mention the new module.

compiler/typecheck_errors.m:
compiler/typeclasses.m:
    Conform to the changes above.

compiler/error_util.m:
compiler/mercury_to_mercury.m:
    Add a newly needed import. (They should have been needed before this;
    the fact that they weren't is a bug.)

compiler/Mercury.options:
    Specify a compiler option for typecheck.m.
2015-01-10 02:16:40 +11:00
Zoltan Somogyi
11f2a2e9ee Print better contexts for module qualification errors.
Specifically, when we find undefined types in type definitions, say WHERE
the undefined type is (both as line number and as function symbol/arg number,
and field name if present), since the body of the type definition is sometimes
quite big.

compiler/module_qual.m:
    When module qualification found an error, it used to get the context
    it printed for the error from the mq_info structure, which also contained
    the rest of the state of the qualification process. The drawback of this
    setup is that the mq_info's record of the error context was updated
    only in a few of the places where that context actually changed.

    This diff takes the error context out of the mq_info, and passes it
    as a separate argument to the predicates that need it. This makes it
    really visible if a context is passed onward unchanged even when it
    should be updated.

    Fix some of these places, and mark the rest with XXXs.

    When printing error messages about predicate or function declarations,
    the message talked about definitions, not declarations. Fix that.

    Put a prog_context inside each function symbol of mq_error_context;
    don't require the creation of a separate memory cell for a pair
    to link the mq_error_context with the prog_context.

    Factor out some common code.

compiler/prog_data.m:
    I tried to put a context inside constraints for use in error contexts
    in module_qual.m, but that turned out to be a bad idea. Document why.

compiler/add_class.m:
compiler/equiv_type.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_data.m:
compiler/post_typecheck.m:
compiler/pred_table.m:
compiler/prog_io_typeclass.m:
compiler/prog_type.m:
compiler/recompilation.usage.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/typeclasses.m:
compiler/unused_imports.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Clean up some code dealing with constraints. I did this cleanup while
    adding contexts to constraints, a change I then had to undo.

tests/invalid/builtin_int.err_exp:
tests/invalid/errors.err_exp:
tests/invalid/errors1.err_exp:
tests/invalid/fundeps_vars.err_exp:
tests/invalid/missing_interface_import.err_exp:
tests/invalid/missing_interface_import2.err_exp:
tests/invalid/test_nested.err_exp:
tests/invalid/transitive_import.err_exp:
tests/invalid/undef_type.err_exp:
tests/invalid/undef_type_mod_qual.err_exp:
tests/recompilation/add_type_re.err_exp.2:
tests/recompilation/remove_type_re.err_exp.2:
    Update these expected output files to match the better messages
    we now generate.
2015-01-01 15:19:56 +11:00
Zoltan Somogyi
c1402f8b99 Clean up hlds_module.m.
compiler/hlds_module.m:
    Put related fields of the module_sub_info next to each other.

    Some of those fields contained lists that were built reversed,
    in order to avoid O(N^2) behavior when repeatedly adding new items
    to the end of the list. Replace these with cords, which did not exist
    when those fields were first added.

    Give some fields and their getter/setter predicates more descriptive
    names.

    Separate out both the declarations and definitions of the getter and
    setter predicates, and put them into the same order as the (updated)
    order of the fields. Put the utility predicates (those that are more
    complicated than just getters or setters) into an order based on
    what fields they work on, following the same order.

    Improve the operation of some of the utility predicates, e.g. replacing
    a nondet predicate with a det predicate returning a set.

    Delete an unused type.

    Conform to the changes in the modules imported by hlds_module.m,
    e.g. pred_table.m, prog_data.m and prog_foreign.m.

compiler/pred_table.m:
    We used to store the set of valid pred ids as two lists, again to avoid
    O(N^2) behavior. Replace the two lists with a set. This allows
    looking up the set *without* updating the pred_table, or, when
    the pred_table is within the module_info, updating the module_info.

    Instead of allowing callers to replace the set of valid pred ids wholesale,
    enforce the documented invariant on that set by only allowing deletions.

    Conform to the changes above.

compiler/add_pragma.m:
compiler/bytecode_gen.m:
compiler/check_typeclass.m:
compiler/compile_target_code.m:
compiler/cse_detection.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/dep_par_conj.m:
compiler/dependency_graph.m:
compiler/deps_map.m:
compiler/det_analysis.m:
compiler/distance_granularity.m:
compiler/equiv_type_hlds.m:
compiler/erl_code_gen.m:
compiler/exception_analysis.m:
compiler/export.m:
compiler/float_regs.m:
compiler/foreign.m:
compiler/higher_order.m:
compiler/hlds_module.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/introduce_parallelism.m:
compiler/lambda.m:
compiler/liveness.m:
    Conform to the changes above.

    In many places, the change to how the valid pred ids are stored
    allows us to avoid creating new module_infos.

    In some places, fix style issues I noticed while working on the above.

compiler/llds.m:
compiler/mercury_compile_llds_back_end.m:
    Conform to the changes above.

    Move a type from llds.m to mercury_compile_llds_back_end.m, since
    only the latter uses it.

compiler/prog_data.m:
compiler/prog_foreign.m:
    Replace some types that used to hold reversed lists with cords.

    In prog_foreign.m, represent the two kinds of foreign code that
    do NOT define procedures with similarly named types.

    Delete a type (user_foreign_code) that duplicated another type.

    Replace an equivalence type with a notag type, for safety.

compiler/recompilation.usage.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
    Now that we have direct access to the set of visible modules,
    simplify the logic of some code dealing with those modules.

compiler/module_imports.m:
    Put some related fields next to each other.

compiler/llds_out_file.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make_hlds_passes.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_middle_passes.m:
compiler/ml_proc_gen.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
compiler/mode_constraints.m:
compiler/modes.m:
compiler/modules.m:
compiler/passes_aux.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/pred_table.m:
compiler/proc_gen.m:
compiler/prog_item.m:
compiler/purity.m:
compiler/rbmm.condition_renaming.m:
compiler/rbmm.execution_path.m:
compiler/rbmm.live_region_analysis.m:
compiler/rbmm.live_variable_analysis.m:
compiler/rbmm.points_to_analysis.m:
compiler/rbmm.region_arguments.m:
compiler/rbmm.region_instruction.m:
compiler/ssdebug.m:
compiler/stm_expand.m:
compiler/stratify.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.m:
compiler/structure_reuse.domain.m:
compiler/structure_sharing.analysis.m:
compiler/structure_sharing.domain.m:
compiler/switch_detection.m:
compiler/tabling_analysis.m:
compiler/term_constr_initial.m:
compiler/term_constr_main.m:
compiler/termination.m:
compiler/trailing_analysis.m:
compiler/trans_opt.m:
compiler/try_expand.m:
compiler/type_constraints.m:
compiler/untupling.m:
compiler/unused_args.m:
compiler/write_deps_file.m:
2014-12-29 22:18:51 +11:00
Zoltan Somogyi
add253af9f Fix compiler abort looking for stream.put (Mantis bug 369).
compiler/module_imports.m:
    Implicitly import stream.m if the module being compiled may call
    stream.string_writer.format.

compiler/simplify_proc.m:
    Keep stream.put around until format_call.m may need it.

compiler/pred_table.m:
    If looking for a predicate fails, generate an error message that mentions
    the module name part of the fully qualified predicate name being
    looked for.

tests/hard_coded/stream_put_bug.{m,exp}:
    New test case, based on one contributed by sebgod (the filer of
    Mantis bug 369).

tests/hard_coded/Mmakefile:
    Enable the new test case.
2014-12-16 10:12:19 +11:00
Zoltan Somogyi
efb56544ed Speed up pred_info's setter predicates a bit.
compiler/hlds_pred.m:
    If the new value of a field of pred_info is likely to be bit-identical
    to the old value, then test the old and new bits for equality in the
    setter, and if they are the same, do not allocate a new pred_info
    structure that is guaranteed to be the same as the old one.

    By avoiding unnecessary memory turnover, this speeds up the compiler a bit,
    though I cannot nail down by how much. I measured it several times, with
    the results being no change, a speedup of 1%, and a speedup of 2%.

    Remove the unused setter predicate for the attributes field.

    Rename some access predicates to pred_infos to better reflect what they do.

    Add a distinguishing prefix to the fields of pred_infos.

compiler/*.m:
    Conform to the changes above.
2014-12-14 10:32:27 +11:00
Zoltan Somogyi
13b6f03f46 Module qualify end_module declarations.
compiler/*.m:
    Module qualify the end_module declarations. In some cases, add them.

compiler/table_gen.m:
    Remove an unused predicate, and inline another in the only place
    where it is used.

compiler/add_pragma.m:
    Give some predicates more meaningful names.
2014-09-04 00:24:52 +02:00
Zoltan Somogyi
500948d549 Break up mdbcomp/prim_data.m. The new modules have much better cohesion.
mdbcomp/sym_name.m:
    New module, containing the part of the old prim_data.m that
    dealt with sym_names.

mdbcomp/builtin_modules.m:
    New module, containing the part of the old prim_data.m that
    dealt with builtin modules.

mdbcomp/prim_data.m:
    Remove the things that are now in the two new modules.

mdbcomp/mdbcomp.m:
deep_proiler/Mmakefile:
slice/Mmakefile:
    Add the two new modules.

browser/*.m:
compiler/*.m:
deep_proiler/*.m:
mdbcomp/*.m:
slice/*.m:
    Conform to the above changes.
2014-09-02 05:20:23 +02:00
Zoltan Somogyi
37c2856234 The predicates that searched the pred table used to return lists of
Estimated hours taken: 5
Branches: main

compiler/pred_table.m:
	The predicates that searched the pred table used to return lists of
	matching pred_ids, but they never returned empty lists; if there
	were no matching pred_ids, they failed. This diff changes them
	from semidet to det, and makes them return empty lists if there
	are no matches.

	This change simplifies both the code of these predicates, and the code
	of the predicates calling them.

	- Some callers of these predicates were prepared BOTH for the call
	  to fail, and for it to succeed returning an empty list; their types
	  allowed both.

	- Some pattern-matched the return value againt a one-element list
	  in the call itself, and treated both no matches and multiple matches
	  the same, even though an error message for one will be misleading
	  for the other.

	- All calls had to have a test for cons to pick up the first match;
	  this test was logically redundant, since they also had a test for
	  success/failure.

	Change the names of the affected predicates by replacing "search"
	in their names with "lookup", both to give the right intuition
	about what they do, and to make sure I didn't miss updating any
	callers.

compiler/add_class.m:
compiler/add_clause.m:
compiler/add_pragma.m:
compiler/add_pred.m:
compiler/check_typeclass.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/elds_to_erlang.m:
compiler/hlds_module.m:
compiler/intermod.m:
compiler/make_hlds_passes.m:
compiler/mmc_analysis.m:
compiler/post_typecheck.m:
compiler/recompilation.usage.m:
compiler/simplify.m:
compiler/type_constraints.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
	Conform to the above change.
2012-09-10 17:08:58 +00:00
Zoltan Somogyi
295415090e Convert almost all remaining modules in the compiler to use
Estimated hours taken: 6
Branches: main

compiler/*.m:
	Convert almost all remaining modules in the compiler to use
	"$module, $pred" instead of "this_file" in error messages.

	In a few cases, the old error message was misleading, since it
	contained an incorrect, out-of-date or cut-and-pasted predicate name.

tests/invalid/unresolved_overloading.err_exp:
	Update an expected output containing an updated error message.
2011-05-23 05:08:24 +00:00
Julien Fischer
322e498a50 Change places where we create an empty map and the immediately do a det_insert
Branches: main

Change places where we create an empty map and the immediately do a det_insert
into it to use the recently added singleton map function.

compiler/add_pragma.m:
compiler/common.m:
compiler/dep_par_conj.m:
compiler/higher_order.m:
compiler/hlds_data.m:
compiler/inst_match.m:
compiler/lco.m:
compiler/modecheck_goal.m:
compiler/modules.m:
compiler/polymorphism.m:
compiler/pred_table.m:
compiler/rbmm.region_resurrection_renaming.m:
compiler/simplify.m:
compiler/stack_layout.m:
compiler/stack_opt.m:
compiler/stm_expand.m:
compiler/switch_util.m:
compiler/term_pass2.m:
compiler/tupling.m:
compiler/type_constraints.m:
compiler/type_ctor_info.m:
compiler/unneeded_code.m:
deep_profiler/autopar_search_callgraph.m:
deep_profiler/html_format.m:
	As above.
2011-05-05 06:39:37 +00:00
Julien Fischer
9f68c330f0 Change the argument order of many of the predicates in the map, bimap, and
Branches: main

Change the argument order of many of the predicates in the map, bimap, and
multi_map modules so they are more conducive to the use of state variable
notation, i.e. make the order the same as in the sv* modules.

Prepare for the deprecation of the sv{bimap,map,multi_map} modules by
removing their use throughout the system.

library/bimap.m:
library/map.m:
library/multi_map.m:
	As above.
NEWS:
	Announce the change.

	Separate out the "highlights" from the "detailed listing" for
	the post-11.01 NEWS.

	Reorganise the announcement of the Unicode support.

benchmarks/*/*.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
extras/*/*.m:
mdbcomp/*.m:
profiler/*.m:
tests/*/*.m:
ssdb/*.m:
samples/*/*.m
slice/*.m:
	Conform to the above change.

	Remove any dependencies on the sv{bimap,map,multi_map} modules.
2011-05-03 04:35:04 +00:00
Zoltan Somogyi
8a28e40c9b Add the predicates sorry, unexpected and expect to library/error.m.
Estimated hours taken: 2
Branches: main

Add the predicates sorry, unexpected and expect to library/error.m.

compiler/compiler_util.m:
library/error.m:
	Move the predicates sorry, unexpected and expect from compiler_util
	to error.

	Put the predicates in error.m into the same order as their
	declarations.

compiler/*.m:
	Change imports as needed.

compiler/lp.m:
compiler/lp_rational.m:
	Change imports as needed, and some minor cleanups.

deep_profiler/*.m:
	Switch to using the new library predicates, instead of calling error
	directly. Some other minor cleanups.

NEWS:
	Mention the new predicates in the standard library.
2010-12-15 06:30:36 +00:00
Zoltan Somogyi
543fc6e342 Change the way the typechecker iterates over the predicates of the program.
Estimated hours taken: 12
Branches: main

Change the way the typechecker iterates over the predicates of the program.
We used to do it by looking up each predicate in the module_info,
typechecking it, and putting it back into the module_info. We now do it
by converting the predicate table into a list, iterating over the list
transforming each pred_info in it, converting the updated list back to
a predicate table.

The original intention of this change was to allow different predicates
to be typechecked in parallel by removing a synchronization bottleneck:
the typechecking of a predicate now doesn't have to wait for the typechecking
of the previous predicate to generate the updated version of the module_info.
However, it turned out that the change is good for sequential execution
as well, improving the time on tools/speedtest from 11.33 seconds to 11.08
seconds, a speedup of 2.2%. On tools/speedtest -l, which tests the compilation
of more modules, the speedup is even better: 3.1% (from 32.63 to 31.60s).

compiler/typecheck.m:
	Implement the above change.

compiler/hlds_module.m:
compiler/pred_table.m:
	Add a new operation, setting the list of valid pred_ids, now needed by
	typecheck.m, to both modules.

	Make the names of the predicates for accessing the predicate table
	more expressive, and make them conform to our naming conventions.

compiler/*.m:
	Trivial changes to conform to the change in hlds_module.m.

library/assoc_list.m:
	Add new predicates used by the new version of typecheck.m
	(at some time in its development).

NEWS:
	Mention the new predicates.

library/list.m:
	Improve documentation that is now copied to assoc_list.m.

tools/speedtest:
	Make the test command more easily configurable.
2010-07-30 05:16:26 +00:00
Peter Wang
11696d60e7 Add an option `--max-error-line-width <n>' to adjust the maximum line width for
Branches: main, 10.04

Add an option `--max-error-line-width <n>' to adjust the maximum line width for
error messages.

compiler/options.m:
doc/user_guide.texi:
NEWS:
        Add and document the option.

compiler/error_util.m:
        Make error message output predicates take globals arguments and get the
        maximum line width from that.

        Delete write_error_pieces_not_first_line and
        write_error_pieces_maybe_first_line which are obsolete and unused.

compiler/abstract_mode_constraints.m:
compiler/accumulator.m:
compiler/compile_target_code.m:
compiler/complexity.m:
compiler/fact_table.m:
compiler/mercury_compile.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/module_cmds.m:
compiler/options_file.m:
compiler/ordering_mode_constraints.m:
compiler/pred_table.m:
compiler/prop_mode_constraints.m:
compiler/term_constr_errors.m:
compiler/term_errors.m:
        Conform to changes.

tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
tests/invalid/max_error_line_width.err_exp:
tests/invalid/max_error_line_width.m:
        Add a test case.
2010-03-30 23:57:27 +00:00
Julien Fischer
a60ac9b107 Add a new warning, --warn-suspicious-foreign-procs.
This checks the bodies of foreign_proc pragmas for possible errors.
Currently, these errors are:

(1) the presence of SUCCESS_INDICATOR (or in Java, succeeded),
in foreign procs. for predicates that cannot fail.

(2) the lack of SUCCESS_INDICATOR (succeeded) in foreign procs.
for predicates that can fail.

(3) the presence of "return" (or "ret" or "jmp" in IL).  This could
indicate the presence of a return statement in the foreign proc.

Potentially, we could also check for the presence of the this
pointer in Java and C# foreign_procs, but that isn't implemented
at the moment.

The warning is disabled by default, since it will produce spurious
results if the things it checks for occur in foreign language
comments.

compiler/make_hlds_warn.m:
	Implement the new warning.

	Fix up another warning.

compiler/options.m:
	Add the new option.

compiler/add_pragma.m:
compiler/pred_table.m:
	Unrelated change: update some module qualifiers in a comment.

doc/user_guide.texi:
	Document the new warning.

tests/warnings/Mercury.options:
tests/warnings/Mmakefile:
tests/warnings/warn_return.m:
tests/warnings/warn_return.exp*:
tests/warnings/warn_succ_id.m:
tests/warnings/warn_succ_id.exp*:
	Test the output of the new warning.
2009-09-08 08:14:42 +00:00
Zoltan Somogyi
fcff4d3372 Document the dependency ordering.
Estimated hours taken: 0.2
Branches: main

compiler/hlds_module.m:
	Document the dependency ordering.

compiler/llds.m:
	Print the comment giving the name of each procedure always,
	and not only when --auto-comments is enabled. This makes it
	much easier to identify procedures whose names are mangled
	by the compiler.

compiler/pred_table.m:
	Minor cleanups.
2009-07-16 02:48:52 +00:00
Peter Wang
22c4408afb Improve the error message from `find_matching_pred_id' when it's unable
Branches: main

compiler/pred_table.m:
	Improve the error message from `find_matching_pred_id' when it's unable
	to resolve predicate overloading.  Instead of telling the user to
	compile with -V, tell the user the location of the call and which
	predicates were matched.

compiler/intermod.m:
compiler/modes.m:
compiler/post_typecheck.m:
compiler/purity.m:
	Add the context arguments needed for calls to `find_matching_pred_id'.

tests/invalid/Mmakefile:
tests/invalid/unresolved_overloading.err_exp:
tests/invalid/unresolved_overloading.m:
	Add test case.
2008-09-08 04:35:54 +00:00
Peter Wang
e1bddaa8a5 Fix a compiler abort when writing out an intermodule optimisation file, the
Branches: main

Fix a compiler abort when writing out an intermodule optimisation file, the
module for which has a typeclass instance of a typeclass that has a method with
an existentially typed argument, but the predicate which implements
the method is not itself existentially typed.  This is Mantis bug #76.

compiler/prog_type.m:
	Make `arg_type_list_subsumes' possibly succeed if a callee may bind
	existential type variables in the caller, rather than failing.

compiler/pred_table.m:
	Update `resolve_pred_overloading' and `find_matching_pred_id' to take
	extra arguments for `arg_type_list_subsumes'.

	Rename `get_pred_id' and `get_pred_id_and_proc_id' to be less
	ambiguous.

compiler/intermod.m:
compiler/modes.m:
compiler/post_typecheck.m:
compiler/purity.m:
	Conform to extra arguments and renamings.

compiler/trans_opt.m:
	Delete an unused predicate.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
tests/valid/intermod_typeclass_exist.m:
	Add test case.
2008-08-22 02:50:14 +00:00