This commit does not change the implementation of any function: it only moves code and adds new includes as necessary. Part of #23149.