mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 12:53:47 +00:00
083d376e6598628362ee91c2da170febd83590f4
7 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
850d461c40 |
Make `:- external' a pragma inside the compiler and out.
We used to have only the first of these three forms, we now have all three:
:- external(low_level_backend, a/2).
% declared pred a/2 and func a/2 to be external on llds
:- pragma external_pred(a/2, [low_level_backend]).
% declared pred a/2 (and NOT func a/2) to be external on llds
:- pragma external_func(a/2, [low_level_backend]).
% declared func a/2 (and NOT pred a/2) to be external on llds
The new forms allow for more precise control of what is declared to be
external. The difference in syntax (the options coming after the name,
and the options being in a list, even though this pragma allows only
one option at present) are to fit in with the style of the other pragmas.
Of course, the backend does not have to be specified, so these are
also allowed:
:- pragma external_pred(a/2).
:- pragma external_func(a/2, []).
Using `:- external' declarations is for implementors only, since using it
requires writing target language code by hand in a way that conforms to all
the compiler's conventions for e.g. symbol naming and parameter passing.
It is not a documented part of Mercury. Therefore the new external_{func,pred}
pragmas are not documented either.
compiler/prog_item.m:
Change the representation of the `:- external' declaration from being
a module_defn to being a pragma. Generalize it to allow the new pragmas,
by allowing the recording of an option pred_or_func indication.
Add a function that returns a description of a pragma for use as a context
in error messages. We need this to avoid confusing users by having an
error message refer to a `:- external' declaration when they wrote e.g.
`:- pragma external_pred', or vice versa.
compiler/add_pragma.m:
Move the code for handling external declarations from make_hlds_passes
(which handles module_defns) to this module (which handles pragmas),
and update it.
Execute this code in pass 2, not pass 1, since we need to record
the "external" flag in the pred_info, and that is created in pass 1.
(I think this worked in the past ONLY if the declaration of the affected
predicate or function came textually before the `:- external' declaration.)
compiler/make_hlds_passes.m:
Remove the code that is now in add_pragma.m (in adapted form).
compiler/prog_io_item.m:
Change the code for parsing old-style `:- external' declarations to
generate the new pragma internally.
compiler/prog_io_pragma.m:
Add code for parsing the new pragmas.
compiler/equiv_type.m:
compiler/item_util.m:
compiler/mercury_to_mercury.m:
compiler/module_imports.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.version.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
compiler/make_hlds_error.m:
Improve a variable name.
compiler/pred_table.m:
Improve the documentation of several predicates.
tests/hard_coded/backend_external.m:
Improve the documetation of this old test case, which tests the
handling of backend-specific `:- external' declarations.
tests/hard_coded/backend_external_{func,pred}.m:
Two copies of the old backend_external.m test case, which test the
handling of backend-specific `:- pragma external_func' and
`:- pragma external_pred' declarations respectively.
tests/hard_coded/backend_external_func.exp:
tests/hard_coded/backend_external_pred.{exp,exp2}:
The expected outputs of the new test cases.
tests/hard_coded/Mmakefile:
Enable the new test cases.
tests/invalid/type_spec.err_exp:
Expect an error message for a `:- external' declaration in the interface
of type_spec.m. Since declaring a procedure to be external is in essence
a representation of the implementation of that procedure, the previous
absence of an error message for this implementation detail in the interface
was a bug.
tests/invalid/external.err_exp:
We always generated an error for a `:- external' declaration that
did not specify an arity, but the text of the error message used to say
"warning", not "error" (even though the severity level was "error").
Expect the corrected error message.
tests/invalid/not_in_interface.err_exp:
Expect the updated, more precise form of an error message.
vim/syntax/mercury.vim:
Add the two new keywords.
|
||
|
|
fdd141bf77 |
Clean up the tests in the other test directories.
tests/invalid/*.{m,err_exp}:
tests/misc_tests/*.m:
tests/mmc_make/*.m:
tests/par_conj/*.m:
tests/purity/*.m:
tests/stm/*.m:
tests/string_format/*.m:
tests/structure_reuse/*.m:
tests/submodules/*.m:
tests/tabling/*.m:
tests/term/*.m:
tests/trailing/*.m:
tests/typeclasses/*.m:
tests/valid/*.m:
tests/warnings/*.{m,exp}:
Make these tests use four-space indentation, and ensure that
each module is imported on its own line. (I intend to use the latter
to figure out which subdirectories' tests can be executed in parallel.)
These changes usually move code to different lines. For the tests
that check compiler error messages, expect the new line numbers.
browser/cterm.m:
browser/tree234_cc.m:
Import only one module per line.
tests/hard_coded/boyer.m:
Fix something I missed.
|
||
|
|
90b2d233c0 |
Improve more error messages.
Make consistency improvements to error messages concerning initialise, finalise and mutable declarations. compiler/make_hlds_error.m: Pass a list of format_components to error_if_exported/5 and error_is_exported/4 as the item description instead of a string. compiler/add_pragma.m: compiler/make_hlds_passes.m: Conform to the above change. compiler/modes.m: Use the pragma_decl/1 format component in a couple of spots. tests/invalid/bad_finalise_decl.err_exp: tests/invalid/bad_initialise_decl.err_exp: tests/invalid/bad_mutable.err_exp: tests/invalid/imported_mode.err_exp: tests/invalid/not_in_interface.err_exp: tests/invalid/uniq_mutable.err_exp: Conform to the above changes. |
||
|
|
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. |
||
|
|
9ec3ae8d08 |
Fix the problems with mutable declarations and sub-modules by making
Estimated hours taken: 11 Branches: main Fix the problems with mutable declarations and sub-modules by making sure that the relevant information is written out in the private interface files. Fix a bug where mutable variables were not being initialised with their declared intial value. The problem was that the compiler was optimizing away the body of the automatically generated predicate that was setting the initial value. We now make such predicates impure to prevent this. In order to support the above, accept `:- intialise' declarations that specify impure predicates, provided that the declaration in question was generated by the compiler. It is still an error for the user to specify such declarations. Fix some other problems with mutable declarations. compiler/modules.m: Do not write `:- mutable' declarations out to private interface files, instead write out the predicate and mode declarations for the access predicates. Remove some old XXX comments about mutables that are no longer relevant. compiler/make_hlds_passes.m: Don't add the export pragmas for initialise declarations during pass 2. For some reason we were doing this during pass 2 and again during pass 3. Make the intialise predicates for mutable variables impure in order to prevent the compiler from optimizing them away Fix origin fields that were being set incorrectly during the mutable transformation. compiler/prog_mutable.m: New module. Shift some code from make_hlds_passes to here, since modules.m also needs access to it. compiler/parse_tree.m: Include the new module. compiler/notes/compiler_design.html: Mention the new module. tests/hard_coded/sub-modules/Mmakefile: tests/hard_coded/sub-modules/mutable_parent.m: tests/hard_coded/sub-modules/mutable_child.m: tests/hard_coded/sub-modules/mutable_grandchild.m: tests/hard_coded/sub-modules/mutable_parent.exp: Test case for mutables and sub-modules. tests/hard_coded/not_in_interface.m: tests/hard_coded/not_in_interface.err_exp: Test for ordering problems between mutable and initialise declarations when emitting errors about items that should not occur in module interfaces. This can happen if the item's origin field is incorrectly set. |
||
|
|
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. |
||
|
|
68d2c2e1e1 |
Improve error reporting for initialise declarations.
Estimated hours taken: 2 Branches: main Improve error reporting for initialise declarations. Make clauses in module interfaces an error rather than a warning. Do the same for pragmas that should not occur in a module interface. compiler/make_hlds_error.m: Add two new predicates that handle error reporting for items that should not occur in module interfaces. compiler/make_hlds_warn.m: Remove the predicate for warning about items that should not occur in module interfaces. It is now unused. compiler/make_hlds_passes.m: Do not emit an error for export declarations that have ended up in the interface of a module as a result of the source-to-source transformation used to implement initialise declarations. Report initialise declarations that refer to predicates that do not exist directly rather than reporting that the introduced export pragmas are incorrect. The latter is confusing since the pragmas do not appear in the source code Delete the XXX comment about the above. Also fix the description of the transformation used to implement initialise declarations. Make clauses in a module interface an error rather than a warning. When reporting this also print out the name and arity of the predicate or function to which the clauses belong. Make it an error for pragmas that are not allowed in a module interface to occur in a module interface. compiler/prog_data.m: Add a type that allows us to distinguish between items that originated with user code and those introduced by source-to-source transformations on the parse tree. compiler/recompilation.version.m: compiler/recompilation.check.m: compiler/prog_io_pragam.m: compiler/prog_io.m: compiler/module_qual.m: compiler/modules.m: compiler/add_pragma.m: compiler/add_solver.m: compiler/equiv_type.m: compiler/intermod.m: Conform to the above changes. tests/invalid/Mmakefile: tests/invalid/not_in_interface.m: tests/invalid/not_in_interface.err_exp.m: Test cases for the above errors. tests/invalid/bad_initialise_decl.m: tests/invalid/bad_initialise_decl.err_exp: Update this test case. |