builtin/apply: move 'p_value' global into 'struct apply_state'