Commit Graph

112 Commits

Author SHA1 Message Date
Zoltan Somogyi
f7355f708b Move var_db and var_{name,type}_source to var_db.m.
In the process, restrict the use of these types to just those modules
that need to provide services both other modules that use var_tables,
and modules that do not. The latter are modules that either can,
or always do, execute before var_tables are set up.

In some cases, code that previously operated on e.g. var_name_sources
had all its callers converted to use var_tables. In those cases, replace
the use of var_name_sources with var_tables directly.

In other cases, code that previously operated on e.g. var_name_sources
still has some callers that use varsets. In those cases,

- provide versions using var_tables if most callers use var_tables,
  renaming predicates/functions to make this the version seem the default,

- leave the operation to work on var_name_sources if some its callers
  also have only var_name_sources,

- if there are no such callers, keep just the two versions operating
  on varsets and var_tables respectively.

compiler/var_db.m:
compiler/var_table.m:
    Move the part of var_table.m that contains the definitions
    of the above three types, and the operations on them, to the
    new module var_db.m. Only 25 modules currently need var_db.m,
    compared to 176 for var_table.m.

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

compiler/parse_tree_out_term.m:
    Add a "_vs" suffix to the names of operations that print variables
    or terms using varsets, and reuse their old names for versions
    that use var_table arguments. For the operations that need var_name_source
    versions, make it just select between the varset and var_table versions.

compiler/hlds_out_goal.m:
compiler/instmap.m:
compiler/hlds_out_mode.m:
compiler/hlds_out_util.m:
compiler/hlds_pred.m:
compiler/pd_info.m:
    Change some predicates that used to operate on var_{name,type}_sources
    to operate on var_tables.

    In hlds_out_mode.m, delete some unused predicates, and stop exporting
    a predicate whose only caller is local.

compiler/*.m:
    Conform to the changes above.
2022-08-19 10:44:39 +10:00
Zoltan Somogyi
404fea1bd2 Start removing non-var_table versions of predicates.
compiler/arg_info.m:
compiler/goal_util.m:
compiler/hlds_rtti.m:
compiler/instmap.m:
compiler/recompute_instmap_deltas.m:
compiler/type_util.m:
    For predicates which had both varset/vartypes and var_table versions,
    but the former is not used anymore because all its callers have been
    switched to the latter,

    - delete the former, and
    - rename the latter to the name of the former.

    In goal_util.m, switch two currently-unused predicates to use var_tables
    instead of varsets/vartypes, in case they are needed again.

compiler/hlds_pred.m:
    Likewise replace define_new_pred with define_new_pred_vt, but also
    change its implementation to use var_table for everything except
    the final construction of the proc_info.

compiler/accumulator.m:
compiler/call_gen.m:
compiler/code_loc_dep.m:
compiler/constraint.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/det_util.m:
compiler/float_regs.m:
compiler/follow_code.m:
compiler/higher_order.m:
compiler/interval.m:
compiler/lambda.m:
compiler/lco.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/loop_inv.m:
compiler/ml_code_gen.m:
compiler/modes.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/push_goals_together.m:
compiler/rbmm.region_liveness_info.m:
compiler/saved_vars.m:
compiler/simplify_goal.m:
compiler/simplify_proc.m:
compiler/size_prof.m:
compiler/ssdebug.m:
compiler/structure_reuse.indirect.m:
compiler/structure_reuse.lbu.m:
compiler/structure_reuse.lfu.m:
compiler/table_gen.m:
compiler/tupling.m:
compiler/unneeded_code.m:
compiler/untupling.m:
    Conform to the changes above.
2022-05-15 21:40:10 +10:00
Zoltan Somogyi
0ab6993894 Convert mode analysis to use var_tables.
compiler/instmap.m:
compiler/mode_comparison.m:
compiler/mode_debug.m:
compiler/mode_info.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/unique_modes.m:
    Convert these modules to use var_tables.

compiler/mode_errors.m:
    Convert this module to use var_tables.

    Fix an ancient error that I think has escaped detection until now
    because it arises only in the presence of a mode error in a procedure
    whose mode is being inferred. The bug is that when we modecheck a call,
    say from p to q, and find no matching modes in the callee because
    its mode inference has generated errors, then we report those errors
    in the callee as part of the explanation of the error in the caller.
    That is fine. What was not fine is that we printed any variables
    in the callee's mode_error using the *caller's* varset. We now
    print them using the callee's var table.

compiler/type_util.m:
    Add a var_table-using variant of an existing predicate,
    for use in new code above.

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

tests/invalid/mode_inf.m:
    Modify this test case to make the caller and callee use disjoint
    sets of variable names, which is probably why the incorrect variables
    in the error message about the callee has not been noticed.

tests/invalid/mode_inf.err_exp:
    Expect the updated, and now correct, version of that error message.
2022-05-02 11:36:42 +10:00
Zoltan Somogyi
6f476f8f1e Convert det analysis and simplify to var_tables.
compiler/common.m:
compiler/const_prop.m:
compiler/format_call.m:
compiler/simplify_goal.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:
    Convert these modules, which comprise the simplification pass,
    to use var_tables.

compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
    Convert the modules of determinism analysis to use var_tables.

compiler/direct_arg_in_out.m:
    Convert this module to use var_tables, because simplification uses it,
    though it is also invoked separately. And this conversion is limited;
    it still uses varsets and vartypes in the code that clones a procedure.
    It will be simpler to fix this when pred_infos and proc_info switch over
    to actually storing var_tables, not making them up on demand.

compiler/hlds_pred.m:
    Export a predicate for use by new code in direct_arg_in_out.m.

compiler/goal_path.m:
    Allow the code in this module to get its type information either
    from vartypes or from var_tables, since some of the modules above
    now need the latter.

compiler/instmap.m:
    Provide a var_table variant of an existing predicate.

compiler/lambda.m:
compiler/par_loop_control.m:
compiler/pd_util.m:
    Conform to the changes above.

compiler/typecheck.m:
compiler/typecheck_errors.m:
    Fix an arguable bug exposed by the changes above. The invalid/bug257.m
    test case contains a variable, Gee, which occurs only in a
    "require_complete_switch [Gee]" scope. Typechecking did not assign it
    even a dummy type, and this was not a problem, because the only
    compiler pass that looked it, determinism analysis, needed only its name.
    However, determinism analysis now gets the name from the var_table,
    which has entries only for variables that have a type (since all variables
    are supposed to have one after typechecking). This meant that the
    old code of typecheck.m lead to a compiler crash when det_report.m
    tried to look up this variable's name for the error report saying that
    the goal in that require_complete_switch scope is not a switch on Gee.

    Fix this by ensuring that variable appearing in scope_reasons
    always have a type, even if that type is a type variable.

compiler/var_table.m:
    Fix the code of the deletion predicates for situations in which
    the highest numbered variable is deleted.

    Delete the var_table_add_corresponding_lists predicate,
    since its implementation cannot be made to work without access to the
    module_info, which, due to being in parse_tree package, var_tables.m
    cannot have.

    Fix some variable names.

tests/invalid/bug257.err_exp:
    Expect the warning that reports an unbound type.
2022-05-01 16:37:18 +10:00
Zoltan Somogyi
2be5342e1b Convert more middle passes to use var_tables.
compiler/complexity.m:
compiler/coverage_profiling.m:
compiler/deep_profiling.m:
compiler/dep_par_conj.m:
compiler/par_loop_control.m:
compiler/size_prof.m:
compiler/tabling_analysis.m:
    Convert these passes to use var_tables. The changes below exist
    to support the changes to these modules.

    In some places, improve argument order.

compiler/var_table.m:
    Add a new way to specify the name of a variable to be created.

compiler/goal_util.m:
    Generalize a predicate to be able to use any var type source.

    Replace some uses of bools with bespoke types.

    In some places, improve argument order.

compiler/instmap.m:
    Provide a version of instmap_changed_vars that takes a var_table instead
    of a var_types.

compiler/make_goal.m:
    Provide new versions of the predicates that create variables to hold
    constants, versions that use var_tables instead of varsets and vartypes.

compiler/polymorphism_type_info.m:
    Provide versions of three predicates that take var_table arguments
    instead of var_types arguments.

    Refactor some code to minimize the code duplication needed for this.
2022-04-18 02:37:16 +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
02f0128c5a Use var_tables in more of the later passes.
compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/float_regs.m:
compiler/lambda.m:
compiler/mark_tail_calls.m:
    Convert these passes to use var_tables instead of varsets and vartypes.

compiler/hlds_pred.m:
    Provide predicates to get and set "the var_table" of a procedure.
    The proc_info still stores varsets and vartypes, but these new predicates
    do the required conversions between representations. Likewise, provide
    a version of proc_info_create that takes a var_table argument instead
    of a varset and vartypes arguments. The new predicates should reduce
    the need for such conversions to be done elsewhere during the transition.

compiler/var_table.m:
    Provide a predicate to turn a var_table back into
    a <varset, vartypes> pair.

    Provide two transitional types, var_db and var_type_source, that
    provide either
    - the functionality of both a varset and a vartypes, or
    - just the functionality of a vartypes,
    using either those structure(s), or a var_table.

    Make it possible to allocate new variables from a var_table,
    by including in it a counter that takes on the role played by
    the var_supply in varsets.

    Provide a predicate to look up the types of several variables at once.

    Provide a way to construct a var_table from a reverse sorted assoc list.

compiler/vartypes.m:
    Provide a way to construct a var_table from a reverse sorted assoc list,
    to allow code to operate the same way on vartypes as on var_tables.

library/varset.m:
    Provide predicates to make the changes in var_table.m possible.
    They have to be exported, but they are in the second interface section,
    so they are not publicly documented.

compiler/quantification.m:
compiler/recompute_instmap_deltas.m:
compiler/goal_util.m:
    Provide versions of some exported predicates that take var_tables
    instead of varsets and vartypes, for use by the modules above.

    Rationalize the argument order of some predicates.

compiler/instmap.m:
    Generalize some existing predicates to take type information
    from either vartypes or var_tables, using a transitional mechanism
    now provided by var_table.m.

    Rationalize the argument order of some predicates.

compiler/inlining.m:
    Fix an unrelated bug that just happened to be tickled by the
    rest of this diff. When inlining a call, set the flag that calls
    for rerunning determinism analysis on the procedure in which the
    inlining takes place if the call has an argument variable that
    does not occur outside the call. We need to do this because
    ignoring the last output argument(s) of a call can reduce
    the max possible number of solutions of the call to one.

compiler/set_of_var.m:
    Provide a predicate needed by the fix in inlining.m.

compiler/prog_type.m:
    Give some predicates meaningful names, and create versions that
    return the same info in a different form (set instead of list).

compiler/add_pragma_type_spec.m:
compiler/check_typeclass.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/deforest.m:
compiler/error_util.m:
compiler/follow_code.m:
compiler/higher_order.m:
compiler/hlds_class.m:
compiler/hlds_rtti.m:
compiler/ml_gen_info.m:
compiler/old_type_constraints.m:
compiler/parse_class.m:
compiler/parse_type_defn.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/polymorphism_type_class_info.m:
compiler/post_typecheck.m:
compiler/push_goals_together.m:
compiler/qual_info.m:
compiler/saved_vars.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_ite.m:
compiler/simplify_goal_switch.m:
compiler/simplify_proc.m:
compiler/size_prof.m:
compiler/table_gen.m:
compiler/trace_gen.m:
compiler/type_assign.m:
compiler/type_ctor_info.m:
compiler/typecheck.m:
compiler/typeclasses.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
    Conform to the changes above.
2022-04-17 13:44:10 +10:00
Zoltan Somogyi
0acc8315bc Optimize merge_instmap_deltas.
compiler/instmap.m:
    Until now, the merge_instmap_deltas predicate has always operated by
    repeatedly invoking merge_instmap_delta in a two-level loop to fixpoint,
    though how we do the inner loop has changed over the years. However,

    - some of the work done by these invocations of merge_instmap_delta,
      such as finding out which of the instmap_deltas is reachable,
      is repeated in each iteration of the outer (fixpoint) loop, and
    - some other work, such as finding out the types of the variables
      whose insts need to be merged, is repeated many times even within
      each iteration of the inner loop.

    This diff moves such code out of the nested fixpoint loop, for
    invocations of merge_instmap_deltas that are given enough deltas
    to make this worthwhile.

    Carve merge_instmapping_delta_var out of merge_instmapping_delta_vars,
    since this is the only part of merge_instmap_delta that the fixpoint
    iteration now repeatedly invokes.

    Optimize even the base predicate merge_instmap_delta by testing whether
    the *initial* instmap is reachable just once.

    Standardize on capitalizating the M in InstMap/InstMapping.
2022-04-16 15:16:02 +10:00
Zoltan Somogyi
5de33e1671 Improve variable names. 2022-04-15 19:23:29 +10:00
Zoltan Somogyi
8055577a7f Optimize the common case in instmap_delta_restrict.
compiler/instmap.m:
    Before code generation, the MLDS backend recomputes all nonlocal sets,
    because the MLDS code generator needs them to contain exact information,
    but the compiler's rules allow the nonlocal sets in goal_infos
    to overapproximate the true nonlocals set. Since instmap_deltas can
    contain a variable as a key only if that variable is in the nonlocals set,
    this also involved calling instmap_delta_restrict to ensure this.

    However, while the nonlocals sets of goal_infos *may* include variables
    that are not true nonlocals, they typically do not do so. This diff
    adds conditionally-enabled code to record information about this,
    and the results show that 90+% of calls to instmap_delta_restrict
    make no changes to the instmap_delta. This diff therefore also
    special-cases the handling of such calls. The reason why I believe
    this to be worthwhile is that in a deep profiled compiler run,
    I observed that the instmap_delta_restrict predicate accounted for
    about 1.4% of the call counts, and about 1.3% of the memory allocated.

library/map.m:
library/tree234.m:
    Add the library predicates needed by the special case code.

    Use predmode declarations in some other places.

NEWS:
    Mention the new library predicates.

compiler/mercury_compile_main.m:
    Invoke the predicate in instmap.m that, if statistics collection
    was enabled, appends its results to a file.

tools/restrict_stats:
    A script to summarize the contents of that file.
2022-04-02 16:35:18 +11:00
Zoltan Somogyi
f8429e128e Put types before in insts in argument lists. 2021-12-17 14:12:53 +11:00
Zoltan Somogyi
cdf8fd8367 Move inst merging code to inst_merge.m.
compiler/instmap.m:
    Delete code moved to inst_merge.m.

compiler/inst_merge.m:
    Add the code moved from instmap.m. Give the predicates involved
    names that fit in better with their new home, and improve their
    documentation a bit. Replace a bool with a bespoke type.
2021-12-17 13:04:10 +11:00
Zoltan Somogyi
ac05623367 Associate a type with an inst.
Many predicates working on the inst of a variable (or part of the value of
a variable) need to know the type of (that part of) the variable, but
in some contexts, the type is not available at compile time. (One instance
is the type of an existentially typed argument.) Because of this, the
compiler used to pass a maybe(mer_type) with each mer_inst.

Act on an old XXX to change this to pass a mer_type with each mer_inst,
with the mer_type being a type variable if the type is not known statically.
This is conceptually cleaner, and should also be faster, due to avoiding
yes() wrappers in the usual case where the type *is* available.

compiler/inst_match.m:
compiler/inst_merge.m:
compiler/inst_test.m:
    As above.

compiler/inst_util.m:
    Update the names as well as the types of two utility predicates.

    Add a function for returning the canonical representation of no type
    information being available.

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

compiler/type_util.m:
    Add a new utility predicate for use by inst_match.m. The old code
    in inst_match.m called a nondet predicate as a semidet test
    by throwing away all its output arguments. The new utility predicate
    avoids the wasted work of constructing those arguments.
2021-12-17 11:40:56 +11:00
Zoltan Somogyi
d76c7bf617 Break up inst_util.m and mode_util.m.
This step significantly improves module cohesion.

compiler/inst_abstract_unify.m:
    New module carved out of inst_util.m, which does abstract unifications
    on insts.

compiler/inst_merge.m:
    New module carved out of inst_util.m, which merges insts.

compiler/inst_lookup.m:
    New module carved partly out of inst_util.m and partly out of mode_util.m,
    which looks up insts in the module_info, and then possibly expands out
    the result.

compiler/mode_test.m:
    New module carved out of mode_util.m, whose predicates
    perform tests on modes.

compiler/mode_top_functor.m:
    New module carved out of mode_util.m, which computes top_functor_modes
    from modes.

compiler/inst_mode_type_prop.m:
    New module carved out of mode_util.m, which propagates type information
    into both insts and modes.

compiler/recompute_instmap_deltas.m:
    New module carved out of mode_util.m, which recomputes goals'
    instmap_deltas.

compiler/inst_test.m:
    Move here the predicates in inst_util.m that perform tests on insts.

compiler/inst_util.m:
compiler/mode_util.m:
    Delete the code that this diff moves to other modules.

compiler/check_hlds.m:
    Add the new modules to the check_hlds package, the package that also
    contains inst_util.m and mode_util.m. (Some of these modules could
    be argued to fit better in the hlds package, but moving them there
    would not be desirable while they depend on code that is still in the
    check_hlds package.)

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

compiler/add_pragma_tabling.m:
compiler/arg_info.m:
compiler/bytecode_gen.m:
compiler/closure_analysis.m:
compiler/complexity.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/det_report.m:
compiler/direct_arg_in_out.m:
compiler/distance_granularity.m:
compiler/equiv_type_hlds.m:
compiler/error_msg_inst.m:
compiler/fact_table.m:
compiler/float_regs.m:
compiler/follow_code.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_pred.m:
compiler/hlds_rtti.m:
compiler/inlining.m:
compiler/inst_match.m:
compiler/inst_user.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/interval.m:
compiler/introduce_exists_casts.m:
compiler/lambda.m:
compiler/lco.m:
compiler/liveness.m:
compiler/lookup_util.m:
compiler/loop_inv.m:
compiler/mark_tail_calls.m:
compiler/ml_args_util.m:
compiler/ml_code_util.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_util.m:
compiler/mode_constraints.m:
compiler/mode_errors.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/oisu_check.m:
compiler/par_conj_gen.m:
compiler/pd_util.m:
compiler/post_typecheck.m:
compiler/pragma_c_gen.m:
compiler/proc_requests.m:
compiler/prog_rep.m:
compiler/push_goals_together.m:
compiler/rbmm.region_transformation.m:
compiler/saved_vars.m:
compiler/simplify_goal_switch.m:
compiler/simplify_proc.m:
compiler/size_prof.m:
compiler/ssdebug.m:
compiler/stack_opt.m:
compiler/stm_expand.m:
compiler/stratify.m:
compiler/structure_reuse.versions.m:
compiler/structure_sharing.domain.m:
compiler/superhomogeneous.m:
compiler/table_gen.m:
compiler/term_constr_build.m:
compiler/term_pass2.m:
compiler/term_util.m:
compiler/tupling.m:
compiler/unify_gen_construct.m:
compiler/unify_gen_util.m:
compiler/unique_modes.m:
compiler/unneeded_code.m:
compiler/untupling.m:
compiler/unused_args.m:
    Conform to the changes above by importing the required new modules,
    sometimes in addition to inst_util.m or mode_util.m, but more usually
    instead of them.
2021-12-16 01:31:35 +11:00
Zoltan Somogyi
1ce46c2797 Pair lambda arg vars with their modes.
compiler/hlds_goal.m:
    This enforces the invariant that the there is one mode par argument var.

    Document that that "nonlocals" field of the lambda actually contains
    the variables that will be put into the closure.

compiler/assertion.m:
compiler/build_mode_constraints.m:
compiler/check_promise.m:
compiler/cse_detection.m:
compiler/dead_proc_elim.m:
compiler/delay_partial_inst.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/float_regs.m:
compiler/format_call.m:
compiler/goal_path.m:
compiler/goal_util.m:
compiler/hhf.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_util.m:
compiler/hlds_statistics.m:
compiler/implementation_defined_literals.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/lco.m:
compiler/loop_inv.m:
compiler/make_hlds_warn.m:
compiler/mode_constraints.m:
compiler/mode_errors.m:
compiler/mode_ordering.m:
compiler/mode_util.m:
compiler/modecheck_unify.m:
compiler/old_type_constraints.m:
compiler/polymorphism.m:
compiler/polymorphism_lambda.m:
compiler/pre_quantification.m:
compiler/purity.m:
compiler/qual_info.m:
compiler/quantification.m:
compiler/simplify_goal_unify.m:
compiler/stratify.m:
compiler/superhomogeneous.m:
compiler/switch_detection.m:
compiler/try_expand.m:
compiler/typecheck.m:
compiler/unused_args.m:
compiler/unused_imports.m:
    Conform to the change above.
2021-08-21 17:49:42 +10:00
Zoltan Somogyi
a818e42cb9 Put bigger/slower-varying inputs before others.
compiler/inst_match.m:
compiler/inst_test.m:
    As above.

compiler/common.m:
compiler/constraint.m:
compiler/goal_mode.m:
compiler/hlds_pred.m:
compiler/inst_util.m:
compiler/instmap.m:
compiler/mode_comparison.m:
compiler/mode_errors.m:
compiler/mode_util.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/pd_info.m:
compiler/simplify_goal_disj.m:
compiler/unique_modes.m:
compiler/unused_args.m:
    Conform to the changes above.
2021-06-14 16:48:19 +10:00
Zoltan Somogyi
c3f39870a1 Clean up the representation of mode errors.
compiler/mode_errors.m:
    Give the function symbols representing the various kinds of mode errors
    more meaningful names. (Some fix misleading implications, such as when
    a function symbol name includes "pred", but the error applies to functions
    as well.) Do the same for other function symbols in this module.

    Where arguments are lists that should never be empty, change their type
    to one_or_more to encode this invariant.

    In one case (var_multimode_pred_error), the same data items were packaged
    in two different ways in two different places. Remove this unnecessary
    difference.

    In some cases, put arguments in a more logical order.

    Improve the comments on most of these function symbols, fixing errors,
    fixing omissions, documenting arguments. Add XXXs where warranted.

    Put the types used in the various kinds of mode errors below the
    mode_error type itself. Put them into meaningful groups.

    The current order of the mode_error function symbols is totally
    haphazard. Propose a new order for them, but do not implement it yet,
    in order to make this diff easier to review.

    Make the representation of the error that says "calling an implied mode
    for this predicate or function is not implemented" say *why* it is
    not implemented. Include this info in the error message we generate.
    This error message is not exercised by any existing test case, which is
    why there are no changes to test cases in this diff.

    Improve the explanation for why you cannot unify two functions or
    two predicates. Since this explanation occurs only in verbose output,
    no test case is affected by this change either.

    Improve variable names.

compiler/mode_info.m:
    Conform to the changes in mode_errors.m.

    If --debug-modes is specified, print each error message as it is added
    to the mode_info. This helped me track down a bug in this change.

compiler/instmap.m:
compiler/modecheck_call.m:
compiler/modecheck_conj.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
    Conform to the changes in mode_errors.m and/or mode_info.m.

    Add XXXs in some places. One marks one possible cause of Mantis bug #529.
2021-02-24 15:34:18 +11:00
Zoltan Somogyi
1161d09948 Make a loop tail recursive. 2020-12-29 19:40:27 +11:00
Zoltan Somogyi
4c071079ad Clarify code. 2020-11-30 17:33:07 +11:00
Zoltan Somogyi
5457e1c772 Improve merge_var_insts.
Put its arguments into a standard order, avoid some repeated nil/cons tests,
and add a sanity check.
2020-07-01 18:27:40 +10:00
Zoltan Somogyi
f7dfaed412 Put related predicates next to each other. 2020-07-01 00:23:15 +10:00
Zoltan Somogyi
df9420c3e6 Flatten the unify_mode structure.
compiler/hlds_goal.m:
    Change the unify_mode structure from

        unify_modes_lhs_rhs(from_to_insts(LI, LF), from_to_insts(RI, RF))

    to

        unify_modes_li_lf_ri_rf(LI, LF, RI, RF)

    This requires fewer memory allocations (1 vs 3) and less memory
    (4 words vs 6), though the performance improvement is too small
    to measure.

    It should also require writing fewer function symbols in code.

compiler/instmap.m:
compiler/mode_util.m:
    For each utility predicate that works with from_to_insts, provide
    a version that works with the separate insts contained in it.
    Delete the from_to_insts version if no longer needed.

compiler/prog_mode.m:
    Delete utility predicates on from_to_insts that are not needed anymore.

compiler/accumulator.m:
compiler/add_pred.m:
compiler/bytecode_gen.m:
compiler/common.m:
compiler/const_prop.m:
compiler/deep_profiling.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/equiv_type_hlds.m:
compiler/erl_unify_gen.m:
compiler/float_regs.m:
compiler/format_call.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_mode.m:
compiler/interval.m:
compiler/lambda.m:
compiler/lco.m:
compiler/make_goal.m:
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_util.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/polymorphism.m:
compiler/proc_requests.m:
compiler/prog_rep.m:
compiler/rbmm.region_transformation.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_scope.m:
compiler/simplify_goal_switch.m:
compiler/size_prof.m:
compiler/stm_expand.m:
compiler/term_util.m:
compiler/unify_gen_construct.m:
compiler/unify_gen_util.m:
compiler/unused_args.m:
    Conform to the changes above.
2019-10-27 02:53:46 +11:00
Zoltan Somogyi
d9dbc33243 Put instmap.m's contents into a logical order. 2019-09-02 11:44:06 +10:00
Zoltan Somogyi
17d684a11e Better arg orders in instmap.m.
compiler/instmap.m:
    Replace a non-state-var-friendly and a state-var-friendly pair
    of predicates with just one state-var-friendly predicate.

    Improve the arg order of another predicate as well.

    Improve documentation.

compiler/accumulator.m:
compiler/call_gen.m:
compiler/code_loc_dep.m:
compiler/constraint.m:
compiler/cse_detection.m:
compiler/delay_construct.m:
compiler/dep_par_conj.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/float_regs.m:
compiler/goal_mode.m:
compiler/goal_util.m:
compiler/hlds_pred.m:
compiler/introduce_parallelism.m:
compiler/lookup_util.m:
compiler/loop_inv.m:
compiler/mode_util.m:
compiler/modecheck_unify.m:
compiler/par_conj_gen.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/prog_rep.m:
compiler/stm_expand.m:
compiler/transform.m:
compiler/try_expand.m:
compiler/unneeded_code.m:
    Conform to the change above. Delete unneeded module qualifications.
2019-08-24 17:18:14 +10:00
Zoltan Somogyi
973de69bdd Delete stray comment. 2018-10-09 06:41:57 +11:00
Zoltan Somogyi
15aa457e12 Delete $module arg from calls to unexpected. 2018-04-07 18:25:43 +10:00
Zoltan Somogyi
cfcfde1db7 Simplify the representation of modes of unifications.
Unifications (x = y) have long had two descriptions of their modes.
One is the unify_mode, which used to look like this:
    (initx -> finalx) - (inity -> finaly)
and other is the uni_mode, which used to look like this:
    (initx - inity) -> (finalx - finaly)
Each unification had one unify_mode, and each unification that includes
a function symbol had one uni_mode per argument of that function symbol.

The two forms of mode information looked similar enough to be easily
confusable, but were subtly different. As it turns out, there was no
particular reason for the difference, so this diff eliminates the
uni_mode type, and the difference along with it.

What rationale there was for the uni_mode type was that the two modes
it represented (one for each side of the unification) both had their
initial and final insts directly available. This is not true for modes
in general: a value of the mer_mode type could have the form
"InitInst -> FinalInst" (which this diff renames "from_to_mode(InitInst,
FinalInst)", but could also be a "user_defined_inst(...)", which required
a table lookup to turn it into an initial/final pair of insts. This matters,
because almost all code that processes the modes of unifications
works with the initial and final insts.

This diff therefore creates a new type, from_to_insts, which represents
mode information only in the form of terms such as "from_to_insts(InitInst,
FinalInst)", and makes a unify_mode take two values of this type, not mer_mode,
as arguments.

As discussed on m-rev, this diff also renames the old, deceptively named
"arg_mode" type: its new name is "top_functor_mode".

compiler/prog_data.m:
compiler/hlds_goal.m:
    As mentioned above, avoid using "->" as a function symbol, and replace
    both -> and - with bespoke function symbols.

compiler/mode_util.m:
    Add some utility predicates and functions on the new types, and
    delete the old utility routines that operated on uni_modes.

    Code that uses the new functions and predicates should have a higher level
    of abstraction than the code that used to do the same job "manually".

compiler/*.m:
    Conform to the changes above, using the new utility predicates and
    functions where relevant. In several cases, this required fixing
    confusion of the kind described at the top. In all but one case,
    the confusion affected only variable names, but in one case,
    deconstruct_functor in make_goal.m, it caused a bug. The bug has
    had no effect up till now because deconstruct_functor is called
    only from three places: try_expand.m, stm_expand.m, and untupling.m.
    The incorrect mode (which was the nonsensical ground -> free)
    generated by the code of try_expand.m itself was discarded and
    overwritten when try_expand.m invoked the modechecker. (I don't
    know whether this bugfix makes that invocation redundant or not.)
    The other two modules, stm_expand.m and untupling.m, may do something
    similar, but in any case, they don't yet work for other reasons.
    (A bootcheck with --untupling causes a compiler abort when compiling
    deep_profiler/query.m in stage 2 both without and with this fix.)

    Delete no-longer-needed imports of the pair module (and of some other
    modules).

    Put the arguments of some predicates into a more logical order.

    In bytecode_gen.m, replace clauses with disjunctions, and delete the
    arguments that this step has revealed to be unused.
2016-05-19 10:43:24 +10:00
Mark Brown
b2ae55c29c Change 'none' to 'none_or_default_func' in ho_inst_info.
This value of ho_inst_info is used for first-order values as well as
for functions that have the default inst, and the new name better
reflects that.

Places using this value have been checked for correctness. Issues that
need to be looked at have been marked with XXX, although have not been
addressed in this change.

compiler/prog_data.m:
	Update the type.

compiler/inst_match.m:
	Add XXX comments. This module needs to check for non-default
	function insts in a bunch of places.

compiler/inst_util.m:
	Add XXX comments. We lose information about non-default function
	insts when merging bound and any. The information needs to be
	either preserved or disallowed entirely.

compiler/float_regs.m:
	Add XXX comments. This module may miss cases involving default
	function insts.

compiler/modecheck_unify.m:
	Add XXX comment. We should exclude pred and non-default func
	lambda non-locals from becoming locked, an addition to default
	functions.

compiler/*.m:
	No special handling is required for other modules.
2015-11-16 21:13:04 +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
Mark Brown
7f5a08eb37 Split parts of inst_match.m into a new module, inst_test.m
Most modules that imported inst_match did so in order to use
predicates such as inst_is_ground to test properties of insts.
These predicates are split into a new module, leaving the more
complex parts of inst_match to be imported in fewer places.
This makes it easier to change inst_match (for example, to
address mantis bug 264) without unintentional changes to
the rest of the compiler.

compiler/inst_test.m:
    New module containing code from inst_match.m.

compiler/check_hlds.m:
    Include the new module.

compiler/inst_match.m:
    Move code to the new module.

compiler/inst_util.m:
    Move inst_expand and inst_expand_and_remove_constrained_inst_vars
    here rather than the new module, since they make more sense here.

compiler/build_mode_constraints.m:
compiler/cse_detection.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/det_report.m:
compiler/fact_table.m:
compiler/float_regs.m:
compiler/goal_util.m:
compiler/interval.m:
compiler/loop_inv.m:
compiler/modecheck_goal.m:
compiler/pd_util.m:
compiler/prog_rep.m:
compiler/simplify_goal_call.m:
compiler/size_prof.m:
compiler/stm_expand.m:
compiler/structure_sharing.domain.m:
compiler/switch_detection.m:
compiler/term_util.m:
compiler/trace_gen.m:
compiler/unify_proc.m:
compiler/unneeded_code.m:
    Only import inst_test.

compiler/common.m:
compiler/instmap.m:
compiler/mode_util.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/simplify_goal_disj.m:
    Import inst_test in addition to inst_match.

compiler/lco.m:
compiler/simplify_goal_switch.m:
    Import inst_test and inst_util, but not inst_match.
2015-11-06 20:52:25 +11:00
Zoltan Somogyi
c5b64d36ea Convert (C->T;E) to (if C then T else E). 2015-10-18 08:21:53 +11:00
Zoltan Somogyi
62ec97d443 Report imports shadowed by other imports.
If a module has two or more import_module or use_module declarations
for the same module, (typically, but not always, one being in its interface
and one in its implementation), generate an informational message about
each redundant declaration if --warn-unused-imports is enabled.

compiler/hlds_module.m:
    We used to record the set of imported/used modules, and the set of
    modules imported/used in the interface of the current module. However,
    these sets

    - did not record the distinction between imports and uses;
    - did not allow distinction between single and multiple imports/uses;
    - did not record the locations of the imports/uses.

    The first distinction was needed only by module_qual.m, which *did*
    pay attention to it; the other two were not needed at all.

    To generate messages for imports/uses shadowing other imports/uses,
    we need all three, so change the data structure storing such information
    for *direct* imports to one that records all three of the above kinds
    of information. (For imports made by read-in interface and optimization
    files, the old set of modules approach is fine, and this diff leaves
    the set of thus *indirectly* imported module names alone.)

compiler/unused_imports.m:
    Use the extra information now available to generate a
    severity_informational message about any import or use that is made
    redundant by an earlier, more general import or use.

    Fix two bugs in the code that generated warnings for just plain unused
    modules.

    (1) It did not consider that a use of the builtin type char justified
    an import of char.m, but without that import, the type is not visible.

    (2) It scanned cons_ids in goals in procedure bodies, but did not scan
    cons_ids that have been put into the const_struct_db. (I did not update
    the code here when I added the const_struct_db.)

    Also, add a (hopefully temporary) workaround for a bug in
    make_hlds_passes.m, which is noted below.

    However, there are at least three problems that prevent us from enabling
    --warn-unused-imports by default.

    (1) In some places, the import of a module is used only by clauses for
    a predicate that also has foreign procs. When compiled in a grade that
    selects one of those foreign_procs as the implementation of the predicate,
    the clauses are discarded *without* being added to the HLDS at all.
    This leads unused_imports.m to generate an uncalled-for warning in such
    cases. To fix this, we would need to preserve the Mercury clauses for
    *all* predicates, even those with foreign procs, and do all the semantic
    checks on them before throwing them away. (I tried to do this once, and
    failed, but the task should be easier after the item list change.)

    (2) We have two pieces of code to generate import warnings. The one in
    unused_imports.m operates on the HLDS after type and mode checking,
    while module_qual.m operates on the parse tree before the creation of
    the HLDS. The former is more powerful, since it knows e.g. what types and
    modes are used in the bodies of predicates, and hence can generate warnings
    about an import being unused *anywhere* in a module, as opposed to just
    unused in its interface.

    If --warn-unused-imports is enabled, we will get two separate set of
    reports about an interface import being unused in the interface,
    *unless* we get a type or mode error, in which case unused_imports.m
    won't be invoked. But in case we do get such errors, we don't want to
    throw away the warnings from module_qual.m. We could store them and
    throw them away only after we know we won't need them, or just get
    the two modules to generate identical error_specs for each warning,
    so that the sort_and_remove_dups of the error specs will do the
    throwing away for us for free, if we get that far.

    (3) The valid/bug100.m test case was added as a regression test for a bug
    that was fixed in module_qual.m. However the bug is still present in
    unused_imports.m.

compiler/make_hlds_passes.m:
    Give hlds_module.m the extra information it now needs for each item_avail.

    Add an XXX for a bug that cannot be fixed right now: the setting of
    the status of abstract instances to abstract_imported. (The "abstract"
    part is correct; the "imported" part may not be.)

compiler/intermod.m:
compiler/try_expand.m:
compiler/xml_documentation.m:
    Conform to the change in hlds_module.m.

compiler/module_qual.m:
    Update the documentation of the relationship of this module
    with unused_imports.m.

compiler/hlds_data.m:
    Document a problem with the status of instance definitions.

compiler/hlds_out_module.m:
    Update the code that prints out the module_info to conform to the change
    to hlds_module.m.

    Print status information about instances, which was needed to diagnose
    one of the bugs in unused_imports.m. Format the output for instances
    nicer.

compiler/prog_item.m:
    Add a convenience predicate.

compiler/prog_data.m:
    Remove a type synonym that makes things harder to understand, not easier.

compiler/modules.m:
    Delete an XXX that asks for the feature this diff implements.
    Add another XXX about how that feature could be improved.

compiler/Mercury.options.m:
    Add some more modules to the list of modules on which the compiler
    should be invoked with --no-warn-unused-imports.

compiler/*.m:
library/*.m:
mdbcomp/*.m:
browser/*.m:
deep_profiler/*.m:
mfilterjavac/*.m:
    Delete unneeded imports. Many of these shadow other imports, and some
    are just plain unneeded, as shown by --warn-unused-imports. In a few
    modules, there were a *lot* of unneeded imports, but most had just
    one or two.

    In a few cases, removing an import from a module, because it *itself*
    does not need it, required adding that same import to those of its
    submodules which *do* need it.

    In a few cases, conform to other changes above.

tests/invalid/Mercury.options:
    Test the generation of messages about import shadowing on the existing
    import_in_parent.m test case (although it was also tested very thoroughly
    when giving me the information needed for the deletion of all the
    unneeded imports above).

tests/*/*.{m,*exp}:
    Delete unneeded imports, and update any expected error messages
    to expect the now-smaller line numbers.
2015-08-25 00:38:49 +10:00
Zoltan Somogyi
04dec8c205 Carve vartypes.m, prog_detism.m and prog_rename.m out of prog_data.m.
Besides defining most of the types representing the smaller parts of
parse trees (parts smaller than items), prog_data.m also has many utility
predicates that operate on values of these types. Carve the three substantial
clusters of predicates out of prog_data.m, and move them into their own
modules, which are each imported by fewer modules than prog_data.m itself.

compiler/vartypes.m:
    New module containing the vartypes type and the predicates that operate
    on it. The new module has *much* better cohesion than the old prog_data.m.

    The vartypes type does not appear in any parse tree; it is used only
    in the HLDS. So make vartypes.m part of the hlds.m package, not
    parse_tree.m.

    Move three predicates that perform renamings and substitutions on vartypes
    here from prog_type_subst.m, since the latter is part of the parse_tree.m
    package, and thus doesn't have access to hlds.vartypes. Make private
    the service predicate that these three moved predicates used to rely on,
    since it has no other callers.

compiler/prog_detism.m:
    New module containing utility predicates that operate on determinisms
    and determinism components.

compiler/prog_rename.m:
    New module containing utility predicates that rename variables in
    various data structures.

compiler/prog_data.m:
    Remove the stuff now in the three new modules.

compiler/prog_type_subst.m:
    Remove the three predicates now in vartypes.m.

compiler/mercury_to_mercury.m:
    Delete an unneded predicate, which was the only part of this module
    that referred to vartypes.

compiler/prog_type.m:
compiler/builtin_lib_types.m:
compiler/type_util.m:
    Move some utility predicates that refer to vartypes from prog_type.m
    and builtin_lib_types.m (both part of parse_tree.m) to type_util.m
    (part of check_hlds.m).

compiler/parse_tree.m:
compiler/hlds.m:
compiler/notes/compiler_design.html:
    Mention the new modules.

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/arg_info.m:
compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/clause_to_proc.m:
compiler/closure_analysis.m:
compiler/code_info.m:
compiler/code_loc_dep.m:
compiler/common.m:
compiler/complexity.m:
compiler/const_prop.m:
compiler/constraint.m:
compiler/continuation_info.m:
compiler/coverage_profiling.m:
compiler/cse_detection.m:
compiler/ctgc.datastruct.m:
compiler/ctgc.util.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/disj_gen.m:
compiler/equiv_type_hlds.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/exception_analysis.m:
compiler/float_regs.m:
compiler/follow_code.m:
compiler/follow_vars.m:
compiler/format_call.m:
compiler/goal_expr_to_goal.m:
compiler/goal_path.m:
compiler/goal_store.m:
compiler/goal_util.m:
compiler/headvar_names.m:
compiler/hhf.m:
compiler/higher_order.m:
compiler/hlds_clauses.m:
compiler/hlds_goal.m:
compiler/hlds_llds.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_module.m:
compiler/hlds_out_pred.m:
compiler/hlds_pred.m:
compiler/hlds_rtti.m:
compiler/inlining.m:
compiler/inst_util.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/interval.m:
compiler/lambda.m:
compiler/lco.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/lookup_switch.m:
compiler/make_goal.m:
compiler/mark_tail_calls.m:
compiler/ml_accurate_gc.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_disj_gen.m:
compiler/ml_gen_info.m:
compiler/ml_lookup_switch.m:
compiler/ml_proc_gen.m:
compiler/ml_unify_gen.m:
compiler/mode_constraints.m:
compiler/mode_info.m:
compiler/mode_util.m:
compiler/modecheck_call.m:
compiler/modecheck_conj.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/par_loop_control.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/prog_rep.m:
compiler/prop_mode_constraints.m:
compiler/purity.m:
compiler/qual_info.m:
compiler/quantification.m:
compiler/rbmm.points_to_graph.m:
compiler/rbmm.points_to_info.m:
compiler/rbmm.region_liveness_info.m:
compiler/rbmm.region_transformation.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/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.indirect.m:
compiler/structure_reuse.lbu.m:
compiler/structure_reuse.lfu.m:
compiler/structure_sharing.analysis.m:
compiler/structure_sharing.domain.m:
compiler/switch_detection.m:
compiler/table_gen.m:
compiler/tabling_analysis.m:
compiler/term_constr_build.m:
compiler/term_constr_initial.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/try_expand.m:
compiler/tupling.m:
compiler/type_assign.m:
compiler/type_constraints.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unneeded_code.m:
compiler/untupling.m:
compiler/unused_args.m:
compiler/var_locn.m:
    Conform to the above changes, mostly by importing some of the
    three new modules as well as, or instead of, prog_data.m.
2015-08-09 19:02:12 +10:00
Zoltan Somogyi
89628ae791 More speedups of inst handling code.
On tools/speedtest -l -m, my tests show a speedup of about 2%, but
on Dirk's stress test module, for which the compiler (used to) spend
almost all its time handling insts, the speedup is about 40%.

This diff also contains some small incidental changes I stumbled upon
the "need" for while working on the main change.

compiler/prog_data.m:
    The existing inst_test_results type used to be able to hold the results
    of four tests about a bound inst. Add two more: the set of inst vars that
    may occur in the inst, and whether a type constructor has already been
    propagated into the cons_ids of the bound insts.

    Put the fields of the the unify_inst and merge_inst inst_names into
    a more sensible order.

    Define types that hold the information stored in specific kinds of
    inst_names, for use by hlds_data.m (see below).

compiler/inst_user.m:
    For each user defined bound inst that matches exactly one parameterless
    type, propagate its type constructor into it, and record the fact that
    it has been done. This avoids having to do it many times later.
    Also record the set of inst vars in each inst, again to avoid having
    to repeat the test many times later.

compiler/mercury_compile_front_end.m:
    Invoke the inst_user module as soon after inst_check.m as we can.

compiler/hlds_data.m:
    Make the structure of six subtables of the inst table private, to allow
    them to be experimented with (and possibly changed) without code changes
    being required in other modules.

    The unify_inst_table, the ground_inst_table and the any_inst_table
    used to be maps whose keys were inst_names, but they were each only ever
    used with one kind of inst_name. Change their keys to the new types
    unify_inst_info, ground_inst_info and any_inst_info, which each contain
    the information in the unify_inst, ground_inst and any_inst inst_names
    respectively. That way, the searches in the maps will perform comparisons
    that don't need to switch on what kind of inst_name they are dealing with,
    and instead go directly to comparing the arguments.

    With the unify_inst_table, also go a step further. The unify_inst_info
    has two fields that are equivalent to booleans. Comparing these
    at every level of the map is wasteful, so switch the representation
    of the unify_inst_table from one map to four maps, one map for each
    possible combination of those booleans. This way, the two booleans
    in the unify_inst_info key are tested just once, when the applicable map
    is selected.

    The merge_inst_table used to have a pair of insts as keys. Replace that
    with the merge_inst_info type, which also holds a pair of insts,
    but on which comparisons should be a bit faster, since it is not
    polymorphic, and thus does not need an implicit typeinfo passed along.

    Provide a combined search_insert operation on each of the inst_tables,
    since their pattern of use is exactly that: search the table, and if
    the key is not found, insert a marker that says the entry is being
    worked on. This avoid one traversal of a possibly-large tree, with
    its associated (possibly very expensive) comparisons.

    For each inst table, provide conversion predicates to and from
    sorted association lists, for use by equiv_type_hlds.m

compiler/equiv_type_hlds.m:
    Expand equivalence types in the new structure of the inst tables.

compiler/inst_util.m:
    Use the new search_insert predicates for the various inst_tables.

    If one of the two insts being unified is free, then avoid using
    the unify_inst_table, since just doing the abstract unification
    is faster, and does not pollute the unify_inst_table.

    If both insts being merged are bound insts, then avoid using the
    merge_inst_table, since (a) the lookup is slower than just doing
    the merge, and (b) it can pollute the merge_inst_table to the extent
    that *all other lookups* in it become very slow.

compiler/inst_match.m:
    Use test result information in bound insts to speed up the corresponding
    tests.

compiler/set_of_var.m:
    Change the representation of sets of vars back to sparse_bitsets.
    I changed them to tree_bitsets several years ago to avoid some bad
    worst-case behavior with sparse_bitsets (which occurred when repeatedly
    appending to the "ends" of sets), but other algorithmic changes have
    since avoiding using set_of_vars in ways that induce that behavior,
    and now my benchmarking tells me that the bottleneck operation is
    conversion of set_of_vars to lists of vars. This is faster with
    sparse_bitsets, since unlike tree_bitsets, they don't have to unravel
    a tree structure.

compiler/mode_util.m:
    Export a predicate now needed by inst_user.m, and clean up the code a bit,
    factoring out repeated code.

compiler/modecheck_util.m:
    Modify an equality comparison of two insts to compare the instantiation
    states themselves, but NOT the test results about those instantiation
    states, since these can differ if the two insts have different histories.

compiler/hlds_code_util.m:
compiler/hlds_out_mode.m:
compiler/hlds_out_module.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/polymorphism.m:
compiler/prog_mode.m:
compiler/recompilation.usage.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the changes above.

The following changes are mostly incidental.

compiler/hlds_args.m:
    Speed up a predicate by avoiding the materialization of a list
    that is needed only for a test.

compiler/instmap.m:
    Clarify some code.

compiler/liveness.m:
    Avoid computing some value when it is not needed.

compiler/mode_errors.m:
    Avoid referring to "arguments" (plural) for errors involving *one*
    argument.

compiler/mode_info.m:
    Move the documentation of some predicates to their declarations.

compiler/modecheck_unify.m:
    Compute some data closer to where it is needed, to reduce the number
    of stack slots needed.

tests/invalid/constrained_poly_insts2.err_exp:
    Expect the updated error message from mode_errors.m (with "argument"
    in singular), as well as module qualified insts, since having inst_user.m
    push type_ctors into the definitions of named inst module qualifies
    the bound_insts inside those definitions.
2015-03-05 20:01:00 +11:00
Zoltan Somogyi
fcb5c42092 Speed up merging instmaps slightly.
compiler/instmap.m:
    Construct yes(Type) only once instead of many times.
2014-09-09 05:35:51 +02:00
Zoltan Somogyi
4b44c29c2e Fix mantis bug 311.
compiler/simplify_goal_disj.m:
    Look for the conditions that lead to the bug (a disjunction that
    further instantiates an already partially instantiated variable).
    Generate an error message when found, PROVIDED that this happens
    in a context in which the surrounding procedure can succeed
    more than once. (If it cannot, then you cannot invoke an all-solutions
    predicate on it, and the bug cannot happen.)

    This condition (a model_non surrounding procedure) was motivated
    by mdbcomp/feedback.m, which does not compile without it.

compiler/simplify_info.m:
    The simplify_info type used to contain four different kinds of fields:

    1 static fields; set and then never changed, such as the id of the
      containing procedure
    2 global information, such as the varset and vartypes, which are updated
      as new variable are added, and whose updates need to be kept regardless
      of what part of the procedure is analyzed next
    3 information about the context surrounding the goal currently being
      analyzed, such as the number of lambda expressions we are inside
    4 information about the point in the code before the goal currently being
      analyzed, such as the set of equivalences that currently hold between
      variables (part of common_info).

    The code of the simplify_goal*.m modules used to have jump through hoops
    to handle 3 and 4 properly, given that the simplify_info was being
    threaded through code in a way that was suitable only for 1 and 2.

    This change takes categories 3 and 4 out of the simplify_info.
    It creates a new type, simplify_nested_context, for category 3,
    and adds information about the ability of the procedure surrounding
    the current point to succeed more than once (needed for the bug311 fix)
    to this new type.

compiler/simplify_tasks.m:
    Rename the do_once task to mark_code_model_changes, since this
    expresses what the task is much less ambiguously.

compiler/simplify_goal*.m:
compiler/simplify_proc.m:
compiler/common.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
    Conform to the changes to simplify_info (and simplify_tasks).
    Pass the current instmap and common_info (the two category 4 fields)
    separately.

    Mark some places that could be improved.

compiler/hlds_out_mode.m:
    Generate easier-to-understand debugging output. I needed this to track
    down a bug in my initial fix.

compiler/inst_match.m:
    Remove a redundant unification that couldn't fail (since it was invoked
    only if the exact same unification succeeded a few lines earlier).
    Apply another minor optimizations.

compiler/instmap.m:
    Remove references to the alias branch. It won't be coming back.

compiler/error_util.m:
    Fix some documentation.

mdbcomp/feedback.m:
    Put related stuff together.

tests/warnings/bug311.{m,err_exp}:
    New test case for the bug.

tests/warnings/Mmakefile:
    Enable the new test case.
2014-07-30 12:10:39 +02:00
Zoltan Somogyi
28c66f3358 Make the error messages that report mismatches in insts between different
Estimated hours taken: 4
Branches: main

Make the error messages that report mismatches in insts between different
branches of a branched control structure more useful, by reporting not just
the insts of the relevant variable at end of each branch, but also the
location of each branch. This makes it MUCH easier to interpret error
messages about large disjunctions and switches.

compiler/mode_errors.m:
	Change the representation of errors of the above kind to include
	the context of each inst, and print the contexts next to the insts.

compiler/instmap.m:
	Give the predicates that merge instmaps the context of the goals
	that the instmaps are talking about, so that if there are any errors,
	these contexts can be given to mode_errors.m.

	Remove the predicate instmap_unify and its helper predicates, since
	it is not used anywhere.

compiler/modecheck_goal.m:
compiler/unique_modes.m:
	Associate a context with each instmap before calling instmap.m
	to merge those instmaps.

compiler/mercury_to_mercury.m:
	Switch the order of the arguments of some functions and predicates
	to make it easier to curry them; mode_errors.m wants this
	functionality.

compiler/hlds_out_mode.m:
compiler/hlds_out_module.m:
compiler/prog_ctgc.m:
	Conform to the changes above.

tests/invalid/merge_inst_error.{m,err_exp}:
	New test case to test the new functionality.

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

tests/invalid/multimode_dcg.err_exp:
	Update this expected output as well.
2012-11-09 05:20:44 +00:00
Zoltan Somogyi
6d1bc24d0b Make vartypes an abstract data type, in preparation for exploring
Estimated hours taken: 4
Branches: main

compiler/prog_data.m:
	Make vartypes an abstract data type, in preparation for exploring
	better representations for it.

compiler/mode_util.m:
	Provide two different versions of a predicate. The generic version
	continues to use map lookups. The other version knows it works on
	prog_vars, so it can use the abstract operations on them provided
	by prog_data.m.

compiler/accumulator.m:
compiler/add_class.m:
compiler/add_heap_ops.m:
compiler/add_pragma.m:
compiler/add_pred.m:
compiler/add_trail_ops.m:
compiler/arg_info.m:
compiler/builtin_lib_types.m:
compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/clause_to_proc.m:
compiler/closure_analysis.m:
compiler/code_info.m:
compiler/common.m:
compiler/complexity.m:
compiler/const_prop.m:
compiler/constraint.m:
compiler/continuation_info.m:
compiler/cse_detection.m:
compiler/ctgc.datastruct.m:
compiler/ctgc.util.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/det_util.m:
compiler/disj_gen.m:
compiler/equiv_type_hlds.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/exception_analysis.m:
compiler/float_regs.m:
compiler/follow_vars.m:
compiler/format_call.m:
compiler/goal_path.m:
compiler/goal_util.m:
compiler/hhf.m:
compiler/higher_order.m:
compiler/hlds_clauses.m:
compiler/hlds_goal.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_pred.m:
compiler/hlds_pred.m:
compiler/hlds_rtti.m:
compiler/inlining.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/interval.m:
compiler/lambda.m:
compiler/lco.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/lookup_switch.m:
compiler/mercury_to_mercury.m:
compiler/ml_accurate_gc.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_disj_gen.m:
compiler/ml_lookup_switch.m:
compiler/ml_proc_gen.m:
compiler/ml_unify_gen.m:
compiler/mode_info.m:
compiler/modecheck_call.m:
compiler/modecheck_conj.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
compiler/par_loop_control.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/prog_type_subst.m:
compiler/prop_mode_constraints.m:
compiler/purity.m:
compiler/qual_info.m:
compiler/rbmm.points_to_info.m:
compiler/rbmm.region_liveness_info.m:
compiler/rbmm.region_transformation.m:
compiler/saved_vars.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/ssdebug.m:
compiler/stack_alloc.m:
compiler/stack_opt.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.indirect.m:
compiler/structure_sharing.analysis.m:
compiler/structure_sharing.domain.m:
compiler/switch_detection.m:
compiler/table_gen.m:
compiler/term_constr_build.m:
compiler/term_constr_util.m:
compiler/term_traversal.m:
compiler/term_util.m:
compiler/trace_gen.m:
compiler/trailing_analysis.m:
compiler/try_expand.m:
compiler/tupling.m:
compiler/type_constraints.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
compiler/typecheck_info.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/untupling.m:
compiler/unused_args.m:
compiler/var_locn.m:
	Conform to the above.

compiler/prog_type.m:
compiler/rbmm.points_to_graph.m:
	Conform to the above.

	Move some comments where they belong.

compiler/stm_expand.m:
	Conform to the above.

	Do not export a predicate that is not used outside this module.

	Disable some debugging output unless it is asked for.

	Remove unnecessary prefixes on variable names.

library/version_array.m:
	Instead writing code for field access lookalike functions and defining
	lookup, set etc in terms of them, write code for lookup, set etc,
	and define the field access lookalike functions in terms of them.

	Change argument orders of some internal predicates to be
	more state variable friendly.

	Fix typos in comments.

tests/hard_coded/version_array_test.exp:
	Conform to the change to version_array.m.
2012-07-02 01:16:39 +00:00
Zoltan Somogyi
30383a8c47 Avoid some redundant work during determinism analysis.
Estimated hours taken: 3
Branches: main

Avoid some redundant work during determinism analysis. This diff speeds up
tools/speedtest by just shy of 0.7%.

compiler/det_analysis.m:
	Instead of (a) getting a list of procedures in the module and then
	(b) classifying them into three categories, do both jobs at once.
	This avoids some redundant traversals and map lookups, and avoids
	the creation of an intermediate data structure.

compiler/instmap.m:
	Instead of converting a set into a list and iterating over that list
	to check that elements of the set have a given property, iterate over
	the set elements directly.

	Put the arguments of a predicate in a more logical order.

compiler/det_util.m:
	Conform to the change in instmap.m.

compiler/set_of_var.m:
	Provide the all_true predicate needed by det_util.

library/*set*.m:
	In every module that implements sets, provide an all_true predicate.

NEWS:
	Mention the new predicates in the library.
2012-04-24 09:18:29 +00:00
Zoltan Somogyi
d00ea69529 Switch from using set(prog_var), which is represented using set_ordlist,
Estimated hours taken: 12
Branches: main

Switch from using set(prog_var), which is represented using set_ordlist,
to set_of_progvar, which is represented using tree_bitset, for most sets
of variables in the compiler, including the nonlocals sets in goal_infos.

This diff yields about a 5% speedup when compiling the training_cars_full.m
stress test, but also about a 1% slowdown on tools/speedtest. Both of these
are with the current default state in which tree_bitset is compiled with
a whole bunch of sanity checks. If these are disabled, we get roughly a 1%
speedup on tools/speedtest. I intend to disable those sanity checks after
a shakedown period of a week or two in which the updated version of the
compiler is installed on our platforms.

compiler/hlds_goal.m:
	Replace almost all occurrences of set(prog_var) with set_of_progvar.
	The main exceptions are the types supporting rbmm.

compiler/set_of_var.m:
	Add some more predicates and functions that previous existed on sets
	but not yet on set_of_vars.

compiler/*.m:
	Conform to the change in hlds_goal.m, and make similar changes
	in set representations.

library/bag.m:
	Add a predicate and function for creating a bag from a sorted list.
	We already had them for creating a bag from a set, but a set_of_progvar
	shouldn't have to be converted to a set.

library/robdd.m:
	Fix deviations from our programming style.
2011-08-16 03:26:40 +00:00
Julien Fischer
9ae7fe6b70 Change the argument ordering of predicates in the set module.
Branches: main

Change the argument ordering of predicates in the set module.

library/set.m:
	Change predicate argument orders to match the versions
	in the svset module.

	Group function definitions with the corresponding predicates
	rather than at the end of the file.

	Delete Ralph's comments regarding the argument order in the
	module interface: readers of the library reference guide are
	unlikely to be interested in his opinion of the argument ordering
	ten or so years ago.

	Add extra modes for set.map/3 and set.map_fold/5.

library/svset.m:
library/eqvclass.m:
library/tree234.m:
library/varset.m:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
mdbcomp/trace_counts.m:
extras/moose/grammar.m:
extras/moose/lalr.m:
extras/moose/moose.m:
tests/hard_coded/bitset_tester.m:
	Conform to the above change.

NEWS:
	Announce the above changes.
2011-05-06 05:03:29 +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
d0bc6f93d8 Fix some things I found while chasing Mantis bug 103.
Estimated hours taken: 0.5
Branches: main

Fix some things I found while chasing Mantis bug 103.

compiler/handle_options.m:
	Add a dump alias to make debugging lco easier.

compiler/instmap.m:
	Add a utility predicate for use by (a now-unneeded version of) lco.m.

compiler/unify_gen.m:
	Minor cleanups.

library/require.m:
	Add four-argument versions of expect and expect_not, to allow
	all uses of this_file to be replaced by $module, $pred.

NEWS:
	Document the new predicates in require.m, as well as expect_not/3,
	which I added earlier.
2011-03-08 07:45:30 +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
3e4eaaa594 Fix typo.
Estimated hours taken: 0.1
Branches: main

compiler/instmap.m:
	Fix typo.
2010-10-01 04:31:18 +00:00
Paul Bone
c877dceb2b Refactor profiler feedback code for implicit parallelism.
This change mostly re-factors the goal representation used to feedback implicit
parallelism information to the compiler.  The goal_rep datatype is now used
rather than the much simpler datatype.  (goal_rep is the same type that is used
by the declarative debugger).

This makes it easier for the compiler to match HLDS goals against goals from
the implicit parallelism analysis and will probably help in the future if the
analysis wants the compiler to re-order goals.

It also makes it easier to pretty-print the feedback sent to the compiler in
more detail.

mdbcomp/feedback.m:
    As above, redefine pard_goal as a type alias to
    goal_rep(pard_goal_annotation).

    Added a new type, candidate_par_conjunctions_proc, it represents candidate
    parallelisations within a procedure along with shared information for the
    procedure.

    Add a new predicate, convert_candidate_par_conjunctions_proc.

    Increment the feedback file format version number.

mdbcomp/program_representation.m:
    XXX: See about refactoring bytecode in/out put into one place.

    Add a new predicate transform_goal_rep for transforming a goal_rep
    structure from one arbitrary annotation type to another.

    Add extra predicates to aid in converting a prog_rep structure to and from
    bytecode.  This includes cut_byte/2 and can_fail_byte/2.

deep_profiler/program_representation_utils.m:
    Export print_goal_to_strings/4 so that it can be used when printing the
    feedback file reports.

deep_profiler/mdprof_fb.automatic_parallelism.m:
    Conform to changes in mdbcomp/feedback.m

    Wrap some lines at 76 characters.

    Improve explanations in comments.

    Use the goal_rep pretty-printer to print the candidate parallel
    conjunctions feedback report.

deep_profiler/mdprof_feedback.m:
    Conform to changes in deep_profiler/mdprof_fb.automatic_parallelism.m

deep_profiler/program_representation_utils.m:
    Modify print_goal_to_strings to print determinisms and annotations on
    separate lines before each goal.

deep_profiler/display_report.m:
    Modify pretty printing of coverage annotations so that they make sense
    after modifying print_goal_to_strings/4.

compiler/implicit_parallelism.m:
    Refactor goal matching code that compares HLDS goals to feedback goals.
    Goal matching is now more accurate and can more easily support goal
    re-ordering when parallelising code (this is not implemented yet).

    The code that builds parallel conjunctions has also been refactored.

    This pass now generates warnings if it is not able to parallelise
    a candidate parallel conjunction in the feedback data.

    Insert deeper and later parallelizations before shallower or earlier ones,
    this makes it easier to continue to parallelise a procedure as it's goal
    tree changes due to parallelisation.

    Silently ignore duplicate candidate parallel conjunctions.

    Refuse to parallelise a procedure that has been parallelized explicitly.

compiler/prog_rep.m:
    Re-factor the hlds_goal to bytecode transformation, this transformation now
    goes via goal_rep.  We use the hlds_goal to goal_rep portion of this
    transformation in compiler/implicit_parallelism.m.

    Add variable names prefixed with DCG_ to the list of those introduced by
    the compiler.

compiler/goal_util.m:
    Modify maybe_transform_goal_at_goal_path so that it returns a value that
    can describe the different kinds of error that may be encountered.

    Add a new predicate, maybe_transform_goal_at_goal_path_with_instmap.  Given
    a goal, goal path and initial inst map this predicate recurses the goal
    structure following the goal path and maintaining the inst map.  It then
    uses a higher order value to transform the goal at it's destination before
    re-constructing the goal.  It is different to
    maybe_transform_goal_at_goal_path in that it passes the instmap to it's
    higher order argument, the instmap is correct for the state immediately
    before executing the goal in question.

compiler/hlds_pred.m:
    Include the procedure's varset in the information used to construct the
    program representation data that is included in deep profiling builds.

compiler/instmap.m:
    Add a useful function, apply_instmap_delta_sv.  This is the same as
    apply_instmap_delta except that it's arguments are in a more convenient
    order for state variable notation.

compiler/stack_layout.m:
    Export compute_var_number_map for the use of implicit_parallelism.m and
    prog_rep.m

compiler/error_util.m:
    Add a new error phase, 'phase_auto_parallelism'.  This is used for warnings
    issued from the automatic parallelisation transformation.

compiler/deep_profiling.m:
    Conform to changes in hlds_pred.m

compiler/mercury_compile_middle_passes.m:
    Conform to changes in implicit_parallelism.m

compiler/type_constraints.m:
    Conform to changes in goal_util.
2010-07-04 10:24:09 +00:00
Zoltan Somogyi
02f9532cc1 Optimize calls to formatting functions and predicates such as
Estimated hours taken: 16
Branches: main

Optimize calls to formatting functions and predicates such as

	Str = string.format("%s_%d", [s(Prefix), i(Num)])

into
	V1 = string.int_to_string(Num),
	V2 = "_" ++ V1,
	Str = Prefix ++ V2

essentially interpreting the format string at compile time rather than runtime.

At the moment, the optimization applies to calls to string.format/3,
io.format/3 and io.format/4, and only in the case where the format specifiers
are just "%c", "%d", or "%s", with no widths, precisions etc, though
that could be changed relatively easily, though at the cost of coupling
the compiler more tightly to the implementation of library/string.m.
(We don't handle %f, because float_to_string(F) yields a different string
than string.format("%f", [f(F)]). The former yields e.g. "1.23", while the
latter yields "1.23000".)

compiler/format_call.m:
	Change the code that looks for malformed calls to formatting predicates
	to also look for well-formed, optimizable calls, and to transform them
	as shown above.

mdbcomp/prim_data.m:
	List the standard library's string module here, since the compiler now
	needs to know what its name is (it generates calls to its predicates).

compiler/options.m:
doc/user_guide.texi:
	Add a new option, --optimize-format-calls, that calls for this
	optimization. Make it enabled by default.

compiler/simplify.m:
	Since the transformation in format_call.m will typically introduce
	nested conjunctions, we now do it before the rest of the
	simplifications. We also invoke the fixups needed by the output
	of format_call.m if it actually optimized any code.

	Delete the code that used to record whether the procedure has any
	format calls, since it now comes too late.

	Decide once, when setting up for processing a procedure, whether
	we want to invoke format_call.m if appropriate, instead of doing it
	later. This allows us to reduce the size of the simplications
	data structure we pass around.

	Protect the predicates that format_call.m can generate calls to
	from being deleted by dead_pred_elim before the simplification pass.

compiler/det_analysis.m:
	Since simplify.m itself cannot record early enough whether a given
	procedure body contains calls to formatting predicates, do it here.

compiler/det_info.m:
	Add a new field to the det_info that records whether we have seen
	a call to a formatting predicate.

	Add another field to the det_info that records the list of errors
	we have found so far, so that we can stop passing it around separately.

compiler/hlds_pred.m:
	Add a marker that allows det_analysis.m to record its conclusions.

compiler/hlds_goal.m:
	Add utility predicate.

compiler/goal_util.m:
	Make the predicates for creating new plain calls (and, for the sake of
	uniformity, calls to foreign code) take instmap_deltas, such as those
	created by the new utility functions in instmap.m. This allows these
	predicates' caller to avoid creating unnecessary intermediate data
	structures.

compiler/instmap.m:
	Make an existing predicate into a function to allow it to be used
	more flexibly.

	Move some utility functions for creating instmap_deltas here from
	table_gen.m, so that they can be used by other modules.

compiler/liveness.m:
	Delete an unused predicate.

compiler/accumulator.m:
compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/builtin_lib_types.m:
compiler/common.m:
compiler/complexity.m:
compiler/deep_profiling.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/det_report.m:
compiler/distance_granularity.m:
compiler/granularity.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/pd_util.m:
compiler/prog_type.m:
compiler/purity.m:
compiler/rbmm.region_transformation.m:
compiler/size_prof.m:
compiler/ssdebug.m:
compiler/table_gen.m:
compiler/try_expand.m:
compiler/typecheck.m:
compiler/unify_proc.m:
	Conform to the changes above.

compiler/stm_expand.m:
	Conform to the changes above. Also, build pairs by using "-" directly
	as the function symbol, instead of this module's old practice
	of doing it the slow way by calling the "pair" function.

tests/general/string_format_lib.m:
	Cleanup the style of the code of this test case.

tests/hard_coded/opt_format.{m,exp}:
	New test case to exercise the behavior of format_call.m's
	transformation.

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
	Enable the new test case.
2009-09-03 23:57:51 +00:00
Zoltan Somogyi
d69ba1a1f0 Include the type_ctor in cons_ids for user-defined types.
Estimated hours taken: 32
Branches: main

Include the type_ctor in cons_ids for user-defined types. The intention is
two-fold:

- It prepares for a future in which we allow more than one function symbol to
  with the same name to be defined in a module.

- It makes the HLDS code more self-contained. In many places, processing
  construction and deconstruction unifications required knowing which type
  the cons_id belongs to, but until now, code couldn't know that unless it
  kept track of the type of the variable unified with the cons_id.

With this diff, user-defined cons_ids are represented as

	cons(SymName, Arity, TypeCtor)

The last field is filled in during post-typecheck. After that time, any module
qualification in the SymName (which may initially be partial) is redundant,
since it is also available in the TypeCtor.

In the future, we could make all those SymNames be just unqualified(_) at that
time. We could also replace the current maps in HLDS type definitions with
full cons_id keys with just name/arity keys (since the module qualifier is a
given for any given type definition), we could also support partially
qualified cons_ids in source code using a map from name/arity pairs to a list
of all the type_ctors that have function symbols with that name/arity, instead
of our current practice of inserting all possible partially module qualified
version of every cons_id into a single giant table, and we could do the same
thing with the field names table.

This diff also separates tuples out from user-defined types, since in many
respects they are different (they don't have a single type_ctor, for starters).
It also separates out character constants, since they were alreay treated
specially in most places, though not in some places where they *ought* to
have been treated specially. Take the opportunity to give some other cons_ids
better names.

compiler/prog_data.m:
	Make the change described above, and document it.

	Put the implementations of the predicates declared in each part
	of this module next to the declarations, instead of keeping all the
	code until the very end (where it was usually far from their
	declarations).

	Remove three predicates with identical definitions from inst_match.m,
	inst_util.m and mode_constraints.m, and put the common definition
	in prog_data.m.

library/term_io.m:
	Add a new predicate that is basically a reversible version of
	the existing function espaced_char, since the definition of char_consts
	needs reversibilty.

compiler/post_typecheck.m:
	For functors of user-defined types, record their type_ctor. For tuples
	and char constants, record them as such.

compiler/builtin_lib_types.m:
compiler/parse_tree.m:
compiler/notes/compiler_design.html:
	New module to centralize knowledge about builtin types, specially
	handled library types, and their function symbols. Previously,
	the stuff now in this module used to be in several different places,
	including prog_type.m and stm_expand.m, and some of it was duplicated.

mdbcomp/prim_data.m:
	Add some predicates now needed by builtin_lib_types.m.

compiler/builtin_ops.m:
	Factor out some duplicated code.

compiler/add_type.m:
	Include the relevant type_ctors in the cons_ids generated in type
	definitions.

compiler/hlds_data.m:
	Document an existing type better.

	Rename a cons_tag in sync with its corresponding cons_id.

	Put some declarations into logical order.

compiler/hlds_out.m:
	Rename a misleadingly-named predicate.

compiler/prog_ctgc.m:
compiler/term_constr_build.m:
	Add XXXs for questionable existing code.

compiler/add_clause.m:
compiler/add_heap_ops.m:
compiler/add_pragma.m:
compiler/add_pred.m:
compiler/add_trail_ops.m:
compiler/assertion.m:
compiler/bytecode_gen.m:
compiler/closure_analysis.m:
compiler/code_info.m:
compiler/complexity.m:
compiler/ctgc_selector.m:
compiler/dead_proc_elim.m:
compiler/deep_profiling.m:
compiler/delay_partial_inst.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/distance_granularity.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
compiler/export.m:
compiler/field_access.m:
compiler/foreign.m:
compiler/format_call.m:
compiler/hhf.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_desc.m:
compiler/hlds_goal.m:
compiler/implementation_defined_literals.m:
compiler/inst_check.m:
compiler/inst_graph.m:
compiler/inst_match.m:
compiler/inst_util.m:
compiler/instmap.m:
compiler/intermod.m:
compiler/interval.m:
compiler/lambda.m:
compiler/lco.m:
compiler/make_tags.m:
compiler/mercury_compile.m:
compiler/mercury_to_mercury.m:
compiler/middle_rec.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_switch_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
compiler/mode_constraints.m:
compiler/mode_errors.m:
compiler/mode_ordering.m:
compiler/mode_util.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/module_qual.m:
compiler/polymorphism.m:
compiler/prog_ctgc.m:
compiler/prog_event.m:
compiler/prog_io_util.m:
compiler/prog_mode.m:
compiler/prog_mutable.m:
compiler/prog_out.m:
compiler/prog_type.m:
compiler/prog_util.m:
compiler/purity.m:
compiler/qual_info.m:
compiler/rbmm.add_rbmm_goal_infos.m:
compiler/rbmm.execution_path.m:
compiler/rbmm.points_to_analysis.m:
compiler/rbmm.region_transformation.m:
compiler/recompilation.usage.m:
compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/simplify.m:
compiler/simplify.m:
compiler/special_pred.m:
compiler/ssdebug.m:
compiler/stack_opt.m:
compiler/stm_expand.m:
compiler/stratify.m:
compiler/structure_reuse.direct.detect_garbagem:
compiler/superhomoegenous.m:
compiler/switch_detection.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_constr_build.m:
compiler/term_norm.m:
compiler/try_expand.m:
compiler/type_constraints.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/typecheck_errors.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unify_modes.m:
compiler/untupling.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
	Minor changes, mostly to ignore the type_ctor in cons_ids in places
	where it is not needed, take the type_ctor from the cons_id in places
	where it is more convenient, conform to the new names of some cons_ids,
	conform to the changes in hlds_out.m, and/or add now-needed imports
	of builtin_lib_types.m.

	In some places, the handling previously applied to cons/2 (which
	included tuples and character constants as well as user-defined
	function symbols) is now applied only to user-defined function symbols
	or to user-defined function symbols and tuples, as appropriate,
	with character constants being handled more like the other kinds of
	constants.

	In inst_match.m, rename a whole bunch of predicates to avoid
	ambiguities.

	In prog_util.m, remove two predicates that did almost nothing yet were
	far too easy to misuse.
2009-06-11 07:00:38 +00:00
Zoltan Somogyi
ea84652184 "Fix" a problem whose workaround by Julien was committed recently.
Estimated hours taken: 6
Branches: main

"Fix" a problem whose workaround by Julien was committed recently.
The immediate symptom was a code generator abort caused by a model_non goal
in a model_det context: a det procedure whose body was multi. The reason
why the body was multi was that a disjunction with no outputs was not
recognized as having no outputs, because instmap_delta_no_output_vars_2
does not succeed if the old and new insts of a variable specify non-overlapping
sets of function symbols.

This diff does not fix the actual problem (though it does document it),
but it does make it much less likely to occur by making the mishandled
situation much less likely to occur.

compiler/instmap.m:
	Document the problem with instmap_delta_no_output_vars_2.
	Simplify the code of instmap_delta_no_output_vars_2.

compiler/mode_util.m:
	When recomputing instmap_deltas of deconstruction unifications,
	abstractly unify the inst of the LHS variable before and after
	the deconstruction. If the cons_id does not appear among the possible
	cons_ids in the old inst, this will make the final inst not_reached,
	and avoid the problem situation for later.

compiler/Mercury.options:
	Remove Julien's workaround, since it is not needed anymore.

doc/user_guide.texi:
	Document the --dump-hlds-options a bit better. This helped in tracking
	down the problem.

tests/hard_coded/Mmakefile:
	Reenable an old test that this change now enables us to pass.

The following are style fixes only.

compiler/compile_target_code.m:
	Fix formatting in the code affected by the workaround.

compiler/handle_options.m:
	Add a dump alias to help diagnose determinism problems.

compiler/inlining.m:
compiler/inst_util.m:
	Minor style fixes.

compiler/inst_match.m:
	Put the predicates into more logical groups.

	Move documentation of exported predicates from the implementation
	section to the interface section.

	Add a prefix to field names, to avoid ambiguity.

	Avoid the use of with_type and with_inst.

	Avoid the use of faux field accesses when it makes the actual
	steps harder to understand.

	Make the initial values of inst_match_info explicit.

	Abort when the lists of a cons_id's argument variables and argument
	modes are of different lengths.
2009-01-28 06:57:51 +00:00
Zoltan Somogyi
a11fc97c95 Add and use the capability of building 234 trees directly.
Estimated hours taken: 16
Branches: main

Add and use the capability of building 234 trees directly.

library/tree234.m:
	Add new predicates for converting sorted assoc lists (both ascending
	and descending) directly to trees. These should be significantly more
	efficient than the existing assoc_list_to_tree234 predicate, which
	does not assume sortedness, and thus inserts each element individually.
	The main source of the efficiency improvement is that we avoid the
	creation of lots of intermediate trees.

	Add some sanity check predicates in the part of the module that
	is not included in the documentation.

library/map.m:
	Add a new predicate for creating a map from a reverse sorted assoc
	list.

	Modify the existing predicate for creating a map from a sorted assoc
	list to use the new predicate in tree234.m, which should be more
	efficient.

	Since the new implementation of this predicate doesn't allow
	duplicates, modify map.old_merge, which cannot ensure the absence of
	duplicates, to call the old general implementation (which is not
	reliant on sortedness or duplicate-freedom) instead.

NEWS:
	Mention the publically visible new predicates, and the change in
	map.from_sorted_assoc_list.

compiler/code_info.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/var_locn.m:
	Use the new, faster predicates when possible.

compiler/hlds_goal.m:
compiler/instmap.m:
	Give some variables better names.

tests/hard_coded/tree234_sorted_insert.{m,exp}:
	New test case to check the new functionality.

tests/hard_coded/Mmakefile:
	Enable the new test case.
2009-01-02 03:12:09 +00:00