Commit Graph

319 Commits

Author SHA1 Message Date
Peter Wang
88047bbb45 Delete Erlang from tests.
tests/general/float_test.exp3:
tests/general/float_test.m:
tests/general/read_dir_regression.exp4:
tests/general/read_dir_regression.m:
tests/hard_coded/remove_file.exp2:
tests/hard_coded/remove_file.m:
    Delete Erlang backend specific expected outputs.

tests/hard_coded/Mmakefile:
tests/hard_coded/erlang_deconstruct.exp:
tests/hard_coded/erlang_deconstruct.m:
tests/hard_coded/existential_list.exp:
tests/hard_coded/existential_list.m:
tests/valid/Mmakefile:
tests/valid/erl_ite_vars.m:
tests/valid/zf_erlang_bug.m:
    Delete erlang target specific tests.

tests/*:
    Delete Erlang foreign procs and foreign types.
2020-10-27 11:10:11 +11:00
Zoltan Somogyi
c18cd1ff51 Rebuild nonlocals and instmaps when deleting code.
This fixes Mantis bug #512, whose symptom is a compiler abort in some
very specific circumstances. The regression test for the bug below
documents the long causal chain needed to tickle this abort.

compiler/simplify_goal_conj.m:
    When deleting unreachable code, set the requanify flag, which also
    causes instmap_deltas to be recomputed. The immediate cause of the bug
    was an instmap_delta that should have been thus recomputed, but wasn't.

    Do this in both places where simplification can delete dead code,
    though the Mantis 512 test case involves only one.

tests/valid/bug512.m:
    A regression test for this bug.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
    Enable the new test case, and run it with the flags that tickle
    the bug it is guarding against.
2020-10-23 01:38:58 +11:00
Zoltan Somogyi
effb79f3ee Delete an overstrong sanity check.
compiler/comp_unit_interface.m:
    As above.

tests/valid/int_imp_test.m:
tests/valid/int_imp_test_2.m:
    A regression test for the abort that the sanity check caused.

tests/valid/Mmakefile:
    Enable the new test case.
2020-09-27 16:49:14 +10:00
Zoltan Somogyi
4a3e4968c9 Fix compiler abort on typeclass accesses in lambdas.
compiler/modecheck_unify.m:
    User-written lambdas always include a mode declaration. However,
    the compiler can also construct lambdas from curried calls, and these
    do not have a mode declaration. These converted, non-mode-declared
    lambdas always start out containing *only* the curried call, but
    the polymorphism transformation can insert other code before this call,
    e.g. to pick up the typeinfos and/or typeclass infos to be passed
    to that call from other typeclass infos, so don't abort if the lambda
    contains calls to the builtin predicates that do these things besides
    the original call.

tests/valid/undetermined_mode_lambda.m:
    A regression test for the bug.

tests/valid/Mmakefile:
    Enable the new test case.
2020-07-29 01:39:42 +10:00
Zoltan Somogyi
6d79ac7802 Fix some anachronisms in tests/valid*.
tests/valid/Mmake.valid.common:
    Delete the RESERVE_TAG_PROGS make variable, since we have not supported
    reserved tags for a long time.

    Delete the NO_SPECIAL_PREDS_PROG make variable, since (despite its
    documentation) we do not actually specify --no-special-preds for
    the test cases listed in it.

tests/valid/Mmakefile:
    Conform to the changes above. Move the only test listed for
    NO_SPECIAL_PREDS_PROG to OTHER_PROGS.

tests/valid_seq/Mmakefile:
    Conform to the changes above.

tests/valid/unify_typeinfo_bug.m:
    Fix programming style.

tests/valid_seq/intermod_user_sharing.m:
    Delete a redundant import.
2020-07-14 00:51:50 +10:00
Zoltan Somogyi
1f45f91886 Make "mmake runtests" work again.
My commit afe2887882 broke the ability
to run the test suite outside of a bootcheck by executing "mmake runtests"
in the tests directory. This diff fixes that.

tests/Mmake.common:
    Don't define "TESTS_DIR = ..". While every single tests/*/Mmakefile
    defined it as such, I overlooked the fact that tests/Mmakefile itself
    defined it ".", referring to the same directory from a different starting
    point. Document this easily-overlooked fact.

    Rename the old runtests target, which after afe2887 runs the tests
    in a single directory, as runtests_dir, to leave the target name
    "runtests" itself free for tests/Mmakefile to use.

tests/Mmakefile:
    Define "TESTS_DIR = .", and add a target "runtests" which invokes
    "mmake runtests_dir" in each test directory.

tools/bootcheck:
    Invoke "mmake runtests_dir" instead of "mmake runtests" in each
    test directory.

    Initialize a variable just before it is used.

tests/*/Mmakefile:
    Add back the definition "TESTS_DIR = .."
2020-06-10 01:05:15 +10:00
Julien Fischer
06c9ecbb6b Fix github issue #89.
The current source-to-source debugger transformation cannot handle the
predicates introduced by higher-order specialization. There are likely similar
issues with other HLDS->HLDS transformations.

The fix (for now) is to disable most HLDS->HLDS transformations in .ssdebug
grades.

compiler/handle_options.m:
    Disable most HLDS->HLDS optimizations when the ss-trace level is
    shallow or deep.

    Add an XXX comment about a separate issue.

compiler/ssdebug.m:
    Add an XXX comment about predicates produced by higher-order
    specialization.

tests/WS_FLAGS.ws:
    Add a missing include.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
tests/valid/gh89.m:
    Add the test case from github issue 89.
2020-05-17 01:12:39 +10:00
Zoltan Somogyi
afe2887882 Remove stale references to test subdirs.
A long time ago, test directories such as hard_coded had subdirectories
such as hard_coded/typeclasses. These have since been flattened out
(e.g. hard_coded/typeclasses is now just typeclasses), but there were
still remnants of the old approach. This diff deletes those remnants.

tests/*/Mmakefile:
    Delete the TESTS_DIR and the SUBDIRS mmake variables; TESTS_DIR
    was always set to "..", and SUBDIRS to the empty string.

    Delete any references to the make variable NOT_WORKING, since
    it is never used.

tests/Mmake.common:
    Document that Mmakefiles in test directories don't have to set
    TESTS_DIR and SUBDIRS anymore. Fix the formatting of the documentation
    of the make variables they do still have to set.

    Delete the targets and actions for handling subdirectories of
    test directories, since there aren't any.

tests/Mmakefile:
    Simplify some code.
2020-04-14 11:23:12 +10:00
Zoltan Somogyi
4f32c50822 Let clauses with unknown warnings be processed.
This implements Mantis feature request #497.

compiler/parse_goal.m:
compiler/parse_dcg_goal.m:
    When we find that a disable_warnings scope contains an unrecognized
    warning name, generate a warning for it, and return this warning
    *alongside*, not *instead of*, the disable_warnings scope goal.
    This requires passing around not a maybe1(goal), as we have been doing
    till now, but a maybe2(goal, list(warning_spec)), so this change
    affects both (1) most of these two modules, and (2) most of the
    modules below.

compiler/error_util.m:
    Provide warning_spec as a synonym for error_spec, to be used in
    situations like this where the "error_spec" is intended contain
    something with severity_warning.

compiler/maybe_error.m:
    Provide some new utility predicates now needed in parse_goal.m
    and elsewhere.

compiler/prog_item.m:
    Provide room in the representation of clauses for the warnings
    generated by parsing the clause body goal.

compiler/add_class.m:
compiler/add_clause.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma_tabling.m:
compiler/du_type_layout.m:
compiler/get_dependencies.m:
compiler/make_hlds_passes.m:
compiler/parse_item.m:
compiler/parse_tree_out_clause.m:
compiler/prog_item_stats.m:
compiler/superhomogeneous.m:
    Conform to the changes above.

tests/valid/unknown_warning.m:
    Add this test case that checks whether a source file with an unknown
    warning name in a disable_warnings scope can have code generated for it.

tests/warnings/unknown_warning.{m,exp}:
    Add the same source file to this directory as well, to check whether
    we get the right set of warnings.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
tests/warnings/Mmakefile:
    Enable the two new test cases.
2020-04-05 19:09:31 +10:00
Zoltan Somogyi
18e222656f Stop common_struct from interfering with mark_static_terms.
This fixes Mantis bug #493.

compiler/common.m:
    Don't apply the common_struct optimization if doing so could possibly
    invalidate the annotations generated by mark_static_terms.m, which the
    MLDS code generator relies on.

    Move the tests for the applicability of the common_struct optimization
    for both construction and deconstruction unifications next to each other.

    Add XXXs about possible problems this code may have when applied to code
    that does region based memory allocation.

tests/valid/bug493.m:
    A simplified version of the Mantis test case.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
    Enable the new test case, and specify the options that originally caused
    the bug to manifest itself.
2020-01-22 22:10:43 +11:00
Zoltan Somogyi
3d37c6a442 Report wrongly qualified type names in foreign enums when parsing.
This fixes Mantis bug #486.

compiler/parse_pragma.m:
    Read in the name of the type in a foreign enum in whatever qualified
    form it is in the source code, and then try to implicitly qualify it,
    generating a specific error message if that attempt is unsuccessful.

compiler/parse_sym_name.m:
    To make the above possible, expose the code that does the
    implicit qualification. Do so not just in the form now needed
    by parse_pragma.m, but in the other forms used by other predicates
    in parse_sym_name.m as well, since they probably will be needed
    sooner or later. (The lack of such separated-out capability
    is what led to the code that caused bug 486 in the first place.)

    Avoid an unneeded asymmetry by providing mechanisms to parse
    implicitly qualified sym_names without arguments, as well as
    with arguments.

compiler/parse_util.m:
    Give several of the predicates involved in the above more expressive names.

compiler/parse_inst_mode_defn.m:
compiler/parse_type_defn.m:
compiler/parse_type_repn.m:
compiler/recompilation.check.m:
    Conform to the changes above.

compiler/error_util.m:
    Fix a bug that silently deleted the newly-added simplest_specs,
    which this diff uses for the first time. Add determinism requirements
    to avoid similar problems in the future.

compiler/add_foreign_enum.m:
    Note that the old code that diagnosed attempts to define foreign_enums
    for types in other modules should not be needed anymore.

tests/invalid/foreign_enum_import.err_exp:
    Expect the error message now generated by parse_pragma.m,
    which is more specific than the one generated by add_foreign_enum.m
    until now.

tests/valid/bug486.m:
tests/valid/bug486.window.m:
    A regression test for the bug.

tests/valid/Mmakefile:
    Enable the new test.
2019-09-29 13:26:44 +10:00
Zoltan Somogyi
a1ab0668a4 Allow foreign_enums for dummy types.
This fixes Mantis bug #485.

compiler/check_parse_tree_type_defns.m:
    Generalize the representation of du types in checked type definitions
    to give special representation to dummy types, as well as enum types.

    Allow foreign enum definitions for types whose du definitions are dummy,
    as well as those whose du definitions are enum.

compiler/prog_type.m:
    Have the predicate that tests whether a du type is an enum type
    to return the number of function symbols as well as the number of bits
    needed to represent them. This is the most direct differentiator between
    dummy types and enum types.

compiler/comp_unit_interface.m:
    Conform to the change in prog_type.m.

tests/valid/bug485.m:
    A regression test for the bug.

tests/valid/Mmakefile:
    Enable the new test case.
2019-09-29 12:16:30 +10:00
Zoltan Somogyi
4ccbefc241 Consider a module used if it defines a type_ctor in an inst defn.
compiler/unused_imports.m:
    As above. This fixes Mantis bug #483.

tests/valid/bug483.m:
    The test case for this bug.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
    Enable the new test case with the right options.
2019-09-02 18:25:23 +10:00
Zoltan Somogyi
1afe0df4e9 Fix an abort when constructing MLDS lookup tables.
This fixes Mantis bug #481.

compiler/ml_code_util.m:
    We used to approach the construction of tables for lookup switches
    by testing whether the shape of the HLDS code fit our requirements,
    and then building those tables using code that assumed that all the
    variables involved represented constants. This approach had a bug:
    when a switch arm constructed an output using *only* the switched-on
    variable, this passed the shape test even when that variable wasn't
    a constant.

    We could fix the shape test, instead this diff changes the approach
    to avoid making the incorrect assumption. This seems more robust,
    and in any case it is the approach used by the LLDS backend.

compiler/ml_disj_gen.m:
    Make the same switch in approach when generating lookup tables
    for disjunctions.

tests/valid/bug481.m:
    The Mantis test case.

tests/valid/Mmakefile:
    Enable the new test case.
2019-08-19 17:27:13 +10:00
Zoltan Somogyi
779e1ce54a Require only pulled-out functors' args to be non-unique.
This fixes the general case of Mantis bug 480.

compiler/cse_detection.m:
    When deciding whether we want to pull common X = f(...) unifications
    out of branched control structures, require only f'a args to be nonunique,
    not the args of any other functors that X may be bound to.

compiler/switch_detection.m:
    Obey the restrictions that cse_detection.m may impose.

tests/valid/bug480a.m:
    A new test case for this bug fix.

tests/valid/Mmakefile:
    Enable the new test case.
2019-08-07 14:59:40 +02:00
Zoltan Somogyi
9fab528bba Refine cse's interaction with uniqueness.
compiler/cse_detection.m:
    When considering whether a variable's unifications can be pulled
    out of disjunctions (or if-then-elses), require only that the
    *arguments* of the function symbols it may be unified with are
    free of uniqueness, but allow the top level memory cell itself
    to be unique (which it will be by default immediately after its
    construction). This is sufficient to avoid github issue 64.

    This fixes mantis bug 480 in *almost* all cases.

tests/valid/bug480.m:
    A modified version of the mantis test case.

tests/valid/Mmakefile:
    Enable the new test case.
2019-08-05 13:08:20 +02:00
Zoltan Somogyi
9c2ef455b3 Copy type_ctor's module qualifiers when pushing types into insts.
compiler/prog_mode.m:
    As above. This fixes github issue #65.

tests/valid/gh65.m:
    A regression test derived from the program attached to the github issue.

tests/valid/Mmakefile:
    Enable the new test case.
2019-07-21 01:11:49 +02:00
Zoltan Somogyi
2466524308 Fix cse_detection.m's interaction with uniqueness.
This fixes github issue #64.

compiler/cse_detection.m:
    When pulling a unification X = f(Y1, ..., Yn) out of an arm of
    a disjunction, switch or if-then-else, require the instantiation state
    of X to be free of unique or mostly_unique components.

    Put the requirements on X's inst into a single predicate.

    Add a mechanism to make debugging similar issues easier.

tests/valid/cse_unique.m:
    A suitably modified form of the test program on github.

tests/valid/Mmakefile:
    Enable the new test case.
2019-06-30 20:16:07 +02:00
Zoltan Somogyi
06542c7070 Add a test case for singleton warnings we don't yet pass.
tests/valid/some_singleton.m:
    The new test case.

tests/valid/Mercury.options:
    Specify the options for the test case.

tests/valid/Mmakefile:
    List the test case, but do not enable it yet.
2019-05-28 23:05:20 +02:00
Zoltan Somogyi
c4dce74bb4 Improve the treatment of promises.
compiler/check_promise.m:
    Fix github issue #50. If a promise is imported from another module,
    do not process it. Processing would require the pred_id/proc_id slots
    in plain_calls to have been filled in by typechecking, but we don't
    invoke the typechecker on imported code.

compiler/assertion.m:
    Improve the documentation of the predicates that test whether
    an assertion falls into a given category of assertion. Provide variants
    of those predicates that work on goals as well as on assert_ids, so later
    we can test whether assertions fall into any of those categories.

    Add an XXX for what I am pretty sure is a bug.

compiler/hlds_module.m:
compiler/make_hlds_passes.m:
compiler/prog_data.m:
compiler/typecheck.m:
    Improve some comments.

tests/valid/github_50.m:
tests/valid/github_50.submodule.m:
    The two-module test case from github, changed to reflect our coding
    standards.

tests/valid/Mmakefile:
    Test that compiling the new test case does not cause a compiler abort.
2018-10-01 06:54:00 +10:00
Peter Wang
72bc36afc2 Fix some problems with static terms in LLDS grades.
compiler/unify_gen.m:
    Add type_info, typeclass_info and ground term constants to the var
    state map using assign_const_to_var instead of assign_expr_to_var.
    expr_is_constant will fail if a constant expression is added with
    the more general assign_expr_to_var, causing missed opportunities
    to construct terms statically in var_locn.m.

    Prevents a compiler abort (bug #457) where mark_static_terms.m
    determines that a term can be constructed statically but var_locn.m
    decides otherwise.

compiler/var_locn.m:
    Do not abort if var_locn_assign_dynamic_cell_to_var is passed
    `construct_statically'. Even after the previous change, it is
    possible for mark_static_terms.m to determine that a cell with a
    dummy type argument can be constructed statically but var_locn.m
    currently does not. This was preventing bootchecks at
    -O5 --intermodule-optimization.

compiler/hlds_goal.m:
    Fix misleading documentation for how_to_construct.

tests/valid/Mercury.options:
tests/valid/bug457.m:
    Add a test case.
2018-04-30 09:41:28 +10:00
Julien Fischer
71e279425c Complete switches on 8- and 16-bit fixed size integers.
compiler/type_util.m:
    Treat complete switches on 8- and 16-bit fixed sized integers as det.
    (We don't do the same for the other fixed size integer types, since having
    a complete switch on them is not practical anyway.)

tests/valid/Mmakefile:
tests/valid/compare_{int8,uint8}_switch.m:
    Add a test for complete switches on the 8-bit integer types.
2018-04-05 20:03:02 +10:00
Zoltan Somogyi
806cdfa011 Add a test case we don't pass yet. 2018-02-07 05:03:46 +11:00
Zoltan Somogyi
fb97df69ed Make "compute type representations" a separate pass.
The ultimate purpose of this diff is to prepare for future improvements
in type representations, allowing values of some data types to be represented
more compactly than up to now.

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

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

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

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

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

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

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

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

    Fix a bad dump stage name.

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

    Make a sub-switch explicit.

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

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

    Delete some forwarding predicates that are no longer needed.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Delete the reserve_tag pragma.

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

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

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

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

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

    Provide some utility predicates.

    Optimize some existing predicates.

    Rename some types to better reflect their meaning.

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

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

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

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

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

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

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

    Move the module from the make_hlds to the hlds package.

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

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

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

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

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

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

    Delete a type moved to type_util.m.

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

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

    Give some predicates more meaningful names.

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

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

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

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

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

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

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

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

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

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

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

    Give some predicates and function symbols more meaningful names.

    Note some problems with the existing code.

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

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

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

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

tests/valid/Mmake.valid.common:
tests/valid/Mmakefile:
    Disable any reserve_tag test cases, as they are not applicable anymore.
2018-01-31 17:54:40 +11:00
Julien Fischer
e5f087a07e Rename a test case.
tests/valid/int64.m:
    Rename this test case to unescaped_special_char since its current name
    conflicts with an upcoming standard library addition.  The new name
    is more descriptive anyway.

    Rename the type int64/0 defined in this test since an upcoming change
    will make that type a builtin (and hence a reserved name).

tests/valid/Mmakefile:
    Conform to the above change.
2018-01-11 23:09:08 -05:00
Zoltan Somogyi
56b636886a Avoid a compiler abort on empty submodules.
This fixes Mantis bug 437.

compiler/split_parse_tree_src.m:
    Add empty submodules to the submodules map, since the abort
    was caused absence of such an entry.

    Warn about the duplication if a submodule is later defined
    with the same name.

tests/valid/empty_submodule.m:
    Add this regression test for the bug.

tests/valid/Mmakefile:
    Enable the new test case.
2017-08-05 18:49:14 +02:00
Zoltan Somogyi
4c76e6833e Fix a bug in unused_imports.m involving instances.
compiler/unused_imports.m:
    When processing type_ctor_info and base_typeclass_info cons_ids, record
    the module name in the cons_id as being used, rather than just the
    module *containing* that module. Effectively, the bug was that we treated
    a module name as if it were a sym_name; the types are the same, but the
    meaning isn't.

tests/valid/use_import_only_for_instance.m:
    A regression test for the bug.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
    Enable the regression test.
2017-06-30 14:59:08 +02:00
Paul Bone
aedaed0545 Match output arguments correctly for mutually recursive code
Mutually-recursive tail calls might have different arguments than their
parents.  They may have more or fewer arguments than the caller, and the
outputs may be in different positions.  This change handles these correctly.

compiler/mark_tail_calls.m?
    As above.

tests/valid/mutual_tailrec_outputs.m:
    Add a test case that triggered a crash with mismatched argument list
    lengths.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
    Add new test.
2017-04-11 15:22:28 +10:00
Paul Bone
d4ef274451 Enable non-tail-call warnings for mutually-recursive code
This change enables warnings for mutual recursion for the low level C
backend.

--warn-non-tail-recursion currently only works for direct recursion.  This
change renames it to --warn-non-tail-recursion-self and adds
--warn-non-tail-recursion which is intended to produce warnings for self
and mutual recursion.

compiler/options.m:
    Add new option.

compiler/handle_options.m:
    Make --warn-non-tail-recursion imply --warn-non-tail-recursion-self.

compiler/ml_tailcall.m:
    Conform to changes in options.m.

compiler/mark_tail_calls.m:
    Simplify the code that interprets tail recursion warning options, this
    avoids the need for the warn_non_tail_rec_calls_opt which was only used
    here in an unnecessary step.  This logic has also been moved to a
    separate predicate.

    Add a warning for mutually recursive calls that are not tail recursive.

    Update these warning/error messages to say if the call is self or
    mutually recursive.  Also in the case of mutually recursive calls, name
    the callee.

compiler/mercury_compile_llds_back_end.m:
    Compute the dependency information before running the pre-LLDS passes.
    This makes sure that we do this once for the whole module, and
    independently of --trad-passes.

compiler/dependency_graph.m:
    Add a method for getting the SCC of a given node from a dependency_info
    structure.  The SCC is retrieved from a lazily built map.

doc/user_guide.texi:
    Document the changes.

tests/invalid/Mmakefile:
tests/invalid/require_tailrec_1.err_exp:
tests/invalid/require_tailrec_1.m:
tests/invalid/require_tailrec_2.err_exp:
tests/invalid/require_tailrec_2.m:
tests/invalid/require_tailrec_3.err_exp:
tests/invalid/require_tailrec_3.m:
tests/valid/Mmakefile:
tests/valid/require_tailrec_1.m:
tests/valid/require_tailrec_2.m:
tests/valid/require_tailrec_3.m:
    Test the tail recursion warnings a lot more extensively, some of these
    are new test programs, others just have many more test cases within
    them.

tests/invalid/Mercury.options:
tests/valid/Mercury.options:
    Add new test files.

    Disable most optimisations as these could optimise away the mutual tail
    recursions.

tests/EXPECT_FAIL_TESTS.hlc.gc:
    New test case failures.
2017-03-30 17:14:46 +11:00
Zoltan Somogyi
f1be23e6ce Fix Mantis bug 429.
compiler/hlds_goal.m:
    Add a new goal feature that marks a goal as having been lifted out of
    a disjunction or switch by cse_detection.m.

compiler/cse_detection.m:
    Add this feature to the deconstruction unifications lifted out by cse.

compiler/det_report.m:
    When expecting the subgoal of a require_complete_switch or
    require_switch_arms_detism scope to be a switch, allow the subgoal
    to be a conjunction of lifted-out goals followed by the switch.

    Improve the wording of an unrelated error message.

compiler/saved_vars.m:
    Conform to the change to hlds_goal.m.

tests/valid/bug429.m:
    A commented version of the Mantis bug 429 test case.

tests/valid/Mmakefile:
    Enable the new test case.
2017-01-20 00:28:19 +11:00
Zoltan Somogyi
9f7d8305a6 Prefer switching on the named variable in require_switch_* scopes.
compiler/switch_detection.m:
    As above.

tests/valid/preferred_switch_var.m:
    A new test case. With the compiler before this change, it did not compile,
    because

    (a) switch detection transformed the disjunction in the
        "require_switch_arms_semidet [T]" scope into a switch on U instead
        of T, because the switch on U is cannot_fail while the switch on T
        is can_fail, and

    (b) having a switch on U inside the "require_switch_arms_semidet [T]" scope
        got an error about the goal not being a switch on T.

tests/valid/Mmakefile:
    Enable the new test case.
2016-09-01 07:09:34 +10:00
Zoltan Somogyi
c894ff3d35 Make switch detection look at all candidates.
When switch detection looks at a disjunction, it loops over all the nonlocal
variables that are already-bound on entry to the disjunction, to see whether
the disjunction is a switch on that variable. We used to stop this search
as soon as we found what looked like an good candidate, but in some
rare cases, (a) committing to this candidate leads to a determinism that is
not as tight as possible, and (b), if we chose to transform the disjunction
into another candidate, the resulting determinism *would* be as tight
as possible.

The fix is to always gather all the candidate switches, rank them in order of
how likely they are to yield a tight determinism, and choose the candidate
with the highest rank. Doing this requires computing whether *each candidate
switch* is a can_fail switch, whereas the old approach required computing
only whether the *chosen switch* is a can_fail switch.

While avoiding this small amount of extra computation was probably a good
tradeoff in the mid 1990s, it isn't anymore. The new code is also simpler
and clearer, for two distinct reasons. One is that committing to a good-enough
candidate as soon as we find it required mixing the code that *finds* candidate
switches with the code that *acts* on the selected candidate. The second is
that the old code could choose the best possible switch (none of whose arms is
reachable due the switched-on variable's initial inst, and which can therefore
be translated to nothing more than just `fail') only by accident, never by
design, since it tested which arms are reachable only *after* it has already
selected the variable to switch on.

This diff fixes Mantis bug #414.

compiler/switch_detection.m:
    As above.

tests/valid/bug414.m:
    The test case for the bug.

tests/valid/Mmakefile:
    Enable the test case.
2016-07-27 11:04:36 +02:00
Julien Fischer
e9dbcb9b9d Add the test case for bug #36 to the test suite.
This bug was reported against rotd-2008-01-14; the problem does not occur with
rotd-2016-06-23, although I'm not sure if that's because the original issue has
been fixed or if there is just something masking it.

tests/valid/bug36.m:
tests/valid/Mercury.options:
tests/valid/Mmakefile:
     Add the test case for bug #36.
2016-06-23 14:45:03 +10:00
Zoltan Somogyi
699fdd47e8 Make switch detection mindful of require_*switch* scopes.
compiler/switch_detection.m:
    Sometimes a disjunction can be interpreted as a switch on more than
    one variable. For example, the disjunction

        (
            A = x,
            B = x,
            ...
        ;
            A = x,
            B = y,
            ...
        ;
            A = y,
            B = x,
            ...
        ;
            A = y,
            B = y,
            ...
        )

    can be viewed either as a switch on A (with a switch on B in each arm) or
    as a switch on B (with a switch on A in each arm). However, if e.g. this
    disjunction is in a require_complete_switch [B] scope, we *want* switch
    detection to choose the second view.

    Switch detection has traditionally tried to see if a disjunction is a
    switch on each bound nonlocal variable of the disjunction in order
    of those variable's variable numbers, which generates the right results
    in this context only by accident. Change this so that inside a scope whose
    subgoal is required to be a switch on a certain variable, we now look for
    a switch on *that* variable first, so that if the disjunction *can* be
    a switch on that variable, it *will be* a switch on that variable.

tests/valid/required_var.m:
    A new test case to test the new capability.

tests/valid/Mmakefile:
    Enable the new test case.
2016-04-20 12:34:33 +10:00
Zoltan Somogyi
502ea379e4 Make require_complete_switch [X] require a switch on X.
compiler/det_report.m:
    Generate an error message if a require_complete_switch [X] scope
    is wrapped around a goal that is not a switch on X.

doc/reference_manual.texi:
    Update the reference manual to document this change. Also fix an
    old documentation problem: require_complete_switch scopes do NOT
    require covering all the function symbols in the type of the
    switch-on variable if the switched-on variable's inst says that
    it cannot be bound to some of them.

compiler/hlds_goal.m:
    Update the comment on the require_complete_switch scope
    in the same way.

NEWS:
    Announce the change.

tests/warnings/bug257.{m,exp}:
tests/invalid/bug257.{m,err_exp}:
tests/warnings/Mmakefile:
tests/invalid/Mmakefile:
    For the bug257.m test case, which has a require_complete_switch [X] scope
    around a goal that is not a switch on X, expect the error message
    we now generate, not the old warning.

    Since the compilation of bug257.m now fails, move it from warnings
    to invalid.

tests/valid/Mmakefile:
    Disable the bug257b.m test case, which also had a
    require_complete_switch [X] scope around a goal that was not a switch on X.

tests/valid/bug257b.m:
    Document that this test case is now disabled, and why.
2016-04-19 18:05:39 +10:00
Julien Fischer
1d351be438 Avoid running some tests in decldebug grades.
Fix an error message.

tests/valid/Mmake.valid.common:
tests/valid/Mmakefile:
tests/valid_seq/Mmakefile:
     Don't run valid/bug50 and valid/bug50_full in decldebug grades,
     since they force the use of --trace deep.

compiler/handle_options.m:
   Quote the trace level when referring to it in an error message.

   Fix an incorrect option name in an error message.
2016-02-09 18:27:57 +11:00
Zoltan Somogyi
d4ccf52c37 Allow !.SV in require_{complete_switch,switch_arms_det*} scopes.
This fixes mantis bug 402.

compiler/prog_item.m:
    Change the representation of require_complete_switch and
    require_switch_arms_{det,semi,...} goals so that the switch variable
    does not have to be a plain variable, but can also be the current value
    of a state variable. (You can't switch on the future value.)

compiler/prog_io_goal.m:
    When parsing the switched-on variable in these kinds of scopes,
    allow the variable in the singleton list to be !.SV as well as a plain
    variable.

compiler/goal_expr_to_goal.m:
    Expand out the !.SV in these scopes if the switched-on variable
    is of that form.

compiler/prog_io_util.m:
    Change the return value of the predicate that parses both plain and
    state vars to make the meaning of its return value more self-describing.

compiler/parse_tree_out_clause.m:
compiler/prog_util.m:
    Conform to the change in prog_item.m.

tests/valid/bug402.m:
    New regression test for the bug.

tests/valid/Mmakefile:
    Enable the new test.
2016-01-02 20:48:57 +11:00
Paul Bone
3452e25fd6 Improve tail call warnings for the low level C grade.
This patch reduces spurious tail call warnings by warning only for the last
of a sequence of recursive calls along an execution path, for example it
no-longer emits a warning for the first of the two recursive calls in
quicksort.  I have already made a change to this effect for the MLDS
backends.

This patch also implements the new the require_tail_recursion pragma.  This
change has already been made for the MLDS backends.

The require_tail_recursion pragma does not yet handle mutual recursion or
raise an error if the code is not recursive at all.  These will be my next
tasks.

compiler/mark_tail_calls.m:
    Combine marking tail calls with warning about tail calls.

    Handle scopes more accurately.

compiler/mercury_compile_llds_back_end.m:
    Conform to changes in mark_tail_calls.m

    No longer warn for tail calls, this is now done in the same pass that
    marks tail calls.  The decision to run this pass is now made on a
    per-procedure basis and in mark_tail_calls.m

tests/invalid/require_tailrec_1.m:
tests/invalid/require_tailrec_2.m:
tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
tests/valid/require_tailrec_1.m:
tests/valid/require_tailrec_2.m:
tests/valid/Mmakefile:
tests/valid/Mercury.options:
    Add new tests.

tests/invalid/Mmakefile:
tests/invalid/Mercury.options:
tests/invalid/require_tail_recursion.{m,err_exp} ->
        require_tailrec_invalid.{m,exp}:
    Rename existing test.
2015-12-16 22:47:08 +11:00
Zoltan Somogyi
c6ab550db8 Remove the code for automatic initialization of solver vars.
We haven't supported it in years, and keeping it in the compiler
is just a maintenance burden and a performance problem.

mdbcomp/prim_data.m:
    Delete the spec_pred_init functor, since we don't support special
    "init" predicates anymore.

compiler/prog_data.m:
    Delete the slot in solver type details that record the name of the
    auto-initialization predicate.

compiler/prog_io_type_defn.m:
    Don't allow a type definition to specify an auto-initialization predicate.

compiler/options.m:
compiler/globals.m:
    Delete the option that allowed support for auto-initialization to be
    turned back on.

compiler/inst_match.m:
compiler/inst_util.m:
    Delete comments about auto-initialization.

compiler/mode_info.m:
    Delete the record of whether we have variables that can be
    auto-initialized (we never do anymore) and the flag that controls whether
    auto-initialization is permitted or not.

compiler/modecheck_conj.m:
    Simplify the code that modechecks conjunctions, since it no longer
    has to figure out where to insert auto-initializations of solver vars.

compiler/modecheck_goal.m:
    Delete the code that ensured that if one branch of a branched
    control structure auto-initialized a solver variable, then they
    all did.

compiler/modecheck_unify.m:
    Don't auto-initializate variables before unifications.

compiler/modecheck_util.m:
    Delete the code that auto-initialized solver variables at the ends
    of procedure bodies if this needed to be done and wasn't done before.

compiler/add_special_pred.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/get_dependencies.m:
compiler/hlds_module.m:
compiler/hlds_pred.m:
compiler/modecheck_call.m:
compiler/modes.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out.m:
compiler/post_term_analysis.m:
compiler/smm_common.m:
compiler/special_pred.m:
compiler/term_constr_errors.m:
compiler/term_constr_initial.m:
compiler/term_util.m:
compiler/termination.m:
compiler/trace_params.m:
compiler/type_util.m:
compiler/unify_proc.m:
    Delete code that handled stuff related to auto-initialization,
    and now always take the path that would normally be taken in the
    absence of auto-initialization.

deep_profiler/read_profile.m:
runtime/mercury_layout_util.c:
runtime/mercury_stack_trace.c:
util/mdemangle.c:
    Remove code that recognized the compiler-generated name of initialization
    predicates.

tests/debugger/solver_test.m:
tests/hard_coded/solver_construction_init_test.m:
tests/hard_coded/solver_disj_inits.m:
tests/hard_coded/solver_ite_inits.m:
tests/invalid/missing_init_pred.m:
tests/invalid/zinc2mer_lib.m:
tests/valid/fz_conf.m:
tests/valid/solver_type_bug_2.m:
tests/valid/solver_type_mutable_bug.m:
    These tests tested the handling of auto-initialization, which we
    no longer support. Keep them around (and a bit more visible than
    inside the git repo) in case we need them again, but add a comment
    to each saying that the test is disabled.

tests/debugger/Mercury.options:
tests/debugger/Mmakefile:
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
tests/valid/Mercury.options:
tests/valid/Mmakefile:
    Disable those tests.

tests/warnings/non_term_user_special.{m,exp}:
    Part of this test tested the handling of auto-initialization;
    delete that part.

tests/warnings/Mercury.options:
    Delete the flag required by the deleted part, since we don't support it
    anymore.
2015-12-03 05:06:28 +11:00
Mark Brown
ecfe659940 Revert the workaround from commit 3c255eea
Bug 264, which this workaround was for, has been fixed in other changes.

compiler/mode_errors.m:
    Remove the temporary error.

compiler/modecheck_unify.m:
    Don't check this error condition.

doc/reference_manual.texi:
    Document the constraint that actually applies, namely that functions
    that do not match the default mode do not match Mercury's 'ground'
    inst.

    Clarify that "no higher-order inst information" means no *explicit*
    information. Given that there is a default, this is not the same as
    saying there are no logical consequences.

tests/invalid/default_ho_inst.err_exp:
tests/invalid/default_ho_inst_2.err_exp:
    Update expected output.

tests/valid/Mmakefile:
tests/valid/ho_func_call_2.m:
    New test case. Function modes that are not the same as the default,
    but that match it, can still safely be treated as ground.
2015-12-02 21:00:13 +11:00
Zoltan Somogyi
bf324f88cc Fix Mantis bug 50.
compiler/liveness.m:
    The bug was a violation of an invariant required by delay_death_proc_body.
    Document the requirement that this invariant places on cse_detection.m,
    the requirement whose non-fulfillment caused the bug.

compiler/cse_detection.m:
    When hoisting a deconstruction unification and creating new variables
    for its arguments, if any of the arguments were named variables holding
    type_infos, typeclass_infos or their components, then give a name
    to the variable holding the corresponding argument as well. This fixes
    the bug by fixing the violation of the above invariant. Add a pointer
    to the invariant in liveness.m.

    Document the reason why another change that looks like a potential fix
    wouldn't actually work.

    Give some predicates better names and argument orders.

    Update the module qualifier (from : to .) in an example. We haven't used
    : in a LONG time.

compiler/continuation_info.m:
    Simplify the code where the bug originally caused the compiler to crash.
    (This code was not actually in error.)

compiler/simplify_goal_conj.m:
    Fix a small performance bug I noted while hunting the bug. When the
    excess_assign optimization replaced all occurrences of a variable,
    it delete the variable from the varset, but not the vartypes,
    leaving lookups on it slower than necessary.

    Record the reason why do not choose to fix a potential performance bug
    that to the best of my knowledge, we haven't actually seen yet in the wild.

compiler/hlds_goal.m:
    Define a type as a shorter and more meaningful synonym for a particular
    type used in a predicate (incremental_rename_vars_in_goal) that I thought
    would have been useful to implement the change to cse_detection.m
    that turned out to be NOT a good fix.

compiler/state_var.m:
    Use the new type synonym.

tests/valid/bug50_full.m:
tests/valid/bug50.m:
    Two versions of the Mantis test case; the original version (slightly
    cleaned up), and the minimal version I actually debugged. The latter
    has a detailed description of the bug.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
    Enable the new test cases.
2015-11-15 23:13:02 +11:00
Zoltan Somogyi
3c255eeac7 Don't allow putting functions with nondefault signatures into terms.
The code that takes the function out of the term can use the function
as if it had the default signature. If it doesn't, this can lead to
This fixes Mantis bug 264.

compiler/mode_errors.m:
    Provide a way to record such errors, and to print error messages for them.

compiler/modecheck_unify.m:
    Look for such errors when constructing terms.

browser/declarative_user.m:
    Don't put a function with a nondefault signature (it used a subtype)
    into a term. Enforce the subtype with a runtime assertion instead.

doc/reference_manual.texi:
    Document the new limitation.

tests/invalid/default_ho_inst.{m,err_exp}:
    The test case for Mantis bug 264.

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

tests/valid/Mmakefile:
    Disable the old ho_func_call test case, since it RELIES on putting
    functions with nondefault modes into terms. It also uses I/O states
    in ui modes.
2015-11-02 13:09:37 +11:00
Zoltan Somogyi
4e4e91da34 Enable the valid/inst_perf_bug_2 test case.
The performance bug it tests for was fixed a while ago,
when we started pretesting user-defined insts.
2015-10-31 19:36:54 +11:00
Zoltan Somogyi
ef6d68a88d Add items to the HLDS by kinds, not in passes.
There are several reasons for this change.

First, it is more flexible than the previous arrangement of adding items
to the HLDS in three passes. Since adding a fourth pass would have had
significant performance implications, we refrained from making changes
that would have required a fourth pass in a pass-based algorithm.
With the new structure, such changes do not lead to any detectable slowdown,
so there is no reason why we should avoid making them.

In fact, the immediate motivation for this diff is to make such a change.
This is a fix for Mantis bug 318, which requires adding abstract and/or
non-foreign definitions for types before foreign definitions for those types
*regardless* of their relative order in the source code.

This diff also has the side effect that e.g. the mode declarations for
a predicate don't have to follow the declaration of the (type of) the predicate
itself. Pred and mode declarations used to be processed in the same pass,
but now, all pred declaration are processed before all mode declarations.

Second, as identified earlier, the new structure is conceptually cleaner than
the old one, and the constraints on when different kinds of items have to be
added to the HLDS can documented next to the code that does the adding,
since that code is no longer mixed with code that adds other kinds of items
at the same time.

Third, the code we used to use to detect invalid type definitions
was only a crude approximation. With the new setup, it is trivial to use
an exact computation. We now proceed to later compiler passes in many cases
that previously led us to stop before type checking because we (erroneously)
believed that the program had an invalid type definition.

Fourth, my benchmarking shows a speedup on tools/speedtest -l -m of about
1.2% to 1.5%. The new approach does allocate a bit more memory (a pair
and a cons cell per item), but it traverses most items just once, not
three times. A few kinds of items (e.g. pred declarations) do have to be
processed more than once, e.g. both before and after some other kinds
of items are added to the HLDS, but four of the five most frequent items
in bootchecks (the pragmas recording the results of the termination and
exception analyses, mode declarations, and clauses) are processed just once.
Evidently, the speedup from traversing fewer items, and avoiding the
switches on item kinds that those traversals involve, is greater than
the extra cost of the additional memory allocations, including their effect
on garbage collection times.

compiler/make_hlds_passes.m:
    Make the change described above.

    Remove "shim" code, i.e. code that serves only to unpack the pairing
    of an item with other info such as a status, and code that tests
    that status, e.g. to see whether the item is defined in the module
    being compiled. Move that shim code to the other submodules of
    make_hlds.m. (We used to have add_xyz predicate in make_hlds_passes.m
    and module_add_xyz predicates in those submodules, in which add_xyz
    contained only shim code and a call to the corresponding module_add_xyz
    predicate.)

compiler/add_class.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pred.m:
compiler/add_solver.m:
    Move shim code here from make_hlds_passes.m.

    Give some predicates better names.

    In a few cases, remove unneeded arguments from predicates. For example,
    most predicates that do only checks don't need write access to the
    module_info.

compiler/add_pragma.m:
    Use subtypes to make the code a bit more efficient.

    Add specialized fold predicates that can handle those subtypes.

compiler/add_type.m:
    Add documentation for an old design decision.

compiler/make_hlds.m:
    Add some utility types for use by make_hlds_passes.m and the various
    add_xyz.m.

compiler/check_typeclass.m:
    Improve an error message. We now get this error message even for modules
    on which the compiler previously stopped before getting to typechecking.

compiler/modes.m:
    Don't generate redundant error messages for mode errors in mutables' aux
    preds. (Previously, the mode checker wouldn't have been invoked if
    make_hlds_passes.m found the original problem.)

compiler/prog_item_stats.m:
    Delete an unneeded import.

library/list.m:
    Add an inst-preserving version of reverse, since make_hlds_passes.m
    now needs one.

tests/debugger/solver_test.exp:
    We add predicates to the HLDS in a different order now (auxiliary
    predicates for solver types are added *after* used-defined predicates).
    This test prints the raw order of those predicates, so expect the new
    order.

tests/invalid/typeclass_test_9.err_exp:
tests/invalid_purity/purity_nonsense2.err_exp:
    Expect error messages we didn't used to get, because the compiler
    stopped before typechecking due to (incorrectly) believing that it found
    an invalid type definition.

    For typeclass_test_9, expect the updated error message from
    check_typeclass.m. (This newly printed error message was the reason
    *why* I improved the message from check_typeclass.m.)

tests/invalid/tc_err1.err_exp:
tests/invalid/tc_err2.err_exp:
tests/invalid/typeclass_bogus_method.err_exp:
tests/invalid/typeclass_missing_mode_2.err_exp:
tests/invalid/typeclass_test_10.err_exp:
tests/invalid/typeclass_test_3.err_exp:
tests/invalid/typeclass_test_4.err_exp:
    Expect the updated error message from check_typeclass.m.

tests/valid/bug318.m:
    A test case for Mantis bug 318.

tests/valid/Mmakefile:
    Enable the new test case.
2015-10-29 14:13:46 +11:00
Julien Fischer
3dd02876a5 Delete the MLDS->IL backend.
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_managed.m:
compiler/il_peephole.m:
compiler/ilasm.m:
compiler/ilds.m:
    Delete the modules making up the MLDS->IL code generator.

compiler/globals.m:
compiler/prog_data.m:
    Delete IL as a target and foreign language.

compiler/prog_io_pragma.m:
    Delete the max_stack_size/1 foreign proc attribute.  This was only
    ever required by the IL backend.

compiler/options.m
    Delete options used for the IL backend.

compiler/write_deps_file.m:
    Don't generate mmake targets for .il files etc.

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

compiler/notes/compiler_design.html
compiler/notes/work_in_progress.html
    Conform to the above changes.

library/*.m:
    Delete IL foreign_proc and foreign_export pragmas.

README.DotNet:
    Delete this file.

browser/Mmakefile:
compiler/Mmakefile:
deep_profiler/Mmakefile:
mdbcomp/Mmakefile:
mfilterjavac/Mmakefile:
profiler/Mmakefile:
runtime/Mmakefile:
slice/Mmakefile:
    Conform the above changes.

configure.ac:
    Don't check that IL is a supported foreign language when performing the
    up-to-date check.

    Delete the '--enable-dotnet-grades' option.

scripts/Mmake.vars.in:
    Delete variables used for the IL backend (and in on case by the Aditi
    backend).

scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
scripts/Mmake.rules:
scripts/canonical_grade.sh-subr:
tools/bootcheck:
    Delete stuff related to the 'il' and 'ilc' grades.

doc/reference_manual.texi:
     Delete the documentation of the 'max_stack_size' option.

doc/user_guide.texi:
     Delete stuff related to the IL backend.

tests/hard_coded/csharp_test.{m,exp}:
tests/invalid/foreign_type_missing.{m,err_exp}:
tests/valid/csharp_hello.m:
	Delete these tests: they are no longer relevant.

tests/hard_coded/equality_pred_which_requires_boxing.m:
tests/hard_coded/foreign_import_module.m:
tests/hard_coded/foreign_import_module_2.m:
tests/hard_coded/foreign_type.m:
tests/hard_coded/foreign_type2.m:
tests/hard_coded/foreign_type3.m:
tests/hard_coded/intermod_foreign_type2.m:
tests/hard_coded/lp.m:
tests/hard_coded/user_compare.m:
tests/invalid/foreign_type_2.m:
tests/invalid/foreign_type_missing.{m,err_exp}:
tests/invalid/foreign_type_visibility.m:
tests/invalid/illtyped_compare.{m,err_exp}:
tests/submodules/external_unification_pred.m
tests/valid/big_foreign_type.m
tests/valid/solver_type_bug.m
tests/valid_seq/foreign_type_spec.m
tests/valid_seq/intermod_impure2.m
    Delete IL foreign_procs where necessary.

tests/hard_coded/Mmakefile
tests/invalid/Mercury.options
tests/invalid/Mmakefile
tests/submodules/Mmakefile
tests/valid/Mercury.options
tests/valid/Mmake.valid.common
tests/valid/Mmakefile
tests/valid_seq/Mmakefile
tests/valid_seq/Mercury.options
    Conform to the above changes.
2015-09-21 11:34:46 +10:00
Zoltan Somogyi
c34f6dd4e8 Let the compiler bootstrap in decldebug grades again.
The big diff that replaced the item list with proper parse trees included code
that the compiler couldn't handle in decldebug grades, aborting with a message
about liveness mismatch between different switch arms. The problem occurred
when compiling this code in generate_missing_start_section_warning_int,
which is one arm of a switch on !.MissingStartSectionWarning:

    !.MissingStartSectionWarning =
        have_not_given_missing_section_start_warning,
    !:MissingStartSectionWarning =
        have_given_missing_section_start_warning,
    Pieces = [invis_order_default_start(1), ...],
    _Spec = error_spec(severity_error, phase_term_to_parse_tree,
        [simple_msg(Context, [always(Pieces)])])

The problem was liveness.m's handling of the from_ground_term_construct
scope that is generated for the assigmnet of the ground term to Pieces.

compiler/liveness.m:
    During the first pass through the procedure body, the liveness pass,
    replace with the empty conjunction any from_ground_term_construct scopes
    that construct terms to assign to dead variables. This prevents the
    second pass, the deadness pass, from including the dead variable
    (Pieces in the above example, after the assignment to _Spec was
    optimized away by earlier passes) in the set of variables that
    have been seen, since obviously, they won't be seen in the other arms.
    This inclusion was the cause of the assertion failure that led to
    the compiler abort.

    Improve the existing debugging infrastructure to help find bugs like this,
    by printing out what the selected procedure's body looks like before
    as well as after the initial requantification.

compiler/quantification.m:
    Replace from_ground_term_construct scopes whose ground term is assigned
    to a dead variable with empty conjunctions, so that the compiler passes
    between the first quantification after mode checking and the liveness
    pass also see a smaller HLDS.

    Implement an unrelated improvement whose possibility I discovered when
    investigating why a version of the test case *without* the from_ground_term
    scope wasn't getting the abort. When processing unifications, build up the
    set of variables in the unification directly, not by recording a bunch
    of maybe(somethings)s and then processing the somethings, if they existed,
    later. This yields code that is shorter, simpler *and* faster.

tests/valid/liveness_disagree.m:
    A new test case for this bug. It is a cut-down version of
    generate_missing_start_section_warning_int.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
    Enable the new test case, and try to compile it in a declarative debugging
    grade.

compiler/assertion.m:
compiler/deep_profiling.m:
compiler/lookup_switch.m:
compiler/par_loop_control.m:
    Add module qualifications in several places. I found the need for these
    when I temporarily redefined the set_of_var type to use sets instead of
    sparse_bitsets, to make debugging the bug in liveness.m easier; without
    them, I got errors about excessive overloading.

    Do some other cleanups as well.

tests/debugger/all_solutions.exp4:
tests/debugger/exception_cmd.exp3:
tests/debugger/loopcheck.exp3:
tests/debugger/uci_index.exp2:
tests/declarative_debugger/Mmakefile:
tests/declarative_debugger/builtin_call_rep.exp:
tests/declarative_debugger/catch_retry.exp:
tests/declarative_debugger/condition_bug.exp:
tests/declarative_debugger/find_origin.exp3:
tests/declarative_debugger/lpe_example.exp3:
tests/declarative_debugger/priv_builtin_bug.exp:
tests/declarative_debugger/solns.exp3:
tests/declarative_debugger/sort.exp:
tests/declarative_debugger/track_through_catch.exp:
tests/declarative_debugger/typed_unify.exp:
    Update all these expected outputs for the changes in line numbers
    caused by my cleanups of the test cases early in 2015.

    For the declarative_debugger/{condition_bug,sort} test cases, also
    update them for the change to print the types and values of foreign types.

tests/hard_coded/type_qual.{m,exp}:
    This test case failed for an earlier version of this diff, so add some
    context to its outputs, to make such failures easier to debug.
    To make *that* easier, bring it to date in programming style.
2015-08-29 13:07:01 +10:00
Zoltan Somogyi
e0cdfc2fe2 Make the tests really work in parallel.
There was a bug that prevented the tests in each directory from being run
in parallel, even when the mmake was invoked with e.g. -j4. The bug
was the absence of a '+' on an action that invoked tests/run_one_test.
Without that +, the make process inside the "mmake -j4 runtests_local"
command issued by bootcheck screwed up its connection with the recursive
make invoked by run_one_test, and apparently decided to stop using
parallelism. It was telling us this all this time but its messages,
which looked like this:

    make[2]: warning: -jN forced in submake: disabling jobserver mode.

were lost in the sea of other bootcheck output until my recent change
to run_one_test.

A single-character change fixes the bug; the rest of this big change is
dealing with the consequences of fixing the bug. Many test cases in
the hard_coded and valid directories contain nested modules, which
need to be compiled sequentially.

tests/Mmake.common:
    Fix the bug.

    Delete the duplicate "ALL TESTS SUCCEEDED" message from the runtests
    target, since the runtests_local target already prints a message
    to that effect. Make this message more emphatic.

tests/run_one_test:
    Make the output a bit easier to understand.

tests/hard_coded/*.{m,exp}:
tests/submodules/*.{m,exp}:
    Move the source files and expected output files of the test cases that
    use nested modules from hard_coded to submodules, since most of the tests
    in the hard_coded can be done in parallel, while the ones in submodules
    are already done in sequence.

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
tests/submodules/Mmakefile:
tests/submodules/Mercury.options:
    Move the Mmakefile and Mercury.options entries of the moved test cases
    from hard_coded to submodules.

tests/valid_seq:
    A new test directory, to hold the test cases originally in tests/valid
    that contain nested modules. Moving these to a new directory, which
    forces -j1, allows us to execute the remaining ones in parallel.

tests/valid/*.m:
tests/valid_seq/*.m:
    Move the source files of the test cases that use nested modules
    from valid to valid_seq.

    In a few cases, clean up the test cases a bit.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
tests/valid_seq/Mmakefile:
tests/valid_seq/Mercury.options:
tests/valid/Mmake.valid.common:
    Add valid_seq/Mmakefile to list the test cases now in valid_seq,
    and add valid_seq/Mercury.options to hold their option values.
    Delete the entries of those tests from valid/Mmakefile, and their option
    values from valid/Mercury.options. Unlike valid/Mmakefile,
    valid_seq/Mmakefile forces -j1.

    To avoid unnecessary duplication between the two Makefiles, put
    all the rules that both need into valid/Mmake.valid.common, and
    include this in both Mmakefiles.

tests/string_format/Mmakefile:
    Force -j1, since these tests share a library module.

tests/Mmakefile:
    List the new valid_seq directory among the others.

tests/bootcheck:
    Execute the tests in the new valid_seq directory as well as the others.

    Record when the execution of the test suite is started.

    Comment out invocations of set -x, since they add no useful information
    in the vast majority of cases. The comment sign can be removed if and
    when the information *would* be useful.

    Don't try to copy a nonexistent file. (The error message about this
    was also lost in the noise.)
2015-08-26 01:01:54 +10:00
Zoltan Somogyi
43fffc2395 Make hlc grades find MR_nth_code_unit and MR_offset_streq.
runtime/mercury.h
    As above. This fixes Mantis bug #380.

    Convert this module to four-space indentation.

tests/valid/bug380.m:
    Peter's test case for the bug.

tests/valid/Mmakefile:
    Enable the new test case.
2015-02-27 21:45:17 +11:00
Zoltan Somogyi
73f0a36719 Allow the use of -jN in many test directories.
tests/Mmake.common:
    Replace the -j1 in the runtests_local target used by all the test
    directories with $(MAYBE_J1).

tests/*/Mmakefile:
    Define MAYBE_J1 it as the empty string in test directories in which
    different tests don't share source files.

    Define MAYBE_J1 as -j1 in test directories in which
    different tests do share source files.

tests/submodules/sub2_a.m:
    Add this copy of sub_a.m to allow tests in the submodules directory
    to be done in parallel.

tests/submodules/accessibility2.m:
    Import sub2_a.m instead of sub_a.m.

tests/warnings/ambig_types_high_level.m:
    Add this copy of ambig_types.m to allow tests in the warnings directory
    to be done in parallel.

tests/warnings/ambig_high_level.m:
    Import ambig_types_high_level.m instead of ambig_types.m.
2015-02-19 06:02:45 +11:00
Zoltan Somogyi
3f11ad2183 generate dummy table stats and reset preds for non-tabling backends.
This fixes Mantis bug #368.

compiler/add_pragma_tabling.m:
    On backends that don't support tabling, generate the declarations
    for table statistics and reset predicates as usual if the tabling memo
    requests them, but make the definition a dummy definition. Dummy
    statistics predicates return statistics full of zeros, while dummy
    reset predicates do nothing.

compiler/add_pragma_tabling.m:
    Pass the qual_info now needed by add_pragma_tabling.m.

library/table_statistics.m:
    Add a predicate to return dummy statistics.

    Switch from error/1 to unexpected/3.

mdbcomp/sym_name.m:
    Add a utility predicate for converting a sym_name to a term, since
    add_pragma_tabling.m now needs this.

    Make the order of predicate definitions match the order of predicate
    declarations.

tests/valid/table_aux_preds_erlang.m:
    New test case to test for the presence of the bug.

tests/valid/Mmakefile:
    Enable the new test case.
2015-02-05 23:08:46 +11:00