mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 05:12:33 +00:00
77a1261d3bd0900b09d06f6d2061da9f72bf22f9
28 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
40bda1e4a0 |
Fix a bug in inst_merge when merging a ground inst with a bound inst
Estimated hours taken: 8
Branches: main
Fix a bug in inst_merge when merging a ground inst with a bound inst
containing 'any' insts. Previously,
inst_merge(ground, bound(f(..., any, ...)))
would return a result of 'any' which is not as accurate as we would
like (e.g. this problem occurs often in Mercury code generated by the
HAL compiler). To improve this, we pass the type of the variable
being merged to inst_merge and when this situation arises we expand
'ground' to 'bound(<functors of type>)' and use this inst in the
merge.
An alternative to passing the types through inst_merge would be to
reinstate the use of 'typed_inst' and 'typed_ground' which are created
by (currently commented out) code in 'propagate_types_into_insts'.
However, this has previously been found to cause performance problems
since it greatly expands the size of all insts and instmaps in the
program. The approach used here is the same as that adopted for
inst_matches_{initial,final} some time ago, where it does not appear
to have a noticeable performance impact on typical programs.
compiler/inst_util.m:
Pass types through inst_merge and implement the changes to
inst_merge(ground, bound(...)) described above.
compiler/inst_match.m:
compiler/instmap.m:
compiler/mode_util.m:
compiler/simplify.m:
Pass types to calls to inst_merge.
compiler/inst_match.m:
compiler/type_util.m:
Move 'maybe_get_cons_id_arg_types' and
'maybe_get_higher_order_arg_types' from inst_match.m to
type_util.m and export them.
compiler/mode_util.m:
Export 'constructors_to_bound_insts'.
tests/valid/Mmakefile:
tests/valid/merge_ground_any.m :
Add a regression test.
tests/invalid/Mmakefile:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/merge_ground_any.m:
Add a test to make sure the ground inst is expanded out to the
full set of functors for the type.
|
||
|
|
82378c381b |
Allow polymorphic ground insts. This change assumes that all inst
Estimated hours taken: 80 Allow polymorphic ground insts. This change assumes that all inst parameters in the mode declaration for a predicate or function are constrained to be ground-shared. This is a temporary measure until we work out a nice syntax to allow the programmer to tell the compiler that certain inst parameters may be treated as ground insts. Since we don't currently support unconstrained inst parameters anyway, this shouldn't cause a problem. TODO: - Add syntax, something like `:- mode p(in(I)) <= ground(I).', to specify that an inst parameter represents a ground inst. - Allow abstract ground insts that are treated in a similar way to what we've done here with ground inst parameters. - Make mode checking more efficient (i.e. rewrite the mode system). compiler/inst.m: Add a new alternative for ground insts: `constrained_inst_var(inst_var)'. Define the type `inst_var_sub'. compiler/inst_match.m: Change inst_matches_initial so that it: - handles constrained_inst_vars correctly; - returns the inst_var substitutions necessary for the call; - handles inst_matches_initial(ground(...), bound(...), ...) properly (this requires knowing the type of the variable). The last change has also been made for inst_matches_final and inst_matches_binding. However, the check is disabled for now because, without alias tracking, the mode checker becomes too conservative. compiler/hlds_pred.m: compiler/mode_info.m: compiler/simplify.m: compiler/det_util.m: Include the inst_varset in the proc_info, mode_info and simplify_info. Add a vartypes field to the det_info. Remove the vartypes field from the simplify_info since it is now in the det_info. Use record syntax for these data structures and their access predicates to make future changes easier. compiler/prog_io.m: When processing pred and func mode declarations, convert all inst_var(V) insts to ground(shared, constrained_inst_var(V)). compiler/prog_data.m: compiler/hlds_data.m: compiler/make_hlds.m: compiler/mode_util.m: Use inst_vars instead of inst_params. compiler/modes.m: compiler/modecheck_call.m: compiler/unique_modes.m: compiler/mode_util.m: When checking or recomputing initial insts of a call, build up an inst_var substitution (using the modified inst_matches_initial) and apply this to the final insts of the called procedure before checking/recomputing them. compiler/mode_util.m: Make sure that recompute_instmap_delta recomputes the instmap_deltas for lambda_goals even when RecomputeAtomic = no. compiler/type_util.m: Add a new predicate, type_util__cons_id_arg_types which nondeterministically returns the cons_ids and argument types for a given type. Add a new predicate type_util__get_consid_non_existential_arg_types which is the same as type_util__get_existential_arg_types except that it fails rather than aborting for existenially typed arguments. compiler/accumulator.m: compiler/check_typeclass.m: compiler/clause_to_proc.m: compiler/common.m: compiler/continuation_info.m: compiler/deforest.m: compiler/det_analysis.m: compiler/det_report.m: compiler/det_util.m: compiler/dnf.m: compiler/follow_code.m: compiler/goal_store.m: compiler/goal_util.m: compiler/higher_order.m: compiler/inst_util.m: compiler/instmap.m: compiler/lambda.m: compiler/magic.m: compiler/magic_util.m: compiler/mercury_to_mercury.m: compiler/modecheck_unify.m: compiler/module_qual.m: compiler/pd_info.m: compiler/pd_util.m: compiler/polymorphism.m: compiler/post_typecheck.m: compiler/prog_io_util.m: compiler/prog_rep.m: compiler/saved_vars.m: compiler/stack_layout.m: compiler/table_gen.m: compiler/unify_proc.m: compiler/unneeded_code.m: compiler/unused_args.m: Pass inst_varsets and types where needed. Changes to reflect change in definition of the inst data type. compiler/inlining.m: Recompute the instmap deltas for a procedure after inlining. This bug showed up compiling tests/hard_coded/lp.m with inlining and deforestation turned on: deforestation was getting incorrect instmap deltas from inlining, causing the transformation to break mode-correctness. It has only just shown up because of the added call to `inst_matches_initial' from within `recompute_instmap_delta'. tests/invalid/Mmakefile: tests/invalid/unbound_inst_var.m: tests/invalid/unbound_inst_var.err_exp: tests/valid/Mmakefile: tests/valid/unbound_inst_var.m: Move the `unbound_inst_var' test case from `invalid' to `valid' and extend its coverage a bit. |
||
|
|
2aecd23064 |
Fix formatting.
Estimated hours taken: 0.1 compiler/instmap.m: Fix formatting. |
||
|
|
34d52a4091 |
Fix a bug with switches on existential types.
Estimated hours taken: 12 Fix a bug with switches on existential types. This bug meant that existential types with two or more functors did not work at all, due to internal compiler errors when compiling the unification and comparison predicates for those types. compiler/type_util.m: Add new function cons_id_adjusted_arity, which computes the arity _including_ the extra typeinfo and typeclassinfo arguments inserted for existential data types. compiler/type_util.m: compiler/polymorphism.m: Move the predicates constraint_list_get_tvars and constraint_get_tvars from polymorphism.m into type_util.m, for use in cons_id_adjusted_arity. compiler/modes.m: compiler/unique_modes.m: When modechecking the functor test in switch statements, use cons_id_adjusted_arity to compute the arity of the inst, compiler/instmap.m: In instmap__bind_var_to_functor (and the instmap_delta version), use cons_id_adjusted_arity to compute the arity of the inst. compiler/goal_util.m: compiler/pd_info.m: compiler/pd_util.m: compiler/saved_vars.m: compiler/mode_util.m: compiler/deforest.m: compiler/follow_code.m: compiler/higher_order.m: compiler/simplify.m: Pass the type(s) down to recompute_instmap_delta and instmap__bind_var_to_functor, since cons_id_adjusted_arity needs to know the type. compiler/hlds_pred.m: compiler/hlds_out.m: Add a `vartypes' typedef, defined by `:- type vartypes == map(prog_var, type)', and make use of it. Rename the `vartypes' type in hlds_out as `maybe_vartypes'. tests/hard_coded/Mmakefile: tests/hard_coded/existential_type_switch.m: tests/hard_coded/existential_type_switch.exp: Add a regression test. tests/hard_coded/Mmakefile: Enable the existential_types_test.m test case, which should have been enabled previously. (The reason that it wasn't seems to be that I made a mistake when merging in the changes from the existential types branch.) |
||
|
|
8ab130a3b0 |
Add a new pass to the compiler, that attempts to introduce accumulators
Estimated hours taken: 500
Add a new pass to the compiler, that attempts to introduce accumulators
into a procedure so as to make that procedure tail recursive.
WORK_IN_PROGRESS:
Document that the transformation now exists.
compiler/goal_util.m:
Create goal_util__can_reorder_goals, which is a version of
pd_util__can_reorder_goals that will work on the alias branch.
compiler/instmap.m:
Add instmap__changed_vars. This predicate is meant to provide the
same functionality as instmap_delta_changed_vars, but work on the
alias branch.
Also add comment to instmap_delta_changed_vars about using
instmap_changed_vars
compiler/accumulator.m:
The transformation.
compiler/mercury_compile.m:
Call the transformation.
compiler/options.m:
Add the option to turn the transformation on.
doc/user_guide.texi:
Document the option.
profiler/demangle.m:
util/mdemangle.c:
Demangle the accumulator version of the procedure labels.
compiler/notes/compiler_design.html:
Add the new pass to the documentation.
|
||
|
|
5c955626f2 |
These changes make var' and term' polymorphic.
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. |
||
|
|
a70b59e83c |
Add a test to find the number of words needed to represent a
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
|
||
|
|
75354e38bb |
Deforestation.
Estimated hours taken: 400
Deforestation.
This increases the code size of the compiler by ~80k when compiling
with --intermodule-optimization --deforestation.
The improvement from deforestation is not measurable for mmc -C make_hlds.m.
Compile time for make_hlds.m increased from 50.7 seconds to 52.2 seconds
when running deforestation.
compiler/simplify.m
compiler/common.m
Provide a nicer interface for simplifying a goal,
not an entire procedure.
Rework the interface to avoid manipulating lots of booleans.
Return an estimate of the improvement in cost from simplification.
Remove failing cases and disjuncts.
Add an option to optimize common structures even across calls.
Remove code to merge branched goals, since that is now
done by deforestation.
Fix a bug: the code to collect instmap_deltas for cases was not
including the switched-on variable in the instmap_delta,
which caused an abort in merge_instmap_delta if the switched
on variable was further instantiated in the switch.
This came up while compiling the compiler with --deforestation.
compiler/det_report.
Output duplicate call warnings even if --warn-simple-code is not set.
XXX fix the same problem with `:- pragma obsolete'.
compiler/code_aux.m
Update code_aux__cannot_loop to use termination information.
compiler/hlds_pred.m
compiler/dnf.m
Pass the type_info_varmap and typeclass_info_varmap
into hlds_pred__define_new_pred.
Restrict the variables of the new procedure onto the variables
of the goal.
Make sure all relevant type_infos are passed into the new
procedure if --typeinfo-liveness is set.
compiler/modes.m
compiler/unique_modes.m
compiler/mode_info.m
compiler/modecheck_unify.m
Put `how_to_check_goal' into the mode_info, rather
than passing it around.
Add a field to the `check_unique_modes' case which
controls whether unique modes is allowed to choose
a different procedure. For deforestation, this is
not allowed, since it could result in choosing a less
efficient procedure after generalisation.
compiler/options.m
New options:
--deforestation
--deforestation-depth-limit
Safety net for termination of the algorithm.
--deforestation-cost-factor
Fudge factor for working out whether deforestation
was worthwhile.
--deforestation-vars-threshold
Like --inline-vars-threshold.
Enable deforestation at -O3.
Removed an unnecessary mode for option_defaults_2, since it
resulted in a warning about disjuncts which cannot succeed.
compiler/handle_options.m
--no-reorder-conj implies --no-deforestation.
compiler/inlining.m
Separate code to rename goals into inlining__do_inline_call.
compiler/hlds_goal.m
Added predicates goal_list_nonlocals, goal_list_instmap_delta
and goal_list_determinism to approximate information about
conjunctions.
compiler/hlds_module.m
Added module_info_set_pred_proc_info to put an updated
pred_info and proc_info back into the module_info.
compiler/hlds_out.m
Exported hlds_out__write_instmap for debugging of deforestation.
Bracket module names on constructors where necessary.
compiler/mercury_compile.m
Call deforestation.
Use the new interface to simplify.m.
compiler/intermod.m
Put recursive predicates with a top-level branched goal
into `.opt' files.
goal_util.m
Added goal_calls_pred_id to work out if a predicate is
recursive before mode analysis.
Export goal_util__goals_goal_vars for use by deforestation.
Give a better message for a missing variable in a substitution.
compiler/instmap.m
Give a better message for inst_merge failing.
compiler/notes/compiler_design.m
Document the new modules.
library/varset.m
Add varset__select to project a varset's names and values
onto a set of variables.
doc/user_guide.texi
Document deforestation.
Remove a reference to a non-existent option, --no-specialize.
util/mdemangle.c
profiler/demangle.m
tests/misc_tests/mdemangle_test.{exp,inp}
Handle the `DeforestationIn__' predicate names introduced by
deforestation, similar to the `IntroducedFrom__' for lambda goals.
New files:
deforest.m Deforestation.
pd_cost.m Cost estimation.
pd_debug.m Debugging output.
pd_info.m State type and version control.
pd_term.m Termination checking.
pd_util.m Utility predicates
|
||
|
|
11d8161692 |
Add support for nested modules.
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.
|
||
|
|
046f2afecb |
Fix a semantic hole. Previously, unique variables could be used
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. |
||
|
|
73131e8df3 |
Undo Zoltan's bogus update of all the copyright dates.
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). |
||
|
|
bb4442ddc1 |
Update copyright dates for 1998.
Estimated hours taken: 0.5 compiler/*.m: Update copyright dates for 1998. |
||
|
|
6d32993826 |
Fix a bug in instmap_delta__search_var: if the instmap
Estimated hours taken: 0.75 instmap.m: Fix a bug in instmap_delta__search_var: if the instmap is unreachable, it should return `not_reached' rather than failing. |
||
|
|
3641af5272 |
Add constant propagation within modules. This occurs during simplification
Estimated hours taken: 10 Add constant propagation within modules. This occurs during simplification and simply attempts to evaluate "known" calls that have all their inputs bound to constants and replaces the call with constructions of the outputs. Currently the "known" calls are (most) of the arithmetic predicates, and the comparison of ints and floats. compiler/instmap.m: add merge_instmap_deltas which merges a list of intmap deltas rather than just two of them. compiler/mercury_compile.m: compiler/options.m: add (and use) the option --optimize-constant-propagation compiler/simplify.m: add a bool to the simplify struct to turn on/off constant propagation. in the simplification of calls, check to see if all the inputs are bound to constants. If we know how to evaluate this call at compile time, then do so. This may change the instmap delta. For branched goals, we merge the instmap deltas to recompute the instmap delta for the goal as a whole so that we know when every branch binds a variable to the same constant. compiler/notes/compiler_design.html: mention constant propagation. doc/user_guide.texi: mention constant propagation. compiler/const_prop.m: code that attempts to evaluate calls at compile time. It contains tables of calls that we know how to evaluate. |
||
|
|
b539cb29f7 |
Better handling of abstract unification of insts which always fail.
Estimated hours taken: 8 Better handling of abstract unification of insts which always fail. compiler/det_analysis.m: New predicate det_par_conjunction_detism/3 to compute the determinism of parallel conjunctions (or virtual parallel conjunctions). compiler/hlds_data.m: Make the ground_inst_table store the determinism of the grounding operation. The reason for this is that make_ground_inst* now returns the determinism of the grounding operation, and so it makes sense to store the determinisms along with cached groundings to avoid recomputing them. compiler/inst_util.m: Add a new argument to return the determinism of the unification/grounding to the following predicates: abstractly_unify_inst_functor abstractly_unify_bound_inst_list abstractly_unify_bound_inst_list_lives abstractly_unify_inst_list_lives make_ground_inst_list_lives make_ground_inst_list make_ground_inst make_ground_bound_inst_list This is to make it easier to locate unifications which cannot succeed. compiler/instmap.m: If you attempt to insert a not_reached into an instmap, the entire instmap becomes unreachable. compiler/modecheck_unify.m: Slight reorganisation of code dealing with var-functor unifications. Simple optimisations have been moved to modecheck_unify_functor. All unifications which definitely fail are now optimised to `fail'. compiler/mode_util.m: Minor change to support the alteration to the ground_inst_table above. tests/valid/Mmake: tests/valid/empty_bound_inst_list.m: Test case. |
||
|
|
04b720630b |
Update the copyright messages so that (a) they contain the correct years
and (b) they say "Copyright (C) ... _The_ University of Melbourne". |
||
|
|
9b7f11c6dd |
Reorganisation of modules to do with the inst data type.
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. |
||
|
|
27d156bbb5 |
Implemented a :- use_module directive. This is the same as
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. |
||
|
|
1848a1f285 |
Add a few comments to instmap_delta_binda_vars and
Estimated hours taken: 0.5 compiler/instmap.m: Add a few comments to instmap_delta_binda_vars and use more meaningful variable names. compiler/mode_util.m: Avoid some unnecessary code duplication. |
||
|
|
a5b7fe7c6e |
Fix some bugs that caused the compiler to generate incorrect code in
Estimated hours taken: 16 Fix some bugs that caused the compiler to generate incorrect code in certain cases. compiler/mode_util.m: Fix bugs in recompute_instmap_delta_cases. The old code was passing the wrong instmap to instmap_delta_bind_var and in the recursive call. It was passing the instmap _after_ the implicit functor test unification at the start of the case. For example, for a switch like this: % Point 0 ( Var has functor f/1 % Point 1 Case ; ... ) it was passing the instmap at point 1 rather than the instmap at point 0. compiler/instmap.m: Fix a bug in instmap_delta_bind_var. It was inserting the new inst for a switch variable in the instmap delta only if it had changed from point 1 in the above example, but it should have been inserting it if it had changed from point 0. |
||
|
|
096f8dea55 |
Fix a bug where the compiler was reporting warnings but exiting with a
Estimated hours taken: 1 Fix a bug where the compiler was reporting warnings but exiting with a zero exit status, even though --halt-at-warn was set. compiler/passes_aux.m: If we encounter an error (or a warning, if --halt-at-warn), then call io__exit_status(1). compiler/mercury_compile.m: Fix a warning about `condition of if-then-else can never fail'. compiler/instmap.m: Fix a warning about an unused interface import: delete `import_module hlds_module', since it's not needed. |
||
|
|
ce9ef7ebbb |
Fix a determinism analysis abort which was caused by det_analysis.m not
Estimated hours taken: 1.5 Fix a determinism analysis abort which was caused by det_analysis.m not updating the instmap to include the initial insts of the lambda variables before processing a lambda goal. This problem was also present in cse_detection.m and simplify.m. compiler/cse_detection.m compiler/det_analysis.m compiler/simplify.m Make sure that the instmap is updated before processing a lambda goal. compiler/switch_detection.m compiler/instmap.m Move some code to update the instmap before a lambda goal from switch_detection.m into a new predicate instmap__update_for_lambda_modes/5. tests/valid/Mmake tests/valid/lambda_instmap_bug.m Regression test. |
||
|
|
1839ebb663 |
Module qualification of constructors.
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.
|
||
|
|
bb2b816787 |
* Inter-module unused argument removal.
Estimated hours taken: 100 * Inter-module unused argument removal. * Allow the user to specify which directories should be searched for .opt files. * Enhancements to simplify.m and common.m which will be useful for partial deduction. compiler/options.m Added and documented options: --intermod-unused-args to enable inter-module unused argument removal. --intermod-directory <dir>, same as --search-directory except used to locate .opt files. --use-search-directories-for-intermod - use the search directories for .opt files as well. --warn-simple-code - a flag to control the warnings produced by simplify.m so that they respect --inhibit-warnings. compiler/unused_args.m Use the unused argument info from the .opt file. Clobber the dependency_info if any new preds were added. compiler/hlds_module.m Added a field to the module_info to store unused argument information from .opt files. compiler/prog_data.m Add :- pragma unused_args to hold unused argument information. This should only be used in .opt files. compiler/make_hlds.m Build the unused_arg_info field in the module_info. Check that pragma unused_args only appears in .opt files. Fill in the non-locals field in the goal_info for the builtin stubs so that mode analysis computes the correct instmap delta. compiler/intermod.m Read in the unused argument information for the current module when compiling to C. This is used to ensure that clauses are produced with the correct number of removed arguments (it may be possible to remove more arguments with the information from other modules). Fix a bug in the handling of module qualified function calls and higher-order predicate constants. compiler/handle_options.m Handle --intermod-unused-args and --use-search-directories-for-intermod. compiler/mercury_compile.m Run the entire front end and polymorphism (not just up to typechecking) when building the .opt file with --intermod-unused-args. Use the new interface to simplify.m, remove calls to excess.m and common.m. compiler/code_util.m compiler/llds_out.m When generating local code for a specialized version of a predicate from another module, put this module's name on the label to avoid link errors. compiler/higher_order.m Don't add the originating module name to the name of the specialized version, since that is now done in code_util.m. Clobber the dependency graph so that inlining will work on the specialized versions in profiling grades (this will cause slightly slower compilation in profiling grades, something I need to fix). compiler/simplify.m Merge a branching goal and an adjacent switch where the branches of the first goal contain extra information about the switched on variable of the second goal. Merge the excess assignments and common subexpression elimination passes into simplify.m. compiler/excess.m The functionality of this module is now in simplify.m, but I'll leave it here for now. compiler/instmap.m Added predicates instmap__bind_var_to_functor and instmap_delta_bind_var_functor to which take a var, cons_id and an instmap and adjust the inst of the var. This is used to update the instmap at the beginning of each case in a switch. Fix a bug in merge_instmap_delta where variables whose inst had information added in one branch of a switch, disj, or ite had that changed inst included in the instmap_delta for the entire branched goal. compiler/mode_util.m Use instmap_delta_bind_var_to_functor in recompute_instmap_delta. Added predicate bind_inst_to_functor which takes a ground or bound inst and a cons_id and adjusts the top level of the inst to be bound to that cons_id. Other types of inst are left unchanged. Change recompute_instmap_delta so that the switched on variable of a switch is bound to the functor in each case even if the binding unification has been removed. Added a boolean argument to request recomputation of instmap_deltas for atomic goals. compiler/modes.m compiler/unique_modes.m Make sure that the instmap_delta for each branch of a switch includes the extra information added by the functor test. compiler/common.m Removed the goal traversal. Leave preds to be called by simplify.m to optimise common unifications and calls. Warn about and eliminate multiple calls to a predicate with the same input arguments. Replace deconstructions of known terms with assignments to the output variables where this would not make more variables live at stack flushes. compiler/follow_code.m Exported move_follow_code_select. Don't move follow code into erroneous branches. library/string.nu.nl Added string__contains_char/2. compiler/base_type_layout.m compiler/special_pred.m compiler/vn_order.m library/mercury_builtin.m Removed duplicate calls. doc/user_guide.texi Documented options. tests/warnings/duplicate_call.m tests/warnings/duplicate_call.exp Test duplicate call warning. |
||
|
|
701e4cb4d4 |
Moved normalise_inst/3, normalise_insts/3 (to mode_util.m)
Estimated hours taken: 0.5 compiler/instmap.m: Moved normalise_inst/3, normalise_insts/3 (to mode_util.m) compiler/mode_util.m: Added normalise_inst/3, normalise_insts/3 (from instmap.m) |
||
|
|
4ec444f20a |
Replace the call to map__det_insert in instmap_delta_apply_sub
Estimated hours taken: 0.25 compiler/instmap.m: Replace the call to map__det_insert in instmap_delta_apply_sub with map__set, as a temporary hack to work around a problem with the excess-assign pass crashing when we compile profiler/propagate.m. |
||
|
|
06e05928e1 |
Makes instmap and instmap_delta into ADTs.
Estimated hours taken: 38 Makes instmap and instmap_delta into ADTs. compiler/code_gen.m: compiler/code_info.m: compiler/cse_detection.m: compiler/det_analysis.m: compiler/dnf.m: compiler/goal_util.m: compiler/higher_order.m: compiler/hlds_goal.m: compiler/hlds_out.m: compiler/hlds_pred.m: compiler/live_vars.m: compiler/liveness.m: compiler/lookup_switch.m: compiler/mode_debug.m: compiler/mode_info.m: compiler/modecheck_call.m: compiler/modecheck_unify.m: compiler/modes.m: compiler/polymorphism.m: compiler/simplify.m: compiler/store_alloc.m: compiler/switch_detection.m: compiler/transform.m: compiler/uniq_modes.m: compiler/unused_args.m: Miscellaneous minor changes to use the new instmap.m compiler/constraint.m: Removed unnecessary duplication of code in constraint__checkpoint/4 and constraint__no_output_vars/2. compiler/det_util.m: Changed no_output_vars/4 to det_no_output_vars/4, moved body of code to instmap.m. compiler/instmap.m: Added abstract types instmap/0, instmap_delta/0. Added predicates: instmap__init_reachable/1, instmap__init_unreachable/1, instmap_delta_init_reachable/1, instmap_delta_init_unreachable/1, instmap__is_reachable/1, instmap__is_unreachable/1, instmap_delta_is_reachable/1, instmap_delta_is_unreachable/1, instmap__from_assoc_list/2, instmap_delta_from_assoc_list/2, instmap__vars/2, instmap__vars_list/2, instmap_delta_changed_vars/2, instmap_delta_lookup_var/3, instmap__set/3, instmap_delta_insert/4, instmap_delta_apply_instmap_delta/3, instmap_delta_restrict/3, instmap_delta_delete_vars/3, instmap__no_output_vars/4, instmap_delta_apply_sub/4, instmap__to_assoc_list/2, instmap_delta_to_assoc_list/2. Renamed predicates: instmap__lookup_var/3 (was instmap_lookup_var/3) instmap__lookup_vars/3 (was instmap_lookup_vars/3) instmap__apply_instmap_delta/3 (was apply_instmap_delta/3) instmap__merge/5 (was instmap_merge/5) instmap__restrict/3 (was instmap_restrict/3) Moved predicates: merge_instmap_delta/5 (from mode_util.m) Removed predicates: instmapping_lookup_var/3 compiler/mode_util.m: Moved merge_instmap_delta/5 to instmap.m |
||
|
|
5c149e55b2 |
Mode analyser reorganisation.
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.
|