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.
... 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 = .."
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.