[m-rev.] for review: work around abort due to classify_type_ctor

Peter Wang novalazy at gmail.com
Tue Oct 2 13:51:16 AEST 2007


Estimated hours taken: 4
Branches: main

Work around a bug exposed by a stricter implementation of
`classify_type_ctor'.  The compiler would abort when compiling builtin.m in a
non-C grade, due to `classify_type_ctor' being called on module-qualified
builtin types (e.g. builtin.int/0) which it doesn't know about, and don't
appear in the type definition table.

The compiler seems to be inconsistent about when to use module-qualified and
unqualified builtin types.  This change does not try to fix that.

compiler/add_special_pred.m:
	Add a predicate `eagerly_add_special_preds' which doesn't check if
	predicates of the type to be added should be generated lazily before
	adding the special predicates.

compiler/make_hlds_passes.m:
	Make `add_builtin_type_ctor_special_preds' call
	`eagerly_add_special_preds' instead.

compiler/type_ctor_info.m:
	Add a missing space in an error message.


Index: compiler/add_special_pred.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_special_pred.m,v
retrieving revision 1.20
diff -u -r1.20 add_special_pred.m
--- compiler/add_special_pred.m	17 May 2007 03:52:39 -0000	1.20
+++ compiler/add_special_pred.m	2 Oct 2007 03:45:25 -0000
@@ -54,6 +54,12 @@
     hlds_type_body::in, prog_context::in, import_status::in,
     module_info::in, module_info::out) is det.
 
+    % XXX should be used only for a temporary workaround in make_hlds_passes.m
+    %
+:- pred eagerly_add_special_preds(tvarset::in, mer_type::in, type_ctor::in,
+    hlds_type_body::in, prog_context::in, import_status::in,
+    module_info::in, module_info::out) is det.
+
 %----------------------------------------------------------------------------%
 %----------------------------------------------------------------------------%
 
@@ -123,6 +129,13 @@
     ->
         true
     ;
+        eagerly_add_special_preds(TVarSet, Type, TypeCtor, Body, Context,
+            Status, !ModuleInfo)
+    ).
+
+eagerly_add_special_preds(TVarSet, Type, TypeCtor, Body, Context, Status,
+        !ModuleInfo) :-
+    (
         can_generate_special_pred_clauses_for_type(!.ModuleInfo, TypeCtor,
             Body)
     ->
Index: compiler/make_hlds_passes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make_hlds_passes.m,v
retrieving revision 1.72
diff -u -r1.72 make_hlds_passes.m
--- compiler/make_hlds_passes.m	20 Aug 2007 03:35:58 -0000	1.72
+++ compiler/make_hlds_passes.m	2 Oct 2007 03:45:25 -0000
@@ -221,7 +221,18 @@
     term.context_init(Context),
     Status = status_local,
     construct_type(TypeCtor, [], Type),
-    add_special_preds(TVarSet, Type, TypeCtor, Body, Context, Status,
+    %
+    % XXX we call `eagerly_add_special_preds' instead of `add_special_preds'
+    % to bypass a call to `special_pred_is_generated_lazily' which calls
+    % `classify_type_ctor'.  `classify_type_ctor' knows about unqualified
+    % builtin types, but not the qualified types like `builtin.int'/0 from
+    % `builtin_type_ctors_with_no_hlds_type_defn'.  Eventually it tries to
+    % look up the builtin type from the type definition table, and aborts as
+    % it won't find it.
+    %
+    % The special preds for these types shouldn't be generated lazily anyway.
+    %
+    eagerly_add_special_preds(TVarSet, Type, TypeCtor, Body, Context, Status,
         !ModuleInfo).
 
 %-----------------------------------------------------------------------------%
Index: compiler/type_ctor_info.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/type_ctor_info.m,v
retrieving revision 1.92
diff -u -r1.92 type_ctor_info.m
--- compiler/type_ctor_info.m	25 Sep 2007 04:56:43 -0000	1.92
+++ compiler/type_ctor_info.m	2 Oct 2007 03:45:25 -0000
@@ -146,7 +146,7 @@
         )
     ;
         SymName = unqualified(TypeName),
-        Msg = "unqualified type " ++ TypeName ++ "found in type_ctor_info",
+        Msg = "unqualified type " ++ TypeName ++ " found in type_ctor_info",
         unexpected(this_file, Msg)
     ).
 

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