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.
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.
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.
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.
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.
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.
compiler/add_type.m:
Generate an error message if a solver type is exported.
NEWS:
Announce the enforcement of this old rule.
tests/invalid/any_mode.err_exp:
tests/invalid/foreign_solver_type.err_exp:
Expect the new error message for exported solver types.
tests/valid/solver_type_bug.m:
To keep this test case valid, don't export the solver type it defines.
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.
compiler/options.m:
Disable the (non-user-visible) --no-special-preds option, which was
only ever used for a few experiments. Document why.
compiler/add_special_pred.m:
compiler/higher_order.m:
compiler/simplify_goal_unify.m:
compiler/special_pred.m:
compiler/type_ctor_info.m:
Simplify the code that used to have to deal with the option.
tests/valid/Mercury.options:
Don't specify the option for a test. It does not affect the test anyway.
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.
NEWS:
Announce the new strictness.
compiler/add_type.m:
Classify *every* type declaration and definition as either solver or
not solver, and insist that *all* declarations and definitions of a type
have the same classification.
Improve the error messages we generate for solver/nosolver mismatches.
Avoid using add_or_replace_type_ctor_defn; use just add_type_ctor_defn
or replace_type_ctor_defn instead.
compiler/hlds_data.m:
Delete the definition of add_or_replace_type_ctor_defn.
tests/invalid/abstract_solver_type.{m,err_exp}:
tests/invalid/foreign_solver_type.{m,err_exp}:
Two new test cases to test the new error detection capabilities.
tests/invalid/Mmakefile:
Add the new test cases.
tests/invalid/any_mode.{m,err_exp}:
Change this existing test slightly to avoid a warning that is
completely unrelated to the test's purpose. Update the line numbers
in the expected output.
tests/valid/solver_type_bug.m:
The old code of this test now gets an error message from the new code
in add_type.m. Change it to avoid this while still testing for the
absence of the code generator error it was originally created for.
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.