[m-rev.] for review: Modify code for stricter mode checking.
Peter Wang
novalazy at gmail.com
Mon Aug 18 16:06:34 AEST 2014
The following changes are necessary to compile the code following an
upcoming change to the mode checker. Some of them are mode errors.
browser/declarative_oracle.m:
The result of `query_oracle_kb' should be specific
to avoid mode errors in callers.
compiler/accumulator.m:
Help the compiler infer the declared inst.
compiler/mode_robdd.tfeirn.m:
`zero' must be declared to return a normalised tfeirn value to
avoid mode errors. Change `one' for symmetry.
`var_restrict_true' and `var_restrict_false' may return
unnormalised tfeirn values (judging by the code).
Modify `normalise' to help the compiler infer
the declared inst.
compiler/tupling.m:
deep_profiler/autopar_find_best_par.m:
Delete final insts that the compiler cannot verify.
library/tree234.m:
Help the mode checker out using an explicit switch.
tests/hard_coded/bitmap_test.m:
tests/hard_coded/bitmap_tester.m:
Add missing modes.
---
browser/declarative_oracle.m | 2 +-
compiler/accumulator.m | 7 +++++--
compiler/mode_robdd.tfeirn.m | 24 ++++++++++++++----------
compiler/tupling.m | 2 +-
deep_profiler/autopar_find_best_par.m | 2 +-
library/tree234.m | 8 ++++++--
tests/hard_coded/bitmap_test.m | 9 +++++++++
tests/hard_coded/bitmap_tester.m | 2 ++
8 files changed, 39 insertions(+), 17 deletions(-)
diff --git a/browser/declarative_oracle.m b/browser/declarative_oracle.m
index 2506493..fe6bbd8 100644
--- a/browser/declarative_oracle.m
+++ b/browser/declarative_oracle.m
@@ -562,7 +562,7 @@ trusted(ProcLayout, Oracle) :-
).
:- pred query_oracle_kb(oracle_kb::in, decl_question(T)::in,
- decl_answer(T)::out) is semidet.
+ decl_answer(T)::out(known_answer)) is semidet.
query_oracle_kb(KB, Question, Answer) :-
Question = wrong_answer(Node, _, Atom),
diff --git a/compiler/accumulator.m b/compiler/accumulator.m
index c474839..17ca218 100644
--- a/compiler/accumulator.m
+++ b/compiler/accumulator.m
@@ -1431,8 +1431,11 @@ accu_related(ModuleInfo, VarTypes, GoalStore, Var, Related) :-
lookup_call(GoalStore, Id, stored_goal(Call, InstMap)) :-
goal_store_lookup(GoalStore, Id, stored_goal(Goal, InstMap)),
- ( Goal = hlds_goal(plain_call(_, _, _, _, _, _), _) ->
- Call = Goal
+ (
+ Goal = hlds_goal(GoalExpr, GoalInfo),
+ GoalExpr = plain_call(_, _, _, _, _, _)
+ ->
+ Call = hlds_goal(GoalExpr, GoalInfo)
;
unexpected($module, $pred, "not a call")
).
diff --git a/compiler/mode_robdd.tfeirn.m b/compiler/mode_robdd.tfeirn.m
index 51f98fd..889f1a9 100644
--- a/compiler/mode_robdd.tfeirn.m
+++ b/compiler/mode_robdd.tfeirn.m
@@ -36,10 +36,10 @@
:- mode no_tfeirn == out(norm_tfeirn).
% Constants.
-:- func one = tfeirn(T).
+:- func one = (tfeirn(T)::no_tfeirn) is det.
:- pragma type_spec(one/0, T = mc_type).
-:- func zero = tfeirn(T).
+:- func zero = (tfeirn(T)::no_tfeirn) is det.
:- pragma type_spec(zero/0, T = mc_type).
% Conjunction.
@@ -102,11 +102,11 @@
:- pragma type_spec(disj_vars_eq/3, T = mc_type).
:- func var_restrict_true(var(T)::in, tfeirn(T)::di_tfeirn) =
- (tfeirn(T)::no_tfeirn) is det.
+ (tfeirn(T)::uo_tfeirn) is det.
:- pragma type_spec(var_restrict_true/2, T = mc_type).
:- func var_restrict_false(var(T)::in, tfeirn(T)::di_tfeirn) =
- (tfeirn(T)::no_tfeirn) is det.
+ (tfeirn(T)::uo_tfeirn) is det.
:- pragma type_spec(var_restrict_false/2, T = mc_type).
%-----------------------------------------------------------------------------%
@@ -621,8 +621,9 @@ ensure_normalised(X) = normalise(X).
:- func normalise(tfeirn(T)::di_tfeirn) = (tfeirn(T)::no_tfeirn) is det.
:- pragma type_spec(normalise/1, T = mc_type).
-normalise(X) = X :-
- X ^ normalised = yes.
+normalise(X0) = X :-
+ X0 = mode_robdd(T, F, E, I, R, yes),
+ X = mode_robdd(T, F, E, I, R, yes).
normalise(mode_robdd(TrueVars0, FalseVars0, EQVars0, ImpVars0, Robdd0, no))
= X :-
% T <-> F
@@ -684,12 +685,15 @@ normalise(mode_robdd(TrueVars0, FalseVars0, EQVars0, ImpVars0, Robdd0, no))
Robdd2, Robdd, ImpVars3, ImpVars),
Changed = Changed9 `bool__or` Changed10,
- X0 = mode_robdd(TrueVars, FalseVars, EQVars,
- ImpVars, Robdd, bool__not(Changed)),
- ( Changed = yes ->
+ (
+ Changed = yes,
+ X0 = mode_robdd(TrueVars, FalseVars,
+ EQVars, ImpVars, Robdd, no),
X = normalise(X0)
;
- X = X0
+ Changed = no,
+ X = mode_robdd(TrueVars, FalseVars,
+ EQVars, ImpVars, Robdd, yes)
)
;
X = zero
diff --git a/compiler/tupling.m b/compiler/tupling.m
index 67daa20..2c4d7f6 100644
--- a/compiler/tupling.m
+++ b/compiler/tupling.m
@@ -248,7 +248,7 @@ maybe_tuple_scc_individual_procs(TraceCounts, TuningParams, DepGraph,
Procs, !ModuleInfo, !Counter, !TransformMap).
:- pred maybe_tuple_scc(trace_counts::in, tuning_params::in,
- dependency_graph::in, list(pred_proc_id)::in(bound([ground | ground])),
+ dependency_graph::in, list(pred_proc_id)::in,
module_info::in, module_info::out, counter::in, counter::out,
transform_map::in, transform_map::out) is det.
diff --git a/deep_profiler/autopar_find_best_par.m b/deep_profiler/autopar_find_best_par.m
index e5b1e83..463107e 100644
--- a/deep_profiler/autopar_find_best_par.m
+++ b/deep_profiler/autopar_find_best_par.m
@@ -197,7 +197,7 @@ gg_get_details(gg_multiple(Index, Num, P), Index, Num, P).
).
:- pred preprocess_conjunction(list(pard_goal_detail)::in,
- maybe(goals_for_parallelisation)::out(maybe(goals_for_parallelisation)),
+ maybe(goals_for_parallelisation)::out,
program_location::in, cord(message)::in, cord(message)::out) is det.
preprocess_conjunction(Goals, MaybeGoalsForParallelisation, Location,
diff --git a/library/tree234.m b/library/tree234.m
index 01422fc..28446b8 100644
--- a/library/tree234.m
+++ b/library/tree234.m
@@ -779,10 +779,14 @@ match_kv_against_subtree_and_stack(KA, VA, LeftmostB, !StackB) :-
KA = KB1,
VA = VB1,
% Update stack and return.
- ( Right \= empty ->
+ (
+ ( Right = two(_, _, _, _)
+ ; Right = three(_, _, _, _, _, _, _)
+ ; Right = four(_, _, _, _, _, _, _, _, _, _)
+ ),
!:StackB = [Right | !.StackB]
;
- true
+ Right = empty
)
;
( Left = two(_, _, _, _)
diff --git a/tests/hard_coded/bitmap_test.m b/tests/hard_coded/bitmap_test.m
index cbb1dcb..a51bf41 100644
--- a/tests/hard_coded/bitmap_test.m
+++ b/tests/hard_coded/bitmap_test.m
@@ -296,6 +296,8 @@ test_set_op(OpStr, Op, !IO) :-
), !IO).
:- pred test_binary_op(string, (func(tbitmap, tbitmap) = T), io, io).
+:- mode test_binary_op(in, (func(tbitmap_ui, tbitmap_di) = tbitmap_uo is det),
+ di, uo) is det.
:- mode test_binary_op(in, (func(tbitmap_ui, tbitmap_di) = out is det),
di, uo) is det.
@@ -304,6 +306,8 @@ test_binary_op(OpStr, Op, !IO) :-
:- pred test_binary_op(string, (func(tbitmap, tbitmap) = T),
pred(T, io, io), io, io).
+:- mode test_binary_op(in, (func(tbitmap_ui, tbitmap_di) = tbitmap_uo is det),
+ (pred(in, di, uo) is det), di, uo) is det.
:- mode test_binary_op(in, (func(tbitmap_ui, tbitmap_di) = out is det),
(pred(in, di, uo) is det), di, uo) is det.
@@ -313,6 +317,8 @@ test_binary_op(OpStr, Op, Writer, !IO) :-
:- pred test_binary_op(int, string, (func(tbitmap, tbitmap) = T),
pred(T, io, io), io, io).
+:- mode test_binary_op(in, in, (func(tbitmap_ui, tbitmap_di) = tbitmap_uo is det),
+ (pred(in, di, uo) is det), di, uo) is det.
:- mode test_binary_op(in, in, (func(tbitmap_ui, tbitmap_di) = out is det),
(pred(in, di, uo) is det), di, uo) is det.
@@ -347,6 +353,9 @@ test_binary_op(BMLength, OpStr, Op, Writer, !IO) :-
:- mode test_binary_op_2(in, tbitmap_ui,
in, (func(tbitmap_ui, tbitmap_di) = tbitmap_uo is det),
in, tbitmap_ui, (pred(in, di, uo) is det), di, uo) is det.
+:- mode test_binary_op_2(in, tbitmap_ui,
+ in, (func(in, in) = out is det),
+ in, tbitmap_ui, (pred(in, di, uo) is det), di, uo) is det.
test_binary_op_2(BMStr1, BM1, OpStr, Op, BMStr2, BM2, Writer, !IO) :-
io.write_string(OpStr, !IO),
diff --git a/tests/hard_coded/bitmap_tester.m b/tests/hard_coded/bitmap_tester.m
index b49e69c..ff0f586 100644
--- a/tests/hard_coded/bitmap_tester.m
+++ b/tests/hard_coded/bitmap_tester.m
@@ -174,8 +174,10 @@
:- mode to_byte_string(in) = out is det.
:- func ordering(tbitmap, tbitmap) = comparison_result.
+:- mode ordering(tbitmap_ui, tbitmap_ui) = out is det.
:- func test_unify(tbitmap, tbitmap) = bool.
+:- mode test_unify(tbitmap_ui, tbitmap_ui) = out is det.
%-----------------------------------------------------------------------------%
:- implementation.
--
1.8.4
More information about the reviews
mailing list