[m-rev.] for review: remove remaining solver type auto init support

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Nov 13 13:29:20 AEDT 2007


For review by Ralph.

Estimated hours taken: 2
Branches: main

Remove support for the `initialisation is ...' attribute from solver types.
This attribute is now a syntax error, unless the developer-only option
`--solver-type-auto-init' is enabled -- in which case things will work
as before.

Update the test suite to conform to the above change.

compiler/globals.m:
 	Add a mutable that stores whether or not we support automatic
 	solver type initialisation.  The value of this mutable is used in
 	the parser to decide if `initialisation is ...' attributes in solver
 	type definitions are legal syntax or not.

compiler/prog_io.m:
 	Only accept `initialisation is ...' attributes in solver type
 	definitions as legal syntax if the value of the above mutable indicates
 	that `--solver-type-auto-init' is enabled.

NEWS:
 	Announce the removal of support for automatic initialisation.

tests/debugger/Mercury.options:
 	Run the solver_test test with `--solver-type-auto-init' enabled.

tests/hard_coded/Mercury.options:
 	Run tests that check if automatic initialisation is working
 	with `--solver-type-auto-init' enabled.

 	Delete a reference to a test case was deleted some time ago.


tests/warnings/Mercury.options:
tests/invalid/Mercury.options:
 	Enable `--solver-type-auto-init' for some tests.

tests/invalid/any_mode.m:
tests/invalid/any_passed_as_ground.m:
tests/invalid/any_should_not_match_bound.m:
tests/invalid/any_ground_in_ite_cond.m:
tests/valid/solv.m:
tests/hard_coded/any_call_hoist_bug.m:
tests/hard_coded/any_free_unify.m:
tests/hard_coded/sub-modules/ts.m:
 	Remove `initialisation is ...' attributes from the solver type
 	definitions in these tests.

Julien.

Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.481
diff -u -r1.481 NEWS
--- NEWS	12 Nov 2007 03:52:35 -0000	1.481
+++ NEWS	13 Nov 2007 02:26:49 -0000
@@ -3,6 +3,7 @@

  Changes to the Mercury language:

+* We have removed support for automatic initialisation of solver variables.
  * A new pragma, foreign_enum, allows the constructors of Mercury
    enumeration types to be assigned values from foreign language code.
  * A new pragma, foreign_export_enum, allows the constructors of Mercury
@@ -262,6 +263,18 @@

  Changes to the Mercury language:

+* Support for the automatic initialisation of solver variables has been
+  removed because it was source of confusing errors and was not used in
+  practice anyway.
+
+  A consequence of this is that solver types are now properly polymorphic,
+  i.e. types like `foo(bar)' where:
+
+  	:- solver type foo(T).
+	:- solver type bar.
+ 
+  are now supported.
+
  * The new pragma, foreign_enum, can be used to establish a
    mapping between values in a foreign language and the constructors
    of a Mercury enumeration type.  This can be useful when writing
Index: compiler/globals.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/globals.m,v
retrieving revision 1.84
diff -u -r1.84 globals.m
--- compiler/globals.m	14 Jul 2007 02:32:42 -0000	1.84
+++ compiler/globals.m	13 Nov 2007 02:26:49 -0000
@@ -233,6 +233,12 @@

  :- pred io_get_extra_error_info(bool::out, io::di, io::uo) is det.

+    % This is semipure because it is called in a context in which the I/O
+    % state is not available.  Note that the corresponding set predicate
+    % below does take the I/O state.
+    %
+:- semipure pred semipure_get_solver_auto_init_supported(bool::out) is det.
+
  :- pred io_get_globals(globals::out, io::di, io::uo) is det.

  :- pred io_set_globals(globals::in, io::di, io::uo) is det.
@@ -244,6 +250,7 @@
  :- pred io_set_trace_level(trace_level::in, io::di, io::uo) is det.
  :- pred io_set_trace_level_none(io::di, io::uo) is det.
  :- pred io_set_extra_error_info(bool::in, io::di, io::uo) is det.
+:- pred io_set_solver_auto_init_supported(bool::in, io::di, io::uo) is det.

  :- pred io_lookup_option(option::in, option_data::out, io::di, io::uo) is det.

@@ -372,6 +379,19 @@
  :- mutable(extra_error_info, bool, no, ground,
      [untrailed, attach_to_io_state, thread_local]).

+    % This mutable is used to control how the parser handles `initialisation'
+    % attributes in solver type definitions.  They are not currently part
+    % of the language so by default if we encounter one it is reported
+    % as a syntax error.   If the developer-only option
+    % `--solver-type-auto-init' is given then we enable support for them .
+    %
+    % Since this information is only needed at one place in the parser
+    % we use this mutable in preference to passing an extra argument
+    % throughout the parser.
+    %
+:- mutable(solver_auto_init_supported, bool, no, ground,
+    [untrailed, attach_to_io_state, thread_local]).
+
  globals_init(Options, Target, GC_Method, TagsMethod,
          TerminationNorm, Termination2Norm, TraceLevel, TraceSuppress,
          MaybeThreadSafe,
@@ -535,7 +555,10 @@
      globals_init(Options, Target1, GC_Method1, TagsMethod1,
          TerminationNorm1, Termination2Norm1, TraceLevel1,
          TraceSuppress1, MaybeThreadSafe1, Globals),
-    io_set_globals(Globals, !IO).
+    io_set_globals(Globals, !IO),
+    getopt_io.lookup_bool_option(Options, solver_type_auto_init,
+        AutoInitSupported),
+    io_set_solver_auto_init_supported(AutoInitSupported, !IO).

  io_get_target(Target, !IO) :-
      io_get_globals(Globals, !IO),
@@ -572,6 +595,9 @@
  io_get_extra_error_info(ExtraErrorInfo, !IO) :-
      get_extra_error_info(ExtraErrorInfo, !IO).

+semipure_get_solver_auto_init_supported(AutoInitSupported) :-
+    semipure get_solver_auto_init_supported(AutoInitSupported).
+
  io_get_globals(Globals, !IO) :-
      globals.get_globals(UnivGlobals, !IO),
      ( univ_to_type(UnivGlobals, Globals0) ->
@@ -616,6 +642,9 @@
  io_set_extra_error_info(ExtraErrorInfo, !IO) :-
      set_extra_error_info(ExtraErrorInfo, !IO).

+io_set_solver_auto_init_supported(AutoInitSupported, !IO) :-
+    set_solver_auto_init_supported(AutoInitSupported, !IO).
+
      % This predicate is needed because mercury_compile.m doesn't know
      % anything about type trace_level.
  io_set_trace_level_none(!IO) :-
Index: compiler/prog_io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/prog_io.m,v
retrieving revision 1.284
diff -u -r1.284 prog_io.m
--- compiler/prog_io.m	31 Oct 2007 03:58:29 -0000	1.284
+++ compiler/prog_io.m	13 Nov 2007 02:26:49 -0000
@@ -2226,10 +2226,29 @@
      (
          Result0 = ok1(no)
      ->
-        Result = parse_where_is("initialization",
+        Result1 = parse_where_is("initialization",
              parse_where_pred_is(ModuleName), Term)
      ;
-        Result = Result0
+        Result1 = Result0
+    ),
+    promise_pure (
+        (
+            Result1 = ok1(yes(_)),
+            semipure semipure_get_solver_auto_init_supported(AutoInitSupported),
+            (
+                AutoInitSupported = yes,
+                Result = Result1
+            ;
+                AutoInitSupported = no,
+                Msg = "unknown attribute in solver type definition",
+                Result = error1([Msg - Term])
+            )
+        ;
+            ( Result1 = ok1(no)
+            ; Result1 = error1(_)
+            ), 
+            Result  = Result1
+        )
      ).

  :- func parse_where_pred_is(module_name, term) = maybe1(sym_name).
Index: tests/debugger/Mercury.options
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/debugger/Mercury.options,v
retrieving revision 1.25
diff -u -r1.25 Mercury.options
--- tests/debugger/Mercury.options	27 Sep 2007 07:28:23 -0000	1.25
+++ tests/debugger/Mercury.options	13 Nov 2007 02:26:49 -0000
@@ -55,7 +55,7 @@
  # The solver_test test case exercises the printing of a procedure name, and
  # that procedure is dead, so we must prevent it being optimized away.
  # The -O2 is to prevent spurious inconsistencies.
-MCFLAGS-solver_test = -O2 --no-optimize-dead-procs
+MCFLAGS-solver_test = -O2 --no-optimize-dead-procs --solver-type-auto-init

  # We need to use shared libraries for interactive queries to work.
  # The following is necessary for shared libraries to work on Linux.
Index: tests/hard_coded/Mercury.options
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/Mercury.options,v
retrieving revision 1.29
diff -u -r1.29 Mercury.options
--- tests/hard_coded/Mercury.options	31 Oct 2007 03:58:32 -0000	1.29
+++ tests/hard_coded/Mercury.options	13 Nov 2007 02:26:49 -0000
@@ -60,13 +60,13 @@
  MCFLAGS-redoip_clobber	=	--no-inlining
  MCFLAGS-rnd		=	-O6

-# This test checks that calls to initialisation predicates are correctly
-# added to construction unifications, so it only works if automatic
-# initialisation of solver types is enabled.
-#
+# These tests check that calls to initialisation predicates are correctly
+# added to various constructs.  They only work of automatic initialisation
+# of solver types is enabled.
  MCFLAGS-solver_construction_init_test = --solver-type-auto-init
+MCFLAGS-solver_disj_inits = --solver-type-auto-init
+MCFLAGS-solver_ite_inits  = --solver-type-auto-init

-MCFLAGS-split_c_files	=	--trace rep
  MCFLAGS-switch_detect	=	--halt-at-warn
  # The trace_goal_1 and trace_goal_2 test cases differ only in that
  # we compile the latter without any --trace-flag arguments.
Index: tests/hard_coded/any_call_hoist_bug.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/any_call_hoist_bug.m,v
retrieving revision 1.2
diff -u -r1.2 any_call_hoist_bug.m
--- tests/hard_coded/any_call_hoist_bug.m	23 Aug 2007 01:14:19 -0000	1.2
+++ tests/hard_coded/any_call_hoist_bug.m	13 Nov 2007 02:26:49 -0000
@@ -57,8 +57,7 @@
  :- mutable(literal_supply, int, 561, ground, [untrailed]).

  :- solver type literal
-    where   representation is int,
-            initialisation is make_new_literal.
+    where   representation is int.

  :- pred make_new_literal(literal::oa) is det.

Index: tests/hard_coded/any_free_unify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/any_free_unify.m,v
retrieving revision 1.5
diff -u -r1.5 any_free_unify.m
--- tests/hard_coded/any_free_unify.m	14 Dec 2005 05:14:16 -0000	1.5
+++ tests/hard_coded/any_free_unify.m	13 Nov 2007 02:26:49 -0000
@@ -16,7 +16,6 @@

  :- solver type foo
  	where	representation is int, 
-		initialisation is init_foo,
  		ground         is ground,
  		any            is ground.

Index: tests/hard_coded/sub-modules/ts.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/sub-modules/ts.m,v
retrieving revision 1.1
diff -u -r1.1 ts.m
--- tests/hard_coded/sub-modules/ts.m	12 Sep 2005 03:05:50 -0000	1.1
+++ tests/hard_coded/sub-modules/ts.m	13 Nov 2007 02:26:49 -0000
@@ -12,8 +12,7 @@
  :- implementation.

  :- import_module int, exception.
-:- solver type st where representation is int,
-    initialisation is init_int.
+:- solver type st where representation is int.

  :- pred init_int(st::oa) is erroneous.
  init_int(_A) :- throw("stop").
Index: tests/invalid/Mercury.options
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/Mercury.options,v
retrieving revision 1.26
diff -u -r1.26 Mercury.options
--- tests/invalid/Mercury.options	25 Oct 2007 05:05:13 -0000	1.26
+++ tests/invalid/Mercury.options	13 Nov 2007 02:26:49 -0000
@@ -144,4 +144,5 @@
  MCFLAGS-vars_in_wrong_places 		= --verbose-error-messages

  # --verbose-error-messages will mask the problem that zinc2mer_lib checks for.
-MCFLAGS-zinc2mer_lib = --no-verbose-error-messages
+MCFLAGS-zinc2mer_lib = --no-verbose-error-messages --solver-type-auto-init
+MCFLAGS-missing_init_pred = --solver-type-auto-init
Index: tests/invalid/any_mode.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/any_mode.m,v
retrieving revision 1.4
diff -u -r1.4 any_mode.m
--- tests/invalid/any_mode.m	10 Sep 2004 03:50:29 -0000	1.4
+++ tests/invalid/any_mode.m	13 Nov 2007 02:26:49 -0000
@@ -10,7 +10,6 @@

  :- solver type foo
  	where representation is int,
-	      initialisation is init_foo,
  	      ground         is ground,
  	      any            is ground,
  	      equality       is eq_foo.
Index: tests/invalid/any_passed_as_ground.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/any_passed_as_ground.m,v
retrieving revision 1.5
diff -u -r1.5 any_passed_as_ground.m
--- tests/invalid/any_passed_as_ground.m	31 Oct 2007 03:58:32 -0000	1.5
+++ tests/invalid/any_passed_as_ground.m	13 Nov 2007 02:26:49 -0000
@@ -23,7 +23,7 @@

  :- import_module int, list, pair.

-:- solver type st where representation is int, initialisation is i.
+:- solver type st where representation is int.

  %-----------------------------------------------------------------------------%

Index: tests/invalid/any_should_not_match_bound.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/any_should_not_match_bound.m,v
retrieving revision 1.2
diff -u -r1.2 any_should_not_match_bound.m
--- tests/invalid/any_should_not_match_bound.m	10 Sep 2004 03:50:30 -0000	1.2
+++ tests/invalid/any_should_not_match_bound.m	13 Nov 2007 02:26:49 -0000
@@ -33,7 +33,6 @@

  :- solver type foo
  	where representation is int,
-	      initialisation is init_foo,
  	      ground         is ground,
  	      any            is ground,
  	      equality       is eq_foo.
Index: tests/invalid/any_to_ground_in_ite_cond.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/invalid/any_to_ground_in_ite_cond.m,v
retrieving revision 1.3
diff -u -r1.3 any_to_ground_in_ite_cond.m
--- tests/invalid/any_to_ground_in_ite_cond.m	14 Dec 2005 05:14:17 -0000	1.3
+++ tests/invalid/any_to_ground_in_ite_cond.m	13 Nov 2007 02:26:49 -0000
@@ -23,7 +23,7 @@

  :- import_module int, list, std_util.

-:- solver type st where representation is int, initialisation is i.
+:- solver type st where representation is int.

  %-----------------------------------------------------------------------------%

Index: tests/valid/solv.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/valid/solv.m,v
retrieving revision 1.4
diff -u -r1.4 solv.m
--- tests/valid/solv.m	24 Mar 2006 04:40:59 -0000	1.4
+++ tests/valid/solv.m	13 Nov 2007 02:26:49 -0000
@@ -53,7 +53,6 @@

  :- solver type fd_var
  	where	representation is c_pointer,
-		initialisation is init_any,
  		ground         is ground,
  		any            is ground.

Index: tests/warnings/Mercury.options
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/warnings/Mercury.options,v
retrieving revision 1.13
diff -u -r1.13 Mercury.options
--- tests/warnings/Mercury.options	20 Jul 2006 01:50:46 -0000	1.13
+++ tests/warnings/Mercury.options	13 Nov 2007 02:26:49 -0000
@@ -40,7 +40,7 @@
  MCFLAGS-pragma_term_conflict = --enable-termination
  MCFLAGS-term_indirect_warning = --check-termination
  MCFLAGS-foreign_term_invalid = --enable-termination
-MCFLAGS-non_term_user_special = --enable-termination
+MCFLAGS-non_term_user_special = --enable-termination --solver-type-auto-init

  MCFLAGS-warn_dead_procs 	= --warn-dead-procs --infer-all


--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list