[m-rev.] diff: fix for bug #48

Mark Brown mark at csse.unimelb.edu.au
Wed Mar 26 12:38:23 AEDT 2008


Hi,

This change addresses the problem with compiling analysis.m.  However, a
couple of people from the G12 group have reported similar looking errors,
and this change does not fix those.  There may be more than one bug
involved, so I'm going to commit this before investigating further.
I'll back this change out if we find that it is wrong.

Note that bootchecks in asm_fast.gc.decldebug still segfault in stage 3,
as they were doing before this change.

Cheers,
Mark.

Estimated hours taken: 20
Branches: main

Fix a failure to compile analysis.m in grade asm_fast.gc.decldebug.  The
problem was that common.m would leave references to type-info variables
that are assigned (i.e., introduced by common.m) rather than the type-infos
that come from constructions, deconstructions or procedure calls.  Later
on, excess-assignment removal may leave these as dangling references.

The fix is to always ensure that we refer to the original type-info, not
the assigned one.

compiler/common.m:
	When generating an assignment, first apply substitutions to the
	RttiVarMaps which eliminate the "To" variable in favor of the
	"From" variable.  Then duplicate the information for the "To"
	variable.

compiler/simplify.m:
	Export a procedure to perform the above steps on a simplify_info.

compiler/hlds_rtti.m:
	Make use of the prog_var_renaming type.

compiler/Mercury.options:
	Add a note that the workaround can be removed once the compiler
	is installed.

Index: compiler/Mercury.options
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Mercury.options,v
retrieving revision 1.36
diff -u -r1.36 Mercury.options
--- compiler/Mercury.options	28 Feb 2008 00:47:24 -0000	1.36
+++ compiler/Mercury.options	26 Mar 2008 01:30:50 -0000
@@ -52,6 +52,8 @@
 # Bug workarounds
 
 # This works around bug 48 in Mantis.
+# (This has been fixed, and the workaround can be removed once new compilers
+# have been installed.)
 MCFLAGS-analysis = --no-common-struct
 
 # XXX work around a bug that sometimes appears at -O4 and above.
Index: compiler/common.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/common.m,v
retrieving revision 1.105
diff -u -r1.105 common.m
--- compiler/common.m	28 Feb 2008 06:08:29 -0000	1.105
+++ compiler/common.m	26 Mar 2008 01:30:50 -0000
@@ -770,7 +770,7 @@
     is det.
 
 generate_assign(ToVar, FromVar, UniMode, _, Goal, !Info) :-
-    apply_induced_tsubst(ToVar, FromVar, !Info),
+    apply_induced_substitutions(ToVar, FromVar, !Info),
     simplify_info_get_var_types(!.Info, VarTypes),
     map.lookup(VarTypes, ToVar, ToVarType),
     map.lookup(VarTypes, FromVar, FromVarType),
@@ -842,15 +842,20 @@
     % rtti_varmaps.  This allows us to avoid an unsafe cast, and also may
     % allow more opportunities for simplification.
     %
+    % If we do need to apply a type substitution, then we also apply the
+    % substituion ToVar -> FromVar to the RttiVarMaps, then duplicate
+    % FromVar's information for ToVar.  This ensures we always refer to the
+    % "original" variables, not the copies created by generate_assign.
+    %
     % Note that this relies on the assignments for type_infos and
     % typeclass_infos to be generated before other arguments with these
     % existential types are processed.  In other words, the arguments of
     % calls and deconstructions must be processed in left to right order.
     %
-:- pred apply_induced_tsubst(prog_var::in, prog_var::in, simplify_info::in,
-    simplify_info::out) is det.
+:- pred apply_induced_substitutions(prog_var::in, prog_var::in,
+    simplify_info::in, simplify_info::out) is det.
 
-apply_induced_tsubst(ToVar, FromVar, !Info) :-
+apply_induced_substitutions(ToVar, FromVar, !Info) :-
     simplify_info_get_rtti_varmaps(!.Info, RttiVarMaps0),
     rtti_varmaps_var_info(RttiVarMaps0, FromVar, FromVarRttiInfo),
     rtti_varmaps_var_info(RttiVarMaps0, ToVar, ToVarRttiInfo),
@@ -858,7 +863,8 @@
         ( map.is_empty(TSubst) ->
             true
         ;
-            simplify_info_apply_type_substitution(TSubst, !Info)
+            simplify_info_apply_substitutions_and_duplicate(ToVar, FromVar,
+                TSubst, !Info)
         )
     ;
         % Update the rtti_varmaps with new information if only one of the
@@ -902,14 +908,13 @@
     (
         FromVarRttiInfo = type_info_var(FromVarTypeInfoType),
         ToVarRttiInfo = type_info_var(ToVarTypeInfoType),
-        type_unify(FromVarTypeInfoType, ToVarTypeInfoType, [],
-            map.init, TSubst)
+        type_list_subsumes([ToVarTypeInfoType], [FromVarTypeInfoType], TSubst)
     ;
         FromVarRttiInfo = typeclass_info_var(FromVarConstraint),
         ToVarRttiInfo = typeclass_info_var(ToVarConstraint),
         FromVarConstraint = constraint(Name, FromArgs),
         ToVarConstraint = constraint(Name, ToArgs),
-        type_unify_list(FromArgs, ToArgs, [], map.init, TSubst)
+        type_list_subsumes(ToArgs, FromArgs, TSubst)
     ;
         FromVarRttiInfo = non_rtti_var,
         ToVarRttiInfo = non_rtti_var,
Index: compiler/hlds_rtti.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_rtti.m,v
retrieving revision 1.13
diff -u -r1.13 hlds_rtti.m
--- compiler/hlds_rtti.m	23 Nov 2007 07:35:06 -0000	1.13
+++ compiler/hlds_rtti.m	26 Mar 2008 01:30:50 -0000
@@ -25,7 +25,6 @@
 :- import_module assoc_list.
 :- import_module bool.
 :- import_module list.
-:- import_module map.
 :- import_module set.
 
 %-----------------------------------------------------------------------------%
@@ -281,8 +280,7 @@
     % is applied to all prog_vars.
     %
 :- pred apply_substitutions_to_rtti_varmaps(tvar_renaming::in, tsubst::in,
-    map(prog_var, prog_var)::in, rtti_varmaps::in, rtti_varmaps::out)
-    is det.
+    prog_var_renaming::in, rtti_varmaps::in, rtti_varmaps::out) is det.
 
     % rtti_varmaps_transform_types(Pred, !RttiVarMaps)
     %
@@ -325,6 +323,7 @@
 :- import_module parse_tree.prog_type.
 :- import_module parse_tree.prog_type_subst.
 
+:- import_module map.
 :- import_module pair.
 :- import_module solutions.
 :- import_module svmap.
@@ -570,7 +569,7 @@
         !:RttiVarMaps = rtti_varmaps(TCIMap, TIMap, TypeMap, ConstraintMap)
     ).
 
-:- pred apply_subst_to_prog_var(map(prog_var, prog_var)::in,
+:- pred apply_subst_to_prog_var(prog_var_renaming::in,
     prog_var::in, prog_var::out) is det.
 
 apply_subst_to_prog_var(Subst, Var0, Var) :-
@@ -581,7 +580,7 @@
     ).
 
 :- pred apply_substs_to_tci_map(tvar_renaming::in, tsubst::in,
-    map(prog_var, prog_var)::in, prog_constraint::in, prog_var::in,
+    prog_var_renaming::in, prog_constraint::in, prog_var::in,
     typeclass_info_varmap::in, typeclass_info_varmap::out) is det.
 
 apply_substs_to_tci_map(TRenaming, TSubst, Subst, Constraint0, Var0, !Map) :-
@@ -599,7 +598,7 @@
     % it maps to a type, we remove it from the map.
     %
 :- pred apply_substs_to_ti_map(tvar_renaming::in, tsubst::in,
-    map(prog_var, prog_var)::in, tvar::in, type_info_locn::in,
+    prog_var_renaming::in, tvar::in, type_info_locn::in,
     type_info_varmap::in, type_info_varmap::out) is det.
 
 apply_substs_to_ti_map(TRenaming, TSubst, Subst, TVar, Locn, !Map) :-
@@ -629,7 +628,7 @@
     ).
 
 :- pred apply_substs_to_type_map(tvar_renaming::in, tsubst::in,
-    map(prog_var, prog_var)::in, prog_var::in, mer_type::in,
+    prog_var_renaming::in, prog_var::in, mer_type::in,
     type_info_type_map::in, type_info_type_map::out) is det.
 
 apply_substs_to_type_map(TRenaming, TSubst, Subst, Var0, Type0, !Map) :-
@@ -647,7 +646,7 @@
     ).
 
 :- pred apply_substs_to_constraint_map(tvar_renaming::in, tsubst::in,
-    map(prog_var, prog_var)::in, prog_var::in, prog_constraint::in,
+    prog_var_renaming::in, prog_var::in, prog_constraint::in,
     typeclass_info_constraint_map::in, typeclass_info_constraint_map::out)
     is det.
 
Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.228
diff -u -r1.228 simplify.m
--- compiler/simplify.m	27 Feb 2008 07:23:14 -0000	1.228
+++ compiler/simplify.m	26 Mar 2008 01:30:50 -0000
@@ -3515,8 +3515,8 @@
 :- pred simplify_info_incr_cost_delta(int::in,
     simplify_info::in, simplify_info::out) is det.
 
-:- pred simplify_info_apply_type_substitution(tsubst::in,
-    simplify_info::in, simplify_info::out) is det.
+:- pred simplify_info_apply_substitutions_and_duplicate(prog_var::in,
+    prog_var::in, tsubst::in, simplify_info::in, simplify_info::out) is det.
 
 :- implementation.
 
@@ -3667,15 +3667,18 @@
     det_info_set_module_info(ModuleInfo, DetInfo0, DetInfo),
     simplify_info_set_det_info(DetInfo, !Info).
 
-simplify_info_apply_type_substitution(TSubst, !Info) :-
+simplify_info_apply_substitutions_and_duplicate(ToVar, FromVar, TSubst,
+        !Info) :-
     simplify_info_get_var_types(!.Info, VarTypes0),
     simplify_info_get_rtti_varmaps(!.Info, RttiVarMaps0),
     ApplyTSubst = (pred(_::in, T0::in, T::out) is det :-
             apply_rec_subst_to_type(TSubst, T0, T)
         ),
     map.map_values(ApplyTSubst, VarTypes0, VarTypes),
-    apply_substitutions_to_rtti_varmaps(map.init, TSubst, map.init,
-        RttiVarMaps0, RttiVarMaps),
+    map.det_insert(map.init, ToVar, FromVar, Renaming),
+    apply_substitutions_to_rtti_varmaps(map.init, TSubst, Renaming,
+        RttiVarMaps0, RttiVarMaps1),
+    rtti_var_info_duplicate(FromVar, ToVar, RttiVarMaps1, RttiVarMaps),
     simplify_info_set_var_types(VarTypes, !Info),
     simplify_info_set_rtti_varmaps(RttiVarMaps, !Info).
 
--------------------------------------------------------------------------
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