Commit Graph

542 Commits

Author SHA1 Message Date
Zoltan Somogyi
c8aabea968 Fix a bug in LLDS codegen's handling of builtins.
compiler/call_gen.m:
    When a builtin generates an output that the rest of the computation
    ignores, don't update the state of the output variable(s), because
    the presence of a state for a variable that shouldn't exist
    can cause a compiler abort later.

compiler/code_gen.m:
    Pass the needed info to call_gen.m.

tests/valid/dead_get_io_state.m:
    A new test case for this bug, whose module comment explains
    the chain of events leading to the compiler abort.

tests/valid/Mmakefile:
    Enable the new test case.
2023-10-06 10:25:57 +11:00
Zoltan Somogyi
769412bec5 Attempt to fix a test failure in C# grades ...
... and make the set of test cases in the valid/valid_seq test directories
easier to handle.

tests/valid_seq/call_impure_in_opt_helper_1.m:
    Add a C# definition for a predicate that is defined entirely
    by foreign_procs.

tests/valid/Mmake.valid.common:
    Note the reason why many of the test cases using this file fail
    when executed in C# grades.

    Add a target that I used to debug that problem.

    Put the descriptions of a set of make variables in lexicographic order,
    except for OTHER_PROGS, which has to stay at thee end as it means
    "none of the above". Without this reordering, it was not clear that
    the cause of the failures was NOT a mistake in the spelling of
    one of these variable names.

tests/valid/Mmakefile:
tests/valid_seq/Mmakefile:
    Put the definitions of those make variables in the same order.

tests/Mmake.common:
    Improve programming style.
2023-10-02 19:01:03 +11:00
Zoltan Somogyi
a0d6710407 Use "ts=4 sw=4 expandtab" as modeline ...
... in Mercury.options files.
2023-09-16 19:12:52 +10:00
Zoltan Somogyi
a6c7a5d245 Rename X's aux modules as X_helper_N in valid. 2023-09-16 14:19:42 +10:00
Zoltan Somogyi
f6c0835246 Move tests/valid/empty_submodule.m to valid_seq.
It contains a submodule, and parallel mmake can cause spurious failures.
2023-09-08 12:19:53 +10:00
Zoltan Somogyi
783f4b2be4 Fix singleton warnings for code with 'some [...]' goals.
The code in make_hlds_warn.m that is intended to generate singleton warnings
hasn't ever been able to handle code containing 'some [...]' goals properly.
The reason is that

- add_clause.m invokes make_hlds_warn.m only *after* it does quantification
  on the body of the clause being added to the HLDS, but

- quantification has always replaced all lists of quantified variables
  with the empty list.

This meant that

- we never could report code in which the only occurrence of a variable
  was in a list of quantified variables, which is something we *should*
  warn about, and

- we always did generate a singleton warning for code such as
  "some [Val] map.search(Map, Key, Val)", which is something we *should not*
  warn about.

This diff fixes this problem.

The main change is a mechanism that allows us to tell quantification.m
to keep lists of quantified variables intact. However, since the rest
of the compiler does not react well to these lists not being empty,
this diff

- gets make_hlds_warn.m to report whether the clause body goal, in which
  quantification.m was told to preserve any lists of quantified variables,
  *actually contained* any nonempty lists of quantified variables, and

- if it did, then we invoke quantification.m again, this time telling it
  to nuke all lists of quantified variables.

This nuking has to be done relatively rarely, because only a very small
fraction of clauses contain any explicit quantification.

(An alternative design would be for make_hlds_warn.m to always nuke
any nonempty list of quantified variables it traversed. However, this would
require *always* rebuilding the clause body goal, which would probably
be slower on average.)

The above is the main change in this diff. However, the change that is
responsible for the bulk of the diff is the addition of a flag to
exist_quant scopes to specify whether that scope was created by the user
or by the compiler. This is needed because if make_hlds_warn.m sees code
such as "some [Val] map.search(Map, Key, Val)", it definitely *should*
generate a warning about Val being singleton (if it does not occur outside
this code) if the "some [Val]" scope was put there by the compiler.

compiler/make_hlds_warn.m:
    Treat user-generated exist_quant scopes as before (the old code did
    the right thing to generate warnings, it was just given wrong inputs).
    Treat compiler-generated exist_quant scopes as if they weren't there,
    for warning-generating purposes.

    To make this distinction possible, use separate code to handle
    exist_quant and promise_solutions scopes.

    Record whether the goal traversal has seen any nonempty lists of quantified
    variables, and return this info to the caller in add_clause.m.

    Encode the nonempty nature of a list in the argument structure of a
    predicate.

    Update some obsolete terminology in variable and field names.

    Clarify the logic of some code.

compiler/quantification.m:
    Add the keep_quant/do_not_keep_quant switch described above.

    Add some documentation of the predicates to which it is applicable.

    Add free_goal_expr_vars, a version of free_goal_vars that takes
    only a goal expr, without the goal info. At one point, I thought
    this diff needed it. It does not, so the new function is not used,
    but there is also not much point in deleting it, Simplify the code
    of free_goal_vars, deleting one of its callees after inlining it
    at its only call site.

    Replace a appended-to-at-the-front-and-then-reversed list with a cord.

compiler/hlds_goal.m:
    Add the created-by-user-or-compiler flag to exist_quant scopes.

compiler/add_clause.m:
    Move the code that invokes make_hlds_warn.m to warn about singletons
    into the clauses_info_add_clause predicate, whose subcontractor
    add_clause_transform does the initial quantification. The reason
    for this move is that we have never generated singleton variable warnings
    for clauses that were read in from .opt files, or for clauses which are
    known to have syntax errors. With the new setup, if we such clauses,
    clauses_info_add_clause can, and does, tell add_clause_transform
    to tell quantification.m to nuke lists of quantified variable
    right away. It is only for the clauses we *can* warn about
    that clauses_info_add_clause will tell add_clause_transform
    to keep those variables, and will then itself invoke the code
    in make_hlds_warn.m that warns about singletons, followed, if needed,
    by a var-list-nuking reinvocation of quantification.

    This centralization of the code relevant to warning code in
    clauses_info_add_clause also allows the deletion of several of its
    output arguments, since its two callers used those arguments
    only to invoke the warning-generation code. It also eliminates
    the duplication of code in those two callers.

compiler/instance_method_clauses.m:
    Conform to the change in add_clause.m.

compiler/add_foreign_proc.m:
compiler/assertion.m:
compiler/constraint.m:
compiler/cse_detection.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/format_call.m:
compiler/goal_expr_to_goal.m:
compiler/goal_util.m:
compiler/hlds_desc.m:
compiler/hlds_out_goal.m:
compiler/interval.m:
compiler/lambda.m:
compiler/mark_tail_calls.m:
compiler/ml_code_gen.m:
compiler/mode_constraints.m:
compiler/modecheck_goal.m:
compiler/polymorphism_goal.m:
compiler/pre_quantification.m:
compiler/purity.m:
compiler/saved_vars.m:
compiler/simplify_goal_scope.m:
compiler/simplify_proc.m:
compiler/state_var.m:
compiler/stm_expand.m:
compiler/superhomogeneous.m:
compiler/switch_detection.m:
compiler/try_expand.m:
compiler/typecheck.m:
compiler/unique_modes.m:
    Conform to the change in hlds_goal.m and/or quantification.m.

compiler/options.m:
    Add a way to detect the presence of this fix in the installed compiler.

tests/valid/Mmakefile:
    Enable the old test case for this problem, some_singleton,
    which we haven't passed until now.

tests/warnings/Mmakefile:
    Enable the missing_singleton_warning test case, which we haven't passed
    until now.
2023-06-10 09:59:00 +02:00
Julien Fischer
2a366cf295 Deprecate --no-ansi and --no-ansi-c.
--no-ansi (mgnuc) and --no-ansi-c (mmc) have not actually done anything for
many years now. Deprecate these options and remove their "use" throughout most
of the Mercury system. (The remaining uses are in the Makefiles for the Boehm
GC, which need to be updated separately.)

Also deprecate the internal compiler option --cflags-for-ansi.

compiler/options.m:
    Document that --no-ansi-c is now deprecated.

    Document that the internal option --cflags-for-ansi is now
    deprecated.

compiler/compile_target_code.m:
    Do not pass the ANSI options to the C compiler.

scripts/mgnuc.in:
scripts/mgnuc_file_opts.sh-subr:
    Deprecate the --no-ansi option; delete code that no longer does
    anything useful.

configure.ac:
    Delete the configuration variable CFLAGS_FOR_ANSI; it is only ever
    set to be empty. (The comment talks about --no-ansi doing other things
    in the mgnuc script. It used to also cause some preprocessor macros
    to be defined for compatibility with the system headers on some
    platforms -- that has not been the case since 2013.)

doc/user_guide.texi:
    Document that --no-ansi-c is deprecated.

bytecode/Mmakefile:
compiler/Mercury.options:
library/Mercury.options:
extras/odbc/odbc.m:
runtime/Mmakefile:
scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
tests/hard_coded/Mercury.options:
tests/valid/Mercury.options:
trace/Mmakefile:
util/Mmakefile:
    Conform to the above change.

NEWS.md:
    Announce the above.
2023-05-31 17:44:26 +10:00
Zoltan Somogyi
ec20b1ed0a Make sparse_bitset.m operate on uints.
NEWS:
    Mention all the user-visible changes below.

library/enum.m:
    Add the typeclass uenum, which is a version of the existing enum typeclass
    that maps items to uints, not ints. It also uses a semidet predicate,
    not a semidet function, to get back to the item from the uint.

library/sparse_bitset.m:
library/fat_sparse_bitset.m:
    Make these modules operate on uints, which means requiring the items
    in the sets to be instances of uenum, not enum.

    If a few places, improve loops by doing previously-repeated conversions
    of [u]ints into <offset, bit-to-set> pairs just once.

library/counter.m:
    Define ucounters, which allocate uints. Improve documentation.

library/digraph.m:
    Change digraph_keys from ints to uints, since we put them into
    sparse_bitsets.

library/int.m:
    Make int an instance of the uenum typeclass. This can help users
    who currently put ints into sparse_bitsets.

library/pprint.m:
    Prettyprint sparse_bitsets as lists of uints.

library/term.m:
    Make vars instances of uenum as well as enum.

library/uint.m:
    Make uint an instance of the uenum typeclass.

    Add the ubits_per_uint function, which allows some casts to be avoided.

compiler/make.deps_set.m:
    Change the indexes we put into sparse_bitsets from ints to uints.

compiler/make.make_info.m:
    Change the source of those indexes from ints to uints.

compiler/make.top_level.m:
compiler/make.util.m:
    Conform to the changes above.

compiler/pre_quantification.m:
    Change zones from ints to uints, since we put them into sparse_bitsets.

tests/hard_coded/int_uenum.{m,exp}:
tests/hard_coded/Mmakefile:
    Enable the new test case.

tests/valid/use_import_only_for_instance.m:
    Update this extract from library/digraph.m the same way as
    library/digraph.m itself.
2022-12-05 09:45:11 +11:00
Peter Wang
7362493e1c Skip or delete tests that fail in low-level parallel grades.
Since the compiler now refuses to allow debugging in parallel grades,
tests that require debugging need to be skipped over in low-level
parallel grades or deleted.

tests/hard_coded/Mmakefile:
    Disable 'parse' test in parallel grades as it happens to link with
    debug libraries.

tests/par_conj/Mercury.options:
tests/par_conj/Mmakefile:
tests/par_conj/par_ddeath.exp:
tests/par_conj/par_ddeath.m:
tests/par_conj/par_ddeath_2.exp:
tests/par_conj/par_ddeath_2.m:
    Delete par_ddeath and par_ddeath_2 tests that once triggered a
    compiler abort with --trace deep in parallel grades.
    I don't think there is much value in keeping them around.

tests/valid/Mmake.valid.common:
    Skip LLDS_PROGS (i.e. test cases that required debugging) in
    parallel grades.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
tests/valid/untuple_bug.m:
    Delete untuple_bug. It tests an old bug in the untupling
    transformation, which was more a programming exercise than something
    that should be used anyway.
2022-11-23 16:15:59 +11:00
Julien Fischer
40401a6b5c Fix hlc test failures with GCC 12.
GCC 12 has new warning, -Winfinite-recursion, that is being triggered by six
tests in the directory tests/valid when compiled in high-level C grades. Since
we also enable -Werror, this is causing these test to fail. Fix these failures
by either removing the infinite recursion from them or by disabling the new GCC
warning for the affected test cases.

configure.ac:
tests/DEFNS_FOR_TESTS.in:
    Define a variable whose value is the option for disabling GCC's infinite
    recursion check.

tests/valid/higher_order5.m:
tests/valid/stack_alloc.m:
    Modify these tests so they do not trigger the infinite recursion warning
    in GCC (or Mercury for that matter).

tests/valid/mode_syntax.m:
tests/valid/same_length_2.m:
    Merge these two tests (under the first name) since they both test the same
    thing.  Delete the same_length_2 version.

tests/valid/Mmakefile:
    Conform to the above deletion.

tests/valid/Mercury.options:
    Include DEFNS_FOR_TESTS here so that mmc --make can see it.

    Disable GCC's infinite recursion check for those tests that trigger
    it.

    Shut up a bunch Mercury warnings for the mode_syntax test case that
    are unrelated to what is actually being tested.
2022-07-04 11:01:13 +10:00
Julien Fischer
f3a34e4651 Replace uses of __ as a module qualifier.
samples/muz.zbstract.m:
tests/*/*.m:
    As above.
2022-04-14 20:25:10 +10:00
Zoltan Somogyi
0186a64520 Warn for unneeded use of mode-specific clauses.
compiler/add_clause.m:
    Generate a warning for mode-specific clauses when the clause is for
    a predicate that has only one mode, provided that the warning is enabled.

compiler/options.m:
    Add an option to enable this warning.

doc/user_guide.texi:
    Document this option.

library/exception.m:
library/int.m:
library/rtti_implementation.m:
library/string.m:
    Delete modes from clause heads that would get this warning.

tests/valid/spurious_purity_warning.m:
    Delete modes from clause heads that would get this warning.

    Do not interleave predicate definitions.

tests/warnings/unneeded_mode_specific_clause.{m,exp}:
    A test case for this warning.
tests/warnings/Mmakefile:
    Enable the new test case.

tests/invalid/multimode_syntax.err_exp:
    Expect the new warning.
2022-04-13 23:39:23 +10:00
Zoltan Somogyi
a31f448ecd Accept inst definitions for char.char.
compiler/mercury_compile_front_end.m:
    Invoke inst_check.m even when warn_insts_without_matching_type
    is not enabled, in order to get both

    - the errors it can generate, and
    - its canonicalization effect.

    The latter fixes Mantis bug #556.

compiler/inst_check.m:
    Document the fact that this module canonicalizes references to
    char.char to refer to the builtin type representing characters.

    Test whether warn_insts_without_matching_type is enabled before
    generating warnings for inst definitions without a "for type_ctor" clause
    that don't match any types.

    Test whether warn_insts_without_matching_type is enabled before
    generating errors for inst definitions *with* a "for type_ctor" clause
    that do not match their declared type, because the mismatch may be
    (and, in the most relevant cases, definitely is) due to a limitation
    of the current compiler.

    Generate a specific error message when an inst definition says
    it is for a user type constructor that is an equivalence type.

compiler/fact_table.m:
    Delete a now-obsolete XXX.

tests/invalid/inst_for_eqv_type.{m,err_exp}:
    A new test case to show that we report inst definitions that specify
    they are for a user-defined equivalence type.

tests/valid/inst_for_char_type.m:
    A new test case to show that we *don't* report inst definitions
    that specify they are for "char.char".

tests/invalid/Mmakefile:
tests/valid/Mmakefile:
    Enable the new test cases.
2022-04-07 12:55:38 +10:00
Zoltan Somogyi
f9fe1d5a1c Delete see/seen/tell/told from io.m.
library/io.m:
    As above. They were already marked as obsolete.

NEWS:
    Mention the change.

tests/hard_coded/remove_file.m:
tests/hard_coded/utf8_io.m:
tests/par_conj/dep_par_24.m:
tests/par_conj/dep_par_24b.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug2.m:
tests/valid/mercury_java_parser_follow_code_bug.m:
    Replace references to the deleted predicates.
2022-03-05 15:14:27 +11:00
Zoltan Somogyi
9ddb180757 Handle const_var_maps left by add_trail_ops.m.
This fixes Mantis bug #544.

The code of add_trail_ops.m can transform

    <code that adds an entry to const_var_map>

into

    (
        ...
        <code that adds an entry to const_var_map>
        ...
    ;
        ...,
        fail
    )

where the const_var_map in the MLDS code generator records which variables'
values are available as ground terms.

The MLDS code generator used to reset the const_var_map in its main data
structure, the ml_gen_info, at the end of every disjunction (actually,
at the end of every branched control structure) to the value it had
at the start. This was intended to prevent the code following the branched
structure from relying on const_var_map entries that were added to the
const_var_map on *some* branches, but not others. However, in this case,
it has the effect of forgetting the entry added by the first disjunct,
even though

- the code after the disjunction can be reached *only* via the first disjunct,
  and

- the code after the disjunction (legitimately, until add_trail_ops) depended
  on that entry being available.

The fix is to allow the code after a branched control structure to depend
on any const_var_map entry that is present in the final const_var_map
in every branch of the branched control structure whose end is reachable.

The LLDS code generator was not affected by the bug, because it uses
totally separate systems both for implementing trailing, and for keeping
track of what variables' values are available statically. In particular,
it does not rely on operations inserted and the annotations left on
unifications by the add_trail_ops and mark_static_term passes,
having been written long before either module existed.

compiler/hlds_goal.m:
    Document the update above to what may be marked static.

compiler/ml_gen_info.m:
    Document the updated protocol for handling the const_var_map field.

    Use a named type instead of its expansion.

compiler/ml_code_gen.m:
    Make the predicates that generate code for a branch in a branched
    control structure return the final const_var_maps from the branches
    whose endpoints are reachable.

    Add a predicate that computes the consensus of all the gathered
    const_var_maps.

    Compute consensus const_var_maps for if-then-elses and negations.

    Fix some inconsistencies in variable naming.

    Simplify some code.

compiler/ml_disj_gen.m:
    Compute consensus const_var_maps for disjunctions.

compiler/ml_string_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
    Compute consensus const_var_maps for various kinds of switches.

    In some predicates, put related arguments next to each other.

compiler/ml_unify_gen_construct.m:
    Delete "dynamic" from the names of several predicates that also handled
    non-dynamic construction unifications.

    Fix an out-of-date comment.

compiler/mark_static_terms:
    Fix grammar in a comment.

library/map.m:
    Fix a careless bug: when doing a merge in map.common_subset_loop,
    we threw away an entry from the wrong list in one of three cases.

    Make such bugs harder to overlook by

    - deleting the common parts from variable names, leaving the differences
      easier to see, and

    - replacing numeric suffixes for completely separate data structures
      with A and B suffixes.

tests/valid/bug544.m:
    A new test case for the bug.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
    Enable the bug, and run it with -O5.
2022-02-07 17:30:32 +11:00
Zoltan Somogyi
1b3e245ce8 Disable bug510, and document how the crash happens. 2022-01-25 22:13:16 +11:00
Zoltan Somogyi
584d856d42 Enable tests/valid/bug510.
The compiler crash this test case got when it was first added
has been fixed sometime since then.
2022-01-25 03:44:16 +11:00
Zoltan Somogyi
34438fac86 Make two torture tests slightly easier ...
... to make them pass on testing.mercurylang.org.
2022-01-15 00:14:19 +11:00
Zoltan Somogyi
638551faaa Add missing code for parsing 'promise_ex's.
compiler/parse_item.m:
    Add previously missing code for parsing promise_ex declarations
    (promise_exclusive, promise_exhaustive, and promise_exclusive_exhaustive)
    of the form ":- all [vars] promise_ex... goal."

    Comment out the code for parsing another form of such declarations,
    ":- promise_ex... goal.", which also had missing code and thus
    never worked.

    Check whether the first argument of a "some" or "all" quantifier
    is a list of variables in just one place.

compiler/status.m:
    Fix a bug in code that already had an XXX. Without this fix,
    the new test case would get a spurious error from check_promise.m.

compiler/check_promise.m:
    Fix several instances of another bug uncovered by the fix in status.m.
    The problem was that the code that checked promises in the interface
    section to see whether they contained any inappropriate references
    to predicates or data constructors defined in the implementation section
    considered, due to the bug now fixed in status.m, predicates and data
    constructors imported from other modules to be defined in the
    implementation section of this module. In fact, it did not even consider
    the question of whether the predicate or data constructor was defined
    in the current module at all.

    Fixing this requires making a choice: may promises in the interface
    refer to predicates and data constructors defined in other modules,
    or not? The language manual does not answer this question, or any
    other, about promises, since (a) all its documentation of promise
    declarations is commented out, and (b) even the commented-out prose
    is silent on references to other modules in promises.

    The fix chosen by this diff is to let a promise refer to other modules
    only if it is in the implementation section. The reason for this is that
    I would find it strange to have module A rely on a promise made by
    module B about the properties of e.g. a predicate in module C.
    While having the code of module B itself rely on a promise that
    module B itself makes about module C is not ideal, at least if the
    promise is wrong, the effect of the wrong promise will be local.
    (In a review comment, Julien pointed out that having module B make promise
    about a predicate in module C may make sense if module C was provided
    by an external entity, which may make moving the promise itself
    to module C problematic in practice.)

    Make error messages clearer via additional punctuation.

compiler/intermod.m:
    Make the result of writing out a promise look better.

compiler/parse_tree_out.m:
    Make the code writing out promises add a parentheses, without which
    we could not read the promise back in.

tests/valid/promise_ex.m:
    Add a test case for whether we can parse a promise_ex declaration.

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

tests/invalid/assert_in_interface.err_exp:
    Expect the error message we now generate for cross-module promises
    in interface sections.

tests/invalid/tricky_assert1.err_exp:
    Expect additional punctuation in an error message.
2021-12-07 17:04:03 +11:00
Zoltan Somogyi
089836c23e Fix a bug in lco.m that left vars undefined.
compiler/lco.m:
    Do not replace a plain call such as

        type_check(E, T)

    with

        LCMCpr_type_check_1(E, AddrOfT)

    which does NOT bind T, if later code in the procedure needs the value of T
    in the current stack frame.

    This fixes Mantis bug 539.

tests/valid/Mmakefile:
    Enable the bug539 test case.

tests/valid/Mercury.options:
    Do not force bug539.m to be compiled in asm_fast.gc; the bug
    is not grade dependent.
2021-10-13 18:56:10 +11:00
Zoltan Somogyi
95d04ab947 Add tests/valid/bug539.m.
Add to Peter's test case a description of the cause of the problem.
2021-10-12 02:07:22 +11:00
Zoltan Somogyi
cbb59b8364 Add bug538.m as feature request placeholder. 2021-09-13 05:44:10 +10:00
Zoltan Somogyi
10da1dcdd0 Fix nonlocal typeclass_infos in rhs_lambda_goals.
This fixes github bug #98.

compiler/polymorphism.m:
    Compiling gh98.m used to cause a compiler crash when the compiler
    tried to look up info about a typeclass_info variable that was needed
    in a call inside a lambda goal, but was not created inside the lambda goal.
    It should therefore have been listed as a nonlocal of the lambda goal,
    but it was not, because none of the variables inside the lambda goal
    had the typeclass constraint represented by that typeclass_info var
    on their types. And since later invocations of quantification may
    reduce, but may not expand, the set of nonlocals in a rhs_lambda_goal
    (as opposed to the nonlocals set of the unification whose RHS consists
    of that rhs_lambda_goal), this problem stuck.

    Fix this underestimation of the final lambda nonlocals set by including
    in it all typeinfo and/or typeclass_info vars in the updated lambda goal.
    Since this may then result in an overestimation, set a flag to force
    a requantification of the whole procedure body once its polymorphism
    transformation has been completed.

compiler/polymorphism_info.m:
    Add a flag to force requantification.

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

compiler/hlds_goal.m:
    Fix documentation of rhs_lambda_goal.

compiler/hlds_out_goal.m:
    Fix a layout problem in HLDS dumps.

compiler/hlds_pred.m:
compiler/lambda.m:
    Fix misleading variable names.

tests/valid/gh98.m:
    Add the github test case.

tests/valid/Mmakefile:
    Enable the new test case.
2021-08-20 20:05:38 +10:00
Julien Fischer
e631146960 Fix a failing test.
tests/valid/agc_ite.m:
    Avoid an ambiguity.
2021-07-28 01:32:43 +10:00
Zoltan Somogyi
c03b11ca48 Update the style of more test cases.
And updated expected outputs for changed line numbers.
2021-07-27 19:29:21 +10:00
Peter Wang
74a31ba8ef Parse and check subtype definitions.
This is the first step towards implementing a subtypes feature.
It introduces type definitions of the form

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

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

doc/reference_manual.texi:
    Add documentation for subtypes.

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

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

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

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

    Add comment for future work.

compiler/parse_type_defn.m:
    Parse subtype definitions.

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

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

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

compiler/add_type.m:
    Rename add_du_ctors_check_foreign_type_for_cur_backend to
    add_du_ctors_check_subtype_check_foreign_type.

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

compiler/make_hlds_passes.m:
    Conform to previous renaming.

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

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

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

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

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

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

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

    Add comments for future work.

tests/invalid/Mmakefile:
tests/invalid/subtype_abstract.err_exp:
tests/invalid/subtype_abstract.m:
tests/invalid/subtype_circular.err_exp:
tests/invalid/subtype_circular.m:
tests/invalid/subtype_ctor_arg.err_exp:
tests/invalid/subtype_ctor_arg.m:
tests/invalid/subtype_eqv.err_exp:
tests/invalid/subtype_eqv.m:
tests/invalid/subtype_exist_constraints.err_exp:
tests/invalid/subtype_exist_constraints.m:
tests/invalid/subtype_exist_vars.err_exp:
tests/invalid/subtype_exist_vars.m:
tests/invalid/subtype_foreign.err_exp:
tests/invalid/subtype_foreign.m:
tests/invalid/subtype_foreign_supertype.err_exp:
tests/invalid/subtype_foreign_supertype.m:
tests/invalid/subtype_foreign_supertype2.err_exp:
tests/invalid/subtype_foreign_supertype2.err_exp2:
tests/invalid/subtype_foreign_supertype2.m:
tests/invalid/subtype_ho.err_exp:
tests/invalid/subtype_ho.m:
tests/invalid/subtype_invalid_supertype.err_exp:
tests/invalid/subtype_invalid_supertype.m:
tests/invalid/subtype_not_subset.err_exp:
tests/invalid/subtype_not_subset.m:
tests/invalid/subtype_syntax.err_exp:
tests/invalid/subtype_syntax.m:
tests/invalid_submodules/Mercury.options:
tests/invalid_submodules/Mmakefile:
tests/invalid_submodules/subtype_submodule.err_exp:
tests/invalid_submodules/subtype_submodule.m:
tests/valid/Mmakefile:
tests/valid/subtype_basic.m:
    Add test cases.
2021-03-15 11:16:31 +11:00
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
Peter Wang
524f4d72e2 Delete references to Erlang backend in makefiles.
Mmake.workspace:
Mmakefile:
*/Mmakefile:
tests/*/Mmakefile:
tests/valid/Mmake.valid.common:
trace/Mmakefile:
    As above.
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
9cacd33f47 Remove "is" as a synonym for "=", step 1.
This first step deals with the consequences of such removal.
The removal itself will happen in stage 2. That step will
add "is" to the prolog module in the library.

compiler/add_pred.m:
    Prepare for "is" being in the prolog module.

compiler/options.m:
    Add a way to test whether the change to add_pred.m is in the
    installed compiler.

tests/accumulator/base.m:
tests/accumulator/call_in_base.m:
tests/accumulator/chain.m:
tests/accumulator/commutative.m:
tests/accumulator/construct_test.m:
tests/accumulator/dcg.m:
tests/accumulator/deconstruct_test.m:
tests/accumulator/disj.m:
tests/accumulator/func.m:
tests/accumulator/heuristic.m:
tests/accumulator/highorder.m:
tests/accumulator/identity.m:
tests/accumulator/inter.m:
tests/accumulator/nonrec.m:
tests/accumulator/out_to_in.m:
tests/accumulator/qsort.m:
tests/accumulator/simple.m:
tests/accumulator/split.m:
tests/accumulator/swap.m:
tests/benchmarks/cqueens.m:
tests/benchmarks/crypt.m:
tests/benchmarks/deriv.m:
tests/benchmarks/deriv2.m:
tests/benchmarks/nrev.m:
tests/benchmarks/poly.m:
tests/benchmarks/primes.m:
tests/benchmarks/qsort.m:
tests/benchmarks/query.m:
tests/benchmarks/tak.m:
tests/debugger/interactive.m:
tests/declarative_debugger/Mercury.options:
tests/declarative_debugger/io_read_bug.m:
tests/declarative_debugger/queens.exp:
tests/declarative_debugger/queens.m:
tests/dppd/imperative_solve_impl.m:
tests/dppd/map_impl.m:
tests/dppd/max_length_impl.m:
tests/dppd/sum.m:
tests/dppd/upto_sum_impl.m:
tests/par_conj/dep_par_21.m:
tests/tabling/seq.m:
tests/term/dds3_14.m:
tests/term/mmatrix.m:
tests/term/money.m:
tests/term/occur.m:
tests/term/pl4_5_2.m:
tests/term/queens.m:
tests/typeclasses/inference_test.m:
tests/typeclasses/inference_test_2.m:
tests/valid/lazy_list.m:
tests/warnings/duplicate_const.m:
    Replace calls to "is" with unifications. In many places,
    bring programming style up to date.
2020-08-21 10:42:37 +10:00
Zoltan Somogyi
58ea6ffff2 Delete old obsolete predicates and functions.
library/*.m:
    Specifically, delete any predicates and functions whose `pragma obsolete'
    dates from 2018 or before. Keep the ones that were obsoleted
    only this year or last year.

NEWS:
    Announce the changes.

tests/debugger/io_tab_goto.m:
tests/debugger/tabled_read.m:
tests/declarative_debugger/io_stream_test.m:
tests/declarative_debugger/tabled_read_decl.m:
tests/declarative_debugger/tabled_read_decl_goto.m:
tests/general/array_test.m:
tests/hard_coded/mutable_init_impure.m:
tests/hard_coded/remove_file.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug2.m:
tests/valid/mercury_java_parser_follow_code_bug.m:
    Replace references to predicates and functions that this diff deletes
    with their suggested replacements.

    In several test cases, bring the programming style up to date.

tests/hard_coded/shift_test.{m,exp}:
    Most of this test case tested the now-deleted legacy shift operations.
    Replace these with tests of their non-legacy versions, including
    testing for the expected exceptions.

tests/hard_coded/shift_test.{m,exp}:
    Don't pass --no-warn-obsolete when compiling shift_test.m anymore.
2020-08-18 11:57:47 +10:00
Zoltan Somogyi
2036a3fea4 Note that a comment is obsolete. 2020-08-10 00:56:20 +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
6d916883e6 Add a test case for a bug. 2020-06-19 17:29:29 +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
520ce39800 Delete stray references to TESTS_DIR. 2020-04-15 01:43:04 +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
Peter Wang
3621cfa650 Delete deprecated substring predicates and functions.
library/string.m:
    Delete long-deprecated substring/3 function and substring/4 predicate.
    The newly introduced `string_piece' type has a substring/3 data
    constructor which takes (start, end) offsets into the base string,
    whereas the function and predicate take (start, count) arguments.
    To reduce potential confusion, delete the deprecated function and
    predicate.

    Delete other deprecated substring predicates and functions as well.

tests/general/Mercury.options:
tests/general/string_foldl_substring.exp:
tests/general/string_foldl_substring.m:
tests/general/string_foldr_substring.exp:
tests/general/string_foldr_substring.m:
tests/hard_coded/Mercury.options:
tests/hard_coded/string_substring.m:
    Delete tests for deprecated predicates.

tests/tabling/mercury_java_parser_dead_proc_elim_bug.m:
tests/tabling/mercury_java_parser_dead_proc_elim_bug2.m:
tests/valid/mercury_java_parser_follow_code_bug.m:
    Replace calls to unsafe_substring with unsafe_between.

NEWS:
    Announce the changes.
2019-11-08 14:25:23 +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
Peter Wang
6e99abc805 Fix typo. 2019-08-20 10:29:04 +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