Refactor rule generation so that no unneeded code is created like (when true ...).

At least one rule has to be declared top-level now (using ^:top metadata), and
only top-level rules are applied automagically.  That brought a speedup of
about 15x.