[m-rev.] for review: remove unnecessary imports from .int files

Julien Fischer juliensf at cs.mu.OZ.AU
Fri Jan 21 02:51:29 AEDT 2005


Estimated hours taken: 22
Branches: main

Do not include `:- import_module' and `:- use_module' declarations
in the implementation section of .int and .int2 files unless
the types that they export are required by the definition of
an equivalence type.  This should help prevent unnecessary
recompilations when new imports are made in the implementation
of modules.

Break up check_hlds.type_util so that predicates that do
not require access to the HLDS are placed in a new module,
parse_tree.prog_type.  The above change requires some of
requires some of these predicates.  This also removes one
of the dependencies between the parse_tree package  on
modules of the check_hlds package.

Remove the remaining such dependency by moving
inst_constrains_unconstrained_var/1 from check_hlds.inst_util
to parse_tree.prog_mode.  None of the modules in parse_tree
now depend upon modules in check_hlds.

Modify the parser so that import_module declarations
that specify more than one module are replaced by multiple
import_module declarations, with one module per declaration.
This makes the above change easier to implement and is in
any case required by the upcoming diff for canonicalizing
module interfaces.  We also doe the same for use_module and
include_module declarations.

compiler/modules.m:
	Don't import modules in the implementation section
	of interface files unless they are required by the
	definition of equivalence types.

compiler/prog_type.m:
	New module.  Move procedures from type_util that do
	not depend on the HLDS to here so that we can use them
	when generating interface files.

	XXX There are probably others that could be moved as
	well - I only moved those that were immediately useful.

compiler/type_util.m:
	Delete the procedures that have been moved to the
	new prog_type module.

compiler/prog_io.m:
	Remove the dependency on check_hlds.inst_util.

compiler/prog_io_typeclass.m:
compiler/equiv_type.m:
	Remove dependencies on check_hlds.type_util.

compiler/prog_util.m:
	Add a predicate sym_name_get_module_name/2 that is
	similar to sym_name_get_module_name/3 except that it
	fails if the input is an unqualified sym_name.

compiler/inst_util.m:
	Delete inst_contains_unconstrained_var/1 from this
	module and copy it to prog_mode.m.

compiler/parse_tree.m:
	Include the new module.

	Do not import the check_hlds package as all dependencies
	on this package have been removed.

compiler/*.m:
	Minor changes to conform to the above.

compiler/notes/compiler_design.html:
	Mention the new module.

Julien.

Workspace:/home/earth/juliensf/ws56
Index: compiler/aditi_builtin_ops.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/aditi_builtin_ops.m,v
retrieving revision 1.12
diff -u -r1.12 aditi_builtin_ops.m
--- compiler/aditi_builtin_ops.m	19 Jan 2005 03:10:28 -0000	1.12
+++ compiler/aditi_builtin_ops.m	20 Jan 2005 12:11:14 -0000
@@ -46,6 +46,7 @@
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module assoc_list.
 :- import_module bool.
Index: compiler/assertion.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/assertion.m,v
retrieving revision 1.31
diff -u -r1.31 assertion.m
--- compiler/assertion.m	19 Jan 2005 03:10:28 -0000	1.31
+++ compiler/assertion.m	20 Jan 2005 04:22:11 -0000
@@ -152,6 +152,7 @@
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module string, bool, list, assoc_list, map, set, require, std_util.

Index: compiler/base_typeclass_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/base_typeclass_info.m,v
retrieving revision 1.31
diff -u -r1.31 base_typeclass_info.m
--- compiler/base_typeclass_info.m	19 Jan 2005 03:10:28 -0000	1.31
+++ compiler/base_typeclass_info.m	20 Jan 2005 13:18:17 -0000
@@ -44,6 +44,7 @@
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_type.

 :- import_module bool, int, string, map, std_util, require, term, assoc_list.

Index: compiler/bytecode_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/bytecode_gen.m,v
retrieving revision 1.85
diff -u -r1.85 bytecode_gen.m
--- compiler/bytecode_gen.m	19 Jan 2005 03:10:29 -0000	1.85
+++ compiler/bytecode_gen.m	20 Jan 2005 02:19:46 -0000
@@ -56,7 +56,7 @@
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_out.
-
+:- import_module parse_tree__prog_type.
 :- import_module bool, int, string, list, assoc_list, set, map, varset.
 :- import_module std_util, require, term, counter.

Index: compiler/code_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/code_info.m,v
retrieving revision 1.295
diff -u -r1.295 code_info.m
--- compiler/code_info.m	19 Jan 2005 03:10:30 -0000	1.295
+++ compiler/code_info.m	20 Jan 2005 02:19:57 -0000
@@ -61,6 +61,7 @@
 :- import_module ll_backend__llds_out.
 :- import_module ll_backend__var_locn.
 :- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_type.

 :- import_module varset.
 :- import_module set, stack.
Index: compiler/common.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/common.m,v
retrieving revision 1.73
diff -u -r1.73 common.m
--- compiler/common.m	14 Jun 2004 04:15:58 -0000	1.73
+++ compiler/common.m	20 Jan 2005 03:08:20 -0000
@@ -94,6 +94,7 @@
 :- import_module libs__globals.
 :- import_module libs__options.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.
 :- import_module transform_hlds__pd_cost.

 :- import_module bool, map, set, eqvclass, require, std_util, string, term.
Index: compiler/continuation_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/continuation_info.m,v
retrieving revision 1.56
diff -u -r1.56 continuation_info.m
--- compiler/continuation_info.m	19 Jan 2005 03:10:31 -0000	1.56
+++ compiler/continuation_info.m	20 Jan 2005 02:20:09 -0000
@@ -353,6 +353,7 @@
 :- import_module hlds__hlds_llds.
 :- import_module libs__options.
 :- import_module ll_backend__code_util.
+:- import_module parse_tree__prog_type.

 :- import_module int, string, require, term, varset.

Index: compiler/deep_profiling.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/deep_profiling.m,v
retrieving revision 1.30
diff -u -r1.30 deep_profiling.m
--- compiler/deep_profiling.m	19 Jan 2005 03:10:31 -0000	1.30
+++ compiler/deep_profiling.m	20 Jan 2005 12:19:38 -0000
@@ -41,6 +41,7 @@
 :- import_module mdbcomp__prim_data.
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.
 :- import_module transform_hlds.
 :- import_module transform_hlds__dependency_graph.

Index: compiler/det_report.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/det_report.m,v
retrieving revision 1.95
diff -u -r1.95 det_report.m
--- compiler/det_report.m	19 Jan 2005 03:10:32 -0000	1.95
+++ compiler/det_report.m	20 Jan 2005 03:13:31 -0000
@@ -150,6 +150,7 @@
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module assoc_list, bool, int, map, set, std_util, require, string.
 :- import_module getopt, term, varset.
Index: compiler/det_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/det_util.m,v
retrieving revision 1.27
diff -u -r1.27 det_util.m
--- compiler/det_util.m	14 Jun 2004 04:16:01 -0000	1.27
+++ compiler/det_util.m	20 Jan 2005 03:22:39 -0000
@@ -88,6 +88,7 @@
 :- import_module libs__options.
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module map, term, require, std_util.

Index: compiler/equiv_type.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/equiv_type.m,v
retrieving revision 1.41
diff -u -r1.41 equiv_type.m
--- compiler/equiv_type.m	19 Jan 2005 03:10:32 -0000	1.41
+++ compiler/equiv_type.m	20 Jan 2005 14:10:07 -0000
@@ -91,13 +91,12 @@

 :- implementation.

-% XXX we shouldn't import the HLDS here.
-:- import_module check_hlds__type_util.
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module assoc_list, bool, require, std_util, map, set, term, varset.

Index: compiler/equiv_type_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/equiv_type_hlds.m,v
retrieving revision 1.8
diff -u -r1.8 equiv_type_hlds.m
--- compiler/equiv_type_hlds.m	19 Jan 2005 03:10:32 -0000	1.8
+++ compiler/equiv_type_hlds.m	20 Jan 2005 02:20:33 -0000
@@ -35,6 +35,7 @@
 :- import_module mdbcomp__prim_data.
 :- import_module parse_tree__equiv_type.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_type.
 :- import_module recompilation.

 :- import_module bool, list, set, map, require, std_util, string, term, varset.
Index: compiler/exception_analysis.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/exception_analysis.m,v
retrieving revision 1.3
diff -u -r1.3 exception_analysis.m
--- compiler/exception_analysis.m	19 Jan 2005 03:10:32 -0000	1.3
+++ compiler/exception_analysis.m	20 Jan 2005 06:09:27 -0000
@@ -112,6 +112,7 @@
 :- import_module parse_tree.prog_data.
 :- import_module parse_tree.prog_out.
 :- import_module parse_tree.prog_util.
+:- import_module parse_tree.prog_type.
 :- import_module transform_hlds.dependency_graph.

 :- import_module bool, list, map, set, std_util, string, term, term_io, varset.
Index: compiler/foreign.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/foreign.m,v
retrieving revision 1.43
diff -u -r1.43 foreign.m
--- compiler/foreign.m	19 Jan 2005 03:10:33 -0000	1.43
+++ compiler/foreign.m	20 Jan 2005 13:06:21 -0000
@@ -245,6 +245,7 @@
 :- import_module parse_tree__modules.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module list, map, assoc_list, std_util, string, varset, int, term.
 :- import_module require.
@@ -769,7 +770,7 @@
 	sorry(this_file, "to_type_string for csharp").
 to_type_string(managed_cplusplus, mercury(Type)) = TypeString :-
 	(
-		type_util__var(Type, _)
+		prog_type__var(Type, _)
 	->
 		TypeString = "MR_Box"
 	;
Index: compiler/hhf.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hhf.m,v
retrieving revision 1.3
diff -u -r1.3 hhf.m
--- compiler/hhf.m	20 Dec 2004 12:46:31 -0000	1.3
+++ compiler/hhf.m	20 Jan 2005 04:33:42 -0000
@@ -35,6 +35,7 @@
 :- import_module hlds__passes_aux.
 :- import_module hlds__quantification.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module term, varset, map, list, set, std_util, require.

Index: compiler/higher_order.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/higher_order.m,v
retrieving revision 1.121
diff -u -r1.121 higher_order.m
--- compiler/higher_order.m	19 Jan 2005 03:10:34 -0000	1.121
+++ compiler/higher_order.m	20 Jan 2005 06:31:40 -0000
@@ -57,6 +57,7 @@
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.
 :- import_module transform_hlds__inlining.

 :- import_module assoc_list, bool, char, int, list, map, require, set.
Index: compiler/hlds_code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_code_util.m,v
retrieving revision 1.13
diff -u -r1.13 hlds_code_util.m
--- compiler/hlds_code_util.m	19 Jan 2005 03:10:34 -0000	1.13
+++ compiler/hlds_code_util.m	20 Jan 2005 02:20:47 -0000
@@ -46,6 +46,7 @@
 :- import_module mdbcomp__prim_data.
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_type.

 :- import_module bool, char, string, require, map, std_util, term.

Index: compiler/inst_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/inst_util.m,v
retrieving revision 1.34
diff -u -r1.34 inst_util.m
--- compiler/inst_util.m	19 Jan 2005 03:10:37 -0000	1.34
+++ compiler/inst_util.m	20 Jan 2005 12:33:19 -0000
@@ -125,13 +125,6 @@

 %-----------------------------------------------------------------------------%

-	% inst_contains_unconstrained_var(Inst) iff Inst includes an
-	% unconstrained inst variable.
-	%
-:- pred inst_contains_unconstrained_var((inst)::in) is semidet.
-
-%-----------------------------------------------------------------------------%
-
 :- implementation.

 :- import_module check_hlds__det_analysis.
@@ -1744,61 +1737,5 @@
 	ArgModes = list__duplicate(Arity - 1, InMode) ++ [OutMode].

 %-----------------------------------------------------------------------------%
-
-inst_contains_unconstrained_var(bound(_Uniqueness, BoundInsts)) :-
-	list.member(BoundInst, BoundInsts),
-	BoundInst = functor(_ConsId, ArgInsts),
-	list.member(ArgInst, ArgInsts),
-	inst_contains_unconstrained_var(ArgInst).
-inst_contains_unconstrained_var(ground(_Uniqueness, GroundInstInfo)) :-
-	GroundInstInfo = higher_order(PredInstInfo),
-	PredInstInfo = pred_inst_info(_PredOrFunc, Modes, _Detism),
-	list.member(Mode, Modes),
-	(
-		Mode = (Inst -> _)
-	;
-		Mode = (_ -> Inst)
-	;
-		Mode = user_defined_mode(_SymName, Insts),
-		list.member(Inst, Insts)
-	),
-	inst_contains_unconstrained_var(Inst).
-inst_contains_unconstrained_var(inst_var(_InstVar)).
-inst_contains_unconstrained_var(defined_inst(InstName)) :-
-	(
-		InstName = user_inst(_, Insts),
-		list.member(Inst, Insts),
-		inst_contains_unconstrained_var(Inst)
-	;
-		InstName = merge_inst(Inst, _),
-		inst_contains_unconstrained_var(Inst)
-	;
-		InstName = merge_inst(_, Inst),
-		inst_contains_unconstrained_var(Inst)
-	;
-		InstName = unify_inst(_, Inst, _, _),
-		inst_contains_unconstrained_var(Inst)
-	;
-		InstName = unify_inst(_, _, Inst, _),
-		inst_contains_unconstrained_var(Inst)
-	;
-		InstName = ground_inst(InstName1, _, _, _),
-		inst_contains_unconstrained_var(defined_inst(InstName1))
-	;
-		InstName = any_inst(InstName1, _, _, _),
-		inst_contains_unconstrained_var(defined_inst(InstName1))
-	;
-		InstName = shared_inst(InstName1),
-		inst_contains_unconstrained_var(defined_inst(InstName1))
-	;
-		InstName = mostly_uniq_inst(InstName1),
-		inst_contains_unconstrained_var(defined_inst(InstName1))
-	;
-		InstName = typed_inst(_, InstName1),
-		inst_contains_unconstrained_var(defined_inst(InstName1))
-	).
-inst_contains_unconstrained_var(abstract_inst(_SymName, Insts)) :-
-	list.member(Inst, Insts),
-	inst_contains_unconstrained_var(Inst).
-
+:- end_module inst_util.
 %-----------------------------------------------------------------------------%
Index: compiler/lambda.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/lambda.m,v
retrieving revision 1.93
diff -u -r1.93 lambda.m
--- compiler/lambda.m	19 Jan 2005 03:10:38 -0000	1.93
+++ compiler/lambda.m	20 Jan 2005 13:07:43 -0000
@@ -86,6 +86,7 @@
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 % HLDS modules
 :- import_module check_hlds__inst_match.
@@ -325,7 +326,7 @@
 		% to have universally quantified constraints.
 	map__keys(TCVarMap, AllConstraints),
 	map__apply_to_list(Vars, VarTypes, LambdaVarTypes),
-	list__map(type_util__vars, LambdaVarTypes, LambdaTypeVarsList),
+	list__map(prog_type__vars, LambdaVarTypes, LambdaTypeVarsList),
 	list__condense(LambdaTypeVarsList, LambdaTypeVars),
 	list__filter(lambda__constraint_contains_vars(LambdaTypeVars),
 		AllConstraints, UnivConstraints),
@@ -592,7 +593,7 @@

 lambda__constraint_contains_vars(LambdaVars, ClassConstraint) :-
 	ClassConstraint = constraint(_, ConstraintTypes),
-	list__map(type_util__vars, ConstraintTypes, ConstraintVarsList),
+	list__map(prog_type__vars, ConstraintTypes, ConstraintVarsList),
 	list__condense(ConstraintVarsList, ConstraintVars),
 		% Probably not the most efficient way of doing it, but I
 		% wouldn't think that it matters.
Index: compiler/magic.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/magic.m,v
retrieving revision 1.48
diff -u -r1.48 magic.m
--- compiler/magic.m	19 Jan 2005 03:10:39 -0000	1.48
+++ compiler/magic.m	20 Jan 2005 02:20:58 -0000
@@ -196,6 +196,7 @@
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_type.
 :- import_module transform_hlds__dead_proc_elim.
 :- import_module transform_hlds__dependency_graph.

Index: compiler/magic_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/magic_util.m,v
retrieving revision 1.43
diff -u -r1.43 magic_util.m
--- compiler/magic_util.m	19 Jan 2005 03:10:39 -0000	1.43
+++ compiler/magic_util.m	20 Jan 2005 02:32:36 -0000
@@ -134,6 +134,7 @@
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module assoc_list, int, require, string, term, varset.

Index: compiler/make_hlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/make_hlds.m,v
retrieving revision 1.492
diff -u -r1.492 make_hlds.m
--- compiler/make_hlds.m	19 Jan 2005 03:10:39 -0000	1.492
+++ compiler/make_hlds.m	20 Jan 2005 13:27:47 -0000
@@ -132,6 +132,7 @@
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.
 :- import_module recompilation.
 :- import_module transform_hlds__term_util.

@@ -3805,7 +3806,7 @@
 constrained_tvar_not_in_arg_types(ClassContext, ArgTypes, TVar) :-
 	ClassContext = constraints(UnivCs, ExistCs),
 	( Constraints = UnivCs ; Constraints = ExistCs ),
-	type_util__constraint_list_get_tvars(Constraints, TVars),
+	prog_type__constraint_list_get_tvars(Constraints, TVars),
 	list__member(TVar, TVars),
 	\+ term__contains_var_list(ArgTypes, TVar).

Index: compiler/ml_call_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_call_gen.m,v
retrieving revision 1.49
diff -u -r1.49 ml_call_gen.m
--- compiler/ml_call_gen.m	19 Jan 2005 03:10:42 -0000	1.49
+++ compiler/ml_call_gen.m	20 Jan 2005 13:08:11 -0000
@@ -132,6 +132,7 @@
 :- import_module mdbcomp__prim_data.
 :- import_module ml_backend__ml_closure_gen.
 :- import_module parse_tree__error_util.
+:- import_module parse_tree__prog_type.

 :- import_module bool, int, string, std_util, term, varset, require, map.

@@ -927,7 +928,7 @@
 			% For closure wrappers, the argument type_infos are
 			% stored in the `type_params' local, so we need to
 			% handle the GC tracing code specially
-			( type_util__var(CallerType, _TypeVar) ->
+			( prog_type__var(CallerType, _TypeVar) ->
 				ml_gen_local_for_output_arg(ArgVarName,
 					CalleeType, ArgNum, Context,
 					ArgVarDecl, !Info)
Index: compiler/ml_closure_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_closure_gen.m,v
retrieving revision 1.30
diff -u -r1.30 ml_closure_gen.m
--- compiler/ml_closure_gen.m	19 Jan 2005 03:10:42 -0000	1.30
+++ compiler/ml_closure_gen.m	20 Jan 2005 12:24:01 -0000
@@ -88,6 +88,7 @@
 :- import_module libs__options.
 :- import_module mdbcomp__prim_data.
 :- import_module parse_tree__error_util.
+:- import_module parse_tree__prog_type.

 % XXX The following modules depend on the LLDS,
 % so ideally they should not be used here.
Index: compiler/ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.146
diff -u -r1.146 ml_code_gen.m
--- compiler/ml_code_gen.m	19 Jan 2005 03:10:42 -0000	1.146
+++ compiler/ml_code_gen.m	20 Jan 2005 13:09:29 -0000
@@ -799,6 +799,7 @@
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__modules.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module assoc_list, bool, string, list.
 :- import_module int, set, term, require, std_util.
@@ -3117,7 +3118,7 @@
 			% Except for MC++, where polymorphic types
 			% are MR_Box.
 			(
-				type_util__var(OrigType, _),
+				prog_type__var(OrigType, _),
 				Lang \= managed_cplusplus
 			->
 				Cast = "(MR_Word) "
@@ -3326,7 +3327,7 @@
 			% `Word' in the C interface but `MR_Box' in the
 			% MLDS back-end.
 			(
-				( type_util__var(OrigType, _)
+				( prog_type__var(OrigType, _)
 				; Cast = yes
 				)
 			->
Index: compiler/ml_code_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_util.m,v
retrieving revision 1.86
diff -u -r1.86 ml_code_util.m
--- compiler/ml_code_util.m	19 Jan 2005 03:10:43 -0000	1.86
+++ compiler/ml_code_util.m	20 Jan 2005 05:12:39 -0000
@@ -757,6 +757,7 @@
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module counter, stack, string, require, set, term, varset.

Index: compiler/ml_type_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_type_gen.m,v
retrieving revision 1.39
diff -u -r1.39 ml_type_gen.m
--- compiler/ml_type_gen.m	19 Jan 2005 03:10:44 -0000	1.39
+++ compiler/ml_type_gen.m	20 Jan 2005 13:39:16 -0000
@@ -88,6 +88,7 @@
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module bool, int, string, list, map, std_util, term, require.

Index: compiler/ml_unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_unify_gen.m,v
retrieving revision 1.79
diff -u -r1.79 ml_unify_gen.m
--- compiler/ml_unify_gen.m	19 Jan 2005 03:10:44 -0000	1.79
+++ compiler/ml_unify_gen.m	20 Jan 2005 13:09:58 -0000
@@ -101,6 +101,7 @@
 :- import_module ml_backend__ml_util.
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module int, string, map, require, term, varset.
 :- import_module assoc_list, set.
@@ -935,7 +936,7 @@
 	->
 		varset__init(TypeVarSet0),
 		varset__new_var(TypeVarSet0, TypeVar, _TypeVarSet),
-		type_util__var(BoxedFieldType, TypeVar)
+		prog_type__var(BoxedFieldType, TypeVar)
 	;
 		BoxedFieldType = FieldType
 	).
Index: compiler/ml_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_util.m,v
retrieving revision 1.33
diff -u -r1.33 ml_util.m
--- compiler/ml_util.m	19 Jan 2005 03:10:44 -0000	1.33
+++ compiler/ml_util.m	20 Jan 2005 04:41:53 -0000
@@ -152,6 +152,7 @@
 :- import_module mdbcomp__prim_data.
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module bool, list, std_util.

Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.117
diff -u -r1.117 mlds.m
--- compiler/mlds.m	19 Jan 2005 03:10:44 -0000	1.117
+++ compiler/mlds.m	20 Jan 2005 02:21:27 -0000
@@ -1740,6 +1740,7 @@
 :- import_module libs__globals.
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__modules.
+:- import_module parse_tree__prog_type.

 :- import_module char, int, term, string, require, library.

Index: compiler/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.167
diff -u -r1.167 mlds_to_c.m
--- compiler/mlds_to_c.m	19 Jan 2005 03:10:44 -0000	1.167
+++ compiler/mlds_to_c.m	20 Jan 2005 02:21:42 -0000
@@ -85,6 +85,7 @@
 :- import_module parse_tree__modules.
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_type.

 :- import_module bool, int, string, library, list, map.
 :- import_module assoc_list, term, std_util, require.
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.143
diff -u -r1.143 mlds_to_il.m
--- compiler/mlds_to_il.m	19 Jan 2005 03:10:45 -0000	1.143
+++ compiler/mlds_to_il.m	20 Jan 2005 04:43:09 -0000
@@ -156,6 +156,7 @@
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module bool, int, map, string, set, list, assoc_list, term.
 :- import_module library, require, counter.
Index: compiler/mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.62
diff -u -r1.62 mlds_to_java.m
--- compiler/mlds_to_java.m	19 Jan 2005 03:10:45 -0000	1.62
+++ compiler/mlds_to_java.m	20 Jan 2005 04:43:24 -0000
@@ -113,6 +113,7 @@
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
 :- import_module parse_tree__prog_io.
+:- import_module parse_tree__prog_type.

 :- import_module bool, int, char, string, library, list, map, set.
 :- import_module assoc_list, term, std_util, require.
Index: compiler/mode_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mode_util.m,v
retrieving revision 1.162
diff -u -r1.162 mode_util.m
--- compiler/mode_util.m	19 Jan 2005 03:10:46 -0000	1.162
+++ compiler/mode_util.m	20 Jan 2005 03:25:31 -0000
@@ -162,6 +162,7 @@
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module require, int, string, map, set, term, std_util.
 :- import_module assoc_list, varset.
Index: compiler/modecheck_call.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modecheck_call.m,v
retrieving revision 1.56
diff -u -r1.56 modecheck_call.m
--- compiler/modecheck_call.m	19 Jan 2005 03:10:47 -0000	1.56
+++ compiler/modecheck_call.m	20 Jan 2005 02:22:03 -0000
@@ -91,6 +91,7 @@
 :- import_module hlds__instmap.
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_mode.
+:- import_module parse_tree__prog_type.

 :- import_module int, map, bool, set, require, term, varset.

Index: compiler/modecheck_unify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modecheck_unify.m,v
retrieving revision 1.73
diff -u -r1.73 modecheck_unify.m
--- compiler/modecheck_unify.m	19 Jan 2005 03:10:47 -0000	1.73
+++ compiler/modecheck_unify.m	20 Jan 2005 03:27:42 -0000
@@ -66,6 +66,7 @@
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module bool, list, map, std_util, int, set, require.
 :- import_module string, assoc_list.
Index: compiler/modes.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modes.m,v
retrieving revision 1.289
diff -u -r1.289 modes.m
--- compiler/modes.m	19 Jan 2005 03:10:47 -0000	1.289
+++ compiler/modes.m	20 Jan 2005 02:22:23 -0000
@@ -363,6 +363,7 @@
 :- import_module parse_tree__module_qual.
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_type.

 :- import_module int, set, term, varset.
 :- import_module list, map, bag, string, require, std_util.
Index: compiler/module_qual.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/module_qual.m,v
retrieving revision 1.95
diff -u -r1.95 module_qual.m
--- compiler/module_qual.m	19 Jan 2005 03:10:48 -0000	1.95
+++ compiler/module_qual.m	20 Jan 2005 14:11:03 -0000
@@ -114,7 +114,6 @@
 %-----------------------------------------------------------------------------%
 :- implementation.

-:- import_module check_hlds__type_util.
 :- import_module libs__globals.
 :- import_module libs__options.
 :- import_module parse_tree__mercury_to_mercury.
@@ -122,6 +121,7 @@
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module int, map, require, set, string, term, varset.
 :- import_module assoc_list.
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.312
diff -u -r1.312 modules.m
--- compiler/modules.m	19 Jan 2005 03:10:48 -0000	1.312
+++ compiler/modules.m	20 Jan 2005 15:41:40 -0000
@@ -780,12 +780,14 @@
 :- import_module parse_tree__prog_io_util.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.
 :- import_module parse_tree__source_file_map.
 :- import_module recompilation__version.

 :- import_module string, map, term, varset, dir, library.
 :- import_module assoc_list, relation, char, require.
-:- import_module getopt, multi_map, sparse_bitset.
+:- import_module getopt, multi_map, sparse_bitset, svset.
+:- import_module deconstruct.

 %-----------------------------------------------------------------------------%

@@ -1412,6 +1414,12 @@
 		map__init, !:IntTypesMap,
 		map__init, !:ImplTypesMap),

+	% Work out which module imports in the implementation section of
+	% the interface are required by the definitions of equivalence
+	% types in the implementation.
+	get_impl_imports_required_by_eqv_types(!.IntTypesMap, !.ImplTypesMap,
+		NecessaryImplImports),
+
 	% If a type in the implementation section doesn't have
 	% foreign type alternatives, make it abstract.
 	map__map_values(
@@ -1463,14 +1471,144 @@
 	IntItems = [make_pseudo_decl(interface) | IntItems0],

 	maybe_strip_import_decls(ImplItems1, ImplItems2),
-	( ImplItems2 = [] ->
+	strip_unnecessary_impl_imports(NecessaryImplImports, ImplItems2,
+		ImplItems3),
+
+	( ImplItems3 = [] ->
 		Items = IntItems
 	;
 		Items = IntItems ++
-			[make_pseudo_decl(implementation) | ImplItems2]
+			[make_pseudo_decl(implementation) | ImplItems3]
 	)
     ).

+	% strip_unnecessary_impl_imports(NecssaryModules, !Items).
+	%
+	% Remove all import_module and use_module declarations for
+	% modules that are not in `NecessaryModules',
+	%
+	% NOTE: This will only work if each item corresponding
+	% to an import_module or use_module declaration only imports
+	% a single module.  (This should be the case, see prog_io.m.)
+	%
+:- pred strip_unnecessary_impl_imports(set(module_name)::in, item_list::in,
+	item_list::out) is det.
+
+strip_unnecessary_impl_imports(NecessaryImports, !Items) :-
+	IsNecessaryImport = (pred(Item::in) is semidet :-
+		( Item = module_defn(_, Defn) - _ ->
+			(
+				( Defn = use(Module)
+				; Defn = import(Module))
+			->
+				( Module = module([ModuleName]) ->
+					set.member(ModuleName,
+						NecessaryImports)
+				;
+					unexpected(this_file,
+					"strip_unnecessary_impl_imports/3" ++
+					": non-singleton import or use decl")
+				)
+			;
+				true
+			)
+		;
+			true
+		)
+	),
+	list.filter(IsNecessaryImport, !Items).
+
+	% Return the set of modules that need to be imported in
+	% the implementation section of an interface file.  The
+	% required modules are those that occur on the rhs of
+	% and equivalence type.
+	%
+	% XXX We should probably only do this for abstract equivalence
+	% types.
+	%
+:- pred get_impl_imports_required_by_eqv_types(type_defn_map::in,
+	type_defn_map::in, set(module_name)::out) is det.
+
+get_impl_imports_required_by_eqv_types(_InterfaceTypes, ImplTypes, Modules) :-
+	%
+	% Grab all of the equivalence types that are defined in the
+	% implementation section.
+	%
+	map.foldl((pred(_TypeCtor::in, V::in, !.Equivs::in, !:Equivs::out)
+			is det :-
+		%
+		% A type may have multiple definitions because it may be
+		% defined as a foreign type and a mercury type.  We
+		% grab any equivalence types that are in there.
+		%
+		list.foldl((pred(T::in, !.Equivs::in, !:Equivs::out) is det :-
+			( T = eqv_type(Type) - _Item ->
+				list.cons(Type, !Equivs)
+			;
+				true
+			)
+		), V, !Equivs)
+	), ImplTypes, [], Equivs),
+	%
+	% Now we have a list of types, strip off the module
+	% qualifiers.
+	%
+	get_modules_from_types(Equivs, set.init, Modules).
+
+	% Given a list of types, return the set of modules that
+	% define these types.
+	%
+	% NOTE: This assumes that everything has been module
+	% qualified.
+	%
+:- pred get_modules_from_types(list(type)::in,
+	set(module_name)::in, set(module_name)::out) is det.
+
+get_modules_from_types(Types, !Modules) :-
+	list.foldl(get_modules_from_type, Types, !Modules).
+
+:- pred get_modules_from_type((type)::in,
+	set(module_name)::in, set(module_name)::out) is det.
+
+get_modules_from_type(Type, !Modules) :-
+	( type_to_ctor_and_args(Type, TypeCtor, Args) ->
+		TypeCtor = SymName - _Arity,
+		( sym_name_get_module_name(SymName, ModuleName) ->
+			svset.insert(ModuleName, !Modules),
+			get_modules_from_types(Args, !Modules)
+		;
+			(
+				type_ctor_is_higher_order(TypeCtor, _, _, _ )
+			->
+				% Higher-order types are builtin so just get
+				% the modules required by the arguments.
+				get_modules_from_types(Args, !Modules)
+			;
+				type_ctor_is_tuple(TypeCtor)
+			->
+				% Tuples are builtin so just get the modules
+				% required by the arguments.
+				get_modules_from_types(Args, !Modules)
+			;
+				( SymName = unqualified("int") ;
+				  SymName = unqualified("float") ;
+				  SymName = unqualified("string") ;
+				  SymName = unqualified("character")
+				)
+			->
+				% We don't need to import these modules
+				% as the types are builtin.
+				true
+			;
+				unexpected(this_file,
+					"get_modules_from_type/5: " ++
+					"unknown type encountered")
+			)
+		)
+	;
+		true
+	).
+
 :- type type_defn_map == multi_map(type_ctor,
 				pair(type_defn, item_and_context)).
 :- type type_defn_pair == pair(type_ctor, pair(type_defn, item_and_context)).
@@ -7195,5 +7333,13 @@
 		dir.directory_separator(Slash),
 	InstallNameOpt = InstallNameFlag++InstallNamePath++
 		char_to_string(Slash)++OutputFileName.
+
+%-----------------------------------------------------------------------------%
+
+:- func this_file = string.
+
+this_file = "modules.m".

+%-----------------------------------------------------------------------------%
+:- end_module modules.
 %-----------------------------------------------------------------------------%
Index: compiler/parse_tree.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/parse_tree.m,v
retrieving revision 1.8
diff -u -r1.8 parse_tree.m
--- compiler/parse_tree.m	19 Jan 2005 03:10:49 -0000	1.8
+++ compiler/parse_tree.m	20 Jan 2005 12:06:03 -0000
@@ -37,6 +37,7 @@
 % Utility routines.
 :- include_module prog_mode.
 :- include_module prog_util.
+:- include_module prog_type.
 :- include_module error_util.

 % Transformations that act on the parse tree,
@@ -53,13 +54,5 @@
 % :- include_module trans_opt.

 %-----------------------------------------------------------------------------%
-
-% XXX lots of stuff uses hlds_data__type_id and type_util.m.
-% XXX modules.m uses llds_out for the init names.
-
-:- implementation.
-
-:- import_module check_hlds.     % XXX for type_util.m
 :- end_module parse_tree.
-
 %-----------------------------------------------------------------------------%
Index: compiler/polymorphism.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/polymorphism.m,v
retrieving revision 1.257
diff -u -r1.257 polymorphism.m
--- compiler/polymorphism.m	19 Jan 2005 03:10:50 -0000	1.257
+++ compiler/polymorphism.m	20 Jan 2005 13:10:42 -0000
@@ -379,6 +379,7 @@
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module bool, int, string, set, map.
 :- import_module term, varset, require, assoc_list.
@@ -1185,7 +1186,7 @@
 	% Compute the type_info/type_class_info variables that would be
 	% used if this unification ends up being a complicated_unify.
 	%
-	type_util__vars(Type, TypeVars),
+	prog_type__vars(Type, TypeVars),
 	list__map_foldl(get_type_info_locn, TypeVars, TypeInfoLocns, !Info),
 	polymorphism__add_unification_typeinfos(TypeInfoLocns,
 		!Unification, !GoalInfo).
@@ -1199,7 +1200,7 @@
 	% Compute the type_info/type_class_info variables that would be
 	% used if this unification ends up being a complicated_unify.
 	%
-	type_util__vars(Type, TypeVars),
+	prog_type__vars(Type, TypeVars),
 	map__apply_to_list(TypeVars, TypeInfoMap, TypeInfoLocns),
 	polymorphism__add_unification_typeinfos(TypeInfoLocns,
 		!Unification, !GoalInfo).
@@ -2668,7 +2669,7 @@
 		% not in a type_info variable. make_typeclass_info_headvar
 		% will fix this up when the typeclass_info is created.
 		%
-		type_util__var(Type, TypeVar),
+		prog_type__var(Type, TypeVar),
 		polymorphism__new_type_info_var(Type, type_info, Var, !Info),
 		TypeInfoLocn = type_info(Var),
 		map__det_insert(TypeInfoMap0, TypeVar, TypeInfoLocn,
Index: compiler/post_typecheck.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/post_typecheck.m,v
retrieving revision 1.67
diff -u -r1.67 post_typecheck.m
--- compiler/post_typecheck.m	19 Jan 2005 03:10:50 -0000	1.67
+++ compiler/post_typecheck.m	20 Jan 2005 03:31:47 -0000
@@ -135,6 +135,7 @@
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module map, set, assoc_list, term, require, int.
 :- import_module string, varset.
Index: compiler/pragma_c_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/pragma_c_gen.m,v
retrieving revision 1.72
diff -u -r1.72 pragma_c_gen.m
--- compiler/pragma_c_gen.m	19 Jan 2005 03:10:51 -0000	1.72
+++ compiler/pragma_c_gen.m	20 Jan 2005 02:22:42 -0000
@@ -61,6 +61,7 @@
 :- import_module ll_backend__llds_out.
 :- import_module ll_backend__trace.
 :- import_module parse_tree__error_util.
+:- import_module parse_tree__prog_type.

 :- import_module bool, string, int, assoc_list, set, map.
 :- import_module std_util, require, term.
Index: compiler/proc_label.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/proc_label.m,v
retrieving revision 1.8
diff -u -r1.8 proc_label.m
--- compiler/proc_label.m	19 Jan 2005 03:10:51 -0000	1.8
+++ compiler/proc_label.m	20 Jan 2005 03:58:06 -0000
@@ -54,6 +54,7 @@
 :- import_module check_hlds__type_util.
 :- import_module hlds__special_pred.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module string, list, std_util, require.

Index: compiler/prog_io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io.m,v
retrieving revision 1.233
diff -u -r1.233 prog_io.m
--- compiler/prog_io.m	19 Jan 2005 03:10:51 -0000	1.233
+++ compiler/prog_io.m	20 Jan 2005 12:54:40 -0000
@@ -262,7 +262,6 @@

 :- implementation.

-:- import_module check_hlds__inst_util.
 :- import_module libs__globals.
 :- import_module libs__options.
 :- import_module parse_tree__modules.
@@ -272,6 +271,7 @@
 :- import_module parse_tree__prog_io_pragma.
 :- import_module parse_tree__prog_io_typeclass.
 :- import_module parse_tree__prog_io_util.
+:- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
 :- import_module recompilation.
@@ -895,6 +895,27 @@
 		ModuleName = ParentModuleName,
 		SourceFileName = SourceFileName0,
 		!:Items = [Item - Context | !.Items]
+	; Item = module_defn(VarSet, import(module(Modules))) ->
+		ImportItems = list.map(
+			make_pseudo_import_module_decl(VarSet, Context),
+			Modules),
+		SourceFileName = SourceFileName0,
+		ModuleName = ModuleName0,
+		list.append(ImportItems, !Items)
+	; Item = module_defn(VarSet, use(module(Modules))) ->
+		UseItems = list.map(
+			make_pseudo_use_module_decl(VarSet, Context),
+			Modules),
+		SourceFileName = SourceFileName0,
+		ModuleName = ModuleName0,
+		list.append(UseItems, !Items)
+ 	; Item = module_defn(VarSet, include_module(Modules)) ->
+ 		IncludeItems = list.map(
+ 			make_pseudo_include_module_decl(VarSet, Context),
+ 			Modules),
+ 		SourceFileName = SourceFileName0,
+ 		ModuleName = ModuleName0,
+ 		list.append(IncludeItems, !Items)
 	;
 		SourceFileName = SourceFileName0,
 		ModuleName = ModuleName0,
@@ -903,6 +924,25 @@
 	read_items_loop(ModuleName, SourceFileName, !Msgs, !Items, !Error,
 		!IO).

+:- func make_pseudo_import_module_decl(prog_varset, prog_context,
+	module_specifier) = item_and_context.
+
+make_pseudo_import_module_decl(Varset, Context, ModuleSpecifier) =
+	module_defn(Varset, import(module([ModuleSpecifier]))) - Context.
+
+:- func make_pseudo_use_module_decl(prog_varset, prog_context,
+	module_specifier) = item_and_context.
+
+make_pseudo_use_module_decl(Varset, Context, ModuleSpecifier) =
+	module_defn(Varset, use(module([ModuleSpecifier]))) - Context.
+
+:- func make_pseudo_include_module_decl(prog_varset, prog_context,
+	module_name) = item_and_context.
+
+make_pseudo_include_module_decl(Varset, Context, ModuleSpecifier) =
+	module_defn(Varset, include_module([ModuleSpecifier])) -
+		Context.
+
 %-----------------------------------------------------------------------------%

 	% read_item/1 reads a single item, and if it is a valid term
@@ -1881,7 +1921,7 @@
 	(
 		prog_io_util__convert_inst(no_allow_constrained_inst_var,
 			Term, Inst),
-		not inst_util__inst_contains_unconstrained_var(Inst)
+		not prog_mode__inst_contains_unconstrained_var(Inst)
 	->
 		ok(Inst)
 	;
Index: compiler/prog_io_typeclass.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_io_typeclass.m,v
retrieving revision 1.32
diff -u -r1.32 prog_io_typeclass.m
--- compiler/prog_io_typeclass.m	19 Jan 2005 03:10:52 -0000	1.32
+++ compiler/prog_io_typeclass.m	20 Jan 2005 13:11:44 -0000
@@ -41,10 +41,10 @@

 :- implementation.

-:- import_module check_hlds__type_util.
 :- import_module parse_tree__prog_io.
 :- import_module parse_tree__prog_io_goal.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module term, varset.
 :- import_module int, string, std_util, require, set, map.
@@ -129,7 +129,7 @@
 				% which do not occur in the type class
 				% parameters
 				%
-				type_util__constraint_list_get_tvars(
+				prog_type__constraint_list_get_tvars(
 					ConstraintList, ConstrainedVars),
 				list__member(Var, ConstrainedVars),
 				\+ list__member(Var, Vars)
@@ -299,7 +299,7 @@
 			list__member(Constraint, ConstraintList),
 			Constraint = constraint(_, Types),
 			list__member(Type, Types),
-			\+ type_util__var(Type, _),
+			\+ prog_type__var(Type, _),
 			\+ term__is_ground(Type)
 		->
 			Result = error(ErrorMessage, ConstraintsTerm)
@@ -484,13 +484,13 @@
 					% Are all the args of the
 					% functor variables?
 				list__map((pred(A::in, B::out) is semidet :-
-					type_util__var(A, B)
+					prog_type__var(A, B)
 				), Args1, _)
 			;
 					% Are all the args of the
 					% functor variables?
 				list__map((pred(A::in, B::out) is semidet :-
-					type_util__var(A, B)
+					prog_type__var(A, B)
 				), Args, _)
 			)
 		),
@@ -560,7 +560,7 @@
 		% argument types in the instance declaration
 		%
 		(
-			type_util__constraint_list_get_tvars(Constraints,
+			prog_type__constraint_list_get_tvars(Constraints,
 				TVars),
 			list__member(TVar, TVars),
 			\+ term__contains_var_list(Types, TVar)
Index: compiler/prog_mode.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_mode.m,v
retrieving revision 1.3
diff -u -r1.3 prog_mode.m
--- compiler/prog_mode.m	19 Jan 2005 03:10:52 -0000	1.3
+++ compiler/prog_mode.m	20 Jan 2005 12:33:23 -0000
@@ -90,6 +90,11 @@

 :- pred rename_apart_inst_vars(inst_varset::in, inst_varset::in,
 	list(mode)::in, list(mode)::out) is det.
+
+	% inst_contains_unconstrained_var(Inst) iff Inst includes an
+	% unconstrained inst variable.
+	%
+:- pred inst_contains_unconstrained_var((inst)::in) is semidet.

 %-----------------------------------------------------------------------------%

@@ -418,6 +423,64 @@
 		typed_inst(Type, Name)) :-
 	rename_apart_inst_vars_in_inst_name(Sub, Name0, Name).
 rename_apart_inst_vars_in_inst_name(_, typed_ground(U, T), typed_ground(U, T)).
+
+%-----------------------------------------------------------------------------%
+
+inst_contains_unconstrained_var(bound(_Uniqueness, BoundInsts)) :-
+	list.member(BoundInst, BoundInsts),
+	BoundInst = functor(_ConsId, ArgInsts),
+	list.member(ArgInst, ArgInsts),
+	inst_contains_unconstrained_var(ArgInst).
+inst_contains_unconstrained_var(ground(_Uniqueness, GroundInstInfo)) :-
+	GroundInstInfo = higher_order(PredInstInfo),
+	PredInstInfo = pred_inst_info(_PredOrFunc, Modes, _Detism),
+	list.member(Mode, Modes),
+	(
+		Mode = (Inst -> _)
+	;
+		Mode = (_ -> Inst)
+	;
+		Mode = user_defined_mode(_SymName, Insts),
+		list.member(Inst, Insts)
+	),
+	inst_contains_unconstrained_var(Inst).
+inst_contains_unconstrained_var(inst_var(_InstVar)).
+inst_contains_unconstrained_var(defined_inst(InstName)) :-
+	(
+		InstName = user_inst(_, Insts),
+		list.member(Inst, Insts),
+		inst_contains_unconstrained_var(Inst)
+	;
+		InstName = merge_inst(Inst, _),
+		inst_contains_unconstrained_var(Inst)
+	;
+		InstName = merge_inst(_, Inst),
+		inst_contains_unconstrained_var(Inst)
+	;
+		InstName = unify_inst(_, Inst, _, _),
+		inst_contains_unconstrained_var(Inst)
+	;
+		InstName = unify_inst(_, _, Inst, _),
+		inst_contains_unconstrained_var(Inst)
+	;
+		InstName = ground_inst(InstName1, _, _, _),
+		inst_contains_unconstrained_var(defined_inst(InstName1))
+	;
+		InstName = any_inst(InstName1, _, _, _),
+		inst_contains_unconstrained_var(defined_inst(InstName1))
+	;
+		InstName = shared_inst(InstName1),
+		inst_contains_unconstrained_var(defined_inst(InstName1))
+	;
+		InstName = mostly_uniq_inst(InstName1),
+		inst_contains_unconstrained_var(defined_inst(InstName1))
+	;
+		InstName = typed_inst(_, InstName1),
+		inst_contains_unconstrained_var(defined_inst(InstName1))
+	).
+inst_contains_unconstrained_var(abstract_inst(_SymName, Insts)) :-
+	list.member(Inst, Insts),
+	inst_contains_unconstrained_var(Inst).

 %-----------------------------------------------------------------------------%

Index: compiler/prog_type.m
===================================================================
RCS file: compiler/prog_type.m
diff -N compiler/prog_type.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ compiler/prog_type.m	20 Jan 2005 14:09:47 -0000
@@ -0,0 +1,365 @@
+%-----------------------------------------------------------------------------%
+% Copyright (C) 2005 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.
+%-----------------------------------------------------------------------------%
+%
+% Main author: fjh
+%
+% Utility predicates dealing with types that do not require access to the
+% HLDS.  (The predicates that do are in type_util.m.)
+%
+%-----------------------------------------------------------------------------%
+
+:- module parse_tree.prog_type.
+
+:- interface.
+
+:- import_module mdbcomp.prim_data.
+:- import_module parse_tree.prog_data.
+
+:- import_module list.
+
+%-----------------------------------------------------------------------------%
+
+	% type_is_higher_order(Type, Purity, PredOrFunc, ArgTypes, EvalMeth):
+	% succeeds iff Type is a higher-order predicate or function type with
+	% the specified argument types (for functions, the return type is
+	% appended to the end of the argument types), purity, and
+	% evaluation method.
+	%
+:- pred type_is_higher_order((type)::in, purity::out, pred_or_func::out,
+ 	lambda_eval_method::out, list(type)::out) is semidet.
+
+	% Succeed if the given type is a tuple type, returning
+	% the argument types.
+	%
+:- pred type_is_tuple((type)::in, list(type)::out) is semidet.
+
+	% type_has_variable_arity_ctor(Type, TypeCtor, TypeArgs)
+	% Check if the principal type constructor of Type is of variable arity.
+	% If yes, return the type constructor as TypeCtor and its args as
+	% TypeArgs. If not, fail.
+	%
+:- pred type_has_variable_arity_ctor((type)::in, type_ctor::out,
+	list(type)::out) is semidet.
+
+ 	% Given a non-variable type, return its type-id and argument types.
+	%
+:- pred type_to_ctor_and_args((type)::in, type_ctor::out, list(type)::out)
+ 	is semidet.
+
+	% type_ctor_is_higher_order(TypeCtor, PredOrFunc) succeeds iff
+	% TypeCtor is a higher-order predicate or function type.
+	%
+:- pred type_ctor_is_higher_order(type_ctor::in, purity::out, pred_or_func::out,
+	lambda_eval_method::out) is semidet.
+
+	% type_ctor_is_tuple(TypeCtor) succeeds iff TypeCtor is a tuple type.
+	%
+:- pred type_ctor_is_tuple(type_ctor::in) is semidet.
+
+	% Given a variable type, return its type variable.
+	%
+:- pred prog_type.var(type, tvar).
+:- mode prog_type.var(in, out) is semidet.
+:- mode prog_type.var(out, in) is det.
+
+	% Return a list of the type variables of a type.
+	%
+:- pred prog_type.vars((type)::in, list(tvar)::out) is det.
+
+	% Given a type_ctor and a list of argument types,
+	% construct a type.
+	%
+:- pred construct_type(type_ctor::in, list(type)::in, (type)::out) is det.
+
+:- pred construct_higher_order_type(purity::in, pred_or_func::in,
+	lambda_eval_method::in, list(type)::in, (type)::out) is det.
+
+:- pred construct_higher_order_pred_type(purity::in, lambda_eval_method::in,
+	list(type)::in, (type)::out) is det.
+
+:- pred construct_higher_order_func_type(purity::in, lambda_eval_method::in,
+	list(type)::in, (type)::in, (type)::out) is det.
+
+	% constraint_list_get_tvars(Constraints, TVars):
+	%	return the list of type variables contained in a
+	%	list of constraints
+	%
+:- pred constraint_list_get_tvars(list(class_constraint)::in, list(tvar)::out)
+	is det.
+
+	% constraint_list_get_tvars(Constraint, TVars):
+	%	return the list of type variables contained in a constraint.
+	%
+:- pred constraint_get_tvars(class_constraint::in, list(tvar)::out) is det.
+
+:- pred get_unconstrained_tvars(list(tvar)::in, list(class_constraint)::in,
+	list(tvar)::out) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- import_module parse_tree.prog_io.
+:- import_module parse_tree.prog_out.
+:- import_module parse_tree.prog_util.
+
+:- import_module std_util.
+:- import_module term.
+
+%-----------------------------------------------------------------------------%
+
+type_is_higher_order(Type, Purity, PredOrFunc, EvalMethod, PredArgTypes) :-
+	(
+		Type = term.functor(term.atom(PurityName), [BaseType], _),
+		purity_name(Purity0, PurityName),
+		type_is_higher_order_2(BaseType,
+			PredOrFunc0, EvalMethod0, PredArgTypes0)
+	->
+		Purity = Purity0,
+		PredOrFunc = PredOrFunc0,
+		EvalMethod = EvalMethod0,
+		PredArgTypes = PredArgTypes0
+	;
+		Purity = (pure),
+		type_is_higher_order_2(Type,
+			PredOrFunc, EvalMethod, PredArgTypes)
+	).
+
+% This parses a higher-order type without any purity indicator.
+:- pred type_is_higher_order_2((type)::in, pred_or_func::out,
+	lambda_eval_method::out, list(type)::out) is semidet.
+
+type_is_higher_order_2(Type, PredOrFunc, EvalMethod, PredArgTypes) :-
+	(
+		Type = term.functor(term.atom("="),
+			[FuncEvalAndArgs, FuncRetType], _)
+	->
+		get_lambda_eval_method_and_args("func", FuncEvalAndArgs,
+			EvalMethod, FuncArgTypes),
+		list.append(FuncArgTypes, [FuncRetType], PredArgTypes),
+		PredOrFunc = function
+	;
+		get_lambda_eval_method_and_args("pred",
+			Type, EvalMethod, PredArgTypes),
+		PredOrFunc = predicate
+	).
+
+	% From the type of a lambda expression, work out how it should
+	% be evaluated and extract the argument types.
+:- pred get_lambda_eval_method_and_args(string::in, (type)::in,
+	lambda_eval_method::out, list(type)::out) is semidet.
+
+get_lambda_eval_method_and_args(PorFStr, Type0, EvalMethod, ArgTypes) :-
+	Type0 = term.functor(term.atom(Functor), Args, _),
+	( Functor = PorFStr ->
+		EvalMethod = normal,
+		ArgTypes = Args
+	;
+		Args = [Type1],
+		Type1 = term.functor(term.atom(PorFStr), ArgTypes, _),
+		Functor = "aditi_bottom_up",
+		EvalMethod = (aditi_bottom_up)
+	).
+
+type_has_variable_arity_ctor(Type, TypeCtor, TypeArgs) :-
+	(
+		type_is_higher_order(Type, _Purity, PredOrFunc, _,
+			TypeArgs0)
+	->
+		TypeArgs = TypeArgs0,
+		PredOrFuncStr = prog_out.pred_or_func_to_str(PredOrFunc),
+		TypeCtor = unqualified(PredOrFuncStr) - 0
+	;
+		type_is_tuple(Type, TypeArgs1)
+	->
+		TypeArgs = TypeArgs1,
+		TypeCtor = unqualified("tuple") - 0
+	;
+		fail
+	).
+
+type_to_ctor_and_args(Type, SymName - Arity, Args) :-
+	Type \= term.variable(_),
+
+	% higher order types may have representations where
+	% their arguments don't directly correspond to the
+	% arguments of the term.
+	(
+		type_is_higher_order(Type, Purity, PredOrFunc,
+			EvalMethod, PredArgTypes)
+	->
+		Args = PredArgTypes,
+		list.length(Args, Arity0),
+		adjust_func_arity(PredOrFunc, Arity, Arity0),
+		(
+			PredOrFunc = predicate,
+			PorFStr = "pred"
+		;
+			PredOrFunc = function,
+			PorFStr = "func"
+		),
+		SymName0 = unqualified(PorFStr),
+		(
+			EvalMethod = (aditi_bottom_up),
+			insert_module_qualifier("aditi_bottom_up", SymName0,
+				SymName1)
+		;
+			EvalMethod = normal,
+			SymName1 = SymName0
+		),
+		(
+			Purity = (pure),
+			SymName = SymName1
+		;
+			Purity = (semipure),
+			insert_module_qualifier("semipure", SymName1, SymName)
+		;
+			Purity = (impure),
+			insert_module_qualifier("impure", SymName1, SymName)
+		)
+	;
+		sym_name_and_args(Type, SymName, Args),
+
+		% `private_builtin:constraint' is introduced by polymorphism,
+		% and should only appear as the argument of a
+		% `typeclass:info/1' type.
+		% It behaves sort of like a type variable, so according to the
+		% specification of `type_to_ctor_and_args', it should
+		% cause failure. There isn't a definition in the type table.
+		\+ (
+			SymName = qualified(ModuleName, UnqualName),
+			UnqualName = "constraint",
+			mercury_private_builtin_module(PrivateBuiltin),
+			ModuleName = PrivateBuiltin
+		),
+		list.length(Args, Arity)
+	).
+
+type_ctor_is_higher_order(SymName - _Arity, Purity, PredOrFunc, EvalMethod) :-
+	get_purity_and_eval_method(SymName, Purity, EvalMethod, PorFStr),
+	(
+		PorFStr = "pred",
+		PredOrFunc = predicate
+	;
+		PorFStr = "func",
+		PredOrFunc = function
+	).
+
+:- pred get_purity_and_eval_method(sym_name::in, purity::out,
+	lambda_eval_method::out, string::out) is semidet.
+
+get_purity_and_eval_method(SymName, Purity, EvalMethod, PorFStr) :-
+	(
+		SymName = qualified(unqualified(Qualifier), PorFStr),
+		(
+			Qualifier = "aditi_bottom_up",
+			EvalMethod = (aditi_bottom_up),
+			Purity = (pure)
+		;
+			Qualifier = "impure",
+			Purity = (impure),
+			EvalMethod = normal
+		;
+			Qualifier = "semipure",
+			Purity = (semipure),
+			EvalMethod = normal
+		)
+	;
+		SymName = unqualified(PorFStr),
+		EvalMethod = normal,
+		Purity = (pure)
+	).
+
+type_is_tuple(Type, ArgTypes) :-
+	type_to_ctor_and_args(Type, TypeCtor, ArgTypes),
+	type_ctor_is_tuple(TypeCtor).
+
+type_ctor_is_tuple(unqualified("{}") - _).
+
+prog_type.var(term.variable(Var), Var).
+
+prog_type.vars(Type, Tvars) :-
+	term.vars(Type, Tvars).
+
+construct_type(TypeCtor, Args, Type) :-
+	(
+		type_ctor_is_higher_order(TypeCtor, Purity, PredOrFunc,
+			EvalMethod)
+	->
+		construct_higher_order_type(Purity, PredOrFunc, EvalMethod,
+			Args, Type)
+	;
+		TypeCtor = SymName - _,
+		construct_qualified_term(SymName, Args, Type)
+	).
+
+construct_higher_order_type(Purity, PredOrFunc, EvalMethod, ArgTypes, Type) :-
+	(
+		PredOrFunc = predicate,
+		construct_higher_order_pred_type(Purity, EvalMethod, ArgTypes,
+			Type)
+	;
+		PredOrFunc = function,
+		pred_args_to_func_args(ArgTypes, FuncArgTypes, FuncRetType),
+		construct_higher_order_func_type(Purity, EvalMethod,
+			FuncArgTypes, FuncRetType, Type)
+	).
+
+construct_higher_order_pred_type(Purity, EvalMethod, ArgTypes, Type) :-
+	construct_qualified_term(unqualified("pred"),
+		ArgTypes, Type0),
+	qualify_higher_order_type(EvalMethod, Type0, Type1),
+	Type = add_purity_annotation(Purity, Type1).
+
+construct_higher_order_func_type(Purity, EvalMethod, ArgTypes, RetType, Type) :-
+	construct_qualified_term(unqualified("func"), ArgTypes, Type0),
+	qualify_higher_order_type(EvalMethod, Type0, Type1),
+	Type2 = term.functor(term.atom("="), [Type1, RetType],
+			term.context_init),
+	Type = add_purity_annotation(Purity, Type2).
+
+:- func add_purity_annotation(purity, (type)) = (type).
+
+add_purity_annotation(Purity, Type0) = Type :-
+	(
+		Purity = (pure),
+		Type = Type0
+	;
+		Purity = (semipure),
+		Type = term.functor(term.atom("semipure"), [Type0],
+			term.context_init)
+	;
+		Purity = (impure),
+		Type = term.functor(term.atom("impure"), [Type0],
+			term.context_init)
+	).
+
+:- pred qualify_higher_order_type(lambda_eval_method::in, (type)::in,
+	(type)::out) is det.
+
+qualify_higher_order_type(normal, Type, Type).
+qualify_higher_order_type((aditi_bottom_up), Type0,
+	term.functor(term.atom("aditi_bottom_up"), [Type0], Context)) :-
+	term.context_init(Context).
+
+%-----------------------------------------------------------------------------%
+
+constraint_list_get_tvars(Constraints, TVars) :-
+	list.map(constraint_get_tvars, Constraints, TVarsList),
+	list.condense(TVarsList, TVars).
+
+constraint_get_tvars(constraint(_Name, Args), TVars) :-
+	term.vars_list(Args, TVars).
+
+get_unconstrained_tvars(Tvars, Constraints, Unconstrained) :-
+	constraint_list_get_tvars(Constraints, ConstrainedTvars),
+	list.delete_elems(Tvars, ConstrainedTvars, Unconstrained0),
+	list.remove_dups(Unconstrained0, Unconstrained).
+
+%-----------------------------------------------------------------------------%
+:- end_module prog_type.
+%-----------------------------------------------------------------------------%
Index: compiler/prog_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/prog_util.m,v
retrieving revision 1.70
diff -u -r1.70 prog_util.m
--- compiler/prog_util.m	19 Jan 2005 03:10:53 -0000	1.70
+++ compiler/prog_util.m	20 Jan 2005 02:19:22 -0000
@@ -86,6 +86,12 @@

 :- pred unqualify_name(sym_name::in, string::out) is det.

+	% sym_name_get_module_name(SymName, ModName):-
+	% Given a symbol name, return the module qualifiers(s).
+	% Fails if the symbol is unqualified.
+	%
+:- pred sym_name_get_module_name(sym_name::in, module_name::out) is semidet.
+
 	% sym_name_get_module_name(SymName, DefaultModName, ModName):
 	% Given a symbol name, return the module qualifier(s).
 	% If the symbol is unqualified, then return the specified default
@@ -278,6 +284,8 @@
 :- implementation.

 :- import_module parse_tree__mercury_to_mercury.
+:- import_module parse_tree__prog_io.
+:- import_module parse_tree__prog_out.

 :- import_module bool, require, string, int, map, varset.

@@ -315,6 +323,9 @@
 unqualify_name(unqualified(PredName), PredName).
 unqualify_name(qualified(_ModuleName, PredName), PredName).

+sym_name_get_module_name(unqualified(_), _) :- fail.
+sym_name_get_module_name(qualified(ModuleName, _), ModuleName).
+
 sym_name_get_module_name(unqualified(_), ModuleName, ModuleName).
 sym_name_get_module_name(qualified(ModuleName, _PredName), _, ModuleName).

@@ -683,4 +694,5 @@
 	).

 %-----------------------------------------------------------------------------%
+:- end_module prog_util.
 %-----------------------------------------------------------------------------%
Index: compiler/pseudo_type_info.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/pseudo_type_info.m,v
retrieving revision 1.14
diff -u -r1.14 pseudo_type_info.m
--- compiler/pseudo_type_info.m	19 Jan 2005 03:10:53 -0000	1.14
+++ compiler/pseudo_type_info.m	20 Jan 2005 13:12:07 -0000
@@ -63,6 +63,7 @@
 :- import_module check_hlds__type_util.
 :- import_module mdbcomp__prim_data.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module int, list, term, std_util, require.

@@ -113,7 +114,7 @@
 					PseudoArgs)
 			)
 		)
-	; type_util__var(Type, Var) ->
+	; prog_type__var(Type, Var) ->
 		% In the case of a type variable, we need to assign a
 		% variable number *for this constructor*, i.e. taking
 		% only the existentially quantified variables of
Index: compiler/purity.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/purity.m,v
retrieving revision 1.69
diff -u -r1.69 purity.m
--- compiler/purity.m	19 Jan 2005 03:10:53 -0000	1.69
+++ compiler/purity.m	20 Jan 2005 03:34:10 -0000
@@ -188,6 +188,7 @@
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module map, varset, term, string, require, std_util.
 :- import_module assoc_list, bool, int, list, set.
Index: compiler/recompilation.usage.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/recompilation.usage.m,v
retrieving revision 1.14
diff -u -r1.14 recompilation.usage.m
--- compiler/recompilation.usage.m	19 Jan 2005 03:10:53 -0000	1.14
+++ compiler/recompilation.usage.m	20 Jan 2005 04:40:43 -0000
@@ -92,6 +92,7 @@
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_util.
 :- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_type.
 :- import_module recompilation__version.

 :- import_module assoc_list, bool, int, require, svmap.
Index: compiler/rl.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rl.m,v
retrieving revision 1.30
diff -u -r1.30 rl.m
--- compiler/rl.m	19 Jan 2005 03:10:54 -0000	1.30
+++ compiler/rl.m	20 Jan 2005 02:56:39 -0000
@@ -686,6 +686,7 @@
 :- import_module libs__options.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module bool, int, require, string.

Index: compiler/rl_exprn.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rl_exprn.m,v
retrieving revision 1.45
diff -u -r1.45 rl_exprn.m
--- compiler/rl_exprn.m	19 Jan 2005 03:10:54 -0000	1.45
+++ compiler/rl_exprn.m	20 Jan 2005 02:59:28 -0000
@@ -153,6 +153,7 @@
 :- import_module mdbcomp__prim_data.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.
 :- import_module transform_hlds__inlining.
 :- import_module backend_libs__name_mangle.

Index: compiler/rl_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rl_gen.m,v
retrieving revision 1.17
diff -u -r1.17 rl_gen.m
--- compiler/rl_gen.m	19 Jan 2005 03:10:54 -0000	1.17
+++ compiler/rl_gen.m	20 Jan 2005 02:22:59 -0000
@@ -44,6 +44,7 @@
 :- import_module mdbcomp__prim_data.
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_type.
 :- import_module transform_hlds__dependency_graph.
 :- import_module transform_hlds__inlining.

Index: compiler/rl_key.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/rl_key.m,v
retrieving revision 1.19
diff -u -r1.19 rl_key.m
--- compiler/rl_key.m	19 Jan 2005 03:10:54 -0000	1.19
+++ compiler/rl_key.m	20 Jan 2005 03:04:14 -0000
@@ -61,6 +61,7 @@
 :- import_module hlds__special_pred.
 :- import_module mdbcomp__prim_data.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module assoc_list, bool, int, require, set, std_util.

Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.135
diff -u -r1.135 simplify.m
--- compiler/simplify.m	19 Jan 2005 03:10:55 -0000	1.135
+++ compiler/simplify.m	20 Jan 2005 03:44:52 -0000
@@ -101,6 +101,7 @@
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.
 :- import_module transform_hlds__const_prop.
 :- import_module transform_hlds__pd_cost.

Index: compiler/size_prof.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/size_prof.m,v
retrieving revision 1.12
diff -u -r1.12 size_prof.m
--- compiler/size_prof.m	19 Jan 2005 03:10:55 -0000	1.12
+++ compiler/size_prof.m	20 Jan 2005 04:41:06 -0000
@@ -119,6 +119,7 @@
 :- import_module check_hlds__mode_util.
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.
 :- import_module transform_hlds__term_norm.

 :- import_module bool, int, string, list, assoc_list, map, set, std_util.
Index: compiler/stack_opt.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stack_opt.m,v
retrieving revision 1.13
diff -u -r1.13 stack_opt.m
--- compiler/stack_opt.m	14 Jun 2004 04:16:37 -0000	1.13
+++ compiler/stack_opt.m	20 Jan 2005 02:23:11 -0000
@@ -105,6 +105,7 @@
 :- import_module ll_backend__store_alloc.
 :- import_module parse_tree__mercury_to_mercury.
 :- import_module parse_tree__prog_data.
+:- import_module parse_tree__prog_type.

 :- import_module counter, bool, int, list, assoc_list.
 :- import_module map, set, std_util, require, term, varset.
Index: compiler/stratify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/stratify.m,v
retrieving revision 1.35
diff -u -r1.35 stratify.m
--- compiler/stratify.m	19 Jan 2005 03:10:56 -0000	1.35
+++ compiler/stratify.m	20 Jan 2005 02:23:24 -0000
@@ -58,6 +58,7 @@
 :- import_module mdbcomp__prim_data.
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_type.
 :- import_module transform_hlds__dependency_graph.

 :- import_module assoc_list, map, list, set, bool, std_util, relation, require.
Index: compiler/switch_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/switch_util.m,v
retrieving revision 1.19
diff -u -r1.19 switch_util.m
--- compiler/switch_util.m	14 Jun 2004 04:16:38 -0000	1.19
+++ compiler/switch_util.m	20 Jan 2005 02:23:35 -0000
@@ -140,6 +140,7 @@
 %-----------------------------------------------------------------------------%

 :- implementation.
+:- import_module parse_tree__prog_type.
 :- import_module char, int, string, require.

 %-----------------------------------------------------------------------------%
Index: compiler/table_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/table_gen.m,v
retrieving revision 1.74
diff -u -r1.74 table_gen.m
--- compiler/table_gen.m	19 Jan 2005 03:10:56 -0000	1.74
+++ compiler/table_gen.m	20 Jan 2005 13:12:29 -0000
@@ -78,6 +78,7 @@
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.
 :- import_module transform_hlds__const_prop.

 :- import_module term, varset.
@@ -2180,7 +2181,7 @@
 		lookup_tabling_category(TypeCat, MaybeCatStringStep),
 		(
 			MaybeCatStringStep = no,
-			( type_util__vars(Type, []) ->
+			( prog_type__vars(Type, []) ->
 				LookupPredName = "table_lookup_insert_user",
 				Step = table_trie_step_user(Type)
 			;
Index: compiler/term_norm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_norm.m,v
retrieving revision 1.5
diff -u -r1.5 term_norm.m
--- compiler/term_norm.m	5 Sep 2004 23:52:46 -0000	1.5
+++ compiler/term_norm.m	20 Jan 2005 02:23:46 -0000
@@ -58,6 +58,7 @@
 :- import_module hlds__hlds_data.
 :- import_module libs__options.
 :- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_type.

 :- import_module assoc_list, bool, map, require, std_util.

Index: compiler/term_traversal.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_traversal.m,v
retrieving revision 1.31
diff -u -r1.31 term_traversal.m
--- compiler/term_traversal.m	14 Jun 2004 04:16:39 -0000	1.31
+++ compiler/term_traversal.m	20 Jan 2005 02:24:02 -0000
@@ -108,6 +108,7 @@
 :- import_module check_hlds__type_util.
 :- import_module hlds__hlds_data.
 :- import_module parse_tree__error_util.
+:- import_module parse_tree__prog_type.

 :- import_module assoc_list, bool, int, require, string.

Index: compiler/term_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/term_util.m,v
retrieving revision 1.37
diff -u -r1.37 term_util.m
--- compiler/term_util.m	14 Jun 2004 04:16:39 -0000	1.37
+++ compiler/term_util.m	20 Jan 2005 02:24:13 -0000
@@ -156,6 +156,7 @@
 :- import_module libs__options.
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_type.

 :- import_module assoc_list, require, string.

Index: compiler/type_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/type_util.m,v
retrieving revision 1.146
diff -u -r1.146 type_util.m
--- compiler/type_util.m	19 Jan 2005 03:10:57 -0000	1.146
+++ compiler/type_util.m	20 Jan 2005 13:12:43 -0000
@@ -37,33 +37,6 @@

 :- pred type_ctor_is_atomic(type_ctor::in, module_info::in) is semidet.

-	% type_is_higher_order(Type, Purity, PredOrFunc, ArgTypes, EvalMeth):
-	% succeeds iff Type is a higher-order predicate or function type with
-	% the specified argument types (for functions, the return type is
-	% appended to the end of the argument types), purity, and
-	% evaluation method.
-:- pred type_is_higher_order((type)::in, purity::out, pred_or_func::out,
-	lambda_eval_method::out, list(type)::out) is semidet.
-
-	% Succeed if the given type is a tuple type, returning
-	% the argument types.
-:- pred type_is_tuple((type)::in, list(type)::out) is semidet.
-
-	% type_has_variable_arity_ctor(Type, TypeCtor, TypeArgs)
-	% Check if the principal type constructor of Type is of variable arity.
-	% If yes, return the type constructor as TypeCtor and its args as
-	% TypeArgs. If not, fail.
-:- pred type_has_variable_arity_ctor((type)::in, type_ctor::out,
-	list(type)::out) is semidet.
-
-	% type_ctor_is_higher_order(TypeCtor, PredOrFunc) succeeds iff
-	% TypeCtor is a higher-order predicate or function type.
-:- pred type_ctor_is_higher_order(type_ctor::in, purity::out, pred_or_func::out,
-	lambda_eval_method::out) is semidet.
-
-	% type_ctor_is_tuple(TypeCtor) succeeds iff TypeCtor is a tuple type.
-:- pred type_ctor_is_tuple(type_ctor::in) is semidet.
-
 	% The list of type_ctors which are builtins which do not have a
 	% hlds_type_defn.
 :- func builtin_type_ctors_with_no_hlds_type_defn = list(type_ctor).
@@ -197,34 +170,9 @@
 	;	void_type
 	;	user_ctor_type.

-	% Given a non-variable type, return its type-id and argument types.
-
-:- pred type_to_ctor_and_args((type)::in, type_ctor::out, list(type)::out)
-	is semidet.
-
-	% Given a variable type, return its type variable.
-
-:- pred type_util__var(type, tvar).
-:- mode type_util__var(in, out) is semidet.
-:- mode type_util__var(out, in) is det.
-
 :- pred canonicalize_type_args(type_ctor::in, list(type)::in, list(type)::out)
 	is det.

-	% Given a type_ctor and a list of argument types,
-	% construct a type.
-
-:- pred construct_type(type_ctor::in, list(type)::in, (type)::out) is det.
-
-:- pred construct_higher_order_type(purity::in, pred_or_func::in,
-	lambda_eval_method::in, list(type)::in, (type)::out) is det.
-
-:- pred construct_higher_order_pred_type(purity::in, lambda_eval_method::in,
-	list(type)::in, (type)::out) is det.
-
-:- pred construct_higher_order_func_type(purity::in, lambda_eval_method::in,
-	list(type)::in, (type)::in, (type)::out) is det.
-
 	% Construct builtin types.
 :- func int_type = (type).
 :- func string_type = (type).
@@ -388,21 +336,17 @@

 :- pred type_unify_list(list(type)::in, list(type)::in, list(tvar)::in,
 	tsubst::in, tsubst::out) is semidet.
-
-	% Return a list of the type variables of a type.
-
-:- pred type_util__vars((type)::in, list(tvar)::out) is det.
-
+
 	% Return a list of the type variables of a type,
 	% ignoring any type variables if the variable in
 	% question is a type-info
-
+	%
 :- pred type_util__real_vars((type)::in, list(tvar)::out) is det.

 	% type_list_subsumes(TypesA, TypesB, Subst) succeeds iff the list
 	% TypesA subsumes (is more general than) TypesB, producing a
 	% type substitution which when applied to TypesA will give TypesB.
-
+	%
 :- pred type_list_subsumes(list(type)::in, list(type)::in, tsubst::out)
 	is semidet.

@@ -442,7 +386,7 @@
 	%
 	% If tvar maps to a another type variable, we keep the new
 	% variable, if it maps to a type, we remove it from the map.
-
+	%
 :- pred apply_substitutions_to_var_map(map(tvar, type_info_locn)::in,
 	tsubst::in, map(tvar, type)::in, map(prog_var, prog_var)::in,
 	map(tvar, type_info_locn)::out) is det.
@@ -451,7 +395,7 @@
 	% and substitution to rename tvars and a variable substition to
 	% rename vars. The type renaming is applied before the type
 	% substitution.
-
+	%
 :- pred apply_substitutions_to_typeclass_var_map(
 	map(class_constraint, prog_var)::in, tsubst::in, map(tvar, type)::in,
 	map(prog_var, prog_var)::in, map(class_constraint, prog_var)::out)
@@ -508,20 +452,6 @@
 	%
 :- func cons_id_adjusted_arity(module_info, type, cons_id) = int.

-	% constraint_list_get_tvars(Constraints, TVars):
-	%	return the list of type variables contained in a
-	%	list of constraints
-	%
-:- pred constraint_list_get_tvars(list(class_constraint)::in, list(tvar)::out)
-	is det.
-
-	% constraint_list_get_tvars(Constraint, TVars):
-	%	return the list of type variables contained in a constraint.
-:- pred constraint_get_tvars(class_constraint::in, list(tvar)::out) is det.
-
-:- pred get_unconstrained_tvars(list(tvar)::in, list(class_constraint)::in,
-	list(tvar)::out) is det.
-
 %-----------------------------------------------------------------------------%

 	% If possible, get the argument types for the cons_id.
@@ -560,6 +490,7 @@
 :- import_module parse_tree__prog_io_goal.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module bool, char, int, string.
 :- import_module assoc_list, require, varset.
@@ -599,8 +530,6 @@

 type_ctor_is_array(qualified(unqualified("array"), "array") - 1).

-type_util__var(term__variable(Var), Var).
-
 type_ctor_has_hand_defined_rtti(Type, Body) :-
 	Type = qualified(mercury_private_builtin_module, Name) - 1,
 	( Name = "type_info"
@@ -694,117 +623,6 @@
 		TypeCategory = user_ctor_type
 	).

-type_is_higher_order(Type, Purity, PredOrFunc, EvalMethod, PredArgTypes) :-
-	(
-		Type = term__functor(term__atom(PurityName), [BaseType], _),
-		purity_name(Purity0, PurityName),
-		type_is_higher_order_2(BaseType,
-			PredOrFunc0, EvalMethod0, PredArgTypes0)
-	->
-		Purity = Purity0,
-		PredOrFunc = PredOrFunc0,
-		EvalMethod = EvalMethod0,
-		PredArgTypes = PredArgTypes0
-	;
-		Purity = (pure),
-		type_is_higher_order_2(Type,
-			PredOrFunc, EvalMethod, PredArgTypes)
-	).
-
-% This parses a higher-order type without any purity indicator.
-:- pred type_is_higher_order_2((type)::in, pred_or_func::out,
-	lambda_eval_method::out, list(type)::out) is semidet.
-
-type_is_higher_order_2(Type, PredOrFunc, EvalMethod, PredArgTypes) :-
-	(
-		Type = term__functor(term__atom("="),
-			[FuncEvalAndArgs, FuncRetType], _)
-	->
-		get_lambda_eval_method_and_args("func", FuncEvalAndArgs,
-			EvalMethod, FuncArgTypes),
-		list__append(FuncArgTypes, [FuncRetType], PredArgTypes),
-		PredOrFunc = function
-	;
-		get_lambda_eval_method_and_args("pred",
-			Type, EvalMethod, PredArgTypes),
-		PredOrFunc = predicate
-	).
-
-	% From the type of a lambda expression, work out how it should
-	% be evaluated and extract the argument types.
-:- pred get_lambda_eval_method_and_args(string::in, (type)::in,
-	lambda_eval_method::out, list(type)::out) is semidet.
-
-get_lambda_eval_method_and_args(PorFStr, Type0, EvalMethod, ArgTypes) :-
-	Type0 = term__functor(term__atom(Functor), Args, _),
-	( Functor = PorFStr ->
-		EvalMethod = normal,
-		ArgTypes = Args
-	;
-		Args = [Type1],
-		Type1 = term__functor(term__atom(PorFStr), ArgTypes, _),
-		Functor = "aditi_bottom_up",
-		EvalMethod = (aditi_bottom_up)
-	).
-
-type_has_variable_arity_ctor(Type, TypeCtor, TypeArgs) :-
-	(
-		type_is_higher_order(Type, _Purity, PredOrFunc, _,
-			TypeArgs0)
-	->
-		TypeArgs = TypeArgs0,
-		PredOrFuncStr = prog_out__pred_or_func_to_str(PredOrFunc),
-		TypeCtor = unqualified(PredOrFuncStr) - 0
-	;
-		type_is_tuple(Type, TypeArgs1)
-	->
-		TypeArgs = TypeArgs1,
-		TypeCtor = unqualified("tuple") - 0
-	;
-		fail
-	).
-
-type_ctor_is_higher_order(SymName - _Arity, Purity, PredOrFunc, EvalMethod) :-
-	get_purity_and_eval_method(SymName, Purity, EvalMethod, PorFStr),
-	(
-		PorFStr = "pred",
-		PredOrFunc = predicate
-	;
-		PorFStr = "func",
-		PredOrFunc = function
-	).
-
-:- pred get_purity_and_eval_method(sym_name::in, purity::out,
-	lambda_eval_method::out, string::out) is semidet.
-
-get_purity_and_eval_method(SymName, Purity, EvalMethod, PorFStr) :-
-	(
-		SymName = qualified(unqualified(Qualifier), PorFStr),
-		(
-			Qualifier = "aditi_bottom_up",
-			EvalMethod = (aditi_bottom_up),
-			Purity = (pure)
-		;
-			Qualifier = "impure",
-			Purity = (impure),
-			EvalMethod = normal
-		;
-			Qualifier = "semipure",
-			Purity = (semipure),
-			EvalMethod = normal
-		)
-	;
-		SymName = unqualified(PorFStr),
-		EvalMethod = normal,
-		Purity = (pure)
-	).
-
-type_is_tuple(Type, ArgTypes) :-
-	type_to_ctor_and_args(Type, TypeCtor, ArgTypes),
-	type_ctor_is_tuple(TypeCtor).
-
-type_ctor_is_tuple(unqualified("{}") - _).
-
 type_has_user_defined_equality_pred(ModuleInfo, Type, UserEqComp) :-
 	type_to_type_defn_body(ModuleInfo, Type, TypeBody),
 	type_body_has_user_defined_equality_pred(ModuleInfo, TypeBody,
@@ -971,62 +789,62 @@
 	hlds_data__get_type_defn_body(TypeDefn, TypeBody),
 	TypeBody ^ du_type_is_enum = yes.

-type_to_ctor_and_args(Type, SymName - Arity, Args) :-
-	Type \= term__variable(_),
-
-	% higher order types may have representations where
-	% their arguments don't directly correspond to the
-	% arguments of the term.
-	(
-		type_is_higher_order(Type, Purity, PredOrFunc,
-			EvalMethod, PredArgTypes)
-	->
-		Args = PredArgTypes,
-		list__length(Args, Arity0),
-		adjust_func_arity(PredOrFunc, Arity, Arity0),
-		(
-			PredOrFunc = predicate,
-			PorFStr = "pred"
-		;
-			PredOrFunc = function,
-			PorFStr = "func"
-		),
-		SymName0 = unqualified(PorFStr),
-		(
-			EvalMethod = (aditi_bottom_up),
-			insert_module_qualifier("aditi_bottom_up", SymName0,
-				SymName1)
-		;
-			EvalMethod = normal,
-			SymName1 = SymName0
-		),
-		(
-			Purity = (pure),
-			SymName = SymName1
-		;
-			Purity = (semipure),
-			insert_module_qualifier("semipure", SymName1, SymName)
-		;
-			Purity = (impure),
-			insert_module_qualifier("impure", SymName1, SymName)
-		)
-	;
-		sym_name_and_args(Type, SymName, Args),
-
-		% `private_builtin:constraint' is introduced by polymorphism,
-		% and should only appear as the argument of a
-		% `typeclass:info/1' type.
-		% It behaves sort of like a type variable, so according to the
-		% specification of `type_to_ctor_and_args', it should
-		% cause failure. There isn't a definition in the type table.
-		\+ (
-			SymName = qualified(ModuleName, UnqualName),
-			UnqualName = "constraint",
-			mercury_private_builtin_module(PrivateBuiltin),
-			ModuleName = PrivateBuiltin
-		),
-		list__length(Args, Arity)
-	).
+% type_to_ctor_and_args(Type, SymName - Arity, Args) :-
+% 	Type \= term__variable(_),
+%
+% 	% higher order types may have representations where
+% 	% their arguments don't directly correspond to the
+% 	% arguments of the term.
+% 	(
+% 		type_is_higher_order(Type, Purity, PredOrFunc,
+% 			EvalMethod, PredArgTypes)
+% 	->
+% 		Args = PredArgTypes,
+% 		list__length(Args, Arity0),
+% 		adjust_func_arity(PredOrFunc, Arity, Arity0),
+% 		(
+% 			PredOrFunc = predicate,
+% 			PorFStr = "pred"
+% 		;
+% 			PredOrFunc = function,
+% 			PorFStr = "func"
+% 		),
+% 		SymName0 = unqualified(PorFStr),
+% 		(
+% 			EvalMethod = (aditi_bottom_up),
+% 			insert_module_qualifier("aditi_bottom_up", SymName0,
+% 				SymName1)
+% 		;
+% 			EvalMethod = normal,
+% 			SymName1 = SymName0
+% 		),
+% 		(
+% 			Purity = (pure),
+% 			SymName = SymName1
+% 		;
+% 			Purity = (semipure),
+% 			insert_module_qualifier("semipure", SymName1, SymName)
+% 		;
+% 			Purity = (impure),
+% 			insert_module_qualifier("impure", SymName1, SymName)
+% 		)
+% 	;
+% 		sym_name_and_args(Type, SymName, Args),
+%
+% 		% `private_builtin:constraint' is introduced by polymorphism,
+% 		% and should only appear as the argument of a
+% 		% `typeclass:info/1' type.
+% 		% It behaves sort of like a type variable, so according to the
+% 		% specification of `type_to_ctor_and_args', it should
+% 		% cause failure. There isn't a definition in the type table.
+% 		\+ (
+% 			SymName = qualified(ModuleName, UnqualName),
+% 			UnqualName = "constraint",
+% 			mercury_private_builtin_module(PrivateBuiltin),
+% 			ModuleName = PrivateBuiltin
+% 		),
+% 		list__length(Args, Arity)
+% 	).

 canonicalize_type_args(TypeCtor, TypeArgs0, TypeArgs) :-
 	(
@@ -1044,66 +862,6 @@
 		TypeArgs = TypeArgs0
 	).

-construct_type(TypeCtor, Args, Type) :-
-	(
-		type_ctor_is_higher_order(TypeCtor, Purity, PredOrFunc,
-			EvalMethod)
-	->
-		construct_higher_order_type(Purity, PredOrFunc, EvalMethod,
-			Args, Type)
-	;
-		TypeCtor = SymName - _,
-		construct_qualified_term(SymName, Args, Type)
-	).
-
-construct_higher_order_type(Purity, PredOrFunc, EvalMethod, ArgTypes, Type) :-
-	(
-		PredOrFunc = predicate,
-		construct_higher_order_pred_type(Purity, EvalMethod, ArgTypes,
-			Type)
-	;
-		PredOrFunc = function,
-		pred_args_to_func_args(ArgTypes, FuncArgTypes, FuncRetType),
-		construct_higher_order_func_type(Purity, EvalMethod,
-			FuncArgTypes, FuncRetType, Type)
-	).
-
-construct_higher_order_pred_type(Purity, EvalMethod, ArgTypes, Type) :-
-	construct_qualified_term(unqualified("pred"),
-		ArgTypes, Type0),
-	qualify_higher_order_type(EvalMethod, Type0, Type1),
-	Type = add_purity_annotation(Purity, Type1).
-
-construct_higher_order_func_type(Purity, EvalMethod, ArgTypes, RetType, Type) :-
-	construct_qualified_term(unqualified("func"), ArgTypes, Type0),
-	qualify_higher_order_type(EvalMethod, Type0, Type1),
-	Type2 = term__functor(term__atom("="), [Type1, RetType],
-			term__context_init),
-	Type = add_purity_annotation(Purity, Type2).
-
-:- func add_purity_annotation(purity, (type)) = (type).
-add_purity_annotation(Purity, Type0) = Type :-
-	(
-		Purity = (pure),
-		Type = Type0
-	;
-		Purity = (semipure),
-		Type = term__functor(term__atom("semipure"), [Type0],
-				term__context_init)
-	;
-		Purity = (impure),
-		Type = term__functor(term__atom("impure"), [Type0],
-				term__context_init)
-	).
-
-:- pred qualify_higher_order_type(lambda_eval_method::in, (type)::in,
-	(type)::out) is det.
-
-qualify_higher_order_type(normal, Type, Type).
-qualify_higher_order_type((aditi_bottom_up), Type0,
-	term__functor(term__atom("aditi_bottom_up"), [Type0], Context)) :-
-	term__context_init(Context).
-
 int_type = Type :-
 	construct_type(unqualified("int") - 0, [], Type).

@@ -1576,7 +1334,7 @@
 		term__apply_rec_substitution_to_list(CalleeExistQTypes0,
 			TypeSubst, CalleeExistQTypes),
 		all [T] (list__member(T, CalleeExistQTypes) =>
-				type_util__var(T, _))
+				prog_type__var(T, _))

 		% it might make sense to also check that
 		% the type substitution did not bind any
@@ -1751,15 +1509,12 @@

 %-----------------------------------------------------------------------------%

-type_util__vars(Type, Tvars) :-
-	term__vars(Type, Tvars).
-
 type_util__real_vars(Type, Tvars) :-
 	( is_introduced_type_info_type(Type) ->
 		% for these types, we don't add the type parameters
 		Tvars = []
 	;
-		type_util__vars(Type, Tvars)
+		prog_type__vars(Type, Tvars)
 	).

 %-----------------------------------------------------------------------------%
@@ -1867,7 +1622,7 @@

 		% if the tvar is still a variable, insert it into the
 		% map with the new var.
-	( type_util__var(NewType, NewTVar) ->
+	( prog_type__var(NewType, NewTVar) ->
 		% Don't abort if two old type variables
 		% map to the same new type variable.
 		map__set(!.NewVarMap, NewTVar, NewLocn, !:NewVarMap)
@@ -2030,20 +1785,6 @@
 	;
 		AdjustedArity = ConsArity
 	).
-
-%-----------------------------------------------------------------------------%
-
-constraint_list_get_tvars(Constraints, TVars) :-
-	list__map(constraint_get_tvars, Constraints, TVarsList),
-	list__condense(TVarsList, TVars).
-
-constraint_get_tvars(constraint(_Name, Args), TVars) :-
-	term__vars_list(Args, TVars).
-
-get_unconstrained_tvars(Tvars, Constraints, Unconstrained) :-
-	constraint_list_get_tvars(Constraints, ConstrainedTvars),
-	list__delete_elems(Tvars, ConstrainedTvars, Unconstrained0),
-	list__remove_dups(Unconstrained0, Unconstrained).

 %-----------------------------------------------------------------------------%

Index: compiler/typecheck.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/typecheck.m,v
retrieving revision 1.360
diff -u -r1.360 typecheck.m
--- compiler/typecheck.m	19 Jan 2005 03:10:58 -0000	1.360
+++ compiler/typecheck.m	20 Jan 2005 13:13:01 -0000
@@ -150,6 +150,7 @@
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.

 :- import_module getopt.
 :- import_module int, set, string, require, multi_map.
@@ -5338,7 +5339,7 @@
 :- func maybe_add_existential_quantifier(head_type_params, (type)) = (type).

 maybe_add_existential_quantifier(HeadTypeParams, Type0) = Type :-
-	type_util__vars(Type0, TVars),
+	prog_type__vars(Type0, TVars),
 	ExistQuantTVars = set__to_sorted_list(set__intersect(
 		set__list_to_set(HeadTypeParams), set__list_to_set(TVars))),
 	( ExistQuantTVars = [] ->
Index: compiler/unify_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_gen.m,v
retrieving revision 1.144
diff -u -r1.144 unify_gen.m
--- compiler/unify_gen.m	2 Sep 2004 04:31:40 -0000	1.144
+++ compiler/unify_gen.m	20 Jan 2005 02:24:38 -0000
@@ -62,6 +62,7 @@
 :- import_module parse_tree__error_util.
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_out.
+:- import_module parse_tree__prog_type.

 :- import_module term, bool, string, int, list, map, require, std_util.

Index: compiler/unify_proc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unify_proc.m,v
retrieving revision 1.142
diff -u -r1.142 unify_proc.m
--- compiler/unify_proc.m	19 Jan 2005 03:10:58 -0000	1.142
+++ compiler/unify_proc.m	20 Jan 2005 04:08:10 -0000
@@ -157,6 +157,7 @@
 :- import_module parse_tree__prog_mode.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.
 :- import_module recompilation.

 :- import_module term.
Index: compiler/unused_args.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/unused_args.m,v
retrieving revision 1.98
diff -u -r1.98 unused_args.m
--- compiler/unused_args.m	19 Jan 2005 03:10:59 -0000	1.98
+++ compiler/unused_args.m	20 Jan 2005 13:13:40 -0000
@@ -88,6 +88,7 @@
 :- import_module parse_tree__prog_data.
 :- import_module parse_tree__prog_out.
 :- import_module parse_tree__prog_util.
+:- import_module parse_tree__prog_type.
 :- import_module transform_hlds__mmc_analysis.

 :- import_module bool, int, char, string, list, assoc_list, set, map.
@@ -419,7 +420,7 @@
 setup_typeinfo_deps([], _, _, _, !VarDep).
 setup_typeinfo_deps([Var | Vars], VarTypeMap, PredProcId, TVarMap, !VarDep) :-
 	map__lookup(VarTypeMap, Var, Type),
-	type_util__vars(Type, TVars),
+	prog_type__vars(Type, TVars),
 	list__map((pred(TVar::in, TypeInfoVar::out) is det :-
 		map__lookup(TVarMap, TVar, Locn),
 		type_info_locn_var(Locn, TypeInfoVar)
Index: compiler/notes/compiler_design.html
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/notes/compiler_design.html,v
retrieving revision 1.94
diff -u -r1.94 compiler_design.html
--- compiler/notes/compiler_design.html	20 Dec 2004 01:15:46 -0000	1.94
+++ compiler/notes/compiler_design.html	20 Jan 2005 12:26:00 -0000
@@ -277,8 +277,9 @@
 	The modules prog_out.m and mercury_to_mercury.m contain predicates
 	for printing the parse tree.  prog_util.m contains some utility
 	predicates for manipulating the parse tree, prog_mode contains utility
-	predicates for manipulating insts and modes, while error_util.m
-	contains predicates for printing nicely formatting error messages.
+	predicates for manipulating insts and modes, prog_type contains utility
+	predicates for manipulating types, while error_util.m contains
+	predicates for printing nicely formatting error messages.

 <li><p> imports and exports are handled at this point (modules.m)


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