Estimated hours taken: 6
Branches: main
This diff changes modes.m, unique_modes.m and mode_info.m to make them easier
to read and to maintain, but contains no changes in algorithms whatsoever.
compiler/modes.m:
compiler/unique_modes.m:
compiler/mode_info.m:
Convert these modules to our current coding standards. Use state
variable notation when appropriate, reordering arguments as necessary.
Delete predicates whose only purpose was to ease programming with DCGs.
Remove the IO state from the mode_info structure, and pass it
separately to the (relatively few) predicates that need it. This
avoids using complicated (and as yet unsupported) modes or lying
to the compiler (we used to do the latter), and we are no longer
forced into that choice by being limited to a single hidden (DCG)
variable.
Use more expressive variable names and factor out code as appropriate.
compiler/*.m:
Conform to the changes in the above two modules.
Estimated hours taken: 4
Branches: main
This diff makes hlds_pred.m and many callers of its predicates easier to read
and to maintain, but contains no changes in algorithms whatsoever.
compiler/hlds_pred.m:
Bring this module into line with our current coding standards.
Use predmode declarations, functions, and state variable syntax
when appropriate.
Reorder arguments of predicates where necessary for the use of state
variable syntax, and where this improves readability.
Replace old-style lambdas with new-style lambdas or with partially
applied named procedures.
Standardize indentation.
compiler/*.m:
Conform to the changes in hlds_pred.m. This mostly means using the
new argument orders of predicates exported by hlds_pred.m. Where this
is now conveniently possible, change predicates to use state
variable notation.
In some modules, using state variable notation required changing the
orders of arguments in the module's top predicate.
compiler/passes_aux.m:
Change the order of arguments in the calls this module makes to
allow the callees to use state variable notation.
Convert this module to state variable notation too.
Estimated hours taken: 2
Branches: main
compiler/*.m:
Import only one compiler module per line. Sort the blocks of imports.
This makes it easier to merge in changes.
In a couple of places, remove unnecessary imports.
Estimated hours taken: 4
Branches: main
Improve the display of insts in mode error messages.
In particular, fully expand all compiler-defined insts;
places where recursive insts refer to themselves are printed as "...".
compiler/mode_errors.m:
Change the argument of output_inst from instvar_set to mode_info,
so that it can have access to the module_info's inst_table.
Call mercury_output_expanded_inst instead of mercury_output_inst.
compiler/mercury_to_mercury.m:
Add new procedures mercury_output_expanded_inst, for use by
mode_errors.m, and mercury_expanded_inst_to_string, for consistency
with the rest of the interface.
These procedures take an extra module_info argument.
They output the inst in a format where all compiler-defined insts
have been expanded out; recursive insts have their self-referential
parts printed out as elipses ("...").
compiler/mode_util.m:
Change strip_builtin_qualifiers_from_inst so that it handles
compiler-defined insts properly, rather than just deleting
typed_ground and typed_inst insts and ignoring the rest.
tests/invalid/merge_ground_any.err_exp:
tests/invalid/polymorphic_unification.err_exp:
Update error messages to reflect the new output.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.
compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
New files. One module for each of the major components of the
Mercury compiler. These modules contain (as separate sub-modules)
all the other modules in the Mercury compiler, except gcc.m and
mlds_to_gcc.m.
Mmakefile:
compiler/Mmakefile:
Handle the fact that the top-level module is now `top_level',
not `mercury_compile' (since `mercury_compile' is a sub-module
of `top_level').
compiler/Mmakefile:
Update settings of *FLAGS-<modulename> to use the appropriate
nested module names.
compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
Convert the `recompilation_*' modules into sub-modules of the
`recompilation' module.
compiler/*.m:
compiler/*.pp:
Module-qualify the module names in `:- module', `:- import_module',
and `:- use_module' declarations.
compiler/base_type_info.m:
compiler/base_type_layout.m:
Deleted these unused empty modules.
compiler/prog_data.m:
compiler/globals.m:
Move the `foreign_language' type from prog_data to globals.
compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
Import `globals', for `foreign_language'.
Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
Rename the %.check.c targets as %.check_hdr.c,
to avoid conflicts with compiler/recompilation.check.c.
Estimated hours taken: 8
Branches: main
Add support for using different clauses for different modes of a
predicate or function, using mode annotations on the clauses.
compiler/make_hlds.m:
Add support for mode annotations on clauses.
compiler/module_qual.m:
Add new routine qualify_clause_mode_list, for use by make_hlds.m.
compiler/mode_errors.m:
Export output_mode_decl, for use by make_hlds.m
compiler/purity.m:
Treat procedures with different clauses for different modes
as impure, unless promised pure.
compiler/notes/compiler_design.html:
Specify when module qualification of modes in
clause mode annotations is done (in make_hlds.m).
NEWS:
doc/reference_manual.texi:
Document the new feature.
Estimated hours taken: 0.25
compiler/mode_errors.m:
Fix a missing newline in an error message.
tests/invalid/Mmakefile:
tests/invalid/mode_inf.m:
tests/invalid/mode_inf.err_exp:
Add a test case to test that error message.
Estimated hours taken: 2
compiler/globals.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/transform_llds.m:
compiler/vn_order.m:
compiler/vn_verify.m:
samples/diff/globals.m:
Add missing `import_module' statements in the interface section.
(The current version of the compiler doesn't detect these errors.
I have a fix for that bug, but I plan to commit it separately.)
Estimated hours taken: 12
Change mode inference so that it supports reordering of conjunctions.
For predicates with inferred modes, if we get a mode error, we don't
report it straight away; instead, we just store the mode error(s) in
the proc_info. Any call to a procedure for which we have recorded a
mode error will itself result in a mode error, which will then
cause reordering of conjunctions as usual.
compiler/hlds_pred.m:
Add a new `mode_errors' field to the proc_info.
For predicates with inferred modes, this field records
the mode errors that we detected for that procedure.
Add a new predicate proc_info_is_invalid_mode that
succeeds iff the list of mode errors is not empty.
Change pred_info_procids and pred_info_non_imported_procids
so that they skip invalid modes. Add new predicates
pred_info_all_procids and pred_info_all_non_imported_procids
that are like those two but that do not skip invalid modes.
compiler/modes.m:
For predicates with inferred modes, if we get a mode
error, don't report it straight away; instead, just
store the mode error in the proc_info.
compiler/modecheck_call.m:
compiler/unique_modes.m:
When modechecking calls, check the mode_errors field in
the callee's proc_info, and if it is non-empty, return
a `mode_error_in_callee' mode error.
compiler/mode_errors.m:
Add a new error `mode_error_in_callee', along with code to
report such errors.
Also change `write_inference_messages', which prints out the
the "Inferred :- mode ..." messages when --infer-modes is set,
so that if `--verbose-errors' is set, it also prints out lines
of the form "Rejected :- mode ..." for each candidate mode
that we added but got a mode error for.
compiler/mode_info.m:
Add procedures `set_pred_id' and `set_proc_id'; these are used
by mode_errors.m to print out the error message for the callee
when printing messages for `mode_error_in_callee' errors.
compiler/clause_to_proc.m:
compiler/hlds_module.m:
compiler/hlds_out.m:
compiler/make_hlds.m:
compiler/termination.m:
Improve abstraction a little by using `pred_info_all_procids'
or `pred_info_procids' rather than just using `map__keys' on
the proc_table.
compiler/modes.m:
compiler/modecheck_unify.m:
compiler/modecheck_call.m:
compiler/unique_modes.m:
Change modecheck_var_has_inst_list so that it takes an extra
argument saying whether you want an exact match (rather than
an implied mode). This is needed to avoid matching implied
versions of invalid modes: when matching against an invalid
mode, we only allow exact matches; for calls that would be
implied modes of the invalid mode, we'll generate a new
inferred mode for the procedure.
Estimated hours taken: 1
Improve the error message for errors in type class instance
definitions that use the named (e.g. "pred(foo/N) is bar") syntax, as
suggested by Ralph Becket: for such procedures, just output "in bar/N"
rather than "in call to bar/N", since the user didn't write any
explicit call.
compiler/hlds_pred.m:
Add a new marker `named_class_instance_method' to the pred_marker type.
compiler/hlds_out.m:
compiler/intermod.m:
Handle the new marker.
compiler/check_typeclass.m:
For instance methods defined using the named syntax,
add the `named_class_instance_method' marker to their markers.
compiler/typecheck.m:
compiler/mode_errors.m:
Pass the pred_markers down to hlds_out__write_call_arg_id.
compiler/hlds_out.m:
Change hlds_out__write_call_arg_id so that for predicates with
the `named_class_instance_method' marker, it doesn't output the
"call to".
tests/invalid/Mmakefile:
tests/invalid/method_impl.m:
tests/invalid/method_impl.exp:
A regression test.
Estimated hours taken: 0.5
compiler/mode_errors.m:
When printing out mode inference messages,
make sure to remove the modes for the extra
type_info and type_class_info arguments inserted
by polymorphism.m.
tests/warnings/Mmakefile:
tests/warnings/inference_test.m:
tests/warnings/inference_test.exp:
Add a test case to check the type/mode/determinism
inference messages.
Estimated hours taken: 220
Aditi update syntax, type and mode checking.
Change the hlds_goal for constructions in preparation for
structure reuse to avoid making multiple conflicting changes.
compiler/hlds_goal.m:
Merge `higher_order_call' and `class_method_call' into a single
`generic_call' goal type. This also has alternatives for the
various Aditi builtins for which type declarations can't
be written.
Remove the argument types field from higher-order/class method calls.
It wasn't used often, and wasn't updated by optimizations
such as inlining. The types can be obtained from the vartypes
field of the proc_info.
Add a `lambda_eval_method' field to lambda_goals.
Add a field to constructions to identify which RL code fragment should
be used for an top-down Aditi closure.
Add fields to constructions to hold structure reuse information.
This is currently ignored -- the changes to implement structure
reuse will be committed to the alias branch.
This is included here to avoid lots of CVS conflicts caused by
changing the definition of `hlds_goal' twice.
Add a field to `some' goals to specify whether the quantification
can be removed. This is used to make it easier to ensure that
indexes are used for updates.
Add a field to lambda_goals to describe whether the modes were
guessed by the compiler and may need fixing up after typechecking
works out the argument types.
Add predicate `hlds_goal__generic_call_id' to work out a call_id
for a generic call for use in error messages.
compiler/purity.m:
compiler/post_typecheck.m:
Fill in the modes of Aditi builtin calls and closure constructions.
This needs to know which are the `aditi__state' arguments, so
it must be done after typechecking.
compiler/prog_data.m:
Added `:- type sym_name_and_arity ---> sym_name/arity'.
Add a type `lambda_eval_method', which describes how a closure
is to be executed. The alternatives are normal Mercury execution,
bottom-up execution by Aditi and top-down execution by Aditi.
compiler/prog_out.m:
Add predicate `prog_out__write_sym_name_and_arity', which
replaces duplicated inline code in a few places.
compiler/hlds_data.m:
Add a `lambda_eval_method' field to `pred_const' cons_ids and
`pred_closure_tag' cons_tags.
compiler/hlds_pred.m:
Remove type `pred_call_id', replace it with type `simple_call_id',
which combines a `pred_or_func' and a `sym_name_and_arity'.
Add a type `call_id' which describes all the different types of call,
including normal calls, higher-order and class-method calls
and Aditi builtins.
Add `aditi_top_down' to the type `marker'.
Remove `aditi_interface' from type `marker'. Interfacing to
Aditi predicates is now handled by `generic_call' hlds_goals.
Add a type `rl_exprn_id' which identifies a predicate to
be executed top-down by Aditi.
Add a `maybe(rl_exprn_id)' field to type `proc_info'.
Add predicate `adjust_func_arity' to convert between the arity
of a function to its arity as a predicate.
Add predicates `get_state_args' and `get_state_args_det' to
extract the DCG state arguments from an argument list.
Add predicate `pred_info_get_call_id' to get a `simple_call_id'
for a predicate for use in error messages.
compiler/hlds_out.m:
Write the new representation for call_ids.
Add a predicate `hlds_out__write_call_arg_id' which
replaces similar code in mode_errors.m and typecheck.m.
compiler/prog_io_goal.m:
Add support for `aditi_bottom_up' and `aditi_top_down' annotations
on pred expressions.
compiler/prog_io_util.m:
compiler/prog_io_pragma.m:
Add predicates
- `prog_io_util:parse_name_and_arity' to parse `SymName/Arity'
(moved from prog_io_pragma.m).
- `prog_io_util:parse_pred_or_func_name_and_arity to parse
`pred SymName/Arity' or `func SymName/Arity'.
- `prog_io_util:parse_pred_or_func_and_args' to parse terms resembling
a clause head (moved from prog_io_pragma.m).
compiler/type_util.m:
Add support for `aditi_bottom_up' and `aditi_top_down' annotations
on higher-order types.
Add predicates `construct_higher_order_type',
`construct_higher_order_pred_type' and
`construct_higher_order_func_type' to avoid some code duplication.
compiler/mode_util.m:
Add predicate `unused_mode/1', which returns `builtin:unused'.
Add functions `aditi_di_mode/0', `aditi_ui_mode/0' and
`aditi_uo_mode/0' which return `in', `in', and `out', but will
be changed to return `di', `ui' and `uo' when alias tracking
is implemented.
compiler/goal_util.m:
Add predicate `goal_util__generic_call_vars' which returns
any arguments to a generic_call which are not in the argument list,
for example the closure passed to a higher-order call or
the typeclass_info for a class method call.
compiler/llds.m:
compiler/exprn_aux.m:
compiler/dupelim.m:
compiler/llds_out.m:
compiler/opt_debug.m:
Add builtin labels for the Aditi update operations.
compiler/hlds_module.m:
Add predicate predicate_table_search_pf_sym, used for finding
possible matches for a call with the wrong number of arguments.
compiler/intermod.m:
Don't write predicates which build `aditi_top_down' goals,
because there is currently no way to tell importing modules
which RL code fragment to use.
compiler/simplify.m:
Obey the `cannot_remove' field of explicit quantification goals.
compiler/make_hlds.m:
Parse Aditi updates.
Don't typecheck clauses for which syntax errors in Aditi updates
are found - this avoids spurious "undefined predicate `aditi_insert/3'"
errors.
Factor out some common code to handle terms of the form `Head :- Body'.
Factor out common code in the handling of pred and func expressions.
compiler/typecheck.m:
Typecheck Aditi builtins.
Allow the argument types of matching predicates to be adjusted
when typechecking the higher-order arguments of Aditi builtins.
Change `typecheck__resolve_pred_overloading' to take a list of
argument types rather than a `map(var, type)' and a list of
arguments to allow a transformation to be performed on the
argument types before passing them.
compiler/error_util.m:
Move the part of `report_error_num_args' which writes
"wrong number of arguments (<x>; expected <y>)" from
typecheck.m for use by make_hlds.m when reporting errors
for Aditi builtins.
compiler/modes.m:
compiler/unique_modes.m:
compiler/modecheck_call.m:
Modecheck Aditi builtins.
compiler/lambda.m:
Handle the markers for predicates introduced for
`aditi_top_down' and `aditi_bottom_up' lambda expressions.
compiler/polymorphism.m:
Add extra type_infos to `aditi_insert' calls
describing the tuple to insert.
compiler/call_gen.m:
Generate code for Aditi builtins.
compiler/unify_gen.m:
compiler/bytecode_gen.m:
Abort on `aditi_top_down' and `aditi_bottom_up' lambda
expressions - code generation for them is not yet implemented.
compiler/magic.m:
Use the `aditi_call' generic_call rather than create
a new procedure for each Aditi predicate called from C.
compiler/rl_out.pp:
compiler/rl_gen.m:
compiler/rl.m:
Move some utility code used by magic.m and call_gen.m into rl.m.
Remove an XXX comment about reference counting being not yet
implemented - Evan has fixed that.
library/ops.m:
compiler/mercury_to_mercury.m:
doc/transition_guide.texi:
Add unary prefix operators `aditi_bottom_up' and `aditi_top_down',
used as qualifiers on lambda expressions.
Add infix operator `==>' to separate the tuples in an
`aditi_modify' call.
compiler/follow_vars.m:
Thread a `map(prog_var, type)' through, needed because
type information is no longer held in higher-order call goals.
compiler/table_gen.m:
Use the `make_*_construction' predicates in hlds_goal.m
to construct constants.
compiler/*.m:
Trivial changes to add extra fields to hlds_goal structures.
doc/reference_manual.texi:
Document Aditi updates.
Use @samp{pragma base_relation} instead of
@samp{:- pragma base_relation} throughout the Aditi documentation
to be consistent with other parts of the reference manual.
tests/valid/Mmakefile:
tests/valid/aditi_update.m:
tests/valid/aditi.m:
Test case.
tests/valid/Mmakefile:
Remove some hard-coded --intermodule-optimization rules which are
no longer needed because `mmake depend' is now run in this directory.
tests/invalid/*.err_exp:
Fix expected output for changes in reporting of call_ids
in typecheck.m.
tests/invalid/Mmakefile
tests/invalid/aditi_update_errors.{m,err_exp}:
tests/invalid/aditi_update_mode_errors.{m,err_exp}:
Test error messages for Aditi updates.
tests/valid/aditi.m:
tests/invalid/aditi.m:
Cut down version of extras/aditi/aditi.m to provide basic declarations
for Aditi compilation such as `aditi__state' and the modes
`aditi_di', `aditi_uo' and `aditi_ui'. Installing extras/aditi/aditi.m
somewhere would remove the need for these.
Estimated hours taken: 4
Merge in the changes from the existential_types_2 branch.
This change adds support for mode re-ordering of code involving
existential types. The change required modifying the order of the
compiler passes so that polymorphism comes before mode analysis,
so that mode analysis can check the modes of the `type_info' or
`typeclass_info' variables that polymorphism introduces, so that
it can thus re-order the code accordingly.
This change also includes some more steps towards making existential data
types work. In particular, you should be able to declare existentially
typed data types, the compiler will generate appropriate unification
and compare/3 routines for them, and deconstruction unifications for them
should work OK. However, currently there's no way to construct them
except via `pragam c_code', and we don't generate correct RTTI for them,
so you can't use `io__write' etc. on them.
library/private_builtin.m:
compiler/accumulator.m:
compiler/bytecode_gen.m:
compiler/check_typeclass.m:
compiler/clause_to_proc.m:
compiler/code_util.m:
compiler/common.m:
compiler/dead_proc_elim.m:
compiler/dependency_graph.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/follow_code.m:
compiler/follow_vars.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_goal.m:
compiler/hlds_out.m:
compiler/hlds_pred.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/live_vars.m:
compiler/magic.m:
compiler/make_hlds.m:
compiler/mercury_compile.m:
compiler/mercury_to_c.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/mode_util.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/pd_cost.m:
compiler/polymorphism.m:
compiler/post_typecheck.m:
compiler/purity.m:
compiler/quantification.m:
compiler/rl_exprn.m:
compiler/rl_key.m:
compiler/simplify.m:
compiler/table_gen.m:
compiler/term_traversal.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
compiler/unused_args.m:
compiler/notes/compiler_design.html:
doc/reference_manual.texi:
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/existential_data_types.m:
tests/hard_coded/typeclasses/existential_data_types.exp:
tests/warnings/simple_code.exp:
tests/hard_coded/Mmakefile:
tests/term/arit_exp.trans_opt_exp:
tests/term/associative.trans_opt_exp:
tests/term/pl5_2_2.trans_opt_exp:
tests/term/vangelder.trans_opt_exp:
tests/term/arit_exp.trans_opt_exp:
tests/term/associative.trans_opt_exp:
tests/term/pl5_2_2.trans_opt_exp:
tests/term/vangelder.trans_opt_exp:
tests/invalid/errors2.err_exp2:
tests/invalid/prog_io_erroneous.err_exp2:
tests/invalid/type_inf_loop.err_exp2:
tests/invalid/types.err_exp2:
tests/invalid/polymorphic_unification.err_exp:
tests/invalid/Mmakefile:
tests/warnings/simple_code.exp:
tests/debugger/queens.exp:
tests/hard_coded/Mmakefile:
tests/hard_coded/existential_reordering.m:
tests/hard_coded/existential_reordering.exp:
Merge in the changes from the existential_types_2 branch.
Estimated hours taken: 4
Fix some old problems with HLDS dumps, including blank lines between goals
(using vi's paragraph commands to move between predicates now works),
unescaped characters in strings and chars in unifications, and extra dots
in type definitions.
compiler/hlds_out.m:
Make the above fixes. To fix the problem of blank lines between goals,
we reinterpret the meaning of the Follow arguments of several
predicates that print goals, which say what to print after the
goal, to include the newline to print after the goal. This avoids
lots of separate calls to io__write_string("\n").
Document the meanings of the arguments of many predicates.
compiler/prog_out.m:
Modify prog_out__write_sym_name to escape any special characters
(e.g. newlines) in the symbols written. (Strings, as cons_ids,
are printed as symbols.)
Add a new predicate for printing a symbol with single forward quotes
around it.
compiler/mercury_to_mercury:
When printing cons_id, quote strings.
compiler/constraint.m:
compiler/mode_errors.m:
compiler/pd_debug.m:
compiler/rl_dump.m:
compiler/saved_vars.m:
Conform to the new meaning of the Follow arguments in hlds_out.m.
Estimated hours taken: 0.5
Allow HLDS dumps to contain references to the pointers used by tabling.
Without this chance, HLDS dumps can abort on modules containing tabled
procedures.
compiler/hlds_out.m:
Allow HLDS dumps to contain references to the pointers used by tabling.
This requires adding an extra argument to an exported procedure.
compiler/mode_errors.m:
compiler/typecheck.m:
Pass the extra argument that exported procedure.
Estimated hours taken: 20
These changes make `var' and `term' polymorphic. This allows us to make
variables and terms representing types of a different type to those
representing program terms and those representing insts.
These changes do not *fix* any existing problems (for instance
there was a messy conflation of program variables and inst variables,
and where necessary I've just called varset__init(InstVarSet) with
an XXX comment).
NEWS:
Mention the changes to the standard library.
library/term.m:
Make term, var and var_supply polymorphic.
Add new predicates:
term__generic_term/1
term__coerce/2
term__coerce_var/2
term__coerce_var_supply/2
library/varset.m:
Make varset polymorphic.
Add the new predicate:
varset__coerce/2
compiler/prog_data.m:
Introduce type equivalences for the different kinds of
vars, terms, and varsets that we use (tvar and tvarset
were already there but have been changed to use the
polymorphic var and term).
Also change the various kinds of items to use the appropriate
kinds of var/varset.
compiler/*.m:
Thousands of boring changes to make the compiler type correct
with the different types for type, program and inst vars and
varsets.
configure.in:
Add a test to find the number of words needed to represent a
synchronization term.
boehm_gc/gc.h:
fix a declaration by replacing the args () with (void).
boehm_gc/solaris_pthreads.c:
add a missing include
check the return values of pthread calls.
compiler/*.m:
Add handling for the new HLDS goal type par_conj.
Add handling for the four new LLDS instructions:
init_sync_term
fork
join_and_terminate
join_and_continue
compiler/code_info.m:
add a new alternative for slot_contents - sync_term.
compiler/handle_options.m:
add .par as part of the grade
compiler/hlds_goal.m:
add the new goal type par_conj.
compiler/instmap.m:
add instmap__unify which takes a list of instmaps
and abstractly unifies them.
add unify_instmap_delta which tajes two instmap deltas
and abstractly unifies them.
compiler/llds.m:
add the new llds instructions.
compiler/mode_info.m:
add par_conj as a lock reason.
library/Makefile:
work around a bug in the solaris version pthread.h
library/benchmarking.m:
reference the stack zones from the engine structure
rather than from global variables.
library/{nc,sp}_builtin.nl:
add an op declaration for &.
library/std_util.m:
change references to global variables to references inside
the engine structure.
runtime/Mmakefile:
add mercury_thread.{c,h}
add THREADLIBS to the libraries
runtime/*.{c,h}
Remove some old junk from the previous processes/shrd-mem
changes that found their way into the repository.
Add MR_ prefixes to lots of names.
runtime/mercury_context.c:
Add init_thread_stuff for creating and initializing a
context structure for the current thread.
runtime/mercury_context.h:
add a field to the mercury context which stores the thread id
of the thread where this context originated.
add various macros for implementing the new llds instructions.
runtime/mercury_engine.c:
initialize the engine structure, rather than a bunch of globals.
runtime/mercury_engine.h:
declare the mercury_engine structure.
runtime/mercury_regorder.h:
if MR_THREAD_SAFE, and there is at least one global register
then use mr0 as a pointer to the mercury engine structure.
scripts/init_grade_options.sh-subr
add thread_safe
scripts/mgnuc.in
add THREAD_OPTS
scripts/ml.in:
add THREAD_LIBS
Estimated hours taken: 6
compiler/mercury_to_mercury.m:
compiler/mode_errors.m:
Make the code a little bit more readable:
use specific types rather than `bool' in a few places.
compiler/mercury_to_mercury.m:
Fix bugs in the generation of interface files where it was
outputting certain graphic tokens incorrectly. In particular,
it was outputting things like `module:?' without any parentheses,
space, or quotes to separate the `:' as module qualifier from
the symbol name.
tests/hard_coded/Mmakefile:
tests/hard_coded/quoting_bug.m:
tests/hard_coded/quoting_bug_test.m:
tests/hard_coded/quoting_bug_test.exp:
Add some tests for the above-mentioned bug fix.
tests/term/*.trans_opt_exp:
tests/misc_tests/pretty_print_test.exp:
Update expected output for these tests to reflect the
above changes.
Estimated hours taken: 50
Add support for nested modules.
- module names may themselves be module-qualified
- modules may contain `:- include_module' declarations
which name sub-modules
- a sub-module has access to all the declarations in the
parent module (including its implementation section).
This support is not yet complete; see the BUGS and LIMITATIONS below.
LIMITATIONS
- source file names must match module names
(just as they did previously)
- mmc doesn't allow path names on the command line any more
(e.g. `mmc --make-int ../library/foo.m').
- import_module declarations must use the fully-qualified module name
- module qualifiers must use the fully-qualified module name
- no support for root-qualified module names
(e.g. `:parent:child' instead of `parent:child').
- modules may not be physically nested (only logical nesting, via
`include_module').
BUGS
- doesn't check that the parent module is imported/used before allowing
import/use of its sub-modules.
- doesn't check that there is an include_module declaration in the
parent for each module claiming to be a child of that parent
- privacy of private modules is not enforced
-------------------
NEWS:
Mention that we support nested modules.
library/ops.m:
library/nc_builtin.nl:
library/sp_builtin.nl:
compiler/mercury_to_mercury.m:
Add `include_module' as a new prefix operator.
Change the associativity of `:' from xfy to yfx
(since this made parsing module qualifiers slightly easier).
compiler/prog_data.m:
Add new `include_module' declaration.
Change the `module_name' and `module_specifier' types
from strings to sym_names, so that module names can
themselves be module qualified.
compiler/modules.m:
Add predicates module_name_to_file_name/2 and
file_name_to_module_name/2.
Lots of changes to handle parent module dependencies,
to create parent interface (`.int0') files, to read them in,
to output correct dependencies information for them to the
`.d' and `.dep' files, etc.
Rewrite a lot of the code to improve the readability
(add comments, use subroutines, better variable names).
Also fix a couple of bugs:
- generate_dependencies was using the transitive implementation
dependencies rather than the transitive interface dependencies
to compute the `.int3' dependencies when writing `.d' files
(this bug was introduced during crs's changes to support
`.trans_opt' files)
- when creating the `.int' file, it was reading in the
interfaces for modules imported in the implementation section,
not just those in the interface section.
This meant that the compiler missed a lot of errors.
library/graph.m:
library/lexer.m:
library/term.m:
library/term_io.m:
library/varset.m:
compiler/*.m:
Add `:- import_module' declarations to the interface needed
by declarations in the interface. (The previous version
of the compiler did not detect these missing interface imports,
due to the above-mentioned bug in modules.m.)
compiler/mercury_compile.m:
compiler/intermod.m:
Change mercury_compile__maybe_grab_optfiles and
intermod__grab_optfiles so that they grab the opt files for
parent modules as well as the ones for imported modules.
compiler/mercury_compile.m:
Minor changes to handle parent module dependencies.
(Also improve the wording of the warning about trans-opt
dependencies.)
compiler/make_hlds.m:
compiler/module_qual.m:
Ignore `:- include_module' declarations.
compiler/module_qual.m:
A couple of small changes to handle nested module names.
compiler/prog_out.m:
compiler/prog_util.m:
Add new predicates string_to_sym_name/3 (prog_util.m) and
sym_name_to_string/{2,3} (prog_out.m).
compiler/*.m:
Replace many occurrences of `string' with `module_name'.
Change code that prints out module names or converts
them to strings or filenames to handle the fact that
module names are now sym_names intead of strings.
Also change a few places (e.g. in intermod.m, hlds_module.m)
where the code assumed that any qualified symbol was
fully-qualified.
compiler/prog_io.m:
compiler/prog_io_goal.m:
Move sym_name_and_args/3, parse_qualified_term/4 and
parse_qualified_term/5 preds from prog_io_goal.m to prog_io.m,
since they are very similar to the parse_symbol_name/2 predicate
already in prog_io.m. Rewrite these predicates, both
to improve maintainability, and to handle the newly
allowed syntax (module-qualified module names).
Rename parse_qualified_term/5 as `parse_implicit_qualified_term'.
compiler/prog_io.m:
Rewrite the handling of `:- module' and `:- end_module'
declarations, so that it can handle nested modules.
Add code to parse `include_module' declarations.
compiler/prog_util.m:
compiler/*.m:
Add new predicates mercury_public_builtin_module/1 and
mercury_private_builtin_module/1 in prog_util.m.
Change most of the hard-coded occurrences of "mercury_builtin"
to call mercury_private_builtin_module/1 or
mercury_public_builtin_module/1 or both.
compiler/llds_out.m:
Add llds_out__sym_name_mangle/2, for mangling module names.
compiler/special_pred.m:
compiler/mode_util.m:
compiler/clause_to_proc.m:
compiler/prog_io_goal.m:
compiler/lambda.m:
compiler/polymorphism.m:
Move the predicates in_mode/1, out_mode/1, and uo_mode/1
from special_pred.m to mode_util.m, and change various
hard-coded definitions to instead call these predicates.
compiler/polymorphism.m:
Ensure that the type names `type_info' and `typeclass_info' are
module-qualified in the generated code. This avoids a problem
where the code generated by polymorphism.m was not considered
type-correct, due to the type `type_info' not matching
`mercury_builtin:type_info'.
compiler/check_typeclass.m:
Simplify the code for check_instance_pred and
get_matching_instance_pred_ids.
compiler/mercury_compile.m:
compiler/modules.m:
Disallow directory names in command-line arguments.
compiler/options.m:
compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/modules.m:
Add a `--make-private-interface' option.
The private interface file `<module>.int0' contains
all the declarations in the module; it is used for
compiling sub-modules.
scripts/Mmake.rules:
scripts/Mmake.vars.in:
Add support for creating `.int0' and `.date0' files
by invoking mmc with `--make-private-interface'.
doc/user_guide.texi:
Document `--make-private-interface' and the `.int0'
and `.date0' file extensions.
doc/reference_manual.texi:
Document nested modules.
util/mdemangle.c:
profiler/demangle.m:
Demangle names with multiple module qualifiers.
tests/general/Mmakefile:
tests/general/string_format_test.m:
tests/general/string_format_test.exp:
tests/general/string__format_test.m:
tests/general/string__format_test.exp:
tests/general/.cvsignore:
Change the `:- module string__format_test' declaration in
`string__format_test.m' to `:- module string_format_test',
because with the original declaration the `__' was taken
as a module qualifier, which lead to an error message.
Hence rename the file accordingly, to avoid the warning
about file name not matching module name.
tests/invalid/Mmakefile:
tests/invalid/missing_interface_import.m:
tests/invalid/missing_interface_import.err_exp:
Regression test to check that the compiler reports
errors for missing `import_module' in the interface section.
tests/invalid/*.err_exp:
tests/warnings/unused_args_test.exp:
tests/warnings/unused_import.exp:
Update the expected diagnostics output for the test cases to
reflect a few minor changes to the warning messages.
tests/hard_coded/Mmakefile:
tests/hard_coded/parent.m:
tests/hard_coded/parent.child.m:
tests/hard_coded/parent.exp:
tests/hard_coded/parent2.m:
tests/hard_coded/parent2.child.m:
tests/hard_coded/parent2.exp:
Two simple tests case for the use of nested modules with
separate compilation.
Estimated hours taken: 0.01
compiler/mode_errors.m
Remove a mode error type which has not been used since
we started module qualifying modes of lambda expressions
in make_hlds.m years ago.
Estimated hours taken: 6
Fix a semantic hole. Previously, unique variables could be used
as non-local variables inside a lambda goal and shared within that
lambda. This fixes the problem by requiring that all non-local
vars to a lambda must be ground-shared.
compiler/modecheck_unify.m:
Changes detailed above.
compiler/mode_errors.m:
Add a new kind of mode error, mode_error_non_local_lambda_var.
One small change to find_important_errors/3 to ensure that this
error will be reported if the lambda is an implicit call argument
unification.
compiler/inst_util.m:
Export make_shared_inst_list/4 for use by modecheck_unify.m.
compiler/instmap.m:
New predicate: instmap__set_vars/4, which sets multiple vars
in an instmap.
tests/invalid/bind_var_errors.m:
tests/invalid/bind_var_errors.err_exp:
Regression test.
Estimated hours taken: 2
Better error reporting for variables bound in illegal places.
compiler/mode_info.m:
Add a var_lock_reason, specifying the reason why a variable
is locked during mode checking.
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/unique_modes.m:
Specify the reason when locking some variables.
compiler/mode_errors.m:
When reporting var locking errors, give the reason why the
var was locked.
tests/invalid/Mmakefile:
tests/invalid/bind_var_errors.err_exp:
tests/invalid/bind_var_errors.m:
Regression tests for the above changes.
Estimated hours taken: 0.75
library/*.m:
compiler/*.m:
Undo Zoltan's bogus update of all the copyright dates.
The dates in the copyright header should reflect the years
in which the file was modified (and no, changes to the
copyright header itself don't count as modifications).
The purpose of this diff is to allow Mercury programs to contain
impure Mercury code without the compiler changing its behavior
inappropriately, while still allowing the compiler to aggressively
optimize pure code. To do this, we require impure predicates to be so
declared, and calls to impure predicates to be flagged as such. We
also allow predicates implemented in terms of impure predicates to be
promised to be pure; lacking such a promise, any predicate that calls
an impure predicate is assumed to be impure.
At the moment, we don't allow impure functions (only predicates),
though some of the work necessary to support them has been done.
Note that to make the operators work properly, the precedence of the
`pred' and `func' operators has been changed from 1199 to 800.
Estimated hours taken: 150
compiler/purity.m:
New compiler pass for purity checking.
compiler/hlds_goal.m:
Add `impure' and `semipure' to the goal_feature enum.
compiler/hlds_out.m:
compiler/typecheck.m:
compiler/special_pred.m:
Fixed code that prints predicate name to write something more
helpful for special (compiler-generated) predicates. Added
code to print new markers. Added purity argument to
mercury_output_pred_type. New public predicate
special_pred_description/2 provides an english description for
each compiler-generated predicate.
compiler/hlds_pred.m:
Add `impure' and `semipure' to marker enum. Added new
public predicates to get predicate purity and whether or not
it's promised to be pure.
compiler/prog_data.m:
compiler/mercury_to_mercury.m:
compiler/prog_io.m:
compiler/prog_io_goal.m:
compiler/prog_io_pragma.m:
compiler/prog_io_dcg.m:
compiler/prog_util.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/mercury_to_c.m:
compiler/module_qual.m:
Add purity argument to pred and func items. Add new `impure'
and `semipure' operators. Add promise_pure pragma. Add
purity/2 wrapper to goal_expr type.
compiler/make_hlds.m:
compiler/mercury_to_goedel.m:
Added purity argument to module_add_{pred,func},
clauses_info_add_pragma_c_code, and to pred and func items.
Handle promise_pure pragma. Handle purity/2 wrapper used to
handle user-written impurity annotations on goals.
compiler/mercury_compile.m:
Add purity checking pass between type and mode checking.
compiler/mode_errors.m:
Distinguish mode errors caused by impure goals preventing
goals being delayed.
compiler/modes.m:
Don't delay impure goals, and ensure before scheduling an
impure goal that no goals are delayed. Actually, we go ahead
and try to schedule goals even if impurity causes a problem,
and then if it still doesn't mode check, then we report an
ordinary mode error. Only if the clause would be mode correct
except for an impure goal do we report it as an impurity problem.
compiler/simplify.m:
Don't optimize away non-pure duplicate calls. We could do
better and still optimize duplicate semipure goals without an
intervening impure goal, but it's probably not worth the
trouble. Also don't eliminate impure goals on a failing branch.
compiler/notes/compiler_design.html:
Documented purity checking pass.
doc/reference_manual.texi:
Document purity system.
doc/transition_guide.texi:
library/nc_builtin.nl:
library/ops.m:
library/sp_builtin.nl:
New operators and new precdence for `pred' and `func'
operators.
tests/hard_coded/purity.m
tests/hard_coded/purity.exp
tests/hard_coded/Mmakefile:
tests/invalid/purity.m
tests/invalid/purity_nonsense.m
tests/invalid/purity.err_exp
tests/invalid/purity_nonsense.err_exp
tests/invalid/Mmakefile:
Test cases for purity.
Estimated hours taken: 4
Change unique mode analysis (unique_modes.m) so that it does the same
fixpoint analysis that ordinary mode analysis (modes.m) does.
This is a first step towards mode inference of "mostly-unique" modes.
Unique mode analysis still won't introduce any new modes, but it may
now change the final insts of inferred modes from `unique' to `mostly_unique'.
The next step (not included in this diff) will be to change the handling of
calls in unique_modes.m so that it does introduce new modes.
Also change things so that the inferred modes are normally printed
only after unique mode analysis, with determinism annotations attached.
compiler/modes.m:
Add an extra WhatToCheck parameter to lots of predicates,
so they can also be used for checking unique modes.
Add a few small new bits of code to handle the
`WhatToCheck = check_unique_modes' case.
compiler/unique_modes.m:
Call the routines in modes.m rather than special casing things.
The checking of goals is still special-cased, since for
example unique_modes does not do reordering, but the traversal
of modules and procedures now uses code from modes.m.
compiler/mode_errors.m:
Add an extra bool parameter to write_mode_inference_messages
indicating whether or not to print determinism annotations.
tests/valid/Mmakefile:
tests/valid/mostly_uniq_mode_inf.m:
Test case for the above change.
Estimated hours taken: 3
Clean up the handling of predicate markers (flags).
compiler/hlds_pred.m:
Delete the `marker_status' type. It was just adding complexity
which wasn't being used.
Change the "markers list" field of the pred_info from a
list(marker_status) to an abstract data type representing
a set of markers.
Add new access predicates for this ADT.
Currently the ADT is still implemented as a list, but it might
be a good idea to eventually change it to be an int, using a
different bit for each flag.
compiler/dnf.m:
Don't bother to record `done(dnf)' markers, since they're not needed.
compiler/make_hlds.m:
Change add_pred_marker so that it adds a single marker, rather
than a list of markers. Allowing a list of markers was just
adding extra complexity which wasn't being used.
compiler/dnf.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/make_hlds.m:
compiler/mode_errors.m:
compiler/modecheck_call.m:
compiler/modes.m:
compiler/simplify.m:
compiler/stratify.m:
compiler/term_util.m:
compiler/termination.m:
compiler/typecheck.m:
compiler/unused_args.m:
Update to use the new ADT.
Estimated hours taken: 3
Report an error for duplicate mode declarations.
compiler/modes.m:
Check for duplicate mode declarations.
compiler/modecheck_call.m:
Add new predicate modes_are_indistinguishable, for use by modes.m.
compiler/mode_errors.m:
Add predicate report_indistinguishable_mode_error to mode_errors.m,
so that modes.m can use it to report duplicate mode declarations.
compiler/mode_errors.m:
compiler/mercury_to_mercury.m:
Move some code in mode_errors.m into a new predicate
mercury_output_mode_subdecls/8 in mercury_to_mercury.m.
compiler/make_hlds.m:
Update a few comments.
tests/invalid/Mmakefile:
tests/invalid/duplicate_modes.m:
tests/invalid/duplicate_modes.err_exp:
Test cases for the above change.
Estimated hours taken: 20
Reorganisation of modules to do with the inst data type.
This is actually the first installment of the alias tracking mode
checker in disguise. A very good disguise. The rationale for
this reorganisation is to reduce coupling in the part of the mode
checker which is _not_ in this change (ie most of it).
Alias tracking requires a new kind of inst, alias(inst_key), where
an inst_key is a handle on some other sub-inst. With it goes a
data structure in which to store dereferenced insts and all the
operations which go with it. This code will go in the new module
inst.m so that it doesn't have to go in prog_data.m. (I briefly
considered putting it in instmap.m however this introduces some
bad coupling since instmap.m imports hlds_module.m. Putting it
in prog_data.m would cause hlds_*.m to depend on prog_data.m,
but we have designed things so that the dependencies go in the
other direction.)
The remainder of the reorganisation is a general cleanup: the
inst testing predicates (inst_is_*) have been moved out of
mode_util because they are not actually operations on modes at
all, and have been moved into inst_match. inst_match has then
been split because otherwise it would be 2000 lines long and
will get significantly bigger when aliasing is added. Roughly
speaking, any operations which create new insts from old ones
have been moved into a new module, inst_util while any operations
which test the values of insts remain in inst_match.
Also included are the removal of some NU-Prologisms since the
NU-Prolog version of the compiler is no longer supported. Two
changes here:
- Removal of some when declarations.
- A gross hack in inst_is_*_2, where two copies of
the same inst were passed into the predicate so that
one could be switched on. Thank NU-Prolog's lack of
common subexpression elimination.
compiler/inst.m:
New module which contains the data types inst, uniqueness,
pred_inst_info, bound_inst.
compiler/inst_util.m:
New module which contains predicates which perform mode
checking-like operations on insts.
Moved in:
abstractly_unify_inst, abstractly_unify_inst_functor,
inst_merge, make_mostly_uniq_inst (from inst_match.m)
compiler/inst_match.m:
Moved out:
inst_merge, make_mostly_uniq_inst,
abstractly_unify_inst, abstractly_unify_inst_functor
(to inst_util.m)
Moved in:
inst_is_*, inst_list_is_*, bound_inst_list_is_*
(from mode_util.m)
Now exported:
unique_matches_initial/2, unique_matches_final/2
inst_contains_instname/3, pred_inst_matches/3
(They are required by inst_util.m, and they are
useful in their own right.)
compiler/instmap.m:
instmap_delta_lookup_var/3 reincarnated as
instmap_delta_search_var/3. The reason for this change is
that previously, instmap_delta_lookup_var simply returned
`free' if the searched-for var did not occur in the
instmap_delta. This is somewhat non-obvious behaviour.
instmap_delta_search_var/3 fails in such a situation.
compiler/mode_util.m:
Moved out:
inst_is_*, inst_list_is_*, bound_inst_list_is_*
(to inst_match.m)
(These are not really operations on modes.)
compiler/modecheck_call.m:
Moved in modecheck_higher_order_func_call/5, from modecheck_unify.m
compiler/modecheck_unify.m:
Moved out modecheck_higher_order_func_call/5, to modecheck_call.m
where it should have been all along.
compiler/prog_data.m:
Moved out the types inst, uniqueness, pred_inst_info,
bound_inst (to inst.m).
compiler/common.m:
compiler/cse_detection.m:
compiler/fact_table.m:
compiler/higher_order.m:
compiler/hlds_data.m:
compiler/hlds_goal.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/liveness.m:
compiler/llds.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/mode_debug.m:
compiler/mode_errors.m:
compiler/mode_info.m:
compiler/modes.m:
compiler/module_qual.m:
compiler/polymorphism.m:
compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/prog_util.m:
compiler/simplify.m:
compiler/switch_detection.m:
compiler/unify_proc.m:
compiler/unique_modes.m:
Miscellaneous minor changes to cope with the above changes.
compiler/notes/compiler_design.html:
Document the new modules.
Estimated hours taken: 14
Implemented a :- use_module directive. This is the same as
:- import_module, except all uses of the imported items
must be explicitly module qualified.
:- use_module is implemented by ensuring that unqualified versions
of items only get added to the HLDS symbol tables if they were imported
using import_module.
Indirectly imported items (from `.int2' files) and items declared in `.opt'
files are treated as if they were imported with use_module, since all uses
of them should be module qualified.
compiler/module_qual.m
Keep two sets of type, mode and inst ids, those which can
be used without qualifiers and those which can't.
Renamed some predicates which no longer have unique names since
'__' became a synonym for ':'.
Made mq_info_set_module_used check whether the current item is in
the interface, rather than relying on its caller to do the check.
Removed init_mq_info_module, since make_hlds.m now uses the
mq_info built during the module qualification pass.
compiler/prog_data.m
Added a pseudo-declaration `used', same as `imported' except uses of
the following items must be module qualified.
Added a type need_qualifier to describe whether uses of an item
need to be module qualified.
compiler/make_hlds.m
Keep with the import_status whether current item was imported
using a :- use_module directive.
Use the mq_info structure passed in instead of building a new one.
Ensure unqualified versions of constructors only get added to the
cons_table if they can be used without qualification.
compiler/hlds_module.m
Added an extra argument to predicate_table_insert of type
need_qualifier.
Only add predicates to the name and name-arity indices if they
can be used without qualifiers.
Changed the structure of the module-name-arity index, so that
lookups can be made without an arity, such as when type-checking
module qualified higher-order predicate constants. This does not
change the interface to the module_name_arity index.
Factored out some common code in predicate_table_insert which
applies to both predicates and functions.
compiler/hlds_pred.m
Removed the opt_decl import_status. It isn't needed any more
since all uses of items declared in .opt files must now be
module qualified.
Added some documentation about when the clauses_info is valid.
compiler/intermod.m
Ensure that predicate and function calls in the `.opt' file are
module qualified. Use use_module instead of import_module in
`.opt' files.
compiler/modules.m
Handle use_module directives.
Report a warning if both use_module and import_module declarations
exist for the same module.
compiler/mercury_compile.m
Collect inter-module optimization information before module
qualification, since it can't cause conflicts any more. This means
that the mq_info structure built in module_qual.m can be reused in
make_hlds.m, instead of building a new one.
compiler/prog_out.m
Add a predicate prog_out__write_module_list, which was moved
here from module_qual.m.
compiler/typecheck.m
Removed code to check that predicates declared in `.opt' files
were being used appropriately, since this is now handled by
use_module.
compiler/*.m
Added missing imports, mostly for prog_data and term.
NEWS
compiler/notes/todo.html
doc/reference_manual.texi
Document `:- use_module'.
tests/valid/intermod_lambda_test.m
tests/valid/intermod_lambda_test2.m
tests/invalid/errors.m
tests/invalid/errors2.m
Test cases.
Estimated hours taken: 0.5
compiler/det_report.m
compiler/mode_errors.m
Use the declared modes when writing error messages.
compiler/hlds_pred.m
Added a predicate proc_info_declared_argmodes which
returns the declared modes if they exist, returning
the inferred modes otherwise.
Estimated hours taken: 8
Enable the code to treat `__' as an alternative syntax for module
qualification, after fixing various places in the compiler where
we use `__' in ways that are incompatible with this.
compiler/prog_io.m:
compiler/prog_io_goal.m:
Uncomment the code to handle `__' as module qualification.
compiler/intermod.m:
compiler/hlds_module.m:
compiler/modecheck_unify.m:
Fix bugs in the handling of module qualified higher-order terms.
compiler/*.m:
s/hlds__/hlds_/g
compiler/passes_aux.m:
s/process__/process_/g
compiler/pragma_c_gen.m:
compiler/code_gen.m:
s/code_gen__/pragma_c_gen__/ for the predicates defined in
pragma_c_gen.m (this ought to have been done when the code
was first moved from code_gen.m to pragma_c_gen.m).
compiler/llds.m:
s/llds__proc_id/llds_proc_id/g
The reason for this was to avoid ambiguity between proc_id
in hlds_pred.m and llds__proc_id in llds.m.
compiler/quantification.m:
compiler/make_hlds.m:
compiler/mercury_to_c.m:
s/goal_vars/quantification__goal_vars/g
The reason for this was to avoid ambiguity between goal_vars
in quantification.m and goal_util__goal_vars in goal_util.m.
compiler/dupelim.m:
compiler/optimize.m:
s/dupelim__main/dupelim_main/g
The reason for this change is that a program can only
have one main/2 predicate.
compiler/prog_io_dcg.m:
Remove the old "temporary hack" to strip off and ignore
io__gc_call/1, since the new handling of `__' broke it.
It was only useful for optimizing NU-Prolog performance,
which we don't care about anymore.
compiler/mercury_compile.m:
compiler/modules.m:
compiler/intermod.m:
compiler/prog_io.m:
Remove occurrences of io__gc_call.
compiler/llds_out.m:
compiler/base_type_info.m:
Ensure that we properly handle the special hacks in mercury_builtin
where predicates from other modules (e.g. term__context_init)
are defined in mercury_builtin because they are needed for
type_to_term and term_to_type. llds_out.m: don't put
`mercury_builtin' in the mangled names for those symbols.
base_type_info.m: handle types whose status is "imported"
in their own module.
Estimated hours taken: 15
Module qualification of constructors.
compiler/modes.m
compiler/unique_modes.m
compiler/modecheck_unify.m
compiler/modecheck_call.m
Enable propagate_type_info_into_modes.
Use type information to module qualify cons_ids.
compiler/mode_util.m
Use propagate_type_information_into_modes to module qualify cons_ids
in bound insts.
typed_ground/2 and free/1 insts are not yet generated, since they
are not yet used anywhere.
Avoid expanding insts when propagating type information, since
that is not yet useful.
I still need to fix the handling of
inst_matches_{initial, final, binding}(
ground(_, _), bound(_, [all_functors_in_the_type]))
compiler/typecheck.m
Don't assume a module qualified cons_id is a function call
or higher-order pred constant.
compiler/modes.m
compiler/unique_modes.m
compiler/modecheck_unify.m
compiler/instmap.m
compiler/inst_match.m
Remove some unnecessary conversion between cons_ids and consts.
compiler/typecheck.m
compiler/mode_errors.m
Strip builtin qualifiers from cons_ids.
compiler/mercury_to_mercury.m
Output module qualified cons_ids.
compiler/prog_io.m
compiler/prog_io_util.m
Module qualify constructors in type definitions.
Parse qualified cons_ids in bound insts.
compiler/hlds_data.m
Remove cons_id_to_const/3, since it doesn't make much sense any more.
Add cons_id_arity/2 and cons_id_and_args_to_term/3.
compiler/make_hlds.m
Add both qualified and unqualified versions of each cons_id to
the cons_table.
compiler/det_util.m
Handle module qualified cons_ids in det_util__interpret_unify.
compiler/code_util.m
Remove some dead code in code_util__cons_id_to_tag to do with
tags for higher-order terms. Don't assume module qualified
cons_ids are higher-order pred constants.
compiler/polymorphism.m
Module qualify type_info cons_ids.
Estimated hours taken: 10
This change fixes two bugs, in quantification and liveness. I made the changes
to the other files while trying to find them; they ought to be useful in
trying to find similar bugs in the future.
The compiler now bootstraps with agressive inlining enabled.
quantification:
Fix a bug that switched two different accumulators of the same type
when processing pragma_c_codes.
liveness:
Fix a bug that could cause a variable to end up in both the post-death
and post-birth set of the same goal.
options:
Reenable inlining.
hlds_out, mercury_to_mercury:
If -D v is given, include the number of each variable at the end of
its name (e.g. Varname_20).
The predicates involved (a few from mercury_to_mercury and many from
hlds_out) now have an extra argument that says whether this should be
done or not. (It is not done when printing clauses e.g. for .opt
files.)
The bug in quantification was causing the improper substitution of
one variable for another, but both had the same name; such bugs would
be very difficult to find without this change.
constraint, det_report, intermod, make_hlds, mercury_to_c, mode_debug,
mode_errors, module_qual, typecheck:
Call predicates in hlds_out or mercury_to_mercury with the extra
argument.
saved_vars:
Thread the io__state through this module to allow debugging.
mercury_compile:
Call saved_vars via its new interface.
Fix an inadvertent use of an out-of-date ModuleInfo.
goal_util, hlds_goal:
Minor formatting cleanup.
code_gen:
Clean up the import sequence.
Estimated hours taken: 5
options:
Add a new option, --assume-gmake. Rename the existing option
--optimize-constructor-recursion to --optimize-constructor-last-call,
since it also affects last calls that are not recursive calls.
modules.m
If --assume-gmake is set, exploit the capabilities of gmake
to produce significantly smaller .dep files (about 10% the size
of the ones we produced before for mercury_compile).
mercury_compile:
Change --optimize-constructor-recursion to
--optimize-constructor-last-call.
hlds_out:
Clean up the way we produce HLDS dumps. The new algorithm eliminates
lines containing nothing but white space or a single comma or dot
in procedure definitions. It should also be easier to modify.
constraint, mode_errors:
Use the new interface of a predicate in hlds_out.
livemap:
Make a predicate more self-contained.
Estimated hours taken: 1
mode_errors.m:
Change the "In clause for `foo(in, out)'" message
so that it handles functions properly, i.e as
"In clause for `foo(in) = out'".
Estimated hours taken: 20
Mode analyser reorganisation.
compiler/mode_util.m:
Removed: instmap_init/1, apply_instmap_delta/3, instmap_lookup_var/3,
instmapping_lookup_var/3, instmap_restrict/3, map_restrict/3 (all
moved to instmap.m).
compiler/hlds_goal.m:
Removed the declarations of instmap_delta, instmap and instmapping.
compiler/mode_errors.m:
Added report_mode_errors/2 (was modecheck_report_errors, from
modes.m).
compiler/modes.m:
Predicates now exported:
modecheck_goal/4
modecheck_goal_expr/5 (previously named modecheck_goal_2/5)
handle_extra_goals/8
mode_context_to_unify_context/3
Moved to mode_errors.m:
modecheck_report_errors/2
Moved to instmap.m:
compute_instmap_delta/4
instmap_merge/3
instmap_lookup_vars (was instmap_lookup_arg_list/3)
compute_instmap_delta/4
Moved to mode_debug.m:
Type port/0
mode_checkpoint/4
Moved to modecheck_call.m:
modecheck_call_pred/7
modecheck_higher_order_call/10
modecheck_higher_order_pred_call/4
modecheck_higher_order_func_call/7
Moved to modecheck_unify.m:
modecheck_unification/9
categorize_unify_var_var/12
categorize_unify_var_functor/11
categorize_unify_var_lambda/9
Moved to mode_info.m:
mode_info_error/4
mode_info_add_error/3
compiler/code_gen.pp, compiler/code_info.m, compiler/constraint.m,
compiler/cse_detection.m, compiler/det_analysis.m, compiler/det_util.m,
compiler/dnf.m, compiler/goal_util.m, compiler/higher_order.m,
compiler/hlds_out.m, compiler/hlds_pred.m, compiler/live_vars.m,
compiler/liveness.m, compiler/lookup_switch.m, compiler/polymorphism.m,
compiler/simplify.m, compiler/store_alloc.m, compiler/switch_detection.m,
compiler/transform.m, compiler/unused_args.m:
Imported instmap.m
New files:
compiler/instmap.m:
Handle operations associated with instmaps.
compiler/modecheck_unify.m:
Handle mode checking of unifications.
compiler/modecheck_call.m:
Handle mode checking of calls
compiler/mode_debug.m:
Code to trace the actions of the mode checker.
Estimated hours taken: 4
Improve error messages from determinism analysis.
mode_errors.m, mode_util.m:
Move the predicate strip_builtin_qualifiers_from_mode_list
from mode_errors.m to mode_util.m so that it can be used
by det_report.m. Also, change it so that it strips off
qualifiers nested inside bound insts, higher-order modes, etc.
(previously it only stripped the top-level modes).
det_report.m:
Call strip_builtin_qualifiers_from_mode_list, to remove the
`mercury_builtin:' qualifiers on built-in modes such as `in', etc.
Make sure that determinism errors in function calls are reported
as being in the function call, not in the containing unification
(I got a misleading error message along those lines that confused me).
Make sure that capital letters are NOT used for lines
that are NOT the first line in the error message.
det_report.m, hlds_out.m:
Make sure that capital letters ARE used for lines
that ARE the first line in the error message.
Estimated hours taken: 45
Module qualification of types, insts and modes.
Added a new interface file - <module>.int3. This contains the
short interface qualified as much as possible given the information
in the current module.
When producing the .int and .int2 files for a module, the compiler uses
the information in the .int3 files of modules imported in the interface
to fully module qualify all items. The .int2 file is just a fully
qualified version of the .int3 file. The .int3 file cannot be overwritten
by the fully qualified version in the .int2 file because then mmake would
not be able to tell when the interface files that depend on that .int3
file really need updating.
The --warn-interface-imports option can be used to check whether
a module imported in the interface really needs to be imported in
the interface.
compiler/module_qual.m
Module qualify all types, insts and modes. Also checks for modules
imported in the interface of a module that do not need to be.
compiler/modules.m
The .int file for a module now depends on the .int3 files of imported
modules. Added code to generate the make rule for the .int file in the
.d file. There is now a file .date2 which records the last time the
.int2 file was updated.
The .int3 files are made using the --make-short-interface option
introduced a few weeks ago.
compiler/options.m
Added option --warn-interface-imports to enable warning about interface
imports which need not be in the interface. This is off by default
because a lot of modules in the library import list.m when they only
need the type list, which is defined in mercury_builtin.m.
Removed option --builtin-module, since the mercury_builtin name is wired
into the compiler in a large number of places.
compiler/prog_util.m
Added a predicates construct_qualified_term/3 and construct_qualfied_term/4
which take a sym_name, a list of argument term and a context for the /4
version and give a :/2 term.
compiler/type_util.m
Modified type_to_type_id to handle qualified types. Also added predicates
construct_type/3 and construct_type/4 which take a sym_name and a list of
types and return a type by calling prog_util:construct_qualified_term.
compiler/modes.m
On the first iteration of mode analysis, module qualify the modes of
lambda expressions.
compiler/mode_info.m
Added field to mode_info used to decide whether or not to module qualify
lambda expressions.
compiler/mode_errors.m
Added dummy mode error for when module qualification fails so that mode
analysis will stop.
Added code to strip mercury_builtin qualifiers from error messages to
improve readability.
compiler/typecheck.m
Strip builtin qualifiers from error messages.
compiler/llds.m
compiler/llds_out.m
compiler/opt_util.m
compiler/opt_debug.m
Change the format of labels produced for the predicates to use the
qualified version of the type name.
compiler/mercury_compile.pp
Call module_qual__module_qualify_items and make_short_interface.
Remove references to undef_modes.m and undef_types.m
compiler/undef_modes.m
compiler/undef_types.m
Removed, since their functionality is now in module_qual.m.
compiler/prog_io.m
Changed to qualify the subjects of type, mode and inst declarations.
compiler/*.m
Changes to stop various parts of the compiler from throwing away
module qualifiers.
Qualified various mercury_builtin builtins, e.g. in, out, term etc.
where they are wired in to the compiler.
compiler/hlds_data.m
The mode_table and user_inst_table are now abstract types each
storing the {mode | inst}_id to hlds__{mode | inst}_defn maps
and a list of mode_ids or inst_ids. This was done to improve the
efficiency of module qualifying the modes of lambda expressions
during mode analysis.
module_info_optimize/2 now sorts the lists of ids.
The hlds_module interface to the mode and inst tables has not changed.
compiler/hlds_module.m
Added yet another predicate to search the predicate table.
predicate_table_search_pf_sym_arity searches for predicates or
functions matching the given sym_name, arity and pred_or_func.
compiler/higher_order.m
Changed calls to solutions/2 to list__filter/3. Eliminated unnecessary
requantification of goals.
compiler/unused_args.m
Improved abstraction slightly.
Estimated hours taken: 12
Four loosely related changes to improve mode inference.
--------------------
(1) Fix a problem with inference of unique modes.
Previously it was sufficient to just look at the final insts of the
mode and check whether they were `clobbered' or not in order to tell
which arguments will be dead on exit from this procedure. However,
that doesn't work for inferred modes, where the final inst will
initially be `not_reached'. Previously mode inference just assumed that
all arguments to a predicate were live, but that prevents it from being
able to infer `di' modes. So I've added a new field to the proc_info
to record which arguments are required to be dead on exit.
I've also changed mode analysis so that it checks that such
arguments really are dead. This means you can declare both `di' and
`ui' modes of a predicate, and so long as you declare the `di' one
first, mode checking should handle this overloading. It also means
that errors such as passing a variable which is live to a procedure with
a `di' mode argument are caught earlier, with a potentially better
error message; mode checking may also be able to reorder such calls,
so that the `di' mode pred is scheduled last. Mode inference now
notices if an argument is dead, and if so will try infering a `di'
mode.
hlds_pred.m:
Add a new field to the proc_info, the `maybe_arglives', of type
`maybe(list(is_live))'. If set, this records whether or not the
arguments are required to be dead after the procedure or not.
Add an access predicate which checks whether this is set,
and returns either the value set, or if no value special value
is set, looks up a value based on the modes by calling get_arg_lives
from mode_util.m.
make_hlds.m:
Add a MaybeArgLives parameter to add_new_pred.
(Also change the error messages about pragmas to reflect
the new pragma syntax.)
clause_to_proc.m, unify_proc.m:
Pass MaybeArgLives = no to add_new_pred.
modes.m, mode_errors.m:
Use the new arglives field. When mode-checking a call (or
higher-order call), check that all the variables which are
required to be dead really are dead.
unique_modes.m:
Use the new arglives field.
mode_util.m:
Add predicate `get_arg_lives', for use by modes.m and hlds_pred.m.
--------------------
(2) Fix a problem with mode inference looping.
It was checking whether a fixpoint had been reached by comparing the
(un-normalised) inferred final insts with the previously recorded final
insts (which had been normalised). Instead, it has to normalise the
insts before the comparison.
modes.m:
When doing mode analysis of an inferred mode, normalise the insts
before checking whether they've changed, rather than vice versa.
--------------------
(3) Fix a problem with the computation of liveness for mode-analysis
of if-then-elses that was detected when I tried to bootcheck the above
changes.
modes.m, unique_modes.m:
When mode-checking if-then-elses, the variables in the "else"
should not be considered live when checking the condition.
(They're nondet-live, but not live with regard to forward execution.)
--------------------
(4) Reduce the occurrence of mode inference inferring spurious
`in(not_reached)' modes.
modes.m:
If the top-level inst of a variable becomes `not_reached', set
the whole instmap to `unreachable'.
Estimated hours taken: 4
compiler/{mode_errors.m,mode_info.m,modes.m,unique_modes.m}:
Fix the handling of error message contexts for mode errors
so that it does say `in call to predicate foo/2' when it
means `in call to function foo/1'.
Estimated hours taken: 24
Add preliminary support for mode inference.
hlds_pred.m, hlds_out.m:
Add a new pred marker `infer_modes'.
make_hlds.m:
If there are no declared modes for a predicate,
set the `infer_modes' marker in the pred_info.
modes.m:
Implement mode inference.
When we see a call to a predicate with the `infer_modes' marker
set, then if the call does not match any of the modes we've
already inferred for the predicate, create a new inferred mode;
the initial insts are set to the normalised argument insts, and
the final insts are initially set to not_reached. When
analysing such a predicate, rather than checking whether the
inferred final insts match the declared final insts, just
replace the old final insts with the normalised version of the
newly inferred insts. Change the top-level to repeat mode
analysis until a fixpoint is reached. We need to "normalise"
insts to a bounded approximation avoid non-termination due to
infinite expansion.
Also fix a bug which meant that using `inst constrained == any.'
didn't work - the checks for `any' weren't calling `inst_expand'.
mode_util.m:
Change the predicates `inst_is_ground', `inst_is_unique', etc.
so that they consider `not_reached' insts to satisfy the
condition.
mode_errors.m:
Change the message for predicates with no mode declaration.
Add code for printing out inferred mode declarations.
clause_to_proc.m:
Add a new predicate copy_module_clauses_to_procs
to call copy_clauses_to_procs for a list of pred_ids.
We call this from modes.m at the start of each fixpoint iteration.
Estimated hours taken: 12
Implement higher-order functions.
Add higher-order function terms
(function lambda expressions, e.g. `Func = (func(X) = Y :- Y is 2 * X)'
and higher-order function calls (apply/N, e.g. `Z = apply(Func, 42)').
Add higher-order function insts and modes.
hlds_goal.m:
Add a new field pred_or_func to lambda_goal.
prog_data.m:
Add a new field pred_or_func to pred_inst_info.
prog_io.m:
Add support for parsing higher-order function terms and
higher-order function insts and modes.
make_hlds.m:
Add support for parsing higher-order function terms.
typecheck.m:
Add support for type-checking higher-order function calls
and higher-order function terms.
modes.m, mode_errors.m:
Add support for mode-checking higher-order function calls
and higher-order function terms.
higher_order.m:
Handle higher-order function types and insts.
hlds_pred.m:
Add new predicate pred_args_to_func_args, for extracting the
function arguments and function return from the arguments
of a predicate that is really a function.
*.m:
Minor changes to handle new pred_or_func field in lambda_goals
and pred_inst_infos.
Estimated hours taken: 24
Treat higher-order predicate calls as a new sort of goal,
rather than as calls to the special predicate call/N, in order to
remove the fixed limit on the number of arguments and on the modes
for call/N.
Also, remove the restriction on output arguments preceding input arguments
in lambda expressions.
hlds_goal.m:
Add new functor higher_order_call/6 to the hlds__goal type.
*.m:
Handle new functor higher_order_call/6.
arg_info.m:
Abstract things a bit more: the argument passing convention
for a procedure may be affected by that procedure's types,
modes, and code_model, as well as the arg_method.
follow_vars.m:
Pass down the args_method, since it is now needed for figuring
out the arg_info for unifications and higher-order calls.
follow_code.m:
Treat complicated unifications in the same way as calls.
lambda.m:
When creating lambda predicates, permute the arguments so
that all input arguments come before all output arguments.
call_gen.m:
When generating higher-order predicate calls, don't abort
if outputs precede inputs; instead, generate code assuming
that the called predicate's args have been permuted so that
the inputs to come before all the outputs.
Estimated hours taken: 8
options.m:
Rename branch_delay_slot to have_delay_slot.
Set optimize_delay_slot in -O2 only if have_delay_slot was set earlier.
This is possible now because the default optimization level is now
set in mc.
mercury_compile:
Change verbose output a bit to be more consistent.
dead_proc_elim:
Export the predicates that will eventually be needed by inlining.m.
inlining.m:
Use the information about the number of times each procedure is called
to inline local nonrecursive procedures that are called exactly once.
EXCEPT that this is turned off at the moment, since the inlining of
parse_dcg_goal_2 in prog_io, which this change enables, causes the
compiler to emit incorrect code.
prog_io:
Moved the data type definitions to prog_data. (Even though prog_io.m
is ten times the size of prog_data.m, the sizes of the .c files are
not too dissimilar.)
Estimated hours taken: 3
A bunch of cleanups: improve error messages, tidy up the code.
Also, do some work towards supporting higher-order functions.
type_util.m:
Add new predicate type_is_higher_order/3 for checking
whether a type is a higher-order type. This recognizes
both higher-order predicate types and also higher-order
function types.
code_info.m, modes.m, polymorphism.m, shapes.m:
Use type_is_higher_order/3.
make_hlds.m:
Fix another error message to do the right thing when
reporting errors for functions.
mercury_to_mercury:
List `func' in the table of operators, so that it gets
parenthesized correctly.
modes.m, mode_errors.m:
Improve the error message for attempted higher-order unifications:
spit out some context, and if verbose_errors is enabled, spit
out a long description.
Estimated hours taken: 10
hlds, hlds_module, hlds_pred, hlds_goal, hlds_data:
Divided the old hlds.m into four files:
hlds_module.m defines the data structures that deal with issues
that are wider than a single predicate. These data structures are
the module_info structure, dependency_info, the predicate table
and the shape table.
hlds_pred.m defined pred_info and proc_info, pred_id and proc_id.
hlds_goal.m defines hlds__goal, hlds__goal_{expr,info}, and the
other parts of goal structures.
hlsd_data.m defines the HLDS types that deal with issues related
to data and its representation: function symbols, types, insts, modes.
It also defines the types related to determinism.
hlds.m is now an empty module. I have not removed it from CVS
because we may need the name hlds.m again, and CVS does not like
the reuse of a name once removed.
other modules:
Import the necessary part of hlds.
det_analysis:
Define a type that was up to now improperly defined in hlds.m.
prog_io:
Move the definition of type determinism to hlds_data. This decision
may need to be revisited when prog_io is broken up.
dnf, lambda:
Simplify the task of defining predicates.
llds:
Fix some comments.
mercury_compile:
If the option -d all is given, dump all HLDS stages.
shape, unused_args:
Fix formatting.