[m-rev.] for review: further polymorphism stuff
Julien Fischer
juliensf at csse.unimelb.edu.au
Tue Jan 9 15:47:55 AEDT 2007
For review by Mark.
Estimated hours taken: 3
Branches: main
During the initial stage of the polymorphism transformation maintain
a more strict separation between the modes for the different kinds
of introduced arguments.
Add a new data structure to do this. The new data structure is called a
poly_arg_vector, which is similar to a proc_arg_vector but is intended to
represent only those arguments that have been introduced by polymorphism.
The new data structure is implemented as a proc_arg_vector in order to
ensure that the calling convention is consistent across both structure.
compiler/hlds_args.m:
Add the poly_arg_vector structure and some predicates that
operate on it.
Fix a comment.
compiler/polymorphism.m:
When processing the clause arguments accumulate the modes for the
introduced type_infos and typeclass_info arguments in a
poly_arg_vector rather than just building up a list of them.
This allows us to maintain the distinction between the different
kinds of introduced arguments.
Introduce state variables in a couple of places and rearrange
some argument orderings to make this possible.
compiler/notes/compiler_design.html:
Mention the hlds_args module.
Julien.
Index: compiler/hlds_args.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_args.m,v
retrieving revision 1.1
diff -u -r1.1 hlds_args.m
--- compiler/hlds_args.m 21 Dec 2006 06:33:57 -0000 1.1
+++ compiler/hlds_args.m 9 Jan 2007 04:33:23 -0000
@@ -103,8 +103,8 @@
%
:- pred apply_renaming_to_proc_arg_vector(map(T, T)::in,
proc_arg_vector(T)::in, proc_arg_vector(T)::out) is det.
-
- % partition_arg_vector_by_origin(Vec, PolyArgs, NonPolyArgs):
+
+ % proc_arg_vector_partition_poly_args(Vec, PolyArgs, NonPolyArgs):
%
% Partition the argument vector into two lists depending on whether
% something was introduced by the polymorphism transformation or not.
@@ -126,6 +126,43 @@
list(T)::out, T::out) is det.
%-----------------------------------------------------------------------------%
+%
+% Stuff related to the polymorphism pass
+%
+
+ % This type represents those arguments of a predicate or function
+ % symbol that are introduced by the polymorphism transformation.
+ % The arguments may be variables, types, modes, etc, depending on the
+ % context.
+ %
+ % Values of this type are used to pass around intermediate values
+ % during the polymorphism transformation.
+ %
+:- type poly_arg_vector(T).
+
+:- func poly_arg_vector_init = poly_arg_vector(T).
+
+:- pred poly_arg_vector_set_instance_type_infos(list(T)::in,
+ poly_arg_vector(T)::in, poly_arg_vector(T)::out) is det.
+:- pred poly_arg_vector_set_instance_typeclass_infos(list(T)::in,
+ poly_arg_vector(T)::in, poly_arg_vector(T)::out) is det.
+:- pred poly_arg_vector_set_univ_type_infos(list(T)::in,
+ poly_arg_vector(T)::in, poly_arg_vector(T)::out) is det.
+:- pred poly_arg_vector_set_exist_type_infos(list(T)::in,
+ poly_arg_vector(T)::in, poly_arg_vector(T)::out) is det.
+:- pred poly_arg_vector_set_univ_typeclass_infos(list(T)::in,
+ poly_arg_vector(T)::in, poly_arg_vector(T)::out) is det.
+:- pred poly_arg_vector_set_exist_typeclass_infos(list(T)::in,
+ poly_arg_vector(T)::in, poly_arg_vector(T)::out) is det.
+
+ % Convert a poly_arg_vector into a list.
+ % XXX ARGVEC - this is only temporary until the proc_info structure use
+ % proc_arg_vectors. We should then provide a predicate that merges a
+ % poly_arg_vector with a proc_arg_vector.
+ %
+:- func poly_arg_vector_to_list(poly_arg_vector(T)) = list(T).
+
+%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
@@ -321,6 +358,38 @@
).
%-----------------------------------------------------------------------------%
+%
+% Stuff related to the polymorphism transformation
+%
+
+ % Internally we represent a poly_arg_vector as a proc_arg_vector.
+ % This ensures that poly_arg_vectors obey the same calling convention
+ % w.r.t introduced type_info and typeclass_info arguments that
+ % proc_arg_vectors do. For the proc_arg_vectors that are
+ % used to represent poly_arg_vectors we insist that the the last
+ % two fields are the empty list and `no' respectively.
+ %
+:- type poly_arg_vector(T) == proc_arg_vector(T).
+
+poly_arg_vector_init = proc_arg_vector_init(predicate, []).
+
+poly_arg_vector_set_instance_type_infos(ITI, !A) :-
+ proc_arg_vector_set_instance_type_infos(ITI, !A).
+poly_arg_vector_set_instance_typeclass_infos(ITCI, !A) :-
+ proc_arg_vector_set_instance_typeclass_infos(ITCI, !A).
+poly_arg_vector_set_univ_type_infos(UTI, !A) :-
+ proc_arg_vector_set_univ_type_infos(UTI, !A).
+poly_arg_vector_set_exist_type_infos(ETI, !A) :-
+ proc_arg_vector_set_exist_type_infos(ETI, !A).
+poly_arg_vector_set_univ_typeclass_infos(UTCI, !A) :-
+ proc_arg_vector_set_univ_typeclass_infos(UTCI, !A).
+poly_arg_vector_set_exist_typeclass_infos(ETCI, !A) :-
+ proc_arg_vector_set_exist_typeclass_infos(ETCI, !A).
+
+poly_arg_vector_to_list(V) =
+ proc_arg_vector_to_list(V).
+
+%-----------------------------------------------------------------------------%
:- func this_file = string.
Index: compiler/polymorphism.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/polymorphism.m,v
retrieving revision 1.315
diff -u -r1.315 polymorphism.m
--- compiler/polymorphism.m 8 Jan 2007 05:36:08 -0000 1.315
+++ compiler/polymorphism.m 9 Jan 2007 01:26:14 -0000
@@ -556,8 +556,8 @@
module_info_set_pred_info(PredId, PredInfo, !ModuleInfo).
:- pred polymorphism_process_clause_info(pred_info::in, module_info::in,
- clauses_info::in, clauses_info::out, poly_info::out, list(mer_mode)::out)
- is det.
+ clauses_info::in, clauses_info::out, poly_info::out,
+ poly_arg_vector(mer_mode)::out) is det.
polymorphism_process_clause_info(PredInfo0, ModuleInfo0, !ClausesInfo, !:Info,
ExtraArgModes) :-
@@ -613,7 +613,8 @@
).
:- pred polymorphism_process_proc_in_table(pred_info::in, clauses_info::in,
- list(mer_mode)::in, proc_id::in, proc_table::in, proc_table::out) is det.
+ poly_arg_vector(mer_mode)::in, proc_id::in,
+ proc_table::in, proc_table::out) is det.
polymorphism_process_proc_in_table(PredInfo, ClausesInfo, ExtraArgModes,
ProcId, !ProcTable) :-
@@ -623,7 +624,8 @@
map.det_update(!.ProcTable, ProcId, ProcInfo, !:ProcTable).
:- pred polymorphism_process_proc(pred_info::in, clauses_info::in,
- list(mer_mode)::in, proc_id::in, proc_info::in, proc_info::out) is det.
+ poly_arg_vector(mer_mode)::in, proc_id::in, proc_info::in, proc_info::out)
+ is det.
polymorphism_process_proc(PredInfo, ClausesInfo, ExtraArgModes, ProcId,
!ProcInfo) :-
@@ -656,8 +658,10 @@
),
% Add the ExtraArgModes to the proc_info argmodes.
+ % XXX ARGVEC - revisit this when the proc_info uses proc_arg_vectors.
proc_info_get_argmodes(!.ProcInfo, ArgModes1),
- list.append(ExtraArgModes, ArgModes1, ArgModes),
+ ExtraArgModesList = poly_arg_vector_to_list(ExtraArgModes),
+ list.append(ExtraArgModesList, ArgModes1, ArgModes),
proc_info_set_argmodes(ArgModes, !ProcInfo).
% XXX document me
@@ -667,31 +671,32 @@
% in a more consistent manner.
%
:- pred setup_headvars(pred_info::in, proc_arg_vector(prog_var)::in,
- proc_arg_vector(prog_var)::out, list(mer_mode)::out,
+ proc_arg_vector(prog_var)::out, poly_arg_vector(mer_mode)::out,
list(tvar)::out, list(tvar)::out,
list(prog_var)::out, list(prog_var)::out,
poly_info::in, poly_info::out) is det.
-setup_headvars(PredInfo, HeadVars0, HeadVars, ExtraArgModes,
+setup_headvars(PredInfo, !HeadVars, ExtraArgModes,
HeadTypeVars, UnconstrainedTVars, ExtraHeadTypeInfoVars,
ExistHeadTypeClassInfoVars, !Info) :-
pred_info_get_origin(PredInfo, Origin),
+ ExtraArgModes0 = poly_arg_vector_init : poly_arg_vector(mer_mode),
( Origin = origin_instance_method(InstanceMethodConstraints) ->
setup_headvars_instance_method(PredInfo,
- InstanceMethodConstraints, HeadVars0, HeadVars,
- ExtraArgModes, HeadTypeVars, UnconstrainedTVars,
- ExtraHeadTypeInfoVars, ExistHeadTypeClassInfoVars, !Info)
+ InstanceMethodConstraints, !HeadVars,
+ HeadTypeVars, UnconstrainedTVars,
+ ExtraHeadTypeInfoVars, ExistHeadTypeClassInfoVars,
+ ExtraArgModes0, ExtraArgModes, !Info)
;
pred_info_get_class_context(PredInfo, ClassContext),
- ExtraArgModes0 = [],
InstanceTVars = [],
InstanceUnconstrainedTVars = [],
InstanceUnconstrainedTypeInfoVars = [],
- setup_headvars_2(PredInfo, ClassContext, ExtraArgModes0,
- InstanceTVars, InstanceUnconstrainedTVars,
- InstanceUnconstrainedTypeInfoVars, HeadVars0, HeadVars,
- ExtraArgModes, HeadTypeVars, UnconstrainedTVars,
- ExtraHeadTypeInfoVars, ExistHeadTypeClassInfoVars, !Info)
+ setup_headvars_2(PredInfo, ClassContext, InstanceTVars,
+ InstanceUnconstrainedTVars, InstanceUnconstrainedTypeInfoVars,
+ !HeadVars, HeadTypeVars, UnconstrainedTVars,
+ ExtraHeadTypeInfoVars, ExistHeadTypeClassInfoVars,
+ ExtraArgModes0, ExtraArgModes, !Info)
).
% For class method implementations, do_call_class_method takes the
@@ -701,13 +706,15 @@
:- pred setup_headvars_instance_method(pred_info::in,
instance_method_constraints::in,
proc_arg_vector(prog_var)::in, proc_arg_vector(prog_var)::out,
- list(mer_mode)::out, list(tvar)::out, list(tvar)::out, list(prog_var)::out,
- list(prog_var)::out, poly_info::in, poly_info::out) is det.
+ list(tvar)::out, list(tvar)::out,
+ list(prog_var)::out, list(prog_var)::out,
+ poly_arg_vector(mer_mode)::in, poly_arg_vector(mer_mode)::out,
+ poly_info::in, poly_info::out) is det.
setup_headvars_instance_method(PredInfo,
- InstanceMethodConstraints, !HeadVars, ExtraArgModes,
+ InstanceMethodConstraints, !HeadVars,
HeadTypeVars, UnconstrainedTVars, ExtraHeadTypeInfoVars,
- ExistHeadTypeClassInfoVars, !Info) :-
+ ExistHeadTypeClassInfoVars, !ExtraArgModes, !Info) :-
InstanceMethodConstraints = instance_method_constraints(_,
InstanceTypes, InstanceConstraints, ClassContext),
@@ -720,43 +727,48 @@
ArgTypeVarSet, UnconstrainedInstanceTypeInfoVars, !Info),
make_typeclass_info_head_vars(do_record_type_info_locns,
InstanceConstraints, InstanceHeadTypeClassInfoVars, !Info),
+
+ proc_arg_vector_set_instance_type_infos(UnconstrainedInstanceTypeInfoVars,
+ !HeadVars),
+ proc_arg_vector_set_instance_typeclass_infos(InstanceHeadTypeClassInfoVars,
+ !HeadVars),
+
poly_info_get_rtti_varmaps(!.Info, RttiVarMaps0),
list.foldl(rtti_reuse_typeclass_info_var,
InstanceHeadTypeClassInfoVars, RttiVarMaps0, RttiVarMaps),
poly_info_set_rtti_varmaps(RttiVarMaps, !Info),
+
in_mode(InMode),
list.duplicate(list.length(UnconstrainedInstanceTypeInfoVars),
InMode, UnconstrainedInstanceTypeInfoModes),
list.duplicate(list.length(InstanceHeadTypeClassInfoVars),
InMode, InstanceHeadTypeClassInfoModes),
-
- ExtraArgModes0 = UnconstrainedInstanceTypeInfoModes ++
- InstanceHeadTypeClassInfoModes,
-
- proc_arg_vector_set_instance_type_infos(UnconstrainedInstanceTypeInfoVars,
- !HeadVars),
- proc_arg_vector_set_instance_typeclass_infos(InstanceHeadTypeClassInfoVars,
- !HeadVars),
+ poly_arg_vector_set_instance_type_infos(
+ UnconstrainedInstanceTypeInfoModes, !ExtraArgModes),
+ poly_arg_vector_set_instance_typeclass_infos(
+ InstanceHeadTypeClassInfoModes, !ExtraArgModes),
setup_headvars_2(PredInfo, ClassContext,
- ExtraArgModes0, InstanceTVars,
+ InstanceTVars,
UnconstrainedInstanceTVars, UnconstrainedInstanceTypeInfoVars,
- !HeadVars, ExtraArgModes, HeadTypeVars,
+ !HeadVars, HeadTypeVars,
UnconstrainedTVars, ExtraHeadTypeInfoVars,
- ExistHeadTypeClassInfoVars, !Info).
+ ExistHeadTypeClassInfoVars, !ExtraArgModes, !Info).
:- pred setup_headvars_2(pred_info::in, prog_constraints::in,
- list(mer_mode)::in, list(tvar)::in, list(tvar)::in, list(prog_var)::in,
+ list(tvar)::in, list(tvar)::in, list(prog_var)::in,
proc_arg_vector(prog_var)::in, proc_arg_vector(prog_var)::out,
- list(mer_mode)::out, list(tvar)::out, list(tvar)::out,
+ list(tvar)::out, list(tvar)::out,
list(prog_var)::out, list(prog_var)::out,
+ poly_arg_vector(mer_mode)::in, poly_arg_vector(mer_mode)::out,
poly_info::in, poly_info::out) is det.
setup_headvars_2(PredInfo, ClassContext,
- ExtraArgModes0, InstanceTVars, UnconstrainedInstanceTVars,
+ InstanceTVars, UnconstrainedInstanceTVars,
UnconstrainedInstanceTypeInfoVars, HeadVars0,
- HeadVars, ExtraArgModes, HeadTypeVars, AllUnconstrainedTVars,
- AllExtraHeadTypeInfoVars, ExistHeadTypeClassInfoVars, !Info) :-
+ HeadVars, HeadTypeVars, AllUnconstrainedTVars,
+ AllExtraHeadTypeInfoVars, ExistHeadTypeClassInfoVars,
+ !ExtraArgModes, !Info) :-
% Grab the appropriate fields from the pred_info.
pred_info_get_arg_types(PredInfo, ArgTypeVarSet, ExistQVars, ArgTypes),
@@ -862,8 +874,12 @@
list.duplicate(NumUnconstrainedExistTVars, Out, ExistTypeInfoModes),
list.duplicate(NumUnivClassInfoVars, In, UnivTypeClassInfoModes),
list.duplicate(NumExistClassInfoVars, Out, ExistTypeClassInfoModes),
- list.condense([ExtraArgModes0, UnivTypeInfoModes, ExistTypeInfoModes,
- UnivTypeClassInfoModes, ExistTypeClassInfoModes], ExtraArgModes),
+ poly_arg_vector_set_univ_type_infos(UnivTypeInfoModes, !ExtraArgModes),
+ poly_arg_vector_set_exist_type_infos(ExistTypeInfoModes, !ExtraArgModes),
+ poly_arg_vector_set_univ_typeclass_infos(UnivTypeClassInfoModes,
+ !ExtraArgModes),
+ poly_arg_vector_set_exist_typeclass_infos(ExistTypeClassInfoModes,
+ !ExtraArgModes),
% Add the locations of the typeinfos for unconstrained, universally
% quantified type variables to the initial rtti_varmaps. Also add the
Index: compiler/notes/compiler_design.html
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/notes/compiler_design.html,v
retrieving revision 1.125
diff -u -r1.125 compiler_design.html
--- compiler/notes/compiler_design.html 3 Nov 2006 08:31:18 -0000 1.125
+++ compiler/notes/compiler_design.html 9 Jan 2007 04:40:12 -0000
@@ -471,11 +471,14 @@
<ol>
<li>
+hlds_args.m defines the parts of the HLDS concerned with predicate
+and function argument lists.
+<li>
hlds_data.m defines the parts of the HLDS concerned with
function symbols, types, insts, modes and determinisms;
<li>
hlds_goal.m defines the part of the HLDS concerned with the
-structure of goals, including the annotations on goals;
+structure of goals, including the annotations on goals.
<li>
hlds_clauses.m defines the part of the HLDS concerning clauses.
<li>
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list