[m-rev.] for review: fix purity in tabling and optimization passes
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Mar 26 10:35:15 AEST 2001
On 24-Mar-2001, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
>
> compiler/deforest.m:
> Use the same method as inlining.m to work out whether
> a procedure can be inlined. Don't inline predicates which
> are promised pure because the extra impurity which
> will be propagated through the goal will stop deforestation
> working on the goal.
What about predicates which are inferred semipure and promised pure?
For those, the extra impurity (or perhaps I should say the extra
semi-impurity) shouldn't prevent deforestation, should it?
It seems to me that the right condition to check here
is not whether the predicate was promised pure, but whether
the predicate body is impure.
> -warn_unnecessary_promise_pure(ModuleInfo, PredInfo, PredId) -->
> +warn_unnecessary_promise_pure(ModuleInfo, PredInfo, PredId, PromisedPurity) -->
> { pred_info_context(PredInfo, Context) },
> write_context_and_pred_id(ModuleInfo, PredInfo, PredId),
> prog_out__write_context(Context),
> - report_warning(" warning: unnecessary `promise_pure' pragma.\n"),
> + {
> + PromisedPurity = pure,
> + Pragma = "promise_pure",
> + CodeStr = "impure or semipure"
> + ;
> + PromisedPurity = (semipure),
> + Pragma = "promise_semipure",
> + CodeStr = "impure"
> + ;
> + PromisedPurity = (impure),
> + error("purity__warn_unnecessary_promise_pure: promise_impure?")
> + },
> +
> + report_warning(" warning: unnecessary `"),
> + io__write_string(Pragma),
> + io__write_string("' pragma.\n"),
> globals__io_lookup_bool_option(verbose_errors, VerboseErrors),
> ( { VerboseErrors = yes } ->
> prog_out__write_context(Context),
> { pred_info_get_is_pred_or_func(PredInfo, PredOrFunc) },
> io__write_string(" This "),
> hlds_out__write_pred_or_func(PredOrFunc),
> - io__write_string(
> - " does not invoke any impure or semipure code,\n"
> - ),
> + io__write_string(" does not invoke any "),
> + io__write_string(CodeStr),
> + io__write_string(",\n"),
I think the word "code" got dropped there.
> +:- type post_typecheck_message
> + ---> error(post_typecheck_error)
> + ; warning(post_typecheck_warning)
> + .
> +
> +:- type post_typecheck_messages == list(post_typecheck_message).
> +
> +:- type post_typecheck_error
> + ---> missing_body_impurity_error(prog_context, pred_id)
> + ; impure_closure(prog_context, purity)
> + ; impure_unification_expr_error(prog_context, purity)
> + ; aditi_builtin_error(aditi_builtin_error)
> + .
> +
> +:- type post_typecheck_warning
> + ---> unnecessary_body_impurity_decl(prog_context, pred_id, purity).
Hmm, should all go in post_typecheck.m rather than purity.m?
Or should those categories be renamed purity_error, purity_warning, etc.?
> --- doc/reference_manual.texi 2001/03/15 06:32:06 1.203
> +++ doc/reference_manual.texi 2001/03/24 02:10:09
> @@ -5846,20 +5846,24 @@
> declared purity of the calls it executes, the lowest purity bound is
> propagated up from callee to caller through the program.
>
> -However, some predicates which call impure or semipure predicates are
> -themselves pure.
> -The only way for the programmer to stop the propagation of impurity is
> -to explicitly promise that a predicate or function is pure.
> +In some cases the impurity of a predicate's body is an implementation
> +detail which should not be exposed to callers. These predicates should
> +be considered to be pure or semipure even though they call impure or
> +semipure predicates. The only way for the programmer to stop the
> +propagation of impurity is to explicitly promise that the predicate
> +or function is pure or semipure.
s/should be considered/are/
> + % XXX Storing the purity in the pred_info is the
> + % wrong thing to do, because optimizations can
> + % make some procedures more pure than others.
Hmm, yes. I need to think about that one after I've had some sleep.
--
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-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