Incorporate rewriting on demand in the evaluator (#3549)