cherry-picking recent changes from master into 3.6.x

This is a large PR that brings the 3.6.x branch in sync with master.

`lib/3.7` was ignored during cherry-picking.  Otherwise nothing exciting happened.