[m-dev.] `highly ambiguous overloading' ??
Fergus Henderson
fjh at cs.mu.OZ.AU
Sat Mar 17 08:59:12 AEDT 2001
On 16-Mar-2001, Nancy Mazur <Nancy.Mazur at cs.kuleuven.ac.be> wrote:
> We're trying to figure out the meaning of the next warning:
>
> hlds_pred.m:1918: In clause for predicate `hlds_pred:proc_info_create/12':
> hlds_pred.m:1918: warning: highly ambiguous overloading. This may cause
> hlds_pred.m:1918: type-checking to be very slow. It may also make your code
> hlds_pred.m:1918: difficult to understand.
>
> I've just added an additional field to the proc_info type, and got
> that warning.
>
> What's wrong here?
...
> proc_info_create(VarSet, VarTypes, HeadVars, HeadModes, InstVarSet, Detism,
> Goal, Context, TVarMap, TCVarsMap, IsAddressTaken, ProcInfo) :-
> map__init(StackSlots),
> set__init(Liveness),
> MaybeHeadLives = no,
> RLExprn = no,
> Alias = no,
> GlobalUse = no,
> Reuse = no,
> StaticTerms = no, % <========== line 1918 ====================
> ModeErrors = [],
> ProcInfo = procedure(VarSet, VarTypes, HeadVars, HeadVars, HeadModes,
> ModeErrors, InstVarSet,
> MaybeHeadLives, Goal, Context, StackSlots,
> yes(Detism), Detism, yes, [], Liveness, TVarMap, TCVarsMap,
> eval_normal, no, no, no, IsAddressTaken, RLExprn,
> Alias, GlobalUse, Reuse, StaticTerms, no, no).
The compiler type-checks things left-to-right, and does breadth-first search
to resolve ambiguities. If you have a whole bunch of unifications with an
overloaded name like `no' (which is used both in `bool' and in `maybe(T)'), and
nothing to resolve the ambiguity, then the current implementation uses up 2^N
time and space. For N > 5 you will get a warning. Here N = 6.
A solution is to write the unification `ProcInfo = procedure(...)'
before all the unifications with `no'; that way the compiler
will be able to use the type of `procedure(...)' to resolve
the ambiguity.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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