444 Commits

Author SHA1 Message Date
Zoltan Somogyi
ee9c7d3a84 Speed up bound vs ground inst checks.
The code that checks whether a bound inst wrapped around
a list of bound_functors matched the ground inst did several things
in a suboptimal fashion.

- It looked up the definition of the type constructor of the relevant type
  (the type of the variable the inst is for) more than once. (This was
  not easily visible because the lookups were in different predicates.)
  This diff factors these out, not for the immesurably small speedup,
  but to make possible the fixes for the next two issues.

- To simplify the "is there a bound_functor for each constructor in the type"
  check, it sorted the constructors of the type by name and arity. (Lists of
  bound_functors are always sorted by name and arity.) Given that most
  modules contain more than one bound inst for any given type constructor,
  any sorting after the first was unnecessarily repeated work. This diff
  therefore extends the representation of du types, which until now has
  include only a list of the data constructors in the type definition
  in definition order, with a list of those exact same data constructors
  in name/arity order.

- Even if a list of bound_functors lists all the constructors of a type,
  the bound inst containing them is not equivalent to ground if the inst
  of some argument of some bound_inst is not equivalent to ground.
  This means that we need to know the actual argument of each constructor.
  The du type definition lists argument types that refer to the type
  constructor's type parameters; we need the instances of these argument types
  that apply to type of the variable at hand, which usually binds concrete
  types to those type parameters.

  We used to apply the type-parameter-to-actual-type substitution to
  each argument of each data constructor in the type before we compared
  the resulting filled-in data constructor descriptions against the list of
  bound_functors. However, in cases where the comparison fails, the
  substitution applications to arguments beyond the point of failure
  are all wasted work. This diff therefore applies the substitution
  only when its result is about to be needed.

This diff leads to a speedup of about 3.5% on tools/speedtest,
and about 38% (yes, more than a third) when compiling options.m.

compiler/hlds_data.m:
    Add the new field to the representation of du types.

    Add a utility predicate that helps construct that field, since it is
    now needed by two modules (add_type.m and equiv_type_hlds.m).

    Delete two functions that were used only by det_check_switch.m,
    which this diff moves to that module (in modified form).

compiler/inst_match.m:
    Implement the first and third changes listed above, and take advantage
    of the second.

    The old call to all_du_ctor_arg_types, which this diff replaces,
    effectively lied about the list of constructors it returned,
    by simply not returning any constructors containing existentially
    quantified  types, on the grounds that they "were not handled yet".
    We now fail explicitly when we find any such constructors.

    Perform the check for one-to-one match between bound_functors and
    constructors with less argument passing.

compiler/det_check_switch.m:
    Move the code deleted from hlds_data.m here, and simplify it,
    taking advantage of the new field in du types.

compiler/Mercury.options:
    Specify --optimize-constructor-last-call for det_check_switch.m
    to optimize the updated moved code.

compiler/add_foreign_enum.m:
compiler/add_special_pred.m:
compiler/add_type.m:
compiler/check_typeclass.m:
compiler/code_info.m:
compiler/dead_proc_elim.m:
compiler/direct_arg_in_out.m:
compiler/du_type_layout.m:
compiler/equiv_type_hlds.m:
compiler/hlds_out_type_table.m:
compiler/inst_check.m:
compiler/intermod.m:
compiler/intermod_decide.m:
compiler/lookup_switch_util.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen_test.m:
compiler/ml_unify_gen_util.m:
compiler/mlds.m:
compiler/post_term_analysis.m:
compiler/recompilation.usage.m:
compiler/resolve_unify_functor.m:
compiler/simplify_goal_ite.m:
compiler/table_gen.m:
compiler/tag_switch_util.m:
compiler/term_norm.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/typecheck_coerce.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the changes above. This mostly means handling
    the new field in du types (usually by ignoring it).
2025-11-19 22:09:04 +11:00
Zoltan Somogyi
d8a31e574e Move six utility modules from check_hlds to hlds.
compiler/inst_lookup.m:
compiler/inst_mode_type_prop.m:
compiler/inst_test.m:
compiler/inst_util.m:
compiler/mode_util.m:
compiler/type_util.m:
    Move these modules from the check_hlds package to the hlds package.
    The reason is that all the content of five of these modules, and
    most of the content of one module (inst_util.m) is not used
    exclusively during semantic checking passes. (A later diff
    should deal with the exception.) Some are used by the pass that
    builds the initial HLDS, and all are used by middle-end and backend
    passes. The move therefore reduces the number of inappropriate imports
    of the check_hlds package.

compiler/check_hlds.m:
compiler/hlds.m:
    Effect the transfer.

compiler/*.m:
    Conform to the changes above.
2025-10-08 23:07:13 +11:00
Zoltan Somogyi
66d07e92fc Replace many calls to io.output_stream ...
... so that the following code can write to an *explicitly*, as opposed
to *implicitly*, specified stream.

compiler/code_gen.m:
compiler/code_info.m:
    Include the stream to which debug output should be written in the
    code_info structure. Move the predicate that tests whether we should
    generate debug output from code_loc_dep.m to code_info.m, since it
    belongs there.

compiler/code_loc_dep.m:
compiler/ite_gen.m:
compiler/proc_gen.m:
    Conform to the changes above.

compiler/typecheck_info.m:
    Include the stream to which debug output should be written in the
    relevant field of the typecheck_info structure.

compiler/unneeded_code.m:
    Include the stream to which debug output should be written in the
    uc_option_values structure.

compiler/dep_par_conj.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_middle_passes.m:
compiler/stack_opt.m:
compiler/typecheck.m:
compiler/typecheck_debug.m:
    Replace calls to io.output_stream with explicitly passed streams.
2023-10-18 08:47:35 +11:00
Zoltan Somogyi
a13a6d0f97 Carve hlds_proc_util.m out of hlds_pred.m.
compiler/hlds_pred.m:
compiler/hlds_proc_util.m:
    As above. hlds_proc_util.m now contains utility predicates
    that most modules that import hlds_pred.m don't need.
    (More than four times as many modules import hlds_pred.m
    as now import hlds_proc_util.m.)

compiler/*.m:
    Conform to the changes above.
2023-09-01 16:41:33 +10:00
Zoltan Somogyi
a6b885e02a Switch rbmm.*.m from vartypes to var_tables.
compiler/rbmm.add_rbmm_goal_infos.m:
compiler/rbmm.live_variable_analysis.m:
compiler/rbmm.region_liveness_info.m:
    As above.

compiler/type_util.m:
    Make is_region_var work only on var_tables, since all the code
    that needs it to operate on vartypes has been replaced.

compiler/prog_ctgc.m:
    Switch this module from operating on varsets to var_name_sources.
    The code in rbmm.*.m now uses var_tables, while the code that operates
    on the associated pragma items uses varsets; var_name_sources
    accommodate both.

compiler/parse_tree_out_pragma.m:
    Conform to the change in prog_ctgc.m.

compiler/hlds_out_pred.m:
    Conform to the change in prog_ctgc.m.

    Write out the variable type info in predicates and procedures using
    var_tables where possible.

    Print more information about the origin of unify/compare/index preds.

compiler/parse_tree_out_term.m:
    Add some utility routines that help generate the same output for
    variable names using var_tables as with varsets, factoring out
    their common code.

compiler/code_info.m:
    Conform to the change in type_util.m.
2022-05-15 00:16:26 +10:00
Zoltan Somogyi
d667194642 Introduce a new type for effective trace levels.
We have two main notions of trace levels. The first is the global trace level,
which is set by compiler options, and the second is the effective trace level
for a given procedure. The two are different not just in that the effective
trace level for a procedure may differ from the global trace level, but also
in that there exist effective trace levels that cannot be specified using
compiler options.

compiler/trace_params.m:
    Add the new type eff_trace_level for representing effective trace levels.
    (Old code has long used "Eff" as an abbreviation for "effective".)
    Use it where relevant.

    Delete functions that (a) first compute the effective trace level
    for a procedure, and (b) then test that effective trace level,
    and replace each of them with a function that does only (b).
    There was already a function that did only (a); rename it to avoid
    an ambiguity.

compiler/code_info.m:
    Store the effective trace level of the procedure being translated
    in the code_info, to save it from having to be recomputed many times.

compiler/code_loc_dep.m:
    Get the effective trace level for the procedure being compiled
    from code_info.

compiler/hlds_out_pred.m:
    Write out each procedure's effective trace level.

compiler/llds.m:
    Include the effective trace level in generated c_procs, for use by
    continuation_info.m.

compiler/continuation_info.m:
    Rename a predicate to avoid a name clash.

    Conform to the changes above.

compiler/handle_options.m:
    Note a non-problem.

compiler/globals.m:
compiler/layout.m:
compiler/layout_out.m:
compiler/liveness.m:
compiler/optimize.m:
compiler/proc_gen.m:
compiler/simplify_goal_conj.m:
compiler/simplify_goal_scope.m:
compiler/simplify_info.m:
compiler/stack_alloc.m:
compiler/stack_layout.m:
compiler/store_alloc.m:
compiler/trace_gen.m:
compiler/transform_llds.m:
    Conform to the changes above.

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

compiler/hlds_out_module.m:
    Simplify some code.

runtime/mercury_goto.h:
    Fix misplaced/wrong casts and stray backslashes in macros that are usually
    only used when debugging the debugger.
2022-05-01 05:34:10 +10:00
Zoltan Somogyi
d9db5d34e0 Convert more passes to var_tables,
compiler/introduce_parallelism.m:
compiler/table_gen.m:
    Convert these passes to use var_tables.

    Improve the argument order of some predicates.

compiler/stack_layout.m:
    Convert the code that constructs stack layouts to use var_tables.

compiler/hlds_pred.m:
    Convert a data structure used by these passes to store var_tables
    instead of varsets/vartypes.

    Generalize some utility predicates to take var_type_sources
    instead of var_types.

    Improve the argument order of some predicates.

compiler/continuation_info.m:
    Convert another data structure used by these passes to store var_tables
    instead of varsets/vartypes.

    Get the callers of some predicates to pass them just the data they need,
    instead of bigger structures from which they have to extract what they
    need. For now, extracting var_tables from proc_infos is expensive.
    And even if it were cheap, it is better for the caller to do it once
    per procedure than for it do be done several times per procedure.

    Improve the argument order of some predicates.

    Fix a copy-and-paste bug in a sanity test, which tested stack vars'
    offsets twice: one test should have been (and now is) for frame vars.

compiler/prog_rep.m:
    Convert another data structure used by these passes to store var_tables
    instead of varsets/vartypes.

    Improve the argument order of some predicates.

compiler/llds.m:
    Fix a very old bug in a comment.

compiler/code_info.m:
    Get the caller of code_info_init, proc_gen.m, to pass it a var_table,
    instead of computing it in code_info_init. This is because proc_gen.m
    now needs it too.

compiler/goal_util.m:
    Create a var_tablee version of another utility predicate.

compiler/deep_profiling.m:
compiler/proc_gen.m:
compiler/trace_gen.m:
    Conform to the changes above.
2022-04-18 15:04:40 +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
3f3045c9e2 Get and set varsets/vartypes in proc_infos together.
compiler/hlds_pred.m:
    We eventually want to replace the varset and vartypes fields in
    each proc_info with a var_table, but it is not practical to do so
    at once; it will have to be done gradually, a few modules at most
    at a time. During this process, we will need a way either

    - to let already converted modules get a var_table out of the proc_info,
      and put an updated var_table back into a proc_info, even though
      proc_infos still contain varset and vartypes fields, or

    - to let not-yet-converted modules get varsets and vartypes out of the
      proc_info, and put updated varsets and vartypes back into a proc_info,
      even though proc_infos already store a var_table.

    The latter cannot be done in two halves (i.e. set the varset half
    of the var_table, and then set its vartypes half), and while the former
    *can* be done that way, it is more efficient to do them at the same time.

    Therefore as a first step, this diff replaces the indiviual getter
    and setter predicates of the varset and vartypes fields of proc_info
    with a getter that gets both and a setter that sets both.

    Put the varset and vartypes next to each other in a structure.

compiler/code_info.m:
    Delete a function that duplicates a function in var_table.m.

    Conform to the change above.

compiler/det_report.m:
    Factor out some common code.

    Conform to the change above.

compiler/det_util.m:
    Delete a no-longer-needed predicate.

    Conform to the change above.

compiler/higher_order.m:
    Fix an old oversight: when deleting variables from the vartypes,
    delete them from the varset as well.

    Conform to the change above.

compiler/liveness.m:
    Avoid constructing and traversing a list unnecessarily.

    Conform to the change above.

compiler/accumulator.m:
compiler/add_heap_ops.m:
compiler/add_trail_ops.m:
compiler/arg_info.m:
compiler/build_mode_constraints.m:
compiler/bytecode_gen.m:
compiler/call_gen.m:
compiler/clause_to_proc.m:
compiler/closure_analysis.m:
compiler/code_gen.m:
compiler/code_loc_dep.m:
compiler/complexity.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/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/dep_par_conj.m:
compiler/det_analysis.m:
compiler/direct_arg_in_out.m:
compiler/disj_gen.m:
compiler/equiv_type_hlds.m:
compiler/exception_analysis.m:
compiler/float_regs.m:
compiler/follow_code.m:
compiler/goal_mode.m:
compiler/goal_path.m:
compiler/hlds_out_pred.m:
compiler/hlds_rtti.m:
compiler/hlds_statistics.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/intermod_analysis.m:
compiler/introduce_exists_casts.m:
compiler/introduce_parallelism.m:
compiler/lambda.m:
compiler/lco.m:
compiler/live_vars.m:
compiler/loop_inv.m:
compiler/mark_tail_calls.m:
compiler/ml_accurate_gc.m:
compiler/ml_args_util.m:
compiler/ml_closure_gen.m:
compiler/ml_gen_info.m:
compiler/ml_proc_gen.m:
compiler/mode_info.m:
compiler/modecheck_goal.m:
compiler/modes.m:
compiler/par_loop_control.m:
compiler/pd_debug.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/polymorphism_info.m:
compiler/proc_gen.m:
compiler/purity.m:
compiler/push_goals_together.m:
compiler/quantification.m:
compiler/rbmm.add_rbmm_goal_infos.m:
compiler/rbmm.live_variable_analysis.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/recompute_instmap_deltas.m:
compiler/saved_vars.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_errors.m:
compiler/term_pass1.m:
compiler/term_pass2.m:
compiler/trace_gen.m:
compiler/trailing_analysis.m:
compiler/try_expand.m:
compiler/tupling.m:
compiler/unneeded_code.m:
compiler/untupling.m:
compiler/unused_args.m:
compiler/unused_imports.m:
    Conform to the change above.
2022-04-07 21:22:21 +10:00
Zoltan Somogyi
99fa99fffe Use var_table.m in the LLDS code generator.
compiler/code_info.m:
    Replace the varset and vartypes fields of the code_info with a var_table.

compiler/var_table.m:
    Add some routines to format variable names in various ways.

compiler/arg_info.m:
    Delete an unneeded vartypes argument from a predicate.

    For some other predicates that took vartypes, create versions
    that take var_tables instead. Simplify the code of some of the
    duplicated predicates.

    Where some predicates took lists of variable and lists of their types,
    modify them to take either a vartypes or a var_table argument instead
    (in different versions). This

    - saves the memory needed for the list of types,
    - saves the traversal needed to build the list of types, and
    - avoids the possibility of a length mismatch between the two lists.

compiler/call_gen.m:
compiler/closure_gen.m:
compiler/code_gen.m:
compiler/code_loc_dep.m:
compiler/disj_gen.m:
compiler/follow_vars.m:
compiler/hlds_llds.m:
compiler/interval.m:
compiler/lco.m:
compiler/lookup_switch.m:
compiler/middle_rec.m:
compiler/ml_code_util.m:
compiler/pragma_c_gen.m:
compiler/proc_gen.m:
compiler/rbmm.region_liveness_info.m:
compiler/switch_gen.m:
compiler/trace_gen.m:
compiler/tupling.m:
compiler/type_util.m:
compiler/unify_gen_construct.m:
compiler/unify_gen_deconstruct.m:
    Conform to the changes above.
2022-03-28 11:36:49 +11:00
Zoltan Somogyi
8ebe125a6a Introduce var_table.m.
Most compiler passes need to know both the names and the types
of the variables they operate on. Until now, they had to pass along
two separate data structures for that, the varset and the vartypes,
and many operations required looking a variable up in both of these.

The var table is a single data structure that records for each variable

- its name, as the varset has traditionally done,
- its type, as the vartypes has traditionally done,
- the is_dummy_type flag which says whether its type is a dummy type,
  which traditionally had to computed afresh at each lookup.

Switch the MLDS code generator to use var_tables instead of varsets and
vartypes. The code generator often needs to know the name and the type
of a variable at the same time, and it often needs to know which variables'
types are dummies, often enough that precomputing this info should be a win.

compiler/var_table.m:
    Add this new module which defines the var_table.

    Its operations are modelled after the operation in var_types.m.

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

compiler/prog_type.m:
compiler/type_util.m:
    Move the is_dummy_type from type_util.m, which is in the
    check_hlds package, to prog_type.m, which in the parse_tree package,
    to avoid having this part of the hlds package depend on check_hlds.
    (It already depends on parse_tree, for a lot of different things.)

    Given a function and a predicate that each took a vartypes arg,
    make new versions that take a var_table arg instead.
    Rationalize the argument list of the function.

compiler/ml_gen_info.m:
    Replace the varset and vartypes fields of the ml_gen_info with a
    var_table field.

compiler/ml_code_util.m:
    Replace code that used to operate on varsets and vartypes with code
    that operates on var_tables.

    Create new versions of a few operations to exploit the info in var_tables.

    Give some predicates more meaningful names.

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_commit_gen.m:
compiler/ml_disj_gen.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_lookup_switch.m:
compiler/ml_proc_gen.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:
    Replace code that used to operate on varsets and vartypes with code
    that operates on var_tables.

    In ml_switch_gen.m and ml_tag_switch.m, put some predicates' arguments
    into an reasonable order by moving related args next to each other.

compiler/vartypes.m:
    Delete an operation that was only needed in the MLDS backend,
    in code that this diff replaces.

compiler/switch_util.m:
    Put the larger input first in the arg list of a predicate.

compiler/closure_gen.m:
compiler/code_info.m:
compiler/code_loc_dep.m:
compiler/export.m:
compiler/lambda.m:
compiler/live_vars.m:
compiler/liveness.m:
compiler/llds.m:
compiler/llds_out_instr.m:
compiler/mark_tail_calls.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/stack_alloc.m:
compiler/stack_layout.m:
compiler/tag_switch.m:
compiler/term_constr_util.m:
compiler/tupling.m:
compiler/unify_gen.m:
compiler/unify_gen_deconstruct.m:
compiler/var_locn.m:
    Conform to the changes above.
2022-03-28 10:20:49 +11:00
Zoltan Somogyi
254cd500bf Add bespoke type for du types' details.
compiler/hlds_data.m:
    As above. The other kinds of types already had bespoke types
    for *their* details.

compiler/add_type.m:
compiler/du_type_layout.m:
    Instead of passing values of the hlds_type_body with an inst
    that said they were du types, pass values of the new types instead,
    which is significantly simpler.

compiler/add_foreign_enum.m:
compiler/add_special_pred.m:
compiler/check_typeclass.m:
compiler/code_info.m:
compiler/dead_proc_elim.m:
compiler/det_report.m:
compiler/direct_arg_in_out.m:
compiler/equiv_type_hlds.m:
compiler/foreign.m:
compiler/hlds_out_module.m:
compiler/inst_check.m:
compiler/intermod.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen_test.m:
compiler/ml_unify_gen_util.m:
compiler/mlds.m:
compiler/mode_util.m:
compiler/post_term_analysis.m:
compiler/recompilation.usage.m:
compiler/resolve_unify_functor.m:
compiler/simplify_goal_ite.m:
compiler/special_pred.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_norm.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_proc.m:
compiler/untupling.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the changes above.
2021-07-01 08:26:04 +10:00
Zoltan Somogyi
5b97566f8c Make pred declaration and definition order match. 2021-03-25 04:27:30 +11:00
Peter Wang
74a31ba8ef Parse and check subtype definitions.
This is the first step towards implementing a subtypes feature.
It introduces type definitions of the form

    :- type subtype =< supertype ---> body.

Later, terms of a subtype should share a data representation with their
supertype, and it will be possible to convert terms between two types
that share "base types" using a coerce operation.

doc/reference_manual.texi:
    Add documentation for subtypes.

    Add documentation for a proposed `coerce' operation, commented out
    for now.

    Add "=<" to the list of reserved type names.

compiler/hlds_data.m:
    Add supertype field to hlds_du_type.

compiler/prog_data.m:
    Add du_supertype field to type_details_du.

    Add comment for future work.

compiler/parse_type_defn.m:
    Parse subtype definitions.

    Check that variables which occur in the "=< supertype" part
    also occur on the left hand side of the subtype definition.

compiler/parse_type_name.m:
    Add a new context for why_no_ho_inst_info.

    Add "=<" to is_known_type_name, i.e. prevent the user from defining
    a type of that name (any longer).

compiler/add_type.m:
    Rename add_du_ctors_check_foreign_type_for_cur_backend to
    add_du_ctors_check_subtype_check_foreign_type.

    In add_du_ctors_check_subtype_check_foreign_type, check that
    subtype definitions satisfy the conditions documented in the
    reference manual.

compiler/make_hlds_passes.m:
    Conform to previous renaming.

compiler/comp_unit_interface.m:
    Follow supertypes when computing the required type constructors
    whose definitions need to be kept in the implementation section
    of a .int file.

compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
    Replace equivalence types in supertypes.

compiler/module_qual.qualify_items.m:
    Perform module qualification in supertypes.

compiler/hlds_out_module.m:
    Write out the "=< supertype" part of subtype definitions.

compiler/parse_tree_out.m:
    Write out the "=< supertype" part of subtype definitions.

compiler/recompilation.usage.m:
    Follow supertypes when finding used items.

compiler/add_foreign_enum.m:
compiler/add_special_pred.m:
compiler/check_parse_tree_type_defns.m:
compiler/check_typeclass.m:
compiler/code_info.m:
compiler/dead_proc_elim.m:
compiler/decide_type_repn.m:
compiler/det_report.m:
compiler/direct_arg_in_out.m:
compiler/du_type_layout.m:
compiler/foreign.m:
compiler/inst_check.m:
compiler/intermod.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen_test.m:
compiler/ml_unify_gen_util.m:
compiler/post_term_analysis.m:
compiler/prog_type.m:
compiler/recompilation.check.m:
compiler/resolve_unify_functor.m:
compiler/simplify_goal_ite.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_norm.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to HLDS changes.

    Add comments for future work.

tests/invalid/Mmakefile:
tests/invalid/subtype_abstract.err_exp:
tests/invalid/subtype_abstract.m:
tests/invalid/subtype_circular.err_exp:
tests/invalid/subtype_circular.m:
tests/invalid/subtype_ctor_arg.err_exp:
tests/invalid/subtype_ctor_arg.m:
tests/invalid/subtype_eqv.err_exp:
tests/invalid/subtype_eqv.m:
tests/invalid/subtype_exist_constraints.err_exp:
tests/invalid/subtype_exist_constraints.m:
tests/invalid/subtype_exist_vars.err_exp:
tests/invalid/subtype_exist_vars.m:
tests/invalid/subtype_foreign.err_exp:
tests/invalid/subtype_foreign.m:
tests/invalid/subtype_foreign_supertype.err_exp:
tests/invalid/subtype_foreign_supertype.m:
tests/invalid/subtype_foreign_supertype2.err_exp:
tests/invalid/subtype_foreign_supertype2.err_exp2:
tests/invalid/subtype_foreign_supertype2.m:
tests/invalid/subtype_ho.err_exp:
tests/invalid/subtype_ho.m:
tests/invalid/subtype_invalid_supertype.err_exp:
tests/invalid/subtype_invalid_supertype.m:
tests/invalid/subtype_not_subset.err_exp:
tests/invalid/subtype_not_subset.m:
tests/invalid/subtype_syntax.err_exp:
tests/invalid/subtype_syntax.m:
tests/invalid_submodules/Mercury.options:
tests/invalid_submodules/Mmakefile:
tests/invalid_submodules/subtype_submodule.err_exp:
tests/invalid_submodules/subtype_submodule.m:
tests/valid/Mmakefile:
tests/valid/subtype_basic.m:
    Add test cases.
2021-03-15 11:16:31 +11:00
Zoltan Somogyi
0be7bdd5be Simplify implications of debugging.
compiler/handle_options.m:
    Having debugging enabled affects several classes of options the same way.
    Record this effect in one flag per class, not on every option
    separately.

compiler/trace_params.m:
    Replace given_trace_level_is_none, which used to return a bool, with
    is_exec_trace_enabled_at_given_trace_level, which now returns either
    exec_trace_is_not_enabled or exec_trace_is_enabled. This should
    allow peopl to read code calling the function without having to
    process double negatives in their head.

compiler/code_info.m:
compiler/code_loc_dep.m:
compiler/compile_target_code.m:
compiler/llds_out_file.m:
compiler/proc_gen.m:
compiler/trace_gen.m:
    Conform to the change to trace_params.m.

compiler/inlining.m:
    Conform to the change to trace_params.m by deleting any reference
    to trace levels. None of these references in the old code were used.
2020-10-13 01:54:43 +11:00
Zoltan Somogyi
91560d2dd7 Make --everything-in-one-c-function a bool option.
It used to be a special option that just set procs_per_c_function
to the special value of zero, but this behavior is inconsistent with
optimization_options taking the max of the old and new values of
integer options. This meant that --procs-per-c-function=5 -O6
would not put all procedures into one C function.

tools/make_optimization_options_db:
tools/make_optimization_options_end:
compiler/optimization_options.m:
    As above: make --everything-in-one-c-function a bool option,
    named use_just_one_c_func for brevity.

compiler/options.m:
    Move the code handling --everything-in-one-c-function next to the
    other optimization options.

compiler/mercury_compile_llds_back_end.m:
    When deciding which procedures should be put into which C functions,
    use the logic: if use_just_one_c_func, then put all procs into the
    same C function, otherwise, put them into one or more C functions
    with up to procs_per_c_function procedures per function.

    This is now the *only* place in the compiler that looks at
    procs_per_c_function; everywhere else looks at use_just_one_c_func.

compiler/code_util.m:
    Replace a maybe pair type that used to store the value of
    procs_per_c_function with a bespoke type storing use_just_one_c_func,
    which documents its meaning.

compiler/code_info.m:
    Replace a bool type with a bespoke type, again documenting
    its meaning.

compiler/call_gen.m:
compiler/closure_gen.m:
compiler/middle_rec.m:
compiler/pragma_c_gen.m:
compiler/proc_gen.m:
compiler/rtti_out.m:
    Conform to the changes above.

compiler/llds.m:
    Fix blank lines.
2020-09-29 10:25:42 +10:00
Zoltan Somogyi
181ada0dbf Avoid -O<n> resetting previously set options.
This implements Mantis feature request #495.

NEWS:
    Announce the change.

compiler/optimization_options.m:
    A new module for managing optimization options.

    It defines a separate bespoke type for every boolean optimization option
    to make it harder to confuse them. It defines a tuple type (opt_tuple)
    for accessing optimization options quickly. It implements the turning on
    (but NOT turning off) of optimizations when a given optimization level
    is selected.

tools/make_optimization_options_middle:
tools/make_optimization_options_db:
    The script that generates the meat of optimization_options.m,
    and the database of option names, kinds and initial values
    that it uses as its input. The script also generates some code
    for the special_handler predicate in compiler/options.m.

tools/make_optimization_options_start:
tools/make_optimization_options_end:
    The handwritten initial and final parts of optimization_options.m.

tools/make_optimization_options:
    The script that pulls these parts together to form optimization_options.m.

compiler/options.m:
    Make every optimization option a special option, to be handled by
    the special_handler predicate. That handling consists of simply
    adding a representation of the option to the end of a cord of
    optimization options, to be processed later by optimization_options.m.
    That processing will record the values of these options in the opt_tuple,
    which is where every other part of the compiler should get them from.

    Change the interface of special_handler to make the above possible.

    Add an "optopt_" (optimization option) prefix to the name of
    every optimization option, to make them inaccessible to the rest
    of the compiler under their old name, and thus help enforce the switch
    to using the opt_tuple. Any access to these options to look up
    their values would fail anyway, since the option data would no longer be
    e.g. bool(yes), but bool_special, but the name change makes this failure
    happen at compile time, not runtime.

    Reclassify a few options to make the above make sense. Some options
    (unneeded_code_debug, unneeded_code_debug_pred_name, and
    common_struct_preds) were classified as oc_opt even though they
    control only the *debugging* of optimizations, while some options
    (c_optimize and inline_alloc) were not classified as oc_opt
    even though we do set them automatically at some optimization levels.

    Delete the opt_level_number option, since it was not used anywhere.

    Delete the code for handling -ON and --opt-space, since that is now
    done in optimization_options.m.

    Add some XXXs.

compiler/handle_options.m:
    Switch to using getopt_io.process_options_userdata_se, as required
    by the new interface of the special_handler in options.m.
    In the absence of errors, invoke optimization_options.m to initialize
    the opt_tuple. Then update the opt_tuple incrementally when processing
    option implications that affect optimization options.

compiler/globals.m:
    Put the opt_tuple into a new field of the globals structure.

compiler/accumulator.m:
compiler/add_pragma_type_spec.m:
compiler/add_trail_ops.m:
compiler/code_info.m:
compiler/code_loc_dep.m:
compiler/compile_target_code.m:
compiler/const_struct.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/disj_gen.m:
compiler/erl_code_gen.m:
compiler/format_call.m:
compiler/global_data.m:
compiler/grab_modules.m:
compiler/higher_order.m:
compiler/hlds_pred.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/ite_gen.m:
compiler/jumpopt.m:
compiler/libs.m:
compiler/llds_out_code_addr.m:
compiler/llds_out_data.m:
compiler/llds_out_file.m:
compiler/llds_out_instr.m:
compiler/llds_out_util.m:
compiler/matching.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/ml_disj_gen.m:
compiler/ml_gen_info.m:
compiler/ml_lookup_switch.m:
compiler/ml_optimize.m:
compiler/ml_proc_gen.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen_construct.m:
compiler/optimize.m:
compiler/pd_util.m:
compiler/peephole.m:
compiler/polymorphism.m:
compiler/proc_gen.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_scope.m:
compiler/simplify_info.m:
compiler/simplify_proc.m:
compiler/simplify_tasks.m:
compiler/stack_layout.m:
compiler/stack_opt.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/tag_switch.m:
compiler/tupling.m:
compiler/unify_gen_construct.m:
compiler/unneeded_code.m:
compiler/unused_args.m:
    Conform to the changes above, mostly by looking up optimization options
    in the opt_tuple. In some places, replace bools containing optimization
    options with the bespoke type of that specific optimization option.

library/getopt_template:
    Fix a bug that screwed up an error message.

    The bug happened when processing a --file option. If one of the
    options in the file was a special option whose special handler failed,
    the code handling that failing option returned both an error indication,
    and the rest of the argument list read in from the file. The code
    handling the --file option then *ignored* the error indication from
    the failed special option, and returned an error message of its own
    complaining about the unconsumed remaining arguments in the file,
    believing them to be non-option arguments, even though these arguments
    were never looked it to see if they were options.

    The fix is for the code handling --flag options to check whether
    the code processing the file contents found any errors, and if so,
    return that error *without* looking at the list of remaining arguments.

    In an unrelated change, factor out a duplicate call.
2020-09-28 18:16:13 +10:00
Zoltan Somogyi
d49f6eab84 Add missing imports of parent modules.
These imports were missing from source files, but were included in imported
modules' .int3 files. An upcoming change will delete these from those .int3
files.
2019-03-20 03:57:10 +11:00
Zoltan Somogyi
624aaa01f1 Pack subword-sized arguments next to a local sectag.
compiler/du_type_layout.m:
    If a new option is set, then try to represent function symbols with
    only subword-sized arguments by packing those arguments into the same word
    as the primary tag and (if it is needed) a secondary tag.

    If there are too many such function symbols for the available number of
    bits, pick the ones that need the least number of bits, in order to
    allow us to use this representation for as many such function symbols
    as possible.

    This diff implements this packing only for types that have more than one
    argument, because implementing it for types that have only one argument
    has two extra complications. One is the need for another new cons_id
    (see below), which would make this diff bigger and harder to review.
    The other is the need to consider interactions with the direct_arg
    optimization.

    Don't invoke the code for deciding the representation of arguments
    if either (a) the function symbol has no arguments, or (b) its cons_id
    alone dictates how we will treat its argument (in such cases, there is
    always exactly one).

    Fix a bug in computing the number of bits needed to distinguish N things.

    Store the value of the "experiment" option in the params for now,
    since it has helped track down bugs in this change, and may do the same
    for my next change. It costs next to nothing.

compiler/options.m:
    Add an option that controls whether we allow du_type_layout to pack
    arguments next to local secondary tags. The default value is "no",
    since "yes" may break binary compatibility.

    Add an option that controls whether we allow du_type_layout to pack
    arguments next to remote secondary tags. This option is not yet used.

compiler/hlds_data.m:
    Add a new cons_id, shared_local_tag_with_args, to represent function
    symbols in which the arguments are packed next to a local secondary tag.
    Rename the existing shared_local_tag cons_id as shared_local_tag_no_args,
    to clarify the distinction.

    Redesign the representation of secondary tags a bit, to meet the
    requirements I discovered while implementing the new data representation.

compiler/prog_data.m:
    Document the now-expanded uses of the arg_pos_width type.

compiler/ml_unify_gen.m:
compiler/unify_gen.m:
    Implement unifications involving the new cons_id.

compiler/var_locn.m:
    Implement deconstruction unifications involving both right-to-left data
    flow and the new cons_id for the LLDS backend requires var_locn.m
    to implement a new kind of assignment to a variable: one that updates
    its old value. Add a predicate for this. (Previously, deconstructions
    with right-to-left flow could update the old value of a word in a
    memory cell, whose state var_locn.m does *not* track.)

compiler/code_loc_dep.m:
    Provide the interface between unify_gen. and var_locn.m.

compiler/code_info.m:
    Store the number of primary tag bits in the code_info, to save it looking
    up in the globals structure, since with its new code, unify_gen.m needs it
    more often now.

compiler/hlds_out_module.m:
doc/user_guide.texi:
    Implement the capability of restricting the dump of the type table
    to only the types defined in the module being compiled. Without this,
    the type table is cluttered with information about types in other
    modules, including the automatically-included builtin modules.

compiler/handle_options.m:
    Add a new value of the -D option. The new value, du, asks for the
    dumping out of the representations of only the locally defined types.

compiler/ml_gen_info.m:
    Store the number of primary tag bits as a uint8, not as int.

compiler/ml_tag_switch.m:
compiler/switch_util.m:
compiler/tag_switch.m:
    Update the code that generates switches on du types to handle
    local secondary tags that must be masked off before use.

compiler/rtti.m:
    Update the compiler's representation of RTTI information to account for
    the new data representation.

compiler/type_ctor_info.m:
    Construct the updated RTTI representation.

compiler/bytecode_gen.m:
compiler/export.m:
compiler/ml_switch_gen.m:
compiler/ml_type_gen.m:
compiler/modecheck_goal.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
    Conform for the changes above.

runtime/mercury_type_info.h:
    Extend the representation of du functors in the RTTI to account for
    the new data representation scheme. The extensions add only to the
    *ends* of structures, or to lists of enum values, with the extensions
    only being used if the representation is actually used, which should
    allow the updated runtime to also work with .c files that were compiled
    with a compiler that does *not* have this diff. For the same reason,
    make the old enum value MR_SECTAG_LOCAL a synonym for the new
    MR_SECTAG_LOCAL_REST_OF_WORD, which expresses a distinction that
    did not previously exist.

    Delete a reference to a file that no longer exists.

runtime/mercury_dotnet.cs.in:
library/rtti_implementation.m:
    Update the C# and Mercury mirrors of the types updated in
    mercury_type_info.h.

runtime/mercury_deconstruct.c:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_ml_expand_body.h:
    Implement the deconstruction of terms using the new data representation.

runtime/mercury_deep_copy_body.h:
    Implement the copying of terms using the new data representation.

runtime/mercury_table_type_body.h:
    Implement the tabling of terms using the new data representation.

runtime/mercury_term_size.c:
    Implement computing the size of terms using the new data representation.

runtime/mercury_unify_compare_body.h:
    Implement RTTI-based unifications of terms using the new data
    representation. (Or at least make a first attempt at this implementation.
    We never use RTTI-based unification, so this code has not been tested,
    but it is not clear that it *needs* to be tested.)

library/construct.m:
    Implement the construction of terms using the new data representation.

library/private_builtin.m:
    List MR_SECTAG_LOCAL_REST_OF_WORD as a synonym of MR_SECTAG_LOCAL for Java,
    since rtti_to_mlds.m will now emit the new version.

    Note that the new data representation is not applicable to Java (or C#),
    so it should never see the other kind of sectag (MR_SECTAG_LOCAL_BITS).

tests/hard_coded/sectag_bits.{m,exp}:
tests/hard_coded/sectag_bits_test_data:
    A new test case to test the reading in and writing out (and therefore
    the construction and deconstruction) of terms containing arguments
    packed with a local sectag.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2018-07-08 17:54:11 +02:00
Zoltan Somogyi
15aa457e12 Delete $module arg from calls to unexpected. 2018-04-07 18:25:43 +10:00
Zoltan Somogyi
8ecd9b1f5f Carve closure_gen.m out of unify_gen.m.
compiler/closure_gen.m:
    New module containing the part of unify_gen.m concerned with creating
    closures.

compiler/code_info.m:
    Move a utility predicate here from unify_gen.m, since it is needed
    by both the code moved to closure_gen.m and the code that stays
    in unify_gen.m.

compiler/unify_gen.m:
    Remove the code moved to other modules.

compiler/ll_backend.m:
compiler/notes/compiler_design.html:
    Add the new module.
2018-03-07 23:49:58 +11:00
Zoltan Somogyi
955a69efff Give better names to some functions.
compiler/type_util.m:
    Rename the "check_dummy_type" function to "is_type_a_dummy", since this
    expresses its job more clearly.

    Make the implementation of "is_type_a_dummy" slightly more efficient,
    by avoiding some redundant actions.

    Provide a new function "is_either_type_a_dummy" that does
    what its name says, and which is somewhat more efficient than
    two separate calls to "is_type_a_dummy".

compiler/prog_type.m:
    Rename the "check_builtin_dummy_type_ctor" function to
    "is_type_ctor_a_builtin_dummy", since this expresses its job
    more clearly.

compiler/ml_unify_gen.m:
    Conform to the name changes.

    Use the new function where relevant to simplify some code.

    Fix some comments.

compiler/code_info.m:
compiler/code_loc_dep.m:
compiler/continuation_info.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/erl_unify_gen.m:
compiler/export.m:
compiler/higher_order.m:
compiler/hlds_pred.m:
compiler/live_vars.m:
compiler/llds_out_instr.m:
compiler/mark_tail_calls.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_foreign_proc_gen.m:
compiler/pragma_c_gen.m:
compiler/stack_layout.m:
compiler/term_constr_util.m:
compiler/trace_gen.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/var_locn.m:
compiler/write_module_interface_files.m:
    Use the new function where relevant.
2018-02-28 13:48:44 +11:00
Zoltan Somogyi
f7fbdd5cfa Store some options in the code_info.
compiler/code_info.m:
    Add the values of three options to the static part of the code_info
    structure.

compiler/unify_gen.m:
    Look up the values of those options in the code_info (which is constant
    time) instead of in the option table (which is logarithmic in the number of
    options, and therefore considerably slower). We pay the cost of setting
    the additional fields of the code_info once per procedure; we get the
    savings once per construction unification, which happens much more often.
2018-02-17 22:01:29 +11:00
Zoltan Somogyi
4b98f58d9d Don't use reserved addresses to represent functors.
Late last year, we agreed to delete the ability to use the addresses
of reserved objects as cons_tags. After another (very short) discussion
on m-dev, this diff also deletes the ability to use small integers
(including zero) acting as pointers.

compiler/options.m:
    Delete the --num-reserved-addresses option.

    Add a synomym for --compiler-sufficiently-recent, with the intention
    that support for the representation of reserved addresses in RTTI
    code in the runtime will be deleted when all installed compilers
    have this new synonym.

compiler/hlds_data.m:
    Delete any mention of the reserved addresses from the cons_tag type,
    since we don't have reserved addresses anymore.

    Don't record for each type whether it uses reserved addresses;
    no type can do so anymore.

compiler/rtti.m:
    Delete the part of the RTTI representation that dealt with reserved
    addresses.

compiler/add_foreign_enum.m:
compiler/add_special_pred.m:
compiler/bytecode_gen.m:
compiler/code_info.m:
compiler/du_type_layout.m:
compiler/equiv_type_hlds.m:
compiler/erl_rtti.m:
compiler/export.m:
compiler/hlds_out_module.m:
compiler/intermod.m:
compiler/ml_switch_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/opt_debug.m:
compiler/prog_data.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
compiler/unify_gen.m:
    Conform to the changes above, mostly by deleting code that used to deal
    with reserved addresses.
2018-02-06 16:03:44 +11:00
Zoltan Somogyi
fb97df69ed Make "compute type representations" a separate pass.
The ultimate purpose of this diff is to prepare for future improvements
in type representations, allowing values of some data types to be represented
more compactly than up to now.

The main way this diff does that is by creating a separate pass for deciding
how values of each type should be represented. We have traditionally decided
data representations for each type as its type definition was processed
during the make_hlds pass, but these decisions were always tentative,
and could be overridden later, e.g. when we processed foreign_type or
foreign_enum pragmas for the type. This dispersed decision making algorithm
is hard to understand, and therefore to change.

This diff centralizes decisions about type representations in a separate
pass that does nothing else. It leaves the algorithm distributed among
several files (du_type_layout.m, make_tags.m, and add_foreign_enum.m) for now,
to make reviewing this diff easier, but soon after it is committed I intend
to move all the relevant code to du_type_layout.m, to centralize the decision
code in "space" as well as in time.

For the reason why this pass runs before any of the semantic analysis
passes, instead of after all of them as I originally intended and as we
discussed on m-dev in late october 2017, see the big comment at the start of
du_type_layout.m.

As per another part of that same discussion on m-dev, this diff
makes a start on implementing a new type of item, the type_repn item,
which is intended *only* to be used in compiler-generated interface files,
*not* in source files. It is only a start because we can use these items
only *after* the creation of a separate type representation decision pass,
and this diff is already very big. The code for making the compiler understand
these items will be added later. The code for generating them will be added
later still, once the code for understanding them has been installed on
all our systems.

Since I was going to be working on the affected code anyway, this diff
also carries out two other decisions that came out of that discussion:

- the deletion of the ability to reserve a tag in a type for HAL,
  either via a compiler option or via a pragma, and

- the deletion of the ability to represent a functor using the address
  of a statically allocated object (which we haven't used and won't use,
  because it slows down accesses to *all the other functors* of the type).

compiler/mercury_compile_front_end.m:
    Invoke the new pass for making decisions about type representations
    after the make_hlds pass. (We used to do only the final part of it then.)

    Fix a bad dump stage name.

    Add an extra check for what it means for a module to be error free.

    Make a sub-switch explicit.

compiler/hlds.m:
compiler/make_hlds.m:
    Move the modules that implement the new pass from the make_hlds package
    to the hlds package, to give the compiler's top level access to them.

    Make the same move for the modules that the new pass's modules need.
    Since they are now part of hlds, they cannot reach into make_hlds,
    and I think this is a cleaner solution than forwarding predicates.

    Delete some forwarding predicates that are no longer needed.

compiler/notes/compiler_design.html:
    Document the updated location of the moved modules.

    Add an XXX to note a place where the documentation has not been
    updated in the past.

compiler/du_type_layout.m:
    Add code to implement the new pass.

    Keep the algorithm for deciding type representations as close
    to the previously used algorithm as possible, since this diff
    is already big enough. (The previous algorithm was scattered across
    add_type.m, add_foreign_enum.m, and make_hlds_passes.m.)

    Simplifications and optimizations will come later, after this module
    is merged with make_tags.m and with (at least) the foreign_enum half of
    add_foreign_enum.m.

compiler/make_tags.m:
    Keep the functionality of this module, which does both the first part
    of deciding type representations (tentatively assigning tags to functors,
    an assignment that may be overridden later), and the last part (packing
    multiple adjacent less-than-word-sized enum args into a single word,
    if possible.), but simplify it where possible, and note possibilities
    for further improvements.

compiler/add_foreign_enum.m:
    This module has two halves, one dealing with foreign_enum pragmas
    and one dealing with foreign_export_enum pragmas.

    Change the half that deals with foreign_enum pragmas to just build
    a data structure that du_type_layout.m will need to make its decisions,
    this structure being a map from type_ctors to the foreign enum
    specification applicable to the current target language. Include
    in this structure a component that add_foreign_enum.m itself can use
    to report better error messages for duplicate foreign_enum pragmas;
    this component records, for each type_ctor and language, the context
    of the previous foreign_enum pragma for that combo.

    Change the input for the half that deals with foreign_export_enum pragmas
    to reflect the fact that it is invoked by du_type_layout.m after all
    decisions about type representations have already been made.

compiler/add_special_pred.m:
    Move this module from the make_hlds package to the hlds package,
    since the code that adds special preds for type is now called from
    du_type_layout.m.

    Change the names of predicates to make clear whether they add
    only the declaration of a predicate, only its definition, or both.

    Don't try to pre-guess whether the implementation of a type's
    compare predicate will need an index predicate. Let the code
    that generates calls to the index predicate both declare and define
    the index predicate. This change removes the potential for
    inconsistencies between the two pieces of code.

compiler/add_pred.m:
    Move this module from the make_hlds package to the hlds package,
    since add_special_pred.m needs access to it.

compiler/add_type.m:
    When adding a type definition to the HLDS, don't try to decide
    its representation. Any such decision was tentative anyway, due
    to the possibility of e.g. the later processing of foreign_type
    or foreign_enum pragmas for the type. Likewise, don't try to
    create the special (unify, compare) predicates for the type.
    Leave both tasks to the du_type_layout pass.

    Likewise, don't try to pack the representation of types, or record
    no_tag types in the table of no_tag types, during the post-processing
    pass either; leave both of these to du_type_layout as well.
    Rename the predicate that post_processes type definitions to reflect
    the two tasks left for it to do.

compiler/prog_data.m:
    Do not store width information about the arguments of those data
    constructors in the parse tree. That information is not computed
    until later; until then, it was always filled in with dummy values.
    (But see hlds_data.m below.)

    Use bespoke types to represent the presence or absence of user-specified
    unify and compare predicates.

    Change the representation of data constructors to use a single "maybe"
    type, not two lists, to denote the presence or absence of existentially
    typed arguments.

    Give the HLDS the ability to hold representation information about
    abstract types that in the future we will get from type_repn items
    in the defining modules' interface files.

    Delete the uses_reserved_tag type, since we never use reserved tags
    anymore.

compiler/prog_item.m:
    Add the new type_repn item type, which is not used yet.

    Delete the reserve_tag pragma.

    Fix an earlier mistake in the wording of a context message.

compiler/hlds_data.m:
    Put all the fields of hlds_du_type (the type definition variant dealing
    with discriminated union types) that deal with type representation
    issues in a single "maybe" field that is set to "no" before the
    type representation decision pass has been run.

    Add new type, constructor_repn, that stores the same information as the old
    constructor type (defined in prog_data.m), PLUS the information
    describing how terms with that data constructor are stored.

    Likewise, add a new type ctor_arg_rep, which likewise stores
    the widths of each constructor argument. When we implement
    argument reordering, we would store the offset of the arg as well.

    Since the parse tree representations of constructors and their arguments
    don't store representation information anymore, the cons_table they
    are stored in doesn't either. Make the lookup of representation information
    for a given constructor possible by adding a map to the new "maybe" field
    of hlds_du_type.

    Provide some utility predicates.

    Optimize some existing predicates.

    Rename some types to better reflect their meaning.

compiler/hlds_module.m:
    Provide a slot in the module_info for storing the information
    gathered by make_hlds.m that is needed by the new pass.

compiler/make_hlds_separate_items.m:
    When we see either a foreign_enum or a foreign_export_enum pragma,
    return values of a bespoke type for them (a type defined in
    hlds_module.m), instead of an item_pragma. This makes handling them
    considerably easier.

compiler/make_hlds_passes.m:
    With the changes in this diff, adding a type to the HLDS won't
    decide its representation. Therefore delete the code that used
    to loop over foreign_export_enum pragmas; in the absence of
    the final type representation information, it won't work right.

    Record the information that the du_type_layout pass will need
    in the module_info.

compiler/add_pragma.m:
    Delete the code for passing on foreign_enum and foreign_export_enum
    pragmas to add_foreign_enum.m; they are now passed to add_foreign_enum.m
    by du_type_layout.m.

    Move a utility predicate to make_hlds_error.m, to allow add_foreign_enum.m
    to call it.

compiler/make_hlds_error.m:
    Add the utility predicate moved from add_pragma.m.

    Move the module from the make_hlds to the hlds package.

compiler/module_qual.m:
    Provide a mechanism for recording error messages about e.g. undefined
    types without recording that we found an undefined type. This sounds
    strange, but there is a valid use case.

    When a type definition declares a functor's argument to be of an
    undefined type, that error is usually fatal; we stop the compiler
    from proceeding even to typechecking, since the typechecker will
    probably abort with a map lookup failure. Most other references
    to undefined types are similarly fatal for the same reason. However,
    if e.g. a foreign_export_enum pragma refers to an undefined type,
    that error *won't* be visible to the typechecker, and therefore
    won't crash it. The error will still cause the compiler to exit
    without generating any target language code, but at least it will be
    able to run the typechecker and other semantic analysis passes.

    Without this change, the compiler will report only one error in
    the ee_invalid.m test case; with it, it reports *every* error
    in the test case expected output.

compiler/module_qual.qualify_items.m:
    Use the capability describe above for undefined types in
    foreign_export_enum pragmas.

compiler/module_qual.qual_errors.m:
    Delete a (somewhat incorrect) copy of a predicate in prog_item.m,
    to reduce code duplication.

compiler/prog_type.m:
    Add ways to represent abstract types whose representations are nevertheless
    known (from type_repn items in the defining modules' interface files)
    to be notag or dummy types. This will be needed to fix Mantis bug #441,
    a fix that will probably be one of the first later changes to build
    on this diff.

    Delete a type moved to type_util.m.

compiler/type_util.m:
    Provide extra versions of some predicates, with the difference between
    the old and the new versions being that one requires type representations
    to have been decided already, and the other one does not.

    Move the definition of the ctor_defn type here from prog_type.m,
    since prog_type.m itself does not use it, but type_util.m does.

    Give some predicates more meaningful names.

compiler/parse_type_defn.m:
    Simplify the code for parsing type definitions, to make it easier
    to reuse to parse type_repn items.

    Add a sanity check that requires existential constraints to have
    *some* existential variables to apply to.

    Allow "type_is_representable_in_n_bits" as a synonym for
    "type_is_abstract_enum", since in the future we want to be able to pack
    e.g. multiple int8s, not just multiple enums, into a single word.

    Generate more specific error messages for some classes of malformed input.

compiler/parse_type_repn.m:
    New module to parse type_repn items.

compiler/polymorphism.m:
    Make some predicates that operate on type constructors take
    the type constructors themselves as input arguments, not a whole type
    *using* that type constructor. Put the arguments of those predicates
    in a more standard order.

    Note that some predicates don't belong in this module.

compiler/special_pred.m:
    Make the code that decides whether a special predicate for a type
    constructor can be defined lazily avoid using type representation
    information. (Actually, we now make decisions about lazy vs eager
    definitions after type representation is available, but that was
    not so in an earlier version of this change, and the new code
    is more robust.)

compiler/unify_proc.m:
    When we decide to generate code for a compare predicate that needs
    the type to have an index predicate, don't presume that the index
    predicate has already been declared and defined; instead, declare
    and define it then and there. (Index predicates are *never* called
    from anywhere else.)

    Pack the information needed to define a special predicate
    into a single structure, to simplify the above.

    Since the creation of a clause for a compare predicate may now require
    the declaration and definition of an index predicate, the module_info
    field of the unify_proc_info is now a writeable field.

    Give some predicates and function symbols more meaningful names.

    Note some problems with the existing code.

compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_mode.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_solver.m:
compiler/check_typeclass.m:
compiler/code_info.m:
compiler/comp_unit_interface.m:
compiler/ctgc.selector.m:
compiler/ctgc.util.m:
compiler/default_func_mode.m:
compiler/det_report.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/erl_code_gen.m:
compiler/export.m:
compiler/foreign.m:
compiler/get_dependencies.m:
compiler/goal_expr_to_goal.m:
compiler/hhf.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_out_module.m:
compiler/inst_check.m:
compiler/inst_test.m:
compiler/inst_util.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/make_hlds_warn.m:
compiler/ml_accurate_gc.m:
compiler/ml_simplify_switch.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/mode_util.m:
compiler/modecheck_goal.m:
compiler/module_qual.collect_mq_info.m:
compiler/modules.m:
compiler/parse_item.m:
compiler/parse_pragma.m:
compiler/parse_tree.m:
compiler/parse_tree_out.m:
compiler/parse_tree_out_pragma.m:
compiler/post_term_analysis.m:
compiler/proc_requests.m:
compiler/prog_item_stats.m:
compiler/qual_info.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/resolve_unify_functor.m:
compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/simplify_goal_ite.m:
compiler/stack_opt.m:
compiler/state_var.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/superhomogeneous.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_constr_build.m:
compiler/term_norm.m:
compiler/trailing_analysis.m:
compiler/type_constraints.m:
compiler/type_ctor_info.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/untupling.m:
compiler/unused_imports.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the changes above.

tests/invalid/Mmakefile:
    Disable the reserve_tag test case, as it is not applicable anymore.

tests/invalid/exported_foreign_enum.{m,err_exp}:
tests/invalid/pragma_qual_error.{m,err_exp}:
    Delete reserve_tag pragmas from these test cases, and its effects
    from the expected outputs.

tests/invalid/bad_foreign_type.err_exp:
tests/invalid/bigtest.err_exp:
tests/invalid/foreign_enum_invalid.err_exp:
tests/invalid/type_lhs_var.err_exp:
tests/invalid/uu_type.err_exp:
tests/invalid/where_abstract_enum.err_exp:
tests/invalid/where_direct_arg.err_exp:
    Expect the updated messages for some errors.

tests/valid/Mmake.valid.common:
tests/valid/Mmakefile:
    Disable any reserve_tag test cases, as they are not applicable anymore.
2018-01-31 17:54:40 +11:00
Julien Fischer
ae94e32d46 Support 64-bit integers in static ground terms with the LLDS backend.
compiler/handle_options.m:
compiler/options.m:
    Add a new internal option --static-ground-int64s, whose value
    says whether 64-bit integers may be placed in static data.
    (As with floats currently, we always do this.)

compiler/llds_out_data.m:
    If 64-bit integers are boxed, then emit a static constant to hold
    the value of each 64-bit integer literal.

compiler/llds.m:
compiler/llds_out_util.m:
compiler/code_info.m:
     Keep track of whether we are using unboxed int64s and static ground int64s
     at various points in the code generator.

     Add decl_ids for the labels we generate for 64-bit integer constants.

compiler/exprn_aux.m:
     Fix an XXX: properly determine whether an expression containing 64-bit
     integers is constant or not.

compiler/c_util.m:
    Add functions for converting 64-bit integers into strings giving
    the C literal representation of those integers.
2018-01-23 01:31:24 -05:00
Julien Fischer
f519e26173 Add builtin 64-bit integer types -- Part 1.
Add the new builtin types: int64 and uint64.

Support for these new types will need to be bootstrapped over several changes.
This is the first such change and does the following:

- Extends the compiler to recognise 'int64' and 'uint64' as builtin types.
- Extends the set of builtin arithmetic, bitwise and relational operators
  to cover the new types.
- Adds the new internal option '--unboxed-int64s' to the compiler; this will be
  used to control whether 64-bit integer types are boxed or not.
- Extends all of the code generators to handle the new types.
- Extends the runtimes to support the new types.
- Adds new modules to the standard library intend to contain basic operations
  on the new types.  (These are currently empty and not documented.)

There are bunch of limitations marks with "XXX INT64"; these will be lifted in
part 2 of this change.  Also, 64-bit integer types are currently always boxed,
again this limitation will be lifted in later changes.

compiler/options.m:
    Add the new option --unboxed-int64s.

compiler/prog_type.m:
compiler/prog_data.m:
compiler/builtin_lib_types.m:
     Recognise int64 and uint64 as builtin types.

compiler/builtin_ops.m:
     Add builtin operations for the new types.

compiler/hlds_data.m:
     Add new tag types for the new types.

compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/export.m:
compiler/foreign.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/implementation_defined_literals.m:
compiler/inst_check.m:
compiler/mercury_to_mercury.m:
compiler/mode_util.m:
compiler/module_qual.qualify_items.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/polymorphism.m:
compiler/prog_out.m:
compiler/prog_util.m:
compiler/rbmm.execution_path.m:
compiler/rtti.m:
compiler/table_gen.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
    Conform to the above changes to the parse tree and HLDS.

compiler/c_util.m:
    Support writing out constants of the new types.

compiler/llds.m:
    Add a representation for constants of the new types to the LLDS.

compiler/stack_layout.m:
    Add a new field to the stack layout params that records whether
    64-bit integers are boxed or not.

compiler/call_gen.:m
compiler/code_info.m:
compiler/disj_gen.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/llds_out_data.m:
compiler/llds_out_instr.m:
compiler/lookup_switch.m:
compiler/mercury_compile_llds_back_end.m:
compiler/prog_rep.m:
compiler/prog_rep_tables.m:
compiler/var_locn.m b/compiler/var_locn.m:
    Support the new types in the LLDS code generator.

compiler/mlds.m:
    Support constants of the new types in the MLDS.

compiler/ml_call_gen.m:
compiler/ml_code_util.m:
compiler/ml_global_data.m:
compiler/ml_rename_classes.m:
compiler/ml_top_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_target_util.m:
compiler/rtti_to_mlds.m:
     Conform to the above changes to the MLDS.

compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
    Generate the appropriate target code for constants of the new types
    and operations involving them.

compiler/bytecode.m:
compiler/bytecode_gen.m:
    Handle the new types in the bytecode generator; we just abort if we
    encounter them for now.

compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_call_gen.m:
compiler/erl_code_util.m:
compiler/erl_unify_gen.m:
    Handle the new types in the Erlang code generator.

library/private_builtin.m:
    Add placeholders for the builtin unify and compare operations for
    the new types.  Since the bootstrapping compiler will not recognise
    the new types we give them polymorphic arguments.  These can be
    replaced after this change has bootstrapped.

    Update the Java list of TypeCtorRep constants here.

library/int64.m:
library/uint64.m:
    New modules that will eventually contain builtin operations on the new
    types.

library/library.m:
library/MODULES_UNDOC:
    Do not include the above modules in the library documentation for now.

library/construct.m:
library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
library/table_statistics.m:
deep_profiler/program_representation_utils.m:
mdbcomp/program_representation.m:
    Handle the new types.

configure.ac:
runtime/mercury_conf.h.in:
    Define the macro MR_BOXED_INT64S.  For now it is always defined, support for
    unboxed 64-bit integers will be enabled in a later change.

runtime/mercury_dotnet.cs.in:
java/runtime/TypeCtorRep.java:
runtime/mercury_type_info.h:
    Update the list of type_ctor reps.

runtime/mercury.h:
runtime/mercury_int.[ch]:
    Add macros for int64 / uint64 -> MR_Word conversion, boxing and
    unboxing.

    Add functions for hashing 64-bit integer types suitable for use
    with the tabling mechanism.

runtime/mercury_tabling.[ch]:
    Add additional HashTableSlot structs for 64-bit integer types.

    Omit the '%' character from the conversion specifiers we pass via
    the 'key_format' argument to the macros that generate the table lookup
    function.  This is so we can use the C99 exact size integer conversion
    specifiers (e.g. PRIu64 etc.) directly here.

runtime/mercury_hash_lookup_or_add_body.h:
    Add the '%' character that was omitted above to the call to debug_key_msg.

runtime/mercury_memory.h:
     Add new builtin allocation sites for boxed 64-bit integer types.

runtime/mercury_builtin_types.[ch]:
runtime/mercury_builitn_types_proc_layouts.h:
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_table_type_body.h:
runtime/mercury_tabling_macros.h:
runtime/mercury_tabling_preds.h:
runtime/mercury_term_size.c:
runtime/mercury_unify_compare_body.h:
    Add the new builtin types and handle them throughout the runtime.

runtime/Mmakefile:
    Add mercury_int.c to the list of .c files.

doc/reference_manual.texi:
     Add the new types to the list of reserved type names.

     Add the mapping from the new types to their target language types.
     These are commented out for now.
2018-01-12 09:29:24 -05:00
Zoltan Somogyi
e35763bc60 Start generating MLDS code by TSCCs.
compiler/ml_proc_gen.m:
    Partition the procedures in an SCC into three categories:

    - those that can't use tail recursion optimization at all;
    - those that have contain only self-tail-recursive calls; and
    - those that have contain mutually-tail-recursive calls (and maybe
      self-recursive calls as well).

    For the third category, divide them into TSCCs (SCC formed taking only
    tail calls into account), and generate code TSCC-by-TSCC. In the future,
    we will compile each TSCC together, though this diff does not do that.

    Do the part of code generation that requires updaing ModuleInfo
    (the requantification of procedure bodies) at the start, so that
    all the rest of the code generator can work with a constant ModuleInfo.

    Do the above *without* looking up the same procedure over and over again.

compiler/hlds_pred.m:
    Provide a place for recording whether a procedure has one or more
    mutually-tail-recursive calls, beside the existing spot for recording
    whether it has one or more self-tail-recursive calls. Make the wording
    used more neutral, to encompass the new use of this slot as well as
    the old.

compiler/mark_tail_calls.m:
    Fill both these slots in proc_infos if asked. ml_proc_gen.m uses them
    to help with the partitioning.

    Use hlds_pred.m's types instead of the isomorphic local ones.

compiler/code_info.m:
compiler/trace_gen.m:
    Conform to the change in hlds_pred.m.

compiler/hlds_dependency_graph.m:
    Fix an old limitation: compute whether a procedure is exported
    correctly.
2017-08-11 00:13:32 +02:00
Julien Fischer
94535ec121 Fix spelling and formatting throughout the system.
configure.ac:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
library/*.m:
ssdb/*.m:
runtime/mercury_conf.h.in:
runtime/*.[ch]:
scripts/Mmake.vars.in:
trace/*.[ch]:
util/*.c:
	Fix spelling and doubled-up words.

	Delete trailing whitespace.

	Convert tabs into spaces (where appropriate).
2015-12-02 18:46:14 +11:00
Zoltan Somogyi
cc9912faa8 Don't import anything in packages.
Packages are modules whose only job is to serve as a container for submodules.
Modules like top_level.m, hlds.m, parse_tree.m and ll_backend.m are packages
in this (informal) sense.

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

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

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

This diff removes all import_module declarations from the packages,
and replaces them with import_module declarations in the modules that need
them. This includes only a SUBSET of their child modules and of the non-child
modules that import them.
2015-11-13 15:03:20 +11:00
Zoltan Somogyi
5d2eed1f20 Convert (C->T;E) to (if C then T else E). 2015-10-25 09:17:21 +11:00
Zoltan Somogyi
8b2251a874 Create each field in sequence. 2015-09-21 18:17:09 +10: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
4d2788ff9e Separate out the location-dependent parts of the code_info.
The code_info type was originally designed to be a single data structure
that holds all of the state of the LLDS code generator. It HAD to be a single
data structure then, because the DCGs we used to pass state around only
supported passing around ONE piece of state. Nevertheless, it contained
three separate kinds of information:

1 static information, which never changed during the lifetime of a code_info
  structure (such as the pred and proc id of the procedure being compiled),

2 persistent information, whose updates were never undone (such as the maximum
  number of temporaries that were ever needed at any one time), and

3 location dependent information, such as "which variables are stored where",
  whose updates *can* be undone when the code generator jumps back to
  a previously visited point in the code, e.g. to start generating code
  for the next disjunct in a disjunction.

Originally, these three kinds of fields were all jumbled up together, but
about ten years ago, I grouped all the fields of the same kind together,
into substructures of code_info named code_info_static, code_info_persistent
and code_info_loc_dep respectively. This improved matters, but some problems
remained, the most important of which is that the code_info always contained
the location dependent information, even when it wasn't meaningful, and there
was no way of indicating this fact. (After initialization, the other two parts
are always meaningful.)

This diff separates out the location dependent part of the code_info
into a new type, code_loc_dep, that can be passed around independently
of the code_info, which now contains only the first two kinds of information
above. In places where the location-dependent information is not meaningful,
you don't need to have a current code_loc_dep.

This separation also makes it easier to see what updates to the code generator
state change only the persistent part (the updated code_info type), only
the location-dependent part (the new code_loc_dep type), or both.

In the process of making this change, I found several places where the
location-dependent part of the code_info (now the code_loc_dep) was being
updated, only for those updates to be thrown away, unread, a short time later.
This happened at the ends of branches in e.g. switches, with the updated
code_loc_deps being thrown away when code generation started working on
the next branch.

compiler/code_loc_dep.m:
    New module containing the location-dependent part of the LLDS code
    generator state. Its contents are derived from those parts of the
    old contents of code_info.m that deal with location-dependent state.

    Many of the predicates moved here work on only on the code_loc_dep
    structure, some others work on both the code_info and code_loc_dep
    structure, and a few work only on the code_info. Predicates in the last
    category are in code_loc_dep.m only if they are either (a) used only
    in this module, or (b) used only with other predicates in this module.

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

compiler/code_info.m:
    Delete the code now in code_loc_dep.m.

    Make the vartypes a field in the static part of the code_info, since it is
    used quite often. (We used to look it up in the proc_info every time.)

    Put the declarations and definitions of the access predicates in an order
    that is consistent with the order of the fields they work on.

    Give some fields and predicates more descriptive names.

compiler/call_gen.m:
compiler/code_gen.m:
compiler/commit_gen.m:
compiler/dense_switch.m:
compiler/disj_gen.m:
compiler/ite_gen.m:
compiler/ll_backend.m:
compiler/lookup_switch.m:
compiler/lookup_util.m:
compiler/middle_rec.m:
compiler/par_conj_gen.m:
compiler/pragma_c_gen.m:
compiler/proc_gen.m:
compiler/string_switch.m:
compiler/switch_case.m:
compiler/switch_gen.m:
compiler/tag_switch.m:
compiler/trace_gen.m:
compiler/unify_gen.m:
compiler/var_locn.m:
    Conform to and take advantage of the changes above.

    Often this required passing an in/out pair of code_loc_deps as well as
    an in/out pair of code_infos, but in many cases, one or more of these
    would not be needed.

    Don't make changes to the code_loc_dep at the end of an arm of a branched
    control structure if those updates are about be thrown away when we
    start generating code for the next arm.

    In several cases, switch to a strategy of taking a snapshot of the
    code_loc_dep before entering a branched control structure as a whole,
    and restoring that state at the start of each arm. We used to take
    a snapshot at the start of each branch, and restore it at its end,
    to be ready for the next branch. The former is easier to make
    correctness arguments about, since the code_loc_dep in an arm
    often has limited scope.

    Make some minor unrelated improvements, such as eliminating the
    unnecessary use of solutions/2, and reordering tests for slightly
    better performance.
2015-07-28 10:19:42 +10:00
Zoltan Somogyi
8dc5a0071c Miscellaneous cleanups.
Just fixes to comments, better variable and predicate names, and the like.
No algorithmic changes.
2015-01-02 16:15:30 +11:00
Zoltan Somogyi
dddb9e552d Factor out common code in code generation for switches.
compiler/switch_util.m:
    Move here some code that was common to switch_gen.m and ml_switch_gen.m.

compiler/switch_gen.m:
compiler/ml_switch_gen.m:
    Remove the code moved to switch_util.m.

    In switch_gen.m, remove a long unused predicate.

compiler/code_info.m:
    Simplify the interface of the init predicate for code_infos.

compiler/proc_gen.m:
    Conform to the change in code_info.m.
2014-12-18 23:28:28 +11:00
Zoltan Somogyi
633141efcb Remove most non-core predicates from hlds_goal.m.
compiler/hlds_goal.m:
    As above.

    Put some of the remaining stuff in a more logical order.

compiler/make_goal.m:
    This new module contains the predicates, previously in hlds_goal.m,
    that construct new goals.

compiler/hlds.m:
compiler/notes/compiler_design.html:
    Include the new module.

compiler/goal_form.m:
    Move to this existing module the predicates previously in hlds_goal.m
    that test whether goals have particular forms (which is the task of
    this module).

compiler/*.m:
    Conform to the above. Note that no module requires a new import
    of BOTH make_goal and goal_form.
2014-08-21 12:14:50 +02:00
Zoltan Somogyi
1f82bd0606 Minor cleanup before fixing Mantis bug 351. (This is NOT the bug fix.)
compiler/hlds_pred.m:
    Replace some uses of booleans in proc_infos with specialized types.
    Put the fields involved into a more logical order. Give their access
    predicates more meaningful names.

    When creating new proc_infos, give names to all the arguments of
    proc_infos and proc_sub_infos. (I believe Mantis bug 351 is in
    these arguments.)

compiler/hlds_module.m:
    Use the new types in hlds_pred.m where relevant.

compiler/parallel_to_plain_conj.m:
    Add some conditionally combined debugging output that helped me track down
    the problem.

compiler/loop_inv.m:
mdbcomp/mdbcomp.goal_path.m:
    Minor cleanup of some comments.

compiler/code_info.m:
compiler/deforest.m:
compiler/dep_par_conj.m:
compiler/distance_granularity.m:
compiler/granularity.m:
compiler/hlds_out_pred.m:
compiler/inlining.m:
compiler/introduce_parallelism.m:
compiler/lambda.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile_middle_passes.m:
compiler/par_loop_control.m:
compiler/proc_gen.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_conj.m:
compiler/simplify_info.m:
compiler/simplify_proc.m:
compiler/trace_gen.m:
compiler/trace_params.m:
    Conform to the changes above.
2014-08-09 02:16:24 +02:00
Peter Wang
1094f42cc9 Conform to memory alignment requirements on doubles.
On some 32-bit architectures, we were violating memory alignment
requirements for double-precision floats, in cell fields and on det and
nondet stacks.  Bug #299.

We now only take the address of a double field when it occurs on an
aligned memory address, i.e. when it starts at an even word offset from
the start of a cell (this assumption is incompatible with term-size
profiling which adds a hidden word before the start of the cell).

For the det stack, we can round up allocations to keep the stack pointer
double-aligned, then allocate slots for doubles at even word offsets
from the stack pointer.

It would be trickier for the nondet stack.  Multiple frame types exist
on the nondet stack, and the different frame types are identified by
their sizes: 3-word and 4-word temporary frames, and 5/6+ word ordinary
frames. Rather than rounding up frame sizes to even numbers of words,
we would probably want to dynamically pad ordinary frame allocations,
such that any doubles in the frame will be at aligned addresses.

However, in this change, we simply store box floats on the nondet stack.

compiler/globals.m:
	Add predicate which returns whether double-width floats
	should be stored on the det stack.

compiler/handle_options.m:
	Disable double-word fields in term-size profiling grades.

compiler/code_info.m:
	Add a predicate to round up det stack frame sizes.

	Remember the width of floats stored on the det stack in
	exprn_opts.

compiler/hlds_llds.m:
compiler/llds.m:
compiler/stack_layout.m:
	Delete the possibility of double-width slots on the nondet
	stack.

	Remember det_stack_float_width in exprn_opts.

compiler/llds_out_data.m:
	Add wrapper macro `MR_dword_ptr' when taking the address of a
	double.

	Only take the address of doubles on the det stack.

compiler/llds_out_instr.m:
compiler/llds_out_util.m:
	Only assign a double field in a single C statement when it is
	aligned.

	Assert that the stack pointer is incremented by an even number,
	if necessary.

compiler/mlds_to_c.m:
	Only take the address of doubles when aligned.

compiler/middle_rec.m:
compiler/proc_gen.m:
	Round up det stack frame allocations to even numbers of words
	when necessary.

compiler/stack_alloc.m:
	Add padding as required so that double-word variables will
	be allocated at even-word offsets from the stack pointer.

compiler/opt_debug.m:
compiler/par_conj_gen.m:
	Conform to changes.

runtime/mercury_conf_param.h:
runtime/mercury_float.h:
	Add macro `MR_dword_ptr' to be wrapped around instances where
	the address of a double is taken. When `MR_DEBUG_DWORD_ALIGNMENT'
	is defined (and using gcc or clang) the address is checked to be
	properly aligned.  Almost all our development is done on x86 or
	x86-64 architecture which do not have strict memory alignment
	requirements, making violations hard to check otherwise.

runtime/mercury_deconstruct.c:
runtime/mercury_layout_util.c:
	Use `MR_float_from_dword' over `MR_float_from_dword_ptr' as the
	former does not require dword alignment.

	Related fix: looking up `double' variables on the nondet stack
	used the stack pointer for the det stack instead.  Fix it,
	though the code now won't be executed after this change.

tests/debugger/nondet_stack.exp5:
	Add new expected output. This is the same as nondet_stack.exp
	except that det stack frames have been rounded up.
2013-10-29 17:30:39 +11:00
Peter Wang
bc75942ef7 Remove unused argument to var_locn_reassign_mkword_hole_var.
compiler/code_info.m:
compiler/var_locn.m:
	var_locn_reassign_mkword_hole_var does not require the
	module_info.
2013-02-14 17:10:34 +11:00
Peter Wang
4d38590690 Construct partially instantiated direct arg functor values.
Construction unifications of partially instantiated values involving direct
argument functors (where the single argument is free) did not generate any code
in both low-level and high-level backends.  Incorrect behaviour could result if
the program tried to deconstruct the value at run-time.

Also, in the LLDS backend, such a construction unification did not enter the
variable into the var_state_map, leading to a compiler abort when the variable
is looked up.

compiler/ml_unify_gen.m:
	Generate code for constructions of a direct arg functor with free
	argument.  This amounts to assigning a variable to a tagged null
	pointer.

compiler/llds.m:
	Add an rval option `mkword_hole', which is like `mkword' but the
	pointer to be tagged is unspecified.

compiler/unify_gen.m:
	Assign a variable to an `mkword_hole' rval, for a construction
	unification of a direct arg functor with a free argument.

	Reassign the variable to an `mkword' rval when the argument becomes
	bound in a later unification.

compiler/code_info.m:
compiler/var_locn.m:
	Add a predicate to reassign a variable from a `mkword_hole' expression
	to a `mkword' expression.

compiler/llds_out_data.m:
	Write out `mkword_hole' values as a tagged null pointer in C code.

compiler/call_gen.m:
compiler/code_util.m:
compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_to_x86_64.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/peephole.m:
compiler/stack_layout.m:
	Conform to addition of `mkword_hole'.

tests/hard_coded/Mmakefile:
tests/hard_coded/direct_arg_partial_inst.exp:
tests/hard_coded/direct_arg_partial_inst.m:
tests/hard_coded/direct_arg_partial_inst2.exp:
tests/hard_coded/direct_arg_partial_inst2.m:
	Add test cases.
2013-02-14 16:37:04 +11: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
ee63cb8d84 Heavily polymorphic code, such as that generated by g12, often builds the same
Estimated hours taken: 80
Branches: main

Heavily polymorphic code, such as that generated by g12, often builds the same
typeinfos and typeclass infos over and over again. We have long had caches
that avoid building a new typeinfo or typeclass info if some variable in the
current scope already contains the right value, but a program that has many
scopes may still build the same typeinfo or typeclass info many times.
If that typeinfo or typeclass info is a ground term, the code generators
will recognize that fact, and will turn all the constructions of that ground
term in different scopes into referencess to the same constant structure.
However, in the meantime, the program can be much bigger than necessary.
In the motivating test case for this change, a single call to fdic_post
is preceded by 133 goals that build the four typeclass infos it needs.

The main idea of this diff is to construct constant typeinfos and typeclass
infos out of line, in a separate data structure. Polymorphism then binds
variables representing typeinfo and typeclass infos to reference to these
constant structures. In the motivating example, this allows polymorphism.m
to insert just four goals before the call to fdic_post, the minimal possible
number: one for each typeclass info that predicate needs.

On Leslie's bug344 program, this change speeds up the compiler by a factor
of five to eight (reducing compile time from about 80 or 85 seconds to
10 or 15).

There is a drawback to this scheme, but it is minor. That drawback is that
once a constant structure is entered into our database of constant structures,
it cannot (yet) be removed. Even if all the references to a constant structure
are eliminated by optimizations, the structure will remain.

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

CHANGES IN THE FRONT END

compiler/const_struct.m:
	A new module to look after our new database of constant structures.
	Currently, its use is enable only on the LLDS and MLDS C backends.

compiler/hlds.m:
compiler/notes/compiler_design.html:
	Add the new module to the HLDS package.

compiler/hlds_module.m:
	Include the constant structure database in the module_info.

compiler/hlds_data.m:
	Add two new cons_ids, which refer to typeinfos and typeclass infos
	implemented as constant structures.

	Move the code for calculating the number of extra instance args
	in base_typeclass_infos here from base_typeclass_info.m, since
	polymorphism.m now needs it too. We can now also eliminate the
	duplicate copy of that code in higher_order.m.

	Make an independent optimization: make the restrict_list_elements
	function more efficient by avoiding redundant tests.

compiler/polymorphism.m:
	When building typeinfo and typeclass infos, keep track of whether
	the structure being built is constant. If it is, then put it in the
	database of constant structures, and replace the code building it
	with a simple reference to that new entry.

	Since I now expect most goal sequences inserted before goals to be
	short, consistent use lists of goals to represent these, since the
	costs of conversions to and from cord form are unlikely to be paid back
	by the higher efficiency of cord operations on longer sequences.

	When we want to get the typeclass info of a superclass out of the
	typeclass info of a subclass, if the typeclass info of the subclass
	is known, do the extraction here. We used to do this optimization
	only in higher_order.m, but doing so here reduces the size of the HLDS
	between polymorphism.m and higher_order.m, and thus improves
	compilation time.

	Reorganize some of the structure of this module to make the above
	changes possible. In particular, our new approach requires making
	snapshots of the varsets and vartypes, and later restoring those
	snapshots if the variables allocated turn out to be unnecessary,
	due to all of them describing the components of a constant structure.
	The correctness of such code is much easier to check if the taking
	and restoring of each snapshot takes places in a single predicate.

	Remove the code moved to higher_order.m.

	Add some debugging code for now. If no issues arise in the next few
	weeks, it can be deleted.

compiler/modecheck_unify.m:
	Treat unifications whose right hand side has a cons_id referring to a
	constant structure specially.

compiler/base_typeclass_info.m:
	Replace the code that is now in num_extra_instance_args with a call
	to that predicate.

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

compiler/higher_order.m:
	When looking up the components of existing typeclass infos, handle
	cases where those typeclass infos are constant structures.

	Give some types, fields and variables better names.

	Avoid a redundant map search.

	Avoid some redundant tests by providing separate predicates to handle
	higher order calls and method calls.

	Move the predicate is_typeclass_info_manipulator here from
	polymorphism.m, since this is the only module that uses that predicate.

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

CHANGES IN THE LLDS BACKEND:

compiler/llds.m:
	Add a type to map constant structure numbers to rvals together with
	their LLDS types.

	Introduce a type to represent rvals together with their LLDS types.

compiler/mercury_compile_llds_back_end.m:
	Before we generate code for the predicates of the module, convert
	the constant structures to typed LLDS rvals. Create a map mapping
	each constant structure number to the corresponding typed rvals.

compiler/proc_gen.m:
	Take that map, and put it into the code_info, to allow references
	to those structures to be translated.

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

compiler/code_info.m:
	Include a map giving the representation of each constant structure
	in the code_info.

compiler/unify_gen.m:
	Add the predicates needed to convert the constant structures of a
	module to LLDS rvals. For now, this code works only on the kinds of
	constant structures generated by polymorphism.m.

	Handle unifications whose right hand side is a reference to a constant
	structure.

compiler/global_data.m:
compiler/stack_layout.m:
	Use the new typed_rval type where relevant.

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

CHANGES IN THE MLDS BACKEND:

compiler/ml_proc_gen.m:
	Before we generate code for the predicates of the module, convert
	the constant structures to typed MLDS rvals. Create a map mapping
	each constant structure number to the corresponding typed rvals.

	Factor out some code into a predicate of its own.

compiler/ml_gen_info.m:
	Include a map giving the representation of each constant structure
	in the ml_gen_info.

	Also add to the ml_gen_info an indication of what GC system we are
	generating code for, since the code generator needs to know this often.

compiler/ml_unify_gen.m:
	Add the predicates needed to convert the constant structures of a
	module to MLDS rvals. For now, this code works only on the kinds of
	constant structures generated by polymorphism.m.

	Handle unifications whose right hand side is a reference to a constant
	structure.

	Simplify some existing code.

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

MINOR CHANGES:

mdbcomp/prim_data.m:
	Add a predicate that gets both the module name and the base name
	from a sym_name at the same time. This is used for minor speedups
	in other code updated in this diff.

compiler/dead_proc_elim.m:
	Scan constant structures for references to entities that need to be
	kept alive.

compiler/term_constr_build.m:
compiler/term_traversal.m:
	Do not build size constraints from references to constant structures.
	The sizes of constant terms don't change, so they are irrelevant
	when building constraints for finding argument size changes.

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

TRIVIAL CHANGES TO CONFORM TO OTHER CHANGES:

compiler/hlds_out_module.m:
	Print out the constant structure database if asked.

doc/user_guide.tex:
	Document how to ask for it.

compiler/hlds_out_util.m:
	Print out the new cons_ids.

compiler/hlds_out_mode.m:
	Print out the new cons_ids in insts.

	Remove a compiler abort, to help debug a problem.

	Improve the structure of a predicate.

compiler/hlds_out_goal.m:
	Fix some missing newlines.

compiler/hlds_code_util.m:
	Add some utility predicates needed by the modules above.

	Conform to the changes above.

compiler/mlds_to_il.m:
	Reorder some predicates.

	Conform to the changes above.

compiler/bytecode_gen.m:
compiler/ctgc.selector.m:
compiler/dependency_graph.m:
compiler/erl_unify_gen.m:
compiler/export.m:
compiler/implementation_defined_literals.m:
compiler/inst_check.m:
compiler/llds_out_globals.m:
compiler/mercury_to_mercury.m:
compiler/ml_global_data.m:
compiler/ml_switch_gen.m:
compiler/ml_type_gen.m:
compiler/module_qual.m:
compiler/prog_rep.m:
compiler/prog_type.m:
compiler/prog_util.m:
compiler/rbmm.execution_path.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/type_ctor_info.m:
compiler/unused_imports.m:
compiler/var_locn.m:
compiler/xml_documentation.m:
	Conform to the changes above.

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

OTHER INDEPENDENT CHANGES:

compiler/handle_options.m:
	Add a dump option that is useful for debugging when working on
	polymorphism.m and constant structures.

compiler/equiv_type_hlds.m:
	Fix an old performance bug: make the code handling try goals keep
	the old memory cells representing such goals, instead of rebuilding
	them, if no changes took place inside them.

compiler/ml_accurate_gc.m:
	Move a test earlier, to allow us to avoid more work in the common case.

compiler/erl_code_gen.m:
compiler/error_util.m:
compiler/hhf.m:
compiler/inst_util.m:
compiler/ml_code_util.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/modecheck_call.m:
compiler/modecheck_util.m:
compiler/post_typecheck.m:
compiler/size_prof.m:
compiler/stack_opt.m:
compiler/stratify.m:
compiler/unused_args.m:
compiler/post_type_analysis.m:
library/erland_rtti_implementation.m:
	Minor cleanups.

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

CHANGES TO THE TEST SUITE:

tests/invalid/any_passed_as_ground.err_exp2:
tests/invalid/invalid_default_func_1.err_exp2:
tests/invalid/invalid_default_func_3.err_exp2:
tests/invalid/try_detism.err_exp2:
	Add second expected output files for these tests. We need alternate
	expected outputs because the numbers of some of the typeinfo variables
	mentioned in error message are different depending on whether or not
	const structures are enabled.
2012-06-08 15:37:07 +00:00
Zoltan Somogyi
0da8adff7d This gets a speedup of 1.5% on tools/speedtest.
Estimated hours taken: 1
Branches: main

This gets a speedup of 1.5% on tools/speedtest. This is a bit odd, since the
relevant procedure showed up as taking only 0.6% of runtime in the profile :-)

compiler/code_info.m:
	Construct the proc_label for the procedure being compiled just once,
	instead of doing once for every label we generate.

compiler/proc_label.m:
	We used to create create proc_labels by creating an rtti_proc_label,
	and then using SOME of its fields to make the proc_label. Some of the
	fields we didn't use were expensive to fill. So we now just get the
	values of the fields we want directly.
2012-04-24 06:02:32 +00:00
Julien Fischer
3a74d3fd88 Change the argument order of some predicates in the stack and pqueue modules in
Branches: main

Change the argument order of some predicates in the stack and pqueue modules in
order to make them more conducive to the use of state variable notation.

library/pqueue.m:
library/stack.m:
	Change the argument ordering as above.

	Rename some variables in stack.m.

library/svpqueue.m:
library/svstack.m:
	Make the predicates exported by these modules as obsolete.

NEWS:
	Announce the above changes.

compiler/code_info.m:
compiler/delay_info.m:
compiler/ml_gen_info.m:
compiler/mode_constraint_robdd.m:
compiler/mode_ordering.m:
	Conform to the above changes.
2012-01-24 05:23:07 +00:00
Julien Fischer
b2f25476d0 Fix bug #248: make the argument order of the singleton_set/2 predicates in the
Branches: main, 11.07 (partial)

Fix bug #248: make the argument order of the singleton_set/2 predicates in the
various set modules in the standard library consistent.  (This breaks backwards
compatibility but in a fairly minor way.)

Add the predicate is_singleton/2 to those set modules that do not already
provide it.

Fix a bug in the implementation of set_unordlist.singleton_set/2.

library/set.m:
library/set_bbbtree.m:
library/set_ctree234.m:
library/set_ordlist.m:
library/set_unordlist.m:
	Swap the argument order of singleton_set/2.

	Add is_singleton/2 where it wasn't already present.

library/set_unordlist.m:
	Fix a bug: singleton_set/2 failed to take account of
	the fact that the representation could contain duplicates
	in the singleton_setT::out, set_unordlist(T)::in) mode.
	The fix is to sort and remove the duplicates before checking
	whether the set is singleton.

NEWS:
	Announce the above changes.

library/eqvclass.m:
library/tree234.m:
compiler/accumulator.m:
compiler/code_info.m:
compiler/graph_colour.m:
compiler/higher_order.m:
compiler/lp_rational.m:
compiler/ml_tag_switch.m:
compiler/pd_info.m:
compiler/pd_util.m:
compiler/proc_gen.m:
compiler/prog_mode.m:
compiler/term_pass1.m:
compiler/type_constraints.m:
compiler/unneeded_code.m:
compiler/var_locn.m:
deep_profiler/autopar_costs.m:
deep_profiler/var_use_analysis.m:
tests/general/set_test.m:
	Conform to the above changes.

tests/hard_coded/Mmakefile:
tests/hard_coded/singleton_dups.{m,exp}:
	Add a regression test for the problem with set_unordlist.singleton_set/2.
2012-01-17 15:49:47 +00:00
Peter Wang
2ccac171dd Add float registers to the Mercury abstract machine, implemented as an
Branches: main

Add float registers to the Mercury abstract machine, implemented as an
array of MR_Float in the Mercury engine structure.

Float registers are only useful if a Mercury `float' is wider than a word
(i.e. when using double precision floats on 32-bit platforms) so we let them
exist only then.  In other cases floats may simply be passed via the regular
registers, as before.

Currently, higher order calls still require the use of the regular registers
for all arguments.  As all exported procedures are potentially the target of
higher order calls, exported procedures must use only the regular registers for
argument passing.  This can lead to more (un)boxing than if floats were simply
always boxed.  Until this is solved, float registers must be enabled explicitly
with the developer only option `--use-float-registers'.

The other aspect of this change is using two consecutive stack slots to hold a
single double variable.  Without that, the benefit of passing unboxed floats
via dedicated float registers would be largely eroded.


compiler/options.m:
	Add developer option `--use-float-registers'.

compiler/handle_options.m:
	Disable `--use-float-registers' if floats are not wider than words.

compiler/make_hlds_passes.m:
	If `--use-float-registers' is in effect, enable a previous change that
	allows float constructor arguments to be stored unboxed in structures.

compiler/hlds_llds.m:
	Move `reg_type' here from llds.m and `reg_f' option.

	Add stack slot width to `stack_slot' type.

	Add register type and stack slot width to `abs_locn' type.

	Remember next available float register in `abs_follow_vars'.

compiler/hlds_pred.m:
	Add register type to `arg_loc' type.

compiler/llds.m:
	Add a new kind of lval: double-width stack slots.
	These are used to hold double-precision floating point values only.

	Record setting of `--use-float-registers' in exprn_opts.

	Conform to addition of float registers and double stack slots.

compiler/code_info.m:
	Make predicates take the register type as an argument,
	where it can no longer be assumed.

	Remember whether float registers are being used.

	Remember max float register for calls to MR_trace.

	Count double width stack slots as two slots.

compiler/arg_info.m:
	Allocate float registers for procedure arguments when appropriate.

	Delete unused predicates.

compiler/var_locn.m:
	Make predicates working with registers either take the register type as
	an argument, or handle both register types at once.

	Select float registers for variables when appropriate.

compiler/call_gen.m:
	Explicitly use regular registers for all higher-order calls,
	which was implicit before.

compiler/pragma_c_gen.m:
	Use float registers, when available, at the interface between Mercury
	code and C foreign_procs.

compiler/export.m:
	Whether a float rval needs to be boxed/unboxed when assigned to/from a
	register depends on the register type.

compiler/fact_table.m:
	Use float registers for arguments to predicates defined by fact tables.

compiler/stack_alloc.m:
	Allocate two consecutive stack slots for float variables when
	appropriate.

compiler/stack_layout.m:
	Represent double-width stack slots in procedure layout structures.

	Conform to changes.

compiler/store_alloc.m:
	Allocate float registers (if they exist) for float variables.

compiler/use_local_vars.m:
	Substitute float abstract machine registers with MR_Float local
	variables.

compiler/llds_out_data.m:
compiler/llds_out_instr.m:
	Output float registers and double stack slots.

compiler/code_util.m:
compiler/follow_vars.m:
	Count float registers separately from regular registers.

compiler/layout.m:
compiler/layout_out.m:
compiler/trace_gen.m:
	Remember the max used float register for calls to MR_trace().

compiler/builtin_lib_types.m:
	Fix incorrect definition of float_type_ctor.

compiler/bytecode_gen.m:
compiler/continuation_info.m:
compiler/disj_gen.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/hlds_out_goal.m:
compiler/jumpopt.m:
compiler/llds_to_x86_64.m:
compiler/lookup_switch.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/proc_gen.m:
compiler/string_switch.m:
compiler/tag_switch.m:
compiler/tupling.m:
compiler/x86_64_regs.m:
	Conform to changes.

runtime/mercury_engine.h:
	Add an array of fake float "registers" to the Mercury engine structure,
	when MR_Float is wider than MR_Word.

runtime/mercury_regs.h:
	Document float registers in the Mercury abstract machine.

	Add macros to access float registers in the Mercury engine.

runtime/mercury_stack_layout.h:
	Add new MR_LongLval cases to represent double-width stack slots.

	MR_LONG_LVAL_TAGBITS had to be increased to accomodate the new cases,
	which increases the number of integers in [0, 2^MR_LONG_LVAL_TAGBITS)
	equal to 0 modulo 4.  These are the new MR_LONG_LVAL_TYPE_CONS_n cases.

	Add max float register field to MR_ExecTrace.

runtime/mercury_layout_util.c:
runtime/mercury_layout_util.h:
	Extend MR_copy_regs_to_saved_regs and MR_copy_saved_regs_to_regs
	for float registers.

	Understand how to look up new kinds of MR_LongLval: MR_LONG_LVAL_TYPE_F
	(previously unused), MR_LONG_LVAL_TYPE_DOUBLE_STACKVAR,
	MR_LONG_LVAL_TYPE_DOUBLE_FRAMEVAR.

	Conform to the new MR_LONG_LVAL_TYPE_CONS_n cases.

runtime/mercury_float.h:
	Delete redundant #ifdef.

runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
	Conform to changes (untested).

trace/mercury_trace.c:
trace/mercury_trace.h:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
trace/mercury_trace_spy.c:
trace/mercury_trace_vars.c:
trace/mercury_trace_vars.h:
	Handle float registers in the trace subsystem.  This is mostly a matter
	of saving/restoring them as with regular registers.
2011-10-17 04:31:33 +00:00
Paul Bone
2efb78955e The loop control transformation now works.
This patch commits the code-generator parts of the loop control transformation.
It also makes corrections and changes to the source-to-source, runtime and
library parts of the transformation.

Preliminary results look good, loop controlled right-recursive dependent code
performs as fast as independent right-recursive code, and it does so using the
minimum number of contexts (8 on apollo (an i7)).  Previously, when
transforming code by hand, we needed 32 contexts on a 4 core system (taura).
The reason for this is that we changed our design so that the master context
would become blocked if there was no free slot.  This ensures that once a
worker finishes it's current job new work is either already available or can be
made available promptly.

compiler/par_conj_gen.m:
compiler/code_gen.m:
    Generate code for the new loop_control scope.

compiler/llds_out_instr.m:
    Write out the lc_spawn_off instruction correctly.

compiler/code_info.m:
    Add support for storing out-of-line code in the code_info structure.

compiler/proc_gen.m:
    After generating a procedure's body add any out-of-line code stored in the
    code_info structure onto the end of the procedure (after the exit code).

compiler/par_loop_control.m:
    Add missing parts to the loop control transformation:
        + Add the barrier in the base case.
        + Transform non-parallel recursive calls.
        + Add a join_and_terminate call to the end of the forked-off code.

    Make minor corrections to comments.

runtime/mercury_par_builtin.h:
runtime/mercury_par_builtin.c:
    MR_lc_wait_free_slot and MR_lc_spawn_off no-longer mangle the labels they
    are passed.

    Fix a typeo that caused a bug.

    Add debugging code.

library/par_builtin.m:
    Store the value of LC in a stack slot during lc_wait_for_slot, This makes
    sure it is available in the case that lc_wait_for_slot suspends the
    context.

    Remove the loop_control_slot type, we now use integers to represent the
    position of a slot within a loop control structure.
2011-10-09 09:56:20 +00:00