[m-dev.] for review: type specialization and functions
Simon Taylor
stayl at cs.mu.OZ.AU
Thu Oct 14 14:17:06 AEST 1999
>
> On 14-Oct-1999, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> >
> > diff -u -u -r1.309 make_hlds.m
> > --- make_hlds.m 1999/10/12 01:55:35 1.309
> > +++ make_hlds.m 1999/10/12 05:07:50
> > @@ -915,8 +917,18 @@
> > goal_info_set_nonlocals(GoalInfo0, NonLocals, GoalInfo1),
> > goal_info_set_context(GoalInfo1, Context, GoalInfo),
> > invalid_proc_id(DummyProcId),
> > - Goal = call(PredId, DummyProcId, Args,
> > - not_builtin, no, SymName) - GoalInfo,
> > + (
> > + PredOrFunc = predicate,
> > + Goal = call(PredId, DummyProcId, Args,
> > + not_builtin, no, SymName) - GoalInfo
> > + ;
> > + PredOrFunc = function,
> > + pred_args_to_func_args(Args, FuncArgs, RetArg),
> > + ConsId = cons(SymName, Arity),
> > + create_atomic_unification(RetArg,
> > + functor(ConsId, FuncArgs), Context,
> > + explicit, [], Goal)
> > + ),
>
> I think this code won't properly handle the case where the function name
> is overloaded. I think you need to use a fully-qualified SymName,
> to avoid ambiguity, but the one you are passing here might not be
> fully-qualified.
It is always fully-qualified - the code in prog_io_pragma.m uses
parse_implicitly_qualified_term which attaches the current module name
on the name of the specialized predicate, checking that any module
name that the programmer specified matches.
> Also, the call to invalid_proc_id/1 should be moved to inside the disjunction.
OK.
> I suggest you add some test cases here for overloaded functions.
Index: tests/hard_coded/type_spec.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/type_spec.m,v
retrieving revision 1.2
diff -u -u -r1.2 type_spec.m
--- type_spec.m 1999/10/03 04:17:25 1.2
+++ type_spec.m 1999/10/14 04:08:03
@@ -52,8 +52,14 @@
% Test specialization of unifications involving no tag types.
:- pred unify_no_tag(no_tag::in, no_tag::in) is semidet.
-:- pragma no_inline(unify_no_tag/2).
+:- func id(T) = T.
+:- pragma type_spec(id/1, T = int).
+
+ % Test specialization of overloaded procedures.
+:- func length(list(T)) = int.
+:- pragma type_spec(length/1, T = int).
+
:- implementation.
main -->
@@ -92,8 +98,15 @@
io__write_string("Succeeded\n")
;
io__write_string("Failed\n")
+ ),
+ ( { id(1) = 1 } ->
+ io__write_string("Succeeded\n")
+ ;
+ io__write_string("Failed\n")
).
+
+
type_spec([], [], []).
type_spec([_ | _], [], []).
type_spec([], [_ | _], []).
@@ -140,4 +153,10 @@
my_unify(X, X).
+:- pragma no_inline(unify_no_tag/2).
+
unify_no_tag(X, X).
+
+id(X) = X.
+
+type_spec__length(List) = list__length(List).
--------------------------------------------------------------------------
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