[m-rev.] for review: change termination2_info pragmas
Julien Fischer
juliensf at cs.mu.OZ.AU
Wed Jul 13 18:56:58 AEST 2005
For review by anyone.
The expected outputs in tests/term will also need to be updated
but I'll do that as a separate change.
Estimated hours taken: 2
Branches: main
Do not base the variable ids in the termination2_info pragmas
directly on variable ids from the HLDS. This makes the
termination2_info pragmas smaller and prevents the test
cases in tests/term failing in the .debug grades.
The identity of variables in the termination2_info pragmas
is now based upon the order of the procedure arguments.
compiler/term_constr_initial.m:
Convert the new form of the pragma into argument size
information.
compiler/term_constr_main.m:
Write out the new form of the termination2_info pragma
to the optimization interfaces.
s/pramga/pragma
Make some unnecessarily exported procedures private.
compiler/prog_data.m:
Remove the headvar_ids field from the termination2_info
pragma.
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/module_qual.m:
compiler/modules.m:
compiler/prog_io_pragma.m:
compiler/recompilation.version.m:
Minor changes to conform to the above.
Julien.
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.514
diff -u -r1.514 make_hlds.m
--- compiler/make_hlds.m 31 May 2005 06:55:28 -0000 1.514
+++ compiler/make_hlds.m 11 Jul 2005 09:20:28 -0000
@@ -871,7 +871,7 @@
Pragma = termination_info(_, _, _, _, _)
;
% As for termination_info pragmas
- Pragma = termination2_info(_, _, _, _, _, _, _)
+ Pragma = termination2_info(_, _, _, _, _, _)
;
Pragma = terminates(Name, Arity),
add_pred_marker("terminates", Name, Arity, ImportStatus, Context,
@@ -1134,11 +1134,11 @@
!ModuleInfo, !IO)
;
Pragma = termination2_info(PredOrFunc, SymName, ModeList,
- HeadVarIds, MaybeSuccessArgSizeInfo,
- MaybeFailureArgSizeInfo, MaybeTerminationInfo)
+ MaybeSuccessArgSizeInfo, MaybeFailureArgSizeInfo,
+ MaybeTerminationInfo)
->
add_pragma_termination2_info(PredOrFunc, SymName, ModeList,
- HeadVarIds, MaybeSuccessArgSizeInfo,
+ MaybeSuccessArgSizeInfo,
MaybeFailureArgSizeInfo, MaybeTerminationInfo, Context,
!ModuleInfo, !IO)
;
@@ -2058,11 +2058,11 @@
%-----------------------------------------------------------------------------%
:- pred add_pragma_termination2_info(pred_or_func::in, sym_name::in,
- list(mode)::in, list(int)::in, maybe(pragma_constr_arg_size_info)::in,
+ list(mode)::in, maybe(pragma_constr_arg_size_info)::in,
maybe(pragma_constr_arg_size_info)::in,
maybe(pragma_termination_info)::in, prog_context::in, module_info::in,
module_info::out, io::di, io::uo) is det.
-add_pragma_termination2_info(PredOrFunc, SymName, ModeList, HeadVarIds,
+add_pragma_termination2_info(PredOrFunc, SymName, ModeList,
MaybePragmaSuccessArgSizeInfo, MaybePragmaFailureArgSizeInfo,
MaybePragmaTerminationInfo,
Context, !ModuleInfo, !IO) :-
@@ -2090,8 +2090,6 @@
some [!TermInfo] (
proc_info_get_termination2_info(ProcInfo0, !:TermInfo),
- !:TermInfo = !.TermInfo ^ import_headvarids
- := yes(HeadVarIds),
!:TermInfo = !.TermInfo ^ import_success :=
MaybePragmaSuccessArgSizeInfo,
!:TermInfo = !.TermInfo ^ import_failure :=
Index: compiler/mercury_to_mercury.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_to_mercury.m,v
retrieving revision 1.259
diff -u -r1.259 mercury_to_mercury.m
--- compiler/mercury_to_mercury.m 23 May 2005 03:15:37 -0000 1.259
+++ compiler/mercury_to_mercury.m 12 Jul 2005 07:55:48 -0000
@@ -644,10 +644,9 @@
Context, MaybePragmaArgSizeInfo, MaybePragmaTerminationInfo, !IO)
;
Pragma = termination2_info(PredOrFunc, PredName,
- ModeList, HeadVarIds, SuccessInfo, FailureInfo,
- MaybeTermination),
+ ModeList, SuccessInfo, FailureInfo, MaybeTermination),
write_pragma_termination2_info(PredOrFunc, PredName,
- ModeList, HeadVarIds, SuccessInfo, FailureInfo,
+ ModeList, SuccessInfo, FailureInfo,
MaybeTermination, Context, !IO)
;
Pragma = terminates(Pred, Arity),
@@ -4165,12 +4164,12 @@
%
:- pred write_pragma_termination2_info(pred_or_func::in, sym_name::in,
- list(mode)::in, list(int)::in, maybe(pragma_constr_arg_size_info)::in,
+ list(mode)::in, maybe(pragma_constr_arg_size_info)::in,
maybe(pragma_constr_arg_size_info)::in,
maybe(pragma_termination_info)::in, prog_context::in,
io::di, io::uo) is det.
-write_pragma_termination2_info(PredOrFunc, PredName, ModeList, HeadVarIds,
+write_pragma_termination2_info(PredOrFunc, PredName, ModeList,
MaybeSuccess, MaybeFailure, MaybeTermination, Context,
!IO) :-
io.write_string(":- pragma termination2_info(", !IO),
@@ -4185,21 +4184,12 @@
FuncModeList, RetMode, no, Context, !IO)
),
io.write_string(", ", !IO),
- write_head_var_ids(HeadVarIds, !IO),
- io.write_string(", ", !IO),
write_maybe_pragma_constr_arg_size_info(MaybeSuccess, !IO),
io.write_string(", ", !IO),
write_maybe_pragma_constr_arg_size_info(MaybeFailure, !IO),
io.write_string(", ", !IO),
write_maybe_pragma_termination_info(MaybeTermination, !IO),
io.write_string(").\n", !IO).
-
-:- pred write_head_var_ids(list(int)::in, io::di, io::uo) is det.
-
-write_head_var_ids(VarIds, !IO) :-
- io.write_char('[', !IO),
- io.write_list(VarIds, ", ", io.write_int, !IO),
- io.write_char(']', !IO).
:- pred write_maybe_pragma_constr_arg_size_info(
maybe(pragma_constr_arg_size_info)::in, io::di, io::uo) is det.
Index: compiler/module_qual.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/module_qual.m,v
retrieving revision 1.107
diff -u -r1.107 module_qual.m
--- compiler/module_qual.m 25 May 2005 03:55:46 -0000 1.107
+++ compiler/module_qual.m 12 Jul 2005 07:56:32 -0000
@@ -1093,9 +1093,9 @@
termination_info(PredOrFunc, SymName, ModeList, Args, Term),
!Info, !IO) :-
qualify_mode_list(ModeList0, ModeList, !Info, !IO).
-qualify_pragma(termination2_info(PredOrFunc, SymName, ModeList0, HeadVars,
+qualify_pragma(termination2_info(PredOrFunc, SymName, ModeList0,
SuccessArgs, FailureArgs, Term),
- termination2_info(PredOrFunc, SymName, ModeList, HeadVars,
+ termination2_info(PredOrFunc, SymName, ModeList,
SuccessArgs, FailureArgs, Term),
!Info, !IO) :-
qualify_mode_list(ModeList0, ModeList, !Info, !IO).
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.334
diff -u -r1.334 modules.m
--- compiler/modules.m 31 May 2005 06:55:31 -0000 1.334
+++ compiler/modules.m 12 Jul 2005 07:57:36 -0000
@@ -2036,7 +2036,7 @@
pragma_allowed_in_interface(exceptions(_, _, _, _, _), no).
pragma_allowed_in_interface(type_spec(_, _, _, _, _, _, _, _), yes).
pragma_allowed_in_interface(termination_info(_, _, _, _, _), yes).
-pragma_allowed_in_interface(termination2_info(_,_,_, _, _, _, _), yes).
+pragma_allowed_in_interface(termination2_info(_,_, _, _, _, _), yes).
pragma_allowed_in_interface(terminates(_, _), yes).
pragma_allowed_in_interface(does_not_terminate(_, _), yes).
pragma_allowed_in_interface(check_termination(_, _), yes).
@@ -7611,7 +7611,7 @@
; Pragma = supp_magic(_, _), Reorderable = no
; Pragma = tabled(_, _, _, _, _), Reorderable = yes
; Pragma = terminates(_, _), Reorderable = yes
- ; Pragma = termination2_info(_, _, _, _, _, _, _), Reorderable = no
+ ; Pragma = termination2_info(_, _, _, _, _, _), Reorderable = no
; Pragma = termination_info(_, _, _, _, _), Reorderable = yes
; Pragma = type_spec(_, _, _, _, _, _, _, _), Reorderable = yes
; Pragma = unused_args(_, _, _, _, _), Reorderable = yes
@@ -7696,7 +7696,7 @@
; Pragma = supp_magic(_, _), Reorderable = no
; Pragma = tabled(_, _, _, _, _), Reorderable = yes
; Pragma = terminates(_, _), Reorderable = yes
- ; Pragma = termination2_info(_, _, _, _, _, _, _), Reorderable = no
+ ; Pragma = termination2_info( _, _, _, _, _, _), Reorderable = no
; Pragma = termination_info(_, _, _, _, _), Reorderable = yes
; Pragma = type_spec(_, _, _, _, _, _, _, _), Reorderable = yes
; Pragma = unused_args(_, _, _, _, _), Reorderable = yes
Index: compiler/prog_data.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_data.m,v
retrieving revision 1.128
diff -u -r1.128 prog_data.m
--- compiler/prog_data.m 7 Jun 2005 02:59:56 -0000 1.128
+++ compiler/prog_data.m 11 Jul 2005 09:10:33 -0000
@@ -502,7 +502,6 @@
pred_or_func,
sym_name,
list(mode),
- list(int),
maybe(pragma_constr_arg_size_info),
maybe(pragma_constr_arg_size_info),
maybe(pragma_termination_info)
Index: compiler/prog_io_pragma.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io_pragma.m,v
retrieving revision 1.83
diff -u -r1.83 prog_io_pragma.m
--- compiler/prog_io_pragma.m 7 Jun 2005 02:59:56 -0000 1.83
+++ compiler/prog_io_pragma.m 12 Jul 2005 07:59:35 -0000
@@ -1135,7 +1135,6 @@
(
PragmaTerms = [
PredAndModesTerm0,
- HeadVarListTerm,
SuccessArgSizeTerm,
FailureArgSizeTerm,
TerminationTerm
@@ -1144,8 +1143,6 @@
ErrorTerm, "`:- pragma termination2_info' declaration",
NameAndModesResult),
NameAndModesResult = ok(PredName - PredOrFunc, ModeList),
- convert_int_list(HeadVarListTerm, HeadVarListResult),
- HeadVarListResult = ok(HeadVars),
parse_arg_size_constraints(SuccessArgSizeTerm, SuccessArgSizeResult),
SuccessArgSizeResult = ok(SuccessArgSizeInfo),
parse_arg_size_constraints(FailureArgSizeTerm, FailureArgSizeResult),
@@ -1162,8 +1159,8 @@
MaybeTerminationInfo = yes(cannot_loop(unit))
),
Result0 = ok(pragma(termination2_info(PredOrFunc, PredName,
- ModeList, HeadVars, SuccessArgSizeInfo,
- FailureArgSizeInfo, MaybeTerminationInfo)))
+ ModeList, SuccessArgSizeInfo, FailureArgSizeInfo,
+ MaybeTerminationInfo)))
->
Result = Result0
;
Index: compiler/recompilation.version.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/recompilation.version.m,v
retrieving revision 1.19
diff -u -r1.19 recompilation.version.m
--- compiler/recompilation.version.m 23 May 2005 03:15:40 -0000 1.19
+++ compiler/recompilation.version.m 12 Jul 2005 08:00:16 -0000
@@ -624,7 +624,7 @@
is_pred_pragma(termination_info(PredOrFunc, Name, Modes, _, _),
yes(yes(PredOrFunc) - Name / Arity)) :-
adjust_func_arity(PredOrFunc, Arity, list__length(Modes)).
-is_pred_pragma(termination2_info(PredOrFunc, Name, Modes, _, _, _, _),
+is_pred_pragma(termination2_info(PredOrFunc, Name, Modes, _, _, _),
yes(yes(PredOrFunc) - Name / Arity)) :-
adjust_func_arity(PredOrFunc, Arity, list__length(Modes)).
is_pred_pragma(terminates(Name, Arity), yes(no - Name / Arity)).
Index: compiler/term_constr_initial.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_constr_initial.m,v
retrieving revision 1.1
diff -u -r1.1 term_constr_initial.m
--- compiler/term_constr_initial.m 7 Apr 2005 06:32:15 -0000 1.1
+++ compiler/term_constr_initial.m 12 Jul 2005 08:08:36 -0000
@@ -192,9 +192,11 @@
some [!ProcInfo] (
!:ProcInfo = !.ProcTable ^ det_elem(ProcId),
proc_info_get_termination2_info(!.ProcInfo, TermInfo0),
- ( TermInfo0 ^ import_headvarids = yes(HeadVarIds) ->
- process_imported_term_info(HeadVarIds, !.ProcInfo,
- TermInfo0, TermInfo),
+ (
+ % Check that there is something to import.
+ TermInfo0 ^ import_success = yes(_)
+ ->
+ process_imported_term_info(!.ProcInfo, TermInfo0, TermInfo),
proc_info_set_termination2_info(TermInfo, !ProcInfo),
svmap.det_update(ProcId, !.ProcInfo, !ProcTable)
;
@@ -202,12 +204,14 @@
)
).
-:- pred process_imported_term_info(list(int)::in, proc_info::in,
+:- pred process_imported_term_info(proc_info::in,
termination2_info::in, termination2_info::out) is det.
-process_imported_term_info(HeadVarIds, ProcInfo, !TermInfo) :-
+process_imported_term_info(ProcInfo, !TermInfo) :-
proc_info_headvars(ProcInfo, HeadVars),
make_size_var_map(HeadVars, _SizeVarset, SizeVarMap),
+ list.length(HeadVars, NumHeadVars),
+ HeadVarIds = 0 .. NumHeadVars - 1,
map.from_corresponding_lists(HeadVarIds, HeadVars, IdsToProgVars),
create_substitution_map(HeadVarIds, IdsToProgVars, SizeVarMap, SubstMap),
create_arg_size_polyhedron(SubstMap, !.TermInfo ^ import_success,
@@ -219,7 +223,9 @@
!:TermInfo = !.TermInfo ^ head_vars := SizeVars,
!:TermInfo = !.TermInfo ^ success_constrs := MaybeSuccessPoly,
!:TermInfo = !.TermInfo ^ failure_constrs := MaybeFailurePoly,
- !:TermInfo = !.TermInfo ^ import_headvarids := no,
+ %
+ % We don't use these fields after this point.
+ %
!:TermInfo = !.TermInfo ^ import_success := no,
!:TermInfo = !.TermInfo ^ import_failure := no.
Index: compiler/term_constr_main.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_constr_main.m,v
retrieving revision 1.3
diff -u -r1.3 term_constr_main.m
--- compiler/term_constr_main.m 7 Jun 2005 11:30:29 -0000 1.3
+++ compiler/term_constr_main.m 13 Jul 2005 08:06:29 -0000
@@ -89,7 +89,7 @@
%----------------------------------------------------------------------------%
%
-% Types that define termination information about procedures.
+% Types that define termination information about procedures
%
% This type is the interargument size relationships between
@@ -109,7 +109,7 @@
:- type term_reason
---> builtin % procedure was a builtin.
- ; pragma_supplied % procedure has pramga terminates decl.
+ ; pragma_supplied % procedure has pragma terminates decl.
; foreign_supplied % procedure has foreign code attribute.
@@ -131,7 +131,7 @@
%----------------------------------------------------------------------------%
%
-% The `termination2_info' structure.
+% The 'termination2_info' structure
%
% All the information needed by the termination analysis is stored in
@@ -143,7 +143,6 @@
:- func term2_info_init = termination2_info.
:- func termination2_info ^ size_var_map = size_var_map.
-:- func termination2_info ^ import_headvarids = maybe(list(int)).
:- func termination2_info ^ import_success =
maybe(pragma_constr_arg_size_info).
:- func termination2_info ^ import_failure =
@@ -156,8 +155,6 @@
:- func termination2_info ^ head_vars = list(size_var).
:- func termination2_info ^ size_var_map := size_var_map = termination2_info.
-:- func termination2_info ^ import_headvarids := maybe(list(int)) =
- termination2_info.
:- func termination2_info ^ import_success :=
maybe(pragma_constr_arg_size_info) = termination2_info.
:- func termination2_info ^ import_failure :=
@@ -177,7 +174,7 @@
%----------------------------------------------------------------------------%
%
-% Termination analysis.
+% Termination analysis
%
% Perform termination analysis on a module.
@@ -185,12 +182,6 @@
:- pred term_constr_main.pass(module_info::in, module_info::out,
io::di, io::uo) is det.
-:- pred term_constr_main.output_maybe_constr_arg_size_info(
- maybe(constr_arg_size_info)::in, io::di, io::uo) is det.
-
-:- pred term_constr_main.output_maybe_termination2_info(
- maybe(constr_termination_info)::in, io::di, io::uo) is det.
-
% Write out a termination2_info pragma for the predicate if:
% - it is exported.
% - it is not compiler generated.
@@ -252,7 +243,7 @@
%------------------------------------------------------------------------------%
%
-% The termination2_info structure.
+% The 'termination2_info' structure
%
:- type termination2_info
@@ -267,9 +258,8 @@
% the initial pass, for procedures in the module we are
% analysing, pass 1 sets it.
- import_headvarids :: maybe(list(int)),
- import_success :: maybe(pragma_constr_arg_size_info),
- import_failure :: maybe(pragma_constr_arg_size_info),
+ import_success :: maybe(pragma_constr_arg_size_info),
+ import_failure :: maybe(pragma_constr_arg_size_info),
% Arg size info. imported from another module via a
% `.opt' or `.trans_opt' file. Pass 0 needs to convert
% these to the proper form. These particular fields are
@@ -297,11 +287,11 @@
% proc. Set by term_constr_build.m.
).
-term2_info_init = term2_info(map.init, [], no, no, no, no, no, no, no, no).
+term2_info_init = term2_info(map.init, [], no, no, no, no, no, no, no).
%----------------------------------------------------------------------------%
%
-% Main pass.
+% Main pass
%
term_constr_main.pass(!ModuleInfo, !IO) :-
@@ -357,7 +347,7 @@
%----------------------------------------------------------------------------%
%
-% Analyse a single SCC.
+% Analyse a single SCC
%
% Analyse a single SCC of the call graph. This will require results
@@ -470,7 +460,7 @@
%------------------------------------------------------------------------------%
%
-% Procedures for storing termination2_info in the HLDS.
+% Procedures for storing 'termination2_info' in the HLDS
%
:- pred set_termination_info_for_procs(list(pred_proc_id)::in,
@@ -492,7 +482,7 @@
%-----------------------------------------------------------------------------%
%
-% Predicates for writing optimization interfaces.
+% Predicates for writing optimization interfaces
%
:- pred maybe_make_optimization_interface(module_info::in, io::di, io::uo)
@@ -594,7 +584,7 @@
%----------------------------------------------------------------------------%
%
-% Predicates for writing termination2_info pragmas.
+% Predicates for writing 'termination2_info' pragmas
%
% NOTE: if these predicates are changed then prog_io_pragma.m must
@@ -615,29 +605,27 @@
mercury_output_func_mode_subdecl(varset.init, SymName,
FuncModeList, RetMode, no, Context, !IO)
),
+
+ list.length(HeadVars, NumHeadVars),
+ HeadVarIds = 0 .. NumHeadVars - 1,
+ map.det_insert_from_corresponding_lists(map.init, HeadVars,
+ HeadVarIds, VarToVarIdMap),
+
io.write_string(", ", !IO),
- output_headvars(HeadVars, !IO),
- io.write_string(", ", !IO),
- output_maybe_constr_arg_size_info(MaybeSuccess, !IO),
+ output_maybe_constr_arg_size_info(VarToVarIdMap, MaybeSuccess,
+ !IO),
io.write_string(", ", !IO),
- output_maybe_constr_arg_size_info(MaybeFailure, !IO),
+ output_maybe_constr_arg_size_info(VarToVarIdMap, MaybeFailure,
+ !IO),
io.write_string(", ", !IO),
output_maybe_termination2_info(MaybeTermination, !IO),
io.write_string(").\n", !IO).
-:- pred output_headvars(size_vars::in, io::di, io::uo) is det.
-
-output_headvars(Vars, !IO) :-
- io.write_char('[', !IO),
- io.write_list(Vars, ", ", output_headvar, !IO),
- io.write_char(']', !IO).
-
-:- pred output_headvar(size_var::in, io::di, io::uo) is det.
-
-output_headvar(Var, !IO) :-
- io.write_int(term.var_to_int(Var), !IO).
+:- pred output_maybe_constr_arg_size_info(map(size_var, int)::in,
+ maybe(constr_arg_size_info)::in, io::di, io::uo) is det.
-output_maybe_constr_arg_size_info(MaybeArgSizeConstrs, !IO) :-
+output_maybe_constr_arg_size_info(VarToVarIdMap,
+ MaybeArgSizeConstrs, !IO) :-
(
MaybeArgSizeConstrs = no,
io.write_string("not_set", !IO)
@@ -647,11 +635,14 @@
Constraints0 = polyhedron.non_false_constraints(Polyhedron),
Constraints1 = list.filter(isnt(nonneg_constr), Constraints0),
Constraints = list.sort(Constraints1),
- OutputVar = (func(Var) = int_to_string(term.var_to_int(Var))),
+ OutputVar = (func(Var) = int_to_string(VarToVarIdMap ^ det_elem(Var))),
lp_rational.output_constraints(OutputVar, Constraints, !IO),
io.write_char(')', !IO)
).
+:- pred output_maybe_termination2_info(maybe(constr_termination_info)::in,
+ io::di, io::uo) is det.
+
output_maybe_termination2_info(MaybeConstrTermInfo, !IO) :-
(
MaybeConstrTermInfo = no,
@@ -666,7 +657,7 @@
%----------------------------------------------------------------------------%
%
-% Utility predicates.
+% Utility predicates
%
% These test whether various fields in the termination2_info struct have
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list