[m-dev.] for review: update of Aditi update changes
Simon Taylor
stayl at cs.mu.OZ.AU
Tue Jul 13 14:06:27 AEST 1999
Hi,
These changes are the non-trivial modifications to the Aditi update
changes made after merging the existential types changes.
There was a bug in the diff I originally posted for
`typecheck__report_error_num_args' - the arity of functions
was being incremented rather than decremented for use
in error messages. This code is now in error_util.m so that
make_hlds.m doesn't have to import typecheck.m.
In the code to handle `aditi_insert' in polymorphism.m:
- Only add type-infos for the arguments of the tuple, not the `aditi__state's.
- Make sure the type-infos are added to the non-locals
for the `aditi_insert' goal, otherwise modes.m optimizes the
type-info constructions away.
In modecheck_call.m and unique_modes.m, changes were made
to adjust the argument numbers of `aditi_insert' goals for
the type-infos that polymorphism.m adds for the tuple to insert.
The Aditi update error message test had to be split into
two because mode analysis is not run if there are type errors
in any predicates. The differences are trivial.
The type `rl_exprn_id' was moved from rl.m to hlds_pred.m to
avoid hlds_pred.m having to import rl.m.
The type `lambda_eval_method' was moved from hlds_data.m to
prog_data.m to avoid prog_io_util.m having to import hlds_data.m.
--- log 1999/07/12 05:05:30 1.4
+++ log 1999/07/13 04:04:23
@@ -6,14 +6,6 @@
Change the hlds_goal for constructions in preparation for
structure reuse to avoid making multiple conflicting changes.
-compiler/hlds_data.m:
- Add a type `lambda_eval_method', which describes how a closure
- is to be executed. The alternatives are normal Mercury execution,
- bottom-up execution by Aditi and top-down execution by Aditi.
-
- Add a `lambda_eval_method' field to `pred_const' and
- `pred_closure_tag' cons_ids.
-
compiler/hlds_goal.m:
Merge `higher_order_call' and `class_method_call' into a single
`generic_call' goal type. This also has alternatives for the
@@ -54,12 +46,20 @@
it must be done after typechecking.
compiler/prog_data.m:
-compiler/prog_out.m:
Added `:- type sym_name_and_arity ---> sym_name/arity'.
+ Add a type `lambda_eval_method', which describes how a closure
+ is to be executed. The alternatives are normal Mercury execution,
+ bottom-up execution by Aditi and top-down execution by Aditi.
+
+compiler/prog_out.m:
Add predicate `prog_out__write_sym_name_and_arity', which
replaces duplicated inline code in a few places.
+compiler/hlds_data.m:
+ Add a `lambda_eval_method' field to `pred_const' cons_ids and
+ `pred_closure_tag' cons_tags.
+
compiler/hlds_pred.m:
Remove type `pred_call_id', replace it with type `simple_call_id',
which combines a `pred_or_func' and a `sym_name_and_arity'.
@@ -73,8 +73,9 @@
Remove `aditi_interface' from type `marker'. Interfacing to
Aditi predicates is now handled by `generic_call' hlds_goals.
- Add a field to type `proc_info' to describe which Aditi code fragment
- is to be used to evaluate an `aditi_top_down' procedure.
+ Add a type `rl_exprn_id' which identifies a predicate to
+ be executed top-down by Aditi.
+ Add a `maybe(rl_exprn_id)' field to type `proc_info'.
Add predicate `adjust_func_arity' to convert between the arity
of a function to its arity as a predicate.
@@ -166,9 +167,11 @@
arguments to allow a transformation to be performed on the
argument types before passing them.
- Export `report_error_num_args' for use by make_hlds.m when
- reporting errors for Aditi builtins. Change `report_error_num_args'
- to allow Aditi builtins to be reported properly.
+compiler/error_util.m:
+ Move the part of `report_error_num_args' which writes
+ "wrong number of arguments (<x>; expected <y>)" from
+ typecheck.m for use by make_hlds.m when reporting errors
+ for Aditi builtins.
compiler/modes.m:
compiler/unique_modes.m:
@@ -244,6 +247,7 @@
tests/invalid/Mmakefile
tests/invalid/aditi_update_errors.{m,err_exp}:
+tests/invalid/aditi_update_mode_errors.{m,err_exp}:
Test error messages for Aditi updates.
tests/valid/aditi.m:
Index: error_util.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/error_util.m,v
retrieving revision 1.9
diff -u -u -r1.9 error_util.m
--- error_util.m 1999/07/09 01:15:25 1.9
+++ error_util.m 1999/07/12 07:28:25
@@ -78,6 +78,16 @@
assoc_list(pred_proc_id, prog_context)::in,
list(format_component)::out) is det.
+ % report_error_num_args(MaybePredOrFunc, Arity, CorrectArities).
+ %
+ % Write
+ % "wrong number of arguments (<Arity>; should be <CorrectArities>)",
+ % adjusting `Arity' and `CorrectArities' if `MaybePredOrFunc' is
+ % `yes(function)'.
+:- pred report_error_num_args(maybe(pred_or_func), int, list(int),
+ io__state, io__state).
+:- mode report_error_num_args(in, in, in, di, uo) is det.
+
:- implementation.
:- import_module prog_out.
@@ -370,4 +380,42 @@
error_util__describe_several_call_sites(Module, Sites, Pieces) :-
list__map(error_util__describe_one_call_site(Module), Sites, Pieces0),
error_util__list_to_pieces(Pieces0, Pieces).
+
+%-----------------------------------------------------------------------------%
+
+report_error_num_args(MaybePredOrFunc, Arity0, Arities0) -->
+ % Adjust arities for functions.
+ { MaybePredOrFunc = yes(function) ->
+ adjust_func_arity(function, Arity, Arity0),
+ list__map(
+ (pred(OtherArity0::in, OtherArity::out) is det :-
+ adjust_func_arity(function,
+ OtherArity, OtherArity0)
+ ),
+ Arities0, Arities)
+ ;
+ Arity = Arity0,
+ Arities = Arities0
+ },
+
+ io__write_string("wrong number of arguments ("),
+ io__write_int(Arity),
+ io__write_string("; should be "),
+ report_error_right_num_args(Arities),
+ io__write_string(")").
+
+:- pred report_error_right_num_args(list(int), io__state, io__state).
+:- mode report_error_right_num_args(in, di, uo) is det.
+
+report_error_right_num_args([]) --> [].
+report_error_right_num_args([Arity | Arities]) -->
+ io__write_int(Arity),
+ ( { Arities = [] } ->
+ []
+ ; { Arities = [_] } ->
+ io__write_string(" or ")
+ ;
+ io__write_string(", ")
+ ),
+ report_error_right_num_args(Arities).
--- hlds_out.m 1999/06/27 01:01:42 1.7
+++ hlds_out.m 1999/07/12 04:33:58
@@ -375,13 +373,30 @@
hlds_out__write_call_arg_id(CallId, ArgNum) -->
( { ArgNum =< 0 } ->
- % We don't know which argument it was.
+ % Argument numbers that are less than or equal to zero
+ % are used for the type_info and typeclass_info arguments
+ % that are introduced by polymorphism.m.
+ % I think argument number equal to zero might also be used
+ % in some other cases when we just don't have any information
+ % about which argument it is.
+ % For both of these, we just say "in call to"
+ % rather than "in argument N of call to".
[]
;
hlds_out__write_arg_number(CallId, ArgNum),
io__write_string(" of ")
),
- io__write_string("call to "),
+ (
+ { CallId = generic_call(GenericCall) },
+ \+ { GenericCall = class_method(_, _) },
+ \+ { GenericCall = aditi_builtin(aditi_call(_, _, _, _), _) }
+ ->
+ % The text printed for generic calls other than `aditi_call'
+ % and `class__method' does not need the "call to" prefix.
+ []
+ ;
+ io__write_string("call to ")
+ ),
hlds_out__write_call_id(CallId).
:- pred hlds_out__write_arg_number(call_id, int, io__state, io__state).
--- make_hlds.m 1999/07/05 01:26:50 1.9
+++ make_hlds.m 1999/07/09 06:39:36
@@ -4914,8 +5076,15 @@
aditi_update_arity_error(Context, UpdateStr, Arity, ExpectedArities) -->
io__set_exit_status(1),
{ MaybePredOrFunc = no },
- report_error_num_args(yes, Context, MaybePredOrFunc,
- unqualified(UpdateStr), Arity, ExpectedArities).
+ prog_out__write_context(Context),
+ io__write_string("Error: "),
+ { MaybePredOrFunc = no },
+ report_error_num_args(MaybePredOrFunc, Arity, ExpectedArities),
+ io__nl,
+ prog_out__write_context(Context),
+ io__write_string(" in `"),
+ io__write_string(UpdateStr),
+ io__write_string("'.\n").
% Produce an invalid goal when parsing of an Aditi update fails.
:- pred invalid_aditi_update_goal(string, list(prog_term), hlds_goal_info,
--- modes.m 1999/06/27 01:01:42 1.5
+++ modes.m 1999/07/07 07:56:17
@@ -1066,9 +1116,9 @@
{ GenericCall = class_method(_, _, _, _) },
{ error("modecheck_goal_expr: class_method_call") }
;
- { GenericCall = aditi_builtin(AditiBuiltin, _) },
- modecheck_aditi_builtin(AditiBuiltin, Args0, Modes0, Det,
- Args, ExtraGoals),
+ { GenericCall = aditi_builtin(AditiBuiltin, UpdatedCallId) },
+ modecheck_aditi_builtin(AditiBuiltin, UpdatedCallId,
+ Args0, Modes0, Det, Args, ExtraGoals),
{ Modes = Modes0 },
{ AllArgs0 = Args0 },
{ AllArgs = Args }
@@ -1079,7 +1129,7 @@
InstMap0, Goal),
mode_info_unset_call_context,
- mode_checkpoint(exit, "call").
+ mode_checkpoint(exit, "generic_call").
modecheck_goal_expr(unify(A0, B0, _, UnifyInfo0, UnifyContext), GoalInfo0, Goal)
-->
--- modecheck_call.m 1999/07/05 04:29:21 1.6
+++ modecheck_call.m 1999/07/12 06:17:24
@@ -37,10 +37,10 @@
:- mode modecheck_higher_order_call(in, in, in, out, out, out, out,
mode_info_di, mode_info_uo) is det.
-:- pred modecheck_aditi_builtin(aditi_builtin, list(prog_var), list(mode),
- determinism, list(prog_var), extra_goals,
- mode_info, mode_info).
-:- mode modecheck_aditi_builtin(in, in, in, out, out, out,
+:- pred modecheck_aditi_builtin(aditi_builtin, simple_call_id,
+ list(prog_var), list(mode), determinism,
+ list(prog_var), extra_goals, mode_info, mode_info).
+:- mode modecheck_aditi_builtin(in, in, in, in, out, out, out,
mode_info_di, mode_info_uo) is det.
%
@@ -116,11 +116,22 @@
ExtraGoals = no_extra_goals
).
-modecheck_aditi_builtin(AditiBuiltin, Args0, Modes, Det, Args, ExtraGoals) -->
+modecheck_aditi_builtin(AditiBuiltin, CallId,
+ Args0, Modes, Det, Args, ExtraGoals) -->
{ aditi_builtin_determinism(AditiBuiltin, Det) },
+
+ % `aditi_insert' goals have type_info arguments for each
+ % of the arguments of the tuple to insert added to the
+ % start of the argument list by polymorphism.m.
+ ( { AditiBuiltin = aditi_insert(_) } ->
+ { CallId = _ - _/Arity },
+ { ArgOffset = -Arity }
+ ;
+ { ArgOffset = 0 }
+ ),
+
% The argument modes are set by post_typecheck.m, so all
% that needs to be done here is to check that they match.
modecheck_arg_list(ArgOffset, Args0, Args, Modes, ExtraGoals).
:- pred aditi_builtin_determinism(aditi_builtin, determinism).
--- polymorphism.m 1999/06/27 01:01:42 1.9
+++ polymorphism.m 1999/07/09 04:01:19
@@ -926,9 +998,11 @@
=(PolyInfo),
{ poly_info_get_var_types(PolyInfo, VarTypes) },
- { map__apply_to_list(Args0, VarTypes, Types) },
- polymorphism__make_type_info_vars(Types, ExistQVars,
+ { get_state_args_det(Args0, TupleArgs, _, _) },
+ { map__apply_to_list(TupleArgs, VarTypes, TupleTypes) },
+
+ polymorphism__make_type_info_vars(TupleTypes, ExistQVars,
Context, TypeInfoVars, TypeInfoGoals),
{ list__append(TypeInfoVars, Args0, Args) },
@@ -938,12 +1012,16 @@
{ list__duplicate(NumTypeInfos, InMode, TypeInfoModes) },
{ list__append(TypeInfoModes, Modes0, Modes) },
+ { goal_info_get_nonlocals(GoalInfo0, NonLocals0) },
+ { set__insert_list(NonLocals0, TypeInfoVars, NonLocals) },
+ { goal_info_set_nonlocals(GoalInfo0, NonLocals, GoalInfo) },
+
{ Call = generic_call(GenericCall, Args, Modes, Det)
- GoalInfo },
{ list__append(TypeInfoGoals, [Call], Goals) },
- { conj_list_to_goal(Goals, GoalInfo, Goal) }
+ { conj_list_to_goal(Goals, GoalInfo0, Goal) }
;
- { Goal = GoalExpr0 - GoalInfo }
+ { Goal = GoalExpr0 - GoalInfo0 }
).
polymorphism__process_goal_expr(call(PredId0, ProcId0, ArgVars0,
--- typecheck.m 1999/07/05 01:24:41 1.7
+++ typecheck.m 1999/07/12 06:44:48
@@ -5028,67 +5104,17 @@
PredOrFunc - SymName/Arity, Arities) -->
write_context_and_pred_id(TypeCheckInfo),
{ typecheck_info_get_context(TypeCheckInfo, Context) },
- report_error_num_args(no, Context, yes(PredOrFunc),
- SymName, Arity, Arities).
-
-report_error_num_args(First, Context, MaybePredOrFunc,
- SymName, Arity0, Arities0) -->
prog_out__write_context(Context),
- (
- { First = yes },
- io__write_string("Error: ")
- ;
- { First = no },
- io__write_string(" error: ")
- ),
- io__write_string("wrong number of arguments ("),
-
- % Adjust arities for functions.
- { MaybePredOrFunc = yes(function) ->
- adjust_func_arity(function, Arity0, Arity),
- list__map(
- (pred(OtherArity0::in, OtherArity::out) is det :-
- adjust_func_arity(function,
- OtherArity0, OtherArity)
- ),
- Arities0, Arities)
- ;
- Arity = Arity0,
- Arities = Arities0
- },
-
- io__write_int(Arity),
- io__write_string("; should be "),
- report_error_right_num_args(Arities),
- io__write_string(")\n"),
+ io__write_string(" error: "),
+ report_error_num_args(yes(PredOrFunc), Arity, Arities),
+ io__nl,
prog_out__write_context(Context),
io__write_string(" in call to "),
- (
- { MaybePredOrFunc = yes(PredOrFunc) },
- hlds_out__write_pred_or_func(PredOrFunc),
- io__write_string(" ")
- ;
- { MaybePredOrFunc = no }
- ),
- io__write_string("`"),
+ hlds_out__write_pred_or_func(PredOrFunc),
+ io__write_string(" `"),
prog_out__write_sym_name(SymName),
io__write_string("'.\n").
-:- pred report_error_right_num_args(list(int), io__state, io__state).
-:- mode report_error_right_num_args(in, di, uo) is det.
-
-report_error_right_num_args([]) --> [].
-report_error_right_num_args([Arity | Arities]) -->
- io__write_int(Arity),
- ( { Arities = [] } ->
- []
- ; { Arities = [_] } ->
- io__write_string(" or ")
- ;
- io__write_string(", ")
- ),
- report_error_right_num_args(Arities).
-
:- pred report_error_undef_cons(typecheck_info, cons_id, int, io__state,
io__state).
:- mode report_error_undef_cons(typecheck_info_no_io, in, in, di, uo) is det.
@@ -5210,11 +5236,10 @@
:- mode report_wrong_arity_constructor(in, in, in, in, di, uo) is det.
report_wrong_arity_constructor(Name, Arity, ActualArities, Context) -->
- io__write_string(" error: wrong number of arguments ("),
- io__write_int(Arity),
- io__write_string("; should be "),
- report_error_right_num_args(ActualArities),
- io__write_string(")\n"),
+ io__write_string(" error: "),
+ { MaybePredOrFunc = no },
+ report_error_num_args(MaybePredOrFunc, Arity, ActualArities),
+ io__nl,
prog_out__write_context(Context),
io__write_string(" in use of constructor `"),
prog_out__write_sym_name(Name),
--- unique_modes.m 1999/06/27 01:01:42 1.4
+++ unique_modes.m 1999/07/12 06:07:42
@@ -395,19 +397,32 @@
NeverSucceeds = no
},
{ determinism_to_code_model(Det, CodeModel) },
- unique_modes__check_call_modes(Args, Modes, CodeModel, NeverSucceeds),
+
+ % `aditi_insert' goals have type_info arguments for each
+ % of the arguments of the tuple to insert added to the
+ % start of the argument list by polymorphism.m.
+ { GenericCall = aditi_builtin(aditi_insert(_), _ - _/Arity) ->
+ ArgOffset = -Arity
+ ;
+ ArgOffset = 0
+ },
+
+ unique_modes__check_call_modes(Args, Modes, ArgOffset,
+ CodeModel, NeverSucceeds),
{ Goal = generic_call(GenericCall, Args, Modes, Det) },
mode_info_unset_call_context,
mode_checkpoint(exit, "generic_call").
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/invalid/Mmakefile,v
retrieving revision 1.42
diff -u -u -r1.42 Mmakefile
--- Mmakefile 1999/07/01 08:30:34 1.42
+++ Mmakefile 1999/07/12 05:17:23
@@ -7,6 +7,8 @@
#-----------------------------------------------------------------------------#
SOURCES= \
+ aditi_update_errors.m \
+ aditi_update_mode_errors.m \
any_mode.m \
bigtest.m \
bind_var_errors.m \
@@ -74,6 +76,8 @@
# typeclass_test_8.m (minor formatting error in the output --
# the type class name should be in quotes)
+MCFLAGS-aditi_update_errors = --aditi
+MCFLAGS-aditi_update_mode_errors = --aditi
MCFLAGS-multisoln_func = --infer-types
MCFLAGS-any_mode = --infer-types
MCFLAGS-duplicate_modes = --verbose-error-messages
@@ -110,8 +114,8 @@
# We only need to make the dependencies for test cases consisting of
# multiple modules; currently the following are the only such cases.
-depend: test_nested.depend partial_implied_mode.depend
-
+depend: aditi_update_errors.depend aditi_update_mode_errors.depend \
+ test_nested.depend partial_implied_mode.depend
clean:
rm -f *.err *.err_res
--------------------------------------------------------------------------
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