mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 21:35:49 +00:00
672f77c4ecd07daaf01217bc81c336dcf5d6aa02
28 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
e8e1690475 |
The following code causes code to be generated which seg-faults
Estimated hours taken: 2
Branches: main
The following code causes code to be generated which seg-faults
:- interface
:- instance tc(list(T)).
:- implementation.
:- instance tc(list(T)) <= tc(T) where [...].
because the exported instance declaration doesn't contain the
typeclass constraint.
mercury/compiler/add_class.m:
Check that for all the "same" instance declarations
the instance constraints are exactly the same on each
declaration.
tests/invalid/incompatible_instance_constraints*:
Add tests for this code.
tests/invalid/*:
Fix some headvar name errors.
tests/valid/*:
Fix some invalid abstract instance declarations.
|
||
|
|
27aaaf412c |
Fix the failure of the invalid/modes_erroneous test case, whose symptom was
Estimated hours taken: 5 Branches: main Fix the failure of the invalid/modes_erroneous test case, whose symptom was an error message about a "mode error in unification of `X' and `X'". The root cause of the problem was that the renaming of head variables computed by headvar_names.m was being applied too early, during typechecking. The fix is to apply it after the frontend (all the passes that can generate error messages). To avoid slowdowns from larger pred_infos, this diff also moves the least frequently used fields of pred_infos to a subterm. (Proc_infos already had a subterm.) This leads to an almost 3% speedup. compiler/headvar_names.m: Store the renaming instead of applying it. compiler/simplify.m: Apply the renaming in invocations after the front end, since doing so may allow some excess assignments to be eliminated. compiler/hlds_pred.m: Add fields to pred_infos and proc_infos for the renaming. Move the least frequently used fields of pred_infos into a pred_sub_info. Some fields of pred_infos were being accessed using predicates that did not follow our naming conventions, and some were accessed using field access functions that are now inappropriate; fix them all. Require the caller to provide the renaming when creating new pred_infos and proc_infos. This is to force the compiler components that do this to propagate the renaming fields of the original predicates and/or procedures to their modified versions. Convert that some old code that used if-then-elses to use switches instead. compiler/hlds_out.m: Write out the new pred_info and proc_info fields. compiler/*.m: Conform to the changes in hlds_pred.m. compiler/hlds_clauses.m: Avoid ambiguity by giving a prefix to the fields of the clauses_info type. tests/invalid/ho_type_mode_bug.err_exp: tests/invalid/merge_ground_any.err_exp: Don't expect error messages about "X = X" anymore. |
||
|
|
b56885be93 |
Fix a bug that caused bootchecks with --optimize-constructor-last-call to fail.
Estimated hours taken: 12 Branches: main Fix a bug that caused bootchecks with --optimize-constructor-last-call to fail. The problem was not in lco.m, but in follow_code.m. In some cases, (specifically, the LCMC version of insert_2 in sparse_bitset.m), follow_code.m moved an impure goal (store_at_ref) into the arms of an if-then-else without marking those arms, or the if-then-else, as impure. The next pass, simplify, then deleted the entire if-then-else, since it had no outputs. (The store_at_ref that originally appeared after the if-then-else was the only consumer of its only output.) The fix is to get follow_code.m to make branched control structures such as if-then-elses, as well as their arms, semipure or impure if a goal being moved into them is semipure or impure, or if they came from an semipure or impure conjunction. Improve the optimization of the LCMC version of sparse_bitset.insert_2, which had a foreign_proc invocation of bits_per_int in it: replace such invocations with a unification of the bits_per_int constant if not cross compiling. Add a new option, --optimize-constructor-last-call-null. When set, LCMC will assign NULLs to the fields not yet filled in, to avoid any junk happens to be there from being followed by the garbage collector's mark phase. This diff also makes several other changes that helped me to track down the bug above. compiler/follow_code.m: Make the fix described above. Delete all the provisions for --prev-code; it won't be implemented. Don't export a predicate that is not now used anywhere else. compiler/simplify.m: Make the optimization described above. compiler/lco.m: Make sure that the LCMC specialized procedure is a predicate, not a function: having a function with the mode LCMC_insert_2(in, in) = in looks wrong. To avoid name collisions when a function and a predicate with the same name and arity have LCMC applied to them, include the predicate vs function status of the original procedure included in the name of the new procedure. Update the sym_name of calls to LCMC variants, not just the pred_id, because without that, the HLDS dump looks misleading. compiler/pred_table.m: Don't have optimizations like LCMC insert new predicates at the front of the list of predicates. Maintain the list of predicates in the module as a two part list, to allow efficient addition of new pred_ids at the (logical) end without using O(N^2) algorithms. Having predicates in chronological order makes it easier to look at HLDS dumps and .c files. compiler/hlds_module.m: Make module_info_predids return a module_info that is physically updated though logically unchanged. compiler/options.m: Add --optimize-constructor-last-call-null. Make the options --dump-hlds-pred-id, --debug-opt-pred-id and --debug-opt-pred-name into accumulating options, to allow the user to specify more than one predicate to be dumped (e.g. insert_2 and its LCMC variant). Delete --prev-code. doc/user_guide.texi: Document the changes in options.m. compiler/code_info.m: Record the value of --optimize-constructor-last-call-null in the code_info, to avoid lookup at every cell construction. compiler/unify_gen.m: compiler/var_locn.m: When deciding whether a cell can be static or not, make sure that we never make static a cell that has some fields initialized with dummy zeros, to be filled in for real later. compiler/hlds_out.m: For goals that are semipure or impure, note this fact. This info was lost when I changed the representation of impurity from markers to a field. mdbcomp/prim_data.m: Rename some ambiguous function symbols. compiler/intermod.m: compiler/trans_opt.m: Rename the main predicates (and some function symbols) of these modules to avoid ambiguity and to make them more expressive. compiler/llds.m: Don't print line numbers for foreign_code fragments if the user has specified --no-line-numbers. compiler/make.dependencies.m: compiler/mercury_to_mercury.m: compiler/recompilation.usage.m: Don't use io.write to write out information to files we may need to parse again, because this is vulnerable to changes to the names of function symbols (e.g. the one to mdbcomp/prim_data.m). The compiler still contains some uses of io.write, but they are for debugging. I added an item to the todo list of the one exception, ilasm.m. compiler/recompilation.m: Rename a misleading function symbol name. compiler/parse_tree.m: Don't import recompilation.m here. It is not needed (all the components of parse_tree that need recompilation.m already import it themselves), and deleting the import avoids recompiling almost everything when recompilation.m changes. compiler/*.m: Conform to the changes above. compiler/*.m: browser/*.m: slice/*.m: Conform to the change to mdbcomp. library/sparse_bitset.m: Use some better variable names. |
||
|
|
c95bacc38c |
Add a new data structure, called an proc_arg_vector, to the compiler that is
Estimated hours taken: 14 Branches: main Add a new data structure, called an proc_arg_vector, to the compiler that is intended to encapsulate the argument passing conventions that we use. (Primarily those described in the comments at the head of polymorphism.m). The intention is to use this new data structure everywhere we currently use lists to represent procedure and call site argument information. This change adds the new data structure plus supporting utility predicates. It also begins the task of moving the code in the compiler over to the new data structure. Specifically, this diff changes the headvars field in the clauses_info structure into a proc_arg_vector. The spots marked XXX ARGVEC will need to be further modified once the proc_info structure has been modified to use proc_arg_vectors. compiler/hlds_args.m: New module. This module defines the proc_arg_vector structure that will eventually be used to represent procedure and call site argument information throughout the compiler. It also defines some utility procedures that operate on that data structure. compiler/hlds.m: Include the new module in the HLDS package. compiler/hlds_clauses.m: Modify the clauses_info structure to represent clause arguments as proc_arg_vectors rather than lists. Adapt the predicates that initialise the clauses_info structure so that they correctly handle the proc_arg_vector structure's representation of function return values. compiler/polymorphism.m: Use the proc_arg_vector data structure when introducing type_infos and typeclass_info arguments into the heads of clauses. Note: the new representation of procedure arguments should allow this module to be simplified but that will be done as a separate change. compiler/add_class.m: compiler/add_clause.m: compiler/add_pragma.m: compiler/add_pred.m: compiler/add_special_pred.m: compiler/clause_to_proc.m: compiler/build_mode_constraints.m: compiler/hhf.m: compiler/higher_order.m: compiler/hlds_pred.m: compiler/hlds_out.m: compiler/intermod.m: compiler/mode_constraints.m: compiler/modes.m: compiler/post_typecheck.m: compiler/prop_mode_constraints.m: compiler/typecheck.m: compiler/unify_proc.m: Conform to the above changes. |
||
|
|
b4c3bb1387 |
Clean up in unused module imports in the Mercury system detected
Estimated hours taken: 3 Branches: main Clean up in unused module imports in the Mercury system detected by --warn-unused-imports. analysis/*.m: browser/*.m: deep_profiler/*.m: compiler/*.m: library/*.m: mdbcomp/*.m: profiler/*.m: slice/*.m: Remove unused module imports. Fix some minor departures from our coding standards. analysis/Mercury.options: browser/Mercury.options: deep_profiler/Mercury.options: compiler/Mercury.options: library/Mercury.options: mdbcomp/Mercury.options: profiler/Mercury.options: slice/Mercury.options: Set --no-warn-unused-imports for those modules that are used as packages or otherwise break --warn-unused-imports, e.g. because they contain predicates with both foreign and Mercury clauses and some of the imports only depend on the latter. |
||
|
|
01a0b8278f |
Implement superclass reduction in the style of CHRs rather than as a top
Estimated hours taken: 15 Branches: main, release Implement superclass reduction in the style of CHRs rather than as a top down search. This is shorter, simpler, and more consistent with the rest of the typeclass implementation. It also removes a few XXXs and fixes a bug reported by Julien. compiler/hlds_data.m: Add an ancestors field to the hlds_constraint type. This caches all the ancestors of assumed constraints, along with proofs (in the form of a sequence of subclass constraints) of how each ancestor is derived. Update this field whenever new assumed constraints are created, by traversing the class hierarchy bottom up. Delete the old subclass_details type, which was part of the superclass table. compiler/typeclasses.m: Use the cached ancestors to apply the class rules, rather than performing a top down search. compiler/type_util.m: Apply substitutions to the ancestors. compiler/typecheck.m: compiler/typecheck_info.m: Update to account for the additional field. compiler/*.m: Remove the superclass table from the module_info and from the interface to context reduction; it is no longer needed. compiler/hlds_out.m: Don't output the superclass table. tests/valid/Mmakefile: tests/valid/superclass_bug.m: Regression test for the bug that is now fixed. |
||
|
|
411b45846a |
Modify check_typeclass.m to gather up all error messages, and print them all
Estimated hours taken: 12 Branches: main Modify check_typeclass.m to gather up all error messages, and print them all at once after sorting. Modify the determinism analysis pass to generate error_specs directly, instead of generating context_det_msgs and converting those to error_specs later. Separate the simplify pass's mechanism for generating error messages from the determinism pass. compiler/check_typeclass.m: Return all error messages instead of printing them when generated. Keep the error messages outside the instance_method_info structure, and give the fields of the structure names. compiler/det_analysis.m: Generate error specs directly. compiler/det_report.m: Delete the context_det_msg data type and the predicates that operated on it, since they are no longer needed. The code that used to convert a context_det_msg into an error_spec is now dispersed to the sites that generate the error report in the first place. These sites are mostly in det_analysis.m and simplify.m, with a few in other modules (e.g. common.m and format_call.m). Export some auxiliary functions that the these sites now need. compiler/simplify.m: Generate error_specs directly, instead of through context_det_msgs, and return them to the caller for printing. compiler/common.m: compiler/format_call.m: Conform to the change to det_report.m. compiler/unused_import.m: Return all error messages instead of printing them when generated. compiler/mercury_compile.m: Print the error message batches returned by the modified passes. Use the version of globals in module_infos in preference to the one in the I/O state, since we would like to phase out the latter. Don't explicitly sort error_specs, since write_error_specs will do it anyway. compiler/error_util.m: Separate the error messages of the simplify pass from those of determinism analysis. Provide a standard way to format type constructor names. Require the calls to provide the globals when printing error_specs. This is to allow callers to provide the globals from a module_info, instead of the one in the I/O state. compiler/passes_aux.m: Provide support for passes that have lists of error_specs threaded through them, as simplify now does. Rename some predicates to avoid some ambiguities. compiler/deforest.m: compiler/pd_util.m: compiler/unify_proc.m: compiler/unused_args.m: Conform to the change to the interface of determinism analysis. compiler/inlining.m: Do not thread the I/O state through this module. compiler/make.module_dep_file.m: compiler/make_hlds_passes.m: compiler/ml_tailcall.m: compiler/mode_errors.m: compiler/modes.m: compiler/modules.m: compiler/stratify.m: compiler/table_gen.m: Conform to the change in error_util. compiler/prog_data.m: Rename some function symbols to avoid some ambiguities. compiler/add_class.m: compiler/base_typeclass_info.m: compiler/hlds_out.m: compiler/intermod.m: compiler/module_qual.m: compiler/prog_io_typeclass.m: compiler/recompilation.check.m: compiler/recompilation.usage.m: compiler/recompilation.version.m: compiler/type_class_info.m: Conform to the change in prog_data.m. tests/invalid/*err_exp: Update the expected output files to conform to the changes above. This mosly involves expecting sorted messages without duplicates. |
||
|
|
f070e2a1b7 |
Convert the make_hlds stage of the compiler from printing out error messages
Estimated hours taken: 14 Branches: main Convert the make_hlds stage of the compiler from printing out error messages one at a time to gathering them all up and printing them all at once after sorting and deleting duplicates. This approach makes it much easier to be consistent about updating the exit status in the I/O state and the error count in the module info, and indeed this diff fixes some bugs in this area. This approach also means that instead of threading a pair of I/O states through these modules, we now mostly thread through a list of error specifications. In a couple of places, we create the I/O states we need for printing progress messages using trace goals. configure.in: Check that the installed compiler supports trace goals (perhaps with warnings), since the compiler now uses them. compiler/Mercury.options: Temporarily compensate for a bug in the handling of trace goals. compiler/add_class.m: compiler/add_clause.m: compiler/add_mode.m: compiler/add_pragma.m: compiler/add_pred.m: compiler/add_solver.m: compiler/add_type.m: compiler/field_access.m: compiler/foreign.m: compiler/make_hlds_error.m: compiler/make_hlds_passes.m: compiler/make_hlds_warn.m: compiler/module_qual.m: compiler/modules.m: compiler/qual_info.m: compiler/state_var.m: compiler/superhomogeneous.m: Make the change described at the top. In many cases, this required changing code to error util instead of io.write_strings to create the error messages. In some cases, move a predicate used in one module but defined in another module to the first module. Delete some predicates whose job used to be to test options to see whether a message should be generated, since we can now embed the option value that a message depends on in the error message itself. In module_qual.m, remove unnecessary module qualifications. In modules.m, give explicit names to a bunch of lambda expressions. Reformat comments to exploit the available columns. compiler/check_typeclass.m: Conform to the changes above. Mark with XXX the places where we are ignoring the proper update of the error count in module_infos. compiler/modes.m: compiler/post_typecheck.m: compiler/stratify.m: compiler/table_gen.m: compiler/unused_args.m: Use error_specs instead of plain pieces to print error messages. compiler/options.m: Rename an option that conflicts with a language keyword. compiler/handle_options.m: Conform to the change to options.m. compiler/prog_data.m: Rename some function symbols that conflict with language keywords. compiler/prog_out.m: compiler/prog_io_util.m: Conform the change above, and delete some predicates that have now become unused. compiler/mercury_compile.m: Rename a predicate to avoid an ambiguity. Conform to the changes above. compiler/hlds_out.m: compiler/make.module_dep_file.m: compiler/make_hlds.m: compiler/mercury_to_mercury.m: compiler/mode_errors.m: compiler/prog_io.m: Conform to the changes above. In some cases, delete predicates that aren't needed anymore. tests/invalid/errors.err_exp: tests/invalid/errors1.err_exp: tests/invalid/state_vars_test3.err_exp: tests/invalid/undef_inst.err_exp: Update this expected output to reflect the fact that we now sort the error messages. tests/invalid/missing_interface_import2.err_exp: tests/warnings/double_underscore.exp: Update this expected output to reflect the fact that we no longer print the same error message twice. tests/invalid/missing_det_decls.err_exp: Update this expected output to reflect the fact that we now indent an error messages correctly. tests/invalid/multimode_syntax.err_exp: Update this expected output to reflect the fact that we now use error_util instead of plain io.writes to create an error message. tests/invalid/typeclass_test.err_exp: tests/invalid/unsatisfiable_constraint.err_exp: Update this expected output to reflect minor improvements in the formatting of an error message. |
||
|
|
5eee81204e |
A big step towards cleaning up the way we handle errors.
Estimated hours taken: 28 Branches: main A big step towards cleaning up the way we handle errors. The main changes are - the provision, in error_util.m, of a mechanism for completely specifying everything to do with a single error in one data structure, - the conversion of typecheck_errors.m from using io.write_string to using this new capability, - the conversion of mode_errors.m and det_report.m from using write_error_pieces to using this new capability, and - consistently using the quoting style `symname'/N instead of `symname/N' in error_util and hlds_error_util (previously, error_util used the former but hlds_error_util used the latter). This diff sets up later diffs which will collect all error specifications in a central place and print them all at once, in order. compiler/error_util.m: The new type error_spec, which completely specifies an error. An error_spec may have multiple components with different contexts and may have parts which are printed only under certain conditions, e.g. a given option being set. Each error_spec has a severity and also records which phase found the error. The new predicate write_error_spec takes care of updates of the exit status for errors and (if --halt-at-warn is set) for warnings. It also takes care of setting the flag that calls for the reminder about -E at the end. This diff also makes it simpler to use the ability to print arbitrary output. It adds the ability to include integers in messages directly, and the ability to create blank lines. It renames some function symbols to avoid ambiguities. Move a predicate that only used by typecheck_errors.m to that file. compiler/hlds_error_util.m: Switch to the `symname'/N quoting style for describing predicates and procedures. compiler/prog_util.m: Switch to the `symname'/N quoting style for describing sym_name_and_arity. compiler/hlds_module.m: Provide a predicate to increment the number of errors not by one, but by the number of errors printed by write_error_spec. Fix some documentation rot. compiler/typecheck_errors.m: Use write_error_spec instead of io.write_strings to print error messages. In several cases, improve the formatting of the messages printed. Mark a number of places where we don't (yet) update the number of errors in the module_info correctly. Rename the checkpoint predicate to avoid potential ambiguity with similar predicates in e.g. mode_info. compiler/typecheck_info.m: Group the code for writing stuff out together in one bunch. For each such predicate, create another that returns a list of format components instead of doing I/O directly. compiler/typecheck.m: Move the code for writing inference messages here from typecheck_errors.m, since these messages aren't errors. compiler/mode_errors.m: compiler/det_report.m: Use write_error_spec instead of write_error_pieces. In the case of mode_errors.m, this means we now get correct the set of circumstances in which we set the flag that calls for the reminder about -E. compiler/add_pragma.m: compiler/add_type.m: Convert some code that used to use write_error_pieces to print error messages to use write_error_spec instead. compiler/assertion.m: compiler/hlds_pred.m: compiler/post_typecheck.m: Assertion.m used to contain some code to check for assertions in the interface that mention predicates that are not exported. Move most of this code to post_typecheck.m (which is where this code used to be called from). One small part, which is a test for a particular property of import_statuses, is moved to hlds_pred.m to be with all the other similar tests of import_statuses. compiler/prog_util.m: Change unqualify_name from a predicate to a function. compiler/pred_table.m: compiler/hlds_out.m: Avoid some ambiguities by adding a suffix to the names of some predicates. compiler/*.m: Conform to the changes above. library/list.m: Add a function that was previously present (with different names) in two compiler modules. tests/hard_coded/allow_stubs.exp: Update the format of the expected exception. tests/invalid/errors2.err_exp2: Remove this file. As far as I can tell, it was never the correct expected output on the main branch. (It originated on the alias branch way back in the mists of time.) tests/invalid/*.err_exp: tests/invalid/purity/*.err_exp: tests/warnings/*.exp: Update the format of the expected error messages. tests/recompilation/*.err_exp.2: Update the format of the expected messages about what was modified. |
||
|
|
2b2f3d3cbe |
This diff contains no algorithmic changes.
Estimated hours taken: 8 Branches: main This diff contains no algorithmic changes. It merely renames apart a bunch of function symbols to reduce ambiguity. Basically I went through prog_data.m, prog_item.m, hlds_data.m, hlds_goal.m and hlds_pred.m looking for type definitions containing function symbol names that were either language "keywords" (e.g. "terminates", which is an annotation on foreign_procs), used with slightly different meanings in several types (e.g. "sym"), or both (e.g. "call"). When I found such type definitions, I changed the names of the function symbols, usually by adding a prefix or suffix indicating the type to all function symbols of the type. For example, the old function symbol "foreign_proc" in type "pragma_type" is now named "pragma_foreign_proc", and the names of all other function symbols in that type also start with "pragma_". All of this should yield simpler compiler error messages when we make mistakes, and will make it more likely that looking up a function symbol using a tags file will take you to the actual definition of the relevant instance of that function symbol. However, the most important benefit is the increase in the readability of unfamiliar code; the reader won't have to emulate the compiler's type ambiguity resolution algorithm (which in many cases used to require distinguishing between f/14 and f/15 by counting the arguments, e.g. for "pred_or_func"). compiler/prog_data.m: compiler/prog_item.m: compiler/hlds_data.m: compiler/hlds_goal.m: compiler/hlds_pred.m: Rename function symbols as explained above. compiler/*.m: Conform to the function symbol renames. In some cases, rename other function symbols as well. Minor style fixes, e.g. replace if-then-elses with switches, or simple det predicates with functions. |
||
|
|
9d23d8e2e7 |
Implement the trace goal construct we discussed, for now for the LLDS backends
Estimated hours taken: 70
Branches: main
Implement the trace goal construct we discussed, for now for the LLDS backends
only.
Since the syntax of trace goals is non-trivial, useful feedback on syntax
errors inside trace goal attributes is essential. With the previous setup, this
wasn't possible, since the code that turned terms into parse tree goals turned
*all* terms into goals; it couldn't recognize any errors, sweeping them under
the rug as calls. This diff changes that. Now, if this code recognizes a
keyword that indicates a particular construct, it insists on the rest of the
code following the syntax required for that construct, and returns error
messages if it doesn't.
We handle the trace goal attributes that specify state variables to be threaded
through the trace goal (either the I/O state or a mutable variable) in
add_clause.m, at the point at which we transform the list of items to the HLDS.
We handle the compile-time condition on trace goals in the invocation of
simplify at the end of semantics analysis, by eliminating the goal if the
compile-time condition isn't met. We handle run-time conditions on trace goals
partially in the same invocation of simplify: we transform trace goals with
runtime conditions into an if-then-else with the trace goal as the then part
and `true' as the else part, the condition being a foreign_proc that is handled
specially by the code generator, that special handling being to replace
the actual code of the foreign_proc (which is a dummy) with the evaluation of
the runtime condition.
Since these changes require significant changes to some of our key data
structures, I took the liberty of doing some renaming of function symbols
at the same time to avoid using ambiguities with respect to language keywords.
library/ops.m:
Add "trace" as an operator.
compiler/prog_data.m:
Define data types to represent the various attributes of trace goals.
Rename some function symbols to avoid ambiguities.
compiler/prog_item.m:
Extend the parse tree representation of goals with a trace goal.
compiler/mercury_to_mercury.m:
Output the new kind of goal and its components.
compiler/hlds_goal.m:
Extend the HLDS representation of scopes with a scope_reason
representing trace goals.
Add a mechanism (an extra argument in foreign_procs) to allow
the representation of goals that evaluate runtime trace conditions.
Since this requires modifying all code that traverses the HLDS,
do some renames that were long overdue: rename not as negation,
rename call as plain_call, and rename foreign_proc as
call_foreign_proc. These renames all avoid using language keywords
as function symbols.
Change the way we record goals' purities. Instead of optional features
to indicate impure or semipure, which is error-prone, use a plain
field in the goal_info, accessed in the usual way.
Add a way to represent that a goal contains a trace goal, and should
therefore be treated as if it were impure when considering whether to
optimize it away.
Reformat some comments describing function symbols.
compiler/hlds_out.m:
Output the new construct in the HLDS.
compiler/prog_io_util.m:
Generalize the maybe[123] types to allow the representation of more
than one error message. Add functions to extract the error messages.
Add a maybe4 type. Rename the function symbols of these types to
avoid massive ambiguity.
Change the order of some predicates to bring related predicates
next to each other.
compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_goal.m:
compiler/prog_io_pragma.m:
Rework these modules almost completely to find and accumulate syntax
errors as terms are being parsed. In some cases, this allowed us to
replace "XXX this is a hack" markers with meaningful error-reporting
code.
In prog_io_goal.m, add code for parsing trace goals.
In a bunch of places, update obsolete coding practices, such as using
nested chains of closures instead of simple sequential code, and
using A0 and A to refer to values of different types (terms and goals
respectively). Use more meaningful variable names.
Break up some too-large predicates.
compiler/superhomogeneous.m:
Find and accumulate syntax errors as terms are being parsed.
compiler/add_clause.m:
Add code to transform trace goals from the parse tree to the HLDS.
This is where the IO state and mutable variable attributes of trace
goals are handled.
Eliminate the practice of using the naming scheme Body0 and Body
to refer to values of different types (prog_item.goal and hlds_goal
respectively).
Use error_util for some error messages.
library/private_builtin.m:
Add the predicates referred to by the transformation in add_clause.m.
compiler/goal_util.m:
Rename a predicate to avoid ambiguity.
compiler/typecheck.m:
Do not print error messages about missing clauses if some errors have
been detected previously.
compiler/purity.m:
Instead of just computing purity, compute (and record) also whether
a goal contains a trace goal. However, treat trace goals as pure.
compiler/mode_info.m:
Add trace goals as a reason for locking variables.
Rename some function symbols to avoid ambiguity.
compiler/modes.m:
When analyzing trace goal scopes, lock the scope's nonlocal variables
to prevent them from being further instantiated.
compiler/det_analysis.m:
Insist on the code in trace goal scopes being det or cc_multi.
compiler/det_report.m:
Generate the error message if the code in a trace goal scope isn't det
or cc_multi.
compiler/simplify.m:
At the end of the front end, eliminate trace goal scopes if their
compile-time condition is false. Transform trace goals with runtime
conditions as described at the top.
Treat goals that contain trace goals as if they were impure when
considering whether to optimize them away.
compiler/mercury_compile.m:
Tell simplify when it is being invoked at the end of the front end.
Rename a predicate to avoid ambiguity.
compiler/trace_params.m:
Provide the predicates simplify.m need to be able to evaluate the trace
goal conditions regarding trace levels.
compiler/trace.m:
compiler/trace_gen.m:
Rename the trace module as trace_gen, since "trace" is now an operator.
Rename some predicates exported by the module, now that it is no longer
possible to preface calls with "trace." as a module qualifier.
compiler/notes/compiler_design.html:
Document this name change.
compiler/options.m:
Rename the trace option as trace_level internally, since "trace"
is now an operator. The user-visible name remains the same.
Add the new --trace-flag option.
Delete an obsolete option.
compiler/handle_options.m:
Rename the function symbols of the grade_component type,
since "trace" is now an operator.
compiler/llds.m:
Extend the LLDS with a mechanism to refer to C global variables.
For now, these are used to refer to C globals that will be created
by mkinit to represent the initial values of the environment variables
referred to by trace goals.
compiler/commit_gen.m:
Check that no trace goal with a runtime condition survives to code
generation; they should have been transformed by simplify.m.
compiler/code_gen.m:
Tell commit_gen.m what kind of scope it is generating code for.
compiler/pragma_c_gen.m:
Generate code for runtime conditions when handling the foreign_procs
created by simplify.m.
compiler/code_info.m:
Allow pragma_c_gen.m to record what environment variables it has
generated references to.
compiler/proc_gen.m:
Record the set of environment variables a procedure refers to
in the LLDS procedure header, for efficient access by llds_out.m.
compiler/llds_out.m:
Handle the new LLDS construct, and tell mkinit which environment
variables need C globals created for them.
compiler/pd_util.m:
Rename some predicates to avoid ambiguity.
compiler/*.m:
Conform to the changes above, mainly the renames of function symbols
and predicates, the changed signatures of some predicates, and the new
handling of purity.
util/mkinit.c:
Generate the definitions and the initializations of any C globals
representing the initial status (set or not set) of environment
variables needed by trace goals.
library/assoc_list.m:
Add some predicates that are useful in prog_io*.m.
library/term_io.m:
Minor cleanup.
tests/hard_coded/trace_goal_{1,2}.{m,exp}:
New test cases to test the new construct, identical except for whether
the trace goal is enabled at compile time.
tests/hard_coded/trace_goal_env_{1,2}.{m,exp}:
New test cases to test the new construct, identical except for whether
the trace goal is enabled at run time.
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
Enable the new test cases.
tests/invalid/*.err_exp:
Update the expected output for the new versions of the error messages
now being generated.
|
||
|
|
46a67b0b48 |
When the typechecker finds highly ambiguous overloading, print what symbols
Estimated hours taken: 16
Branches: main
When the typechecker finds highly ambiguous overloading, print what symbols
were overloaded, and where they occurred. Without this information, it is
very hard to fix the error if the predicate body is at all large.
Fix some software engineering problems encountered during this process.
Modify some predicates in error_util in order to simplify their typical usage.
Change the type_ctor type to be not simply a sym_name - int pair but a type
with its own identifying type constructor. Change several other types that
were also sym_name - int pairs (mode_id, inst_id, item_name, module_qual.id
and the related simple_call_id) to have their own function symbols too.
compiler/typecheck_info.m:
Add a field to the typecheck_info structure that records the overloaded
symbols encountered.
compiler/typecheck.m:
When processing ambiguous predicate and function symbols, record this
fact in the typecheck_info.
Add a field to the cons_type_info structure to make this possible.
compiler/typecheck_errors.m:
When printing the message about highly ambiguous overloading,
what the overloaded symbols were and where they occurred.
compiler/error_util.m:
Make error_msg_specs usable with plain in and out modes by separating
out the capability requiring special modes (storing a higher order
value in a function symbol) into its own, rarely used type.
Make component_list_to_line_pieces a bit more flexible.
compiler/prog_data.m:
compiler/module_qual.m:
compiler/recompilation.m:
Change the types listed above from being equivalence types (pairs)
to being proper discriminated union types.
compiler/*.m:
Conform to the changes above.
In some cases, simplify the code's use of error_util.
tests/warnings/ambiguous_overloading.{m,exp}:
Greatly extend this test case to test the new functionality.
tests/recompilation/*.err_exp.2
Reflect the fact that the expected messages now use the standard
error_util way of quoting sym_name/arity pairs.
|
||
|
|
459847a064 |
Move the univ, maybe, pair and unit types from std_util into their own
Estimated hours taken: 18 Branches: main Move the univ, maybe, pair and unit types from std_util into their own modules. std_util still contains the general purpose higher-order programming constructs. library/std_util.m: Move univ, maybe, pair and unit (plus any other related types and procedures) into their own modules. library/maybe.m: New module. This contains the maybe and maybe_error types and the associated procedures. library/pair.m: New module. This contains the pair type and associated procedures. library/unit.m: New module. This contains the types unit/0 and unit/1. library/univ.m: New module. This contains the univ type and associated procedures. library/library.m: Add the new modules. library/private_builtin.m: Update the declaration of the type_ctor_info struct for univ. runtime/mercury.h: Update the declaration for the type_ctor_info struct for univ. runtime/mercury_mcpp.h: runtime/mercury_hlc_types.h: Update the definition of MR_Univ. runtime/mercury_init.h: Fix a comment: ML_type_name is now exported from type_desc.m. compiler/mlds_to_il.m: Update the the name of the module that defines univs (which are handled specially by the il code generator.) library/*.m: compiler/*.m: browser/*.m: mdbcomp/*.m: profiler/*.m: deep_profiler/*.m: Conform to the above changes. Import the new modules where they are needed; don't import std_util where it isn't needed. Fix formatting in lots of modules. Delete duplicate module imports. tests/*: Update the test suite to confrom to the above changes. |
||
|
|
12deb40264 |
Rename all the get access predicates in these modules that don't
Estimated hours taken: 0.1 Branches: main compiler/hlds_clauses.m: compiler/hlds_pred.m: Rename all the get access predicates in these modules that don't already have put "get" in their name. (The names of the set access predicates were OK already.) compiler/*.m: Conform to the above. All this was done by this sed script: s/clauses_info_varset/clauses_info_get_varset/ s/clauses_info_explicit_vartypes/clauses_info_get_explicit_vartypes/ s/clauses_info_vartypes/clauses_info_get_vartypes/ s/clauses_info_headvars/clauses_info_get_headvars/ s/clauses_info_clauses_rep/clauses_info_get_clauses_rep/ s/clauses_info_rtti_varmaps/clauses_info_get_rtti_varmaps/ s/pred_info_import_status/pred_info_get_import_status/ s/pred_info_arg_types/pred_info_get_arg_types/ s/pred_info_typevarset/pred_info_get_typevarset/ s/pred_info_tvar_kinds/pred_info_get_tvar_kinds/ s/pred_info_procedures/pred_info_get_procedures/ s/proc_info_context/proc_info_get_context/ s/proc_info_varset/proc_info_get_varset/ s/proc_info_vartypes/proc_info_get_vartypes/ s/proc_info_headvars/proc_info_get_headvars/ s/proc_info_inst_varset/proc_info_get_inst_varset/ s/proc_info_maybe_declared_argmodes/proc_info_get_maybe_declared_argmodes/ s/proc_info_argmodes/proc_info_get_argmodes/ s/proc_info_maybe_arglives/proc_info_get_maybe_arglives/ s/proc_info_declared_determinism/proc_info_get_declared_determinism/ s/proc_info_inferred_determinism/proc_info_get_inferred_determinism/ s/proc_info_goal/proc_info_get_goal/ s/proc_info_can_process/proc_info_get_can_process/ s/proc_info_rtti_varmaps/proc_info_get_rtti_varmaps/ s/proc_info_eval_method/proc_info_get_eval_method/ s/proc_info_is_address_taken/proc_info_get_is_address_taken/ s/proc_info_stack_slots/proc_info_get_stack_slots/ s/proc_info_liveness_info/proc_info_get_liveness_info/ s/proc_info_context/proc_info_get_context/ s/proc_info_context/proc_info_get_context/ s/proc_info_context/proc_info_get_context/ s/proc_info_context/proc_info_get_context/ s/proc_info_context/proc_info_get_context/ s/proc_info_context/proc_info_get_context/ s/proc_info_context/proc_info_get_context/ |
||
|
|
a4519ed079 |
Move the all-solutions predicates from the library module std_util into their
Estimated hours taken: 4 Branches: main Move the all-solutions predicates from the library module std_util into their own module, solutions. Move semidet_fail, semidet_succeed, cc_multi_equal and dynamic cast from std_util.m into builtin.m. Add some more utility functions for performing determinism or purity casts. (The later are primarily intended for use by solver implementors.) library/std_util.m: Move the all-solutions predicates into their own module, solutions.m. For now there are (obsolete) forwarding predicates from this module to the new one. The forwarding predicates will be included in the upcoming 0.13 release and then removed in later versions. Move semidet_succeed, semidet_fail, cc_multi_equal and dynamic_cast to builtin.m library/solutions.m: New file. This is the new home for the all-solutions predicates. This is pretty much cut and pasted from std_util (with module qualifiers updated accordingly). I've rearranged the code in a more top-down fashion as per our current coding standard. library/builtin.m: Move semidet_fail/0, semidet_succeed/0, cc_multi_equal/2 and dynamic_cast/2 to this module. Add semidet_true/0 and semidet_false/0 as synonyms for semidet_fail/0 and semidet_succeed/0. Add impure_true/0 and semipure_true/0. These are useful for performing purity casts, e.g. in solver implementations. library/library.m: Add the new module. NEWS: Announce the changes. library/*.m: Update to conform to the above. compiler/const_prop.m: Update evaluate_semidet_call/5 with the new module name for dynamic_cast. compiler/*.m: Module qualify calls to solutions to either disambiguate them from the versions in std_util (where they weren't module qualified) or change the module qualifier where they were (to avoid warnings about calls to the now deprecated versions). tests/debugger/declarative/solutions.*: Rename this module as the name conflicts with the new library module. tests/debugger/declarative/solns.*: Renamed version of above (with updated expected output). tests/debugger/declarative/Mmakefile: Handle the renamed version of the solutions test. tests/debugger/all_solutions.m: tests/debugger/declarative/args.m: tests/debugger/declarative/library_forwarding.m: tests/hard_coded/constant_prop_2.m: tests/invalid/multisoln_func.m: tests/invalid/one_member.m: tests/invalid/promise_equivalent_claueses.m: tests/valid/simplify_bug2.m: tests/valid/solv.m: Update to conform to the above changes. sample/solutions/*.m: Update to conform to the above changes. |
||
|
|
3ebda6545f |
Move the stuff currently in hlds_pred.m that deals with clauses into a new
Estimated hours taken: 1.5 Branches: main Move the stuff currently in hlds_pred.m that deals with clauses into a new module, hlds_clauses.m. Move the stuff currently in hlds_pred.m that deals with RTTI into a new module, hlds_rtti.m. Move the stuff currently in hlds_module.m that deals with predicate tables into a new module, pred_table.m. These changes make hlds_pred.m and hlds_module.m much more cohesive, but there are no changes in algorithms. compiler/hlds_clauses.m: compiler/hlds_rtti.m: compiler/pred_table.m: New modules as described above. In some cases, fix mixleading or ambiguous predicate names in the process, and convert a few predicates to functions. compiler/hlds_pred.m: compiler/hlds_module.m: Delete the stuff moved to other modules. compiler/*.m: In modules that need the functionality moved a new module, import the new module. It is rare for all the new modules to be needed, and many modules don't need any of the new modules at all. (For example, of the 200+ modules that import hlds_module.m, only about 40 need pred_table.m.) Conform to the few minor changes to e.g. predicate names. compiler/notes/compiler_design.html: Document the new modules. |
||
|
|
be5b71861b |
Convert almost all the compiler modules to use . instead of __ as
Estimated hours taken: 6 Branches: main compiler/*.m: Convert almost all the compiler modules to use . instead of __ as the module qualifier. In some cases, change the names of predicates and types to make them meaningful without the module qualifier. In particular, most of the types that used to be referred to with an "mlds__" prefix have been changed to have a "mlds_" prefix instead of changing the prefix to "mlds.". There are no algorithmic changes. |
||
|
|
b78d146b75 |
Improve error reporting for type class declarations in the situation where a
Estimated hours taken: 10
Branches: main
Improve error reporting for type class declarations in the situation where a
mode declaration for a method has been provided but there is no function or
predicate declaration for that method. Currently, this causes an internal
abort in the compiler.
Avoid another compiler abort in polymorphism.m when a type class method has two
duplicate mode declarations.
compiler/add_class.m:
Change the order in which we add type class declarations to the HLDS
so that we can detect and report situations where a type class method
has a mode declaration but no corresponding predicate or function
declaration. All of the predicate/function method declarations for a
particular typeclass need to be added before any mode declarations.
We can then check that there is a corresponding predicate/function
method declaration as each mode is added.
compiler/post_typecheck.m:
Have the post-typechecking pass indicate that an error has occurred if
we encounter indistinguishable mode declarations. This prevents
polymorphism being run if there are such mode declarations. This
avoids an internal abort in polymorphism.m when the mode declarations
in question are type class methods.
Unrelated change: s/io.state/io__state/ in an error message.
compiler/hlds_error_util.m:
When formatting predicate names, specifically identify type class
methods as such. e.g. instead of `predicate foo/1' we now
write them out as `type class predicate method foo/1'.
compiler/modecheck_call.m:
Fix a typo: s/identical/indentical/
compiler/prog_item.m:
Add the equivalence: class_methods == list(class_method).
compiler/equiv_type.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/prog_data.m:
compiler/prog_io_typeclass.m:
compiler/recompilation.version.m:
Minor changes to conform to the above.
tests/README:
Fix an line that exceeds 80 characters in length.
tests/invalid/Mmakefile:
Enable the test cases typeclass_mode_{2,3,4} since we now pass those
tests.
Delete a comment about `--split-c-files'. That option is no longer
supported.
tests/invalid/typeclass_mode_{2,3,4}.err_exp:
Add expected outputs for these test cases.
tests/invalid/invalid_main.err_exp:
The module qualifier in the expected output is now '.'.
tests/invalid/qualified_cons_id2.err_exp:
Delete the determinism error from the expected output. It won't show
up now as the above changes mean the compiler will abort before
determinism checking in this case.
tests/invalid/typeclass_dup_method_mode.{m,err_exp}:
Add a test case for the problem that causes an abort in the
polymorphism pass when a type class method has duplicate mode
declarations.
tests/invalid/typeclass_mode.err_exp:
Update the expected output to conform with the above changes. Also,
we no longer emit the spurious error message about missing clauses.
tests/recompilation/typeclass_method_pragma_r.err_exp.2:
Update to conform to the new naming of type class methods
in the error message.
|
||
|
|
45fdb6c451 |
Use expect/3 in place of require/2 throughout most of the
Estimated hours taken: 4 Branches: main compiler/*.m: Use expect/3 in place of require/2 throughout most of the compiler. Use unexpected/2 (or sorry/2) in place of error/1 in more places. Fix more dodgy assertion error messages. s/map(prog_var, mer_type)/vartypes/ where the latter is meant. |
||
|
|
5f589e98fb |
Various cleanups for the modules in the compiler directory.
Estimated hours taken: 4 Branches: main Various cleanups for the modules in the compiler directory. The are no changes to algorithms except the replacement of some if-then-elses that would naturally be switches with switches and the replacement of most of the calls to error/1. compiler/*.m: Convert calls to error/1 to calls to unexpected/2 or sorry/2 as appropriate throughout most or the compiler. Fix inaccurate assertion failure messages, e.g. identifying the assertion failure as taking place in the wrong module. Add :- end_module declarations. Fix formatting problems and bring the positioning of comments into line with our current coding standards. Fix some overlong lines. Convert some more modules to 4-space indentation. Fix some spots where previous conversions to 4-space indentation have stuffed the formatting of the code up. Fix a bunch of typos in comments. Use state variables in more places; use library predicates from the sv* modules where appropriate. Delete unnecessary and duplicate module imports. Misc. other small cleanups. |
||
|
|
21685c9e22 |
Improve the error messages generated for determinism errors involving committed
Estimated hours taken: 6
Branches: main
Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.
The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.
compiler/det_analysis.m:
Keep track of goals to the right of the current goal that could fail,
and include them in the error representation if required.
compiler/det_report.m:
Include the list of failing goals to the right in the representations
of determinism errors involving committed committed choice goals.
Convert the last part of this module that wasn't using error_util
to use error_util. Make most parts of this module just construct
error message specifications; print those specifications (using
error_util) in only a few places.
compiler/hlds_out.m:
Add a function for use by the new code in det_report.m.
compiler/error_util.m:
Add a function for use by the new code in det_report.m.
compiler/error_util.m:
compiler/compiler_util.m:
Error_util is still changing reasonably often, and yet it is
included in lots of modules, most of which need only a few simple
non-parse-tree-related predicates from it (e.g. unexpected).
Move those predicates to a new module, compiler_util.m. This also
eliminates some undesirable dependencies from libs to parse_tree.
compiler/libs.m:
Include compiler_util.m.
compiler/notes/compiler_design.html:
Document compiler_util.m, and fix the documentation of some other
modules.
compiler/*.m:
Import compiler_util instead of or in addition to error_util.
To make this easier, consistently use . instead of __ for module
qualifying module names.
tests/invalid/det_errors_cc.{m,err_exp}:
Add this new test case to test the error messages for cc contexts.
tests/invalid/det_errors_deet.{m,err_exp}:
Add this new test case to test the error messages for unifications
inside function symbols.
tests/invalid/Mmakefile:
Add the new test cases.
tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
Change the expected output to conform to the change in det_report.m,
which is now more consistent.
|
||
|
|
f9fe8dcf61 |
Improve the error messages generated for determinism errors involving committed
Estimated hours taken: 8
Branches: main
Improve the error messages generated for determinism errors involving committed
choice contexts. Previously, we printed a message to the effect that e.g.
a cc pred is called in context that requires all solutions, but we didn't say
*why* the context requires all solutions. We now keep track of all the goals
to the right that could fail, since it is these goals that may reject the first
solution of a committed choice goal.
The motivation for this diff was the fact that I found that locating the
failing goal can be very difficult if the conjunction to the right is
a couple of hundred lines long. This would have been a nontrivial problem,
since (a) unifications involving values of user-defined types are committed
choice goals, and (b) we can expect uses of user-defined types to increase.
compiler/det_analysis.m:
Keep track of goals to the right of the current goal that could fail,
and include them in the error representation if required.
compiler/det_report.m:
Include the list of failing goals to the right in the representations
of determinism errors involving committed committed choice goals.
Convert the last part of this module that wasn't using error_util
to use error_util. Make most parts of this module just construct
error message specifications; print those specifications (using
error_util) in only a few places.
compiler/hlds_out.m:
Add a function for use by the new code in det_report.m.
compiler/error_util.m:
Add a function for use by the new code in det_report.m.
compiler/error_util.m:
compiler/compiler_util.m:
Error_util is still changing reasonably often, and yet it is
included in lots of modules, most of which need only a few simple
non-parse-tree-related predicates from it (e.g. unexpected).
Move those predicates to a new module, compiler_util.m. This also
eliminates some undesirable dependencies from libs to parse_tree.
compiler/libs.m:
Include compiler_util.m.
compiler/notes/compiler_design.html:
Document compiler_util.m, and fix the documentation of some other
modules.
compiler/*.m:
Import compiler_util instead of or in addition to error_util.
To make this easier, consistently use . instead of __ for module
qualifying module names.
tests/invalid/det_errors_cc.{m,err_exp}:
Add this new test case to test the error messages for cc contexts.
tests/invalid/det_errors_deet.{m,err_exp}:
Add this new test case to test the error messages for unifications
inside function symbols.
tests/invalid/Mmakefile:
Add the new test cases.
tests/invalid/det_errors.err_exp:
tests/invalid/magicbox.err_exp:
Change the expected output to conform to the change in det_report.m,
which is now more consistent.
|
||
|
|
b2012c0c0e |
Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
Estimated hours taken: 8 Branches: main compiler/*.m: Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst' and 'mer_mode'. This is to avoid the need to parenthesize these type names in some contexts, and to prepare for the possibility of a parser that considers those words to be reserved words. Rename some other uses of those names (e.g. as item types in recompilation.m). Delete some redundant synonyms (prog_type, mercury_type) for mer_type. Change some type names (e.g. mlds__type) and predicate names (e.g. deforest__goal) to make them unique even without module qualification. Rename the function symbols (e.g. pure, &) that need to be renamed to avoid the need to parenthesize them. Make their replacement names more expressive. Convert some more modules to four space indentation. Avoid excessively long lines, such as those resulting from the automatic substitution of 'mer_type' for 'type'. |
||
|
|
b54ab42d70 |
A simple tool for performing substitutions on the source files of the
Estimated hours taken: 0.5 Branches: main tools/subst: A simple tool for performing substitutions on the source files of the compiler. compiler/*.m: Change the names of the get predicates operating on module_infos to include "get" in the name, for uniformity. This was done mostly by the following sed script, with some manual cleanup afterwards to reduce excessive line lengths. s/module_info_types/module_info_get_type_table/ s/module_info_set_types/module_info_set_type_table/ s/module_info_insts/module_info_get_inst_table/ s/module_info_set_insts/module_info_set_inst_table/ s/module_info_modes/module_info_get_mode_table/ s/module_info_set_modes/module_info_set_mode_table/ s/module_info_ctors/module_info_get_cons_table/ s/module_info_set_ctors/module_info_set_cons_table/ s/module_info_classes/module_info_get_class_table/ s/module_info_set_classes/module_info_set_class_table/ s/module_info_instances/module_info_get_instance_table/ s/module_info_set_instances/module_info_set_instance_table/ s/module_info_superclasses/module_info_get_superclass_table/ s/module_info_set_superclasses/module_info_set_superclass_table/ s/module_info_assertion_table/module_info_get_assertion_table/ s/module_info_exclusive_table/module_info_get_exclusive_table/ s/module_info_ctor_field_table/module_info_get_ctor_field_table/ s/module_info_name/module_info_get_name/ s/module_info_globals/module_info_get_globals/ s/module_info_contains_foreign_types/module_info_get_contains_foreign_types/ s/module_info_num_errors/module_info_get_num_errors/ s/module_info_type_ctor_gen_infos/module_info_get_type_ctor_gen_infos/ s/module_info_stratified_preds/module_info_get_stratified_preds/ s/module_info_unused_arg_info/module_info_get_unused_arg_info/ s/module_info_exception_info/module_info_get_exception_info/ s/module_info_type_spec_info/module_info_get_type_spec_info/ s/module_info_no_tag_types/module_info_get_no_tag_types/ s/module_info_analysis_info/module_info_get_analysis_info/ s/module_info_aditi_top_down_procs/module_info_get_aditi_top_down_procs/ |
||
|
|
3fc6b3f128 |
Change the representation of types in the compiler.
Estimated hours taken: 30 Branches: main Change the representation of types in the compiler. We also add some support for handling kinds, which will be used later when we have a kind system. There are a number of places where kinds are not yet handled correctly -- we assume that all kinds will be `star'. Each of these locations is flagged with a comment that contains "XXX kind inference:". compiler/prog_data.m: Implement the new version of type (type). Change the definition of type_param to be a variable instead of a term, since all parameters must be variables anyway. Implement versions of varset.merge_* which work with tvarsets and produce renamings instead of substitutions. Renamings are more convenient than substitutions because we don't need to know the kinds of type variables in order to build the renaming, and in any case the substitutions shouldn't have anything other than variables in the range so renamings will be more efficient and safe. Define the type of kinds, and provide a couple of utility predicates to operate on them. compiler/prog_io.m: Parse type definition heads as a sym_name and list of type_params, rather than a functor. Handle this change in other predicates. Allow parse errors to be returned by get_with_type/3, and handle these errors. Remove parse_type/2. This predicate didn't do any processing, it just forwarded handling to convert_type/2. compiler/prog_io_typeclass.m: Change type_is_functor_and_vars to handle the new representation of types. In doing so, we retain the old behaviour that pure predicates pass this test, but no other pred or func types. This behaviour is arguably incorrect, but there is little point changing the behaviour at the moment. Instead we should remove these kind of restrictions entirely, but that should be done later. compiler/prog_io_util.m: Provide predicates to both parse and unparse types. We need to unparse types before printing them out, since we do a lot of special case handling when printing out terms and we don't want to duplicate this functionality for types. compiler/module_qual.m: Remove report_invalid_type. We now report ill-formed types during parsing. compiler/superhomogeneous.m: Handle errors from the parsing of type expressions. compiler/prog_out.m: Provide a predicate to convert builtin_types to their string names, and vice-versa. compiler/prog_type.m: Add a bunch of simple tests to use on types which may have kind annotations present. In such cases, types do not have a canonical representation so the simple handling of these tests is not what we want. (Note that these are only required in early phases. The kind annotations -- when they are implemented -- will be removed before type checking.) Consistently handle the application of renamings, substitutions and recursive substitutions to various data structures. compiler/mercury_to_mercury.m: Implement mercury_output_type, mercury_format_type and mercury_type_to_string. These convert the type to a term before formatting -- the reason for this is so that appropriate parentheses are used when formatting operators. This results in some slight changes to error messages, which are reflected in changes to the expected output files in the tests. Remove the old version of mercury_type_to_string. Change the argument ordering of mercury_format_var to be consistent with mercury_format_type. (Other predicates in this module should probably be changed in a similar way, since this argument ordering is more amenable to higher-order programming. But that can be left for another change.) compiler/type_util.m: Implement type unification. The behaviour is much the same as the previous behaviour, except that we now handle apply/N types properly, and we also allow for kind annotations. Implement an occurs check for types. Remove the example definition of replace_eqv_type. It isn't used and would no longer work anyway even if it would have worked before. Add a tvar_kind_map field to ctor_defn. The functions type_info_type and type_ctor_info_type now return types with `void' as their argument, rather than the type that the type_info or type_ctor_info was for. Remove type_util.real_vars/2, since it no longer does anything different from prog_type.vars/2. Remove the commented out implementation of type_to_ctor_and_args/3. Its implementation is in prog_type.m, and has changed significantly in any case. compiler/add_clause.m: Move parse_purity_annotation/3 to prog_io_util.m. compiler/check_typeclass.m: Remove apply_substitution_to_var_list/3, since we now have predicates in prog_type.m to handle such things. compiler/continuation_info.m: compiler/trace.m: Use prog_type.vars/2 instead of type_util.real_vars/2. The two predicates have the same meaning now since type_infos don't contain any type variables. compiler/hlds_data.m: Add tvar_kind_map fields to hlds_type_defn and hlds_class_defn. compiler/hlds_pred.m: Add a tvar_kind_map field to pred_info. compiler/polymorphism.m: Add a tvar_kind_map field to poly_info. Remove unify_corresponding_types, which is no longer used. compiler/hlds_out.m: Use mercury_output_type/5 instead of term_io__write_term/4 and mercury_output_term/5. compiler/post_typecheck.m: Build the void substitution directly rather than building intermediate lists. compiler/recompilation.version.m: Use term__list_subsumes instead of type_list_subsumes, which now operates only on types. This follows up on what was suggested in an XXX comment. compiler/typecheck_errors.m: Use unparse_type/2 to format error messages. compiler/typecheck_info.m: Don't export write_type_with_bindings/5. It is no longer used outside of this module. compiler/*.m: Conform to the above changes. library/rtti_implementation.m: Fix a syntax error that went undetected in our previous implementation, and amazingly enough was compiled correctly anyway. library/term.m: Move the versions of term__unify, term__unify_list and term__list_subsumes that were implemented specifically for types to here. The version of term_unify that takes a list of bound variables (i.e., variables that should not be bound any further) is used by the subsumption check, which in turn is used by recompilation.version.m. tests/invalid/kind.err_exp: tests/invalid/tc_err1.err_exp: tests/invalid/tc_err2.err_exp: tests/misc_tests/pretty_print_test.exp: Update the expected output of these tests to match what we now do. |
||
|
|
a25ba19ea0 |
Improve the error checking for mutable declarations.
Estimated hours taken: 12 Branches: main Improve the error checking for mutable declarations. Fix a bug with solver types and sub-modules reported by Peter Hawkins. Workaround a bug with mutable declarations and sub-modules. Currently, the compiler aborts if there is a mutable declaration in the parent module. With this change mutable declarations will not be visible in child modules. XXX This is not correct since they should be visible, but this can be fixed as a separate change. compiler/prog_data.m: Extend the item_origin type with information about what source-to-source transformations are responsible for compiler introduced items. We need this information for error checking mutable declarations. It also provides an additional layer of sanity checking in the parse tree. Add origin fields to the clause and initialise items, since they can both now be introduced by source-to-source transformations. compiler/prog_io.m: compiler/prog_io_dcg.m: compiler/prog_io_typeclass.m: Conform to the above change. compiler/make_hlds_passes.m: Don't issue spurious errors about initialise declarations that were introduced by the transformation for mutable declarations. Abort if invalid initialise declarations were introduced by other compiler passes since this indicates a bug in the compiler. Check if mutable declarations occur in the interface of a module and emit an error if they do. Don't generate initialise items and foreign code from a mutable declaration unless we are in the defining module for the mutable declaration. Don't generate foreign_procs for solver types *unless* we are in the defining module. Doing otherwise breaks the compiler when using solver types and sub-modules. Fix the formatting of an error message concerning initialise decls. s/foreign_code/foreign_proc/ in a spot. compiler/add_solver.m: compiler/mercury_to_mercury.m: compiler/recompilation.check.m: compiler/recompilation.version.m: compiler/add_class.m: compiler/add_pragma.m: compiler/state_var.m: Conform to the above changes. compiler/modules.m: Handle mutable declarations in private interfaces. Clean up some code related to foreign_import_module decls. Conform to the changes in prog_data.m. compiler/prog_util.m: Shift the functions for mutable access predicates and variables to this module. The code that generates interface files also needs to be able to access them. compiler/module_qual.m: Conform to the above changes. Fix a bug where the context in the mq_info structure was not being updated. This caused error messages for mutable declarations that contain undefined types or insts to have the wrong context. compiler/hlds_data.m: Fix a typo. vim/syntax/mercury.vim: Highlight `mutable' and `untrailed' appropriately. tests/hard_coded/sub-modules/Mmakefile: tests/hard_coded/sub-modules/ts.m: tests/hard_coded/sub-modules/ts.tsub.m: tests/hard_coded/sub-modules/ts.exp: Add Peter Hawkin's test case for the bug with solver types and sub-modules. tests/invalid/Mmakefile: tests/invalid/bad_mutable.m: tests/invalid/bad_mutable.err_exp: Add a test for the various sorts of errors that can occur with mutable declarations. |
||
|
|
6df9a05856 |
This diff cleans up a bunch of modules. It has no algorithmic changes
Estimated hours taken: 10 Branches: main This diff cleans up a bunch of modules. It has no algorithmic changes other than in the formatting of error messages. compiler/error_util.m: Delete the obsolete predicate append_punctuation, since the suffix format component can now do more, and do it more easily. compiler/goal_util.m: compiler/hlds_goal.m: compiler/hlds_llds.m: compiler/instmap.m: compiler/const_prop.m: Change the argument order of some the predicates exported by these modules to make them easier to use with state variable syntax. compiler/*.m: Convert a bunch of these modules to four space indentation, and fix departures from our coding style. Conform to the changed argument order above. Use suffixes instead of append_punctuation. library/string.m: Add string.foldl2. tests/invalid/circ_*.err_exp: tests/warnings/unused_args_*.exp: Expect the updated error messages, which format sym_names consistently the same way as other messages. |
||
|
|
10536c5ee0 |
Divide make_hlds.m into submodules of manageable size.
Estimated hours taken: 12 Branches: main Divide make_hlds.m into submodules of manageable size. compiler/make_hlds.m: Distribute all the code that was previously here to new submodules. Include those submodules. Keep the existing interface of this module by defining predicates that do nothing except call the actual implementation in one of those submodules. The only changes visible from outside are the renaming of a predicate and the creation of a second name, make_hlds_qual_info, for qual_info. Both changes are designed to avoid ambiguity in the presence of intermodule optimization. compiler/add_aditi.m: Submodule for dealing with aditi-specific issues. compiler/add_class.m: Submodule for handling typeclasses. compiler/add_clause.m: Submodule for handling the general processing of clauses. compiler/add_pred.m: Submodule for handling new predicates. compiler/add_special_pred.m: Submodule for handling special (unify/compare/index/init) predicates. compiler/add_type.m: Submodule for handling new types. compiler/add_mode.m: Submodule for handling new insts and modes. compiler/add_solver.m: Submodule for handling new solver types. compiler/add_pragma.m: Submodule for handling new pragmas. compiler/state_var.m: Submodule for handling the state variable transformation. compiler/superhomogeneous.m: Submodule for converting clauses to superhomogeneous form. compiler/field_access.m: Submodule for field access syntax. compiler/make_hlds_passes.m: Submodule containing the code that performs passes on the item list, adding things to the HLDS, calling the other submodules as necessary. compiler/make_hlds_warn.m: Submodule that looks for constructs that merit warnings. compiler/make_hlds_error.m: Submodule containing error messages used by more than one submodule. compiler/hlds_pred.m: Since this module defines the clauses_info and proc_id types, move the predicates that initialize values of that type here as well from make_hlds.m (deleting an unnecessary parameter from one). compiler/hlds_pred.m: compiler/prog_data.m: Move the type tvar_name_map from from hlds_pred.m to prog_data.m, since that is where similar maps are. compiler/check_typeclass.m: compiler/mercury_compile.m: Conform to the change to make_hlds_qual_info. compiler/hlds_out.m: compiler/prog_out.m: Replace two identical predicates for printing out lists of strings in hlds_out.m and make_hlds.m with just one in prog_out.m, since that is where it belongs in the compiler. compiler/prog_util.m: Move some utility predicates for substitutions and term recognition here from make_hlds.m, since they are needed by more than one submodule. Make this module conform to our coding guidelines, and convert it to four-space indentation to eliminate bad line breaks. compiler/clause_to_proc.m: compiler/hlds_code_util.m: compiler/make_tags.m: compiler/prog_mode.m: compiler/quantification.m: compiler/type_util.m: Trivial formatting changes. compiler/notes/compiler_design.html: Describe the new modules. |