Functional delineation of tissue-resident CD8+ T cell heterogeneity during infection and cancer