Improve compileRule to avoid unnecessary projections.