mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 06:47:17 +00:00
11d81616926a51f900b8d8efd27435c4019f49dd
40 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
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.
|
||
|
|
d0085d8119 |
Assorted changes to make the HLDS type and mode correct
Estimated hours taken: 45
Assorted changes to make the HLDS type and mode correct
after lambda expansion. The HLDS is still not unique mode
correct after common structure elimination.
compiler/det_analysis.m
Make sure the inferred_determinism field of the proc_info is filled
in correctly for imported procedures and class methods.
compiler/mode_util.m
Fix a bug in recompute_instmap_delta_call to do with unreachable
instmaps. This caused an abort a couple of months ago when
compiling with --deforestation (not yet committed), but
can't currently be reproduced.
compiler/hlds_pred.m
compiler/lambda.m
Add a field to the proc_info to record which args_method
should be used for this procedure. Procedures directly
called by do_call_*_closure must be compiled with
the `compact' argument convention to avoid the need to permute
the arguments so inputs come before outputs.
compiler/lambda.m
compiler/higher_order.m
Remove permutation of argument variables of lambda expressions
so the HLDS is type and mode correct and mode analysis can
be rerun. Otherwise, rerunning mode analysis will fail on
tests/hard_coded/ho_order.m.
compiler/arg_info.m
Added arg_info__ho_call_args_method which returns
an args_method which can always be directly called by
do_call_*_closure (`compact').
Added arg_info__args_method_is_ho_callable to check that
a given args_method can be directly called.
compiler/unify_gen.m
Abort if a closure is created for a procedure compiled
with the simple argument convention.
compiler/hlds_goal.m
compiler/lambda.m
Mode analysis was not storing the non-locals list on which the
uni_modes field of the construction of a lambda goal was computed.
If the nonlocals were renamed, the sort order could change, and
the non-locals could be incorrectly matched with the arguments
of the introduced lambda expression, causing a mode error. The
argument list is now stored.
This caused rerunning mode-checking on tests/valid/lazy_list.m
after polymorphism to fail.
compiler/*.m
Fill in the args_method field of proc_infos with the value
from the globals.
Handle the extra argument to the lambda_goal unify_rhs.
compiler/follow_vars.m
Remove code to handle complicated unifications, since
they should be removed by polymorphism.m.
compiler/special_pred.m
library/mercury_builtin.m
Make the uniqueness of the comparison_result argument
of builtin_compare_* and the automatically generated
comparison procedures match that of compare/3. Unique mode
errors will still be introduced if polymorphism.m specializes
calls to any of the unique modes of compare/3 and then mode analysis
is rerun, since the compiler-generated comparison procedures
only implement the (uo, in, in) mode. (This is not yet a problem
because currently we don't rerun mode analysis.)
runtime/mercury_ho_call.c
Remove code in do_call_*_closure to deal with the
`simple' args_method. Since the output arguments no longer
need to be moved, the closure call is now a tailcall.
Remove some magic numbers.
compiler/modecheck_unify.m
Avoid some aborts and mode errors when rerunning mode analysis,
especially those resulting from not_reached insts being treated
as bound.
Avoid aborting on higher-order predicate constants with multiple
modes if lambda expansion has already been run.
tests/valid/higher_order.m
Add a test case for an abort in mode analysis when
compiling with --deforestation (not yet committed),
due to a predicate constant for a procedure with multiple
modes.
tests/valid/unreachable_code.m
Add a test case for bogus higher-order unification
mode errors in unreachable code.
|
||
|
|
31a9c3a10a |
Fix a bug that caused bootcheck to fail at `-O4 --intermodule-optimization'.
Estimated hours taken: 8 Fix a bug that caused bootcheck to fail at `-O4 --intermodule-optimization'. compiler/higher_order.m: When doing type substitutions to specialize the types during specialization of higher-order calls, make sure that we permute the argument types of the caller based on the modes, with all input arguments preceding all output arguments, because lambda.m has already done this for the argument types of the callee. compiler/lambda.m: Change the type of lambda__permute_argvars to be polymorphic, so that it can be used to permute types as well as permuting variables. |
||
|
|
5013dd9c76 |
Implement nondet pragma C codes.
Estimated hours taken: 40
Implement nondet pragma C codes.
runtime/mercury_stacks.h:
Define a new macro, mkpragmaframe, for use in the implementation
of nondet pragma C codes. This new macro includes space for a
struct with a given sruct tag in the nondet stack frame being created.
compiler/{prog_data.m,hlds_goal.m}:
Revise the representation of pragma C codes, both as the item and
in the HLDS.
compiler/prog_io_pragma.m:
Parse nondet pragma C declarations.
Fix the indentation in some places.
compiler/llds.m:
Include an extra argument in mkframe instructions. This extra argument
gives the details of the C structure (if any) to be included in the
nondet stack frame to be created.
Generalize the LLDS representation of pragma C codes. Instead of a
fixed sequence of <assign from inputs, user c code, assign to outputs>,
let the sequence contain these elements, as well as arbitrary
compiler-generated C code, in any order and possibly with repetitions.
This flexibility is needed for nondet pragma C codes.
Add a field to pragma C codes to say whether they can call Mercury.
Some optimizations can do a better job if they know that a pragma C
code cannot call Mercury.
Add another field to pragma C codes to give the name of the label
they refer to (if any). This is needed to prevent labelopt from
incorrectly optimizing away the label definition.
Add a new alternative to the type pragma_c_decl, to describe the
declaration of the local variable that points to the save struct.
compiler/llds_out.m:
Output mkframe instructions that specify a struct as invoking the new
mkpragmaframe macro, and make sure that the struct is declared just
before the procedure that uses it.
Other minor changes to keep up with the changes to the representation
of pragma C code in the LLDS, and to make the output look a bit nicer.
compiler/pragma_c_gen.m:
Add code to generate code for nondet pragma C codes. Revise the utility
predicates and their data structures a bit to make this possible.
compiler/code_gen.m:
Add code for the necessary special handling of prologs and epilogs
of procedures defined by nondet pragma C codes. The prologs need
to be modified to include a programmer-defined C structure in the
nondet stack frame and to communicate the location of this structure
to the pragma C code, whereas the functionality of the epilog is
taken care of by the pragma C code itself.
compiler/make_hlds.m:
When creating a proc_info for a procedure defined by a pragma C code,
we used to insert unifications between the headvars and the vars of
the pragma C code into the body goal. We now perform substitutions
instead. This removes a factor that would complicate the generation
of code for nondet pragma C codes.
Pass a moduleinfo down the procedures that warn about singletons
(and other basic scope errors). When checking whether to warn about
an argument of a pragma C code not being mentioned in the C code
fragment, we need to know whether the argument is input or output,
since input variables should appear in some code fragments in a
nondet pragma C code and must not appear in others. The
mode_is_{in,out}put checks need the moduleinfo.
(We do not need to check for any variables being mentioned where
they shouldn't be. The C compiler will fail in the presence of any
errors of that type, and since those variables could be referred
to via macros whose definitions we do not see, we couldn't implement
a reliable test anyway.)
compiler/opt_util.m:
Recognize that some sorts of pragma_c codes cannot affect the data
structures that control backtracking. This allows peepholing to
do a better job on code sequences produced for nondet pragma C codes.
Recognize that the C code strings inside some pragma_c codes refer to
other labels in the procedure. This prevents labelopt from incorrectly
optimizing away these labels.
compiler/dupelim.m:
If a label is referred to from within a C code string, then do not
attempt to optimize it away.
compiler/det_analysis.m:
Remove a now incorrect part of an error message.
compiler/*.m:
Minor changes to conform to changes to the HLDS and LLDS data
structures.
|
||
|
|
bb4442ddc1 |
Update copyright dates for 1998.
Estimated hours taken: 0.5 compiler/*.m: Update copyright dates for 1998. |
||
|
|
b4813457c9 |
A rewrite of termination analysis to make it significantly easier to modify,
Estimated hours taken: 60
A rewrite of termination analysis to make it significantly easier to modify,
and to extend its capabilities.
compiler/error_util.m:
A new file containing code that makes it easier to generate
nicely formatted error messages.
compiler/termination.m:
Updates to reflect the changes to the representation of termination
information.
Instead of doing pass 1 on all SCCs and then pass 2 on all SCCs,
we now do both pass 1 and 2 on an SCC before moving on to the next.
Do not insist that either all procedures in an SCC are
compiler-generated or all are user-written, since this need not be
true in the presence of user-defined equality predicates.
Clarify the structure of the code that handles builtins and compiler
generated predicates.
Concentrate all the code for updating module_infos in this module.
Previously it was scattered in several places in several files.
Put all the code for writing out termination information at the
end of the module in a logical order.
compiler/term_traversal.m:
A new file containing code used by both pass 1 and pass 2 to
traverse procedure bodies.
compiler/term_pass1.m:
Use the new traversal module.
Clarify the fixpoint computation on the set of output supplier
arguments.
Remove duplicates from the list of equations given to the solver.
This avoids a det stack overflow in lp.m when doing termination
analysis on options.m.
If an output argument of a predicate makes sense only in the absence
of errors, then return it only in the absence of errors.
compiler/term_pass2.m:
Use the new traversal module. Unlike the previous code, this allows us
to ignore recursive calls with input arguments bigger than the head
if those calls occur after goals that cannot succeed (since those
calls will never be reached).
Implement a better way of doing single argument analysis, which
(unlike the previous version) works in the presence of mutual recursion
and other calls between the recursive call and the start of the clause.
Implement a more precise way of checking for recursions that don't
cause termination problems. We now allow calls from p to q in which
the recursive input supplier arguments can grow, provided that on
any path on which q can call p, directly or indirectly, the recursive
input supplier arguments shrink by a greater amount.
If an output argument of a predicate makes sense only in the absence
of errors, then return it only in the absence of errors.
compiler/term_util.m:
Updates to reflect the changes to the representation of termination
information.
Reorder to put related code together.
Change the interface of several predicates to better reflect the
way they are used.
Add some more utility predicates.
compiler/term_errors.m:
Small changes to the set of possible errors, and major changes in
the way the messages are printed out (we now use error_util).
compiler/options.m:
Change --term-single-arg from being a bool to an int option,
whose value indicates the maximum size of an SCC in which we try
single argument analysis. (Large SCCs can cause single-arg analysis
to require a lot of iterations.)
Add an (int) option that controls the max number of paths
that we are willing to analyze (analyzing too many paths can cause
det stack overflow).
Add an (int) option that controls the max number of causes of
nontermination that we print out.
compiler/hlds_pred.m:
Use two separate slots in the proc_info to hold argument size data
and termination info, instead of the single slot used until now.
The two kinds of information are produced and used separately.
Make the layout of the get and set procedures for proc_infos more
regular, to facilitate later updates.
The procedures proc_info_{,set_}variables did the same work as
proc_info_{,set_}varset. To eliminate potential confusion, I
removed the first set.
compiler/*.m:
Change proc_info_{,set_}variables to proc_info_{,set_}varset.
compiler/hlds_out.m:
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
Change the code to handle the arg size data and the termination
info separately.
compiler/prog_data.m:
Change the internal representation of termination_info pragmas to
hold the arg size data and the termination info separately.
compiler/prog_io_pragma.m:
Change the external representation of termination_info pragmas to
group the arg size data together with the output supplier data,
to which it is logically connected.
compiler/module_qual.m:
compiler/modules.m:
Change the code to accommodate the change to the internal
representation of termination_info pragmas.
compiler/notes/compiler_design.html:
Fix some documentation rot, and clarify some points.
Document termination analysis.
doc/user_guide.texi:
Document --term-single-arg and the new options.
Remove spaces from the ends of lines.
library/bag.m:
Add a new predicate, bag__least_upper_bound.
Fix code that would do the wrong thing if executed by Prolog.
Remove spaces from the ends of lines.
library/list.m:
Add a new predicate, list__take_upto.
library/set{,_ordlist}.m:
Add a new predicate, set{,_ordlist}__count.
tests/term/*:
A bunch of new test cases to test the behaviour of termination
analysis. They are the small benchmark suite from our paper.
tests/Mmakefile:
Enable the new test case directory.
|
||
|
|
7406335105 |
This change implements typeclasses. Included are the necessary changes to
Estimated hours taken: 500 or so This change implements typeclasses. Included are the necessary changes to the compiler, runtime and library. compiler/typecheck.m: Typecheck the constraints on a pred by adding constraints for each call to a pred/func with constraints, and eliminating constraints by applying context reduction. While reducing the constraints, keep track of the proofs so that polymorphism can produce the tyepclass_infos for eliminated constraints. compiler/polymorphism.m: Perform the source-to-source transformation which turns code with typeclass constraints into code without constraints, but with extra "typeclass_info", or "dictionary" parameters. Also, rather than always having a type_info directly for each type variable, sometimes the type_info is hidden inside a typeclass_info. compiler/bytecode*.m: Insert some code to abort if bytecode generation is used when typeclasses are used. compiler/call_gen.m: Generate code for a class_method_call, which forms the body of a class method (by selecting the appropriate proc from the typeclass_info). compiler/dead_proc_elim.m: Don't eliminate class methods if they are potentially used outside the module compiler/hlds_data.m: Define data types to store: - the typeclass definitions - the instances of a class - "constraint_proof". ie. the proofs of redundancy of a constraint. This info is used by polymorphism to construct the typeclass_infos for a constraint. - the "base_tyepclass_info_constant", which is analagous the the base_type_info_constant compiler/hlds_data.m: Define the class_method_call goal. This goal is inserted into the body of class method procs, and is responsible for selecting the appropriate part of the typeclass_info to call. compiler/hlds_data.m: Add the class table and instance table to the module_info. compiler/hlds_out.m: Output info about base_typeclass_infos and class_method_calls compiler/hlds_pred.m: Change the representation of the locations of type_infos from "var" to type_info_locn, which is either a var, or part of a typeclass_info, since now the typeclass_infos contain the type_infos for the type that they constrain. Add constraints to the pred_info. Add constraint_proofs to the pred_info (so that typeclass.m can annotate the pred_info with the reasons that constraints were eliminated, so that polymorphism.m can in turn generate the typeclass_infos for the constraints). Add the "class_method" marker. compiler/lambda.m: A feable attempt at adding class ontexts to lambda expressions, untested and almost certainly not working. compiler/llds_out.m: Output the code addresses for do_*det_class_method, and output appropriately mangled symbol names for base_typeclass_infos. compiler/make_hlds.m: Add constraints to the types on pred and func decls, and add class and instance declarations to the class_table and instance_table respectively. compiler/mercury_compile.m: Add the check_typeclass pass. compiler/mercury_to_mercury.m: Output constraints of pred and funcs, and output typeclass and instance declarations. compiler/module_qual.m: Module qualify typeclass names in pred class contexts, and qualify the typeclass and instance decls themselves. compiler/modules.m: Output typeclass declarations in the short interface too. compiler/prog_data.m: Add the "typeclass" and "instance" items. Define the types to store information about the declarations, including class contexts on pred and func decls. compiler/prog_io.m: Parse constraints on pred and func declarations. compiler/prod_out.m: Output class contexts on pred and func decls. compiler/type_util.m: Add preds to apply a substitution to a class_constraint, and to a list of class constraints. Add type_list_matches_exactly/2. Also add typeclass_info and base_typeclass_info as types which should not be optimised as no_tag types (seeing that we cheat a bit about their representation). compiler/notes/compiler_design.html: Add notes on module qualification of class contexts. Needs expansion to include more stuff on typeclasses. compiler/*.m: Various minor changes. New Files: compiler/base_typeclass_info.m: Produce one base_typeclass_info for each instance declaration. compiler/prog_io_typeclass.m: Parse typeclass and instance declarations. compiler/check_typeclass.m: Check the conformance of an instance declaration to the typeclass declaration, including building up a proof of how superclass constraints are satisfied so that polymorphism.m is able to construct the typeclass_info, including the superclass typeclass_infos. library/mercury_builtin.m: Implement that base_typeclass_info and typeclass_info types, as well as the predicates type_info_from_typeclass_info/3 to extract a type_info from a typeclass_info, and superclass_from_typeclass_info/3 for extracting superclasses. library/ops.m: Add "typeclass" and "instance" as operators. library/string.m: Add a (in, uo) mode for string__length/3. runtime/mercury_ho_call.c: Implement do_call_*det_class_method, which are the pieces of code responsible for extracting the correct code address from the typeclass_info, setting up the arguments correctly, then executing the code. runtime/mercury_type_info.h: Macros for accessing the typeclass_info structure. |
||
|
|
470532637d |
Clean up the handling of predicate markers (flags).
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. |
||
|
|
5976f769f7 |
Fix a bug for the case of a higher-order function call in code
Estimated hours taken: 1 Fix a bug for the case of a higher-order function call in code with common sub-expression; mercury 0.7 failed this test, reporting "Software Error: modecheck fails when repeated", due to confusion between h.o. _function_ call and h.o. _predicate_ call. compiler/hlds_goal.m: Add `pred_or_func' field to HLDS higher_order_calls. compiler/modes.m: compiler/modecheck_call.m: compiler/hlds_out.m: compiler/*.m: Add code to handle new field for higher_order_call goals. tests/valid/Mmake: tests/valid/ho_func_call.m: Regression test for the above-mentioned bug. |
||
|
|
2980b59474 |
Profiling code with lots of lambda goals was painful, because the names
Estimated hours taken: 1.5 Profiling code with lots of lambda goals was painful, because the names of the predicates contained no information about which piece of the source they correspond to. This change corrects this problem by enabling the profiler to produce output such as: ... 0.00 0.00 <pred/func goal from lp:'pivot', line 362> [10] ... 0.00 0.00 <pred/func goal from lp:'pivot', line 356> [11] ... 0.00 0.00 <pred/func goal from lp:'simplex', line 262> [12] compiler/lambda.m: compiler/polymorphism.m: construct more meaningful predicate names for lambda predicates. this required adding the name of the predicate that contained the lambda goal to the info structures that gets threaded through these modules. profiler/demangle.m: util/mdemangle.c: demangle the names for lambda goals. |
||
|
|
04b720630b |
Update the copyright messages so that (a) they contain the correct years
and (b) they say "Copyright (C) ... _The_ University of Melbourne". |
||
|
|
06c70c62eb |
Bug fix.
Estimated hours taken: 2 Bug fix. compiler/higher_order.m lambda.m reorders the argument variables of lambda expressions so that inputs come before outputs. higher_order.m was not doing the reordering before replacing a higher_order_call with a call to the lambda expression. compiler/lambda.m Export lambda__permute_argvars for use by higher_order.m. tests/hard_coded/Mmake tests/hard_coded/ho_order.m tests/hard_coded/ho_order.exp Regression test. |
||
|
|
6dd00b858d |
Fix some spelling mistakes.
Estimated hours taken: 0.4 compiler/det_report.m: compiler/lambda.m: Fix some spelling mistakes. |
||
|
|
9b6dab0055 |
Fix a buggy optimization: the code was assuming that the
Estimated hours taken: 1 compiler/lambda.m: Fix a buggy optimization: the code was assuming that the argument variables to a procedure call are all distinct, but that is not necessarily the case -- although they are made distinct for type checking and mode analysis, excess assignment elimination (which is done by simplify.m) can reintroduce duplicate args. This fixes a "variable not found" bug. |
||
|
|
e3471f333f |
Fix a bug in inlining of polymorphic pragma c_code procedures.
Estimated hours taken: 3 Fix a bug in inlining of polymorphic pragma c_code procedures. The bug was that if the actual argument type has a specific type of say `float', then the C variable for the corresponding formal parameter will be declared to have type `Float', whereas without inlining the argument type would have been polymorphic and so the C variable would have been declared to have type `Word'. Hence we need to keep track of the original argument types, before any inlining or specialization has occurred, and use these original argument types to determine how to declare the C variables, rather than using the actual argument types for this particular specialization. compiler/hlds_goal.m: Add a new field to pragma_c_code goals, holding the original argument types (before any inlining or specialization) of the pragma_c_code procedure. compiler/make_hlds.m: Initialize this field with the declared argument types for the pragma c_code procedure. compiler/polymorphism.m: Update this field to account for the inserted type_info variables. compiler/code_gen.m: Pass this field to pragma_c_gen.m. compiler/pragma_c_gen.m: Use the original argument types field for the pragma variable declarations, rather than looking up the actual types of the arguments. compiler/*.m: Trivial changes to handle new field. compiler/live_vars.m: Comment out some code to avoid a warning about `fail' in the condition of an if-then-else. |
||
|
|
4c3b0ecb09 |
Replace calls to map__set with calls to either map__det_insert or
Estimated hours taken: 3 Replace calls to map__set with calls to either map__det_insert or map__det_update. In some cases this required a small amount of code reorganization. |
||
|
|
3ec8a17ffc |
Enable the code to treat `__' as an alternative syntax for module
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. |
||
|
|
91c4330db7 |
The first half of a change to introduce nondet pragma C goals.
Estimated hours taken: 12 The first half of a change to introduce nondet pragma C goals. This half makes the necessary modifications to the HLDS; the next half will modify the LLDS and emit it. prog_data: Add a new pragma type for nondet pragma c_codes; these specify the names of a a bunch of variables to save across backtracking, and a list of label names to which backtracking may take place. Rename is_recursive to may_call_mercury, since this is a more direct expression of the meaning. prog_io: Move much of the functionality to new files. prog_io_dcg, prog_io_goal, prog_io_pragma, prog_io_util: New files, made up of pieces of prog_io. hlds_goal: Add an extra argument to the pragma_c_goals to store the extra information present in the new type of pragma c_codes. det_analysis: Take into account that the new type of pragma_c goal may have more than one solution. goal_util: Rename variables in the new field of pragma_cs. live_vars: Allocate stack slots to the saved variables in the new type of pragma_c goals. make_hlds: Handle the new type of pragma_c goals. mercury_output, hlds_out: Output the new type of pragma_c goals. garbage_out: Rename type "det" to "frame_type". others: Ignore one more arg of pragma_c goals or import prog_io_util. |
||
|
|
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. |
||
|
|
3243dbe238 |
The only significant change in this checkin is that liveness.m now
Estimated hours taken: 0.5 The only significant change in this checkin is that liveness.m now tries to compute the best resume_locs for negations (it already did for if-then-elses and disjunctions; leaving out negations was an oversight in my earlier checkin). The other changes are only syntactic: I have removed the cont-lives and nondet-lives field from goal_info, since they are not used anymore. I have replaced the nondet-lives field in code_info, which is not used anymore, with a follow-vars field, which is not used yet (but will be). Some of the "read" access predicates in hlds_goal did not have "get" in their name; I added them. |
||
|
|
ee24e66a71 |
Switch from using a stack of store_maps in the code_info to govern what
Estimated hours taken: 2.5 Switch from using a stack of store_maps in the code_info to govern what goes where at the end of each branched structure to using the store map fields of the goal expressions of those structures. Fix variable names where they resembled the wrong kind of map(var, lval). code_info: Remove the operations on stacks of store maps. Modify the generate_forced_saves and remake_with_store_map operations to take a store_map parameter. When making variables magically live, pick random unused variables to hold them, since we can no longer use the guidance of the top store map stack entry. This may lead to the generation of some excess move instructions at non-reachable points in the code; this will be fixed later. code_gen: Remove the store map push and pop invocations. Modify the generate_forced_goal operation to take a store_map parameter. code_exprn: Export a predicate for use by code_info. middle_rec, disj_gen, ite_gen, switch_gen, dense_switch, lookup_switch, string_switch, tag_switch: Pass the store map around to get it to invocations of the primitives in code_gen and code_info that now need it. goal_util: Name apart the new follow_vars field in hlds__goal_infos. (This should have been in the change that introduced that field.) common, constraint, cse_detection, det_analysis, dnf, excess, follow_code, intermod, lambda, lco, liveness, make_hlds, mode_util, modes, polymorphism, quantification, simplify, switch_detection, typecheck, unique_modes, unused_args: Fix variable names. follow_vars, store_alloc: Add comments. |
||
|
|
5d64b759db |
The main changes are
Estimated hours taken: 12
The main changes are
1 associating a name with the arguments of constructors
2 removing the follow_vars field from calls, higher-order calls
and complicated unifications, since they are not used
3 merging the follow_vars and store_alloc passes, since they logically
belong together
4 add a new module, lco, for detecting opportunities for last
call optimization modulo constructor application; it won't
actually apply the optimization until the mode system becomes
expressive enough to handle it (this module detects 529 opportunities
in the compiler and library)
5 make "-O3 --optimize-value-number" do the right thing; previously,
it used not to apply value numbering because the vnrepeat option
defaulted to zero
6 don't refer to .err2 files anymore; use .err instead.
prog_data:
The list associated with each value of type "constructor" now
contains not only the types of the arguments but their names as well.
equiv_type, hlds_data, hlds_out, make_hlds, mercury_to_{goedel,mercury},
mode_util, module_qual, shapes, type_util, unify_proc:
Modify the traversal of type definitions to account for the names
in the lists inside values of type "constructor".
prog_io:
Parse argument names. An unrelated change is that we now
check whether :- pred declarations give modes to some of their
arguments but not to all, in which case we return an error.
hlds_goal:
Remove the follow_vars field from calls, higher-order calls
and complicated unifications.
*.m:
Handle the new arities of calls, higher order calls and complicated
unifications.
mercury_compile:
Don't call follow_vars directly anymore, but do call lco if its option
is set. Also flush the main output before a call to maybe_report_stats
to prevent ugly output.
store_alloc:
Call follow_vars directly.
follow_vars:
Expose the initialization and traversal predicates for store_alloc.
lco:
Find opportunities for last call optimization modulo constructor
application.
passes_aux:
Add a HLDS traversal type for lco.
optimize:
Consider the vnrepeat count to be zero unless value numbering is on.
options:
Set the default value of vnrepeat to 1.
modules:
Don't refer to .err2 files.
|
||
|
|
9205a7e445 |
Module qualification of function calls and higher-order predicate constants.
Estimated hours taken: 6 Module qualification of function calls and higher-order predicate constants. compiler/hlds_data.m Changed the cons(string, arity) constructor of cons_id to cons(sym_name, arity). A module qualified cons_id is assumed to be a function or higher-order pred constant, since we don't yet support module qualification of constructors (Explicit type qualification is much more useful anyway, but that doesn't work yet either). compiler/hlds_goal.m Changed the functor(const, list(var)) constructor of unify_rhs to functor(cons_id, list(var)) to allow the storing of a module qualifier. compiler/make_hlds.m Parse qualified function calls and higher-order pred constants. compiler/modes.m compiler/intermod.m Take module qualifiers into account when resolving function overloading. compiler/*.m Updated unify_rhs's and cons_id's everywhere. |
||
|
|
03d1f75c7e |
These changes comprise
Estimated hours taken: 40 (including testing) These changes comprise * some configuration changes for accurate GC (setting -DNATIVE_GC, working out dependencies for accurate GC, new .agc grade) * liveness changes for supporting polymorphism in accurate GC * some support of polymorphism for GC (mostly consisting of keeping the typevar -> typinfo_var mappings (eg T in list(T) is stored in TypeInfo_For_T) and corresponing mappings into lvals at continuation labels. * changes required to data structures so that above changes could work. * cut down on the number of abstract exports handled by checking types to see whether they are imported (duh...) * don't use '-I' directories when searching for '.m' files. (since this will wrecks dependency generation in some situations). * don't lookup and create shape information when not doing accurate GC. (instead we just give back dummy values). |
||
|
|
5d9e4158f7 |
Module qualification of types, insts and modes.
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.
|
||
|
|
0e1e0b0b91 |
Implement recursive' and non_recursive' pragma c_code declarations.
Estimated hours taken: 4 Implement `recursive' and `non_recursive' pragma c_code declarations. This allows the compiler to optimize cases when the C code is known to not call Mercury code. It's also necessary to allow C code which modifies the hp register to work (such code must be declared `non_recursive', otherwise the registers will be saved and restored over it). To make things bootstrap OK, the old pragma c_code declarations default to `non_recursive'. prog_data.m, hlds_goal.m: Add new field c_is_recursive to pragma c_code goals. prog_io.m: Parse the new `recursive' and `non_recursive' pragma c_code declarations. make_hlds.m: Pass the c_is_recursive field from the parse tree to the HLDS. live_vars.m: For non-recursive C code, don't save variables on the stack. code_gen.pp: For non-recursive C code, don't save variables on the stack, don't mark the succip as needing to be saved, and don't call save_registers() and restore_registers(). *.m: Change c_code/5 to c_code/6. |
||
|
|
60b9fa83b6 |
Implement higher-order functions.
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. |
||
|
|
9a7da88ce0 |
Treat higher-order predicate calls as a new sort of goal,
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. |
||
|
|
649b6908c3 |
Rename branch_delay_slot to have_delay_slot.
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.) |
||
|
|
d344165793 |
Add a new option, --branch-delay-slot, intended for use by mc on
Estimated hours taken: 3 options: Add a new option, --branch-delay-slot, intended for use by mc on the basis of the configuattion script. It says whether the machine architecture has delays slots on branches. The setting of option should affect whether we set --optimize-delay-slots at -O2, but this doesn't work yet. hlds_goal: Add an extra field to hold follow_vars infromation to disjunctions, switches and if-then-elses. I intend to use this information to generate better code. *.m: Changes to accommodate the extra field. |
||
|
|
1c9dc0e499 |
Re-enable the optimization of not introducing separate
Estimated hours taken: 2 compiler/lambda.m: Re-enable the optimization of not introducing separate predicates for lambda expressions when not necessary, after fixing it so that it doesn't attempt to curry output arguments in cases such as lambda([Y::out] is det, q(_, Y)) where q/2 is declared as :- pred q(int::out, int::out) is det. |
||
|
|
2833bfffb7 |
Divided the old hlds.m into four files:
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.
|
||
|
|
3b36da6e77 |
Implement functional syntax. You can now use `:- func' in a similar manner
Estimated hours taken: 12 Implement functional syntax. You can now use `:- func' in a similar manner to `:- pred'. For example, `:- func foo(int, int) = int.' declares a function, and `:- mode foo(in, in) = out.' defines a mode for it. You can write clauses for functions, such as `foo(X, Y) = Z :- Z is 2*X + Y.' Any term in the head or body of a clause can be a function call, e.g. `bar(X, Y, foo(X, Y))'. Until we have implemented a proper Mercury debugger, this syntax should not be used (except that I might reimplement the functions provided by Prolog's is/2 predicate using this syntax, rather than the current special-case hack in the parser). prog_io.m: Add syntax for declaring and defining functions. Disallow the use of `=' to define modes, as in `:- mode foo = bar.' (Instead, you should use `::'. `==' is also allowed.) Also, use higher-order predicates to simplify some of the rather repetitious parsing code. mercury_to_mercury.m, mercury_to_goedel.m, make_hlds.m, modules.m: Handle new functional syntax. typecheck.m: Add support for functions, function types such as `func(int) = int', and currying. (But there's currently no equivalent to call/N for functions, so function types and currying aren't very useful yet.) undef_types.m: Add support for function types. modes.m: Convert function calls into predicate calls. (This must be done after typechecking is complete, so I put it in mode analysis.) hlds.m: Add new field `pred_or_func' to the pred_info. hlds_out.m: Print out the `pred_or_func' field. higher_order.m, unused_args.m, lambda.m, dnf.m: Pass extra pred_or_func argument to pred_info_init to specify that the thing being created is a predicate, not a function. constraint.m, dependency_graph.m, hlds_out.m: `mercury_output_mode_subdecl' has been renamed `mercury_output_pred_mode_subdecl'. prog_util.m: Add new predicate split_type_and_mode/3. llds.m: Print out /* code for predicate '*'/3 in mode 0 */ rather than /* code for predicate */3 in mode 0 */ to avoid a syntax error in the generated C code. |
||
|
|
6d7f4b9b30 |
Undo dylan's changes in the names of some library entities,
Estimated hours taken: 1.5 Undo dylan's changes in the names of some library entities, by applying the following sed script s/term_atom/term__atom/g s/term_string/term__string/g s/term_integer/term__integer/g s/term_float/term__float/g s/term_context/term__context/g s/term_functor/term__functor/g s/term_variable/term__variable/g s/_term__/_term_/g s/std_util__bool_/bool__/g to all the `.m' and `.pp' files in the compiler and library directories. The reason for undoing these changes was to minimize incompatibilities with 0.4 (and besides, the changes were not a really good idea in the first place). I also moved `bool' to a separate module. The main reason for that change is to ensure that the `__' prefix is only used when it genuinely represents a module qualifier. (That's what dylan's changes were trying to acheive, but `term__' does genuinely represent a module qualifier.) compiler/*.m: Apply sed script above; where appropriate, add `bool' to the list of imported modules. |
||
|
|
837661243b |
This check-in combines several changes.
Estimated hours taken: 16 This check-in combines several changes. * Change mercury_compile.pp so that it continues as far as possible after errors. * Split the parts of mercury_compile.pp which handle module imports and exports into a new module called `modules.m'. * Move the polymorphism.m pass after determinism analysis and unique mode checking. This is because unique_modes.m may change the mode in which a unification predicate is called; as a result, we need to do mode checking, determinism analysis, and unique mode checking for new modes of unification predicates which are requested only after unique mode checking. That won't work if we have done polymorphism.m in between mode checking and determinism analysis, since unification predicates are created without type_info arguments, and polymorphism.m cannot be run on just one predicate at a time. (NB. I haven't changed unique_modes.m to actually do this yet.) I also had to move lambda.m after polymorphism.m, since polymorphism.m doesn't handle higher-order pred constants. * Fix determinism analyis of simple_test unifications. The compiler would think that a unification of an inst such as `bound(foo)' with itself could fail. The problem is that there is no `can_fail' field for simple_test unifications, so determinism.m just assumes that they can all fail. I fixed this by changing modes.m to optimize away simple_tests that cannot fail. * Fix determinism analyis of complicated_unifications. Again, determinism analysis just assumed that all complicated_unifications were semidet, because unify_proc.m always declared the out-of-line unification predicates to be semidet. The fix was to pass the determinism inferred during mode analysis to unify_proc__request_unify. However, the '='(in, in) mode still needs to be semidet - its address is taken and put into the type_infos, and so it needs to have the right interface. To handle det '='(in, in) unifications, the determinism also needs to be passed to unify_proc__search_mode_num, which will select the '='(in, in) mode only if the determinism is semidet. (It would of course be better to optimize det '='(in, in) unifications to `true', but they are unlikely to occur much in real code anyway, so that is a low priority.) * Compute the instmap deltas for all variables, not just the non-local variables of a goal, because variables which are not present in a goal can become nondet live if the goal is e.g. a nondet call. mercury_compile.pp: - Rearrange the order of the passes as described above. - Add code to call check_undef_types and check_undef_modes directly rather than via typecheck.m/modes.m. Stop only if we get an undef error; if we get any other sort of type/mode error, we can keep going. - Move lots of code to modules.m. modules.m: New file, containing code moved from mercury_compile.pp. polymorphism.m: Make sure that the goals that we generate have the correct determinism annotations. Handle switches. Put back the call to lambda__transform_lambda. lambda.m: Put back the stuff that allowed lambda.m to be called from polymorphism.m. modes.m, unify_proc.m, call_gen.m, polymorphism.m, Pass the determinism of the unification to unify_proc__request_unify, so that it can declare the right determinism for the unification predicate. (Previously it just assumed that all complicated unifications were `semidet'.) Also pass the determinism to unify_proc__search_mode_num, so that it will generate a new unification pred for deterministic '='(in,in) unifications rather than calling the existing semidet one. modes.m, typecheck.m: Remove the calls to check_undefined_types and check_undefined_modes. They are now instead called directly from mercury_compile.pp. modes.m: Don't call lambda__transform_lambda. Optimize away simple_tests that cannot fail. modes.m, unique_modes.m: Call mode_info_get_instmap/2 rather than mode_info_get_vars_instmap/3. mode_info.m: Delete the predicate mode_info_get_vars_instmap/3. |
||
|
|
729c0a941c |
Rearrange the ordering of the different phases in the compiler.
Estimated hours taken: 6 Rearrange the ordering of the different phases in the compiler. Moved lambda elimination (lambda.m) after unique_modes.m, because mode analysis must have been fully completed before lambda elimination, so that we get the right mode on the introduced predicates. Also moved inlining.m and common.m after unique modes, since they are optimization passes, not semantic checking passes. The cse_detection.m, switch_detection.m, and determinism.m passes now need to recursively traverse lambda goals. (Previously they assumed that lambda goals had already been eliminated.) mercury_compile.pp: Move the inlining.m and common.m passes from semantic_phases to middle_phases. polymorphism.m: Remove the code which called lambda.m. switch_detection.m: Recursively traverse lambda goals. cse_detection.m: Recursively traverse lambda goals. Also, when redoing mode analysis and switch detection, we shouldn't reinvoke lambda.m. det_analysis.m, det_report.m: Recursively traverse lambda goals, check for determinism errors in them, and report them. Also, print the calling predicate name & mode in the error message for calls to predicates with cc_* determinism in all-solutions contexts. modes.m: Add an extra argument to modecheck_unification that specifies how we should recursively process lambda goals, so that we can do the right thing when called from unique_modes.m. The right thing in this case is to call unique_modes__check_goal instead of modecheck_goal, and to then invoke lambda__transform_lambda on the result. unique_modes.m: Make sure we don't clobber the predicate table, since we now indirectly call lambda__transform_lambda, which inserts new predicates into the table. Also, simplify the code a little and add a sanity check. lambda.m: Make some changes that were needed because lambda.m now comes directly after (unique_)modes.m not after polymorphism.m. |
||
|
|
20013e0829 |
Add the module name to name of LambdaGoal predicates.
Estimated hours taken: 0.2 Add the module name to name of LambdaGoal predicates. compiler/lambda.m: Prepend the module name to __LambdaGoal__, as name clashes occur with native gc (because static symbols become global). |
||
|
|
3ab8d92226 |
Change names with badly placed double underscores (ie where the part of
Estimated hours taken: _2___ Change names with badly placed double underscores (ie where the part of a name before a double underscore is not the same as the module name.) Reflect changes in the library interface. compiler/*: Use the newer, more correct form of the term and bool names. Predicates "bool__" are now "std_util__bool" and labels of the term ADT are now "term_" instead of "term__". compiler/vn*.m: change all names "vn__*" to a correct module prefix. All the names remain qualified. compiler/hlds.m: s/\<is_builtin__/hlds__is_builtin_/g s/\<dependency_info__/hlds__dependency_info_/g compiler/unify_proc.m: s/\<unify_proc_info__/unify_proc__info_/g compiler/transform.m: s/\<reschedule__conj/transform__reschedule_conj/g |
||
|
|
970bf7b2f1 |
Added better warnings and error messages. Fixed bug with having
Estimated hours taken: 3 Added better warnings and error messages. Fixed bug with having pragma(c_code, ...) decs for different modes of the same pred, and with having clauses and pragma(c_code, ...) decs. hlds.m: Added a fields to the pred_info indicating whether the pred contained pragma(c_code, ...) decs, clauses, or was currently empty. Also updated the access predicates, and require a new argument for pred_info_init lambda.m: Pass the new argument to pred_info_init make_hlds.m: Improve error messages and warnings. Fix bug with pragma decs for different modes, and bug with clauses an pragmas for same pred. |
||
|
|
0669cdd93a |
Fix design error which led to the bug reported by Philip Dart:
Estimated hours taken: 15 (Debugging 3 people * 3 hours, design 2 hours, coding 4 hours.) Fix design error which led to the bug reported by Philip Dart: cse_detection was reinvoking mode analysis, which converted higher-order pred terms into lambda expressions, but was not reinvoking polymorphism.m, and so they remained as lambda expressions, which caused the code generator to generate incorrect code. compiler/polymorphism.m: Move the stuff for handling lambda expressions into a new file lambda.m. compiler/lambda.m: New file. Contains the lambda expression handling stuff from polymorphism.m, plus new code to traverse the HLDS for a predicate applying this transformation to each lambda expression in the procedure bodies for that predicate. compiler/cse_detection.m: After re-running mode analysis, invoke lambda__process_pred to transform away lambda expressions. |