mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 14:25:56 +00:00
f007b45df8da9d0b6111713aeeb4c1f3aee18c93
23 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
10cea48947 |
Remove unneeded parentheses from module name.
Estimated hours taken: 0.1 Branches: main compiler/assertion.m: compiler/inst.m: Remove unneeded parentheses from module name. compiler/unneeded_code.m: Remove duplicate import. |
||
|
|
9551640f55 |
Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2 Branches: main compiler/*.m: Import only one compiler module per line. Sort the blocks of imports. This makes it easier to merge in changes. In a couple of places, remove unnecessary imports. |
||
|
|
ef7ed9c2f5 |
Support impurity declarations for higher-order code.
Estimated hours taken: 24 Branches: main Support impurity declarations for higher-order code. In particular, allow `impure' and `semipure' annotations on higher-order types, higher-order calls, and lambda expresions. NEWS: doc/reference_manual.texi: Document the new language feature. compiler/hlds_goal.m: compiler/hlds_pred.m: Add `purity' field to - the `higher_order' alternative of the hlds_goal.generic_call type - the `higher_order' alternative of the hlds_pred.generic_call_id type - the `lambda_goal' alternative of the hlds_goal.unify_rhs type compiler/type_util.m: Add a new `purity' argument to the procedures dealing with higher-order types. Add code for parsing impure/semipure higher-order types. compiler/lambda.m: compiler/make_hlds.m: compiler/typecheck.m: compiler/post_typecheck.m: compiler/purity.m: compiler/polymorphism.m: Various minor changes to support impure/semipure higher-order lambda expressions. compiler/polymorphism.m: compiler/pseudo_type_info.m: XXX ought to change these to include purity in the RTTI for higher-order function types. compiler/simplify.m: Don't try to optimize semipure/impure higher-order calls. compiler/assertion.m: compiler/bytecode_gen.m: compiler/call_gen.m: compiler/continuation_info.m: compiler/cse_detection.m: compiler/dead_proc_elim.m: compiler/deep_profiling.m: compiler/det_analysis.m: compiler/det_util.m: compiler/equiv_type.m: compiler/goal_util.m: compiler/higher_order.m: compiler/hlds_out.m: compiler/intermod.m: compiler/magic.m: compiler/magic_util.m: compiler/ml_call_gen.m: compiler/ml_closure_gen.m: compiler/mode_util.m: compiler/modecheck_call.m: compiler/modecheck_unify.m: compiler/modes.m: compiler/module_qual.m: compiler/pd_util.m: compiler/prog_rep.m: compiler/pseudo_type_info.m: compiler/quantification.m: compiler/recompilation.usage.m: compiler/rl_gen.m: compiler/stratify.m: compiler/switch_detection.m: compiler/term_traversal.m: compiler/term_util.m: compiler/unify_gen.m: compiler/unique_modes.m: Trivial changes to handle the new purity fields and/or arguments. tests/hard_coded/purity/Mmakefile: tests/hard_coded/purity/impure_func_t5_fixed2.m: tests/hard_coded/purity/impure_func_t5_fixed2.exp: tests/hard_coded/purity/impure_func_t5_fixed2.exp2: tests/hard_coded/purity/impure_pred_t1_fixed3.m: tests/hard_coded/purity/impure_pred_t1_fixed3.exp: tests/invalid/purity/Mmakefile: tests/invalid/purity/impure_func_t5_fixed.m: tests/invalid/purity/impure_func_t5_fixed.err_exp: tests/invalid/purity/impure_pred_t1_fixed.m: tests/invalid/purity/impure_pred_t1_fixed.err_exp: Add new test cases to test the new feature. tests/invalid/purity/impure_func_t5.err_exp: tests/invalid/purity/impure_pred_t1.err_exp: tests/invalid/purity/impure_pred_t2.err_exp: tests/invalid/purity/purity.err_exp: tests/invalid/purity/purity_nonsense.err_exp: Update the expected error messages for existing test cases. tests/invalid/purity/.cvsignore: New file, copied from tests/invalid/.cvsignore. |
||
|
|
681d78c92b |
Fix a bug which caused misleading error messages when
Estimated hours taken: 1
Branches: main
Fix a bug which caused misleading error messages when
the module qualifier for an undefined symbol matched a
module imported only by ancestor modules.
compiler/make_hlds.m:
Add modules imported by ancestor modules to the list
of imported modules.
compiler/modules.m:
compiler/prog_data.m:
compiler/hlds_pred.m:
compiler/*.m:
Record which items are imported from ancestor modules.
Reorder the arguments of `modules__append_pseudo_decl'
to make it easier to use with state variables.
Use state variable syntax in `modules__grab_imported_modules'.
compiler/hlds_module.m:
Remove an XXX comment documenting this bug.
configure.in:
Check for state variable syntax when checking whether
the compiler is up-to-date.
tests/invalid/Mmakefile:
tests/invalid/import_in_parent.{m,err_exp}:
Test case.
|
||
|
|
9dbcf4714a |
Fix a bug which caused type-incorrect HLDS to be generated by mode
Estimated hours taken: 5
Branches: main
Fix a bug which caused type-incorrect HLDS to be generated by mode
analysis, which then caused a compiler abort in simplification.
In the code below, mode analysis must treat the headvar unification
as a construction followed by a var-var unification. If it is treated
as a deconstruction, the argument unifications will be ill-typed.
:- type t ---> some [T] f(T) => enum(T).
:- pred p(t::in) is semidet.
p('new f'(1)).
compiler/modecheck_unify.m:
Make sure unifications with a RHS of the form 'new f(X)'
are always classified as constructions.
compiler/hlds_goal.m:
compiler/*.m:
Add a field to var-functor unifications which identifies
those which must be treated as constructions.
compiler/polymorphism.m:
Fill in the field.
tests/hard_coded/Mmakefile:
tests/hard_coded/unify_existq_cons.{m,exp}:
Test case.
|
||
|
|
189b9215ae |
This diff implements stack slot optimization for the LLDS back end based on
Estimated hours taken: 400
Branches: main
This diff implements stack slot optimization for the LLDS back end based on
the idea that after a unification such as A = f(B, C, D), saving the
variable A on the stack indirectly also saves the values of B, C and D.
Figuring out what subset of {B,C,D} to access via A and what subset to access
via their own stack slots is a tricky optimization problem. The algorithm we
use to solve it is described in the paper "Using the heap to eliminate stack
accesses" by Zoltan Somogyi and Peter Stuckey, available in ~zs/rep/stackslot.
That paper also describes (and has examples of) the source-to-source
transformation that implements the optimization.
The optimization needs to know what variables are flushed at call sites
and at program points that establish resume points (e.g. entries to
disjunctions and if-then-elses). We already had code to compute this
information in live_vars.m, but this code was being invoked too late.
This diff modifies live_vars.m to allow it to be invoked both by the stack
slot optimization transformation and by the code generator, and allows its
function to be tailored to the requirements of each invocation.
The information computed by live_vars.m is specific to the LLDS back end,
since the MLDS back ends do not (yet) have the same control over stack
frame layout. We therefore store this information in a new back end specific
field in goal_infos. For uniformity, we make all the other existing back end
specific fields in goal_infos, as well as the similarly back end specific
store map field of goal_exprs, subfields of this new field. This happens
to significantly reduce the sizes of goal_infos.
To allow a more meaningful comparison of the gains produced by the new
optimization, do not save any variables across erroneous calls even if
the new optimization is not enabled.
compiler/stack_opt.m:
New module containing the code that performs the transformation
to optimize stack slot usage.
compiler/matching.m:
New module containing an algorithm for maximal matching in bipartite
graphs, specialized for the graphs needed by stack_opt.m.
compiler/mercury_compile.m:
Invoke the new optimization if the options ask for it.
compiler/stack_alloc.m:
New module containing code that is shared between the old,
non-optimizing stack slot allocation system and the new, optimizing
stack slot allocation system, and the code for actually allocating
stack slots in the absence of optimization.
Live_vars.m used to have two tasks: find out what variables need to be
saved on the stack, and allocating those variables to stack slots.
Live_vars.m now does only the first task; stack_alloc.m now does
the second, using code that used to be in live_vars.m.
compiler/trace_params:
Add a new function to test the trace level, which returns yes if we
want to preserve the values of the input headvars.
compiler/notes/compiler_design.html:
Document the new modules (as well as trace_params.m, which wasn't
documented earlier).
compiler/live_vars.m:
Delete the code that is now in stack_alloc.m and graph_colour.m.
Separate out the kinds of stack uses due to nondeterminism: the stack
slots used by nondet calls, and the stack slots used by resumption
points, in order to allow the reuse of stack slots used by resumption
points after execution has left their scope. This should allow the
same stack slots to be used by different variables in the resumption
point at the start of an else branch and nondet calls in the then
branch, since the resumption point of the else branch is not in effect
when the then branch is executed.
If the new option --opt-no-return-calls is set, then say that we do not
need to save any values across erroneous calls.
Use type classes to allow the information generated by this module
to be recorded in the way required by its invoker.
Package up the data structures being passed around readonly into a
single tuple.
compiler/store_alloc.m:
Allow this module to be invoked by stack_opt.m without invoking the
follow_vars transformation, since applying follow_vars before the form
of the HLDS code is otherwise final can be a pessimization.
Make the module_info a part of the record containing the readonly data
passed around during the traversal.
compiler/common.m:
Do not delete or move around unifications created by stack_opt.m.
compiler/call_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/var_locn.m:
Allow the code generator to delete its last record of the location
of a value when generating code to make an erroneous call, if the new
--opt-no-return-calls option is set.
compiler/code_gen.m:
Use a more useful algorithm to create the messages/comments that
we put into incr_sp instructions, e.g. by distinguishing between
predicates and functions. This is to allow the new scripts in the
tool directory to gather statistics about the effect of the
optimization on stack frame sizes.
library/exception.m:
Make a hand-written incr_sp follow the new pattern.
compiler/arg_info.m:
Add predicates to figure out the set of input, output and unused
arguments of a procedure in several different circumstances.
Previously, variants of these predicates were repeated in several
places.
compiler/goal_util.m:
Export some previously private utility predicates.
compiler/handle_options.m:
Turn off stack slot optimizations when debugging, unless
--trace-optimized is set.
Add a new dump format useful for debugging --optimize-saved-vars.
compiler/hlds_llds.m:
New module for handling all the stuff specific to the LLDS back end
in HLDS goal_infos.
compiler/hlds_goal.m:
Move all the relevant stuff into the new back end specific field
in goal_infos.
compiler/notes/allocation.html:
Update the documentation of store maps to reflect their movement
into a subfield of goal_infos.
compiler/*.m:
Minor changes to accomodate the placement of all back end specific
information about goals from goal_exprs and individual fields of
goal_infos into a new field in goal_infos that gathers together
all back end specific information.
compiler/use_local_vars.m:
Look for sequences in which several instructions use a fake register
or stack slot as a base register pointing to a cell, and make those
instructions use a local variable instead.
Without this, a key assumption of the stack slot optimization,
that accessing a field in a cell costs only one load or store
instruction, would be much less likely to be true. (With this
optimization, the assumption will be false only if the C compiler's
code generator runs out of registers in a basic block, which for
the code we generate should be unlikely even on x86s.)
compiler/options.m:
Make the old option --optimize-saved-vars ask for both the old stack
slot optimization (implemented by saved_vars.m) that only eliminates
the storing of constants in stack slots, and the new optimization.
Add two new options --optimize-saved-vars-{const,cell} to turn on
the two optimizations separately.
Add a bunch of options to specify the parameters of the new
optimizations, both in stack_opt.m and use_local_vars.m. These are
for implementors only; they are deliberately not documented.
Add a new option, --opt-no-return-cells, that governs whether we avoid
saving variables on the stack at calls that cannot return, either by
succeeding or by failing. This is for implementors only, and thus
deliberately documented only in comments. It is enabled by default.
compiler/optimize.m:
Transmit the value of a new option to use_local_vars.m.
doc/user_guide.texi:
Update the documentation of --optimize-saved-vars.
library/tree234.m:
Undo a previous change of mine that effectively applied this
optimization by hand. That change complicated the code, and now
the compiler can do the optimization automatically.
tools/extract_incr_sp:
A new script for extracting stack frame sizes and messages from
stack increment operations in the C code for LLDS grades.
tools/frame_sizes:
A new script that uses extract_incr_sp to extract information about
stack frame sizes from the C files saved from a stage 2 directory
by makebatch and summarizes the resulting information.
tools/avg_frame_size:
A new script that computes average stack frame sizes from the files
created by frame_sizes.
tools/compare_frame_sizes:
A new script that compares the stack frame size information
extracted from two different stage 2 directories by frame_sizes,
reporting on both average stack frame sizes and on specific procedures
that have different stack frame sizes in the two versions.
|
||
|
|
7597790760 |
Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure of the compiler clearer, and to encourage better encapsulation of the major components. compiler/libs.m: compiler/backend_libs.m: compiler/parse_tree.m: compiler/hlds.m: compiler/check_hlds.m: compiler/transform_hlds.m: compiler/bytecode_backend.m: compiler/aditi_backend.m: compiler/ml_backend.m: compiler/ll_backend.m: compiler/top_level.m: New files. One module for each of the major components of the Mercury compiler. These modules contain (as separate sub-modules) all the other modules in the Mercury compiler, except gcc.m and mlds_to_gcc.m. Mmakefile: compiler/Mmakefile: Handle the fact that the top-level module is now `top_level', not `mercury_compile' (since `mercury_compile' is a sub-module of `top_level'). compiler/Mmakefile: Update settings of *FLAGS-<modulename> to use the appropriate nested module names. compiler/recompilation_check.m: compiler/recompilation_version.m: compiler/recompilation_usage.m: compiler/recompilation.check.m: compiler/recompilation.version.m: compiler/recompilation.version.m: Convert the `recompilation_*' modules into sub-modules of the `recompilation' module. compiler/*.m: compiler/*.pp: Module-qualify the module names in `:- module', `:- import_module', and `:- use_module' declarations. compiler/base_type_info.m: compiler/base_type_layout.m: Deleted these unused empty modules. compiler/prog_data.m: compiler/globals.m: Move the `foreign_language' type from prog_data to globals. compiler/mlds.m: compiler/ml_util.m: compiler/mlds_to_il.m: Import `globals', for `foreign_language'. Mmake.common.in: trace/Mmakefile: runtime/Mmakefile: Rename the %.check.c targets as %.check_hdr.c, to avoid conflicts with compiler/recompilation.check.c. |
||
|
|
41a27af862 |
Change type_id to the more descriptive type_ctor everywhere.
Estimated hours taken: 6 Branches: main compiler/*.m: Change type_id to the more descriptive type_ctor everywhere. |
||
|
|
c0ec782364 |
Added initial error checking of promise ex declarations, and adding
Estimated hours taken: 150 Branches: main Added initial error checking of promise ex declarations, and adding the declarations into the HLDS as dummy predicates to leverage off the error checking done for predicates (similarly to how assertions were done). Following this, `promise_exclusive' and `promise_exclusive_exhaustive' declarations are added into a separate table in the HLDS. assertion.m: Moved the pred declaration for assertion__normalise_goal into the interface. goal_util.m: Added a predicate to get the predids of a goal or list of goals. hlds_data.m: hlds_module.m: Added exclusive_table to HLDS, and operations on it. hlds_out.m: Added printing of promise ex declaration error messages (also improves assertion error messages). hlds_pred.m: Change to type `goal_type' to add constructor for general promise declarations (merged with assertions). dead_proc_elim.m: error_util.m: intermod.m: typecheck.m: Updated to handle promise declarations similarly to how assertions were handled. make_hlds.m: Perform initial typechecking of promise ex declarations, then add them to the HLDS as dummy predicates. purity.m: post_typecheck.m: Post typechecking routine to add exclusivity declarations to the exclusive_table. |
||
|
|
cdbbaa5ac2 |
Support multiple language foreign_procs in the one file.
Estimated hours taken: 16 Branches: main Support multiple language foreign_procs in the one file. If there is more then one applicable foreign_proc for a given clause, select the most "preferred" programming language to use as the implementation. Currently only the IL backend has multiple languages supported by the backend, and C# is preferred over MC++. compiler/options.m: compiler/handle_options.m: Rename backend_foreign_language as backend_foreign_languages, and use it to record the list of foreign languages the selected backend can handle. Remove --use-foreign-language as it doesn't do anything right now. compiler/foreign.m: Update code to use the list of backend foreign languages. Add prefer_foreign_language function, to compute the preferred foreign language ordering for each backend. Move simple_foreign_language_string here from globals.m, and add foreign_language_file_extension and foreign_language_module_name functions. (much of the rest of the code in this module is intended to deal with the case where the backend *doesn't* handle the foreign language, but we don't have any working support for that at the moment). compiler/globals.m: Add globals__io_get_backend_foreign_languages and globals__get_backend_foreign_languages. compiler/make_hlds.m: Handle selection of foreign_proc code depending upon the preferred language. Rename a few *_foreign_code predicates as *_foreign_proc predicates. Handle the extra field in clause. compiler/ml_code_gen.m: compiler/mlds.m: Generate different mlds__foreign_code for each language (only one language is selected for each predicate, but there can be multiple languages in the onle module). and put them in a map which is indexed on foreign language. compiler/modules.m: Generate appropriate dependencies for foreign language modules. We now record which languages a list of items uses (taking into account the preferred foreign language for foreign_proc). We also allow for the fact that some foreign_proc declarations won't generate any external modules. compiler/hlds_pred.m: Add an extra field to clause which records which language this clause has been implemented in. compiler/assertion.m: compiler/clause_to_proc.m: compiler/dead_proc_elim.m: compiler/goal_util.m: compiler/hlds_out.m: compiler/inlining.m: compiler/intermod.m: compiler/modes.m: compiler/polymorphism.m: compiler/purity.m: compiler/typecheck.m: compiler/unify_proc.m: Handle the extra field in clause. compiler/mlds_to_c.m: compiler/mlds_to_csharp.m: compiler/mlds_to_gcc.m: compiler/mlds_to_mcpp.m: Select the appropriate mlds__foreign code from the map and generate code for it. |
||
|
|
1c65d003f7 |
Add the shorthand_goal_expr wrapper type to ease hlds->hlds transformations.
Estimated hours taken: 4.5
Branches: main
Add the shorthand_goal_expr wrapper type to ease hlds->hlds transformations.
compiler/hlds_goal.m
Create a new type, the `shorthand_goal_expr', for goals kinds that
are implemented by a (ordinary_hlds + shorthand) -> (ordinary_hlds)
transformation. At present, bi_implication is the only kind of
of goal that is implemented in this way.
Moved bi_implication functor from the type goal_expr to the new
shorthand_goal_expr type.
Added the functor shorthand to the goal_expr type.
compiler/*.m
Change switches on hlds_goal_expr that call error when they recognise
`bi_implication' from calling error when they recognise
`bi_implication' to calling error when they recognise `shorthand'.
For all predicates K that
a) switch on hlds_goal_expr and
b) perform non-trivial processing when they recognise
`bi_implication'
change K such that it now calls K_shorthand upon recognising the
functor `shorthand'. Define K_shorthand to switch on
shorthand_goal_expr, where the code for the `bi_implication' case
formerly contained in K is now contained in K_shorthand.
|
||
|
|
711da78188 |
Rename foreign_code as foreign_proc where appropriate in the compiler.
Estimated hours taken: 4.0 Branches: main Rename foreign_code as foreign_proc where appropriate in the compiler. The rationale for this change is that it makes maintaining the code much simpler because it is clear whether `foreign' refers to a slab of code (foreign_code) or a procedure (foreign_proc). :- type pragma_foreign_code_attributes :- type pragma_foreign_proc_attributes The functors for pragma_type foreign(Lang, BodyCode) foreign(Attributes, Name, PredOrFunc, Vars, Varset, Impl) become foreign_code(Lang, BodyCode) foreign_proc(Attributes, Name, PredOrFunc, Vars, Varset, Impl) And the HLDS goal `pragma_foreign_code' becomes `foreign_proc'. compiler/*.m: Update the compiler to use the new names. |
||
|
|
15f0e17ab7 |
Merge changes from the reuse branch to the main branch.
Estimated hours taken: 1
Branches: main
Merge changes from the reuse branch to the main branch.
This change introduces a new import_status opt_exported.
A local predicate which appeared in a .opt file (even if it was only a
call to that predicate) needs to have its export status changed to
exported so that an entry point to that predicate is available. This
can confuse the structure reuse analysis, so we added the new
import_status: opt_exported.
compiler/hlds_pred.m:
Add opt_exported to the import_status, and adapt the predicates
corresponding predicates.
compiler/intermod.m:
When the status of a local predicate is changed due to its presence
in the .opt file, this status is now set to opt_exported instead of
exported.
compiler/unused_args.m:
When we check for pred_info_is_exported, also check for
pred_info_is_opt_exported.
compiler/termination.m:
Write out termination info pragmas for opt_exported procedures.
compiler/assertion.m:
compiler/hlds_out.m:
Minor changes.
|
||
|
|
ef91da404e |
Fix the handling of procedures declared `external' for the MLDS back-end.
Estimated hours taken: 3 Fix the handling of procedures declared `external' for the MLDS back-end. This change fixes some problems that broke many of the test cases in tests/valid in the hl*prof* grades. compiler/hlds_pred.m: Add `external' as a new import_status, rather than using `imported'. compiler/assertion.m: compiler/higher_order.m: compiler/hlds_out.m: compiler/hlds_pred.m: compiler/intermod.m: compiler/make_hlds.m: Minor changes to handle the new import_status. compiler/mlds.m: Add a comment about the handling of procedures declared `:- external'. compiler/ml_code_gen.m: Generate MLDS function definitions, with no function body, for procedures declared `external'. compiler/mlds_to_c.m: Declare private functions with no function body as `extern' rather than `static'. |
||
|
|
477ecb18f6 |
Implement pragma foreign_code for Managed C++.
Estimated hours taken: 60 Implement pragma foreign_code for Managed C++. Currently you can only write MC++ code if your backend is capable of generating use MC++ as its "native" foreign language. The IL backend is the only backend that does this at the moment (the other backends have C as their "native" foreign language). Most of the machinery is in place to call from C to (normal) C++ but there is little work done on actually spitting out the C++ code into a separate file. The IL backend does this step already with managed C++. The intention is to turn foreign_code for C++ into a pragma import (which imports the C++ function from a separate file) and foreign_code for C (which calls the imported function). The C++ code will be inserted into a separate file that is compiled using C linkage. The important improvement this change gives is that you can write a module with a C and a MC++ implementations side-by-side. The target backend will select the most appropriate foreign language to use. You can override its choice using --use-foreign-language. Later on we will probably want more flexibility than just a single language selection option). This change also implements :- pragma foreign_decl, which allows header file style declarations to be written in languages other than C. compiler/code_gen.m: Reject code that is not C when generating LLDS. compiler/export.m: Start renaming C as foreign. Reject code that is not C when generating exports. compiler/foreign.m: A new module to handle foreign language interfacing. The bulk of the code for pragma import has been moved here from make_hlds. compiler/globals.m: Convert foreign language names to foreign_language. This code has been moved closer to the similar conversion we do for target language names. Add globals__io_lookup_foreign_language_option to make it easier to deterministically lookup the options relating to foreign languages. compiler/hlds_module.m: Move module_add_foreign_decl and module_add_foreign_body_code from make_hlds.m (where they were called module_add_c_header and module_add_c_code). compiler/hlds_out.m: Write the foreign language out in HLDS dumps. compiler/llds.m: Change foreign_header_info to foreign_decl_info. Change definitions of foreign_decl_code and foreign_body_code to include the language. compiler/llds_out.m: Reject code that is not C when writing out LLDS. compiler/make_hlds.m: Add foreign language information to the bodys and decls when creating them. Update error messages to refer to foreign code instead of C code. Use foreign.m to generate interfaces from the backend language to the foreign language. Hardcode C as the language for fact tables. compiler/mercury_compile.m: Collect the appropriate foreign language code together for output to the backend. compiler/intermod.m: compiler/mercury_to_mercury.m: Output the foreign language string. Change a few names to foreign_code instead of c_code. compiler/ml_code_gen.m: Filter the foreign language bodys and decls so that we only get the ones we are in (given by the use-foreign-language option). compiler/mlds_to_c.m: Abort if we are given non C foreign language code to output (we might handle it here in future, or we might handle it elsewhere). compiler/mlds_to_ilasm.m: Abort if we are given non MC++ foreign language code to output (we might handle it here in future, or we might handle it elsewhere). compiler/options.m: compiler/handle_options.m: Add --use-foreign-language as a user option to control the preferred foreign language to use as the implementation of this module. Add backend_foreign_language as an internal option which stores the foreign language that the compiler will use as a default (e.g. the natural foreign language for the backend to use). Set the preferred backend foreign language depending on the target. compiler/prog_data.m: Add managedcplusplus as a new alternative for the foreign_language type. Make c_header_code into foreign_decl. Give the foreign language for foreign_code as an attribute of the code. Write code to turn attributes into a list of strings (suitable for writing out by mercury_to_mercury). This fixes what appears to be a bug in tabled_for_io -- the tabled_for_io attribute was not being written out. Structure the code so this bug is difficult to repeat in future. compiler/prog_io_pragma.m: Parse foreign_decl. Turn c_header_code into a special case of foreign_decl. compiler/*.m: Remove the language field from pragma_foreign_code, it is now an attribute of the code. Various type and variable renamings. tests/invalid/pragma_c_code_and_clauses1.err_exp: tests/invalid/pragma_c_code_dup_var.err_exp: tests/warnings/singleton_test.exp: Update the tests to reflect the new error messages talking about :- pragma foreign_code rather than :- pragma c_code. |
||
|
|
c192d50143 |
Add preliminary support for a new pragma:
Estimated hours taken: 15 Add preliminary support for a new pragma: :- pragma foreign_code(LanguageString, .... <same args as c_code>). This is intended to be the eventual replacement of pragma c_code. Presently the only valid language is "C". The existing pragma c_code is simply turned into pragma foreign_code. pragma foreign_code is not a supported pragma at the moment. There are several other changes that are intended (for example, foreign_code will be impure by default). This change also changes the HLDS goal pragma_c_code/7 to pragma_foreign_code/8 where the extra argument is the foreign language. Any code currently generating output for pragma C code simply checks that the foreign language is set to "c". Since this is the only alternative of the type foreign_language, it will always succeed. However when new alternatives are added it should be fairly easy to find where the changes need to be made. Some type names and predicate names have also been updated, however there are many more that haven't yet been touched. compiler/prog_io_pragma.m: Accept the new syntax. Turn the old syntax into the new item. compiler/hlds_goal.m: Change pragma_c_code/7 to pragma_foreign_code/8. Define the foreign_language type. compiler/llds.m: Change user_c_code/2 to user_foreign_code/3. compiler/*.m: Update the rest of the compiler to handle these types. Make a few small changes to update variable names, predicate names and type names. |
||
|
|
05042c60ca |
Rewrite the accumulator introduction algorithm, so that it is a
Estimated hours taken: 70
Rewrite the accumulator introduction algorithm, so that it is a
combination of the algorithms presented in "Making Mercury Programs Tail
Recursive" and "State Update Transformation".
compiler/accumulator.m:
Rewrite and fix two bugs.
The bugs fixed were
* construction unifications which depend on associative calls
are handled correctly (not a problem in 0.9.x as the only
associative call it handled was list__append).
* that commutativity implied associativity, now check to see
whether an associative predicate has the addition property of
commutativity.
compiler/assertion.m:
assertion__is_associativity_assertion now reports the output
variable which is constructed from the two associative input
variables. It can now also handle the case where there is no
explicit existential quantification.
Add assertion__is_construction_equivalence_assertion which
recognises when a predicate is equivalent with a constrution
unification.
Add assertion__is_update_assertion which recognises when a predicate
can update some state in an arbitary order.
compiler/goal_store.m:
A module to associate arbitrary Ids with a hlds_goal and the instmap
before the goal.
library/int.m:
Add associativity declarations for + and *.
library/list.m:
Add the law
:- promise all [L,H,T] ( L = [H|T] <=> list__append([H], T, L)).
|
||
|
|
d79cc30587 |
Recognise associativity assertions, and use them to introduce
Estimated hours taken: 35
Recognise associativity assertions, and use them to introduce
accumulators.
mercury/compiler/assertion.m:
Add assertion__is_associativity_assertion, which for an assert_id
determines whether the assertion is associative.
mercury/compiler/accumulator.m:
Call assertion__is_associativity_assertion to determine whether a
call is associative.
Rather than failing if a call is associative and nothing is known
about the effect of rearranging the argument order, report a
suppressible warning.
Fix a bug where the mode of the introduced pred wasn't correct.
mercury/compiler/mercury_compile.m:
Move accumulator introduction before inlining and unused_args, as
inlining can inline an associative call making it unrecognisable and
unused_args eliminates arguments which make it difficult to relate
the assertion with the actual call.
mercury/compiler/notes/compiler_design.html:
Document the constraints on when the module accumulator.m can be
called for it to be effective.
mercury/compiler/options.m:
Add the new option "--inhibit-accumulator-warnings".
mercury/doc/user_guide.texi:
Document "--inhibit-accumulator-warnings".
mercury/library/list.m:
Declare list__append to be associative.
tests/general/accumulator/runtests:
Turn the tests back on, they *should* work under different
optimization levels now.
tests/warnings/Mmakefile:
tests/warnings/arg_order_rearrangment.exp:
tests/warnings/arg_order_rearrangment.m:
Test that a warning is output when accumulator introduction reorders
the arguments to a call without knowing the performance
implications.
|
||
|
|
ed9bb38494 |
Change from :- assertion' to :- promise'.
Estimated hours taken: 2
Change from `:- assertion' to `:- promise'.
compiler/assertion.m:
compiler/error_util.m:
compiler/hlds_data.m:
compiler/hlds_out.m:
compiler/make_hlds.m:
compiler/mercury_to_goedel.m:
compiler/mercury_to_mercury.m:
compiler/prog_io.m:
compiler/notes/glossary.html:
doc/transition_guide.texi:
library/ops.m:
Change all externally visible references to promise from assertion.
|
||
|
|
e7c2bb3059 |
Assertion declarations in the interface must not contain any symbols from
Estimated hours taken: 26
Assertion declarations in the interface must not contain any symbols from
modules imported only in the implementation. This constraint requires
that each imported symbol be annotated with whether it is imported from
the interface or implementation.
compiler/prog_data.m:
Update the pseudo declaration `:- imported' to include which section
(either implementation or interface) the items following it were
imported from.
compiler/modules.m:
Add a new version of get_dependencies, which divides the modules up
into those imported in the interface and implementation.
Use the new version of get_dependencies to place the new form of
`:- imported' declarations at the start of items from different
sections.
compiler/hlds_pred.m:
Add a new field to the imported data constructor in the type
import_status, which records in which section the symbol was
imported in.
compiler/make_hlds.m:
Modify module_defn_update_import_status so that it now records from
which section a symbol is imported.
compiler/module_qual.m:
Any unqualified symbol in an assertion might come from *any*
of the imported modules, so turn off the warning about modules which
are imported in the interface but not used, if an unqualified symbol
appears in the assertion.
compiler/assertion.m:
Use where a symbol is imported from when deciding whether an
assertion in the interface is valid.
Call module_info_incr_errors whenever an error message is written.
compiler/dead_proc_elim.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/unused_args.m:
Updates to use the new form of the data constructor imported.
|
||
|
|
d551dd1dc9 |
Handle quantification analysis of bi-implication (`<=>') goals correctly.
Estimated hours taken: 10
Handle quantification analysis of bi-implication (`<=>') goals correctly.
Previously we used to expand bi-implications before doing quantification
analysis, which stuffed up the results of quantification analysis for
those goals. We need to do quantification analysis first, and only
then can we expand bi-implications. In addition, elimination of double
negation needs to come after expansion of bi-implication, so I moved
that from make_hlds.m to purity.m.
compiler/hlds_goal.m:
Add a new alternative to the HLDS goal type for bi-implications.
Also add a new predicate negate_goal, for use by purity.m.
compiler/make_hlds.m:
Don't expand bi-implication here, instead just use the new
bi_implication/2 HLDS goal type.
Don't eliminated double negation here.
compiler/quantification.m:
Handle quantification for bi-implications.
Expand bi-implications.
compiler/purity.m:
Eliminate double negation.
compiler/hlds_out.m:
Add code to print out bi-implication goals.
compiler/*.m:
Trivial changes to handle the new bi_implication/2
alternative in the HLDS goal type.
compiler/notes/compiler_design.html:
Document the above changes.
tests/hard_coded/Mmakefile:
tests/hard_coded/quantifier2.m:
tests/hard_coded/quantifier2.exp:
A regression test for the above change.
|
||
|
|
79ab7d373d |
Extend the assertion system by
Estimated hours taken: 56
Extend the assertion system by
* handling assertions in the interface of a module differently to
those in the implementation.
* testing an assertion for the commutivity property.
compiler/polymorphism.m:
Remove the resolving of function calls and data constructors, do it
in post_typecheck instead so that assertions are fully resolved.
compiler/post_typecheck.m:
Add the resolving of function calls and data constructors.
Also call assertion__in_interface_check, if an assertion is in the
interface.
compiler/purity.m:
post_typecheck__finish_assertion can now print error messages so
pass the io__states.
compiler/hlds_data.m:
Add assertion_table_pred_ids, so that intermod knows which pred_ids
are assertions.
compiler/hlds_out.m:
Add predicate hlds_out__write_assertion, which is used by intermod
to write assertions to .opt files.
Change the behaviour of outputing a call, so that if the call is a
function it gets written out in functional syntax. This is
necessary because the resolving of function symbols now occurs in
post_typecheck (pre writing .opt files) rather than in polymorphism
(post writing .opt files).
compiler/intermod.m:
Change intermod so that it writes out any assertion in the
interface to the .opt file.
compiler/modules.m:
Ensure that assertions in the interface are not written to the
.int files. Assertions should only appear in .opt files.
compiler/dead_proc_elim.m:
When intermodule optimization is turned on dead_proc_elim gets run
before typechecking and the assertion predicates are removed. This
change makes dead_proc_elim keep assertions.
compiler/make_hlds.m:
The head variables for an assertion are already known, so initialise
the clause_info structure to those variables rather then creating
Arity fresh variables.
Also don't insert unifications with the head of the assertion, since
we already know that only variables are in the head.
compiler/goal_util.m:
Add mode `goal_calls_pred_id(in, out) is nondet' for use by
assertion__record_preds_used_in.
compiler/assertion.m:
Add a predicate assertion__is_comutativity_assertion, which given
an assertion_id determines whether or not that assertion declares
the commutivity of a pred/func.
Add a predicate assertion__in_interface_check, which checks that an
assertion doesn't refer to any constructors, functions and
predicates defined in the implementation of that module (note
doesn't handle modules imported in the implementation section
correctly).
Rewrite assertion__record_preds_used_in to use the nondet mode of
goal_calls_pred_id.
compiler/accumulator.m:
Remove the facts which declare '+' and '*' to be commutative, and
instead use the new assertion__is_commutivity_assertion predicate.
Also remove the bool from assoc_fact which is the commutivity of the
predicate, since only associative predicates reside in the table
now.
library/int.m:
Add commutivity declarations for '+' and '*', now that they have
been removed from the assoc_fact table. This allows me to test that
all of these changes actually work!
compiler/hlds_goal.m:
Clear up the documentation (I hope) for the type call_unify_context,
so that it is clear that the unification may also have been a
function application.
doc/reference_manual.texi:
doc/transition_guide.texi:
Document assertions.
|
||
|
|
88c3e52881 |
Record in which predicate an assertion is used.
Estimated hours taken: 8
Record in which predicate an assertion is used.
compiler/accumulator.m:
compiler/lambda.m:
compiler/magic.m:
Initialise the assertions field in the new pred_info.
compiler/assertion.m:
An abstract interface to the assertion table (hopefully).
compiler/hlds_data.m:
Modify assertion_table_add_assertion to return the assert_id of the
inserted assertion.
compiler/hlds_pred.m:
Record in the pred_info the set of assertions that mention the pred.
compiler/post_typecheck.m:
Now record which predicates are used in assertions.
compiler/notes/compiler_design.html:
Document assertion.m
|