Just as variable bindings should be unbound on backtracking, the same could be expected from dynamic rule definitions.
Currently a rule is only undefined at the end of a scope (also if the body of the scope fails), so by placing appropriate scopes the user can achieve this by hand. But in general, automated undefining on backtracking might be useful.

Submitted on 29 April 2004 at 20:13

On 30 April 2004 at 00:06 Jira commented:

STR-76, adam:
Reply by Eelco on stratego-dev:
But not something you want in general. In the semantics as described in the paper dynamic rules are explicitly kept upon failure, i.e., represent a state.

The scope operator does not undefine rules on failure of the strategy, but ensures that the scope is exited also on failure. Any rules in outer scopes that have (re)defined remain.

My view is that control over definition and undefinition of dynamic rules should be explicit and not be determined by failure of strategies.

As an example application: in the instruction selection strategy in the RTA’02 paper a loop by failure strategy is used to find all possible matches of instruction selection rules at a node in an expression. Each succesful match leads to the definition of a dynamic rule; the subsequent failure forces bactracking to alternative matches.

On the other hand I can imagine that there are cases where it would be attractive to do a rollback. This would entail setting up a changeset when entering the left branch of a choice and committing it when the branch succeeds.

Since this is a pretty expensive operation, it is probably more useful to have special operator dr-left-choice(s1,s2|rulenames) (with some appropriate syntax) that can be used where it is needed rather than doing it at every choice for all dynamic rules.

– Eelco


On 29 October 2005 at 22:54 Jira commented:

STR-76, visser:
dr-left-choice(s1,s2|rulenames) implements a left choice with dynamic
rule roll-back in case s1 fails for all rules with their name in the
list rulenames.

General roll-back for all dynamic rules in all choices will not be
implemented as it woul be (1) to expensive and (2) difficult to
implement, since it would require some way to know about all dynamic
rules (that are affected by a strategy).

Note that this operation is not cheap: it requires setting up a change
set for every dynamic rule in the list and later committing or
discarding it.

Log in to post comments