[m-rev.] for review: rtti_varmaps

Mark Brown mark at cs.mu.OZ.AU
Fri Jul 22 22:31:01 AEST 2005


On 22-Jul-2005, Mark Brown <mark at cs.mu.OZ.AU> wrote:
> Yep.  Bootstraps in several grades including a tsw grade.

...and here's the relative diff:

diff -u compiler/cse_detection.m compiler/cse_detection.m
--- compiler/cse_detection.m	13 Jul 2005 07:27:06 -0000
+++ compiler/cse_detection.m	22 Jul 2005 06:04:43 -0000
@@ -785,7 +785,7 @@
 		% Traverse TVarsList again, this time looking for locations
 		% in later branches that merge with locations in the first
 		% branch.  When we find one, add a type substitution which
-		% represents the type variables that thus got merged.
+		% represents the type variables that were merged.
 		%
 	list__foldl(find_merged_tvars(RttiVarMaps0, LaterOldNewMap, NewTvarMap),
 		TvarsList, map__init, TSubst),
diff -u compiler/hlds_pred.m compiler/hlds_pred.m
--- compiler/hlds_pred.m	13 Jul 2005 10:47:29 -0000
+++ compiler/hlds_pred.m	22 Jul 2005 06:10:25 -0000
@@ -39,6 +39,7 @@
 :- implementation.
 
 % Parse tree modules.
+:- import_module parse_tree__error_util.
 :- import_module parse_tree__prog_type.
 :- import_module parse_tree__prog_util.
 
@@ -191,8 +192,9 @@
 	).
 
 %-----------------------------------------------------------------------------%
-
-	% Types and predicates to store information about RTTI.
+%
+% Types and predicates to store information about RTTI.
+%
 
 	% Describes the class constraints on an instance method implementation.
 	% This information is used by polymorphism.m to ensure that the
@@ -467,10 +469,11 @@
 		->
 			true
 		;
-			error("maybe_check_type_info_var: inconsistent info")
+			unexpected(this_file,
+				"inconsistent info in rtti_varmaps")
 		)
 	;
-		error("maybe_check_type_info_var: missing info")
+		unexpected(this_file, "missing info in rtti_varmaps")
 	).
 maybe_check_type_info_var(typeclass_info(_, _), _, !VarMaps).
 
@@ -3720,2 +3723,9 @@
 %-----------------------------------------------------------------------------%
+
+:- func this_file = string.
+
+this_file = "hlds_pred.m".
+
+%-----------------------------------------------------------------------------%
+:- end_module hlds.hlds_pred.
 %-----------------------------------------------------------------------------%
diff -u library/injection.m library/injection.m
--- library/injection.m	12 Jul 2005 13:26:42 -0000
+++ library/injection.m	22 Jul 2005 07:19:32 -0000
@@ -9,8 +9,10 @@
 %
 % This module provides the `injection' ADT.  An injection is like a `map'
 % (see map.m) but it allows efficient reverse lookups, similarly to `bimap'.
-% The difference between an injection and a bimap is that there can be
-% values in the range of the injection that are not returned for any key.
+% This time efficiency comes at the expense of using twice as much space
+% or more.  The difference between an injection and a bimap is that there
+% can be values in the range of the injection that are not returned for any
+% key, but for which a reverse lookup will still return a valid key.
 %
 % The invariants on this data structure, which are enforced by this module,
 % are as follows:
@@ -89,13 +91,11 @@
 
 	% Succeeds if the injection contains the given key.
 	%
-:- pred injection.contains_key(injection(K, V), K).
-:- mode injection.contains_key(in, in) is semidet.
+:- pred injection.contains_key(injection(K, V)::in, K::in) is semidet.
 
 	% Succeeds if the injection contains the given value.
 	%
-:- pred injection.contains_value(injection(K, V), V).
-:- mode injection.contains_value(in, in) is semidet.
+:- pred injection.contains_value(injection(K, V)::in, V::in) is semidet.
 
 	% Insert a new key-value pair into the injection.  Fails if either
 	% the key or value already exists.
@@ -366,93 +366,92 @@
 injection.contains_value(injection(_, R), V) :-
 	map.contains(R, V).
 
-injection.insert(injection(F0, R0), K, V) = injection(F, R) :-
-	map.insert(F0, K, V, F),
-	map.insert(R0, V, K, R).
+injection.insert(injection(!.F, !.R), K, V) = injection(!:F, !:R) :-
+	svmap.insert(K, V, !F),
+	svmap.insert(V, K, !R).
 
 injection.insert(I, K, V, injection.insert(I, K, V)).
 
-injection.det_insert(injection(F0, R0), K, V) = injection(F, R) :-
-	map.det_insert(F0, K, V, F),
-	map.det_insert(R0, V, K, R).
+injection.det_insert(injection(!.F, !.R), K, V) = injection(!:F, !:R) :-
+	svmap.det_insert(K, V, !F),
+	svmap.det_insert(V, K, !R).
 
 injection.det_insert(I, K, V, injection.det_insert(I, K, V)).
 
-injection.update(injection(F0, R0), K, V) = injection(F, R) :-
-	map.update(F0, K, V, F),
-	map.insert(R0, V, K, R).
+injection.update(injection(!.F, !.R), K, V) = injection(!:F, !:R) :-
+	svmap.update(K, V, !F),
+	svmap.insert(V, K, !R).
 
 injection.update(I, K, V, injection.update(I, K, V)).
 
-injection.det_update(injection(F0, R0), K, V) = injection(F, R) :-
-	map.det_update(F0, K, V, F),
-	map.det_insert(R0, V, K, R).
+injection.det_update(injection(!.F, !.R), K, V) = injection(!:F, !:R) :-
+	svmap.det_update(K, V, !F),
+	svmap.det_insert(V, K, !R).
 
 injection.det_update(I, K, V, injection.det_update(I, K, V)).
 
-injection.set(injection(F0, R0), K, V) = injection(F, R) :-
-	injection.set_2(K, V, F0, F, R0, R).
+injection.set(injection(!.F, !.R), K, V) = injection(!:F, !:R) :-
+	injection.set_2(K, V, !F, !R).
 
 injection.set(I, K, V, injection.set(I, K, V)).
 
 :- pred injection.set_2(K::in, V::in, map(K, V)::in, map(K, V)::out,
 	map(V, K)::in, map(V, K)::out) is semidet.
 
-injection.set_2(K, V, F0, F, R0, R) :-
-	map.set(F0, K, V, F),
+injection.set_2(K, V, !F, !R) :-
+	svmap.set(K, V, !F),
 	(
-		map.search(R0, V, OrigK)
+		map.search(!.R, V, OrigK)
 	->
 		% Fail if the existing key is not the same as the
 		% given key.
-		K = OrigK,
-		R = R0
+		K = OrigK
 	;
-		map.det_insert(R0, V, K, R)
+		svmap.det_insert(V, K, !R)
 	).
 
-injection.det_set(injection(F0, R0), K, V) = injection(F, R) :-
-	injection.det_set_2(K, V, F0, F, R0, R).
+injection.det_set(injection(!.F, !.R), K, V) = injection(!:F, !:R) :-
+	injection.det_set_2(K, V, !F, !R).
 
 injection.det_set(I, K, V, injection.det_set(I, K, V)).
 
 :- pred injection.det_set_2(K::in, V::in, map(K, V)::in, map(K, V)::out,
 	map(V, K)::in, map(V, K)::out) is det.
 
-injection.det_set_2(K, V, F0, F, R0, R) :-
-	map.set(F0, K, V, F),
+injection.det_set_2(K, V, !F, !R) :-
+	svmap.set(K, V, !F),
 	(
-		map.search(R0, V, OrigK)
+		map.search(!.R, V, OrigK)
 	->
 		% Abort if the existing key is not the same as the
 		% given key.
 		(
 			K = OrigK
 		->
-			R = R0
+			true
 		;
 			error("injection.det_set: " ++
 				"value is already associated with another key")
 		)
 	;
-		map.det_insert(R0, V, K, R)
+		svmap.det_insert(V, K, !R)
 	).
 
 injection.insert_from_assoc_list(A, injection(F0, R0)) = injection(F, R) :-
-	P = (pred(KV::in, F1::in, F2::out, R1::in, R2::out) is semidet :-
+	P = (pred(KV::in, !.F::in, !:F::out, !.R::in, !:R::out) is semidet :-
 			KV = K - V,
-			map.insert(F1, K, V, F2),
-			map.insert(R1, V, K, R2)
+			svmap.insert(K, V, !F),
+			svmap.insert(V, K, !R)
 		),
 	list.foldl2(P, A, F0, F, R0, R).
 
 injection.insert_from_assoc_list(A, I, injection.insert_from_assoc_list(A, I)).
 
 injection.det_insert_from_assoc_list(A, injection(F0, R0)) = injection(F, R) :-
-	P = (pred(KV::in, F1::in, F2::out, R1::in, R2::out) is det :-
+	P = (pred(KV::in, !.F::in, !:F::out, !.R::in, !:R::out) is det :-
 			KV = K - V,
-			map.det_insert(F1, K, V, F2),
-			map.det_insert(R1, V, K, R2)
+			svmap.det_insert(K, V, !F),
+			svmap.det_insert(V, K, !R)
 		),
 	list.foldl2(P, A, F0, F, R0, R).
 
@@ -460,18 +459,18 @@
 	injection.det_insert_from_assoc_list(A, I)).
 
 injection.set_from_assoc_list(A, injection(F0, R0)) = injection(F, R) :-
-	P = (pred(KV::in, F1::in, F2::out, R1::in, R2::out) is semidet :-
+	P = (pred(KV::in, !.F::in, !:F::out, !.R::in, !:R::out) is semidet :-
 			KV = K - V,
-			injection.set_2(K, V, F1, F2, R1, R2)
+			injection.set_2(K, V, !F, !R)
 		),
 	list.foldl2(P, A, F0, F, R0, R).
 
 injection.set_from_assoc_list(A, I, injection.set_from_assoc_list(A, I)).
 
 injection.det_set_from_assoc_list(A, injection(F0, R0)) = injection(F, R) :-
-	P = (pred(KV::in, F1::in, F2::out, R1::in, R2::out) is det :-
+	P = (pred(KV::in, !.F::in, !:F::out, !.R::in, !:R::out) is det :-
 			KV = K - V,
-			injection.det_set_2(K, V, F1, F2, R1, R2)
+			injection.det_set_2(K, V, !F, !R)
 		),
 	list.foldl2(P, A, F0, F, R0, R).
 
@@ -480,9 +479,10 @@
 
 injection.insert_from_corresponding_lists(As, Bs, injection(F0, R0)) =
 		injection(F, R) :-
-	P = (pred(K::in, V::in, F1::in, F2::out, R1::in, R2::out) is semidet :-
-			map.insert(F1, K, V, F2),
-			map.insert(R1, V, K, R2)
+	P = (pred(K::in, V::in, !.F::in, !:F::out, !.R::in, !:R::out)
+		is semidet :-
+			svmap.insert(K, V, !F),
+			svmap.insert(V, K, !R)
 		),
 	list.foldl2_corresponding(P, As, Bs, F0, F, R0, R).
 
@@ -491,38 +491,36 @@
 
 injection.det_insert_from_corresponding_lists(As, Bs, injection(F0, R0)) =
 		injection(F, R) :-
-	P = (pred(K::in, V::in, F1::in, F2::out, R1::in, R2::out) is det :-
-			map.det_insert(F1, K, V, F2),
-			map.det_insert(R1, V, K, R2)
+	P = (pred(K::in, V::in, !.F::in, !:F::out, !.R::in, !:R::out) is det :-
+			svmap.det_insert(K, V, !F),
+			svmap.det_insert(V, K, !R)
 		),
 	list.foldl2_corresponding(P, As, Bs, F0, F, R0, R).
 
 injection.det_insert_from_corresponding_lists(As, Bs, I,
 	injection.det_insert_from_corresponding_lists(As, Bs, I)).
 
-injection.set_from_corresponding_lists(As, Bs, injection(F0, R0)) =
-		injection(F, R) :-
-	list.foldl2_corresponding(injection.set_2, As, Bs, F0, F, R0, R).
+injection.set_from_corresponding_lists(As, Bs, injection(!.F, !.R)) =
+		injection(!:F, !:R) :-
+	list.foldl2_corresponding(injection.set_2, As, Bs, !F, !R).
 
 injection.set_from_corresponding_lists(As, Bs, I,
 	injection.set_from_corresponding_lists(As, Bs, I)).
 
-injection.det_set_from_corresponding_lists(As, Bs, injection(F0, R0)) =
-		injection(F, R) :-
-	list.foldl2_corresponding(injection.det_set_2, As, Bs, F0, F, R0, R).
+injection.det_set_from_corresponding_lists(As, Bs, injection(!.F, !.R)) =
+		injection(!:F, !:R) :-
+	list.foldl2_corresponding(injection.det_set_2, As, Bs, !F, !R).
 
 injection.det_set_from_corresponding_lists(As, Bs, I,
 	injection.det_set_from_corresponding_lists(As, Bs, I)).
 
-injection.delete_key(injection(F0, R0), K) = injection(F, R) :-
+injection.delete_key(injection(!.F, !.R), K) = injection(!:F, !:R) :-
 	(
-		map.remove(F0, K, _, F1)
+		svmap.remove(K, _, !F)
 	->
-		F = F1,
-		map.foldl(filter_values_with_key(K), R0, map.init, R)
+		map.foldl(filter_values_with_key(K), !.R, map.init, !:R)
 	;
-		F = F0,
-		R = R0
+		true
 	).
 
 injection.delete_key(K, I, injection.delete_key(I, K)).
@@ -539,24 +537,22 @@
 		svmap.det_insert(V, K, !Map)
 	).
 
-injection.delete_value(injection(F0, R0), V) = injection(F, R) :-
+injection.delete_value(injection(!.F, !.R), V) = injection(!:F, !:R) :-
 	(
-		map.remove(R0, V, K, R1)
+		svmap.remove(V, K, !R)
 	->
 		% Only K could possibly be associated with V.  If it is,
 		% then we throw an exception.
 		(
-			map.lookup(F0, K, V)
+			map.lookup(!.F, K, V)
 		->
 			error("injection.delete_value: " ++
 				"value is associated with a key")
 		;
-			F = F0
-		),
-		R = R1
+			true
+		)
 	;
-		F = F0,
-		R = R0
+		true
 	).
 
 injection.delete_value(V, I, injection.delete_value(I, V)).
@@ -603,19 +599,19 @@
 
 :- func insert_transformed_key_f(func(V, K) = L, K, V, map(L, V)) = map(L, V).
 
-insert_transformed_key_f(Func, K, V, Map0) = Map :-
-	map.set(Map0, Func(V, K), V, Map).
+insert_transformed_key_f(Func, K, V, !.Map) = !:Map :-
+	svmap.set(Func(V, K), V, !Map).
 
-injection.map_keys(Pred, injection(F0, R0), injection(F, R)) :-
-	map.foldl(insert_transformed_key_p(Pred), F0, map.init, F),
-	map.map_values(Pred, R0, R).
+injection.map_keys(Pred, injection(!.F, !.R), injection(!:F, !:R)) :-
+	map.foldl(insert_transformed_key_p(Pred), !.F, map.init, !:F),
+	map.map_values(Pred, !R).
 
 :- pred insert_transformed_key_p(pred(V, K, L)::in(pred(in, in, out) is det),
 	K::in, V::in, map(L, V)::in, map(L, V)::out) is det.
 
-insert_transformed_key_p(Pred, K, V, Map0, Map) :-
+insert_transformed_key_p(Pred, K, V, !Map) :-
 	Pred(V, K, L),
-	map.set(Map0, L, V, Map).
+	svmap.set(L, V, !Map).
 
 injection.filter_map_keys(Pred, injection(F0, R0), injection(F, R)) :-
 	F = map.foldl(maybe_set_transformed_key(Pred), F0, map.init),
@@ -627,13 +623,13 @@
 :- mode maybe_set_transformed_key(in(pred(in, in, out) is semidet), in, in, in)
 	= out is det.
 
-maybe_set_transformed_key(Pred, K, V, Map0) = Map :-
+maybe_set_transformed_key(Pred, K, V, !.Map) = !:Map :-
 	(
 		Pred(V, K, L)
 	->
-		map.set(Map0, L, V, Map)
+		svmap.set(L, V, !Map)
 	;
-		Map = Map0
+		true
 	).
 
 :- pred maybe_transform_key(pred(V, K, L)::in(pred(in, in, out) is semidet),
@@ -649,19 +645,19 @@
 :- func insert_transformed_value_f(func(K, V) = W, V, K, map(W, K)) =
 	map(W, K).
 
-insert_transformed_value_f(Func, V, K, Map0) = Map :-
+insert_transformed_value_f(Func, V, K, !.Map) = !:Map :-
 	W = Func(K, V),
 	(
-		map.insert(Map0, W, K, Map1)
+		svmap.insert(W, K, !Map)
 	->
-		Map = Map1
+		true
 	;
 		% Another value in the original was already mapped to this
 		% value.  We ensure that it had the same key.
 		(
-			map.lookup(Map0, W, K)
+			map.lookup(!.Map, W, K)
 		->
-			Map = Map0
+			true
 		;
 			error("injection.map_values: " ++
 				"merged two values with different keys")
only in patch2:
unchanged:
--- library/bimap.m	16 Jun 2005 04:07:59 -0000	1.20
+++ library/bimap.m	22 Jul 2005 06:18:57 -0000
@@ -11,7 +11,8 @@
 % This file provides a bijective map ADT.
 % A map (also known as a dictionary or an associative array) is a collection
 % of (Key, Data) pairs which allows you to look up any Data item given the
-% Key.  A bimap also allows you to look up the Key given the Data.
+% Key.  A bimap also allows you to efficiently look up the Key given the Data.
+% This time efficiency comes at the expense of using twice as much space.
 %
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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