Reapply r106422, splitting the code for materializing a value out of