diff: higher_order.m termination fix
Simon TAYLOR
stayl at students.cs.mu.oz.au
Sat Jun 14 13:59:08 AEST 1997
Hi Fergus,
Could you please review this.
Simon.
Estimated hours taken: 0.5
Fix a code size bug in higher_order.m.
compiler/higher_order.m
Don't create specialised versions of specialised versions,
since for some fairly contrived examples of building up
lambda expressions recursively a ridiculously large number
of versions can be created. The only reason the specialisation
was guaranteed to terminate was the size limit on the
predicate for which a version is being created.
Don't fill in the clauses_info for specialised versions, since
it just clutters the HLDS dumps.
Index: higher_order.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/higher_order.m,v
retrieving revision 1.26
diff -u -r1.26 higher_order.m
--- higher_order.m 1997/05/05 11:17:00 1.26
+++ higher_order.m 1997/06/04 04:56:35
@@ -35,7 +35,7 @@
:- import_module type_util, options, prog_data, quantification.
:- import_module mercury_to_mercury.
-:- import_module assoc_list, bool, int, list, map, require, set.
+:- import_module assoc_list, bool, char, int, list, map, require, set.
:- import_module std_util, string, varset, term.
% Iterate collecting requests and processing them until there
@@ -53,7 +53,7 @@
process_requests(Requests0, GoalSizes0, NextHOid0, NextHOid,
NewPreds0, NewPreds, ModuleInfo1, ModuleInfo) -->
- { filter_requests(Requests0, GoalSizes0, Requests) },
+ { filter_requests(ModuleInfo1, Requests0, GoalSizes0, Requests) },
(
{ Requests = [] }
->
@@ -717,17 +717,32 @@
% specialized, as with inlining?
% Nonlocal predicates are filtered out here, since they
% will not have an entry in the goal_sizes.
-:- pred filter_requests(set(request)::in, goal_sizes::in,
+ % Don't create specialized versions of specialized
+ % versions, since for some fairly contrived examples
+ % involving recursively building up lambda expressions
+ % this can create ridiculous numbers of versions.
+:- pred filter_requests(module_info::in, set(request)::in, goal_sizes::in,
list(request)::out) is det.
-filter_requests(Requests0, GoalSizes, Requests) :-
+filter_requests(ModuleInfo, Requests0, GoalSizes, Requests) :-
set__to_sorted_list(Requests0, Requests1),
list__filter(lambda([X::in] is semidet, (
X = request(_, CalledPredProcId, _),
CalledPredProcId = proc(CalledPredId, _),
map__search(GoalSizes, CalledPredId, GoalSize),
max_specialized_goal_size(MaxSize),
- GoalSize =< MaxSize)),
+ GoalSize =< MaxSize,
+ predicate_name(ModuleInfo, CalledPredId, PredName),
+ \+ (
+ % There are probably cleaner ways to check
+ % if this is a specialised version.
+ string__sub_string_search(PredName,
+ "__ho", Index),
+ NumIndex is Index + 4,
+ string__index(PredName, NumIndex, Digit),
+ char__is_digit(Digit)
+ )
+ )),
Requests1, Requests).
:- pred create_new_preds(list(request)::in, new_preds::in, new_preds::out,
@@ -814,7 +829,6 @@
pred_info_typevarset(PredInfo0, TypeVars),
remove_listof_higher_order_args(Types0, 1, HOArgs, Types),
pred_info_context(PredInfo0, Context),
- pred_info_clauses_info(PredInfo0, ClausesInfo),
(
pred_info_is_inlined(PredInfo0)
->
@@ -823,9 +837,14 @@
Inline = no
),
pred_info_get_goal_type(PredInfo0, GoalType),
- % *** This will need to be fixed when the condition
- % field of the pred_info becomes used
Name = qualified(PredModule, PredName),
+ varset__init(EmptyVarSet),
+ map__init(EmptyVarTypes),
+
+ % This isn't looked at after here, and just clutters up
+ % hlds dumps if it's filled in.
+ ClausesInfo = clauses_info(EmptyVarSet, EmptyVarTypes,
+ EmptyVarTypes, [], []),
pred_info_init(PredModule, Name, Arity, Tvars,
Types, true, Context, ClausesInfo, local, Inline, GoalType,
PredOrFunc, PredInfo1),
More information about the developers
mailing list