Generalize MacExpr / MacPat / MacItems

Closes #17637
Merge #18814 into rollup

Approved-by: