Commit Graph

60 Commits

Author SHA1 Message Date
Zoltan Somogyi
063c7fab12 Fix punctuation. 2022-10-17 18:09:34 +11:00
Zoltan Somogyi
0f0f1e6605 Parse conjunctions using tail recursive code ...
to allow even very long conjunctions to be parsed in constant stack space.

compiler/prog_item.m:
    We used to represent a conjunction in the parse tree as

        conj_expr(ContextA, GoalA,
            conj_expr(ContextB, GoalB,
                conj_expr(ContextC, GoalC,
                    GoalD)))

    To enable the changes in parse_goal.m and parse_dcg_goal.m, switch over
    to representing them as

        conj_expr(ContextA, GoalA, [GoalB, GoalC, GoalD])

    and likewise for par_conj_exprs.

    The fact that this throws away ContextB and ContextC is not a problem;
    they were never used, being thrown away when converting the parse tree
    to the HLDS.

compiler/parse_goal.m:
compiler/parse_dcg_goal.m:
    Have the new predicate parse_goal_conjunction, and its DCG variant,
    accumulate errors *alongside* disjuncts, to be checked just once
    outside the loop, and keep the loop going as long as the right operand
    of the conjunction operator (comma or ampersand) is another conjunction
    of the same kind (plain or parallel). This makes parse_goal_conjunction
    self-tail-recursive, which should allow it to process conjunctions
    of arbtrary length using fixed stack space (in grades that support
    tail recursion, that is).

    Unlike with disjunctions, don't flatten conjunctions; leave that to
    goal_expr_to_goal.m.

compiler/goal_expr_to_goal.m:
    Convert the updated parse tree representation of conjunctions to HLDS.

    Use the same auxiliary predicate, suitably generalized, for flattening
    both plain and parallel conjunctions.

compiler/add_pragma_tabling.m:
compiler/get_dependencies.m:
compiler/make_hlds_warn.m:
compiler/module_qual.collect_mq_info.m:
compiler/parse_tree_out_clause.m:
compiler/prog_item_stats.m:
compiler/prog_mutable.m:
compiler/prog_util.m:
    Conform to the change in prog_item.m.
2022-05-07 17:51:49 +10:00
Zoltan Somogyi
edf8afc0df Document an old design decision. 2022-03-07 07:41:36 +11:00
Zoltan Somogyi
e42e24d8f3 Use string.format to construct foreign lang code. 2022-03-06 18:22:39 +11:00
Zoltan Somogyi
7424f93a30 Use one error msg for undeclared mode references.
compiler/add_clause.m:
compiler/make_hlds_passes.m:
    We used to have two separate predicates for generating error messages
    about references to undeclared modes of predicates and functions.
    One, in add_clause.m, was for undeclared modes in mode-specific clauses,
    and generated messages that were as informative as possible.
    The other, in make_hlds_passes.m, which was used for undeclared modes
    in type_spec in foreign_export pragmas, was perfunctory, and gave
    no details.

    Act on an old XXX and delete the second predicate, replacing its uses
    by calls to the first. To make this possible, move the first predicate,
    which used to be private to add_clause.m, to make_hlds_passes.m.

compiler/add_pragma.m:
compiler/add_pragma_type_spec.m:
    Call the first predicate, not the second.

compiler/prog_item.m:
    The first predicate requires access to a varset that describes the names
    of any inst variables in the undeclared mode. Include a varset for this
    purpose in foreign_export pragmas. (type_spec pragmas already had the
    required varset.)

compiler/convert_parse_tree.m:
compiler/get_dependencies.m:
compiler/item_util.m:
compiler/make_hlds_error.m:
compiler/module_qual.qualify_items.m:
compiler/parse_pragma_foreign.m:
compiler/parse_tree_out_pragma.m:
compiler/prog_mutable.m:
    Conform to the change in prog_item.m.

tests/invalid/pragma_qual_error.err_exp:
tests/invalid/type_spec.err_exp:
    Expect updated error messages.
2022-02-23 04:31:38 +11:00
Zoltan Somogyi
ee0a21b98c Replace some 'arity's with {pred_form,user}_arity.
This removes uncertainty in the affected places in the compiler,
because unlike the 'arity' type, the pred_form_arity and user_arity
types specify *which definition* of arity they represent.

Whether I replaced a use of arity with pred_form_arity or user_arity
depended on whether I believed the original arity to have been intended to be
- a pred_form_arity without the wrapper, or
- a user_arity without the wrapper.
The reason for the size of this diff is that when I replaced one use of
arity with pred_form_arity or user_arity, I often could not be sure about
the right way to propagate this change to the rest of the affected code
without making similar replacements elsewhere, and seeing whether
*that* worked. This diff is in effect the "smallest fixpoint" of this process.

In places where the pred form arity of predicate or function
is inherent in a list which has one element for each argument
(the element may be a term, a type, a mode, etc), do not take
a separate arity argument as well, since (a) it is not needed, and
(b) it is a potential source of inconsistencies. The only downside
is that we may need to take the length of a list in both the caller
and the callee, but this cost is negligible.

Add "XXX ARITY" comments to mark opportunities for future improvements.

compiler/hlds_clauses.m:
    Make clauses_info_init take a pred_form_arity instead of an arity
    as argument.

compiler/hlds_pred.m:
    Make pred_info_init take a pred_form_arity instead of an arity
    as argument.

compiler/prog_data.m:
    Specify that the arity part of the pf_sym_name_arity type
    is a pred_form_arity.

    Add a variant of the sym_name_arity type, which does not say
    what kind of arity it contains, which does say that it contains
    a pred_form_arity.

    Store the arities of instance methods as user_arity, not arity.

    Move the definition of an instance method out of between
    the instance's name and its arity.

    Add a convenience function for computing the pred_form_arity
    of an argument list.

    Delete a type moved to parse_sym_name.m.

compiler/prog_item.m:
    Use user_arities in item_initialise_infos and item_finalise_infos.

compiler/typecheck_errors.m:
    Specify that the arity in an arg_vector_plain_pred_call,
    and in the argument list of a function that construct a message
    for a related type error, is a pred_form_arity.

compiler/add_class.m:
    In the predicate that converts clauses to instance methods,
    delete its arity argument, given that another argument is
    the list of argument terms.

    Move the generator of a variable before its first consumer.

compiler/add_clause.m:
    In predicates that add clauses to the HLDS, delete their arity argument
    where another argument is the list of argument terms.

compiler/superhomogeneous.m:
    Explicit specify that the arity of a clause is recorded as a
    pred_form_arity.

compiler/add_foreign_proc.m:
    In predicates that add foreign_procs to the HLDS, delete their arity
    argument where another argument is the list of argument terms.

compiler/check_typeclass.m:
    Record the arity of the method being checked as user_arity.

    Fix incorrect arities in the error messages we generate.

compiler/make_hlds_error.m:
    Get callers to specify the pred_form_arity of a missing predicate or
    function. If that predicate or function exists with other arities,
    we try to be helpful and print out those arities in the error message.
    This process had some bugs, which this diff fixes.

compiler/typecheck_info.m:
    Specify that the arity we record for overloaded symbols is the
    pred_form_arity.

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

    Move a comment to the code it is about.

compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
    Conform to the changes above.

    In two comments, write out the user arities of function methods,
    not their pred form arity.

compiler/make_hlds_passes.m:
    Conform to the change in the representation of initialise and finalise
    items.

    Use the new method for constructing target names in prog_foreign.m.

    Indent the code example part of an error message.

compiler/prog_foreign.m:
    Provide a single predicate for creating target language names
    for initialise and finalise predicates. This new predicate factors out
    what used to be duplicate code in make_hlds_passes.m.

compiler/parse_sym_name.m:
    Move a type here from prog_data.m, since it is used only by
    parse_sym_name.m and the modules that call it.

compiler/add_pragma_tabling.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/add_special_pred.m:
compiler/check_promise.m:
compiler/det_report.m:
compiler/get_dependencies.m:
compiler/goal_expr_to_goal.m:
compiler/higher_order.m:
compiler/hlds_out_typeclass_table.m:
compiler/intermod.m:
compiler/mark_tail_calls.m:
compiler/parse_class.m:
compiler/parse_mutable.m:
compiler/parse_tree_out.m:
compiler/pred_name.m:
compiler/prog_mutable.m:
compiler/prog_out.m:
compiler/state_var.m:
compiler/table_gen.m:
compiler/typecheck.m:
compiler/unused_args.m:
    Conform to the changes above.

compiler/make_hlds.m:
    Conform to the change in add_class.m.

tests/invalid/bad_pred_arity.err_exp:
tests/invalid/mode_decl_in_wrong_section.err_exp:
tests/invalid/pragma_c_code_dup_var.err_exp:
tests/invalid/state_vars_test3.err_exp:
tests/invalid/typeclass_bogus_method.err_exp:
tests/invalid/typeclass_test_3.err_exp:
tests/invalid/typeclass_test_4.err_exp:
    Update these expected outputs for the bug fixes above.

tests/invalid_nodepend/bad_finalise_decl.err_exp:
tests/invalid_nodepend/bad_initialise_decl.err_exp:
    Update these expected outputs for formatting change above.

tests/invalid/no_method.{m,err_exp}:
    A new test case for an arity-related error message that wasn't
    being exercised before.

tests/invalid/Mmakefile:
    Enable the new test case.
2022-02-17 22:21:16 +11:00
Zoltan Somogyi
c1f0913996 Simplify the logic of prog_mutable.m.
compiler/prog_mutable.m:
    The old logic was complicated by the need to have some decisions
    made by prog_mutable.m and some by add_mutable_aux_preds.m,
    which had different tasks (generating public declarations
    vs generating both public and private definitions), and thus
    used different approaches.

    Replace this with code in which for each kind of auxiliary predicate,
    the code to generate its declaration is just before the code
    to generate its definition. And the code that decides what public
    declarations to generate is just before the code that decides
    what public and private definitions to generate.

    Make this latter logic operate as directly as possible on the mutable's
    attributes, instead of first calling a separate predicate to compute
    the set of auxiliary predicates the mutable needs, recording the results
    in the mutable_target_params structure, and then generating definitions
    as directed by this structure.

    To make this possible, split some existing predicates that used
    to do two related but nevertheless separate jobs, such as defining
    get and set predicates for both constant and nonconstant mutables.

    Give a bunch of predicates names that better reflect whether they
    generate declarations only, definitions only, or both.

    Consistently refer to the name of the mutable as MutableName,
    since the code handles the names of other kinds of things as well.

    Give some predicates slightly shorter names, so calls to them
    fit on just one line.

compiler/prog_item.m:
    Change the arg type of a function based on the updated needs of
    prog_mutable.m.

compiler/add_mutable_aux_preds.m:
compiler/comp_unit_interface.m:
    Conform to the changes above.
2021-05-29 20:40:18 +10:00
Zoltan Somogyi
b0875c3769 Simplify the creation of the global variable. 2021-05-28 00:55:21 +10:00
Zoltan Somogyi
e10bc34a74 Implement mutables only in prog_mutable.m.
compiler/prog_mutable.m:
    Move code implementing mutables here, mostly from add_mutable_aux_preds.m,
    but some from comp_unit_interface.m. Export only what those two modules
    need.

    Replace the

compiler/add_mutable_aux_preds.m:
compiler/comp_unit_interface.m:
    Delete the code moved to prog_mutable. In add_mutable_aux_preds.m,
    make minor rearrangements to make this possible.

compiler/hlds_module.m:
compiler/prog_foreign.m:
    Move the pred_target_names type, and two predicates that operate
    on it, from hlds_module.m to prog_foreign.m, to make it accessible
    from prog_mutable.m, which is part of the parse_tree package, and thus
    should not import anything from the hlds package.

compiler/prog_item.m:
    Move a (renamed) type here from add_mutable_aux_preds.m, since
    prog_mutable.m now needs access to it as well.

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

compiler/prog_data.m:
    Fix some old comments.
2021-05-27 22:06:33 +10:00
Zoltan Somogyi
854d63d1ce Make illegal mutable attributes unrepresentable.
compiler/prog_item.m:
    Change the representation of mutable_var_attributes,
    in two different ways.

    The first is replacing a list of elements that each say
    "in this language, use this name", which allowed duplicate entries
    for a language, with a map from languages to names, which does not.

    The second is replacing of a set of four boolean-equivalent flags,
    many of whose 16 possible combinations are invalid, with
    a structured type that allows the representation of only
    the valid combinations.

    To allow code working on attributes to exploit this defense against
    illegal attribute sets, export the new representation. (Fully taking
    advantage of this will require moving the code that creates the
    declarations and definitions of each aux predicate next to each other.)

compiler/parse_mutable.m:
    Previously, the code that parsed mutable declarations checked for
    *some* invalid combinations of attributes, but not *all*. Since
    invalid combinations are no longer representable, the new parsing code
    does check for a reject all invalid combinations.

    Diagnose repeated attributes, as well as conflicting attributes.

    Improve error messages, even when not related to this change,
    e.g. by quoting echoed user code.

compiler/add_mutable_aux_preds.m:
    Delete the code that used to check for illegal combinations of mutable
    values, since these cannot happen anymore.

    Conform to the change above.

    Delete an unneeded field from the parameters. The old ImplLang and Lang
    fields contained exactly the same information, so keep only Lang.

compiler/prog_mutable.m:
    Conform to the change above.

tests/invalid/bad_mutable.m:
    Add some more bad mutable declarations to diagnose.

    Add an XXX pointing out an error for which we generate *two* error
    messages (one in add_mutable_aux_preds.m, and one during module
    qualification).

tests/invalid/bad_mutable.err_exp:
    Expect the updated error messages for both the old and the new
    bad mutable declarations.

tests/invalid/bad_finalise.err_exp:
    Expect quoting of echoed user code.
2021-05-25 21:39:58 +10:00
Zoltan Somogyi
99334e8469 Switch to structured item sequence numbers.
compiler/prog_data.m:
    Define a data type that encodes the distinction between valid
    and dummy item sequence numbers in the type. Previously, different
    parts of the compiler expressed this distinction in two different ways,
    either using "-1" to represent a dummy sequence number, or using "no"
    in a maybe(int) type.

compiler/prog_item.m:
    Use the new type instead of plain "int" as the sequence number in items.

compiler/hlds_pred.m:
    Use the new type instead of plain "int" as the sequence number
    in cur_user_decl_infos. Document the fact that the presence of a
    cur_user_decl_info in a pred_info does NOT guarantee a valid
    item sequence number.

compiler/add_foreign_proc.m:
    When adding a foreign_proc to the HLDS, pass a whole item_pragma_info,
    not its components. (This change is what this diff started as, before
    the item_seq_num changes overwhelmed it.)

compiler/accumulator.m:
compiler/add_class.m:
compiler/add_clause.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma.m:
compiler/add_pragma_tabling.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_special_pred.m:
compiler/check_typeclass.m:
compiler/comp_unit_interface.m:
compiler/decide_type_repn.m:
compiler/default_func_mode.m:
compiler/hlds_clauses.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/make_hlds_passes.m:
compiler/par_loop_control.m:
compiler/parse_class.m:
compiler/parse_dcg_goal.m:
compiler/parse_inst_mode_defn.m:
compiler/parse_item.m:
compiler/parse_module.m:
compiler/parse_mutable.m:
compiler/parse_pragma.m:
compiler/parse_pragma_analysis.m:
compiler/parse_pragma_foreign.m:
compiler/parse_pragma_tabling.m:
compiler/parse_type_defn.m:
compiler/parse_type_repn.m:
compiler/parse_types.m:
compiler/proc_requests.m:
compiler/prog_mutable.m:
compiler/split_parse_tree_src.m:
compiler/stm_expand.m:
compiler/style_checks.m:
compiler/table_gen.m:
    Conform to the changes above.
2021-05-19 13:27:27 +10:00
Zoltan Somogyi
3248c11c11 Move a comment to the code it describes. 2019-09-02 00:48:39 +10:00
Zoltan Somogyi
315c7758a4 Add all predicates via item_pred_decl_infos.
compiler/add_pred.m:
    Don't export the predicate that used to allow other parts of the compiler
    to create new predicates without constructing a new item_pred_decl_info.
    In fact, inline this predicate in its only caller.

    Base decisions about what predicates are exported based on the predicate
    status, which is always there, not on an optionally supplied
    item_mercury_status.

    Standardize some variable names.

compiler/prog_item.m:
    Since the change to add_pred.m does not allow other compiler modules
    to specify a pred_origin for the new predicate *directly*, make it
    possible for them to specify it *indirectly*. This centralises handling
    of the implications of the origins of new compiler-generated predicates
    in one place in add_pred.m.

    Delete the maybe_allow_export attribute from items. It had no meaningful
    semantics, so there was no correct way to fill in that field.

compiler/prog_data.m:
    Move the definitions of the types that describe the auxiliary predicates
    used by solver types and tabling here from hlds_pred.m, since prog_item.m
    now needs access to them.

compiler/hlds_pred.m:
    Delete the type definitions moved to prog_data.m.

    Add three new kinds of origins for predicates, which we have previously
    ignored.

compiler/add_class.m:
compiler/add_foreign_proc.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma_tabling.m:
compiler/add_solver.m:
    Change the code that adds new predicates to the HLDS to conform
    to the changes above.

compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/layout_out.m:
compiler/make_hlds_passes.m:
compiler/mode_errors.m:
compiler/polymorphism.m:
compiler/prog_mutable.m:
compiler/trace_params.m:
    Conform to the changes above.
2019-09-02 00:45:45 +10:00
Zoltan Somogyi
a39adc549d Centralize decisions about which aux preds a mutable needs.
The implementation of a mutable requires several predicates, some user visible,
some not. Exactly what set of predicates a mutable needs depends both on its
attributes and on the target platform. Previously, we computed that set of
predicates three times:

- when adding their declarations to the HLDS,
- when adding their definitions to the HLDS, and
- when adding (a subset of) their declarations to a .int0 file.

This diff tries to centralizes these decisions in one place. It does not
quite get there, because getting there would require compromises that are
undesirable for other reasons, but it gets close.

compiler/prog_data.m:
    Document the uses of the various kinds of predicates we can generate
    for a mutable.

compiler/prog_mutable.m:
    Add a predicate that decides which public auxiliary predicates
    a mutable needs, for use by both add_mutable_aux_preds.m and by
    comp_unit_interface.m.

    Add a predicate that constructs the pred_decl item of any given
    mutable auxiliary predicate, again for use by add_mutable_aux_preds.m
    and by comp_unit_interface.m.

    Move predicates that are used only by add_mutable_aux_preds.m
    to add_mutable_aux_preds.m.

    Delete predicates that are no longer needed.

compiler/add_mutable_aux_preds.m:
    Add a predicate that decides which private auxiliary predicates
    a mutable needs,

    Use the new mechanisms above to declare a mutable's auxiliary procedures.

    Use the new mechanisms above to define a mutable's auxiliary procedures,
    mostly. There is still some code that repeats the logic of the decision
    predicate for public auxiliary predicates, but now a sanity check
    ensures that the two decision procedures arrived at the same result.

    Move predicates that are used only by add_mutable_aux_preds.m
    here from prog_mutable.m.

    Delete predicates that are no longer needed.

    Give several predicates more descriptive names. Standardize
    argument orders.

compiler/add_pred.m:
    Add a mechanism for adding a pred_decl item as a whole to the HLDS.
    (Previously, we could a pred_decl to the HLDS by first breaking it down
    to its components.) The code is mostly copied from make_hlds_passes.m.

compiler/comp_unit_interface.m:
    Use the new mechanisms above to declare a mutable's auxiliary procedures.
    The new code does not need any knowledge of what auxiliary predicates
    a mutable needs.

compiler/make_hlds_passes.m:
    Use the new mechanism in add_pred.m, in order to avoid code duplication.

library/set.m:
    Add a new predicate for add_mutable_aux_preds.m.
2019-09-01 18:22:06 +10:00
Zoltan Somogyi
ce65f6b2aa Fix more issues reported by --warn-inconsistent-pred-order-clauses.
compiler/assertion.m:
compiler/clause_to_proc.m:
compiler/compute_grade.m:
compiler/const_struct.m:
compiler/export.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_mode.m:
compiler/hlds_promise.m:
compiler/lambda.m:
compiler/lp_rational.m:
compiler/make_goal.m:
compiler/mercury_compile_llds_back_end.m:
compiler/ml_type_gen.m:
compiler/name_mangle.m:
compiler/parse_tree_out_inst.m:
compiler/parse_tree_out_pragma.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/passes_aux.m:
compiler/polyhedron.m:
compiler/pred_table.m:
compiler/process_util.m:
compiler/prog_data.m:
compiler/prog_data_foreign.m:
compiler/prog_mutable.m:
compiler/rat.m:
compiler/recompilation.m:
compiler/source_file_map.m:
compiler/timestamp.m:
compiler/trace_params.m:
compiler/write_deps_file.m:
    As above.

compiler/Mercury.options:
    Don't pass --no-warn-inconsistent-pred-order-clauses for the above modules.
2019-08-23 20:54:27 +10:00
Zoltan Somogyi
0b60daa112 Record the origin of mutable aux predicates.
compiler/prog_item.m:
    If a predicate declaration is created for an auxiliary predicate
    for an operation on a mutable, add slots for recording the details
    of the item's origin.

compiler/hlds_pred.m:
compiler/prog_data.m:
    Move the mutable_pred_kind type from hlds_pred.m to prog_data.m
    to make the above possible.

compiler/prog_mutable.m:
    Fill the slots added to prog_item.m for some kinds of mutable
    aux predicates.

compiler/add_mutable_aux_preds.m:
    Fill the slots added to prog_item.m for the other kinds of mutable
    aux predicates.

    Fix an old typo: record a mutable's init predicate as its init predicate,
    not as its pre-init predicate.

compiler/make_hlds_passes.m:
    Use the new info in predicate declaration items to create an accurate
    predicate origin for mutable aux predicates.

compiler/dead_proc_elim.m:
    Conform to the change above.
2019-05-30 12:13:54 +02: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
8de9dd84fd Replace (C->T;E) with (if C then T else E). 2015-07-29 04:43:54 +10:00
Zoltan Somogyi
4b135c9a78 Reorder the fields of items for meaningful sorting.
compiler/prog_item.m:
    Put the fields of the types representing items into an order that is
    useful for sorting, since we sort the items we put into interface files.
    This should make it less likely that just changing the order of e.g. type
    definitions requires a recompilation of all the other modules that import
    the changed module.

    Make the same change in the types representing class methods, since these
    are often copied to and from items.

compiler/*.m:
    Conform to the above.
2015-01-28 15:32:01 +11:00
Zoltan Somogyi
5cc616dcef Remove the condition field from items.
We used to have a condition field in pred_infos, but we deleted it in 2004,
saying "it won't be used in its current form". The parser that was supposed
to read in conditions has never been written, and this field has been sitting
there unused in several kinds of items for the last 20 years. These fields
also won't be used in their current form, and they gave me unnecessary work
to do when factoring out the common code for aux preds for mutables, so
I am deleting them to prevent another such occurrence.

compiler/prog_data.m:
    Remove the definition of the condition type.

compiler/add_class.m:
compiler/add_mode.m:
compiler/add_mutable_aux_preds.m:
compiler/add_type.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/make_hlds_passes.m:
compiler/mercury_to_mercury.m:
compiler/module_imports.m:
compiler/module_qual.m:
compiler/prog_io_item.m:
compiler/prog_io_mode_defn.m:
compiler/prog_io_pragma.m:
compiler/prog_io_type_defn.m:
compiler/prog_io_typeclass.m:
compiler/prog_io_util.m:
compiler/prog_item.m:
compiler/prog_mutable.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/recompilation.version.m:
compiler/write_module_interface_files.m:
    Conform to the above. Don't call the condition type's parser, don't
    pass it around, don't put it into items, etc.
2015-01-28 00:22:59 +11:00
Zoltan Somogyi
cc1b3e1b42 Add aux entities to the HLDS without add_item_*_pass_N.
When we see some kinds of items, e.g. mutables, in make_hlds_passes.m,
we have to declare and/or define some new entities, such as the get and set
predicates of those mutables. We used to do this by constructing new items,
and then invoking add_item_decl_pass_1, add_item_decl_pass_2, or
add_item_pass_3 to add those newly constructed items to the HLDS.
This approach had several undesirable consequences.

- We had to make make_hlds_passes.m export add_item_decl_pass_1 and
  add_item_pass_3 predicates, even though their tasks *should* be local
  to make_hlds_passes.m.

- add_item_decl_pass_2 was not exported, but it *was* used by code
  that should not be in make_hlds_passes.m, but was here just to avoid
  having to export add_item_decl_pass_2.

- Calls to add_item_*_pass_N may, in general, update the item status.
  In the calls that declare or define new entities, this never happened,
  because the only thing that can update the status is an item_module_defn,
  and you cannot use those to implement anything else. Nevertheless, most
  (though not all) of the callers of add_item_*_pass_N *did* in fact
  pass around in/out pairs of status arguments.

- A predicate declaration item does not have room to record the origin
  of the predicate as a pred_origin. They have a field that contains
  an item_origin, but item_origins are used only for purposes that are
  completely orthogonal to purposes that pred_origins are used for,
  and new predicates pred_origins are NOT set from the item_pred_decl's
  item_origin. This meant that predicates declared during the make_hlds
  pass could not have their pred_origin set to anything other than
  "user-declared predicate", which is wrong for all of the auxiliary
  predicates needed for mutables, tabling and solver types.

- The compiler built up items and then immediately deconstructed them.
  This was inefficient, though this inefficiency was by far the least
  important undesirable consequence.

This diff changes things so that when processing items such as mutables
that create new entities, we declare and define those entities directly,
*without* calling add_item_*_pass_N. This should allow us to move the code
doing that creating out of make_hlds_passes.m, which should significantly
improve its cohesion. The movement of that code will be part of the next
change; it is not part of this one, because it is easier to review
in-place changes in make_hlds_passes.m than to review a diff that
both moves *and* modifies that code.

This diff also replaces in/out pairs of import_status arguments with just
an input of the current import_status. Since the status now changes only at
module_defn items (which mark changes e.g. from interface to implementation
or to opt_imported items), this should make it significantly easier
to implement future improvements of the import status system.

compiler/hlds_pred.m:
    Make it possible to record the origin of a predicate as auxiliary
    predicates for mutables, solver types and tabling. Previously,
    these origins were ignored, because the declarations of such predicates
    are not the result of HLDS-to-HLDS transformations; these auxiliary
    predicates are declared during the initial parse-tree-to-HLDS
    transformation.

compiler/prog_item.m:
    Replace the item_origin type. Instead of having it record an incomplete
    notion of where the item came from, we now have values of the replacement
    item_maybe_attrs type record the answers to the questions whose answers
    used to be derived from the values of the item_origin type.

compiler/add_pred.m:
    When declaring a new predicate, allow (and require) the caller to tell us
    its origin (as pred_origin, not item_origin).

compiler/add_pragma.m:
    Export the code that defines predicates via foreign_procs.

compiler/add_solver.m:
    Avoid calling add_item_pass_3 when defining the representation
    change predicates for solver types.

    Set a meaningful pred_origin when declaring those predicates.

compiler/make_hlds_passes.m:
    Make the main change described at the top.

    Note that this module still contains multiple pieces of code
    that define the access predicates for mutables differently for
    the different backends. While some differences are inevitable,
    the differences currently between these implementations are much more
    extensive than necessary. That should be fixed *after* the relevant
    code has been moved to add_mutable_aux_preds.m (see below).

compiler/prog_mutable.m:
    This module used to create and return items declaring all the auxiliary
    predicates needed by mutables (init, preinit, lock, unlock, and several
    varieties of get and set).

    It now returns item_pred_decls, not items, and those only for the
    predicates whose declarations write_module_interface_files.m needs
    to output, since these declarations are NOT put into the HLDS.
    (It would be better to just write the mutable definition into the
    interface file, and have the readers of that file declare the
    auxiliary predicates themselves, but that is different change.)

    This module used to have lots of cut-and-pasted code. Factor out all
    the resulting commonalities.

compiler/add_mutable_aux_preds.m:
    Add a new module to handle the low level details of adding to the HLDS
    the auxiliary predicates needed by mutables. The basis of this code
    is code that used to be in prog_mutable.m, but the replacement code
    has very little in common with the old code there. The high level code
    that decides *what* to add to the HLDS will be moved here from
    make_hlds_passes.m as well, once this diff has been reviewed.

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

compiler/add_class.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/intermod.m:
compiler/layout_out.m:
compiler/mode_errors.m:
compiler/modules.m:
compiler/polymorphism.m:
compiler/prog_io_dcg.m:
compiler/prog_io_item.m:
compiler/prog_io_mutable.m:
compiler/prog_io_pragma.m:
compiler/trace_params.m:
compiler/write_module_interface_files.m:
    Conform to the changes above. In some cases, this change exposed
    code that was probably not right; mark these with XXXs.

compiler/hlds_goal.m:
compiler/ml_unify_gen.m:
    Simplify some code.
2015-01-23 17:12:59 +11:00
Zoltan Somogyi
13b6f03f46 Module qualify end_module declarations.
compiler/*.m:
    Module qualify the end_module declarations. In some cases, add them.

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

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

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

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

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

browser/*.m:
compiler/*.m:
deep_proiler/*.m:
mdbcomp/*.m:
slice/*.m:
    Conform to the above changes.
2014-09-02 05:20:23 +02:00
Zoltan Somogyi
16bd4acd2f Shorten lines longer than 79 characters.
Estimated hours taken: 2
Branches: main

compiler/*.m:
	Shorten lines longer than 79 characters.
2012-10-24 05:49:47 +00:00
Peter Wang
c8d8202224 Allow mutable variables to be initialised by impure functions.
Branches: main, 11.07

Allow mutable variables to be initialised by impure functions.

Also fix bug #223.  Make thread.semaphore.init/1 and thread.mvar.init/1
impure, as they should be.  They were introduced to be used as mutable
initialisers, which led to the oversight of making them pure.

compiler/make_hlds_passes.m:
compiler/prog_mutable.m:
	Modify the generated mutable initialisation predicates such that the
	initial value may be the return value of a impure function call.

compiler/purity.m:
	Ignore warnings about unnecessary impure annotations on goals in
	generated mutable predicates.  These would now appear when
	a mutable is initialised by a call to a pure function, or
	by a constant.

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

library/thread.mvar.m:
library/thread.semaphore.m:
	Make thread.semaphore.init/1 and thread.mvar.init/1 impure.

tests/hard_coded/Mmakefile:
tests/hard_coded/mutable_init_impure.exp:
tests/hard_coded/mutable_init_impure.m:
	Add test case.
2011-11-03 01:01:36 +00:00
Zoltan Somogyi
295415090e Convert almost all remaining modules in the compiler to use
Estimated hours taken: 6
Branches: main

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

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

tests/invalid/unresolved_overloading.err_exp:
	Update an expected output containing an updated error message.
2011-05-23 05:08:24 +00:00
Zoltan Somogyi
022b559584 Make error messages for require_complete_switch scopes report the missing
Estimated hours taken: 8
Branches: main

Make error messages for require_complete_switch scopes report the missing
functors.

Knowing which functors are missing requires knowing not only the set of
functors in the switched-on variable's type, but also which of these functors
have been eliminated by earlier tests, which requires having the instmap at
the point of entry to the switch. Simplification, which initially detected
unmet require_complete_switch requirements, does not have the instmap, and
threading the instmap through it would make it significantly less efficient.
So instead we now detect any problems with require_complete_switch scopes
(and require_detism scopes, which are similar) during determinism checking.

compiler/det_report.m:
	Factor out the code for finding the missing functors in conventional
	determinism errors, to allow it to be used for this new purpose.

	Check whether the requirements of require_complete_switch and
	require_detism scopes are met IF the predicate has any such scopes.

compiler/det_analysis.m:
compiler/det_util.m:
	Record whether the predicate has any such scopes.

compiler/hlds_pred.m:
	Add a predicate marker that allows this recording.

compiler/simplify.m:
	Delete the code that checks the require_complete_switch and
	require_detism scopes. Keep the code that deletes those scopes.
	(We have to do that here because determinism error reporting
	never updates the goal).

compiler/prog_out.m:
	Delete an unused predicate.

compiler/*.m:
	Remove unnecesary imports as flagged by --warn-unused-imports.
2011-01-02 14:38:08 +00:00
Peter Wang
a28023f3db Implement thread-local mutables for C# backend correctly.
Branches: main

Implement thread-local mutables for C# backend correctly.
A child thread automatically inherits the values of thread-local
mutables from the thread that spawned it.

runtime/mercury_dotnet.cs.in:
        Add a `ThreadLocalMutables' class that implements inheritable
        thread-local mutables, using the same technique as for C grades.

library/thread.m:
        Make newly spawned threads copy the values of thread-local mutables
        from the parent thread.

compiler/make_hlds_passes.m:
        Update the C# mutable transformation to use the methods in the
        `ThreadLocalMutables' class.

compiler/prog_mutable.m:
        Describe the C# thread-local mutable transformation.
2010-10-28 03:16:32 +00:00
Peter Wang
cc0c96e114 Special case `int' mutables in C# and Java grades.
Branches: main

Special case `int' mutables in C# and Java grades.
All mutables were represented with the generic `object' type, but that means
integer values require boxing/unboxing.  Since integer mutables are used to
hold counters in the source-to-source debugger (among other applications),
it is best to avoid boxing.

compiler/make_hlds_passes.m:
compiler/ml_foreign_proc_gen.m:
compiler/prog_io_mutable.m:
        As above.

compiler/prog_mutable.m:
        Update description of the mutable transformation.
2010-10-28 02:56:08 +00:00
Peter Wang
3e782e9411 Reads/writes of 32-bit variables in Java are are atomic and do not require
Branches: main, 10.04

Reads/writes of 32-bit variables in Java are are atomic and do not require
further synchronisation.  Don't generate `synchronized' statements in Java
mutable accessors.

compiler/make_hlds_passes.m:
compiler/prog_mutable.m:
        As above.
2010-05-07 03:46:24 +00:00
Peter Wang
de1329a55e Support `thread_local' mutables on Java backend.
Branches: main

compiler/make_hlds_passes.m:
        Support `thread_local' mutables on Java backend.

        Add some newlines in generated code for mutables.

compiler/prog_mutable.m:
        Update documentation.

java/runtime/JavaInternal.java:
        Avoid a warning.
2009-09-02 07:12:26 +00:00
Peter Wang
a031639e89 The recent changes to support warnings about non-contiguous clauses broke
Branches: main

The recent changes to support warnings about non-contiguous clauses broke
mutable support in Java.  The problem was that we generated both a foreign
procedure called "get_<var>" and a clause called "get_<var>", due to sharing
code with the C backends.

compiler/make_hlds_passes.m:
        Rename the foreign procs generated for Java to "unsafe_get_<var>" and
        "unsafe_set_<var>", to align the Java backend with the C backends.

compiler/prog_mutable.m:
        Update the description of the mutables transformation for Java.
2009-08-24 03:33:26 +00:00
Zoltan Somogyi
d69ba1a1f0 Include the type_ctor in cons_ids for user-defined types.
Estimated hours taken: 32
Branches: main

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

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

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

With this diff, user-defined cons_ids are represented as

	cons(SymName, Arity, TypeCtor)

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

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

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

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

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

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

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

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

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

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

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

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

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

	Rename a cons_tag in sync with its corresponding cons_id.

	Put some declarations into logical order.

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

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

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

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

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

	In prog_util.m, remove two predicates that did almost nothing yet were
	far too easy to misuse.
2009-06-11 07:00:38 +00:00
Peter Wang
5e27937316 Don't generate lock objects for a constant mutables in Java grade
Branches: main

compiler/make_hlds_passes.m:
        Don't generate lock objects for a constant mutables in Java grade
        as they won't be used.

compiler/prog_mutable.m:
        Document mutable transformation for Java.
2009-04-27 05:09:22 +00:00
Zoltan Somogyi
b445b51205 Add a sequence number to the information we collect for each kind of item.
Estimated hours taken: 4
Branches: main

Add a sequence number to the information we collect for each kind of item.
The purpose of this is to prepare for a later change that will switch from
representing the stuff we read in from a file as a list of items to
representing it is a data structure that groups all items of a given kind
together. This will lose the original order of the items. The sequence number
will allow us to recreate it if necessary, e.g. for pretty-printing.

compiler/prog_item.m:
	Add the sequence number field to the information we have about each
	kind of item.

compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_pragma.m:
compiler/prog_io_typeclass.m:
	Add code to generate the item sequence numbers.

	In prog_io.m, change some predicates that used to return an
	intermediate type such as processed_type_body to make them return
	an item, since this simplifies adding sequence numbers; it also
	simplifies the code in general and reduces memory allocation.

	Rename some uninformatively-named variables that I missed in my last
	diff.

compiler/*.m:
	Minor changes to conform to the above. Mostly this involves either
	ignoring the seqnum field, or copying it when an item is updated.
2008-07-28 08:34:19 +00:00
Zoltan Somogyi
a00596c283 The file modules.m contains lots of different kinds of functionality.
Estimated hours taken: 16
Branches: main

The file modules.m contains lots of different kinds of functionality.
While much of it belongs together, much of it does not. This diff moves
most of the functionality that does not belong with the rest to several
new modules:

	libs.file_util
	parse_tree.deps_map
	parse_tree.file_names
	parse_tree.module_cmds
	parse_tree.module_imports
	parse_tree.read_module
	parse_tree.write_deps_file

To make them coherent, move some predicates from hlds.passes_aux,
parse_tree.prog_io and parse_tree.prog_out to the new modules, making them
more accessible, reducing the required access from the hlds package to
parse_tree, or from the parse_tree package to libs.

In the same spirit, this diff also moves some simple predicates and functions
dealing with sym_names from prog_util.m to mdbcomp/prim_data.m. This allows
several modules to avoid depending on parse_tree.prog_util.

Rename some of the moved predicates and function symbols where this avoids
ambiguity. (There were several that differed from other predicates or function
symbols only in arity.)

Replace several uses of bools with purpose-specific types. This makes some
of the code significantly easier to read.

This diff moves modules.m from being by far the largest module, to being
only the seventh largest, from 8900+ lines to just 4200+. It also reduces
the number of modules that import parse_tree.modules considerably; most
modules that imported it now import only one or two of the new modules instead.

Despite the size of the diff, there should be no algorithmic changes.

compiler/modules.m:
compiler/passes_aux.m:
compiler/prog_io.m:
compiler/prog_out.m:
	Delete the moved functionality.

compiler/file_util.m:
	New module in the libs package. Its predicates search for files
	and do simple error or progress reporting.

compiler/file_names.m:
	New module in the parse_tree package. It contains predicates for
	converting module names to file names.

compiler/module_cmds.m:
	New module in the parse_tree package. Its predicates handle the
	commands for manipulating interface files of various kinds.

compiler/module_import.m:
	New module in the parse_tree package. It contains the module_imports
	type and its access predicates, and the predicates that compute
	various sorts of direct dependencies (those caused by imports)
	between modules.

compiler/deps_map.m:
	New module in the parse_tree package. It contains the data structure
	for recording indirect dependencies between modules, and the predicates
	for creating it.

compiler/read_module.m:
	New module in the parse_tree package. Its job is reading in modules,
	both human-written and machine-written (such as interface and
	optimization files).

compiler/write_deps_file.m:
	New module in the parse_tree package. Its job is writing out
	makefile fragments.

compiler/libs.m:
compiler/parse_tree.m:
	Include the new modules.

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

mdbcomp/prim_data.m:
compiler/prog_util.m:
	Move the predicates that operate on nothing but sym_names from
	prog_util to prim_data.

	Move get_ancestors from modules to prim_data.

compiler/prog_item.m:
	Move stuff that looks for foreign code in a list of items here from
	modules.m.

compiler/source_file_map.m:
	Note why this module needs to be in the parse_tree package.

compiler/add_pred.m:
compiler/add_special_pred.m:
compiler/analysis.file.m:
compiler/analysis.m:
compiler/assertion.m:
compiler/check_typeclass.m:
compiler/compile_target_code.m:
compiler/cse_detection.m:
compiler/det_analysis.m:
compiler/elds_to_erlang.m:
compiler/exception_analysis.m:
compiler/export.m:
compiler/fact_table.m:
compiler/higher_order.m:
compiler/hlds_module.m:
compiler/hlds_pred.m:
compiler/intermod.m:
compiler/llds_out.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_passes.m:
compiler/maybe_mlds_to_gcc.pp:
compiler/mercury_compile.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/mode_debug.m:
compiler/modes.m:
compiler/module_qual.m:
compiler/optimize.m:
compiler/passes_aux.m:
compiler/proc_gen.m:
compiler/prog_foreign.m:
compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/prog_mutable.m:
compiler/prog_out.m:
compiler/pseudo_type_info.m:
compiler/purity.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/simplify.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.direct.m:
compiler/structure_sharing.analysis.m:
compiler/tabling_analysis.m:
compiler/term_constr_main.m:
compiler/termination.m:
compiler/trailing_analysis.m:
compiler/trans_opt.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/typecheck_info.m:
compiler/unify_proc.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
	Minor changes to conform to the changes above.
2008-07-21 03:10:29 +00:00
Zoltan Somogyi
801125616f A first step towards rationalizing the parse tree representation of the
Estimated hours taken: 24
Branches: main

A first step towards rationalizing the parse tree representation of the
program. This step moves the information specific to each kind of item
into a structure specific to that kind of item.

In the short term, this allows us to express some old invisible invariants
as types. For example, we used to store general items in method definitions;
we now store clause-specific data there. This allows us to simplify some code
and eliminate some old "can't fail" tests.

In the longer term, this change will allow us to replace the old list of items
representation of the parse tree with a more structured representation,
which aggregates each kind of item differently. For example, we could
keep clause items in a list, but map module imports to the contexts
of their :- import_module items, which would allow us to detect duplicate
imports. We could also change the current three pass structure of the
parse tree to HLDS conversion step, where each pass processes *all* items,
to a much more flexible structure where each pass processes only what it
needs to process, new passes could be added much more simply, and in fact
the whole notion of a "pass" could be eliminated.

In a bunch of places, factor out some common code.

compiler/prog_item.m:
	Make the change to the item type as above.

	Rename the old item_pred_or_func as item_pred_decl (it already had
	a field to indicate predicate or function) and item_pred_or_func_mode
	as item_mode_decl. These names are much more consistent with the
	other item names.

	Eliminate the item_and_context type by moving the context into
	the items themselves. In code that cares about contexts, this
	makes it easier to match up each item with its context. In code
	that doesn't care about contexts, this avoids the extra code
	that would be required to discard the item_and_context wrapper.

compiler/prog_data.m:
	Store item_clause_infos instead of items in method definitions.

compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_pragma.m:
compiler/prog_io_typeclass.m:
	Construct the new item structure when creating the parse tree.

	Instead of constructing items and later attaching the context to them,
	pass the context down, since we now need to include them in items.

	Some old code was assuming that term.variables had no contexts;
	update such code.

	In prog_io_pragma.m, replace a single predicate that parsed all kinds
	of pragmas, which spanned more than one thousand lines and whose
	clauses had been interspersed with the clauses of other predicates,
	with a predicate whose only job is to select which of a bunch of
	pragma-type-specific parse predicates to invoke. Each of these
	pragma-type-specific parse predicates corresponds to one of the
	clauses of the old predicate. In that form, the predicates can be
	declared det, even though the predicate as a whole is semidet
	(since not all pragma names are valid). This actually exposed
	an old bug; the case MaybeAttributes = error1(_) was not handled
	in foreign_export_enum pragmas.

	To make the diff easier to check, I left the predicates in the
	original order of the clauses, even though that order does not
	make sense (it does not group related pragmas together). I did
	leave an XXX comment about this. The matter will be addressed
	in a later diff. (A similar problem occurs in some of the other
	modules in which I broke up very large predicates.)

compiler/prog_io_util.m:
	Remove some stuff that the new item structure makes unnecessary.

compiler/make_hlds_passes.m:
compiler/add_class.m:
compiler/add_mode.m:
compiler/add_pragma.m:
compiler/add_solver.m:
	Conform to the new item structure when converting it to HLDS.
	Break up excessively large predicates.

compiler/prog_foreign.m:
	Provide a function to return all supported foreign languages,
	instead of requiring callers to call solutions to compute this list.

compiler/mercury_to_mercury.m:
	Print out the new item structure.
	Break up excessively large predicates.
	Rename some predicates to avoid name collisions.

compiler/equiv_type.m:
compiler/hlds_module.m:
compiler/intermod.m:
compiler/make.module_dep_file.m:
compiler/mercury_compile.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/prog_mutable.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/state_var.m:
compiler/trans_opt.m:
	Operate on the new item structure. Factor out code (usually tests)
	where the new item structure makes this possible and desirable.
	Turn if-then-elses into switches where this is desirable.
	Build up large terms from named pieces instead of all at once.
	Break up excessively large predicates.

	In equiv_type.m, rename a predicate to clarify its function,
	and add an XXX about a possible improvement in abstraction.

	In modules.m, simplify the interface between some predicates
	and their callers, turn some predicates into functions, and
	make some code return error specifications instead of doing
	raw printing of error messages. Note that this module still
	has plenty of scope for improvement (I marked some with XXXs),
	but that is for a later date.

	In some cases, mark potential bugs with XXXs.

compiler/equiv_type_hlds.m:
	Conform to the change in equiv_type.m.

library/term.m:
compiler/recompilation.check.m:
	Move the function for getting the context out of a term from
	recompilation.check.m to term.m, so it can be used from other modules.
	(Also, adding such a function to the standard library is long overdue.)

NEWS:
	Note the change to term.m.
2008-02-15 02:27:04 +00:00
Julien Fischer
e323dee594 Fix a problem that was causing the namespace cleanliness check to
Estimated hours taken: 0.5
Branches: main

Fix a problem that was causing the namespace cleanliness check to
fail in the library directory.

compiler/prog_mutable.m:
	For standard library modules prefix the globals used for
	mutables with `mercury__'.

compiler/hlds_module.m:
	Do likewise for the exported C functions introduced by
	initialise and finalise declarations.
2007-08-06 12:50:25 +00:00
Peter Wang
b028ebae48 Add support for mutables in the Erlang backend.
Estimated hours taken: 15
Branches: main

Add support for mutables in the Erlang backend.

compiler/make_hlds_passes.m:
	Refactor code that inserts mutable-related items for C backend.

	Insert items for mutable-related predicates for Erlang.

compiler/prog_item.m:
	Add item_mutable inst.

compiler/prog_mutable.m:
	Document the mutable transformation for Erlang.

library/Mercury.options:
library/erlang_builtin.m:
	New module.  This contains a server process that will run in the
	background to handle messages relating to mutables in Erlang.  In
	future it may hold other things for the Erlang backend.

library/library.m:
	Add `erlang' module to the standard library.

compiler/elds_to_erlang.m:
	Make the Erlang main wrapper start and stop the Erlang global server.

doc/reference_manual.texi:
	Add a (commented out) reminder that that mutables are supported
	in Erlang as well.

tests/hard_coded/Mmakefile:
tests/hard_coded/float_gv.m:
tests/hard_coded/sub-modules/non_word_mutable.m:
	Make these test cases work in Erlang.
2007-06-12 06:53:59 +00:00
Zoltan Somogyi
b56885be93 Fix a bug that caused bootchecks with --optimize-constructor-last-call to fail.
Estimated hours taken: 12
Branches: main

Fix a bug that caused bootchecks with --optimize-constructor-last-call to fail.

The problem was not in lco.m, but in follow_code.m. In some cases,
(specifically, the LCMC version of insert_2 in sparse_bitset.m),
follow_code.m moved an impure goal (store_at_ref) into the arms of an
if-then-else without marking those arms, or the if-then-else, as impure.
The next pass, simplify, then deleted the entire if-then-else, since it
had no outputs. (The store_at_ref that originally appeared after the
if-then-else was the only consumer of its only output.)

The fix is to get follow_code.m to make branched control structures such as
if-then-elses, as well as their arms, semipure or impure if a goal being moved
into them is semipure or impure, or if they came from an semipure or impure
conjunction.

Improve the optimization of the LCMC version of sparse_bitset.insert_2, which
had a foreign_proc invocation of bits_per_int in it: replace such invocations
with a unification of the bits_per_int constant if not cross compiling.

Add a new option, --optimize-constructor-last-call-null. When set, LCMC will
assign NULLs to the fields not yet filled in, to avoid any junk happens to be
there from being followed by the garbage collector's mark phase.

This diff also makes several other changes that helped me to track down
the bug above.

compiler/follow_code.m:
	Make the fix described above.

	Delete all the provisions for --prev-code; it won't be implemented.

	Don't export a predicate that is not now used anywhere else.

compiler/simplify.m:
	Make the optimization described above.

compiler/lco.m:
	Make sure that the LCMC specialized procedure is a predicate, not a
	function: having a function with the mode LCMC_insert_2(in, in) = in
	looks wrong.

	To avoid name collisions when a function and a predicate with the same
	name and arity have LCMC applied to them, include the predicate vs
	function status of the original procedure included in the name of the
	new procedure.

	Update the sym_name of calls to LCMC variants, not just the pred_id,
	because without that, the HLDS dump looks misleading.

compiler/pred_table.m:
	Don't have optimizations like LCMC insert new predicates at the front
	of the list of predicates. Maintain the list of predicates in the
	module as a two part list, to allow efficient addition of new pred_ids
	at the (logical) end without using O(N^2) algorithms. Having predicates
	in chronological order makes it easier to look at HLDS dumps and
	.c files.

compiler/hlds_module.m:
	Make module_info_predids return a module_info that is physically
	updated though logically unchanged.

compiler/options.m:
	Add --optimize-constructor-last-call-null.

	Make the options --dump-hlds-pred-id, --debug-opt-pred-id and
	--debug-opt-pred-name into accumulating options, to allow the user
	to specify more than one predicate to be dumped (e.g. insert_2 and
	its LCMC variant).

	Delete --prev-code.

doc/user_guide.texi:
	Document the changes in options.m.

compiler/code_info.m:
	Record the value of --optimize-constructor-last-call-null in the
	code_info, to avoid lookup at every cell construction.

compiler/unify_gen.m:
compiler/var_locn.m:
	When deciding whether a cell can be static or not, make sure that
	we never make static a cell that has some fields initialized with
	dummy zeros, to be filled in for real later.

compiler/hlds_out.m:
	For goals that are semipure or impure, note this fact. This info was
	lost when I changed the representation of impurity from markers to a
	field.

mdbcomp/prim_data.m:
	Rename some ambiguous function symbols.

compiler/intermod.m:
compiler/trans_opt.m:
	Rename the main predicates (and some function symbols) of these modules
	to avoid ambiguity and to make them more expressive.

compiler/llds.m:
	Don't print line numbers for foreign_code fragments if the user has
	specified --no-line-numbers.

compiler/make.dependencies.m:
compiler/mercury_to_mercury.m:
compiler/recompilation.usage.m:
	Don't use io.write to write out information to files we may need to
	parse again, because this is vulnerable to changes to the names of
	function symbols (e.g. the one to mdbcomp/prim_data.m).

	The compiler still contains some uses of io.write, but they are
	for debugging. I added an item to the todo list of the one exception,
	ilasm.m.

compiler/recompilation.m:
	Rename a misleading function symbol name.

compiler/parse_tree.m:
	Don't import recompilation.m here. It is not needed (all the components
	of parse_tree that need recompilation.m already import it themselves),
	and deleting the import avoids recompiling almost everything when
	recompilation.m changes.

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

compiler/*.m:
browser/*.m:
slice/*.m:
	Conform to the change to mdbcomp.

library/sparse_bitset.m:
	Use some better variable names.
2007-01-19 07:05:06 +00:00
Peter Wang
81b8e55825 Add support for thread-local mutables. These can take on a different value for
Estimated hours taken: 15
Branches: main

Add support for thread-local mutables.  These can take on a different value for
each Mercury thread.  Child threads automatically inherit the thread-local
values of the parent thread that spawned it.

compiler/make_hlds_passes.m:
compiler/prog_io.m:
compiler/prog_item.m:
compiler/prog_mutable.m:
	Accept a `thread_local' attribute for mutables and update the
	source-to-source transformation.

doc/reference_manual.texi:
	Document the `thread_local' attribute as a Melbourne Mercury compiler
	extension.

runtime/mercury_context.c:
runtime/mercury_context.h:
	Add a `thread_local_mutables' field to MR_Context, which points to an
	array which holds all the values of thread-local mutables in the
	program.  Each thread-local mutable has an associated index into the
	array, which is allocated during initialisation.  A child thread
	inherits the parent's thread-locals simply by copying the array.

	Add a `thread_local_mutables' field to MR_Spark and update the parallel
	conjunction implementation to take into account thread-locals.

runtime/mercury_thread.c:
runtime/mercury_thread.h:
	Add the functions and macros which are used by the code generated for
	thread-local mutables.

runtime/mercury_wrapper.c:
	Allocate a thread-local mutable array for the initial context at
	startup.

extras/concurrency/spawn.m:
	Update the spawn/3 implementation to make child threads inherit the
	thread-local values of the parent.

	Make different threads in high-level C grades use different
	MR_Contexts.  This makes it possible to use the same implementation of
	thread-local mutables as in the low-level C grades.

tests/hard_coded/mutable_decl.exp:
tests/hard_coded/mutable_decl.m:
tests/hard_coded/pure_mutable.exp:
tests/hard_coded/pure_mutable.m:
tests/invalid/bad_mutable.err_exp:
tests/invalid/bad_mutable.m:
	Add some thread-local mutables to these test cases.

NEWS:
	Announce the addition.
2007-01-12 05:00:32 +00:00
Julien Fischer
b4c3bb1387 Clean up in unused module imports in the Mercury system detected
Estimated hours taken: 3
Branches: main

Clean up in unused module imports in the Mercury system detected
by --warn-unused-imports.

analysis/*.m:
browser/*.m:
deep_profiler/*.m:
compiler/*.m:
library/*.m:
mdbcomp/*.m:
profiler/*.m:
slice/*.m:
	Remove unused module imports.

	Fix some minor departures from our coding standards.

analysis/Mercury.options:
browser/Mercury.options:
deep_profiler/Mercury.options:
compiler/Mercury.options:
library/Mercury.options:
mdbcomp/Mercury.options:
profiler/Mercury.options:
slice/Mercury.options:
	Set --no-warn-unused-imports for those modules that are used as
	packages or otherwise break --warn-unused-imports, e.g. because they
	contain predicates with both foreign and Mercury clauses and some of
	the imports only depend on the latter.
2006-12-01 15:04:40 +00:00
Julien Fischer
e35f5832d2 Make the get and set operations for non-constant mutables thread safe.
Estimated hours taken: 12
Branches: main

Make the get and set operations for non-constant mutables thread safe.  (The
get operation for constant mutables is thread safe by definition.)  The
source-to-source transformation for (non-constant) mutables is modified as
follows: we introduce four primitive operations: unsafe_get, unsafe_set, lock
and unlock.  These operations are private implementation details.  The first
two read and write the value of the mutable.  In .par grades lock and unlock
are used to respectively acquire and release the mutex associated with the
mutable.  In non .par grades they are no-ops.

The user-level mutable operations are now defined in terms of these
primitives.  In particular get and set must acquire the mutable's mutex before
they can read or modify its value.  (We will shortly add support for atomic
updates to mutables - defined in terms of the above primitives - as well.)

Fix intermodule inlining so that the clauses for the mutable access predicates
are written to .opt files even though they contain calls to impure predicates.
This is usually not allowed because of problems caused by reordering what were
headvar unifications in the original source file.  It's okay to do this for
the mutable access predicates since we can guarantee that they won't need to
be reordered by construction.

compiler/make_hlds_passes.m:
	Add declarations and implementation for: unsafe_{get,set}, lock
	and unlock.

	Redefine get/1, set/1, get/3 and set/3 in terms of the above
	operations.  In .par grades acquire the mutable's mutex before reading
	or writing to it and release it afterwards.

	Fill in the item_origin field for predicate declarations introduced by
	the source-to-source transformation for mutables.

compiler/prog_mutable.m:
	Add auxiliary predicates required by the above.

	Update the description of the mutable source-to-source transformation.

compiler/prog_util.m:
	Add a function: goal_list_to_conj/2.  This is needed by the mutable
	transformation.

compiler/add_clauses.m:
	Delete the function goal_list_to_goal/2 which is identical
	to goal_list_to_conj/2 but for the name.

compiler/prog_item.m:
	Add an origin field to the pred_or_func item.

compiler/hlds_pred.m:
	Add a new pred_marker for identifying predicates that were introduced
	by the mutable source-to-source transformation.

compiler/add_pragma.m:
	Fill in the item_origin field for the predicate declarations introduced
	by tabling pragmas.

compiler/intermod.m:
	Mutable access predicates should always be written to the .opt files
	if they are referred to by an opt_exported predicate.

	Remove the restriction that clauses that call impure predicates should
	not be opt_exported in the case where the clause in question was
	introduced by the mutable transformation.  For those clauses we can
	guarantee that there won't be any problems associated with reordering
	(the reason given for the restriction) by construction.

	Rename some variables.

compiler/prog_io.m:
	Fill in the origin field for pred_or_func items.

compiler/add_pred.m:
compiler/equiv_type.m:
compiler/hlds_out.m:
compiler/inlining:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/prog_io_goal.m:
compiler/prog_io_typeclass.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/table_gen.m:
	Conform to the above changes.

TODO: update reference manual to mention the new behaviour of mutables in
grades that support concurrency.
2006-08-30 04:46:02 +00:00
Julien Fischer
a7f866a244 In parallel grades associate a mutex with each non-constant mutable.
Estimated hours taken: 8
Branches: main

In parallel grades associate a mutex with each non-constant mutable.  A
subsequent change will modify the mutable get and set predicates to use this
mutex to ensure that accesses to the mutable in parallel grades are thread
safe.

Modify the initialisation predicate for non-constant mutables so that they
also initialise the mutex belonging to the mutable.

Break up the overly-long clause that adds the foreign_procs for the mutable
get, set and initialise predicates.  Move most of it into separate auxiliary
predicates.

compiler/make_hlds_passes.m:
	For each non-constant mutable also create a mutex.  (The mutexes are
	conditionally compiled away in non-parallel grades).

	Modify mutable initialisation so that if MR_THREAD_SAFE is defined
	then a call to pthread_mutex_init is made for each mutex introduced
	for a mutable.

	Add separate auxiliary predicates for that handle introducing the
	foreign_procs for get, set and initialise predicates for mutables.

compiler/prog_mutable.m:
	Add functions to construct the name and predmode decl for the mutable
	mutex initialisation predicate.

	Update the description of the source-to-source transformation used to
	implement mutables.

runtime/mercury_trace_base.c:
	Unrelated change: s/isalnum/MR_isalnum/ in order to avoid a warning
	on Solaris.
2006-08-22 09:41:16 +00:00
Zoltan Somogyi
00741b0162 This diff contains no algorithmic changes.
Estimated hours taken: 6
Branches: main

This diff contains no algorithmic changes. It merely renames apart a bunch more
function symbols to reduce ambiguity.

After this diff, the summary line from the mdb command "ambiguity -f" is

	Total: 351 names used 975 times, maximum 31, average: 2.78

browser/*.m:
compiler/*.m:
	Rename function symbols to eliminate ambiguities.

tests/debugger/declarative/dependency.exp:
tests/debugger/declarative/dependency2.exp:
	Update the expected out where some internal function symbol names
	appear in the output of the debugger. (This output is meant for
	implementors only.)
2006-08-22 05:04:29 +00:00
Zoltan Somogyi
2b2f3d3cbe This diff contains no algorithmic changes.
Estimated hours taken: 8
Branches: main

This diff contains no algorithmic changes. It merely renames apart a bunch of
function symbols to reduce ambiguity. Basically I went through prog_data.m,
prog_item.m, hlds_data.m, hlds_goal.m and hlds_pred.m looking for type
definitions containing function symbol names that were either language
"keywords" (e.g. "terminates", which is an annotation on foreign_procs),
used with slightly different meanings in several types (e.g. "sym"),
or both (e.g. "call"). When I found such type definitions, I changed the
names of the function symbols, usually by adding a prefix or suffix
indicating the type to all function symbols of the type. For example,
the old function symbol "foreign_proc" in type "pragma_type" is now named
"pragma_foreign_proc", and the names of all other function symbols in that
type also start with "pragma_".

All of this should yield simpler compiler error messages when we make mistakes,
and will make it more likely that looking up a function symbol using a tags
file will take you to the actual definition of the relevant instance of that
function symbol. However, the most important benefit is the increase in
the readability of unfamiliar code; the reader won't have to emulate the
compiler's type ambiguity resolution algorithm (which in many cases used to
require distinguishing between f/14 and f/15 by counting the arguments,
e.g. for "pred_or_func").

compiler/prog_data.m:
compiler/prog_item.m:
compiler/hlds_data.m:
compiler/hlds_goal.m:
compiler/hlds_pred.m:
	Rename function symbols as explained above.

compiler/*.m:
	Conform to the function symbol renames.

	In some cases, rename other function symbols as well.

	Minor style fixes, e.g. replace if-then-elses with switches,
	or simple det predicates with functions.
2006-08-20 08:21:36 +00:00
Julien Fischer
16184103d7 Add new documentation for the implementation of mutables.
Estimated hours taken: 1
Branches: main

Add new documentation for the implementation of mutables.

compiler/prog_mutable.m:
	Provide an up-to-date description of the source-to-source
	transformation used to implement mutables.

compiler/prog_io.m:
	Delete the old description of the transformation.  (This hadn't
	been maintained and was quite out-of-date.)

	Minor documentation update caused by the removal of the mutable
	`thread_safe' attribute.

compiler/make_hlds_passes.m:
	Add a pointer to the new documentation in prog_mutable.m.
2006-08-15 07:34:49 +00:00
Julien Fischer
fe65fe427e Get rid of the `thread_safe' mutable attribute, since this doesn't actually
Estimated hours taken: 1
Branches: main, release

Get rid of the `thread_safe' mutable attribute, since this doesn't actually
make access to a mutable thread safe (in fact it makes them less thread
safe than the `not_thread_safe' version).

By extension this also removes support for the `not_thread_safe' mutable
attribute.

compiler/prog_io.m:
compiler/prog_item.m:
compiler/prog_mutable.m:
	Remove support for the `thread_safe' mutable attribute.

compiler/make_hlds_passes.m:
	Remove support for the `thread_safe' mutable attribute.

	Mark the foreign clauses for `get' predicates for constant
	mutables as thread safe.

doc/reference_manual.texi:
	Delete the documentation for the `thread_safe' mutable attribute.

tests/hard_coded/mutable_decl.m:
tests/hard_coded/pure_mutable.m:
tests/hard_coded/trace_goal_env_1.m:
tests/hard_coded/trace_goal_env_2.m:
tests/hard_coded/unusual_name_mutable.m:
tests/hard_coded/sub-modules/mutable_child.m:
tests/hard_coded/sub-modules/mutable_grandchild.m:
tests/hard_coded/sub-modules/mutable_parent.m:
tests/invalid/bad_mutable.{err_exp,m}:
tests/invalid/not_in_interface.m:
	Conform to the above change.
2006-08-14 09:09:22 +00:00
Zoltan Somogyi
fb9f78b784 Fix a bug reported by Peter Hawkins. The bug was that an predicate without
Estimated hours taken: 3
Branches: main

Fix a bug reported by Peter Hawkins. The bug was that an predicate without
a declared determinism but whose inferred determinism was invalid for its
tabling declaration led to a compiler abort.

compiler/det_analysis.m:
	Fix the main cause of the bug, which was that the check for the
	compatibility of evaluation method and determinism was performed
	only for predicates with declared determinisms, not those without.

	Centralize the printing of determinism error messages, and sort
	the messages first.

compiler/hlds_pred.m:
	Fix the other half of the bug: the predicate that checked the
	compatibility of evaluation method and determinism was too liberal
	with minimal model predicates, letting through determinisms that the
	tabling transformation cannot (yet) support.

compiler/det_report.m:
	Fix the formatting of the error message.

compiler/prog_data.m:
	Rename the function symbols of the type "determinism", to avoid
	conflicts with language keywords.

compiler/*.m:
	Conform to the change to prog_data.m.

tests/invalid/hawkins_mm_fail_reset.{m,err_exp}:
	New test case for the bug being fixed.

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

tests/invalid/loopcheck.err_exp:
	Expect the new format of the improved error message.
2006-07-12 02:51:22 +00:00
Zoltan Somogyi
74ce85d476 Provide a mechanism for collecting statistics about tabling operations,
Estimated hours taken: 60
Branches: main

Provide a mechanism for collecting statistics about tabling operations,
and provide a much more convenient mechanism for resetting tables.

Since it would too complex to do this while preserving the capability
of setting --tabling-via-extra-args to no, eliminate that capability
and the option. That option was useful only for measurements of the
performance boost from setting --tabling-via-extra-args to yes in any case,
so users lose no functionality.

Previously, the only way to debug the low level details of the tabling
mechanism was to build a runtime with a specific C macro (MR_TABLE_DEBUG)
and link with that runtime; this was cumbersome. Change that so that
every one of the debuggable tabling macros has a bool argument that says
whether debugging is enabled or not. The compiler can then set this to
MR_TRUE if the new option --table-debug is given, and to MR_FALSE otherwise.
If set to MR_FALSE, the C compiler should optimize away the debug code,
with zero impact on program size or speed.

Since these changes to macros require nontrivial bootstrapping, which we don't
want to do unnecessarily, modify the interface of the tabling macros as
required to support size limits on tables. This diff also implements the
parsing of size limit specifications on tables, but does not implement them
yet; that is for a future change.

To make the syntax simpler, this diff deletes the free-standing fast_loose_memo
pragma. The same functionality is now available with a fast_loose annotation
on an ordinary memo pragma.

Make a bunch of changes to improve readability and maintainability
in the process. These mostly take the form of renaming ambiguous and/or
not sufficiently expressive function symbols.

runtime/mercury_stack_layout.h:
runtime/mercury_tabling.h:
	Move the description of structure of tables from mercury_stack_layout.h
	to mercury_tabling.h, since we now need it for statistics even if
	execution tracing is not enabled.

	Modify those data structures to have room for the statistics.

	Don't distinguish "strict", "fast_loose" and "specified" memoing
	as separate eval methods; treat them as just different kinds
	of the same eval method: "memo".

	Remove underscores from the names of some types that the style guide
	says shouldn't be there.

runtime/mercury_tabling_preds.h:
runtime/mercury_tabling_macros.h:
	Modify the approach we use for macros that implement the predicates
	of library/table_builtin.m. Instead of selecting between debug and
	nondebug based on whether MR_TABLE_DEBUG is defined or not, add
	an explicit argument controlling this to each debuggable macro.
	The advantage of the new arrangement is that it scales. Another
	argument controls whether we are computing statistics (and if yes,
	where do we put it), and a third argument controls whether we maintain
	back links in the tries and hash tables (this last argument is present
	but is ignored for now).

	Since the values of the arguments will be known when the .c files
	containing calls to these macros are compiled, we pay the space and
	time cost of debugging, statistics gathering and the maintenance of
	back links if and only we need the revelant functionality.

	Provide macros for limited backward compatibility with the old set
	of macros; these allow workspaces created by old compilers to work
	with the new macros in the runtime. The old macros followed the
	naming scheme MR_table_*, the new ones are named MR_tbl_*.

runtime/mercury_table_int_fix_index_body.h:
runtime/mercury_table_int_start_index_body.h:
runtime/mercury_table_type_body.h:
	New files containing parts of the old mercury_tabling.c. Each of these
	files contains the body of the functions that used to be in
	mercury_tabling.c. The new mercury_tabling.c #includes each of these
	files more than once, to provide more than one variant of the old
	function. These variants differ in aspects such as whether debugging
	is enabled or statistics is being collected. Each variant therefore
	incurs only the time costs it needs to. (We pay the space cost of
	having all these variants all the time of course, but this cost
	is negligible.)

runtime/mercury_tabling_stats_defs.h:
runtime/mercury_tabling_stats_nodefs.h:
runtime/mercury_tabling_stats_undefs.h:
	New files that serve as wrappers around the newly #included files,
	controlling how they handle statistics.

runtime/mercury_tabling.c:
	Delete functions now in the new files, and #include them instead.
	Delete the data structures that used to contain summary statistics;
	the new approach keeps statistics in compiler-generated,
	procedure-specific data structures.

runtime/mercury_trace_base.c:
	Use the new versions of the tabling macros to access the I/O table.

runtime/mercury_type_info.h:
	Update some documentation for the movement of code out of
	mercury_tabling.c.

runtime/mercury_types.h:
	Provide forward declarations of the identifiers denoting the new types
	in mercury_tabling.h.

runtime/mercury_grade.h:
	Increment the exec trace version number, since we have changed
	a part of the exec trace structure.

runtime/mercury_bootstrap.h:
	Fix some temporary issues that arise from some renames above.

runtime/mercury_hash_lookup_or_add_body.h:
	Fix comment.

runtime/Mmakefile:
	Mention the new files and the dependencies that involve them.

library/table_builtin.m:
	Provide a type for representing statistics and a predicate for
	printing statistics.

	Use the updated versions of the macros in
	runtime/mercury_tabling_preds.h.

compiler/prog_item.m:
	Change representation of tabling pragmas to allow room for the new
	attributes.

	Allow an item to be marked as being generated by the compiler
	as a result of a pragma memo attribute. We use this for the reset
	and statistics predicates.

compiler/mercury_to_mercury.m:
	Write out the new attributes of the tabling pragma.

compiler/prog_data.m:
compiler/hlds_data.m:
	Change the cons_id that used to refer to a procedure's call table root
	to refer to the entirety of the new data structure now containing it.
	The compiler now needs a way to refer to the other components of this
	new data structure, since it contains the statistics.

	As in the runtime, don't distinguish "strict", "fast_loose" and
	"specified" memoing as separate eval methods; treat them as just
	different kinds of the same eval method: "memo".

	Rename some of the uses of the function symbols "c", "java", "il".

compiler/hlds_pred.m:
	Add an extra field in proc_infos for storing any tabling attributes.

	Change the existing proc_info field that records information about
	the kinds of arguments of tabled procedures to record the information
	needed by the debugger too. This was needed to allow us to shift all
	the RTTI for procedure-specific tables (as opposed to the RTTI for
	the global I/O table) from mercury_stack_layout.h to mercury_tabling.h
	without duplicating the data (which would be a maintenance problem).

	Reformat some comments to make them easier to read.

compiler/layout.m:
compiler/layout_out.m:
	Delete the part of the exec trace information that used to record
	RTTI for tables, since this information is not generated only as
	part of the debugger data structures anymore.

compiler/prog_io_pragma.m:
	Recognize the updated syntax for tabling pragmas.

compiler/add_pragma.m:
	When processing tabling pragmas for inclusion in the HLDS, create
	any reset and statistics predicates they ask for.

compiler/make_hlds_passes.m:
	Export a predicate now needed by add_pragma.m.

	Handle the new attributes on tabling pragmas

compiler/globals.m:
	Change the function symbols of the types describing backends and
	foreign languages to say what they are. Previously, both types (as well
	as several others) included the function symbol "c"; now, they are
	target_c and lang_c respectively.

compiler/table_gen.m:
	Implement the changes described at the top.

	When passing around varsets and vartypes, pass the arguments in the
	standard order.

compiler/goal_util.m:
compiler/hlds_goal.m:
	When passing around varsets and vartypes, pass the arguments in the
	standard order.

compiler/rtti.m:
	Provide types for representing the runtime's data structures for
	tabling (which are now significantly more complex than a single word)
	and predicates for manipulating them, for use by both the ml and ll
	backends.

compiler/llds.m:
	Replace the comp_gen_c_var type with the tabling_info_struct type,
	which contains the information needed to create the per-procedure
	tabling data structures.

	Replace references to call tables with references to the various
	components of the new tabling data structures.

compiler/llds_out.m:
	Add code to write out tabling_info_structs.

	Delete the code required for the old, hacky way of resetting tables.

	Reorder some code more logically.

compiler/proc_gen.m:
	Generate tabling_info_structs.

compiler/stack_layout.m:
	Don't generate the information now generated in proc_gen.m.

compiler/mlds.m:
	Give mlds_proc_labels their own function symbols, instead of using
	a pair. Rename some other function symbols to avoid ambiguity and add
	expressiveness.

	Provide for the representation of references to the various components
	of the new tabling data structures, and for the representation of their
	types.

compiler/ml_code_gen.m:
	When generating code for a tabled procedure, generate also the data
	structures required for its table.

compiler/rtti_to_mlds.m:
compiler/ml_util.m:
	Move some predicates from rtti_to_mlds.m to ml_util.m, since we
	now also want to call them from ml_code_gen.m.

compiler/name_mangle.m:
	Add some utility predicates.

compiler/options.m:
	Delete the old --allow-table-reset option.

	Add the new --table-debug option.

	Comment out an implementor-only option.

compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_trail_ops.m:
compiler/add_type.m:
compiler/bytecode_gen.m:
compiler/code_gen.m:
compiler/compile_target_code.m:
compiler/complexity.m:
compiler/dependency_graph.m:
compiler/det_report.m:
compiler/export.m:
compiler/fact_table.m:
compiler/foreign.m:
compiler/global_data.m:
compiler/globals.m:
compiler/handle_options.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_data.m:
compiler/hlds_goal.m:
compiler/hlds_out.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/make.dependencies.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile.m:
compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_switch_gen.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
compiler/modes.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/polymorphism.m:
compiler/pragma_c_gen.m:
compiler/proc_label.m:
compiler/prog_data.m:
compiler/prog_foreign.m:
compiler/prog_item.m:
compiler/prog_mutable.m:
compiler/prog_out.m:
compiler/prog_rep.m:
compiler/prog_util.m:
compiler/recompilation.version.m:
compiler/size_prof.m:
compiler/special_pred.m:
compiler/switch_util.m:
compiler/transform_llds.m:
compiler/tupling.m:
compiler/type_ctor_info.m:
compiler/unify_gen.m:
	Conform to the changes above, and/or improve some comments.

mdbcomp/prim_data.m:
	Make the names of the function symbols of the proc_label type more
	expressive and less ambiguous.

mdbcomp/prim_data.m:
mdbcomp/mdbcomp.m:
mdbcomp/program_representation.m:
mdbcomp/rtti_access.m:
mdbcomp/slice_and_dice.m:
mdbcomp/trace_counts.m:
	Use . instead of __ as module qualifier.

	Conform to the change to prim_data.m.

browser/declarative_execution.m:
browser/declarative_oracle.m:
browser/declarative_tree.m:
	Conform the change to mdbcomp/prim_data.m.

tests/debugger/Mercury.options:
	Don't specify --allow-table-reset for fib.m, since that option
	doesn't exist anymore.

tests/debugger/fib.m:
	Use the new mechanism for resetting the table.

tests/debugger/print_table.m:
	Use the new syntax for pragma memo attributes.

tests/invalid/specified.{m,err_exp}:
	Use to the new syntax and reset method for pragma memo attributes.
	Test the handling of errors in the new attribute syntax.

tests/tabling/Mercury.options:
	Don't specify --allow-table-reset for specified.m, since that option
	doesn't exist anymore.

tests/tabling/specified.m:
	Use the new syntax for pragma memo attributes, and use the new
	mechanism for resetting tables. We could also use this test case
	for testing the printing of statistics, but the format of that
	output is still not final.

tests/tabling/fast_loose.m:
	Use the new syntax for pragma memo attributes, and use the new
	mechanism for resetting tables.

trace/mercury_trace.c:
trace/mercury_trace_cmd_developer.c:
	Conform to the changes in the RTTI data structures regarding tabling.

	Remove underscores from the names of some types that the style guide
	says shouldn't be there.

library/robdd.m:
	Comment out the tabling pragma until this change is bootstrapped.
	Without this, the conflict between the old calls to macros generated
	by the existing compiler and the new definition of those macros
	in the runtime would cause errors from the C compiler.
2006-06-08 08:20:17 +00:00