Backport lang/mercury fixes from trunk.