1. finish range span, intersection rewriting and code-gen