Modular invariance is known to constrain the spectrum of 2d conformal field theories. We investigate this constraint systematically, using the linear functional method to put new improved upper bounds on the lowest gap in the spectrum. We also consider generalized partition functions of N = (2,2) superconformal theories and discuss the application of our results to Calabi-Yau compactifications. For Calabi-Yau threefolds with no enhanced symmetry we find that there must always be non-BPS primary states of weight 0.6 or less.