[m-rev.] For review: inst any non-locals in promise_equivalent_solutions
Ralph Becket
rafe at csse.unimelb.edu.au
Mon Feb 5 13:35:05 AEDT 2007
Estimated hours taken: 1
Branches: main
Fix a bug where promise_equivalent_solutions complained both if you did or did
not include non-locals with inst any in the var list. Such vars *must* now be
included in the list.
NEWS:
Mention the change.
compiler/det_analysis.m:
Require inst any non-locals to appear in the var list.
compiler/instmap.m:
Added var_is_any_in_instmap.
doc/reference_manual.texi:
Document the change.
tests/invalid/Mmakefile:
tests/invalid/promise_equivalent_solutions_test_2.err_exp:
tests/invalid/promise_equivalent_solutions_test_2.m:
Added a test case.
Index: NEWS
===================================================================
RCS file: /home/mercury1/repository/mercury/NEWS,v
retrieving revision 1.440
diff -u -r1.440 NEWS
--- NEWS 1 Feb 2007 08:07:56 -0000 1.440
+++ NEWS 5 Feb 2007 02:17:54 -0000
@@ -14,6 +14,8 @@
values for each thread.
* Unicode characters can now be encoded in string literals using an
escape sequence.
+* promise_equivalent_solutions scopes (et al.) must now also list variables
+ with inst any that may be constrained by the goal.
Changes to the Mercury standard library:
Index: compiler/det_analysis.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/det_analysis.m,v
retrieving revision 1.205
diff -u -r1.205 det_analysis.m
--- compiler/det_analysis.m 19 Jan 2007 07:04:10 -0000 1.205
+++ compiler/det_analysis.m 5 Feb 2007 02:15:20 -0000
@@ -1398,8 +1398,14 @@
goal_info_get_instmap_delta(GoalInfo, InstmapDelta),
instmap_delta_changed_vars(InstmapDelta, ChangedVars),
det_info_get_module_info(DetInfo, ModuleInfo),
+ % BoundVars must include both vars whose inst has changed and vars
+ % with inst any which may have been further constrained by the goal.
set.divide(var_is_ground_in_instmap(ModuleInfo, InstMap0),
- ChangedVars, _GroundAtStartVars, BoundVars),
+ ChangedVars, _GroundAtStartVars, GroundBoundVars),
+ goal_info_get_nonlocals(GoalInfo, NonLocalVars),
+ AnyBoundVars = set.filter(var_is_any_in_instmap(ModuleInfo, InstMap0),
+ NonLocalVars),
+ BoundVars = set.union(GroundBoundVars, AnyBoundVars),
% Which vars were bound inside the scope but not listed
% in the promise_equivalent_solution{s,_sets} or arbitrary scope?
@@ -1421,8 +1427,16 @@
MissingVarNames = [_, _ | _],
MissingListStr = "some variables that are not listed:"
),
+ (
+ set.member(MissingVar, MissingVars),
+ set.member(MissingVar, AnyBoundVars)
+ ->
+ BindsWords = "goal may constrain"
+ ;
+ BindsWords = "goal binds"
+ ),
MissingPieces = [words("Error: the"), quote(MissingKindStr),
- words("goal binds"), words(MissingListStr)]
+ words(BindsWords), words(MissingListStr)]
++ list_to_pieces(MissingVarNames) ++ [suffix(".")],
MissingSpec = error_spec(severity_error, phase_detism_check,
[simple_msg(Context, [always(MissingPieces)])]),
Index: compiler/instmap.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/instmap.m,v
retrieving revision 1.55
diff -u -r1.55 instmap.m
--- compiler/instmap.m 15 Jan 2007 10:30:32 -0000 1.55
+++ compiler/instmap.m 5 Feb 2007 01:20:35 -0000
@@ -304,6 +304,9 @@
:- pred var_is_ground_in_instmap(module_info::in, instmap::in, prog_var::in)
is semidet.
+:- pred var_is_any_in_instmap(module_info::in, instmap::in, prog_var::in)
+ is semidet.
+
% var_is_bound_in_instmap_delta(ModuleInfo, InstMap,
% InstMapDelta, Var)
%
@@ -1220,6 +1223,10 @@
lookup_var(InstMap, Var, Inst),
inst_is_ground(ModuleInfo, Inst).
+var_is_any_in_instmap(ModuleInfo, InstMap, Var) :-
+ lookup_var(InstMap, Var, Inst),
+ inst_is_any(ModuleInfo, Inst).
+
var_is_bound_in_instmap_delta(ModuleInfo, InstMap, InstMapDelta, Var) :-
instmap.lookup_var(InstMap, Var, OldVarInst),
inst_is_free(ModuleInfo, OldVarInst),
Index: doc/reference_manual.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/reference_manual.texi,v
retrieving revision 1.379
diff -u -r1.379 reference_manual.texi
--- doc/reference_manual.texi 15 Jan 2007 02:23:58 -0000 1.379
+++ doc/reference_manual.texi 5 Feb 2007 02:21:12 -0000
@@ -789,7 +789,9 @@
with respect to the equality theories of the variables in @var{Vars}.
It is an error for @var{Vars} to include a variable not bound by @var{Goal}
or for @var{Goal} to bind a non-local variable
-that is not listed in @var{Vars}.
+that is not listed in @var{Vars}
+(non-local variables with inst @var{any} are assumed to be further constrained
+by @var{Goal} and must also be included in @var{Vars}).
If @var{Goal} has determinism @samp{multi} or @samp{cc_multi} then
@code{promise_equivalent_solutions @var{Vars} @var{Goal}}
has determinism @samp{det}.
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.206
diff -u -r1.206 Mmakefile
--- tests/invalid/Mmakefile 15 Jan 2007 02:24:03 -0000 1.206
+++ tests/invalid/Mmakefile 5 Feb 2007 02:01:52 -0000
@@ -150,6 +150,7 @@
prog_io_erroneous \
promise_equivalent_clauses \
promise_equivalent_solutions_test \
+ promise_equivalent_solutions_test_2 \
qual_basic_test2 \
qualified_cons_id2 \
quant_constraint_1 \
Index: tests/invalid/promise_equivalent_solutions_test_2.err_exp
===================================================================
RCS file: tests/invalid/promise_equivalent_solutions_test_2.err_exp
diff -N tests/invalid/promise_equivalent_solutions_test_2.err_exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/invalid/promise_equivalent_solutions_test_2.err_exp 5 Feb 2007 02:01:31 -0000
@@ -0,0 +1,8 @@
+promise_equivalent_solutions_test_2.m:018: Error: the
+promise_equivalent_solutions_test_2.m:018: `promise_equivalent_solutions'
+promise_equivalent_solutions_test_2.m:018: goal may bind a variable that is
+promise_equivalent_solutions_test_2.m:018: not listed: Y.
+promise_equivalent_solutions_test_2.m:024: Error: the
+promise_equivalent_solutions_test_2.m:024: `promise_equivalent_solutions'
+promise_equivalent_solutions_test_2.m:024: goal binds a variable that is not
+promise_equivalent_solutions_test_2.m:024: listed: Y.
Index: tests/invalid/promise_equivalent_solutions_test_2.m
===================================================================
RCS file: tests/invalid/promise_equivalent_solutions_test_2.m
diff -N tests/invalid/promise_equivalent_solutions_test_2.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/invalid/promise_equivalent_solutions_test_2.m 5 Feb 2007 02:03:10 -0000
@@ -0,0 +1,33 @@
+:- module promise_equivalent_solutions_test_2.
+:- interface.
+
+:- pred p1(int::ia) is semidet.
+
+:- pred p2(int::ia, int::ia) is semidet.
+
+:- pred p3(int::ia, int::out) is semidet.
+
+:- implementation.
+
+p1(X) :-
+ promise_equivalent_solutions [X] (
+ q(X)
+ ).
+
+p2(X, Y) :-
+ promise_equivalent_solutions [X] (
+ q(X),
+ q(Y)
+ ).
+
+p3(X, Y) :-
+ promise_equivalent_solutions [X] (
+ q(X),
+ q(Y)
+ ).
+
+:- pred q(int::oa) is multi.
+
+q(1).
+q(2).
+q(3).
--------------------------------------------------------------------------
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