[m-dev.] diff: fix bogus error context explanation
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Nov 22 16:46:03 AEDT 1999
Estimated hours taken: 0.75
Fix a problem where the compiler was reporting bogus context explanations
for errors occurring in the function result term of a clause head. For a
function of arity N, it was saying "in argument N+1 of clause head: ...".
I changed it to say "in function result term of clause head: ...".
compiler/hlds_goal.m:
Add a new alternative `head_result' to the unify_main_context type.
compiler/hlds_out.m:
Handle the new `head_result' alternative.
compiler/make_hlds.m:
Add `is_pred_or_func' and `arity' arguments to the `head' alternative
of the arg_context type. When converting an arg_context to a
unify_main_context, if PredOrFunc = function and ArgNum = Arity,
then convert to `head_result' rather than to `head(ArgNum)'.
tests/invalid/funcs_as_preds.err_exp:
Adjust the expected output for this test case to reflect
the change described above.
Workspace: /home/mercury0/fjh/mercury
Index: compiler/hlds_goal.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_goal.m,v
retrieving revision 1.64
diff -u -d -r1.64 hlds_goal.m
--- hlds_goal.m 1999/10/25 03:48:53 1.64
+++ hlds_goal.m 1999/11/22 05:17:16
@@ -509,6 +509,9 @@
% (first argument == no. 1)
)
+ % a unification in the function result term of a clause head
+ ; head_result
+
% a unification in an argument of a predicate call
; call(
call_id, % the name and arity of the predicate
Index: compiler/hlds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_out.m,v
retrieving revision 1.231
diff -u -d -r1.231 hlds_out.m
--- hlds_out.m 1999/11/12 09:08:17 1.231
+++ hlds_out.m 1999/11/22 05:43:58
@@ -524,9 +524,11 @@
hlds_out__write_unify_main_context(First, explicit, _, First) -->
[].
hlds_out__write_unify_main_context(First, head(ArgNum), Context, no) -->
- % XXX handle function return values better.
hlds_out__write_in_argument(First, ArgNum, Context),
io__write_string(" of clause head:\n").
+hlds_out__write_unify_main_context(First, head_result, Context, no) -->
+ hlds_out__start_in_message(First, Context),
+ io__write_string("function result term of clause head:\n").
hlds_out__write_unify_main_context(First, call(CallId, ArgNum), Context, no) -->
hlds_out__start_in_message(First, Context),
hlds_out__write_call_arg_id(CallId, ArgNum),
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.316
diff -u -d -r1.316 make_hlds.m
--- make_hlds.m 1999/11/15 07:24:27 1.316
+++ make_hlds.m 1999/11/22 05:33:25
@@ -3001,7 +3001,7 @@
{ map__keys(Procs, ModeIds) },
clauses_info_add_clause(Clauses0, PredId, ModeIds,
ClauseVarSet, TVarSet0, Args, Body, Context,
- IsAssertion, Goal,
+ PredOrFunc, Arity, IsAssertion, Goal,
VarSet, TVarSet, Clauses, Warnings,
ModuleInfo0, ModuleInfo1, Info0, Info),
{
@@ -3258,7 +3258,7 @@
{ PragmaImpl = ordinary(C_Code, no) },
clauses_info_add_pragma_c_code(Clauses0, Purity, Attributes,
PredId, ProcId, VarSet, PragmaVars, ArgTypes, PragmaImpl,
- Context, Clauses, Info0, Info),
+ Context, PredOrFunc, Arity, Clauses, Info0, Info),
%
% Store the clauses_info etc. back into the pred_info
@@ -3486,7 +3486,7 @@
clauses_info_add_pragma_c_code(Clauses0, Purity,
Attributes, PredId, ProcId, VarSet,
PVars, ArgTypes, PragmaImpl, Context,
- Clauses, Info0, Info),
+ PredOrFunc, Arity, Clauses, Info0, Info),
{ pred_info_set_clauses_info(PredInfo1, Clauses,
PredInfo2) },
{ pred_info_set_goal_type(PredInfo2, pragmas,
@@ -4431,22 +4431,25 @@
:- pred clauses_info_add_clause(clauses_info::in, pred_id::in,
list(proc_id)::in, prog_varset::in, tvarset::in,
- list(prog_term)::in, goal::in, prog_context::in, bool::in,
+ list(prog_term)::in, goal::in, prog_context::in,
+ pred_or_func::in, arity::in, bool::in,
hlds_goal::out, prog_varset::out, tvarset::out,
clauses_info::out, list(quant_warning)::out,
module_info::in, module_info::out, qual_info::in,
qual_info::out, io__state::di, io__state::uo) is det.
clauses_info_add_clause(ClausesInfo0, PredId, ModeIds, CVarSet, TVarSet0,
- Args, Body, Context, IsAssertion, Goal, VarSet, TVarSet0,
- ClausesInfo, Warnings, Module0, Module, Info0, Info) -->
+ Args, Body, Context, PredOrFunc, Arity, IsAssertion, Goal,
+ VarSet, TVarSet0, ClausesInfo, Warnings, Module0, Module,
+ Info0, Info) -->
{ ClausesInfo0 = clauses_info(VarSet0, VarTypes0, VarTypes1,
HeadVars, ClauseList0,
TI_VarMap, TCI_VarMap) },
{ update_qual_info(Info0, TVarSet0, VarTypes0, PredId, Info1) },
{ varset__merge_subst(VarSet0, CVarSet, VarSet1, Subst) },
- transform(Subst, HeadVars, Args, Body, VarSet1, Context, IsAssertion,
- Goal, VarSet, Warnings, Module0, Module, Info1, Info2),
+ transform(Subst, HeadVars, Args, Body, VarSet1, Context, PredOrFunc,
+ Arity, IsAssertion, Goal, VarSet, Warnings,
+ Module0, Module, Info1, Info2),
{ qual_info_get_found_syntax_error(Info2, FoundError) },
{ qual_info_set_found_syntax_error(no, Info2, Info) },
(
@@ -4476,13 +4479,14 @@
:- pred clauses_info_add_pragma_c_code(clauses_info, purity,
pragma_c_code_attributes, pred_id, proc_id, prog_varset,
list(pragma_var), list(type), pragma_c_code_impl, prog_context,
- clauses_info, qual_info, qual_info, io__state, io__state) is det.
+ pred_or_func, arity, clauses_info, qual_info,
+ qual_info, io__state, io__state) is det.
:- mode clauses_info_add_pragma_c_code(in, in, in, in, in, in, in, in, in, in,
- out, in, out, di, uo) is det.
+ in, in, out, in, out, di, uo) is det.
clauses_info_add_pragma_c_code(ClausesInfo0, Purity, Attributes, PredId,
ModeId, PVarSet, PVars, OrigArgTypes, PragmaImpl, Context,
- ClausesInfo, Info0, Info) -->
+ PredOrFunc, Arity, ClausesInfo, Info0, Info) -->
{
ClausesInfo0 = clauses_info(VarSet0, VarTypes, VarTypes1,
HeadVars, ClauseList, TI_VarMap, TCI_VarMap),
@@ -4506,8 +4510,9 @@
% Since the set of head vars and the set vars in the
% pragma C code are disjoint, the unifications can be
% implemented as substitutions, and they will be.
- insert_arg_unifications(HeadVars, TermArgs, Context, head, yes,
- HldsGoal0, VarSet1, HldsGoal1, VarSet2, Info0, Info),
+ insert_arg_unifications(HeadVars, TermArgs, Context,
+ head(PredOrFunc, Arity), yes, HldsGoal0, VarSet1,
+ HldsGoal1, VarSet2, Info0, Info),
{
map__init(Empty),
implicitly_quantify_clause_body(HeadVars, HldsGoal1, VarSet2, Empty,
@@ -4530,14 +4535,16 @@
%-----------------------------------------------------------------------------
:- pred transform(prog_substitution, list(prog_var), list(prog_term), goal,
- prog_varset, prog_context, bool, hlds_goal, prog_varset,
- list(quant_warning), module_info, module_info,
- qual_info, qual_info, io__state, io__state).
-:- mode transform(in, in, in, in, in, in, in, out, out, out,
+ prog_varset, prog_context, pred_or_func, arity, bool,
+ hlds_goal, prog_varset, list(quant_warning),
+ module_info, module_info, qual_info, qual_info,
+ io__state, io__state).
+:- mode transform(in, in, in, in, in, in, in, in, in, out, out, out,
in, out, in, out, di, uo) is det.
-transform(Subst, HeadVars, Args0, Body, VarSet0, Context, IsAssertion,
- Goal, VarSet, Warnings, Module0, Module, Info0, Info) -->
+transform(Subst, HeadVars, Args0, Body, VarSet0, Context, PredOrFunc,
+ Arity, IsAssertion, Goal, VarSet, Warnings,
+ Module0, Module, Info0, Info) -->
transform_goal(Body, VarSet0, Subst, Goal1, VarSet1, Info0, Info1),
{ term__apply_substitution_to_list(Args0, Subst, Args) },
{ map__init(Empty) },
@@ -4553,8 +4560,9 @@
{ Info = Info0 }
;
{ Module = Module0 },
- insert_arg_unifications(HeadVars, Args, Context, head, no,
- Goal1, VarSet1, Goal2, VarSet2, Info1, Info)
+ { ArgContext = head(PredOrFunc, Arity) },
+ insert_arg_unifications(HeadVars, Args, Context, ArgContext,
+ no, Goal1, VarSet1, Goal2, VarSet2, Info1, Info)
),
{ implicitly_quantify_clause_body(HeadVars, Goal2, VarSet2, Empty,
Goal, VarSet, _, Warnings) }.
@@ -4932,8 +4940,10 @@
{ map__init(Substitution) },
transform_goal(ParsedGoal, VarSet2, Substitution,
PredGoal0, VarSet3, Info0, Info1),
- insert_arg_unifications(HeadArgs, HeadArgs1, Context, head, no,
- PredGoal0, VarSet3, PredGoal, VarSet4, Info1, Info2),
+ { ArgContext = head(PredOrFunc, PredArity) },
+ insert_arg_unifications(HeadArgs, HeadArgs1, Context,
+ ArgContext, no, PredGoal0, VarSet3, PredGoal, VarSet4,
+ Info1, Info2),
% Quantification will reduce this down to
% the proper set of nonlocal arguments.
@@ -5214,9 +5224,15 @@
% complicate the handling of code generation for nondet pragma C codes.
:- type arg_context
- ---> head % the arguments in the head of the clause
- ; call(call_id) % the arguments in a call to a predicate
- ; functor( % the arguments in a functor
+ --->
+ % the arguments in the head of the clause
+ head(pred_or_func, arity)
+ ;
+ % the arguments in a call to a predicate
+ call(call_id)
+ ;
+ % the arguments in a functor
+ functor(
cons_id,
unify_main_context,
unify_sub_contexts
@@ -5358,10 +5374,18 @@
unify_main_context, unify_sub_contexts).
:- mode arg_context_to_unify_context(in, in, out, out) is det.
-arg_context_to_unify_context(head, N, head(N), []).
-arg_context_to_unify_context(call(PredId), N, call(PredId, N), []).
-arg_context_to_unify_context(functor(ConsId, MainContext, SubContexts), N,
- MainContext, [ConsId - N | SubContexts]).
+arg_context_to_unify_context(head(PredOrFunc, Arity), ArgNum,
+ ArgContext, []) :-
+ ( PredOrFunc = function, ArgNum = Arity ->
+ % it's the function result term in the head
+ ArgContext = head_result
+ ;
+ % it's a head argument
+ ArgContext = head(ArgNum)
+ ).
+arg_context_to_unify_context(call(PredId), ArgNum, call(PredId, ArgNum), []).
+arg_context_to_unify_context(functor(ConsId, MainContext, SubContexts), ArgNum,
+ MainContext, [ConsId - ArgNum | SubContexts]).
%-----------------------------------------------------------------------------%
@@ -5694,8 +5718,9 @@
{ map__init(Substitution) },
transform_goal(ParsedGoal, VarSet1, Substitution,
HLDS_Goal0, VarSet2, Info1, Info2),
- insert_arg_unifications(LambdaVars, Args, Context, head, no,
- HLDS_Goal0, VarSet2, HLDS_Goal1, VarSet, Info2, Info),
+ { ArgContext = head(PredOrFunc, NumArgs) },
+ insert_arg_unifications(LambdaVars, Args, Context, ArgContext,
+ no, HLDS_Goal0, VarSet2, HLDS_Goal1, VarSet, Info2, Info),
%
% Now figure out which variables we need to explicitly existentially
Index: tests/invalid/funcs_as_preds.err_exp
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/funcs_as_preds.err_exp,v
retrieving revision 1.6
diff -u -d -r1.6 funcs_as_preds.err_exp
--- funcs_as_preds.err_exp 1998/10/30 04:38:44 1.6
+++ funcs_as_preds.err_exp 1999/11/22 05:41:47
@@ -10,7 +10,7 @@
funcs_as_preds.m:030: Error: clause for function `funcs_as_preds:ap/2'
funcs_as_preds.m:030: without preceding `func' declaration.
funcs_as_preds.m:017: In clause for function `funcs_as_preds:null/1':
-funcs_as_preds.m:017: in argument 2 of clause head:
+funcs_as_preds.m:017: in function result term of clause head:
funcs_as_preds.m:017: error: the language construct =/2 should be
funcs_as_preds.m:017: used as a goal, not as an expression.
funcs_as_preds.m:030: In clause for function `funcs_as_preds:ap/2':
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list