[m-dev.] diff: improve performance of term__coerce and varset__coerce

Simon Taylor stayl at cs.mu.OZ.AU
Thu Oct 26 17:12:27 AEDT 2000



Estimated hours taken: 0.25

library/term.m:
library/varset.m:
	Use private_builtin__unsafe_type_cast rather
	than copying the value in term__coerce and
	varset__coerce. This change reduces the time
	taken by `mmc -C make_hlds' by 2-3%.

Index: term.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/term.m,v
retrieving revision 1.95
diff -u -u -r1.95 term.m
--- term.m	2000/10/17 01:33:23	1.95
+++ term.m	2000/10/26 05:40:20
@@ -1118,10 +1118,11 @@
 
 %-----------------------------------------------------------------------------%
 
-term__coerce(term__variable(var(V)), term__variable(var(V))).
-term__coerce(term__functor(Cons, Args0, Ctxt),
-		term__functor(Cons, Args, Ctxt)) :-
-	list__map(term__coerce, Args0, Args).
+term__coerce(A, B) :-
+	% Normally calls to this predicate should only be
+	% generated by the compiler, but type coercion by
+	% copying was taking about 3% of the compiler's runtime.
+	private_builtin__unsafe_type_cast(A, B).
 
 term__coerce_var(var(V), var(V)).
 
Index: varset.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/varset.m,v
retrieving revision 1.62
diff -u -u -r1.62 varset.m
--- varset.m	1999/10/30 04:16:13	1.62
+++ varset.m	2000/10/26 05:47:17
@@ -1,5 +1,5 @@
 %---------------------------------------------------------------------------%
-% Copyright (C) 1993-1999 The University of Melbourne.
+% Copyright (C) 1993-2000 The University of Melbourne.
 % This file may only be copied under the terms of the GNU Library General
 % Public License - see the file COPYING.LIB in the Mercury distribution.
 %---------------------------------------------------------------------------%
@@ -530,28 +530,11 @@
 
 %-----------------------------------------------------------------------------%
 
-varset__coerce(varset(S0, N0, B0), varset(S, N, B)) :-
-		% Coerce the var_supply
-	term__coerce_var_supply(S0, S),
-
-		% Coerce all the vars in the mapping from vars to names
-	map__to_assoc_list(N0, NList0),
-	list__map(lambda([P0::in, P::out] is det, (
-		P0 = V0 - Name,
-		P = V - Name,
-		term__coerce_var(V0, V)
-	)), NList0, NList),
-	map__from_assoc_list(NList, N),
-
-		% Coerce all the vars and terms in the substitution
-	map__to_assoc_list(B0, BList0),
-	list__map(lambda([Q0::in, Q::out] is det, (
-		Q0 = V0 - Binding0,
-		Q = V - Binding,
-		term__coerce_var(V0, V),
-		term__coerce(Binding0, Binding)
-	)), BList0, BList),
-	map__from_assoc_list(BList, B).
+varset__coerce(A, B) :-
+	% Normally calls to this predicate should only be
+	% generated by the compiler, but type coercion by 
+	% copying was taking about 3% of the compiler's runtime.
+	private_builtin__unsafe_type_cast(A, B).
 
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%

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