12 Commits

Author SHA1 Message Date
Zoltan Somogyi
8ab02a3134 Stop littering /tmp with temp files. 2023-10-06 05:30:37 +11:00
Zoltan Somogyi
b2ab9f8711 Wrap the test term in angle brackets.
tests/hard_coded/write_binary.{m,exp}:
    Wrap the test term in angle brackets, in order to make the presence
    of spaces, tabs and newlines apparent.
2023-04-27 21:27:21 +10:00
Zoltan Somogyi
810d95a7ea Update the hard_coded/write_binary test case.
tests/hard_coded/write_binary.m:
    Print the term whose write-out-and-read-back is being tested
    before the test, not after. Print the result of the test after this.

    If the test succeeds, don't print the term out again.

    Put blank lines between different kinds of tests, and between
    tests of different terms.

    Return error messages as strings, rather than as exceptions,
    where possible.

    Make the diagnostic for "read back term differs from original"
    more useful for debugging write_binary/read_binary.

    Put the declaration of a predicate just before the predicate.

tests/hard_coded/write_binary.exp:
    Expect the updated output.
2023-04-27 21:19:51 +10:00
Zoltan Somogyi
25b4b67403 Carve io.file.m out of io.m.
library/io.file.m:
library/io.m:
    Move two sections of io.m, the "file handling predicates" section
    and the "handling temporary files" section to the new submodule io.file.m.

    Leave behind in io.m "forwarding predicates", predicates that do nothing
    except call the moved predicates in io.file.m, to provide backward
    compatibility. But do mark the forwarding predicates as obsolete,
    to tell people to update their (at their leisure, since the obsoleteness
    warning can be turned off).

    Also leave behind in io.m the definitions of the two types used
    by some parameters of some of the moved predicates. Document the reason
    why this is done.

library/MODULES_DOC:
    List the new module among the documented modules.

NEWS:
    Announce the changes.

browser/browse.m:
browser/interactive_query.m:
browser/listing.m:
compiler/analysis.file.m:
compiler/compile_target_code.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_util.m:
compiler/handle_options.m:
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
compiler/parse_module.m:
compiler/passes_aux.m:
compiler/prog_event.m:
compiler/recompilation.check.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
deep_profiler/conf.m:
deep_profiler/mdprof_cgi.m:
library/dir.m:
mdbcomp/program_representation.m:
ssdb/ssdb.m:
    Call the file operation predicates directly in io.file.m, not indirectly
    through io.m.

    In two modules, add a #include of fcntl.h in C code. These modules contain
    C code that needs this #include, but until now, they got it via a copy
    in an automatically generated C header file of a foreign_decl pragma
    in io.m that contained that #include. This diff moves that foreign_decl
    to io.file.m, removing that crutch.

tests/debugger/browser_test.m:
tests/hard_coded/bit_buffer_test.m:
tests/hard_coded/bitmap_test.m:
tests/hard_coded/construct_bug.m:
tests/hard_coded/dir_fold.m:
tests/hard_coded/dir_test.m:
tests/hard_coded/read_binary_int16.m:
tests/hard_coded/read_binary_int32.m:
tests/hard_coded/read_binary_int64.m:
tests/hard_coded/read_binary_uint16.m:
tests/hard_coded/read_binary_uint32.m:
tests/hard_coded/read_binary_uint64.m:
tests/hard_coded/read_bitmap_size.m:
tests/hard_coded/remove_file.m:
tests/hard_coded/write_binary.m:
tests/hard_coded/write_binary_int8.m:
tests/hard_coded/write_binary_multibyte_int.m:
tests/hard_coded/write_binary_uint8.m:
    Call the file operation predicates directly in io.file.m, not indirectly
    through io.m.
2022-03-08 06:01:21 +11:00
Julien Fischer
61b0860e2c Extend hard_coded/write_binary to cover fixed size integers.
tests/hard_coded/write_binary,{m,exp}:
     As above.
2017-09-15 10:13:52 -04:00
Zoltan Somogyi
253378fe21 Improve error messages for malformed lambda expressions.
Do this by insisting that terms whose top level(s) look like lambda
expressions should be parsed as lambda expressions, and return error
messages if that parsing attempt fails.

I did this is in several commits to modules in the parse_tree.m package
that translated terms to the parse tree, i.e. to goal_exprs. This diff
does the same thing for lambda expressions.

NEWS:
    Document this change, as well as other, similar changes in the recent past.

compiler/superhomogeneous.m:
    When translating a var-functor unification, which has the form
    X = f(Y1, ..., Yn), to the HLDS, we parse the right hand side term,
    looking for Mercury constructs such as lambda expressions and
    field accesses. We used to do this by checking if the RHS was
    a well-formed version of the construct we were looking for,
    and falling back to parsing it as an ordinary term. That meant that
    terms that the programmer *intended* to be lambda expressions,
    but which contained a syntax error, were not diagnosed during the
    construction of the HLDS, but during a later pass. Virtually always,
    that later pass was typechecking. Since in such cases, the typechecker
    is given terms whose function symbols were *intended* to be the "keywords"
    of Mercury constructs (to the extent that Mercury *has* keywords),
    not the names of data constructors or predicates, those error messages
    were almost always confusing, and at best an *indirect* indication
    of the actual problem with the code.

    This diff changes things so that when the top function symbol on
    the RHS of a unification is a Mercury "keyword" used only in lambda
    expressions, we commit to parsing it as such. If the parsing fails,
    we now generate an error message that describes the problem *directly*.

    To make the task of generating good error messages easier, and to make it
    possible to generate *consistent* error messages for the same error
    in different contexts, unify the four separate pieces of code that
    *used* to parse different kinds of lambda expressions. These four
    pieces of code used to parse

    - predicates defined using DCG notation;
    - predicates defined using non-DCG notation;
    - functions that used the default function mode and determinism; and
    - functions that did not use the default function mode and determinism.

    The unified code allows a function lambda expression to omit the
    default argument modes *independently* of whether it omits the default
    determinism, and vice versa. The old code did not do that: if you didn't
    explicitly specify one, you couldn't explicitly specify the other either,
    probably because it would have required two more pieces of code.

    The language reference manual says, in section 8.1:

        As with ‘:- func’ declarations, if the modes and determinism
        of the function are omitted in a higher-order function term, then
        the modes default to ‘in’ for the arguments, ‘out’ for
        the function result, and the determinism defaults to ‘det’.

    This text is vague on whether the modes and determinism are *allowed*
    to be omitted independently. The old behavior was a strict reading
    of this text. The new behavior follows the most liberal possible reading,
    and thus allows all the behaviors that the old one did, and more.

    Integrate the test for big integers that are too big to be represented
    with the conversion of all ordinary functors into cons_ids, both to
    simplify the code, and to speed it up. In the process, improve the
    error message for too-big integers.

compiler/add_clause.m:
    Don't try to generate warnings for singleton variables in a clause
    if the clause had syntax errors. Part of the parser's recovery from
    those syntax errors (e.g. when they occur in lambda expressions' clause
    heads) may have included not translating parts of the original term
    into the parsed clause body, so any such warnings could be misleading.

    Such warnings could also be correct, but I expect most programmers
    would prefer to miss some correct singleton warnings while the
    syntax errors are present in their code, and get them only once
    they have fixed those syntax errors, than to have to wade through
    misleading errors messages for the initial syntax error to get to
    the real ones.

compiler/field_access.m:
    Clarify the text of an error message.

    Delete a predicate that superhomogeneous.m no longer needs.

compiler/mercury_compile_front_end.m:
    Don't proceed past typechecking if the parser found syntax errors,
    since any errors we find later, e.g. as part of mode checking,
    are quite likely to be avalanche errors caused by those syntax errors.

    The reason why this wasn't a problem in the past is that when
    the program contained malformed uses of builtin constructs such as
    lambda expressions and field accesses, the parser used to simply
    transform the terms containing the malformed constructs into the arguments
    of call goals and unifications, and it was the typechecker that discovered
    that these function symbols did not match any declared type.
    The "type errors" generated for such problems told the compiler
    not to run later compiler passes to prevent avalanche errors.

    We now report syntax errors earlier, during the construction of the HLDS,
    and it is entirely possible that the parser's recovery from those errors
    leaves *no* type errors to be reported. This is why we need to make
    the presence of syntax errors in a predicate block the invocation
    of later passes.

compiler/typecheck.m:
    Return whether the predicates we typechecked had syntax errors,
    to make the change in mercury_compile_front_end.m possible.

compiler/state_var.m:
    If a lambda expression has two or more arguments of the form !X,
    we now print an error message for each, with each message naming the bad
    state variable and giving the context of the argument. We used to
    print only a single message saying that *some* argument misused
    state variables this way. Similarly, we now print the correct context
    for !X appearing as a function result, whether in a lambda expression
    or at the top level of a clause.

    The actual printing of those error messages takes place elsewhere,
    but change the utility predicates exported by state_var.m to make
    the change possible.

    Change the error message we generate for !X appearing as a function
    result, to avoid suggesting a possible repair that is virtually never
    the right repair.

compiler/mode_util.m:
    Delete a predicate that was used only by superhomogeneous.m; an updated
    version of that predicate is now in superhomogeneous.m itself.

compiler/module_qual.m:
compiler/module_qual.qualify_items.m:
    Instead of exporting predicates to module qualify the whole list of
    argument modes of a lambda expression, export predicates that module
    qualify only one such mode, since that is what superhomogeneous.m
    now wants.

compiler/hlds_clauses.m:
    Add access predicates for fields of the clauses_info type that previously
    did not have them, including the one that records the presence of syntax
    errors.

    Put related fields of the clauses_info together.

    Group both the declarations and the definitions of the access predicates
    together, and put them in the same order as the fields themselves.

compiler/add_class.m:
compiler/add_pred.m:
compiler/add_pragma_type_spec.m:
compiler/higher_order.m:
compiler/hlds_pred.m:
compiler/unify_proc.m:
    Conform to the changes above.

tests/invalid/lambda_syntax_error.err_exp:
    Print one error message for each of the four malformed lambda expressions
    in this test case, instead of the 13 avalanche messages we used to get
    from the typechecker, which tried to interpret the malformed lambda
    expression heads as calls, unifications etc.

    The motivation for this diff was a set of similar set of avalanche error
    messages for a real-life syntax error in a lambda expression in a change
    I worked on a while ago.

tests/benchmarks/deriv.{m,exp}:
    This test case used to use "^" as a data constructor (to represent
    raising X to the Nth power). Since the parser now insists on treating it
    as a field access operator, replace "^" with "power". (This test has
    the excuse of predating the addition of field access syntax to Mercury
    by several years.)

tests/dppd/grammar_impl.m:
    This test case used to define a type which contained "is" as a data
    constructor. After this diff, this is no longer allowed (as part of
    "is detism", it looks to the parser like the top constructor in a
    lambda expression head, and therefore as the top constructor of
    the lambda expression as a whole if it has no body), so add the type
    name as a prefix to this data constructor. To future-proof the test case,
    do the same with the several other data constructors that also duplicate
    the names of Mercury keywords.

tests/hard_coded/pprint_test2.{m,exp}:
tests/hard_coded/write.{m,exp}:
tests/hard_coded/write_binary.{m,exp}:
    These test cases used to define a type which contained ":-" as a data
    constructor. After this diff, this is no longer allowed, so replace them
    with "?-". (The tests check how io.m formats terms whose data constructor
    is an operator, so the replacement needs to be an operator, and Mercury
    syntax does not use "?-"; library/ops.m lists it as an operator only
    because it is an operator in Prolog.)

    Update write_binary.m to conform to our current style guide, and to avoid
    using the recently-deprecated io.make_temp.

tests/invalid/invalid_int.err_exp:
    Expect the updated text of the error message for a too-big
    integer constant.

tests/invalid/record_syntax_error.err_exp:
    Expect the updated text of the error message for a malformed field name.

tests/invalid/state_vars_test3.err_exp:
    Expect the updated text of the error message for a !X appearing
    as the result of a lambda function.

tests/invalid/state_vars_test4.err_exp:
    Expect the error message for a !X lambda argument, but (since we now
    stop after typechecking in the presence of such syntax errors),
    don't expect the avalanche error messages we used to print from the
    mode checker.
2016-05-20 05:47:36 +10:00
Zoltan Somogyi
33eb3028f5 Clean up the tests in half the test directories.
tests/accumulator/*.m:
tests/analysis_*/*.m:
tests/benchmarks*/*.m:
tests/debugger*/*.{m,exp,inp}:
tests/declarative_debugger*/*.{m,exp,inp}:
tests/dppd*/*.m:
tests/exceptions*/*.m:
tests/general*/*.m:
tests/grade_subdirs*/*.m:
tests/hard_coded*/*.m:
    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 debugger tests,
    specify the new line numbers in .inp files and expect them in .exp files.
2015-02-14 20:14:03 +11:00
Julien Fischer
47fec100be Further library consistency improvements.
Branches: main

Further library consistency improvements.

library.term.m:
	Change the argument ordering of the predicate create_var/3.
	(This breaks backwards compatibility but that should be okay
	as most code uses the varset module rather than calling this
	directly.)

	Fix the layout in a spot.

library/string.m:
library/type_desc.m:
	Change predicates and functions that use a "_det" suffix in
	their name to use a "det_" prefix as in the rest of the library
	modules.  Deprecate the suffix versions.

library/varset.m:
	Delete a reference to the graph module.

NEWS:
	Announce the above changes.

library/construct.m:
library/varset.m:
library/term_to_xml.m:
compiler/passes_aux.m:
tests/hard_coded/construct_test.m:
tests/hard_coded/deep_copy.m:
tests/hard_coded/write.m:
tests/hard_coded/write_binary.m:
tests/hard_coded/write_reg1.m:
	Conform to the above changes.
2011-05-25 02:02:53 +00:00
Julien Fischer
0c895bad7b Remove deprecated syntax from some test cases.
Estimated hours taken: 0.1
Branches: main

Remove deprecated syntax from some test cases.
(This was done on the release branch some time ago.)

tests/*/*.m:
	Replace deprecated syntax.
2005-09-12 09:02:30 +00:00
Zoltan Somogyi
6d48037c30 Make this test clean up after itself by deleting the temporary files
Estimated hours taken: 0.5 (mostly to find where the temp files originated)
Branches: main

tests/hard_coded/write_binary.m:
	Make this test clean up after itself by deleting the temporary files
	it creates.

	Add with_type annotations to avoid a bunch of warnings about
	unresolved polymorphism.
2004-05-04 07:57:33 +00:00
Fergus Henderson
cc15f3f0dc Fix a bug in io__read_binary: it was leaving unread the trailing
Estimated hours taken: 0.5
Branches: main

library/io.m:
	Fix a bug in io__read_binary: it was leaving unread the trailing
	newline that io__write_binary writes.

tests/hard_coded/write_binary.m:
	Uncomment the part of the test case which tests for this bug.
2004-02-12 05:14:41 +00:00
Fergus Henderson
e9af7e7177 Add a test of io__write_binary/io__read_binary.
Branches: main
Estimated hours taken: 1

tests/hard_coded/Mmakefile:
tests/hard_coded/write_binary.m:
tests/hard_coded/write_binary.exp:
	Add a test of io__write_binary/io__read_binary.
2004-01-22 04:35:13 +00:00