[m-dev.] for review: fix existential types bug
David Glen JEFFERY
dgj at cs.mu.OZ.AU
Sun Oct 17 02:48:11 AEST 1999
On 15-Oct-1999, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
>
> Estimated hours taken: 12
>
> Fix a bug with switches on existential types. This bug meant that
> existential types with two or more functors did not work at all,
> due to internal compiler errors when compiling the unification and
> comparison predicates for those types.
>
> compiler/type_util.m:
> Add new function cons_id_adjusted_arity, which computes the
> arity _including_ the extra typeinfo and typeclassinfo
> arguments inserted for existential data types.
>
> compiler/type_util.m:
> compiler/polymorphism.m:
> Move the predicates constraint_list_get_tvars
> and constraint_get_tvars from polymorphism.m into
> type_util.m, for use in cons_id_adjusted_arity.
>
> compiler/modes.m:
> compiler/unique_modes.m:
> When modechecking the functor test in switch statements,
> use cons_id_adjusted_arity to compute the arity of the inst.
>
> compiler/instmap.m:
> In instmap__bind_var_to_functor (and the instmap_delta version),
> use cons_id_adjusted_arity to compute the arity of the inst.
>
> compiler/goal_util.m:
> compiler/pd_info.m:
> compiler/pd_util.m:
> compiler/saved_vars.m:
> compiler/mode_util.m:
> compiler/deforest.m:
> compiler/follow_code.m:
> compiler/higher_order.m:
> compiler/simplify.m:
> Pass the type(s) down to recompute_instmap_delta and
> instmap__bind_var_to_functor, since cons_id_adjusted_arity
> needs to know the type.
>
> compiler/hlds_pred.m:
> compiler/hlds_out.m:
> Add a `vartypes' typedef, defined by `:- type vartypes == map(prog_var, type)',
> and make use of it. Rename the `vartypes' type in hlds_out as `maybe_vartypes'.
>
> tests/hard_coded/Mmakefile:
> tests/hard_coded/existential_type_switch.m:
> tests/hard_coded/existential_type_switch.exp:
> Add a regression test.
>
> tests/hard_coded/Mmakefile:
> Enable the existential_types_test.m test case,
> which should have been enabled previously.
> (The reason that it wasn't seems to be that I made
> a mistake when merging in the changes from the
> existential types branch.)
> +cons_id_adjusted_arity(ModuleInfo, Type, ConsId) = AdjustedArity :-
> + % figure out the arity of this constructor,
> + % _including_ any type-infos or typeclass-infos
> + % inserted for existential data types.
> + cons_id_arity(ConsId, ConsArity),
> + (
> + type_util__get_existq_cons_defn(ModuleInfo, Type, ConsId,
> + ConsDefn)
> + ->
> + ConsDefn = ctor_defn(_TVarSet, ExistQTVars, Constraints,
> + _ArgTypes, _ResultType),
> + list__length(Constraints, NumTypeClassInfos),
> + constraint_list_get_tvars(Constraints, ConstrainedTVars),
> + list__delete_elems(ExistQTVars, ConstrainedTVars,
> + UnconstrainedExistQTVars),
> + list__length(UnconstrainedExistQTVars, NumTypeInfos),
> + AdjustedArity = ConsArity + NumTypeClassInfos + NumTypeInfos
> + ;
> + AdjustedArity = ConsArity
> + ).
It is perhaps a little unfortunate that this code in typecheck.m has to know
how we add type infos and type class infos (ie. that we only add type infos
for unconstrained tvars), but I guess it is still the best place for this code.
Commit away (if you haven't already).
dgj
--
David Jeffery (dgj at cs.mu.oz.au) | If your thesis is utterly vacuous
PhD student, | Use first-order predicate calculus.
Dept. of Comp. Sci. & Soft. Eng.| With sufficient formality
The University of Melbourne | The sheerist banality
Australia | Will be hailed by the critics: "Miraculous!"
| -- Anon.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list