Introduce needsCodegen.

This is a backport of the code from 2.065.
This comment is out of date, then.