[m-dev.] for review: record where assertions used

Peter Ross petdr at cs.mu.OZ.AU
Wed Jul 14 11:53:11 AEST 1999


Hi,

This is for Simon to review.


===================================================================


Estimated hours taken: 8

Record in which predicates an assertion is used.

compiler/accumulator.m:
compiler/lambda.m:
compiler/magic.m:
    Initialise the assertions field in the new pred_info.
    
compiler/assertion.m:
    An abstract interface to the assertion table (hopefully).

compiler/hlds_data.m:
    Modify assertion_table_add_assertion to return the assert_id of the
    inserted assertion.

compiler/hlds_pred.m:
    Record in the pred_info the set of assertions that mention the pred.

compiler/post_typecheck.m:
    Now record which predicates are used in assertions.

compiler/notes/compiler_design.html:
    Document assertion.m

Index: compiler/accumulator.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/accumulator.m,v
retrieving revision 1.5
diff -u -r1.5 accumulator.m
--- accumulator.m	1999/07/13 08:52:39	1.5
+++ accumulator.m	1999/07/14 00:34:43
@@ -575,6 +575,7 @@
 	pred_info_get_class_context(PredInfo, ClassContext),
 	pred_info_get_aditi_owner(PredInfo, Owner),
 
+	set__init(Assertions),
 
 	proc_info_context(NewProcInfo, Context),
 	term__context_line(Context, Line),
@@ -587,7 +588,7 @@
 
 	pred_info_create(ModuleName, SymName, TypeVarSet, ExistQVars, Types,
 			Cond, PredContext, local, Markers, PredOrFunc,
-			ClassContext, Owner, NewProcInfo, NewProcId,
+			ClassContext, Owner, Assertions, NewProcInfo, NewProcId,
 			NewPredInfo).
 
 %-----------------------------------------------------------------------------%
Index: compiler/assertion.m
===================================================================
RCS file: assertion.m
diff -N assertion.m
--- /dev/null	Wed Jul 14 11:33:06 1999
+++ assertion.m	Wed Jul 14 11:19:00 1999
@@ -0,0 +1,141 @@
+%-----------------------------------------------------------------------------%
+% Copyright (C) 1999 The University of Melbourne.
+% This file may only be copied under the terms of the GNU General
+% Public License - see the file COPYING in the Mercury distribution.
+%-----------------------------------------------------------------------------%
+%
+% Module: assertion
+%
+% Main authors: petdr
+%
+% This module is an abstract interface to the assertion table.
+% Note that this is a first design and will probably change
+% substantially in the future.
+%
+%-----------------------------------------------------------------------------%
+
+:- module (assertion).
+
+:- interface.
+
+:- import_module hlds_data, hlds_goal, hlds_module.
+
+	%
+	% assertion__goal
+	%
+	% Get the hlds_goal which represents the assertion.
+	%
+:- pred assertion__goal(assert_id::in, module_info::in, hlds_goal::out) is det.
+
+	%
+	% assertion__record_preds_used_in
+	%
+	% Record into the pred_info of each pred used in the assertion
+	% the assert_id.
+	%
+:- pred assertion__record_preds_used_in(hlds_goal::in, assert_id::in,
+		module_info::in, module_info::out) is det.
+
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module hlds_pred.
+:- import_module list, require, set, std_util.
+
+%-----------------------------------------------------------------------------%
+
+assertion__goal(AssertId, Module, Goal) :-
+	module_info_assertion_table(Module, AssertTable),
+	assertion_table_lookup(AssertTable, AssertId, PredId),
+	module_info_pred_info(Module, PredId, PredInfo),
+	pred_info_clauses_info(PredInfo, ClausesInfo),
+	clauses_info_clauses(ClausesInfo, Clauses),
+	(
+		Clauses = [clause(_ProcIds, Goal0, _Context)]
+	->
+		Goal = Goal0
+	;
+		error("assertion__goal: not an assertion")
+	).
+
+%-----------------------------------------------------------------------------%
+
+assertion__record_preds_used_in(call(PredId, _, _, _, _, _) - _, AssertId,
+		Module0, Module) :-
+	update_pred_info(PredId, AssertId, Module0, Module).
+assertion__record_preds_used_in(generic_call(_, _, _, _) - _, _AssertId,
+		Module, Module).
+assertion__record_preds_used_in(conj(Goals) - _, AssertId, Module0, Module) :-
+	assertion__record_preds_used_in_goal_list(Goals, AssertId,
+			Module0, Module).
+assertion__record_preds_used_in(switch(_, _, Cases, _) - _, AssertId,
+		Module0, Module) :-
+	assertion__record_preds_used_in_cases(Cases, AssertId, Module0, Module).
+assertion__record_preds_used_in(unify(_, _, _, _, _) - _,
+		_AssertId, Module, Module).
+assertion__record_preds_used_in(disj(Goals, _) - _, AssertId,
+		Module0, Module) :-
+	assertion__record_preds_used_in_goal_list(Goals, AssertId,
+			Module0, Module).
+assertion__record_preds_used_in(not(Goal) - _, AssertId, Module0, Module) :-
+	assertion__record_preds_used_in(Goal, AssertId, Module0, Module).
+assertion__record_preds_used_in(some(_, _, Goal) - _, AssertId,
+		Module0, Module) :-
+	assertion__record_preds_used_in(Goal, AssertId, Module0, Module).
+assertion__record_preds_used_in(if_then_else(_, If, Then, Else, _) - _,
+		AssertId, Module0, Module) :-
+	assertion__record_preds_used_in(If, AssertId, Module0, Module1),
+	assertion__record_preds_used_in(Then, AssertId, Module1, Module2),
+	assertion__record_preds_used_in(Else, AssertId, Module2, Module).
+assertion__record_preds_used_in(pragma_c_code(_, _, _, _, _, _, _) - _,
+		_AssertId, Module, Module).
+assertion__record_preds_used_in(par_conj(Goals, _) - _, AssertId,
+		Module0, Module) :-
+	assertion__record_preds_used_in_goal_list(Goals, AssertId,
+			Module0, Module).
+	
+%-----------------------------------------------------------------------------%
+
+:- pred assertion__record_preds_used_in_goal_list(list(hlds_goal)::in,
+		assert_id::in, module_info::in, module_info::out) is det.
+
+assertion__record_preds_used_in_goal_list([], _, Module, Module).
+assertion__record_preds_used_in_goal_list([Goal | Goals], AssertId,
+		Module0, Module) :-
+	assertion__record_preds_used_in(Goal, AssertId, Module0, Module1),
+	assertion__record_preds_used_in_goal_list(Goals, AssertId,
+			Module1, Module).
+
+%-----------------------------------------------------------------------------%
+
+:- pred assertion__record_preds_used_in_cases(list(case)::in, assert_id::in,
+		module_info::in, module_info::out) is det.
+
+assertion__record_preds_used_in_cases([], _, Module, Module).
+assertion__record_preds_used_in_cases([Case | Cases], AssertId,
+		Module0, Module) :-
+	Case = case(_, Goal),
+	assertion__record_preds_used_in(Goal, AssertId, Module0, Module1),
+	assertion__record_preds_used_in_cases(Cases, AssertId, Module1, Module).
+
+%-----------------------------------------------------------------------------%
+
+	%
+	% update_pred_info(Id, A, M0, M)
+	%
+	% Record in the pred_info pointed to by Id that that predicate
+	% is used in the assertion pointed to by A.
+	%
+:- pred update_pred_info(pred_id::in, assert_id::in, module_info::in,
+		module_info::out) is det.
+
+update_pred_info(PredId, AssertId, Module0, Module) :-
+	module_info_pred_info(Module0, PredId, PredInfo0),
+	pred_info_get_assertions(PredInfo0, Assertions0),
+	set__insert(Assertions0, AssertId, Assertions),
+	pred_info_set_assertions(PredInfo0, Assertions, PredInfo),
+	module_info_set_pred_info(Module0, PredId, PredInfo, Module).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
Index: compiler/hlds_data.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_data.m,v
retrieving revision 1.37
diff -u -r1.37 hlds_data.m
--- hlds_data.m	1999/07/13 08:52:56	1.37
+++ hlds_data.m	1999/07/14 00:34:48
@@ -827,8 +827,8 @@
 
 :- pred assertion_table_init(assertion_table::out) is det.
 
-:- pred assertion_table_add_assertion(pred_id::in,
-		assertion_table::in, assertion_table::out) is det.
+:- pred assertion_table_add_assertion(pred_id::in, assertion_table::in,
+		assert_id::out, assertion_table::out) is det.
 
 :- pred assertion_table_lookup(assertion_table::in, assert_id::in,
 		pred_id::out) is det.
@@ -844,7 +844,7 @@
 assertion_table_init(assertion_table(0, AssertionMap)) :-
 	map__init(AssertionMap).
 
-assertion_table_add_assertion(Assertion, AssertionTable0, AssertionTable) :-
+assertion_table_add_assertion(Assertion, AssertionTable0, Id, AssertionTable) :-
 	AssertionTable0 = assertion_table(Id, AssertionMap0),
 	map__det_insert(AssertionMap0, Id, Assertion, AssertionMap),
 	AssertionTable = assertion_table(Id + 1, AssertionMap).
Index: compiler/hlds_pred.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/hlds_pred.m,v
retrieving revision 1.62
diff -u -r1.62 hlds_pred.m
--- hlds_pred.m	1999/07/13 08:53:00	1.62
+++ hlds_pred.m	1999/07/14 00:36:53
@@ -461,9 +461,9 @@
 
 :- pred pred_info_create(module_name, sym_name, tvarset, existq_tvars,
 	list(type), condition, prog_context, import_status, pred_markers,
-	pred_or_func, class_constraints, aditi_owner, proc_info,
-	proc_id, pred_info).
-:- mode pred_info_create(in, in, in, in, in, in, in, in, in, in, in, in, in,
+	pred_or_func, class_constraints, aditi_owner, set(assert_id),
+	proc_info, proc_id, pred_info).
+:- mode pred_info_create(in, in, in, in, in, in, in, in, in, in, in, in, in, in,
 	out, out) is det.
 
 :- pred pred_info_module(pred_info, module_name).
@@ -628,6 +628,12 @@
 :- pred pred_info_set_indexes(pred_info, list(index_spec), pred_info).
 :- mode pred_info_set_indexes(in, in, out) is det.
 
+:- pred pred_info_get_assertions(pred_info, set(assert_id)).
+:- mode pred_info_get_assertions(in, out) is det.
+
+:- pred pred_info_set_assertions(pred_info, set(assert_id), pred_info).
+:- mode pred_info_set_assertions(in, in, out) is det.
+
 :- pred pred_info_get_purity(pred_info, purity).
 :- mode pred_info_get_purity(in, out) is det.
 
@@ -794,10 +800,13 @@
 					% it is an Aditi predicate. Set to
 					% the value of --aditi-user if no
 					% `:- pragma owner' declaration exists.
-			list(index_spec)
+			list(index_spec),
 					% Indexes if this predicate is
 					% an Aditi base relation, ignored
 					% otherwise.
+			set(assert_id)
+					% List of assertions which
+					% mention this predicate.
 		).
 
 pred_info_init(ModuleName, SymName, Arity, TypeVarSet, ExistQVars, Types,
@@ -810,15 +819,16 @@
 	list__delete_elems(TVars, ExistQVars, HeadTypeParams),
 	UnprovenBodyConstraints = [],
 	Indexes = [],
+	set__init(Assertions),
 	PredInfo = predicate(TypeVarSet, Types, Cond, ClausesInfo, Procs,
 		Context, PredModuleName, PredName, Arity, Status, TypeVarSet, 
 		GoalType, Markers, PredOrFunc, ClassContext, ClassProofs,
 		ExistQVars, HeadTypeParams, UnprovenBodyConstraints, User,
-		Indexes).
+		Indexes, Assertions).
 
 pred_info_create(ModuleName, SymName, TypeVarSet, ExistQVars, Types, Cond,
 		Context, Status, Markers, PredOrFunc, ClassContext, User,
-		ProcInfo, ProcId, PredInfo) :-
+		Assertions, ProcInfo, ProcId, PredInfo) :-
 	map__init(Procs0),
 	proc_info_declared_determinism(ProcInfo, MaybeDetism),
 	next_mode_id(Procs0, MaybeDetism, ProcId),
@@ -843,11 +853,11 @@
 		Context, ModuleName, PredName, Arity, Status, TypeVarSet, 
 		clauses, Markers, PredOrFunc, ClassContext, ClassProofs,
 		ExistQVars, HeadTypeParams, UnprovenBodyConstraints, User,
-		Indexes).
+		Indexes, Assertions).
 
 pred_info_procids(PredInfo, ProcIds) :-
 	PredInfo = predicate(_, _, _, _, Procs, _, _, _, _, _, _, _, 
-		_, _, _, _, _, _, _, _, _),
+		_, _, _, _, _, _, _, _, _, _),
 	map__keys(Procs, ProcIds).
 
 pred_info_non_imported_procids(PredInfo, ProcIds) :-
@@ -880,57 +890,57 @@
 
 pred_info_clauses_info(PredInfo, Clauses) :-
 	PredInfo = predicate(_, _, _, Clauses, _, _, _, _, _, _, _, _, _,
-		_, _, _, _, _, _, _, _).
+		_, _, _, _, _, _, _, _, _).
 
 pred_info_set_clauses_info(PredInfo0, Clauses, PredInfo) :-
 	PredInfo0 = predicate(A, B, C, _, E, F, G, H, I, J, K, L, M, N, O, P,
-		Q, R, S, T, U),
+		Q, R, S, T, U, V),
 	PredInfo = predicate(A, B, C, Clauses, E, F, G, H, I, J, K, 
-		L, M, N, O, P, Q, R, S, T, U).
+		L, M, N, O, P, Q, R, S, T, U, V).
 
 pred_info_arg_types(PredInfo, ArgTypes) :-
 	pred_info_arg_types(PredInfo, _TypeVars, _ExistQVars, ArgTypes).
 
 pred_info_arg_types(PredInfo, TypeVars, ExistQVars, ArgTypes) :-
 	PredInfo = predicate(TypeVars, ArgTypes, _, _, _, _, _, _, _, _, _,
-		_, _, _, _, _, ExistQVars, _, _, _, _).
+		_, _, _, _, _, ExistQVars, _, _, _, _, _).
 
 pred_info_set_arg_types(PredInfo0, TypeVarSet, ExistQVars, ArgTypes,
 		PredInfo) :-
 	PredInfo0 = predicate(_, _, C, D, E, F, G, H, I, J, K, L, M, N, O, P,
-		_, R, S, T, U),
+		_, R, S, T, U, V),
 	PredInfo = predicate(TypeVarSet, ArgTypes, C, D, E, F, G, H, I, J, K,
-		L, M, N, O, P, ExistQVars, R, S, T, U).
+		L, M, N, O, P, ExistQVars, R, S, T, U, V).
 
 pred_info_procedures(PredInfo, Procs) :-
 	PredInfo = predicate(_, _, _, _, Procs, _, _, _, _, _, _, 
-		_, _, _, _, _, _, _, _, _, _).
+		_, _, _, _, _, _, _, _, _, _, _).
 
 pred_info_set_procedures(PredInfo0, Procedures, PredInfo) :-
 	PredInfo0 = predicate(A, B, C, D, _, F, G, H, I, J, K, L, M, N, O, P,
-		Q, R, S, T, U),
+		Q, R, S, T, U, V),
 	PredInfo = predicate(A, B, C, D, Procedures, F, G, H, I, J, K, L, M, 
-		N, O, P, Q, R, S, T, U).
+		N, O, P, Q, R, S, T, U, V).
 
 pred_info_context(PredInfo, Context) :-
 	PredInfo = predicate(_, _, _, _, _, Context, _, _, _, 
-		_, _, _, _, _, _, _, _, _, _, _, _).
+		_, _, _, _, _, _, _, _, _, _, _, _, _).
 
 pred_info_module(PredInfo, Module) :-
 	PredInfo = predicate(_, _, _, _, _, _, Module, _, _, _, _, 
-		_, _, _, _, _, _, _, _, _, _).
+		_, _, _, _, _, _, _, _, _, _, _).
 
 pred_info_name(PredInfo, PredName) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, PredName, _, _, _, 
-		_, _, _, _, _, _, _, _, _, _).
+		_, _, _, _, _, _, _, _, _, _, _).
 
 pred_info_arity(PredInfo, Arity) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, Arity, _, _, 
-		_, _, _, _, _, _, _, _, _, _).
+		_, _, _, _, _, _, _, _, _, _, _).
 
 pred_info_import_status(PredInfo, ImportStatus) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, _, ImportStatus, _, _, _,
-				_, _, _, _, _, _, _, _).
+				_, _, _, _, _, _, _, _, _).
 
 pred_info_is_imported(PredInfo) :-
 	pred_info_import_status(PredInfo, imported).
@@ -963,35 +973,35 @@
 
 pred_info_mark_as_external(PredInfo0, PredInfo) :-
 	PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, _, K, L, M, N, O, P,
-		Q, R, S, T, U),
+		Q, R, S, T, U, V),
 	PredInfo  = predicate(A, B, C, D, E, F, G, H, I, imported, K, L, M, 
-		N, O, P, Q, R, S, T, U).
+		N, O, P, Q, R, S, T, U, V).
 
 pred_info_set_import_status(PredInfo0, Status, PredInfo) :-
 	PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, _, K, L, M, N, O, P,
-		Q, R, S, T, U),
+		Q, R, S, T, U, V),
 	PredInfo  = predicate(A, B, C, D, E, F, G, H, I, Status, K, 
-		L, M, N, O, P, Q, R, S, T, U).
+		L, M, N, O, P, Q, R, S, T, U, V).
 
 pred_info_typevarset(PredInfo, TypeVarSet) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, TypeVarSet, _, _, 
-		_, _, _, _, _, _, _, _).
+		_, _, _, _, _, _, _, _, _).
 
 pred_info_set_typevarset(PredInfo0, TypeVarSet, PredInfo) :-
 	PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, _, L, M, N, O, P,
-		Q, R, S, T, U),
+		Q, R, S, T, U, V),
 	PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, TypeVarSet, L, M,
-				N, O, P, Q, R, S, T, U).
+				N, O, P, Q, R, S, T, U, V).
 
 pred_info_get_goal_type(PredInfo, GoalType) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, GoalType, _, 
-		_, _, _, _, _, _, _, _).
+		_, _, _, _, _, _, _, _, _).
 
 pred_info_set_goal_type(PredInfo0, GoalType, PredInfo) :-
 	PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, _, M, N, O, P,
-		Q, R, S, T, U),
+		Q, R, S, T, U, V),
 	PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, GoalType, M, 
-		N, O, P, Q, R, S, T, U).
+		N, O, P, Q, R, S, T, U, V).
 
 pred_info_requested_inlining(PredInfo0) :-
 	pred_info_get_markers(PredInfo0, Markers),
@@ -1025,41 +1035,41 @@
 
 pred_info_get_markers(PredInfo, Markers) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, Markers, 
-		_, _, _, _, _, _, _, _).
+		_, _, _, _, _, _, _, _, _).
 
 pred_info_set_markers(PredInfo0, Markers, PredInfo) :-
 	PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, _, N, O, P,
-		Q, R, S, T, U),
+		Q, R, S, T, U, V),
 	PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, Markers, 
-		N, O, P, Q, R, S, T, U).
+		N, O, P, Q, R, S, T, U, V).
 
 pred_info_get_is_pred_or_func(PredInfo, IsPredOrFunc) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _,
-			IsPredOrFunc, _, _, _, _, _, _, _).
+			IsPredOrFunc, _, _, _, _, _, _, _, _).
 
 pred_info_set_class_context(PredInfo0, ClassContext, PredInfo) :-
 	PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, _, P,
-		Q, R, S, T, U),
+		Q, R, S, T, U, V),
 	PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, 
-		ClassContext, P, Q, R, S, T, U).
+		ClassContext, P, Q, R, S, T, U, V).
 
 pred_info_get_class_context(PredInfo, ClassContext) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, 
-		ClassContext, _, _, _, _, _, _).
+		ClassContext, _, _, _, _, _, _, _).
 
 pred_info_set_constraint_proofs(PredInfo0, Proofs, PredInfo) :-
 	PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, _,
-		Q, R, S, T, U),
+		Q, R, S, T, U, V),
 	PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, 
-		O, Proofs, Q, R, S, T, U).
+		O, Proofs, Q, R, S, T, U, V).
 
 pred_info_get_constraint_proofs(PredInfo, ConstraintProofs) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		ConstraintProofs, _, _, _, _, _).
+		ConstraintProofs, _, _, _, _, _, _).
 
 pred_info_get_exist_quant_tvars(PredInfo, ExistQVars) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, ExistQVars, _, _, _, _).
+		_, ExistQVars, _, _, _, _, _).
 
 pred_info_get_univ_quant_tvars(PredInfo, UnivQVars) :-
 	pred_info_arg_types(PredInfo, ArgTypes),
@@ -1070,45 +1080,55 @@
 
 pred_info_get_head_type_params(PredInfo, HeadTypeParams) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, HeadTypeParams, _, _, _).
+		_, _, HeadTypeParams, _, _, _, _).
 
 pred_info_set_head_type_params(PredInfo0, HeadTypeParams, PredInfo) :-
 	PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P,
-		Q, _, S, T, U),
+		Q, _, S, T, U, V),
 	PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P,
-		Q, HeadTypeParams, S, T, U).
+		Q, HeadTypeParams, S, T, U, V).
 
 pred_info_get_unproven_body_constraints(PredInfo, UnprovenBodyConstraints) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, UnprovenBodyConstraints, _, _).
+		_, _, UnprovenBodyConstraints, _, _, _).
 
 pred_info_set_unproven_body_constraints(PredInfo0, UnprovenBodyConstraints,
 		PredInfo) :-
 	PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P,
-		Q, R, _, T, U),
+		Q, R, _, T, U, V),
 	PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P,
-		Q, R, UnprovenBodyConstraints, T, U).
+		Q, R, UnprovenBodyConstraints, T, U, V).
 
 
 pred_info_get_aditi_owner(PredInfo, Owner) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, _, _, Owner, _).
+		_, _, _, _, Owner, _, _).
 
 pred_info_set_aditi_owner(PredInfo0, Owner, PredInfo) :-
 	PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N,
-		O, P, Q, R, S, _, U),
+		O, P, Q, R, S, _, U, V),
 	PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, 
-		O, P, Q, R, S, Owner, U).
+		O, P, Q, R, S, Owner, U, V).
 
 pred_info_get_indexes(PredInfo, Indexes) :-
 	PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
-		_, _, _, _, _, Indexes).
+		_, _, _, _, _, Indexes, _).
 
 pred_info_set_indexes(PredInfo0, Indexes, PredInfo) :-
+	PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N,
+		O, P, Q, R, S, T, _, V),
+	PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, 
+		O, P, Q, R, S, T, Indexes, V).
+
+pred_info_get_assertions(PredInfo, Assertions) :-
+	PredInfo = predicate(_, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
+		_, _, _, _, _, _, Assertions).
+
+pred_info_set_assertions(PredInfo0, Assertions, PredInfo) :-
 	PredInfo0 = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N,
-		O, P, Q, R, S, T, _),
+		O, P, Q, R, S, T, U, _),
 	PredInfo  = predicate(A, B, C, D, E, F, G, H, I, J, K, L, M, N, 
-		O, P, Q, R, S, T, Indexes).
+		O, P, Q, R, S, T, U, Assertions).
 
 %-----------------------------------------------------------------------------%
 
@@ -1245,9 +1265,11 @@
 		Context, TVarMap, TCVarMap, IsAddressTaken, ProcInfo0),
 	proc_info_set_maybe_termination_info(ProcInfo0, TermInfo, ProcInfo),
 
+	set__init(Assertions),
+
 	pred_info_create(ModuleName, SymName, TVarSet, ExistQVars, ArgTypes,
 		true, Context, local, Markers, predicate, ClassContext, 
-		Owner, ProcInfo, ProcId, PredInfo),
+		Owner, Assertions, ProcInfo, ProcId, PredInfo),
 
 	module_info_get_predicate_table(ModuleInfo0, PredTable0),
 	predicate_table_insert(PredTable0, PredInfo, PredId,
Index: compiler/lambda.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/lambda.m,v
retrieving revision 1.52
diff -u -r1.52 lambda.m
--- lambda.m	1999/07/13 08:53:02	1.52
+++ lambda.m	1999/07/14 00:34:50
@@ -525,9 +525,11 @@
 			AllArgModes, Detism, LambdaGoal, LambdaContext,
 			TVarMap, TCVarMap, address_is_taken, ProcInfo),
 
+		set__init(Assertions),
+
 		pred_info_create(ModuleName, PredName, TVarSet, ExistQVars,
 			ArgTypes, true, LambdaContext, local, LambdaMarkers,
-			PredOrFunc, Constraints, Owner, ProcInfo,
+			PredOrFunc, Constraints, Owner, Assertions, ProcInfo,
 			ProcId, PredInfo),
 
 		% save the new predicate in the predicate table
Index: compiler/magic.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/magic.m,v
retrieving revision 1.6
diff -u -r1.6 magic.m
--- magic.m	1999/07/13 08:53:07	1.6
+++ magic.m	1999/07/14 01:29:33
@@ -470,9 +470,10 @@
 	{ pred_info_get_indexes(PredInfo0, Indexes) },
 		% type classes aren't supported in Aditi.
 	{ ClassConstraints = constraints([], []) },
+	{ set__init(Assertions) },
 	{ pred_info_create(Module, NewName, TVarSet,
 		ExistQVars, ArgTypes, true, Context, Status, Markers, 
-		PredOrFunc, ClassConstraints, Owner, ProcInfo0, 
+		PredOrFunc, ClassConstraints, Owner, Assertions, ProcInfo0, 
 		NewProcId, NewPredInfo0) },
 	{ pred_info_set_indexes(NewPredInfo0, Indexes, NewPredInfo) },
 
@@ -1019,9 +1020,10 @@
 	{ varset__init(TVarSet) },	% must be empty.
 	{ term__context_init(DummyContext) },
 	{ ExistQVars = [] },
+	{ set__init(Assertions) },
 	{ pred_info_create(PredModule, NewPredName,
 		TVarSet, ExistQVars, NewArgTypes, true, DummyContext,
-		exported, Markers, predicate, ClassContext, User,
+		exported, Markers, predicate, ClassContext, User, Assertions,
 		JoinProcInfo, JoinProcId, JoinPredInfo1) },
 
 	magic_info_get_module_info(ModuleInfo0),
@@ -1288,9 +1290,10 @@
 	{ pred_info_get_aditi_owner(PredInfo, Owner) },
 	{ ClassConstraints = constraints([], []) },
 	{ ExistQVars = [] },
+	{ set__init(Assertions) },
 	{ pred_info_create(ModuleName, SymName, TVarSet, ExistQVars,
 		AllArgTypes, true, Context, local, Markers, predicate,
-		ClassConstraints, Owner, ProcInfo, MagicProcId,
+		ClassConstraints, Owner, Assertions, ProcInfo, MagicProcId,
 		MagicPredInfo) },
 
 	{ module_info_get_predicate_table(ModuleInfo0, PredTable0) },
Index: compiler/post_typecheck.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/post_typecheck.m,v
retrieving revision 1.9
diff -u -r1.9 post_typecheck.m
--- post_typecheck.m	1999/07/13 08:53:21	1.9
+++ post_typecheck.m	1999/07/14 00:37:44
@@ -107,7 +107,8 @@
 
 :- implementation.
 
-:- import_module typecheck, clause_to_proc, mode_util, inst_match, (inst).
+:- import_module (assertion), typecheck, clause_to_proc.
+:- import_module mode_util, inst_match, (inst).
 :- import_module mercury_to_mercury, prog_out, hlds_data, hlds_out, type_util.
 :- import_module globals, options.
 
@@ -594,11 +595,25 @@
 	post_typecheck__propagate_types_into_modes(ModuleInfo, PredId,
 		PredInfo0, PredInfo).
 
+	%
+	% Remove the assertion from the list of pred ids to be processed
+	% in the future and place the pred_info associated with the
+	% assertion into the assertion table.
+	% Also records for each predicate that is used in an assertion
+	% which assertion it is used in.
+	% 
 post_typecheck__finish_assertion(Module0, PredId, Module) :-
-	module_info_assertion_table(Module0, AssertionTable0),
-	assertion_table_add_assertion(PredId, AssertionTable0, AssertionTable),
-	module_info_set_assertion_table(Module0, AssertionTable, Module1),
-	module_info_remove_predid(Module1, PredId, Module).
+		% store into assertion table.
+	module_info_assertion_table(Module0, AssertTable0),
+	assertion_table_add_assertion(PredId, AssertTable0, Id, AssertTable),
+	module_info_set_assertion_table(Module0, AssertTable, Module1),
+		
+		% Remove from further processing.
+	module_info_remove_predid(Module1, PredId, Module2),
+
+		% record which predicates are used in assertions
+	assertion__goal(Id, Module2, Goal),
+	assertion__record_preds_used_in(Goal, Id, Module2, Module).
 	
 
 	% 
Index: compiler/notes/compiler_design.html
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/notes/compiler_design.html,v
retrieving revision 1.31
diff -u -r1.31 compiler_design.html
--- compiler_design.html	1999/07/13 02:56:12	1.31
+++ compiler_design.html	1999/07/14 00:35:01
@@ -254,7 +254,17 @@
 	  of typechecking, but it is actually called from purity
 	  analysis (see below).  It contains the stuff related to
 	  type checking that can't be done in the main type checking pass.
+	  It also removes assertions from further processing.
 	</ul>
+
+<dt> assertions
+
+	<dd>
+	assertion.m is the abstract interface to the assertion table.
+	Currently all the compiler does is type check the assertions and
+	record for each predicate that is used in an assertion, which
+	assertion it is used in.  The set up of the assertion table occurs
+	in post_typecheck__finish_assertion.
 
 <dt> purity analysis
 	
----
 +----------------------------------------------------------------------+
 | Peter Ross      M Sci/Eng Melbourne Uni                              |
 | petdr at cs.mu.oz.au  WWW: www.cs.mu.oz.au/~petdr/ ph: +61 3 9344 9158  |
 +----------------------------------------------------------------------+
--------------------------------------------------------------------------
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