[m-rev.] diff: fix erlang switch gen bug with existential types

Peter Ross pro at missioncriticalit.com
Thu Jun 7 08:25:51 AEST 2007


This calculation of the size was incorrect in this fix.
The following diff fixes this.

===================================================================


Estimated hours taken: 1
Branches: main

compiler/erl_code_gen.m:
	In cons_id_size get_type_and_cons_defn can throw an exception,
	replace it with semidet code.
	The calculation of the size was also incorrect, as some
	existential type_vars are hidden in type_class_infos, we now
	factor this into the size calculation.


Index: compiler/erl_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/erl_code_gen.m,v
retrieving revision 1.9
diff -u -r1.9 erl_code_gen.m
--- compiler/erl_code_gen.m	6 Jun 2007 06:30:25 -0000	1.9
+++ compiler/erl_code_gen.m	6 Jun 2007 22:17:23 -0000
@@ -65,6 +65,7 @@
 :- import_module libs.globals.
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_foreign.
+:- import_module parse_tree.prog_type.
 
 :- import_module bool.
 :- import_module int.
@@ -675,10 +676,22 @@
 :- func cons_id_size(module_info, mer_type, cons_id) = int.
 
 cons_id_size(ModuleInfo, Type, ConsId) = Size :-
-    ( ConsId = cons(_, _) ->
-        get_type_and_cons_defn(ModuleInfo, Type, ConsId, _TypeDefn, ConsDefn),
-        Size = list.length(ConsDefn ^ cons_exist_tvars) +
-            list.length(ConsDefn ^ cons_constraints) +
+    (
+        type_to_ctor_and_args(Type, TypeCtor, _),
+        get_cons_defn(ModuleInfo, TypeCtor, ConsId, ConsDefn)
+    ->
+
+            %
+            % There will be a cell for each existential type variable
+            % which isn't mentioned in a typeclass constraint and
+            % a cell for each constraint and for each arg.
+            %
+        Constraints = ConsDefn ^ cons_constraints,
+        constraint_list_get_tvars(Constraints, ConstrainedTVars),
+        ExistTVars = ConsDefn ^ cons_exist_tvars,
+        UnconstrainedTVars = list.delete_elems(ExistTVars, ConstrainedTVars),
+
+        Size = list.length(UnconstrainedTVars) + list.length(Constraints) +
             list.length(ConsDefn ^ cons_args)
     ;
         Size = 0

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