Commit Graph

19 Commits

Author SHA1 Message Date
Zoltan Somogyi
3dc4babb24 Update the style of more test cases.
And update expected output files for changes in line numbers.
2021-07-27 13:29:46 +10:00
Zoltan Somogyi
56243daa79 Avoid co-traversals when creating unify/compare preds.
compiler/unify_proc.m:
    When creating goals of the form

        X = f(ArgX1, ArgX2),
        Y = f(ArgY1, ArgY2),
        ...

    don't traverse (a) the types of the arguments of f, (b) the ArgXi, and
    (c) the ArgYi separately, living with the possibility that the lists
    containing them have different lengths. Instead, create a list of triples,
    and traverse that.

    Give names such as ArgX1 to these variables. (They used to be unnamed.)

    Reorder things to ensure that the order of predicate/function declarations
    is matched by the order of their definitions.

tests/invalid/partial_implied_mode.err_exp:
    Expect ArgX2 to be a named variable in an error message.
2017-06-22 01:37:42 +02:00
Zoltan Somogyi
f4ad6de055 Generate more readable mode errors.
compiler/mode_errors.m:
    When printing insts in error messages, use predicates specifically
    designed for that purpose.

    The insts output by these predicates improve on the existing output
    in the following ways.

    - We now show the structure of complex insts through indentation.

    - We now show both the name of named insts, and their expansion.
      Sometimes, you need the expanded inst to understand the error message,
      in the case of recursive insts, you cannot expand them forever.
      Since the expansion *has* to refer to the inst name, showing that name
      at the *start* of the expansion is necessary to allow readers to
      understand the inst.

    - We now eliminate the module qualification from the names of function
      symbols. The module qualifiers on function symbols are specified
      by the type, not the inst, of the relevant term, and if we get to
      the point of mode analysis having been run, then the predicate
      we are generating errors for must be *type* correct, though obviously
      it is not *mode* correct.

    - We now eliminate the module qualification from names of named insts
      if the module qualifier is the name of the module being compiled.
      This is a common case, and in these cases, the module qualifier
      in the error message acts as clutter, making it *harder* to read.

    - We now avoid printing parentheses that humans never need, but which
      the parser sometimes does, and which the existing inst output predicates
      therefore had to print.

    - Higher order insts contain the modes of the function or predicate.
      We now print the builtin modes as e.g. "in" instead of the old
      "free >> ground".

compiler/error_util.m:
    Add some utility predicates now needed by mode_errors.m.

tests/invalid/any_passed_as_ground.err_exp2:
tests/invalid/anys_in_negated_contexts.err_exp:
tests/invalid/bind_in_negated.err_exp:
tests/invalid/bug117.err_exp:
tests/invalid/bug191.err_exp:
tests/invalid/constrained_poly_insts.err_exp:
tests/invalid/constrained_poly_insts2.err_exp:
tests/invalid/ho_any_inst.err_exp:
tests/invalid/ho_default_func_1.err_exp:
tests/invalid/ho_default_func_2.sub.err_exp:
tests/invalid/ho_default_func_3.err_exp:
tests/invalid/ho_default_func_4.err_exp:
tests/invalid/ho_type_mode_bug.err_exp:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/merge_inst_error.err_exp:
tests/invalid/multimode_dcg.err_exp:
tests/invalid/occurs.err_exp:
tests/invalid/partial_implied_mode.err_exp:
tests/invalid/polymorphic_unification.err_exp:
tests/invalid/qualified_cons_id2.err_exp:
tests/invalid/state_vars_test4.err_exp:
tests/invalid/try_detism.err_exp2:
tests/warnings/unify_f_g.exp:
    Update expected outputs.
2015-11-29 04:33:41 +11:00
Zoltan Somogyi
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.
2015-02-16 12:32:18 +11:00
Julien Fischer
a1c5bff008 Fix a problem with conjunction re-ordering that was introduced by my
Estimated hours taken: 2
Branches: main

Fix a problem with conjunction re-ordering that was introduced by my
recent change to remove automatic solver type initialisation.
This was causing the stage 2 deep profiler to break.

compiler/modes.m:
	Despite its name, modecheck_delayed_solver_goals, in fact
	attempts to reschedule all goals, not just solver goals.
	Call this predicate as we did before my previous change and
	shift the code disables automatic initialisation to a place
	where the rescheduling of non-solver goals will not be affected.

tests/valid/Mmakefile:
tests/valid/trace_goal_reorder.m:
	A test case for the above bug.

tests/invalid/partial_implied_mode.err_exp:
	Revert the last change to this file.  The change to the
	expected error was caused by the above bug.
2007-11-01 01:07:26 +00:00
Julien Fischer
f5667464c7 Remove support for automatic initialisation of solver types from the language.
Estimated hours taken: 10
Branches: main

Remove support for automatic initialisation of solver types from the language.
This is being done because:

* the current implementation of automatic initialisation means we cannot
  support polymorphic solver types, e.g. you cannot have the type foo(bar)
  where:
  		:- solver type foo(T).
		:- solver type bar.

* the current initialisation strategy is fairly ad-hoc anyway; in particular
  it has a tendency to unnecessarily change the determinism of procedures.

* mode error messages are often quite poor because of the interaction between
  automatic initialisation and impure code.

* automatic initialisation is not used in practice.  All of the
  G12 solver libraries that use solver types recommend explicitly
  initialising solver variables.

This change removes support for automatic solver initialisation from the
language.  The code for supporting it remains in the implementation, but
it is now dependent upon the developer-only `--solver-type-auto-init'
option.

As a transitional measure the compiler will still accept
`initialisation is ...' attributes in solver type definitions even when
`--no-solver-type-auto-init' is enabled.  After this change has bootstrapped,
and the relevant updates have been made to the G12 solver libraries, this
will be changed so that `initialisation is ...' attributes are considered
a syntax error unless `--solver-type-auto-init' is enabled.

doc/reference_manual.texi:
	Document that solver type definitions no longer allow initialisation
	predicates to be supplied.  (The section documenting initialisation
	predicates has been commented out rather than deleted since the
	implementation of automatic initialisation still exists.)

	Remove the section documenting the restrictions on polymorphic
	solver types.  These restrictions no longer apply in the absence
	of automatic initialisation.

compiler/options.m:
	Add a new developer-only option, `--solver-type-auto-init', that
	controls whether automatic initialisation of solver variables is
	allowed (for those solver types that have initialisation predicates
	specified.)

compiler/prog_data.m:
	Add a type that represents whether a solver type allows automatic
	initialisation or not.

	Extend the solver_type_details structure to allow initialisation
	predicates to be optional.

compiler/prog_io.m:
	Allow initialisation predicates to be optional in solver type
	definitions.

compiler/modes.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
	Only insert calls to solver type initialisation predicates if
	the solver type has an initialisation predicate and the
	developer-only option `--solver-type-auto-init' is enabled.

compiler/unify_proc.m:
	Handle the situation where a solver type does not have an
	initialise predicate.

compiler/add_special_pred.m:
	Only add initialisation special predicates for those solver
	types whose definition provides an initialisation predicate.

compiler/mode_info.m:
	Add a utility predicate that tests whether the support for
	automatic solver type initialisation is enabled.

compiler/type_util.m:
	Add a predicate that tests whether a type is a solver type
	that supports automatic initialisation.

	Add an XXX comment about such types and abstract equivalence
	types.

compiler/mercury_to_mercury.m:
	Conform to the above changes.

compiler/special_pred.m:
	Fix some typos.

samples/solver_types/eqneq.m:
	Delete the `initialisation is ...' from the definition of the solver
	type eqneq/1.

tests/hard_coded/Mercury.options:
	Enable `--solver-type-auto-init' for the solver_construction_init_test
	test.

tests/hard_coded/solver_build_call.m:
tests/invalid/any_pass_as_ground.m:
	Don't use automatic solver variable initialisation in these
	test cases.

tests/invalid/partial_implied_mode.err_exp:
	Conform to the above changes in the mode analyser.

tests/valid/Mercury.options:
	Compile some tests cases with `--solver-type-auto-init' enabled.
2007-10-31 03:58:33 +00:00
Peter Ross
e8e1690475 The following code causes code to be generated which seg-faults
Estimated hours taken: 2
Branches: main

The following code causes code to be generated which seg-faults

 :- interface
 :- instance tc(list(T)).
 :- implementation.
 :- instance tc(list(T)) <= tc(T) where [...].

because the exported instance declaration doesn't contain the
typeclass constraint.

mercury/compiler/add_class.m:
       Check that for all the "same" instance declarations
       the instance constraints are exactly the same on each
       declaration.

tests/invalid/incompatible_instance_constraints*:
	Add tests for this code.

tests/invalid/*:
	Fix some headvar name errors.

tests/valid/*:
	Fix some invalid abstract instance declarations.
2007-05-21 04:23:26 +00:00
Zoltan Somogyi
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.
2006-09-07 05:51:48 +00:00
Julien Fischer
835d8315ef Do not allow discriminated unions with a single zero-arity constructor to have
Estimated hours taken: 10
Branches: main, release

Do not allow discriminated unions with a single zero-arity constructor to have
user-defined equality or comparison.  Defining such types causes an assertion
failure in the compiler because the types are considered to be dummy types and
the runtime currently doesn't support (and probably won't ever) d.u. dummy
types with user-defined equality or comparison.

Fix another bug where the compiler was not printing out the `recompile with
-E' prompt at the appropriate time.  The bug was caused by the fact that there
were several copies of the globals structure and the one that was being
checked at the time the prompt was being printed out was not the one that had
been updated during the rest of compilation.

compiler/add_types.m:
	Emit an error message if an attempt is made to define a d.u.  dummy
	type with user-defined equality or comparison.

compiler/globals.m:
	Remove the extra_error_info field from the globals structure and turn
	it into a mutable.  Export access predicates for this mutable.  The
	reason for doing this is that the compiler was sometimes looking at
	the wrong copy of the globals structure when checking the value of
	this flag - this meant that sometimes the recompile with `-E' prompt
	was not being displayed.  Turning this flag into a mutable avoids the
	problem because now there is only one copy.

compiler/make_hlds.m:
	s/__/./  in a few spots.

doc/reference_manual.texi:
	Mention the new restrictions on discriminated union types with
	user-defined equality or comparison.

tests/invalid/exported_unify2.m:
tests/invalid/exported_unify3.m:
	Change some types with user-defined equality or comparison so that
	they are no longer dummy types.  These test cases have not been
	triggering the assertion failure in the compiler because they are only
	error checked and the assertion that is failing occurs further along
	in the compilation process.

tests/invalid/user_eq_dummy.{m,err_exp}:
	Test the new error message for dummy types with user-defined equality
	or comparison.

tests/invalid/extra_info_prompt.{m,err_exp}:
	Test that the recompile with `-E' prompt is being displayed when it
	should.

tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
	Include the new test cases.

	Where there is a verbose version of the error message compile with
	`-E'.

tests/recompilation/add_type_re.err_exp.2:
tests/invalid/*.err_exp:
	Update expected outputs to conform to the above.
2006-06-14 08:15:01 +00:00
Julien Fischer
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.
2005-09-14 05:27:11 +00:00
Zoltan Somogyi
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.
2005-08-22 03:55:23 +00:00
Zoltan Somogyi
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.
2005-04-25 08:47:39 +00:00
Julien Fischer
fee08da074 Update the expected output for this test case as
tests/invalid/partial_implied_mode.err_exp:
	Update the expected output for this test case as
	it has changed since solver types were added.
	(Ralph posted a fix for this but didn't commit it).
2004-09-20 13:42:26 +00:00
Julien Fischer
d761d245a5 Update the expected output for these test cases since
Estimated hours taken: 0.5
Branches: main

invalid/*.err_exp:
	Update the expected output for these test cases since
	the compiler now generates error messages that doesn't
	use the deprecated syntax for mode declarations.
2004-08-23 09:53:13 +00:00
Ralph Becket
a8ffd3680c Change the compiler and tools so that .' and not :' is now used as the
Estimated hours taken: 14
Branches: main

Change the compiler and tools so that `.' and not `:' is now used as the
module separator in all output.

Infix `.' now has associativity yfx and priority 10.

NEWS:
	Report the change.

configure.in:
	Amend the test for an up-to-date Mercury compiler to check whether
	it recognises `.' as a module qualifier.

compiler/code_gen.m:
compiler/error_util.m:
compiler/hlds_out.m:
compiler/prog_out.m:
compiler/prog_util.m:
compiler/rl_exprn.m:
compiler/rl_gen.m:
compiler/source_file_map.m:
compiler/unused_args.m:
library/io.m:
library/rtti_implementation.m:
library/type_desc.m:
runtime/mercury_debug.c:
runtime/mercury_deconstruct.c:
runtime/mercury_stack_trace.c:
	Change `:' to `.' as module separator for output.

compiler/mercury_to_mercury.m:
compiler/prog_io_typeclass.m:
	As above.
	Fixed a bug where `.' was not being recognised as a module separator.

doc/reference_manual.texi:
	Report the change.

library/term_io.m:
	Ensure that infix `.' is written without surrounding spaces.

tests/hard_coded/dot_separator.m:
tests/hard_coded/dot_separator.exp:
tests/hard_coded/Mmakefile:
	Test case added.
2003-01-17 05:57:20 +00:00
Zoltan Somogyi
e4e46f1b31 Update now that the head variables of compiler-generated procedures
Estimated hours taken: 0.1

tests/invalid/partial_implied_mode.err_exp:
	Update now that the head variables of compiler-generated procedures
	have real names.
1999-09-30 01:52:22 +00:00
Simon Taylor
47c8617b8e Added `set_goal_contexts', which sets all the contexts
Estimated hours taken: 1

compiler/hlds_goal.m:
	Added `set_goal_contexts', which sets all the contexts
	of the goal_infos of the sub-goals of a goal.

compiler/unify_proc.m:
	Use `set_goal_contexts' to ensure that error messages
	for automatically generated procedures have a useful context.

tests/invalid/partial_implied_mode.err_exp:
	Update the expected output.
1999-06-16 00:39:24 +00:00
Simon Taylor
1d05aece38 Update the line numbers which changed after Zoltan's
Estimated hours taken: 0.1

tests/invalid/partial_implied_mode.err_exp:
	Update the line numbers which changed after Zoltan's
	change to stop putting #line directives in .int files.
1999-05-19 04:19:25 +00:00
Simon Taylor
5f7880aca3 Fix a code generator abort reported by Stephane Marie
Estimated hours taken: 10

Fix a code generator abort reported by Stephane Marie
<stephane.marie@detexis.thomson-csf.com>.

The bug was in the code to work out the instmap after a deconstruction
unification with complicated sub-unifications.
The instmap_delta for the unification contained only the bindings for
the first argument for which a new variable was created.

The test case now gives an error during mode analysis
rather than a code generator abort (for unification procedures
of imported types) or a mode error during unique mode analysis
(for local types).

compiler/modes.m:
compiler/modecheck_call.m:
compiler/modecheck_unify.m:
	Simplify the code to handle extra goals by not attempting
	to bodge together the instmap after the main goal.
	Instead, the code now creates the extra unifications and
	rechecks the goal with the unifications added.

compiler/mode_info.m:
	Add a field to say whether we are reprocessing a goal after
	adding extra goals. Abort if the reprocessing adds more extra goals.

	The `may_changed_called_proc' field is now separate from
	the `how_to_check_goal' field. This is used to avoid
	repeating the search for the best procedure when rerunning
	mode analysis after adding the extra goals.

compiler/modecheck_unify.m:
	Removed predicate unify_vars - it is no longer used.

compiler/unify_proc.m:
	Call module_info_remove_predid if there are mode errors
	in a unification procedure to avoid spurious determinism
	errors.

tests/hard_coded/Mmakefile:
tests/hard_coded/partial_implied_mode.m:
tests/hard_coded/partial_implied_mode.err_exp:
	Test case. It would be nicer if the error message pointed
	to the unification which caused the unification procedure
	to be created, rather than the type declaration in the
	interface file.
1999-05-18 03:09:21 +00:00