[m-dev.] Re: Mercury Tcl/Tk interface broken
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Aug 27 02:23:24 AEST 1999
On 26-Aug-1999, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
>
> > I'm now trying to rebuild a version from just before this change. I'll let
> > you know how it goes.
>
> It will work, but for the wrong reason.
>
> DJ and I just tracked down the cause of this. The problem is the handling
> of the mode declaration for get:
>
> :- pred get(tcl_interp, widget, string, io__state, io__state).
> :- mode get(in, in(entry), out, di, uo) is det.
> :- mode get(in, in(text), out, di, uo) is det.
>
> The clauses for get are:
>
> get(Interp, entry(Path), String) -->
> { string__format("%s get", [s(Path)], CmdStr) },
> eval(Interp, CmdStr, Res, String),
> { Res = tcl_ok -> true ; error(String) }.
> get(Interp, text(Path), String) -->
> { string__format("%s get 1.0 end", [s(Path)], CmdStr) },
> eval(Interp, CmdStr, Res, String),
> { Res = tcl_ok -> true ; error(String) }.
>
> These are turned into a disjunction, and in each mode of get, mode analysis
> replaces the unification with Headvar2 in one arm of the disjunction with
> fail.
>
> The problem is that after this step, that arm of the disjunction reads
> "Headvar1 = Interp, fail" instead of just "fail". Since removing code before
> a fail may in general change the operational semantics, simplification does
> not remove the arm of the disjunction, so the disjunction has one arm with
> detism det and one arm with detism failure, so its overall detism is det.
Well, it's kind of irrelevant what simplification does, because
unique mode analysis is done before simplification.
Whether or not you get a unique mode error depends only on what
the passes up to unique mode analysis do,
i.e. mode analysis, switch detection, cse detection, determinism
analysis, and unique mode analysis.
Of course it may help to simplify such goals, but that's an efficiency
issue rather than a correctness issue.
> In April Fergus changed unique mode checking so that any unique variable that
> is live on entry to any disjunction, even a model-det disjunction like this
> one, will be set to mostly_unique.
>
> There are two changes we can make to fix this problem. First, Fergus should
> change unique-mode checking again, so that what you check before making
> a unique variable into only a mostly-unique variable is not the detism
> of the disjunction, but the detism of the disjunct; you cannot backtrack
> out of a det disjunct.
That is a good suggestion. I'll do that.
> This will avoid Warwick's problem without reintroducing
> Serge's. The other is to modify simplication so that any sequence of primitive
> unifications (i.e. any unification that cannot call a user-defined equality
> predicate) followed by a fail are replaced by fail. This will allow the
> existing code in simplification, which removes a disjunct if it consists
> of only "fail", to kick in.
simplify.m already contains a more general optimization: it replaces any
code with determinism `failure' by fail, if that code cannot loop.
For some reason that optimization is not working or not being called in
this case. I don't understand why not. I'll investigate further.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- 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