[m-rev.] diff: expand equiv. types in constraint_store attributes (bug #190, cont.)

Julien Fischer juliensf at csse.unimelb.edu.au
Fri Mar 18 14:38:09 AEDT 2011


Branches: main, 11.01

Fix another aspect of bug #190: equivalence types in solver type
constraint_store attributes were not being expanded.

compiler/equiv_type.m:
 	Expand equivalence types in solver type constraint_store
 	attributes.

tests/valid/bug190.m:
 	Extend this test case to check that the above occurs.

Julien.

Index: compiler/equiv_type.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/equiv_type.m,v
retrieving revision 1.86
diff -u -r1.86 equiv_type.m
--- compiler/equiv_type.m	15 Dec 2010 06:29:34 -0000	1.86
+++ compiler/equiv_type.m	18 Mar 2011 03:12:35 -0000
@@ -412,16 +412,16 @@
      maybe(recompilation_info)::in, maybe(recompilation_info)::out,
      used_modules::in, used_modules::out, list(error_spec)::out) is det.

-replace_in_type_defn_info(ModuleName, Location, EqvMap, _EqvInstMap,
+replace_in_type_defn_info(ModuleName, Location, EqvMap, EqvInstMap,
          Info0, Info, !RecompInfo, !UsedModules, Specs) :-
      Info0 = item_type_defn_info(VarSet0, SymName, TArgs, TypeDefn0, Cond,
          Context, SeqNum),
      list.length(TArgs, Arity),
      maybe_start_recording_expanded_items(ModuleName, SymName, !.RecompInfo,
          UsedTypeCtors0),
-    replace_in_type_defn(Location, EqvMap, type_ctor(SymName, Arity),
-        TypeDefn0, TypeDefn, ContainsCirc, VarSet0, VarSet,
-        UsedTypeCtors0, UsedTypeCtors, !UsedModules),
+    replace_in_type_defn(Location, EqvMap, EqvInstMap,
+        type_ctor(SymName, Arity), TypeDefn0, TypeDefn, ContainsCirc,
+        VarSet0, VarSet, UsedTypeCtors0, UsedTypeCtors, !UsedModules),
      (
          ContainsCirc = yes,
          ( TypeDefn0 = parse_tree_eqv_type(_) ->
@@ -671,18 +671,30 @@

  replace_in_mutable_info(ModuleName, Location, EqvMap, EqvInstMap,
          Info0, Info, !RecompInfo, !UsedModules, []) :-
-    Info0 = item_mutable_info(MutName, Type0, InitValue, Inst0, Attrs, Varset,
-        Context, SeqNum),
+    MutName = Info0 ^ mut_name,
      QualName = qualified(ModuleName, MutName),
      maybe_start_recording_expanded_items(ModuleName, QualName, !.RecompInfo,
          ExpandedItems0),
+    replace_in_mutable_defn(Location, EqvMap, EqvInstMap, Info0, Info,
+        ExpandedItems0, ExpandedItems, !UsedModules),
+    ItemId = item_id(mutable_item, item_name(QualName, 0)),
+    finish_recording_expanded_items(ItemId, ExpandedItems, !RecompInfo).
+
+:- pred replace_in_mutable_defn(eqv_type_location::in,
+    eqv_map::in, eqv_inst_map::in,
+    item_mutable_info::in, item_mutable_info::out,
+    equiv_type_info::in, equiv_type_info::out,
+    used_modules::in, used_modules::out) is det.
+
+replace_in_mutable_defn(Location, EqvMap, EqvInstMap, Info0, Info,
+        !ExpandedItems, !UsedModules) :-
+    Info0 = item_mutable_info(MutName, Type0, InitValue, Inst0, Attrs, Varset,
+        Context, SeqNum),
      TVarSet0 = varset.init,
      replace_in_type_location(Location, EqvMap, Type0, Type, _TypeChanged,
-        TVarSet0, _TVarSet, ExpandedItems0, ExpandedItems1, !UsedModules),
-    replace_in_inst(Location, Inst0, EqvInstMap, Inst,
-        ExpandedItems1, ExpandedItems, !UsedModules),
-    ItemId = item_id(mutable_item, item_name(QualName, 0)),
-    finish_recording_expanded_items(ItemId, ExpandedItems, !RecompInfo),
+        TVarSet0, _TVarSet, !ExpandedItems, !UsedModules),
+    replace_in_inst(Location, Inst0, EqvInstMap, Inst, !ExpandedItems,
+        !UsedModules),
      Info = item_mutable_info(MutName, Type, InitValue, Inst, Attrs, Varset,
          Context, SeqNum).

@@ -752,12 +764,13 @@
      Attr = event_attribute(AttrNum, AttrName, AttrType, AttrMode,
          MaybeSynthCall).

-:- pred replace_in_type_defn(eqv_type_location::in, eqv_map::in, type_ctor::in,
-    type_defn::in, type_defn::out, bool::out, tvarset::in, tvarset::out,
-    equiv_type_info::in, equiv_type_info::out,
+:- pred replace_in_type_defn(eqv_type_location::in,
+    eqv_map::in, eqv_inst_map::in, type_ctor::in,
+    type_defn::in, type_defn::out, bool::out,
+    tvarset::in, tvarset::out, equiv_type_info::in, equiv_type_info::out,
      used_modules::in, used_modules::out) is det.

-replace_in_type_defn(Location, EqvMap, TypeCtor, TypeDefn0, TypeDefn,
+replace_in_type_defn(Location, EqvMap, EqvInstMap, TypeCtor, TypeDefn0, TypeDefn,
          ContainsCirc, !VarSet, !EquivTypeInfo, !UsedModules) :-
      (
          TypeDefn0 = parse_tree_eqv_type(TypeBody0),
@@ -774,13 +787,15 @@
      ;
          TypeDefn0 = parse_tree_solver_type(SolverDetails0, MaybeUserEqComp),
          SolverDetails0 = solver_type_details(RepresentationType0, InitPred,
-            GroundInst, AnyInst, MutableItems),
+            GroundInst, AnyInst, MutableItems0),
          replace_in_type_location_2(Location, EqvMap, [TypeCtor],
              RepresentationType0, RepresentationType,
              _, ContainsCirc, !VarSet, !EquivTypeInfo, !UsedModules),
+        replace_in_constraint_store(Location, EqvMap, EqvInstMap,
+            MutableItems0, MutableItems, !EquivTypeInfo, !UsedModules),
          SolverDetails = solver_type_details(RepresentationType, InitPred,
              GroundInst, AnyInst, MutableItems),
-        TypeDefn = parse_tree_solver_type(SolverDetails,  MaybeUserEqComp)
+        TypeDefn = parse_tree_solver_type(SolverDetails, MaybeUserEqComp)
      ;
          ( TypeDefn0 = parse_tree_abstract_type(_)
          ; TypeDefn0 = parse_tree_foreign_type(_, _, _)
@@ -789,6 +804,24 @@
          ContainsCirc = no
      ).

+:- pred replace_in_constraint_store(eqv_type_location::in,
+    eqv_map::in, eqv_inst_map::in, list(item)::in, list(item)::out,
+    equiv_type_info::in, equiv_type_info::out,
+    used_modules::in, used_modules::out) is det.
+
+replace_in_constraint_store(_, _, _, [], [], !EquivTypeInfo, !UsedModules).
+replace_in_constraint_store(Location, EqvMap, EqvInstMap,
+        [CStore0 | CStores0], [CStore | CStores], !EquivTypeInfo, !UsedModules) :-
+    ( if CStore0 = item_mutable(ItemMutableInfo0) then
+        replace_in_mutable_defn(Location, EqvMap, EqvInstMap,
+            ItemMutableInfo0, ItemMutableInfo, !EquivTypeInfo, !UsedModules),
+        CStore = item_mutable(ItemMutableInfo)
+      else
+        unexpected($module, $pred, "item is not a mutable")
+    ),
+    replace_in_constraint_store(Location, EqvMap, EqvInstMap,
+        CStores0, CStores, !EquivTypeInfo, !UsedModules).
+
  %-----------------------------------------------------------------------------%

  replace_in_prog_constraints(EqvMap, Cs0, Cs, !VarSet, !EquivTypeInfo) :-
Index: tests/valid/bug190.m
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/valid/bug190.m,v
retrieving revision 1.1
diff -u -r1.1 bug190.m
--- tests/valid/bug190.m	17 Mar 2011 05:36:44 -0000	1.1
+++ tests/valid/bug190.m	18 Mar 2011 02:19:46 -0000
@@ -1,6 +1,7 @@
  % A regression test for bug #190.
  % rotd-2011-03-17 and before were not module qualifying mutable definitions
-% attached to the constraint_store attributes of solver types.
+% attached to the constraint_store attributes of solver types.  Nor were
+% equivalence types in such definitions being expanded.

  :- module bug190.
  :- interface.
@@ -11,6 +12,11 @@

  :- import_module list.

+:- type bar_type == list(int).
+
  :- solver type foo where
  	representation is character,
-	constraint_store is mutable(foo, list(int), [3], ground, [untrailed]).
+	constraint_store is [
+		mutable(foo, list(int), [3], ground, [untrailed]),
+		mutable(bar, bar_type, [3], ground, [untrailed])
+	].

--------------------------------------------------------------------------
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