[m-rev.] for review: automatically generate all type_ctor_infos on non C backends
Peter Ross
pro at missioncriticalit.com
Sat Nov 22 02:15:43 AEDT 2003
Estimated hours taken: 1.5
Branches: main
Address review comments of fjh about my change to generate type_ctor and
special preds for the builtin types which don't have an abstract type
declaration.
compiler/make_hlds.m:
Change parse_tree_to_hlds to use the state variable syntax.
compiler/type_util.m:
s/builtin_type_ctors/builtin_type_ctors_with_no_type_defn/
which better reflects which type ctors this function returns.
compiler/type_ctor_info.m:
Improve the documentation of how the code determines whether
or not a type_ctor_info needs to be generated.
compiler/typecheck.m:
Use builtin_type_ctors_with_no_type_defn and make the documentation
more explicit.
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.453
diff -u -r1.453 make_hlds.m
--- compiler/make_hlds.m 20 Nov 2003 22:58:56 -0000 1.453
+++ compiler/make_hlds.m 21 Nov 2003 15:07:19 -0000
@@ -138,19 +138,20 @@
parse_tree_to_hlds(module(Name, Items), MQInfo0, EqvMap, Module, QualInfo,
InvalidTypes, InvalidModes, !IO) :-
+ some [!Module] (
globals__io_get_globals(Globals, !IO),
mq_info_get_partial_qualifier_info(MQInfo0, PQInfo),
- module_info_init(Name, Items, Globals, PQInfo, no, Module0),
- add_item_list_decls_pass_1(Items,
- item_status(local, may_be_unqualified), Module0, Module1,
- no, InvalidModes0, !IO),
+ module_info_init(Name, Items, Globals, PQInfo, no, !:Module),
+ add_item_list_decls_pass_1(Items,
+ item_status(local, may_be_unqualified), !Module,
+ no, InvalidModes0, !IO),
globals__io_lookup_bool_option(statistics, Statistics, !IO),
maybe_report_stats(Statistics, !IO),
check_for_errors(
add_item_list_decls_pass_2(Items,
item_status(local, may_be_unqualified)),
- InvalidTypes1, Module1, Module2, !IO),
+ InvalidTypes1, !Module, !IO),
% Add constructors and special preds to the HLDS.
% This must be done after adding all type and
@@ -159,19 +160,19 @@
% doing this may cause a compiler abort.
(
InvalidTypes1 = no,
- module_info_types(Module2, Types),
+ module_info_types(!.Module, Types),
map__foldl3(process_type_defn, Types,
- no, InvalidTypes2, Module2, Module3a, !IO)
+ no, InvalidTypes2, !Module, !IO)
;
InvalidTypes1 = yes,
- InvalidTypes2 = yes,
- Module3a = Module2
+ InvalidTypes2 = yes
),
- % Add the special preds for the builtins
+ % Add the special preds for the builtin types which don't have a
+ % type declaration, hence no hlds_type_defn is generated for them.
(
Name = mercury_public_builtin_module,
- compiler_generated_rtti_for_the_builtins(Module3a)
+ compiler_generated_rtti_for_the_builtins(!.Module)
->
varset__init(TVarSet),
Body = abstract_type(non_solver_type),
@@ -182,18 +183,17 @@
construct_type(TypeCtor, [], Type),
add_special_preds(TVarSet, Type, TypeCtor,
Body, Context, Status, M0, M)
- ), builtin_type_ctors, Module3a, Module3)
+ ), builtin_type_ctors_with_no_type_defn, !Module)
;
- Module3 = Module3a
+ true
),
maybe_report_stats(Statistics, !IO),
% balance the binary trees
- module_info_optimize(Module3, Module4),
+ module_info_optimize(!Module),
maybe_report_stats(Statistics, !IO),
init_qual_info(MQInfo0, EqvMap, QualInfo0),
- add_item_list_clauses(Items, local, Module4, Module5,
- QualInfo0, QualInfo, !IO),
+ add_item_list_clauses(Items, local, !Module, QualInfo0, QualInfo, !IO),
qual_info_get_mq_info(QualInfo, MQInfo),
mq_info_get_type_error_flag(MQInfo, InvalidTypes3),
@@ -202,12 +202,14 @@
InvalidModes = InvalidModes0 `or` InvalidModes1,
mq_info_get_num_errors(MQInfo, MQ_NumErrors),
- module_info_num_errors(Module5, NumErrors5),
+ module_info_num_errors(!.Module, NumErrors5),
NumErrors = NumErrors5 + MQ_NumErrors,
- module_info_set_num_errors(NumErrors, Module5, Module6),
+ module_info_set_num_errors(NumErrors, !Module),
% the predid list is constructed in reverse order, for
% efficiency, so we return it to the correct order here.
- module_info_reverse_predids(Module6, Module).
+ module_info_reverse_predids(!Module),
+ Module = !.Module
+ ).
:- pred check_for_errors(pred(module_info, module_info, io__state, io__state),
bool, module_info, module_info, io__state, io__state).
Index: compiler/type_ctor_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_ctor_info.m,v
retrieving revision 1.48
diff -u -r1.48 type_ctor_info.m
--- compiler/type_ctor_info.m 20 Nov 2003 22:58:57 -0000 1.48
+++ compiler/type_ctor_info.m 21 Nov 2003 15:07:20 -0000
@@ -91,7 +91,7 @@
ModuleName = mercury_public_builtin_module,
compiler_generated_rtti_for_the_builtins(!.ModuleInfo)
->
- TypeCtors = builtin_type_ctors ++ TypeCtors0
+ TypeCtors = builtin_type_ctors_with_no_type_defn ++ TypeCtors0
;
TypeCtors = TypeCtors0
),
@@ -114,26 +114,28 @@
ModuleName, ModuleInfo, TypeCtorGenInfos1),
TypeCtor = SymName - TypeArity,
(
+ % Check if we should generate a type_ctor_info for this type.
+ % There are three cases that we have to check
+ % - the builtin types which have no type defn
+ % - the builtin types which are declared abstract
+ % - all the rest of the types
SymName = qualified(TypeModuleName, TypeName),
(
TypeModuleName = ModuleName,
- ( list__member(TypeCtor, builtin_type_ctors) ->
+ ( list__member(TypeCtor,
+ builtin_type_ctors_with_no_type_defn) ->
+ % the builtin types with no type definition.
compiler_generated_rtti_for_the_builtins(ModuleInfo),
TypeModuleName = unqualified(ModuleNameString),
- TypeDefn = builtin_type_defn,
- builtin_type_ctor(ModuleNameString, TypeName, TypeArity, _)
+ builtin_type_ctor(ModuleNameString, TypeName, TypeArity, _),
+ TypeDefn = builtin_type_defn
;
map__lookup(TypeTable, TypeCtor, TypeDefn),
hlds_data__get_type_defn_body(TypeDefn, TypeBody),
(
- TypeBody \= abstract_type(_)
+ TypeBody = abstract_type(_)
->
- \+ type_ctor_has_hand_defined_rtti(TypeCtor, TypeBody),
- ( are_equivalence_types_expanded(ModuleInfo)
- => TypeBody \= eqv_type(_) )
- ;
- % type_ctor_infos need be generated for the builtin
- % types (which are declared as abstract types)
+ % the builtin types which are declared abstract
compiler_generated_rtti_for_the_builtins(ModuleInfo),
TypeModuleName = unqualified(ModuleNameString),
( builtin_type_ctor(ModuleNameString,
@@ -141,6 +143,11 @@
; impl_type_ctor(ModuleNameString,
TypeName, TypeArity, _)
)
+ ;
+ % all the other types
+ \+ type_ctor_has_hand_defined_rtti(TypeCtor, TypeBody),
+ ( are_equivalence_types_expanded(ModuleInfo)
+ => TypeBody \= eqv_type(_) )
)
)
->
@@ -158,6 +165,7 @@
error(Msg)
).
+ % Generate a type_defn for the builtin types which don't have one.
:- func builtin_type_defn = hlds_type_defn.
builtin_type_defn = TypeDefn :-
Index: compiler/type_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_util.m,v
retrieving revision 1.131
diff -u -r1.131 type_util.m
--- compiler/type_util.m 20 Nov 2003 22:58:57 -0000 1.131
+++ compiler/type_util.m 21 Nov 2003 15:07:27 -0000
@@ -69,8 +69,10 @@
:- pred type_ctor_is_tuple(type_ctor).
:- mode type_ctor_is_tuple(in) is semidet.
- % The list of type_ctors which are builtins.
-:- func builtin_type_ctors = list(type_ctor).
+ % The list of type_ctors which are builtins which do not have a
+ % hlds_type_defn, ie. those builtin type which are not declared as
+ % abstract types in the standard library.
+:- func builtin_type_ctors_with_no_type_defn = list(type_ctor).
% Succeed iff there was either a `where equality is <predname>' or a
% `where comparison is <predname>' declaration for the principal type
@@ -2060,7 +2062,7 @@
%-----------------------------------------------------------------------------%
-builtin_type_ctors =
+builtin_type_ctors_with_no_type_defn =
[ qualified(mercury_public_builtin_module, "int") - 0,
qualified(mercury_public_builtin_module, "string") - 0,
qualified(mercury_public_builtin_module, "character") - 0,
Index: compiler/typecheck.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/typecheck.m,v
retrieving revision 1.346
diff -u -r1.346 typecheck.m
--- compiler/typecheck.m 20 Nov 2003 22:58:57 -0000 1.346
+++ compiler/typecheck.m 21 Nov 2003 15:07:43 -0000
@@ -860,9 +860,9 @@
MaybeSpecial = yes(_SpecialId - TypeCtor),
%
% check that the special pred isn't one of the builtin
- % types
+ % types which don't have a hlds_type_defn
%
- \+ list__member(TypeCtor, builtin_type_ctors),
+ \+ list__member(TypeCtor, builtin_type_ctors_with_no_type_defn),
%
% check whether that type is a type for which there is
% a user-defined equality predicate, or which is existentially typed.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list