[m-rev.] for review: exists_casts

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Aug 12 14:23:34 AEST 2005


On 12-Aug-2005, Mark Brown <mark at cs.mu.OZ.AU> wrote:
> +	% The various kinds of casts that we can do.
> +	%
> +:- type cast_type
> +	--->	unsafe_type_cast
> +			% An unsafe type cast between ground values.
> +
> +	;	unsafe_type_inst_cast
> +			% An unsafe type and inst cast.
> +
> +	;	equiv_type_cast
> +			% A safe type cast between equivalent types.

Give :- type t1 == t2, does the cast always go from t1 to t2, or not?
Either way, the answer is worth documenting here.

> +	;	exists_cast.
> +			% A safe cast between an internal type_info or
> +			% typeclass_info variable, for which the bindings of
> +			% existential type variables are known, to an external
> +			% type_info or typeclass_info head variable, for which
> +			% they are not.

... are known STATICALLY, ...

> +	% Add exists_casts for any head vars which are existentially typed,
> +	% and for which the type is bound inside the procedure.  The tsubst
> +	% that we pass in represents which existential types are bound.
> +	introduce_exists_casts_head(ModuleInfo, Subn, OrigArgTypes,
> +		OrigArgModes, OrigHeadVars1, OrigHeadVars, VarSet0, VarSet1,
> +		VarTypes0, VarTypes1, [], ExistsCastHeadGoals),

Please say which var here contains the tsubst.

> +	list__append(ExistsCastHeadGoals, ExistsCastExtraGoals,
> +		ExistsCastGoals),
> +	list__append(Goals0, ExistsCastGoals, Goals),
> +	list__append(ExtraHeadVars, OrigHeadVars, HeadVars),

Using ++ functions here would make this easier to read and much shorter.

> +introduce_exists_casts_head_2(ModuleInfo, Subn, ExternalType, ArgMode,
> +		HeadVar0, HeadVar, !VarSet, !VarTypes, !ExtraGoals) :-

I'd do

	s/introduce_exists_casts_head/introduce_exists_casts_for_head/
	s/introduce_exists_casts_head_2/introduce_exists_casts_for_arg/

> +introduce_exists_casts_extra(_, _, [], [], [], !VarSet, !VarTypes,
> +	!RttiVarMaps, []).
> +introduce_exists_casts_extra(_, _, [], [_ | _], _, _, _, _, _, _, _, _) :-
> +	unexpected(this_file, "introduce_exists_casts_extra: length mismatch").
> +introduce_exists_casts_extra(_, _, [_ | _], [], _, _, _, _, _, _, _, _) :-
> +	unexpected(this_file, "introduce_exists_casts_extra: length mismatch").
> +introduce_exists_casts_extra(ModuleInfo, Subn, [ArgMode | ArgModes],
> +		[Var0 | Vars0], [Var | Vars], !VarSet, !VarTypes, !RttiVarMaps,
> +		ExtraGoals) :-

I think we need versions of assoc_list__from_corresponding lists that
create lists of 3- and 4-tuples.

> +	introduce_exists_casts_extra(ModuleInfo, Subn, ArgModes, Vars0, Vars,
> +		!VarSet, !VarTypes, !RttiVarMaps, ExtraGoals0),
> +
> +	(
> +		mode_is_output(ModuleInfo, ArgMode)
> +	->
> +			% Update the type of this variable.  This only needs
> +			% to be done because type_info/1 and typeclass_info/1
> +			% have types in their respective arguments.
> +			%
> +		map__lookup(!.VarTypes, Var0, ExternalType),
> +		term__apply_rec_substitution(ExternalType, Subn, InternalType),
> +		svmap__det_update(Var0, InternalType, !VarTypes),
> +
> +			% Create the exists_cast goal.
> +			%
> +		term__context_init(Context),
> +		make_new_exist_cast_var(Var0, Var, !VarSet),
> +		svmap__det_insert(Var, ExternalType, !VarTypes),
> +		generate_cast(exists_cast, Var0, Var, Context, ExtraGoal),
> +		ExtraGoals = [ExtraGoal | ExtraGoals0],
> +	
> +			% Update the rtti_varmaps.
> +			% XXX need to do this
> +		true

Is that XXX intended to be fixed in another change, or this one?

Other than that, the diff is fine.

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