[m-dev.] for review: remove index preds
Zoltan Somogyi
zs at cs.mu.OZ.AU
Mon Apr 17 18:10:51 AEST 2000
Estimated hours taken: 2
compiler/make_hlds.m:
Do not generate type-specific index predicates for du types which
(a) have user-defined equality, (b) are enums, or (c) have only one
constructor, since for these types the comparison predicate does
not call index.
compiler/unify_proc.m:
Delete the code for generate bodies for type-specific index predicates
for types which do not need them after the change to make_hlds.m.
library/builtin.m:
library/private_builtin.m:
library/std_util.m:
Delete index predicates that have been made redundant by this change
and the previous change involving index predicates.
This should also fix a problem reported by Fergus, which was caused
by the entry labels of these index predicates were not declared
before being defined. Since they are no longer defined, the problem
should go away.
Zoltan.
cvs diff: Diffing .
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.332
diff -u -b -B -r1.332 make_hlds.m
--- compiler/make_hlds.m 2000/04/14 08:38:03 1.332
+++ compiler/make_hlds.m 2000/04/17 05:56:27
@@ -2717,14 +2717,26 @@
% The only place that the index predicate for a type can ever
% be called from is the compare predicate for that type.
- % However, the compare predicate for an equivalence type
- % never calls the index predicate for that type; it calls
- % the compare predicate of the expanded type instead.
- % We therefore do not generate index predicates for equivalence types.
+ % The only types whose compare predicates call the type's index
+ % predicate are du types which
%
+ % - do not have user-defined equality (the compare predicates for
+ % types with user-defined equality generate a runtime abort),
+ %
+ % - are not enums (comparison predicates for enums just do an integer
+ % comparison), and
+ %
+ % - have more than one constructor (for types with only one
+ % constructor, the comparison predicate just deconstructs the
+ % arguments and compares them).
+ %
+ % The compare predicate for an equivalence type never calls the index
+ % predicate for that type; it calls the compare predicate of the
+ % expanded type instead.
+ %
% When we see an abstract type declaration, we do not declare an index
- % predicate for that type, since the type definition may later define
- % the type as an equivalence type. If the type does turn out to need
+ % predicate for that type, since the actual type definition may later
+ % turn out not to require one. If the type does turn out to need
% an index predicate, its declaration will be generated together with
% its implementation.
%
@@ -2748,11 +2760,14 @@
SpecialPredIds = [unify, compare],
add_special_pred_decl_list(SpecialPredIds, Module0, TVarSet,
Type, TypeId, Body, Context, Status, Module)
- ;
- ( Body = eqv_type(_) ->
- SpecialPredIds = [unify, compare]
;
+ (
+ Body = du_type(Ctors, _, no, no),
+ Ctors = [_, _|_]
+ ->
SpecialPredIds = [unify, index, compare]
+ ;
+ SpecialPredIds = [unify, compare]
),
add_special_pred_list(SpecialPredIds, Module0, TVarSet,
Type, TypeId, Body, Context, Status, Module)
Index: compiler/unify_proc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_proc.m,v
retrieving revision 1.82
diff -u -b -B -r1.82 unify_proc.m
--- compiler/unify_proc.m 2000/04/11 07:57:07 1.82
+++ compiler/unify_proc.m 2000/04/14 04:03:27
@@ -572,6 +572,11 @@
{ error("trying to create unify proc for abstract type") }
).
+ % This predicate generates the bodies of index predicates for the
+ % types that need index predicates.
+ %
+ % add_special_preds in make_hlds.m should o
+
:- pred unify_proc__generate_index_clauses(hlds_type_body, prog_var, prog_var,
prog_context, list(clause), unify_proc_info, unify_proc_info).
:- mode unify_proc__generate_index_clauses(in, in, in, in, out, in, out)
@@ -582,22 +587,20 @@
{ TypeBody = du_type(Ctors, _, IsEnum, MaybeEqPred) },
( { MaybeEqPred = yes(_) } ->
%
- % For non-canonical types, we just give up and
- % always return -1 (meaning "index not available")
- % from index/1.
+ % For non-canonical types, the generated comparison
+ % predicate returns an error, and does not call the
+ % type's index predicate, so do not generate an index
+ % predicate for such types.
%
- { ArgVars = [X, Index] },
- unify_proc__build_call(
- "builtin_index_non_canonical_type",
- ArgVars, Context, Goal),
- unify_proc__quantify_clause_body(ArgVars, Goal,
- Context, Clauses)
+ { error("trying to create index proc for non-canonical type") }
; { IsEnum = yes } ->
- { ArgVars = [X, Index] },
- unify_proc__build_call("unsafe_type_cast",
- ArgVars, Context, Goal),
- unify_proc__quantify_clause_body(ArgVars, Goal,
- Context, Clauses)
+ %
+ % For enum types, the generated comparison predicate
+ % performs an integer comparison, and does not call the
+ % type's index predicate, so do not generate an index
+ % predicate for such types.
+ %
+ { error("trying to create index proc for enum type") }
;
unify_proc__generate_du_index_clauses(Ctors, X, Index,
Context, 0, Clauses)
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing library
Index: library/builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.30
diff -u -b -B -r1.30 builtin.m
--- library/builtin.m 2000/04/11 07:57:15 1.30
+++ library/builtin.m 2000/04/12 12:17:22
@@ -175,11 +175,6 @@
:- mode compare(uo, in, ui) is det.
:- mode compare(uo, in, in) is det.
- % This predicate is obsolete. It is required only while bootstrapping
- % the change that deletes references to it by compiler-generated
- % compare and index predicates.
-:- pred index(T::in, int::out) is det.
-
% In addition, the following predicate-like constructs are builtin:
%
% :- pred (T = T).
@@ -231,7 +226,6 @@
%-----------------------------------------------------------------------------%
:- external(unify/2).
-:- external(index/2).
:- external(compare/3).
%-----------------------------------------------------------------------------%
@@ -299,12 +293,10 @@
MR_DEFINE_BUILTIN_TYPE_CTOR_INFO_UNUSED(ticket, 0, MR_TYPECTOR_REP_TICKET);
Define_extern_entry(mercury__builtin_unify_pred_2_0);
-Define_extern_entry(mercury__builtin_index_pred_2_0);
Define_extern_entry(mercury__builtin_compare_pred_3_0);
BEGIN_MODULE(builtin_types_module)
init_entry_ai(mercury__builtin_unify_pred_2_0);
- init_entry_ai(mercury__builtin_index_pred_2_0);
init_entry_ai(mercury__builtin_compare_pred_3_0);
BEGIN_CODE
/* code for predicate 'builtin_unify_pred'/2 in mode 0 */
@@ -312,11 +304,6 @@
MR_incr_sp_push_msg(2, ""private_builtin:builtin_unify_pred"");
fatal_error(""attempted unification of higher-order terms"");
-/* code for predicate 'builtin_index_pred'/2 in mode 0 */
-Define_entry(mercury__builtin_index_pred_2_0);
- r1 = (Integer) -1;
- proceed();
-
/* code for predicate 'builtin_compare_pred'/3 in mode 0 */
Define_entry(mercury__builtin_compare_pred_3_0);
MR_incr_sp_push_msg(2, ""private_builtin:builtin_compare_pred"");
@@ -472,7 +459,6 @@
BEGIN_MODULE(unify_c_pointer_module)
init_entry(mercury____Unify___builtin__c_pointer_0_0);
- init_entry(mercury____Index___builtin__c_pointer_0_0);
init_entry(mercury____Compare___builtin__c_pointer_0_0);
BEGIN_CODE
@@ -485,10 +471,6 @@
** However, it might not be correct in general...
*/
r1 = (r1 == r2);
- proceed();
-
-Define_entry(mercury____Index___builtin__c_pointer_0_0);
- r1 = -1;
proceed();
Define_entry(mercury____Compare___builtin__c_pointer_0_0);
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.46
diff -u -b -B -r1.46 private_builtin.m
--- library/private_builtin.m 2000/04/14 07:20:28 1.46
+++ library/private_builtin.m 2000/04/14 07:22:33
@@ -51,33 +51,27 @@
% runtime/mercury_type_info.{c,h}.
:- pred builtin_unify_int(int::in, int::in) is semidet.
-:- pred builtin_index_int(int::in, int::out) is det.
:- pred builtin_compare_int(comparison_result::uo, int::in, int::in) is det.
:- pred builtin_unify_character(character::in, character::in) is semidet.
-:- pred builtin_index_character(character::in, int::out) is det.
:- pred builtin_compare_character(comparison_result::uo, character::in,
character::in) is det.
:- pred builtin_unify_string(string::in, string::in) is semidet.
-:- pred builtin_index_string(string::in, int::out) is det.
:- pred builtin_compare_string(comparison_result::uo, string::in, string::in)
is det.
:- pred builtin_unify_float(float::in, float::in) is semidet.
-:- pred builtin_index_float(float::in, int::out) is det.
:- pred builtin_compare_float(comparison_result::uo, float::in, float::in)
is det.
:- pred builtin_unify_pred((pred)::in, (pred)::in) is semidet.
-:- pred builtin_index_pred((pred)::in, int::out) is det.
:- pred builtin_compare_pred(comparison_result::uo, (pred)::in, (pred)::in)
is det.
- % The following two preds are used for index/1 or compare/3
+ % The following two preds are used for compare/3
% on non-canonical types (types for which there is a
% `where equality is ...' declaration).
-:- pred builtin_index_non_canonical_type(T::in, int::out) is det.
:- pred builtin_compare_non_canonical_type(comparison_result::uo,
T::in, T::in) is det.
@@ -120,8 +114,6 @@
builtin_unify_int(X, X).
-builtin_index_int(X, X).
-
builtin_compare_int(R, X, Y) :-
( X < Y ->
R = (<)
@@ -133,9 +125,6 @@
builtin_unify_character(C, C).
-builtin_index_character(C, N) :-
- char__to_int(C, N).
-
builtin_compare_character(R, X, Y) :-
char__to_int(X, XI),
char__to_int(Y, YI),
@@ -149,8 +138,6 @@
builtin_unify_string(S, S).
-builtin_index_string(_, -1).
-
builtin_compare_string(R, S1, S2) :-
builtin_strcmp(Res, S1, S2),
( Res < 0 ->
@@ -163,8 +150,6 @@
builtin_unify_float(F, F).
-builtin_index_float(_, -1).
-
builtin_compare_float(R, F1, F2) :-
( F1 < F2 ->
R = (<)
@@ -182,11 +167,8 @@
"Res = strcmp(S1, S2);").
:- external(builtin_unify_pred/2).
-:- external(builtin_index_pred/2).
:- external(builtin_compare_pred/3).
-builtin_index_non_canonical_type(_, -1).
-
builtin_compare_non_canonical_type(Res, X, _Y) :-
% suppress determinism warning
( semidet_succeed ->
@@ -304,10 +286,8 @@
BEGIN_MODULE(type_info_module)
init_entry(mercury____Unify___private_builtin__type_info_1_0);
- init_entry(mercury____Index___private_builtin__type_info_1_0);
init_entry(mercury____Compare___private_builtin__type_info_1_0);
init_entry(mercury____Unify___private_builtin__typeclass_info_1_0);
- init_entry(mercury____Index___private_builtin__typeclass_info_1_0);
init_entry(mercury____Compare___private_builtin__typeclass_info_1_0);
BEGIN_CODE
Define_entry(mercury____Unify___private_builtin__type_info_1_0);
@@ -327,10 +307,6 @@
proceed();
}
-Define_entry(mercury____Index___private_builtin__type_info_1_0);
- r1 = -1;
- proceed();
-
Define_entry(mercury____Compare___private_builtin__type_info_1_0);
{
/*
@@ -351,9 +328,6 @@
{
fatal_error(""attempt to unify typeclass_info"");
}
-Define_entry(mercury____Index___private_builtin__typeclass_info_1_0);
- r1 = -1;
- proceed();
Define_entry(mercury____Compare___private_builtin__typeclass_info_1_0);
{
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.188
diff -u -b -B -r1.188 std_util.m
--- library/std_util.m 2000/04/14 07:20:29 1.188
+++ library/std_util.m 2000/04/14 07:22:33
@@ -1048,15 +1048,12 @@
#endif
Define_extern_entry(mercury____Unify___std_util__type_desc_0_0);
-Define_extern_entry(mercury____Index___std_util__type_desc_0_0);
Define_extern_entry(mercury____Compare___std_util__type_desc_0_0);
BEGIN_MODULE(unify_univ_module)
init_entry(mercury____Unify___std_util__univ_0_0);
- init_entry(mercury____Index___std_util__univ_0_0);
init_entry(mercury____Compare___std_util__univ_0_0);
init_entry(mercury____Unify___std_util__type_desc_0_0);
- init_entry(mercury____Index___std_util__type_desc_0_0);
init_entry(mercury____Compare___std_util__type_desc_0_0);
BEGIN_CODE
Define_entry(mercury____Unify___std_util__univ_0_0);
@@ -1098,10 +1095,6 @@
}
}
-Define_entry(mercury____Index___std_util__univ_0_0);
- r1 = -1;
- proceed();
-
Define_entry(mercury____Compare___std_util__univ_0_0);
{
/*
@@ -1155,10 +1148,6 @@
r1 = (comp == MR_COMPARE_EQUAL);
proceed();
}
-
-Define_entry(mercury____Index___std_util__type_desc_0_0);
- r1 = -1;
- proceed();
Define_entry(mercury____Compare___std_util__type_desc_0_0);
{
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing trial
cvs diff: Diffing util
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list