compiler/polymorphism.m:
Fix two bugs with higher-order predicates.
The first one was that it was optimizing
P = lambda([X::out] is nondet, p(Y, X))
^^^^^^
to
P = p(Y)
even in the case where p/2 is semidet, which is wrong.
The second one was that it computing the modes of introduced
lambda-predicates incorrectly; this caused switch_detection
to fall over with "Software error: lists of different length",
because the length of the mode list didn't match the number of
arguments.
compiler/Mmake:
Add EXTRA_MLFLAGS variable, so that you can set
EXTRA_MLFLAGS=--no-strip if you want to preserve
the debugging info.
code_util.m, polymorphism.m, hlds.m, special_pred.m:
Move the stuff dealing with special_preds from hlds.m into
a new module special_pred. Add a new predicate special_pred_get_type
to that module, and use it in code_util.m and polymorphism.m
(replacing some fairly non-maintainable hacks).
make_hlds.m, unify_proc.m:
Import special_pred.m.
quantification.m:
Make implicit quantification rename apart vars that
are local to distinct scopes. This will help in the
singleton variable warning pass once the latter has
been changed to work on the HLDS.
These changes also allow goals of the form:
.... X ....,
some [X] Goal
which were previously not allowed.
cse_detection.m:
A 1 line bugfix from Zoltan.
det_analysis.m:
Rather than redoing quantification, construct
a correct goal_info directly in det__disj_to_ite/3.
optimize.pp:
Fix a singleton variable. Zoltan, there is an
XXX for you to read and remove if the fix is
correct.
common.m, cse_detection.m, det_analysis.m,
follow_code.m, make_hlds.m, polymorphism.m,
unify_proc.m:
Fix the calls to implicitly_quantify_clause_body and
implicity_quantify_goal.
TODO:
Update a couple of things.
parser.m:
Add a map(string, var) to the state so that varset
can be simplified.
varset.m:
Simplfy the varset structure so that the binding
of names to variables is cheaper.
modes.m, mode_errors.m, mode_util.m:
Finish implementing mode checking of lambda expressions.
inst_match.m:
Mode checking of higher-order pred modes was slightly
too strict - relax it a little.
modes.m, mode_errors.m, mode_info.m:
For mode errors that occur in predicate calls,
record the argument number that they occurred in,
and print it out in mode error messages.
(This also fixes a bug where some of the determinism
error messages would say "in argument 0 of call to pred ...").
polymorphism.m:
A couple of minor simplifications.
frameopt:
Look inside blocks introduced by value numbering when looking
restorations of succip.
value_number, opt_util:
If we are using conservative garbage collection, disable value
numbering for blocks that allocate more than one cell on the heap.
This allows value numbering of most blocks to work in the absence
of -DALL_INTERIOR_POINTERS.
all other source files:
Clean up "blank" lines that nevertheless contain space or tab
characters.
This set of changes includes most of the work necessary for
mode and determinism checking of higher-order predicates.
prog_io.m:
Change the syntax for lambda expressions: they need
to have a determinism declaration. Lambda
expressions must now look like this:
lambda([X::in, Y::out] is det, ...goal...).
^^^^^^
Note that both the modes and the determinism are mandatory,
not optional.
hlds.m:
Insert a determinism field in the lambda_goal structure.
hlds_out.m, inlining.m, make_hlds.m, modes.m, polymorphism.m, quantification.m,
switch_detection.m, typecheck.m:
Modified to use lambda_goal/4 rather than lambda_goal/3.
prog_io.m:
Add a new field to the `ground' inst, of type `maybe(pred_inst_info)'.
We use this to store the modes and determinism of higher-order
predicate terms.
code_info.m, inst_match.m, mercury_to_mercury.m, mode_util.m, modes.m,
polymorphism.m, shapes.m, undef_modes.m:
Modified to handle higher-order pred modes:
use ground/2 rather than ground/1.
(Note that modes.m still requires a bit more work on this.)
llds.m:
Add a new field to the call_closure/3 instruction to hold the
caller address for use with profiling, since the C macros
require a caller address.
dup_elim.m, frame_opt.m, garbage_out.m, live_map.m, middle_rec.m, opt_debug.m,
opt_util.m, value_number.m, vn_*.m:
Modified to use call_closure/4 rather than call_closure/3.
mercury_to_mercury.m:
Export mercury_output_det for use by hlds_out.m.
Lambda expressions now work, and you can now use polymorphic predicates
as higher-order pred terms. (Mode checking and determinism checking
are still not implemented, and the modes of call/N are very restrictive.
But these change makes solutions/2 a lot more useful now.)
hlds.m:
Comment out the stuff for recording num_warnings, since it
wasn't being used. Instead we now use that slot in the
module_info for a counter which holds a number to use to
name the predicates for lambda expressions. Add a new
predicate module_info_next_lambda_count/3 to get and
increment this counter.
modes.m:
Transform higher-order pred constants into lambda expressions.
(Also, use slightly more meaningful variable names in a few places.)
polymorphism.m:
Use module_info_next_lambda_count/3 to name the predicates
created for lambda expressions.
code_util.m:
Handle __LambdaGoal__ labels correctly.
quantification.m:
Fix ANOTHER bug in quantification of lambda expressions.
hlds_out.m:
Fix minor indentation problem in output of lambda expressions.
polymorphism.m:
When a lambda expression is encountered, convert it into a
new predicate. (Works OK, with one caveat: you can currently
only have one lambda expression per program.)
make_hlds.m:
Export a couple of predicates so that polymorphism.m can use
them when it is creating new predicates for lambda expressions.
modes.m:
Fix a problem with quantification of lambda goals.
Add some code to convert higher order predicate calls into
lambda expressions so that they get mode checked and
polymorphism-processed properly. (Unfinished, code
commented out.)
hlds.m:
Simplify the code for goal_info__remove_feature.
polymorphism.m:
Optimize calls to special predicates compare/3 and index/2
for which the type is known at compile time: generate a
direct call to the special predicate for that type, rather
than generating code to create a type_info and then call
the general version to dispatch on the type_info.
hlds.m, make_hlds.m:
A couple of minor changes as part of above change.
-------------------------------------------------------
Implement unique modes. We do not handle local aliasing yet, so this
is still not very useful, except for io__state. Destructive update is
not yet implemented. Also note that this really only implements
"mostly unique" variables that may be non-unique on backtracking - we
don't check that you don't backtrack over I/O, for example.
prog_io.m, mode_util.m, modes.m, inst_match.m:
Major changes to Handle unique modes.
mercury_to_mercury.m, polymorphism.m, prog_out.m, undef_modes.m:
Use `ground(Uniqueness)' rather than just `ground'.
compiler/*.m:
Fix compile errors now that unique modes are enforced: add a
few calls to copy/2, and comment out lots of unique mode
declarations that caused problems.
typecheck.m, mode_info.m:
Hack around the use of unique modes, which doesn't work
because we don't allow local aliasing yet: make the insts
`uniq_type_info' and `uniq_mode_info' not unique at all,
and add a call to copy/2 when extracting the io_state from
type_info or mode_info.
-------------------------------------------------------
Plus a couple of unrelated changes:
hlds.m:
Change the modes for the special predicates from `ground -> ground'
to `in', so that any error messages that show those modes
come out looking nicer.
Add a new shared_inst_table for shared versions of user-defined
insts.
mercury_to_goedel.m:
Use string__is_alnum_or_underscore.
context of the unification from which call was made. We we use this to generate
significantly better error messages. (There should be no more messages of the
form "call to __Unify__(blah blah blah) can fail".) Most of the files are
changed just to reflect this.
An unrelated change in det_analysis is that we now ensure the absence of
cycles by modifying the new inferred determinism in the light of the old
one, ensuring that any changes are monotonic.
In hlds_out, inhibit the printing of pseudo-imported predicates (unifications)
since nobody cares about them except sometimes Fergus.
unifications. See the comments at the top of unify_proc.m for
details of how it's done.
hlds.m:
Add new export statuses `pseudo_imported' and `pseudo_exported'
to handle unification predicates, which can now have complicated
modes.
code_gen.pp, code_info.m, common.m, constraint.m, cse_detection.m,
follow_code.m, follow_vars.m, hlds_out.m, inlining.m, live_vars,
make_hlds.m, mercury_compile.pp, modes.m, store_alloc.m,
switch_detection.m:
Handle pseudo_imported predicates.
modes.m, constraint.m:
Change modecheck to return an updated module_info, since
modechecking may insert new entries into the unify_requests
queue in the module_info. Make sure that modechecking
never inserts requests into the unify_requests queue
for code that has mode errors (or needs rescheduling).
call_gen.m, polymorphism.m:
Move duplicated code into unify_proc.m.
clause_to_proc.m:
Add new predicate clauses_to_proc for use by unify_proc.m.
unify_proc.m:
Implement complicated unifications with complicated modes.
hlds.m and lots of other files:
Change the type of the first two arguments of unify/5 in
hlds__goal_expr from `term, term' to `var, unify_rhs'
where unify_rhs is given by
:- type unify_rhs
---> var(var)
; functor(const, list(var))
; lambda_goal(list(var), hlds__goal).
This change was for two reasons: firstly, it simplifies the
code in a lot of places, and secondly, it is a step towards
implementing lambda closures and higher-order predicates
properly.
modes.m, typecheck.m, code_util.m:
Don't report a compile error if there is a higher-order pred
unification in a compiler-generated predicate. (Instead, delay
the error until run-time so that it only occurs if the higher-order
pred unification in question actually gets executed.)
compiler/Mmake:
Include the library .m files in the tags file.
hlds.m and lots of other places:
Change the type of the argument list of a HLDS `call' from
`list(term)' to `list(var)'.
compiler/*:
Add copyright messages.
Change all occurences of *.nl in comments to *.m.
compiler/mercury_compile.pp:
Change the output to the .dep files to use *.m rather than *.nl.
(NOTE: this means that `mmake' will not work any more if you
call your files *.nl!!!)
code_util.nl, float.nl, llds.nl, mercury_builtin.nl, opt_debug.nl,
parser.nl, polymorphism.nl, sp_lib.nl, string.nl, string.nu.nl,
type_util.nl, typecheck.nl, unify_gen.nl:
Implement floating point.
Makefile.common:
Remove `-include test.dep' line. Use Mmake.
int.nl:
Update a few of the comments.
io.nu.nl:
For Sicstus Prolog, if main/2 is not defined then enter the
debugger.
list.nl:
reimplement remove_dups so that it works for unsorted lists.
XXX the call in sort should be to a specialized version since
for unsorted lists the current implementation is O(NlogN).
polymorphism.nl:
Fix the places where it was sorting a list of variables to
remove duplicates. Now it just removes duplicates without
sorting. This means that polymorphism works irrespective
of the given set of variable numbers. :-)
( fjh says 'd'oh' at this stage )
code_info.nl hlds.nl hlds_out.nl io.nl llds.int llds.nl opt_debug.nl
polymorphism.nl shapes.nl switch_gen.nl unify_gen.nl:
The fields in a `type_info' structure should be just
procedure addresses, not closures.
polymorphism.nl, mercury_builtin.nl:
Change the definition of the type_info functor in mercury_builtin
from type_info/1 to type_info/0, so that it gets the right sort
of tag.
Makefile.common:
Add new targets `mercury_compile.sicstus' (the Mercury compiler
compiled with Sicstus) and `mercury_compile.sicstus.debug'
(debugging version of the above).
*.nl:
Use Sicstus-compatible char and string escapes.
Avoid the use of explicit existential quantification.
Various other hacks to get things to parse correctly under Sicstus.
prog_io.nl:
Don't allow (A -> B) in DCGs, since NU-Prolog and Mercury give
it different semantics to Sicstus.
sp_builtin.nl, sp_lib.nl:
Split sp_builtin.nl into sp_builtin.nl and sp_lib.nl.
sp_conv.sed:
Add sed script which converts some character escapes so that
they work with Sicstus.
term_io.nl:
Remove term_io__prefix_op etc. since they aren't used anymore.
Makefile.common:
Various minor bugfixes.
Makefile.mercury:
Add rules for creating assembler (.s) files.
term.nl, *.nl:
Replace term__context_init/1 with term__context_init/0.
The first argument was always zero anyway.
io.nl:
Change the interface to io__read_char and io__read_line so that
they return a better error indicator.
Add a new predicate io__putback_char.
polymorphism.nl:
Don't abort if a predicate doesn't have any modes.
options.nl:
Let's try turning polymorphism on again. It seems to work this time.
string.nl, string.nu.nl:
Add string__to_float.
Move implementation of string__to_int from string.nl to string.nu.nl.
code_util.nl:
Fix bug in make_proc_label: for unification predicates,
look at the _last_ argument to determine the type for
name mangling, not the first, since we introduce extra
higher-order arguments at the start.
make_hlds.nl, hlds.nl:
Ensure that the proc_info head_vars has the right length even for
imported predicates. This fixes a problem with --polymorphism.
make_hlds, unify_proc.nl, prog_util.nl:
Output unification procedures for equivalence types.
polymorphism.nl:
Ensure that this works even for unification procedures for
equivalence types, which are a bit wierd since they are not
quite type correct.
typecheck.nl:
Don't attempt to typecheck unification predicates, since
they are already type-correct when we construct them.
In particular don't typecheck unification procedures for
equivalence types, since it would report a spurious error.
mercury_to_mercury.nl:
Remove a superfluous duplicate clause.
Makefile.common:
Add some targets for compiling the compiler and the library.
type_util.nl, dense_switch.nl, switch_gen.nl, polymorphism.nl:
Rename inttype, chartype, etc. as int_type, char_type, etc.
Add polymorphic_type.
modes.nl, mode_errors.nl:
Report an error for direct attempts to unify higher-order pred types.
(Of course, we don't catch indirect attempts via polymorphic types -
that would require global analysis. For them, we report the error
at runtime.)
modes.nl:
Remove unreachable code from conjuctions.
(XXX also should do this for if-then-else.)
options.nl:
Turn -p off by default. I'll turn it on again when it works ;-)
polymorphism.nl, mercury_builtin.nl:
Generate sensible code in the case were we take the address
of the unification predicate for a builtin or enumeration type.
hlds.nl code_info.nl hlds.int hlds_out.nl polymorphism.nl:
Create a new cons_id `pred_const(pred_id, proc_id)',
to avoid ambiguities with the old use of
`cons_id(name, arity)'.
code_util.nl, polymorphism.nl, mercury_builtin.nl:
Change things so that only call/1 is builtin.
For call/N, we can implement them by hand in mercury_builtin.nl.
(Procedure call overhead is the least of our worries right now.)
Note that call/N still only works in the following mode.
:- call (in, in, ..., in) is semidet.
You can't use it to call det predicates.
polymorphism.nl:
Handle polymorphic unifications (finally!)
Give some of the introduced variables meaningful names.
Don't insert additional arguments for polymorphic builtins
(currently the only polymorphic builtin is call/N.)
polymorphism.nl, hlds.nl, typecheck.nl:
Store two typevarsets in the pred_info rather than just one.
The first one holds the typevarset for the arguments only,
the second also includes any local type variables occuring
in the bodies of any of the procedures for that predicate.
This solves a performance problem with polymorphism.nl.
polymorphism.nl:
Fix some bugs:
- I had forgotten to update the argmodes of the modified
procedures
- I was updating the argtypes and attempting to use there
old value. I fixed this by splitting the algorithm
into two passes.
- to compute the types of the arguments to a call,
apply the type mapping from the _caller_ not the callee.
Also improve efficiency in a couple of places.
hlds.nl:
Add some new access predicates required by polymorphism.nl.
list.nl:
Add a new predicate list__duplicate, which is used by polymorphism.nl.
typecheck.nl, type_util.nl:
Move the type_unify routines from typecheck.nl into type_util.nl,
since they're also needed by polymorphism.nl.
term.nl:
Export term__apply_rec_substitution_to_list, since it's needed
by polymorphism.nl.
- - - - - - - - - - - - - - - - - - - - - - - - -
mode_util.nl, type_util.nl:
Move some routines from mode_util.nl to type_util.nl, where they
really belong.
- - - - - - - - - - - - - - - - - - - - - - - - -
make_hlds.nl, code_util.nl, typecheck.nl:
Mark builtin predicates as "external" in make_hlds.nl,
rather than checking for them as a special case in typecheck.nl.
- - - - - - - - - - - - - - - - - - - - - - - - -
prog_io.nl, hlds.nl, typecheck.nl:
For documentation purposes, define equivalent types `tvar',
`tvarset', `tsubst' for type variables, type varsets, and
type substitutions.
- - - - - - - - - - - - - - - - - - - - - - - - -
mercury_compile.pp, options.nl:
Change the handling of the --dump-hlds option so that you can
now dump the HLDS after any of the 12 HLDS transformation passes.
- - - - - - - - - - - - - - - - - - - - - - - - -
make_hlds.nl:
Report an error if there are clauses for an imported predicate.
- - - - - - - - - - - - - - - - - - - - - - - - -
io.nu.nl:
Add a new predicate r/1 which is like run/1 except that
you pass it a string rather than a list of atoms.
So now you can do
$ mercury_compile.debug
Mercury Interpreter 0.1
NU-Prolog 1.6.4
1?- r("mc -options blah blah blah").
polymorphism.nl:
New module which does a syntactic tranformation of the HLDS
to implement polymorphic unifications by passing higher-order
unification predicates.
Still very unfinished (lots of syntax errors, etc. :-).