[backport] Backports library changes related to SI-6566 from a419799

The idea of backporting this occured while developing the -source flag for
SI-8126 : without this the library breaks at refchecks for any Scala compiler
that checks type aliases variance.

Should be BC and promote good hygiene. Review by @retronym.