Merge fix from upstream.
Harden logic for marking pure as in 'has no side effects'