mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-15 05:44:58 +00:00
672f77c4ecd07daaf01217bc81c336dcf5d6aa02
121 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
672f77c4ec |
Add a new compiler option. --inform-ite-instead-of-switch.
Estimated hours taken: 20 Branches: main Add a new compiler option. --inform-ite-instead-of-switch. If this is enabled, the compiler will generate informational messages about if-then-elses that it thinks should be converted to switches for the sake of program reliability. Act on the output generated by this option. compiler/simplify.m: Implement the new option. Fix an old bug that could cause us to generate warnings about code that was OK in one duplicated copy but not in another (where a switch arm's code is duplicated due to the case being selected for more than one cons_id). compiler/options.m: Add the new option. Add a way to test for the bug fix in simplify. doc/user_guide.texi: Document the new option. NEWS: Mention the new option. library/*.m: mdbcomp/*.m: browser/*.m: compiler/*.m: deep_profiler/*.m: Convert if-then-elses to switches at most of the sites suggested by the new option. At the remaining sites, switching to switches would have nontrivial downsides. This typically happens with the switched-on type has many functors, and we treat one or two specially (e.g. cons/2 in the cons_id type). Perform misc cleanups in the vicinity of the if-then-else to switch conversions. In a few cases, improve the error messages generated. compiler/accumulator.m: compiler/hlds_goal.m: (Rename and) move insts for particular kinds of goal from accumulator.m to hlds_goal.m, to allow them to be used in other modules. Using these insts allowed us to eliminate some if-then-elses entirely. compiler/exprn_aux.m: Instead of fixing some if-then-elses, delete the predicates containing them, since they aren't used, and (as pointed out by the new option) would need considerable other fixing if they were ever needed again. compiler/lp_rational.m: Add prefixes to the names of the function symbols on some types, since without those prefixes, it was hard to figure out what type the switch corresponding to an old if-then-else was switching on. tests/invalid/reserve_tag.err_exp: Expect a new, improved error message. |
||
|
|
beeedc6e0d |
Change some types that are defined as equivalences for pairs into
Estimated hours taken: 1 Branches: main Change some types that are defined as equivalences for pairs into named d.u. types. Fix a bug in with the handling of type class method calls in the termination analyser. We should not run pass 2 if we encounter a method call during pass 1. Add an XXX comment about some other possible bugs of a similar nature. compiler/prog_data.m: Define the type arg_size_term/0 as a d.u. type, not a pair. compiler/term_errors.m: Define the type termination_error_context/0 as a d.u. type, not a pair. Change the semidet predicate indirect_error/1 into a det function is_indirect_error/1. Add the function is_fatal_error/1. (See change to termination.m below.) compiler/term_pass2.m: Define the type call_weight_info/0 as a d.u. type, not a pair. compiler/termination.m: Move the body of the closure that determines if an error is fatal into term_errors.m, and make it into a named function that returns a bool. Use that here. (In the process of doing this I discovered that the code for handling fatal errors was not handling type class method calls correctly, they *should* be handled like higher-order calls. Also, some of the more recently added termination error categories may not be handled correctly here - I have added an XXX comment to term_errors.m regarding this.) compiler/unify_proc.m: Define the type unify_proc_id/0 as a d.u. type, not a pair. compiler/goal_store.m: Define the type stored_goal/0 as a d.u. type, not a pair. compiler/mode_errors.m: Define the type merge_error/0 as a d.u. type, not a pair. compiler/accumulator.m: compiler/instmap.m: compiler/mercury_to_mercury.m: compiler/modecheck_unify.m: compiler/prog_io_pragma.m: compiler/term_constr_initial.m: compiler/term_pass1.m: compiler/term_traversal.m: compiler/term_util.m: Conform to the above changes. |
||
|
|
e53a6192d0 |
Improve the performance of the compiler by making sure that the mode_info
Estimated hours taken: 3 Branches: main Improve the performance of the compiler by making sure that the mode_info structure contains only its most frequently updated and/or accessed fields and that these fit into an eight-word memory cell, moving the rest of the fields to the mode_sub_info structure. This improves performance on our standard benchmark from 20.60 seconds to 19.06 seconds, an improvement of 7%. compiler/mode_info.m: Make the change described above. Several fields of mode_sub_info were bools. Replace these with single-purpose types, to make them harder to mix up, especially during initialization. Similarly, replace the type of the field used for checking parallel conjunctions with a specialized type instead of a pair. Rename some predicates for greater consistency with the rest of the compiler. Rename field names to avoid ambiguities. Use the access predicates instead of field access syntax to access the fields of mode_info and mode_sub_info, to make any similar changes easier in the future, and also to make statistics about frequency of field accesses easier to gather. compiler/modecheck_call.m: compiler/modecheck_unify.m: compiler/modes.m: Conform to the changes in mode_info. compiler/modes.m: compiler/unique_modes.m: Do not execute the (save, set to known value, restore) sequence for the "duplicated for switch" feature unless necessary. This avoids a bunch of accesses and updates to the mode_sub_info. In both cases, this required moving some code that would otherwise have had to be duplicated into an inlined predicate. In unique_modes.m, rename a predicate to allow its name to be used for the new inlined predicate. compiler/Mercury.options: Change the inlining limit to allow those predicates to be inlined. |
||
|
|
168f531867 |
Add new fields to the goal_info structure for region based memory management.
Estimated hours taken: 4 Branches: main Add new fields to the goal_info structure for region based memory management. The fields are currently unused, but (a) Quan will add the code to fill them in, and then (b) I will modify the code generator to use the filled in fields. compiler/hlds_goal.m: Make the change described above. Group all the procedures that access goal_info components together. Some of the getters were predicates while some were functions, so this diff changes them all to be functions. (The setters remain predicates.) compiler/*.m: Trivial changes to conform to the change in hlds_goal.m. In simplify.m, break up a huge (800+ line) predicate into smaller pieces. |
||
|
|
002c728b95 |
Fix a problem in compiler/error_util.m where the compiler would throw an
Estimated hours taken: 4 Branches: main Fix a problem in compiler/error_util.m where the compiler would throw an exception when attempting to eliminate duplicate error messages for output. The problem was that error_util defined a data constructor (print_anything) with a higher order argument; higher order terms cannot be compared. compiler/error_util.m: Replace the higher order argument of the print_anything data constructor argument with an existentially quantified constrained type. Define the print_anything/1 type class. compiler/mode_errors.m: Use the new definition for print_anything. |
||
|
|
ac651b033b |
Only report mode warnings if they occur in all modes.
Estimated hours taken: 5 Branches: main Only report mode warnings if they occur in all modes. simplify.m already had code to remove error_specs that do not occur in all modes, so move this code to error_util.m and reuse it in modes.m. Also only report mode warnings for user defined predicates. Do not report them for compiler generated predicates (after making the change in the previous paragraph, the compiler issued a warning for a generated unification predicate in term_to_xml.m). compiler/cse_detection.m: Conform to new interface of modecheck_proc. compiler/error_util.m: Add an abstract type error_spec_accumulator and predicates for working with this type. The new type is used for accumulating errors over multiple modes of a predicate. The code for accumulating error specs has been moved from simplify.m. There was a bug in this code caused by the arguments of the pair in the error_spec_accumulator type getting mixed up. This bug has now been fixed. Add mode_report_control to the modecheck phase, so we can mark which error specs should only be reported if they occur in all modes. compiler/mode_errors.m: Delete report_mode_errors and report_mode_warnings, since these are no longer used. Export mode_error_info_to_spec and mode_warning_info_to_spec for converting mode errors and warnings to error specs. Conform to changes in error_util.m. compiler/modecheck_unify.m: Do not supress warnings if the mode may use a subtype, since we want such warnings to be displayed if the occur in all modes. Only report mode warnings if the predicate is not a compiler generated predicate. compiler/modes.m: Delete modecheck_pred_mode and modecheck_proc_info, since they are not used anywhere. In modecheck_proc and modecheck_proc_general report a list of error specs, instead of the number of errors. These predicates are now no longer responsible for printing the errors, they just return the error specs. We need to do it this way so we can accumulate the errors over all modes (eliminating any warnings that don't occur in all modes) before printing them. Report errors in modecheck_pred_mode_2, after all modes have been processed. Accumulate the error specs in modecheck_procs, using the new predicates in error_util.m. Move the code for only reporting the first error encountered for a proc from mode_errors.m to here. Also improve the comment for that bit of code. Conform to changes in error_util.m. compiler/pd_util.m: Conform to changes in error_util.m. compiler/simplify.m: Move the code for accumulating error specs to error_util.m compiler/unify_proc.m: compiler/unique_modes.m: Conform to changes elsewhere. tests/invalid/ho_type_mode_bug.err_exp: The order the errors are reported has changed here, because we now call write_error_specs to report mode errors. tests/invalid/qualified_cons_id2.err_exp: tests/warnings/simple_code.exp: tests/warnings/simple_code.m: We now correctly report a warning we didn't report before. |
||
|
|
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. |
||
|
|
ba93a52fe7 |
This diff changes a few types from being defined as equivalent to a pair
Estimated hours taken: 10 Branches: main This diff changes a few types from being defined as equivalent to a pair to being discriminated union types with their own function symbol. This was motivated by an error message (one of many, but the one that broke the camel's back) about "-" being used in an ambiguous manner. It will reduce the number of such messages in the future, and will make compiler data structures easier to inspect in the debugger. The most important type changed by far is hlds_goal, whose function symbol is now "hlds_goal". Second and third in importance are llds.instruction (function symbol "llds_instr") and prog_item.m's item_and_context (function symbol "item_and_context"). There are some others as well. In several places, I rearranged predicates to factor the deconstruction of goals into hlds_goal_expr and hlds_goal_into out of each clause into a single point. In many places, I changed variable names that used "Goal" to refer to just hlds_goal_exprs to use "GoalExpr" instead. I also changed variable names that used "Item" to refer to item_and_contexts to use "ItemAndContext" instead. This should make reading such code less confusing. I renamed some function symbols and predicates to avoid ambiguities. I only made one algorithmic change (at least intentionally). In assertion.m, comparing two goals for equality now ignores goal_infos for all kinds of goals, whereas previously it ignored them for most kinds of goals, but for shorthand goals it was insisting on them being equal. This seemed to me to be a bug. Pete, can you confirm this? |
||
|
|
07b216c4fb |
Treat trace goals as quantifying the variables that occur in their io() and/or
Estimated hours taken: 2
Branches: main
Treat trace goals as quantifying the variables that occur in their io() and/or
state() components.
compiler/hlds_goal.m:
Extend trace scopes with a field for recording the set of quantified
variables.
compiler/add_clause.m:
Record the list of quantified variables.
compiler/quantification.m:
Treat the list of quantified variables as for other scopes.
compiler/hlds_out.m:
Write out the new field.
compiler/mercury_to_mercury.m:
Reorder the arguments of some predicates to make them easier to curry,
e.g. for the new code in hlds_out.m.
Rename some predicates to avoid ambiguities.
compiler/*.m:
Conform to the changes in hlds_goal.m and/or mercury_to_mercury.m.
tests/hard_coded/trace_goal_3.{m,exp}:
New test case to test the new functionality.
tests/hard_coded/Mmakefile:
Enable the new test case.
|
||
|
|
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. |
||
|
|
84ffc0924d |
Fix --warn-unused-imports warnings in some of the modules.
Estimated hours taken: 4 Branches: main library/*.m: compiler/*.m: Fix --warn-unused-imports warnings in some of the modules. |
||
|
|
6de9f4d1e3 |
Modify the type and purity check passes to gather up all error messages,
Estimated hours taken: 8 Branches: main Modify the type and purity check passes to gather up all error messages, and print them all at once after sorting. compiler/typecheck.m: compiler/typeclasses.m: compiler/post_typecheck.m: compiler/purity.m: Gather up all error messages instead of printing them when generated. In some places the gathered list of error specifications allows us to eliminate error counts and error flags. Eliminate the last occurrences of io.write_* in these modules, replacing them with error_specs. Change the error messages generated by purity.m to eliminate the unnecessary module qualification of the name of the predicate or function in which the error occurs. compiler/typecheck_errors.m: Turn the predicates here that used to print error messages into functions that just return the error specification. compiler/mode_errors.m: Make a predicate used by post_typecheck.m return an error spec instead of writing it out. compiler/typecheck_info.m: Record the list of errors instead of simple a count of the errors printed. compiler/mercury_compile.m: Print the error message batches returned by type checking and purity checking. compiler/error_util.m: Modify the way we represent severity to allow passes such as typechecking to count the number of errors *without* printing anything. compiler/add_pred.m: compiler/det_report.m: compiler/make_hlds_warn.m: compiler/module_qual.m: Conform to the change in error_util.m. compiler/Mercury.options: Record the fact that some more compiler modules need the workaround for trace goals. tests/invalid/*err_exp: tests/warnings/*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. |
||
|
|
aeeedd2c13 |
Standardize formatting of comments at the beginning of modules.
compiler/*.m: Standardize formatting of comments at the beginning of modules. |
||
|
|
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.
|
||
|
|
73e40cd5e2 |
Make it an error for the (promised) purity of a foreign clause to disagree
Estimated hours taken: 6
Branches: main, release
Make it an error for the (promised) purity of a foreign clause to disagree
with the declared purity of the corresponding predicate or function
declaration. We only perform this check in the absence of a
promise_{pure,semipure} pragma for the predicate or function.
Previously this situation was sometimes picked up by purity analysis but not
in all cases. For example, if a predicate was declared impure but the
foreign_proc was promised pure it wasn't reported. In that particular case
it was a problem because if the foreign_proc did not have any outputs, then
simplify.m might have optimised its body away (which is how I noticed this).
compiler/add_pramga.m:
In the absence of promise_{pure,semipure} pragmas emit error messages
about mismatches between the declared purity of a procedure and the
(promised) purity of a foreign clause for it.
compiler/mode_errors.m:
Fix a typo in an error message: s/becaise/because/
compiler/purity.m:
Fix a bug reported by Ian. Inconsistent purity annotation were being
treated as both a warning and an error. Make it into an error.
library/private_builtin.m:
library/solutions.m:
Delete bogus purity promises from foreign_proc attributes reported by
the new check.
tests/invalid/Mmakefile:
tests/invalid/foreign_purity_mismatch.{m,err_exp}:
Test case for the new error.
compiler/simplify.m:
compiler/prog_io_pragma.m:
Fix some formatting.
tests/*/*:
Fix purity errors picked up by the new check.
|
||
|
|
e038451a54 |
Fix a badly formatted verbose error message.
Estimated hours taken: 0.5 Branches: main, release Fix a badly formatted verbose error message. compiler/det_report.m: Fix the formatting of the error message. Fix a typo: s/appropiate/appropriate/ Replace an if-then-else with switch. compiler/accumulator.m: compiler/mode_errors.m: compiler/prog_io_util.m: compiler/term_constr_errors.m: compiler/term_errors.m: compiler/typecheck_errors.m: Minor formatting fixes. Fix some spelling errors. tests/invalid/Mercury.options: tests/invalid/multisoln_func.err_exp: Test the verbose error message for this test case. |
||
|
|
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/ |
||
|
|
a9a2825ace |
Replace __ with . as the module qualifier everywhere in all the modules
Estimated hours taken: 0.5 Branches: main profiler/*.m: deep_profiler/*.m: compiler/*.m: Replace __ with . as the module qualifier everywhere in all the modules of the profiler and deep profiler and in some modules of the compiler. |
||
|
|
684ecfbd55 |
Undo my recent changes to purity error checking in the context of inst any
Estimated hours taken: 16
Branches: main
Undo my recent changes to purity error checking in the context of inst any
non-locals in negated contexts.
Implement a better way of handling the problem, as discussed on the mailing
list. The new solution is to require that any goals featuring inst any
non-locals in a negated context must appear in a
promise_{pure,semipure,impure} context. This is something of a compromise:
on the one hand it does require that the condition be explicitly recognised
by the programmer; on the other, it does not require that the "offending" goals
be individually identified (this is partly for pragmatic reasons: the earlier
approach required a plethora of awkward impurity declarations on goals that
would otherwise be considered completely pure).
compiler/mode_errors.m:
Remove purity_error_should_be_impure and purity_error_wrongly_impure
data constructors; add purity_error_should_be_in_promise_purity_scope.
compiler/mode_info.m:
Replace the in_negated_context field with the in_promise_purity_scope
field.
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
Back out my previous change.
compiler/modes.m:
Record a purity error if a non-local inst any variable appears
in a negation or the condition of an if-then-else goal.
compiler/purity.m:
compiler/unique_modes.m:
Back out my previous change.
doc/reference_manual.texi:
Document the new purity rules for inst any non-locals in negated
contexts.
tests/debugger/solver_test.m:
tests/hard_coded/any_free_unify.m:
tests/invalid/any_passed_as_ground.m:
tests/invalid/any_to_ground_in_ite_cond.m:
tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/anys_in_negated_contexts.m:
tests/invalid/purity/impure_func_t7.err_exp:
tests/invalid/purity/impure_func_t7.m:
Fix up error cases to use the new syntax.
|
||
|
|
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. |
||
|
|
a1ed9368a7 |
Require impurity annotations on goals in negated contexts or lambdas
Estimated hours taken: 10 Branches: main Require impurity annotations on goals in negated contexts or lambdas containing non-local inst any variables. Such goals can violate referential transparency, even though they might otherwise be considered pure. NEWS: Mention the new change. compiler/inst_util.m: Add utility preds inst_contains_any/2 and var_inst_contains_any/3. compiler/mode_errors.m: Add three new mode errors to cover the new cases. compiler/mode_info.m: Add field `in_negated_context' to the mode_info. compiler/modecheck_call.m: compiler/modecheck_unify.m: Perform purity checks for goals in negated contexts containing inst any non-locals or lambdas containing inst any non-locals. compiler/modes.m: Add negated context tracking. compiler/purity.m: Defer purity checking on goals in negated contexts because we don't have inst information at the time purity analysis is run. compiler/unique_modes.m: We now have to include the goal_info in calls to modecheck_call_pred. doc/reference_manual.texi: Document the new requirement. tests/invalid/Mmakefile: tests/invalid/anys_in_negated_contexts.err_exp: tests/invalid/anys_in_negated_contexts.m: Add a test case. |
||
|
|
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/ |
||
|
|
e069d16ab1 |
Do not display the For more information try recompiling with -E'' prompt
Estimated hours taken: 1.5 Branches: main Do not display the `For more information try recompiling with `-E'' prompt unless we really mean it, i.e. there is actually more information available. XXX This change is incomplete for the mode_errors module because that module requires more substantial changes to make this work - I'll do that as a separate diff. compiler/globals.m Add a new global (and access predicates) that keeps track of whether we have any verbose error information that could be displayed if we recompiled with `-E'. compiler/mercury_compile.m Check the new global flag before prompting the user to recompile with `-E'. compiler/mode_errors.m Add an XXX comment about needing to respect the extra error info flag properly. compiler/accumulator.m compiler/add_clause.m compiler/add_pred.m compiler/add_type.m compiler/assertion.m compiler/check_typeclass.m compiler/det_report.m compiler/magic_util.m compiler/make_hlds_error.m compiler/modes.m compiler/module_qual.m compiler/modules.m compiler/post_typecheck.m compiler/purity.m compiler/stratify.m compiler/typecheck_errors.m Set the new global flag when we come across an error for which we have a verbose error message. tests/recompilation/*: tests/invalid/*: Update expected error files. |
||
|
|
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. |
||
|
|
2f06c5b8fe |
Don't just detect when successive unifications unify the same variable with
Estimated hours taken: 6
Branches: main
Don't just detect when successive unifications unify the same variable with
incompatible function symbols: also issue a warning.
compiler/ml_code_gen.m:
compiler/stratify.m:
compiler/table_gen.m:
mdbcomp/trace_counts.m:
Fix pieces of code that get the new warning.
compiler/modecheck_unify.m:
When detecting such unifications, add warnings for them, except if
the initial inst of the current restricts the set of allowed bindings
of the input arguments. If the initial inst of X is bound(f), then
an otherwise correct unification Y = g may fail if Y has been computed
from X. (We don't whether it has, so we have to be conservative.)
There are examples of such code in the library, e.g. functor in
deconstruct.m.
Factor out some common code.
compiler/mode_errors.m:
Add the infrastructure needed for printing warnings, and the two forms
of this warning in particular.
compiler/mode_info.m:
Extend the mode_info structure to make room for warnings, and for the
initial inst of the procedure arguments.
Switch to four-space indentation.
compiler/inst_util.m:
Add a predicate that tests whether an inst may restrict the set of
possible cons_ids a variable may be bound to.
Change the argument order of some predicates to allow them to be
used in higher order code. We don't need to make the switched-on
argument the first argument anymore.
Switch to four-space indentation.
compiler/hlds_goal.m:
Change the argument order of some predicates to allow the use of state
variables.
compiler/higher_order.m:
compiler/instmap.m:
compiler/mode_constraints.m:
compiler/mode_debug.m:
compiler/mode_ordering.m:
compiler/modecheck_call.m:
compiler/trace.m:
Conform to the changed argument orders described above.
Switch to four-space indentation.
compiler/common.m:
compiler/inst_match.m:
compiler/hlds_pred.m:
compiler/lambda.m:
compiler/magic.m:
compiler/magic_util.m:
compiler/modes.m:
compiler/pd_util.m:
compiler/post_typecheck.m:
compiler/unique_modes.m:
Conform to the changed argument orders described above.
tests/invalid/occurs.err_exp:
Expect the extra warning.
tests/warnings/Mmakefile:
Enable the unify_f_g test case I accidentally committed earlier.
tests/warnings/unify_f_g.{m,err_exp}:
Finalize that test case.
tests/warnings/simple_code.err_exp:
Expect the extra warning.
|
||
|
|
d692bb674f |
Move the rest of mode_errors.m to use error_util.
Estimated hours taken: 8 Branches: main Move the rest of mode_errors.m to use error_util. compiler/mode_errors.m: The parts of this module that generate error messages (as opposed to progress messages) now all return a description of the error to a central place for printing by error_util.m. This should make it significantly easier to add new error messages. compiler/error_util.m: Add the new capability to support mode_errors.m: that of describing in one data structure a sequence of calls to write_error_pieces. compiler/hlds_out.m: Given a bunch of existing predicates that print various things, provide versions that convert those things to strings, for use in mode_errors.m. Write_unify_context had two versions for printing and only one version for conversion to pieces; add the second version for conversion to pieces. Change the order of arguments of the five-argument version of write_unify_context to allow the use of state variables. compiler/mercury_to_mercury.m: compiler/prog_out.m: Given a bunch of existing predicates that print various things, provide versions that convert those things to strings, for use in hlds_out.m and mode_errors.m. compiler/det_report.m: Conform to the changed argument order of write_unify_context. library/term_io.m: Fix an old bug: the code of add_escaped_char wasn't actually doing any escaping. hlds_out.m now relies on it doing so. tests/hard_coded/xmlable_test.m: Due to the bugfix in term_io.m, string__string now protects &s with backslashes; expect this. tests/invalid/*.err_exp: Expect mode error messages in the new, better format. |
||
|
|
e06106dfd6 |
Convert this module to four-space indentation to reduce the number
Estimated hours taken: 4 Branches: main compiler/mode_errors.m: Convert this module to four-space indentation to reduce the number of bad line breaks. Fix some departures from our coding standards. Convert most of this module to use error_util.m to format error messages instead just io__write_strings. (Converting the rest will require some changes in hlds_out.m.) compiler/error_util.m: Provide the ability to add prefixes in front of following format components, and the ability to influence the indentation level when starting a new line. This is needed to support some of the new uses of error_util in mode_errors.m. compiler/state_var.m: Remove a redundant format component that causes a minor test case discrepancy with the new code in error_util.m. compiler/modes.m: Minor style fixes. tests/invalid/*.err_exp: Expect better format in mode error messages. |
||
|
|
408f060ed7 |
When printing error messages involving lists of insts, put each inst
Estimated hours taken: 1 Branches: main compiler/mode_errors.m: When printing error messages involving lists of insts, put each inst on a line of its own. Since insts can be deeply nested, it could be difficult to divide the generated humongous lines into the original sequence of insts without this diff. tests/invalid/*.err_exp: Expect the new format of error messages. |
||
|
|
3c60c0e485 |
Change a bunch of modules to import only one module per line, even
Estimated hours taken: 4 Branches: main compiler/*.m: Change a bunch of modules to import only one module per line, even from the library. compiler/mlds_to_il.m: compiler/mlds_to_managed.m: Convert these modules to our current coding style. Use state variables where appropriate. Use predmode declarations where possible. |
||
|
|
9521818650 |
Get the purity check pass to not issue warnings about unnecessary purity
Estimated hours taken: 16 Branches: main Get the purity check pass to not issue warnings about unnecessary purity annotations on compiler-generated predicates. The problem I am addressing is that when an optimization such as type specialization creates a clone of a predicate, that predicate gets all the original predicate's annotations. During the creation of a .opt file, purity checking sees the clauses of the original predicate and knows that the annotation is not redundant, but doesn't know that about the copy, since it has no definition at all (it doesn't need one). The fix is to put into each pred_info an indication of where the predicate came from, and to never warn about unnecessary purity annotations of predicates that the programmer didn't write. This diff also uses the origin indication to record human-usable names of compiler-generated or compiler-transformed predicates in RTTI for use by the debugger. compiler/hlds_pred.m: Replace two fields in pred_infos, that say (a) whether the predicate is a special (unify/compare/index/init) predicate and (b) whether it is a type class method implementation, with an origin field saying where the predicate came from. This field has several alternatives, special preds and type class method implementation being only two. Make the predicates that create pred_infos take an argument specifing where the predicate comes from. Replace a copy of one of the old fields in rtti_proc_labels with the new one. Make the name of the existing function more descriptive. compiler/purity.m: Use the origin field to suppress unnecessary annotation warnings for compiler-generated predicates. compiler/layout_out.m: Use the origin field to generate more human-friendly names for predicates, instead of the existing linker-friendly names. The debugger doesn't insist on predicate names being unique, even within a module. compiler/*.m: Conform to the changed interface of hlds_pred.m. The most significant changes were for recording the origin of new predicates. In one case (dnf.m) it also involved passing the required information down to the place where the new predicates were created through the dnf_info tuple instead of separate arguments, and switching to state variable notation. tests/debugger/*.exp*: tests/debugger/declarative/*.exp*: tests/hard_coded/*.exp*: Update the expected outputs to expect human-friendly predicate names. |
||
|
|
59d2d4a573 |
This adds a module mdbcomp__trace_counts that reads in the
Estimated hours taken: 17 Branches: main This adds a module mdbcomp__trace_counts that reads in the .mercury_trace_counts files produced by the compiler's trace mechanism. The format of said files was slightly changed. As the new module is to be used by the compiler and the debugger, it is placed in the mdbcomp module. This required bringing some types from the compiler into a new module within mdbcomp. browser/trace_counts.m: New module for reading execution trace summaries. browser/prim_data.m: New module holding types and predicates moved in from the compiler. Types: pred_or_func, sym_name, module_name, proc_label, special_pred_id, trace_port Predicates: string_to_sym_name, insert_module_qualifier The mode field of proc_label is now an int instead of a proc_id to avoid pulling proc_id into mdbcomp. browser/mdbcomp.m: Add trace_counts and prim_data to the mdbcomp module. browser/declarative_execution.m: Renamed mdb's definition of module_name to flat_module_name to avoid conflicts with the definition in mdbcomp__prim_data. runtime/mercury_trace_base.c: In the format of .mercury_trace_counts, write module and predicate names now use quoted atom syntax so that names with spaces and non-printable characters can be machine-parsed. browser/: compiler/: Many changes to account for movement of types, and the change to proc_label. |
||
|
|
20cd51e70a |
This is a cleanup diff; there are no changes in algorithms.
Estimated hours taken: 8 Branches: main This is a cleanup diff; there are no changes in algorithms. compiler/delay_info.m: compiler/instmap.m: compiler/inst_match.m: compiler/inst_util.m: compiler/make.module_target.m: compiler/mode_errors.m: compiler/modes.m: compiler/mode_util.m: compiler/process_util.m: compiler/prog_io_goal.m: compiler/prog_io.m: compiler/prog_io_pragma.m: compiler/prog_io_typeclass.m: compiler/recompilation.check.m: compiler/recompilation.m: compiler/recompilation.usage.m: compiler/recompilation.version.m: compiler/unique_modes.m: Bring these modules up to date with our current style guidelines. Switch to predmode syntax and state variable notation where appropriate. Switch argument orders where this makes it possible to use state variable notation. Use the svmap and svset modules where appropriate. Fix inconsistent indentation; in some places, fix inconsistent placement of comments. compiler/passes_aux.m: compiler/modecheck_unify.m: compiler/mercury_compile.m: compiler/post_typecheck.m: compiler/prog_io_dcg.m: compiler/mode_ordering.m: compiler/inst_graph.m: compiler/polymorphism.m: compiler/prog_io_util.m: compiler/mode_debug.m: compiler/mode_robdd.check.m: compiler/transform.m: Minor changes to conform to the changed argument orders of some predicates in the cleaned up modules. Also, some minor cleanups. |
||
|
|
926fcebfcf |
Fix a comment. /s/diffferent/different/.
compiler/mode_errors.m: Fix a comment. /s/diffferent/different/. |
||
|
|
bf2e37d199 |
Implemented the solver types design.
Estimated hours taken: 100s Branches: main Implemented the solver types design. Solver types provide the means for adding constrained types to Mercury programs. A variable of a constrained type may have constraints placed on it, limiting the values it may be bound to, *before* the variable is actually bound to a particular value (cf. CLP(Z), CLP(R), CLP(FD) etc.) Improve the scheduling of solver type goals by preferring deconstructions over constructions followed by unifications. This is arranged by allowing solver type initialisation calls to be inserted only when all else fails. (XXX This implementation is O(n^2). I will fix things if this becomes an issue in practice.) I have also made some small, opportunistic cosmetic changes. This implementation has evolved through several design changes, during which some functionality was added then later removed - I elected to preserve any cleaned-up replacement code if removing the no-longer-needed-by-the- solver-types-design functionality was easy to do. doc/reference_manual.texi: Document solver types. compiler/hlds_data.m: Changed the du_type and foreign_type constructors appropriately and added a new solver_type constructor. compiler/hlds_out.m: Improved the code to write out the `where ...' part of a type definition and moved it to mercury_output.m. compiler/inst_match.m: Added the pred inst_is_any/1. compiler/inst_util.m: Added the pred inst_contains_unconstrained_var/1. compiler/make_hlds.m: Added processing for solver types, in particular adding the compiler generated declarations and implementations of the conversion functions. compiler/mercury_to_mercury.m: Added predicate mercury_output_where_attributes. compiler/mode_info.m: Added a new field to mode_info to indicate whether solver type initialisation calls can be inserted by modecheck_conj_list_2. compiler/mode_errors.m: compiler/modecheck_call.m: compiler/modecheck_unify.m: compiler/modes.m: The compiler now inserts calls to initialisation preds, where necessary, before calls and at the end of procedures. It does not yet do this at the end of disjuncts and its scheduling policy is naive (i.e. it performs terribly.) Added modecheck_conj_list_3 which allows modecheck_conj_list_2 to insert initialisation calls for a single goal, then repeats if this succeeded in scheduling some delayed goals. compiler/modules.m: XXX Reviewers: please look at the `rafe: XXX' comments and advise! compiler/prog_data.m: Added the solver_type constructor and the special_type_details and solver_type_details types. compiler/prog_io.m: compiler/prog_io_pragma.m: Parse the new syntax. Replaced get_maybe_equality_compare_preds with parse_type_decl_where_part_if_present. compiler/prog_mode.m: Added funcs in_mode/1, out_mode/1, in_any_mode/0, out_any_mode/0, and any_inst/0. compiler/special_pred.m: Added `initialise' constructor to special_pred_id. Changed special_pred_name to include the type name and arity with `__Unify__', `__Inex__' etc. compiler/type_util.m: Added some more utility funcs/preds. compiler/unify_proc.m: Generate the forwarding predicates for initialisation preds. compiler/equiv_type.m: compiler/equiv_type_hlds.m: compiler/foreign.m: compiler/hlds_module.m: compiler/intermod.m: compiler/magic_util.m: compiler/ml_code_gen.m: compiler/ml_type_gen.m: compiler/ml_unify_gen.m: compiler/mlds.m: compiler/module_qual.m: compiler/post_typecheck.m: compiler/pragma_c_gen.m: compiler/prog_util.m: compiler/purity.m: compiler/recompilation.check.m: compiler/recompilation.usage.m: compiler/recompilation.version.m: compiler/rl_key.m: compiler/table_gen.m: compiler/term_norm.m: compiler/termination.m: compiler/type_ctor_info.m: compiler/typecheck.m: Propagate the changes to hlds_goal_expr. |
||
|
|
885fd4a387 |
Remove almost all dependencies by the modules of parse_tree.m on the modules
Estimated hours taken: 12 Branches: main Remove almost all dependencies by the modules of parse_tree.m on the modules of hlds.m. The only such dependencies remaining now are on type_util.m. compiler/hlds_data.m: compiler/prog_data.m: Move the cons_id type from hlds_data to prog_data, since several parts of the parse tree data structure depend on it (particularly insts). Remove the need to import HLDS modules in prog_data.m by making the cons_ids that refer to procedure ids refer to them via a new type that contains shrouded pred_ids and proc_ids. Since pred_ids and proc_ids are abstract types in hlds_data, add predicates to hlds_data to shroud and unshroud them. Also move some other types, e.g. mode_id and class_id, from hlds_data to prog_data. compiler/hlds_data.m: compiler/prog_util.m: Move predicates for manipulating cons_ids from hlds_data to prog_util. compiler/inst.m: compiler/prog_data.m: Move the contents of inst.m to prog_data.m, since that is where it belongs, and since doing so eliminates a circular dependency. The separation doesn't serve any purpose any more, since we don't need to import hlds_data.m anymore to get access to the cons_id type. compiler/mode_util.m: compiler/prog_mode.m: compiler/parse_tree.m: Move the predicates in mode_util that don't depend on the HLDS to a new module prog_mode, which is part of parse_tree.m. compiler/notes/compiler_design.m: Mention prog_mode.m, and delete the mention of inst.m. compiler/mercury_to_mercury.m: compiler/hlds_out.m: Move the predicates that depend on HLDS out of mercury_to_mercury.m to hlds_out.m. Export from mercury_to_mercury.m the predicates needed by the moved predicates. compiler/hlds_out.m: compiler/prog_out.m: Move predicates for printing parts of the parse tree out of hlds_out.m to prog_out.m, since mercury_to_mercury.m needs to use them. compiler/purity.m: compiler/prog_out.m: Move predicates for printing purities from purity.m, which is part of check_hlds.m, to prog_out.m, since mercury_to_mercury.m needs to use them. compiler/passes_aux.m: compiler/prog_out.m: Move some utility predicates (e.g. for printing progress messages) from passes_aux.m to prog_out.m, since some predicates in submodules of parse_tree.m need to use them. compiler/foreign.m: compiler/prog_data.m: Move some types from foreign.m to prog_data.m to allow the elimination of some dependencies on foreign.m from submodules of parse_tree.m. compiler/*.m: Conform to the changes above, mostly by updating lists of imported modules and module qualifications. In some cases, also do some local cleanups such as converting predicate declarations to predmode syntax and fixing white space. |
||
|
|
ff60134ee9 |
Bring these modules up to our current coding standards.
Estimated hours taken: 8 Branches: main analysis/analysis.m: browser/browse.m: compiler/accumulator.m: compiler/assertion.m: compiler/atsort.m: compiler/c_util.m: compiler/check_typeclass.m: compiler/clause_to_proc.m: compiler/code_gen.m: compiler/code_model.m: compiler/const_prop.m: compiler/constraint.m: compiler/dead_proc_elim.m: compiler/delay_construct.m: compiler/dependency_graph.m: compiler/det_analysis.m: compiler/det_report.m: compiler/export.m: compiler/fact_table.m: compiler/follow_code.m: compiler/graph_colour.m: compiler/hlds_module.m: compiler/inlining.m: compiler/llds.m: compiler/make_hlds.m: compiler/mercury_to_mercury.m: compiler/ml_tailcall.m: compiler/ml_unify_gen.m: compiler/mmc_analysis.m: compiler/mode_errors.m: compiler/passes_aux.m: compiler/post_typecheck.m: compiler/size_prof.m: compiler/switch_util.m: compiler/table_gen.m: compiler/term_errors.m: compiler/transform_llds.m: compiler/type_util.m: compiler/unify_gen.m: compiler/unneeded_code.m: compiler/unused_args.m: Bring these modules up to our current coding standards. Use predmode declarations and state variable syntax where relevant. Reorder arguments where this is needed for the use state variables. Make the orders of predicate definitions correspond to the order of their declarations. Replace some overly large lambda expressions with named predicates. Convert some predicates to functions where this makes their use more convenient. Use field access notation where convenient. Fix any inconsistent indentation. Remove module prefixes on predicate names where this is necessary to allow sane indentation. In several places, use predicates from error_util.m to print error messages. Apart from this, there are no changes in algorithms. In some places, conform to the changes below. compiler/error_util.m: compiler/hlds_error_util.m: Add new variants of existing predicates for use in some of the changed modules above. compiler/hlds_out.m: Add some functions to convert values of some HLDS types as strings, for use in preparing the arguments of the new calls to predicates in error_util.m. Change the implementations of the predicates that print values of those types to call those functions instead of allowing code duplication. compiler/llds.m: Add some field names to allow use of field updates where relevant. tests/invalid/assert_in_interface.err_exp: tests/invalid/multisoln_func.err_exp: tests/invalid/tricky_assert1.err_exp: Update the expected outputs of these test cases to allow for them being generated by error_util.m, and hence being better formatted than before. |
||
|
|
9c9c610f5a |
This diff changes modes.m, unique_modes.m and mode_info.m to make them easier
Estimated hours taken: 6 Branches: main This diff changes modes.m, unique_modes.m and mode_info.m to make them easier to read and to maintain, but contains no changes in algorithms whatsoever. compiler/modes.m: compiler/unique_modes.m: compiler/mode_info.m: Convert these modules to our current coding standards. Use state variable notation when appropriate, reordering arguments as necessary. Delete predicates whose only purpose was to ease programming with DCGs. Remove the IO state from the mode_info structure, and pass it separately to the (relatively few) predicates that need it. This avoids using complicated (and as yet unsupported) modes or lying to the compiler (we used to do the latter), and we are no longer forced into that choice by being limited to a single hidden (DCG) variable. Use more expressive variable names and factor out code as appropriate. compiler/*.m: Conform to the changes in the above two modules. |
||
|
|
8693e293a2 |
This diff makes hlds_pred.m and many callers of its predicates easier to read
Estimated hours taken: 4 Branches: main This diff makes hlds_pred.m and many callers of its predicates easier to read and to maintain, but contains no changes in algorithms whatsoever. compiler/hlds_pred.m: Bring this module into line with our current coding standards. Use predmode declarations, functions, and state variable syntax when appropriate. Reorder arguments of predicates where necessary for the use of state variable syntax, and where this improves readability. Replace old-style lambdas with new-style lambdas or with partially applied named procedures. Standardize indentation. compiler/*.m: Conform to the changes in hlds_pred.m. This mostly means using the new argument orders of predicates exported by hlds_pred.m. Where this is now conveniently possible, change predicates to use state variable notation. In some modules, using state variable notation required changing the orders of arguments in the module's top predicate. compiler/passes_aux.m: Change the order of arguments in the calls this module makes to allow the callees to use state variable notation. Convert this module to state variable notation too. |
||
|
|
6554ef7daa |
Replace "is" with "=".
Estimated hours taken: 2 Branches: main Replace "is" with "=". Add field names where relevant. Replace integers with counters where relevant. |
||
|
|
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. |
||
|
|
c11e1ab157 |
Improve the display of insts in mode error messages.
Estimated hours taken: 4
Branches: main
Improve the display of insts in mode error messages.
In particular, fully expand all compiler-defined insts;
places where recursive insts refer to themselves are printed as "...".
compiler/mode_errors.m:
Change the argument of output_inst from instvar_set to mode_info,
so that it can have access to the module_info's inst_table.
Call mercury_output_expanded_inst instead of mercury_output_inst.
compiler/mercury_to_mercury.m:
Add new procedures mercury_output_expanded_inst, for use by
mode_errors.m, and mercury_expanded_inst_to_string, for consistency
with the rest of the interface.
These procedures take an extra module_info argument.
They output the inst in a format where all compiler-defined insts
have been expanded out; recursive insts have their self-referential
parts printed out as elipses ("...").
compiler/mode_util.m:
Change strip_builtin_qualifiers_from_inst so that it handles
compiler-defined insts properly, rather than just deleting
typed_ground and typed_inst insts and ignoring the rest.
tests/invalid/merge_ground_any.err_exp:
tests/invalid/polymorphic_unification.err_exp:
Update error messages to reflect the new output.
|
||
|
|
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. |