compiler/common.m:
The code that tries to optimize X = f(...) into X = Y if Y already
contains f(...) used to insist on the X = f(...) construction unification
being marked as a dynamic unification, i.e. one that constructs a term
on the heap on each invocation. This was part of the fix of Mantis bug
#493, which affected only the MLDS code generator, but for LLDS backend,
in the presence of --loop-invariants, it prevented a constant propagation
optimization that we had a test for (tests/hard_coded/constant_prop_2).
So make both backends happy by insisting on construct_dynamically
only for the MLDS backend.
compiler/simplify_info.m:
Record for common.m whether the backend we are targeting pays
any attention to whether a cell is construct_dynamically.
Replace some bools with bespoke types, to eliminate the risk of confusion.
compiler/hlds_goal.m:
For each construction unification marked construct_statically, record
whether the term was "born static" by being created as a static term
by a compiler pass, or whether it is a user-written unification that was
"marked static" by mark_static_terms.m. Document the meaning of both.
(I originally thought this distinction would be useful in the bug fix,
but it turned out not to be.)
compiler/deep_profiling.m:
compiler/dep_par_conj.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/polymorphism.m:
compiler/polymorphism_type_info.m:
Record compiler-generated static terms as born static.
compiler/mark_static_terms.m:
Mark discovered-to-be-static terms as marked static.
compiler/hlds_out_goal.m:
compiler/interval.m:
compiler/liveness.m:
compiler/loop_inv.m:
compiler/ml_unify_gen_construct.m:
compiler/quantification.m:
compiler/rbmm.add_rbmm_goal_infos.m:
compiler/simplify_goal.m:
compiler/simplify_goal_conj.m:
compiler/simplify_goal_disj.m:
compiler/simplify_goal_scope.m:
compiler/structure_reuse.indirect.m:
compiler/structure_reuse.versions.m:
compiler/unify_gen_construct.m:
compiler/var_locn.m:
Conform to the changes above.
tests/hard_coded/constant_prop_loop_inv.{m,exp}:
A new test case. It contains the part of the constant_prop_2 test case
that used to fail in LLDS grades with --loop-invariants.
tests/hard_coded/Mercury.options:
Specify --loop-invariants for the new test case, even if it is not
specified for constant_prop_2.
tests/hard_coded/Mmakefile:
Enable the new test case.
tests/hard_coded/constant_prop_2.m:
Fix programming style.
compiler/const_prop.m:
Extend this module to support compile time evaluation of uint operations.
compiler/uint_emu.m:
A new module that emulates `uint' operations for the bits-per-uint in
a manner similar to the int_emu module.
compiler/libs.m:
Include the new module.
tests/hard_coded/constant_prop_1.{m,exp}:
tests/hard_coded/constant_prop_2.{m,exp}:
Test compile time evaluation of uint operations.
Update coding style in these tests.
tests/hard_coded/Mmakefile:
Conform to the above changes. (XXX the existing check
for the Java grade doesn't actually work.)
Delete left over IL and GCC backend stuff.
compiler/parse_item.m:
Don't accept `:- external' items.
compiler/prog_item.m:
Require the presence of a pred_or_func flag on external pragmas.
They are specified by `:- pragma external_{pred/func}' pragmas,
which are still supported.
compiler/parse_pragma.m:
When parsing external_{pred/func} pragmas, allow the predicate name
to contain a module qualifier; they were allowed on `:- external' items.
We do require the module qualifier to specify the expected (i.e. the
current) module.
compiler/add_pragma.m:
compiler/parse_tree_out_pragma.m:
compiler/recompilation.version.m:
Conform to the changes above.
tests/hard_coded/backend_external.m:
tests/hard_coded/constant_prop_2.m:
tests/invalid/external.err_exp:
tests/invalid/external.m:
tests/invalid/io_in_ite_cond.err_exp:
tests/invalid/io_in_ite_cond.m:
tests/invalid/overloading.m:
tests/invalid/tricky_assert1.m:
tests/invalid/type_spec.err_exp:
tests/invalid/type_spec.m:
tests/invalid/uniq_neg.err_exp:
tests/invalid/uniq_neg.m:
tests/valid/dcg_test.m:
tests/valid/inst_perf_bug_1.m:
tests/valid/lambda_recompute.m:
tests/valid/semidet_disj.m:
tests/valid/solv.m:
tests/valid/solver_type_bug.m:
tests/valid/stack_alloc.m:
tests/valid/tricky_assert2.m:
Replace `:- external' items with external_{pred/func} pragmas.
Modernize the code where needed, replacing DCGs with state variables.
tests/accumulator/*.m:
tests/analysis_*/*.m:
tests/benchmarks*/*.m:
tests/debugger*/*.{m,exp,inp}:
tests/declarative_debugger*/*.{m,exp,inp}:
tests/dppd*/*.m:
tests/exceptions*/*.m:
tests/general*/*.m:
tests/grade_subdirs*/*.m:
tests/hard_coded*/*.m:
Make these tests use four-space indentation, and ensure that
each module is imported on its own line. (I intend to use the latter
to figure out which subdirectories' tests can be executed in parallel.)
These changes usually move code to different lines. For the debugger tests,
specify the new line numbers in .inp files and expect them in .exp files.
Estimated hours taken: 4
Branches: main
Move the all-solutions predicates from the library module std_util into their
own module, solutions.
Move semidet_fail, semidet_succeed, cc_multi_equal and dynamic cast from
std_util.m into builtin.m.
Add some more utility functions for performing determinism or purity casts.
(The later are primarily intended for use by solver implementors.)
library/std_util.m:
Move the all-solutions predicates into their own module, solutions.m.
For now there are (obsolete) forwarding predicates from this module to
the new one. The forwarding predicates will be included in the
upcoming 0.13 release and then removed in later versions.
Move semidet_succeed, semidet_fail, cc_multi_equal and dynamic_cast
to builtin.m
library/solutions.m:
New file. This is the new home for the all-solutions predicates.
This is pretty much cut and pasted from std_util (with module
qualifiers updated accordingly). I've rearranged the code in a more
top-down fashion as per our current coding standard.
library/builtin.m:
Move semidet_fail/0, semidet_succeed/0, cc_multi_equal/2 and
dynamic_cast/2 to this module.
Add semidet_true/0 and semidet_false/0 as synonyms for semidet_fail/0
and semidet_succeed/0.
Add impure_true/0 and semipure_true/0. These are useful for performing
purity casts, e.g. in solver implementations.
library/library.m:
Add the new module.
NEWS:
Announce the changes.
library/*.m:
Update to conform to the above.
compiler/const_prop.m:
Update evaluate_semidet_call/5 with the new module name for
dynamic_cast.
compiler/*.m:
Module qualify calls to solutions to either disambiguate them from the
versions in std_util (where they weren't module qualified) or change
the module qualifier where they were (to avoid warnings about calls to
the now deprecated versions).
tests/debugger/declarative/solutions.*:
Rename this module as the name conflicts with the new library module.
tests/debugger/declarative/solns.*:
Renamed version of above (with updated expected output).
tests/debugger/declarative/Mmakefile:
Handle the renamed version of the solutions test.
tests/debugger/all_solutions.m:
tests/debugger/declarative/args.m:
tests/debugger/declarative/library_forwarding.m:
tests/hard_coded/constant_prop_2.m:
tests/invalid/multisoln_func.m:
tests/invalid/one_member.m:
tests/invalid/promise_equivalent_claueses.m:
tests/valid/simplify_bug2.m:
tests/valid/solv.m:
Update to conform to the above changes.
sample/solutions/*.m:
Update to conform to the above changes.
Estimated hours taken: 4
Branches: main
Do constant propagation for calls to private_builtin.typed_unify and
std_util.dynamic_cast, i.e. evaluate them at compile time if the types
are known, and optimize the implementation of dynamic_cast.
Also clean up the code in const_prop.m.
library/std_util.m:
Implement dynamic_cast more efficiently, using typed_unify(X, Y)
rather than univ_to_type(univ(X), Y). This avoids allocating a
cell on the heap.
compiler/const_prop.m:
Keep track of the types of the arguments.
Add new code for evaluating semidet calls with one output,
and use this to evaluate calls to dynamic_cast and typed_unify.
Rename evaluate_builtin to evaluate_call, since it may evaluate
any standard library procedure, not just those which are builtin
(in the sense of pred_info_is_builtin). Likewise for its subroutines.
Various other clean-ups, e.g. combine evaluate_builtin_bi and
evaluate_builtin_tri into a single predicate evaluate_det_call,
delete unused arguments, reorder arguments so that inputs precede
outputs, use combined pred-mode declarations, and add some comments.
compiler/simplify.m:
Update to reflect the new interface to const_prop.m.
tests/hard_coded/constant_prop_2.m:
tests/hard_coded/constant_prop_2.exp:
Test that we do constant propagation for calls to typed_unify
and dynamic_cast.
Estimated hours taken: 1
Branches: main
Improve the testing of constant propagation.
tests/hard_coded/Mmakefile:
tests/hard_coded/constant_prop_1.m:
tests/hard_coded/constant_prop_1.exp:
tests/hard_coded/constant_prop_2.m:
tests/hard_coded/constant_prop_2.exp:
tests/hard_coded/Mercury.options:
Add two new tests of constant propagation.
For the first test, we test by grepping the generated target code
for the expected constants.
For the second test, we test by including a reference to an
undefined external procedure "link_error" which will get
optimized away iff the compiler does constant propagation.