[m-rev.] for review: fix tests/hard_coded/ho_and_type_spec

Simon Taylor staylr at gmail.com
Tue May 1 13:16:19 AEST 2007


Estimated hours taken: 10
Branches: main

Fix a compiler abort on tests/hard_coded/ho_and_type_spec.
This also fixes problems compiling compiler/mode_robdd.tfeirn.m
and compiler/mode_robdd.implications.m, but the flags to reduce
optimization for those files can't be removed until this change
is installed.

The sequence of events leading to the abort was:
1. higher_order.construct_higher_order_terms builds a construction
unification for a type-info which isn't yet used.
2. quantification works out that the type-info isn't used and
removes it from the instmap_delta.
3. further specialization makes the type-info become used.
4. recompute_instmap_delta doesn't put it back in the instmap_delta.
5. crash.

compiler/mode_util.m:
	Make recompute_instmap_delta recompute the instmap_deltas
	for goals which construct terms of builtin types where
	the constructed variable occurs in the nonlocals but
	not the instmap_delta.

compiler/Mercury.options:
	Document that the workaround for this bug can be removed
	once this change is installed everywhere.


Index: compiler/mode_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_util.m,v
retrieving revision 1.197
diff -u -u -r1.197 mode_util.m
--- compiler/mode_util.m	19 Jan 2007 07:04:22 -0000	1.197
+++ compiler/mode_util.m	28 Apr 2007 02:16:37 -0000
@@ -202,6 +202,7 @@
 
 :- import_module int.
 :- import_module map.
+:- import_module maybe.
 :- import_module pair.
 :- import_module set.
 :- import_module term.
@@ -1322,6 +1323,9 @@
         InstMap, InstMapDelta, RI) :-
     % Deconstructions are the only types of unifications that can require
     % updating of the instmap_delta after simplify.m has been run.
+    % Type specialization may require constructions of type-infos, 
+    % typeclass-infos or predicate constants to be added to the
+    % instmap_delta.
     ModuleInfo = RI ^ module_info,
     (
         Uni = deconstruct(Var, _ConsId, Vars, UniModes, _, _CanCGC)
@@ -1354,10 +1358,62 @@
             ModuleInfo, InstMapDelta),
         UniMode = UniMode0
     ;
+        Uni = construct(Var, ConsId, Args, _, _, _, _),
+        goal_info_get_nonlocals(GoalInfo, NonLocals),
+        set.member(Var, NonLocals),
+        goal_info_get_instmap_delta(GoalInfo, OldInstMapDelta),
+        \+ instmap_delta_search_var(OldInstMapDelta, Var, _),
+        MaybeInst = cons_id_to_shared_inst(ModuleInfo, ConsId, length(Args)),
+        MaybeInst = yes(Inst)
+    ->
+        UniMode = UniMode0,
+        instmap_delta_init_reachable(InstMapDelta0),
+        instmap_delta_set(Var, Inst, InstMapDelta0, InstMapDelta)
+    ;
         goal_info_get_instmap_delta(GoalInfo, InstMapDelta),
         UniMode = UniMode0
     ).
 
+    % For a builtin constructor, return the inst of the constructed term.
+    % Handling user-defined constructors properly would require running
+    % mode analysis again.
+    %
+:- func cons_id_to_shared_inst(module_info, cons_id, int) = maybe(mer_inst).
+
+cons_id_to_shared_inst(_, cons(_, _), _) = no.
+cons_id_to_shared_inst(_, ConsId @ int_const(_), _) =
+            yes(bound(shared, [bound_functor(ConsId, [])])).
+cons_id_to_shared_inst(_, ConsId @ float_const(_), _) =
+            yes(bound(shared, [bound_functor(ConsId, [])])).
+cons_id_to_shared_inst(_, ConsId @ string_const(_), _) =
+            yes(bound(shared, [bound_functor(ConsId, [])])).
+cons_id_to_shared_inst(ModuleInfo, pred_const(PredProcId, _), NumArgs) =
+        yes(ground(shared, higher_order(pred_inst_info(PorF, Modes, Det)))) :-
+    module_info_pred_proc_info(ModuleInfo, unshroud_pred_proc_id(PredProcId),
+        PredInfo, ProcInfo),
+    PorF = pred_info_is_pred_or_func(PredInfo),
+    proc_info_interface_determinism(ProcInfo, Det),
+    proc_info_get_argmodes(ProcInfo, ProcArgModes),
+    ( list.drop(NumArgs, ProcArgModes, Modes0) ->
+        Modes = Modes0
+    ;
+        unexpected(this_file, "list.drop failed in cons_id_to_shared_inst")
+    ).
+cons_id_to_shared_inst(_, type_ctor_info_const(_, _, _), _) =
+            yes(ground(shared, none)).
+cons_id_to_shared_inst(_, base_typeclass_info_const(_, _, _, _), _) =
+            yes(ground(shared, none)).
+cons_id_to_shared_inst(_, type_info_cell_constructor(_), _) =
+            yes(ground(shared, none)).
+cons_id_to_shared_inst(_, typeclass_info_cell_constructor, _) =
+            yes(ground(shared, none)).
+cons_id_to_shared_inst(_, tabling_info_const(_), _) =
+            yes(ground(shared, none)).
+cons_id_to_shared_inst(_, deep_profiling_proc_layout(_), _) =
+            yes(ground(shared, none)).
+cons_id_to_shared_inst(_, table_io_decl(_), _) =
+            yes(ground(shared, none)).
+
 %-----------------------------------------------------------------------------%
 
     % Arguments with final inst `clobbered' are dead, any
Index: compiler/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Mercury.options,v
retrieving revision 1.26
diff -u -u -r1.26 Mercury.options
--- Mercury.options     1 Dec 2006 15:03:48 -0000       1.26
+++ Mercury.options     1 May 2007 03:13:34 -0000
@@ -44,7 +44,9 @@
 
 # Bug workarounds
 
-# This is the same bug as tests/valid/ho_and_type_spec_bug
+# This is the same bug as tests/valid/ho_and_type_spec_bug.
+# The bug has been fixed, but the fix needs to be installed everywhere
+# before these are removed.
 MCFLAGS-mode_robdd.tfeirn = -O3
 MCFLAGS-mode_robdd.implications = -O0
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list